From c3d486ba13c6cd12558d4c0cf01d3fd93e797d64 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 18 Mar 2010 11:07:51 +0800 Subject: [PATCH] Bugfixing initrd and ld-acess - ld-acess passed NULL to SysLoadBin if the file is not found - InitRD ignored Offset in ReadFile --- Kernel/Makefile.BuildNum | 2 +- Kernel/arch/x86/main.c | 9 +- Kernel/bin/elf.c | 19 ++++- Kernel/bin/elf.h | 6 +- Kernel/binary.c | 2 +- Kernel/include/vfs_ext.h | 2 +- Kernel/modules.c | 26 ++++-- Kernel/syscalls.c | 2 +- Kernel/vfs/main.c | 4 + Modules/Filesystems/InitRD/GenerateInitRD.php | 82 ++++++++++++------- Modules/Filesystems/InitRD/Makefile | 4 +- Modules/Filesystems/InitRD/files.lst | 10 +++ Modules/Filesystems/InitRD/main.c | 4 +- Usermode/Filesystem/Conf/BootConf.cfg | 2 +- Usermode/Libraries/ld-acess.so_src/loadlib.c | 4 + 15 files changed, 124 insertions(+), 54 deletions(-) diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 61acd3c6..46b9e67e 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1541 +BUILD_NUM = 1556 diff --git a/Kernel/arch/x86/main.c b/Kernel/arch/x86/main.c index f6879f8d..c8e4e4df 100644 --- a/Kernel/arch/x86/main.c +++ b/Kernel/arch/x86/main.c @@ -51,11 +51,12 @@ int kmain(Uint MbMagic, tMBoot_Info *MbInfo) // Load Virtual Filesystem VFS_Init(); - Log("Loading Modules..."); + Log("Loading Modules... (%i of them)", MbInfo->ModuleCount); // Load initial modules mods = (void*)( MbInfo->Modules + KERNEL_BASE ); - for(i=0;iModuleCount;i++) + Log("MbInfo = %p", MbInfo); + for( i = 0; i < MbInfo->ModuleCount; i ++ ) { // Adjust into higher half mods[i].Start += KERNEL_BASE; @@ -68,6 +69,7 @@ int kmain(Uint MbMagic, tMBoot_Info *MbInfo) { Warning("Unable to load module\n"); } + Log("Done. (MbInfo = %p)", MbInfo); } // Pass on to Independent Loader @@ -75,6 +77,7 @@ int kmain(Uint MbMagic, tMBoot_Info *MbInfo) System_Init( (char*)(MbInfo->CommandLine + KERNEL_BASE) ); // Sleep forever (sleeping beauty) - for(;;) Threads_Sleep(); + for(;;) + Threads_Sleep(); return 0; } diff --git a/Kernel/bin/elf.c b/Kernel/bin/elf.c index 4bc13b16..ad8edb0c 100644 --- a/Kernel/bin/elf.c +++ b/Kernel/bin/elf.c @@ -57,7 +57,12 @@ tBinary *Elf_Load(int fp) } // Read Program Header Table - phtab = malloc(sizeof(Elf32_Phdr)*hdr.phentcount); + phtab = malloc( sizeof(Elf32_Phdr) * hdr.phentcount ); + if( !phtab ) { + LEAVE('n'); + return NULL; + } + LOG("hdr.phoff = 0x%08x", hdr.phoff); VFS_Seek(fp, hdr.phoff, SEEK_SET); VFS_Read(fp, sizeof(Elf32_Phdr)*hdr.phentcount, phtab); @@ -88,7 +93,17 @@ tBinary *Elf_Load(int fp) for( i = 0; i < hdr.phentcount; i++ ) { int lastSize; - LOG("phtab[%i].Type = 0x%x", i, phtab[i].Type); + //LOG("phtab[%i].Type = 0x%x", i, phtab[i].Type); + LOG("phtab[%i] = {", i); + LOG(" .Type = 0x%08x", phtab[i].Type); + LOG(" .Offset = 0x%08x", phtab[i].Offset); + LOG(" .VAddr = 0x%08x", phtab[i].VAddr); + LOG(" .PAddr = 0x%08x", phtab[i].PAddr); + LOG(" .FileSize = 0x%08x", phtab[i].FileSize); + LOG(" .MemSize = 0x%08x", phtab[i].MemSize); + LOG(" .Flags = 0x%08x", phtab[i].Flags); + LOG(" .Align = 0x%08x", phtab[i].Align); + LOG(" }"); // Get Interpreter Name if( phtab[i].Type == PT_INTERP ) { diff --git a/Kernel/bin/elf.h b/Kernel/bin/elf.h index 1ff21281..13724eb3 100644 --- a/Kernel/bin/elf.h +++ b/Kernel/bin/elf.h @@ -130,9 +130,9 @@ enum { struct sElf32_Phdr { Uint32 Type; - Uint Offset; - Uint VAddr; - Uint PAddr; + Uint32 Offset; + Uint32 VAddr; + Uint32 PAddr; Uint32 FileSize; Uint32 MemSize; Uint32 Flags; diff --git a/Kernel/binary.c b/Kernel/binary.c index b02ca6e9..0cd0bf3c 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -190,7 +190,7 @@ Uint Binary_Load(char *file, Uint *entryPoint) sTruePath = VFS_GetTruePath(file); if(sTruePath == NULL) { - Warning("[BIN ] '%s' does not exist.", file); + Warning("[BIN ] '%s' does not exist.", file); LEAVE('x', 0); return 0; } diff --git a/Kernel/include/vfs_ext.h b/Kernel/include/vfs_ext.h index 2fd7fd37..e2f03447 100644 --- a/Kernel/include/vfs_ext.h +++ b/Kernel/include/vfs_ext.h @@ -8,7 +8,7 @@ // === CONSTANTS === //! Maximum size of a Memory Path generated by VFS_GetMemPath -#define VFS_MEMPATH_SIZE (3 + (BITS/8)*2) +#define VFS_MEMPATH_SIZE (3 + (BITS/4)*2) /** * \name Flags for VFS_Open * \{ diff --git a/Kernel/modules.c b/Kernel/modules.c index 5b5a906a..29a03f84 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -26,7 +26,7 @@ extern void gKernelModulesEnd; // === GLOBALS === int giNumBuiltinModules = 0; - int giModuleSpinlock = 0; +tSpinlock glModuleSpinlock; tModule *gLoadedModules = NULL; tModuleLoader *gModule_Loaders = NULL; tModule *gLoadingModules = NULL; @@ -114,31 +114,33 @@ int Module_int_Initialise(tModule *Module) ret = Module->Init(NULL); if( ret != MODULE_ERR_OK ) { - Log("[MOD ] Loading Failed, all modules that depend on this will also fail"); switch(ret) { case MODULE_ERR_MISC: - Log("[MOD ] Reason: Miscelanious"); + Warning("[MOD ] Unable to load, reason: Miscelanious"); break; case MODULE_ERR_NOTNEEDED: - Log("[MOD ] Reason: Module not needed (probably hardware not found)"); + Warning("[MOD ] Unable to load, reason: Module not needed (probably hardware not found)"); break; case MODULE_ERR_MALLOC: - Log("[MOD ] Reason: Error in malloc/realloc/calloc, probably not good"); + Warning("[MOD ] Unable to load, reason: Error in malloc/realloc/calloc, probably not good"); break; default: - Log("[MOD ] Reason - Unknown code %i", ret); + Warning("[MOD ] Unable to load reason - Unknown code %i", ret); break; } LEAVE_RET('i', ret); + return ret; } // Remove from loading list gLoadingModules = gLoadingModules->Next; // Add to loaded list + LOCK( &glModuleSpinlock ); Module->Next = gLoadedModules; gLoadedModules = Module; + RELEASE( &glModuleSpinlock ); LEAVE_RET('i', 0); } @@ -250,6 +252,13 @@ int Module_LoadFile(char *Path, char *ArgString) return 0; } + #if 1 + if( Module_int_Initialise( info ) ) + { + Binary_Unload(base); + return 0; + } + #else // Resolve Dependencies if( !Module_int_ResolveDeps(info) ) { Binary_Unload(base); @@ -271,10 +280,11 @@ int Module_LoadFile(char *Path, char *ArgString) } // Add to list - LOCK( &giModuleSpinlock ); + LOCK( &glModuleSpinlock ); info->Next = gLoadedModules; gLoadedModules = info; - RELEASE( &giModuleSpinlock ); + RELEASE( &glModuleSpinlock ); + #endif return 1; } diff --git a/Kernel/syscalls.c b/Kernel/syscalls.c index 523b3f2a..cafe7c28 100644 --- a/Kernel/syscalls.c +++ b/Kernel/syscalls.c @@ -168,7 +168,7 @@ void SyscallHandler(tSyscallRegs *Regs) if( !Syscall_ValidString(Regs->Arg1) || !Syscall_Valid(sizeof(Uint), Regs->Arg2) ) { err = -EINVAL; - ret = -1; + ret = 0; break; } // Path, *Entrypoint diff --git a/Kernel/vfs/main.c b/Kernel/vfs/main.c index c8636b16..736b5785 100644 --- a/Kernel/vfs/main.c +++ b/Kernel/vfs/main.c @@ -20,6 +20,9 @@ tVFS_Driver *VFS_GetFSByName(char *Name); int VFS_AddDriver(tVFS_Driver *Info); void VFS_UpdateDriverFile(); +// === EXPORTS === +EXPORT(VFS_AddDriver); + // === GLOBALS === tVFS_Node NULLNode = {0}; tSpinlock siDriverListLock = 0; @@ -86,6 +89,7 @@ void VFS_GetMemPath(char *Dest, void *Base, Uint Length) itoa( &Dest[1], (Uint)Base, 16, BITS/4, '0' ); Dest[BITS/4+1] = ':'; itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' ); + Dest[BITS/2+2] = '\0'; Log("VFS_GetMemPath: Dest = \"%s\"", Dest); } diff --git a/Modules/Filesystems/InitRD/GenerateInitRD.php b/Modules/Filesystems/InitRD/GenerateInitRD.php index d89d6e9c..031ad590 100644 --- a/Modules/Filesystems/InitRD/GenerateInitRD.php +++ b/Modules/Filesystems/InitRD/GenerateInitRD.php @@ -1,10 +1,15 @@ + + * Generated $lGenDate */ #include "initrd.h" -$item) { - if(is_array($item[1])) { - + if(is_array($item[1])) + { ProcessFolder("{$prefix}_{$i}", $item[1]); - echo "tInitRD_File {$prefix}_{$i}_entries[] = {\n"; + $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n"; foreach($item[1] as $j=>$child) { - if($j) echo ",\n"; - echo "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}"; + if($j) $gOutput .= ",\n"; + $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}"; } - echo "\n};\n"; + $gOutput .= "\n};\n"; $size = count($item[1]); - echo <<$child) { - if($j) echo ",\n"; - echo "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}"; + if($j) $gOutput .= ",\n"; + $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}"; } -echo "\n};\n"; -?> +$gOutput .= "\n};\n"; +$nRootFiles = count($lStack[0][1]); +$gOutput .= <<, + .Size = $nRootFiles, .ImplPtr = gInitRD_Root_Files, .ReadDir = InitRD_ReadDir, .FindDir = InitRD_FindDir }; +EOF; + +$fp = fopen($argv[2], "w"); +fputs($fp, $gOutput); +fclose($fp); +?> diff --git a/Modules/Filesystems/InitRD/Makefile b/Modules/Filesystems/InitRD/Makefile index 18dbc599..1a263019 100644 --- a/Modules/Filesystems/InitRD/Makefile +++ b/Modules/Filesystems/InitRD/Makefile @@ -6,5 +6,5 @@ NAME = FS_InitRD -include ../Makefile.tpl -files.c: - php GenerateInitRD.php files.lst > files.c +files.c: GenerateInitRD.php files.lst + php GenerateInitRD.php files.lst files.c diff --git a/Modules/Filesystems/InitRD/files.lst b/Modules/Filesystems/InitRD/files.lst index bf365273..ea7797f5 100644 --- a/Modules/Filesystems/InitRD/files.lst +++ b/Modules/Filesystems/InitRD/files.lst @@ -5,4 +5,14 @@ Dir "SBin" { Dir "Bin" { File "CLIShell" "../../../Usermode/Applications/CLIShell" File "ls" "../../../Usermode/Applications/ls" + File "cat" "../../../Usermode/Applications/cat" +} +Dir "Libs" { + File "ld-acess.so" "../../../Usermode/Libraries/ld-acess.so" + File "libacess.so" "../../../Usermode/Libraries/libacess.so" + File "libc.so.1" "../../../Usermode/Libraries/libc.so.1" + File "libgcc.so" "../../../Usermode/Libraries/libgcc.so" +} +Dir "Conf" { + File "BootConf.cfg" "../../../Usermode/Filesystem/Conf/BootConf.cfg" } diff --git a/Modules/Filesystems/InitRD/main.c b/Modules/Filesystems/InitRD/main.c index 14850587..cc54f27d 100644 --- a/Modules/Filesystems/InitRD/main.c +++ b/Modules/Filesystems/InitRD/main.c @@ -56,7 +56,7 @@ Uint64 InitRD_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buff if(Offset + Length > Node->Size) Length = Node->Size - Offset; - memcpy(Buffer, Node->ImplPtr, Length); + memcpy(Buffer, Node->ImplPtr+Offset, Length); return Length; } @@ -82,6 +82,8 @@ tVFS_Node *InitRD_FindDir(tVFS_Node *Node, char *Name) int i; tInitRD_File *dir = Node->ImplPtr; + Log("InirRD_FindDir: Name = '%s'", Name); + for( i = 0; i < Node->Size; i++ ) { if(strcmp(Name, dir[i].Name) == 0) diff --git a/Usermode/Filesystem/Conf/BootConf.cfg b/Usermode/Filesystem/Conf/BootConf.cfg index fcd6ad6f..788da485 100644 --- a/Usermode/Filesystem/Conf/BootConf.cfg +++ b/Usermode/Filesystem/Conf/BootConf.cfg @@ -1,4 +1,4 @@ -module /Acess/Modules/bochsvbe.kmd +#module /Acess/Modules/bochsvbe.kmd #module /Acess/Modules/ps2mouse #edimod /Acess/Modules/serial.edi #module /Acess/Modules/ne2000.akm diff --git a/Usermode/Libraries/ld-acess.so_src/loadlib.c b/Usermode/Libraries/ld-acess.so_src/loadlib.c index b5fb0a15..5cfa26e8 100644 --- a/Usermode/Libraries/ld-acess.so_src/loadlib.c +++ b/Usermode/Libraries/ld-acess.so_src/loadlib.c @@ -66,6 +66,10 @@ Uint LoadLibrary(char *SoName, char *SearchDir, char **envp) // Create Temp Name filename = FindLibrary(sTmpName, SoName, SearchDir); + if(filename == NULL) { + DEBUGS("LoadLibrary: RETURN 0\n"); + return 0; + } DEBUGS(" LoadLibrary: filename='%s'\n", filename); if( (iArg = IsFileLoaded(filename)) ) -- 2.20.1