X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fbinary.c;h=aa5d954759a9b344fa63fa1aab6379516deccbfc;hb=26e66aa0a682e2f1a5d9328b6037b5779310f8f3;hp=eb7094d2dad1679c08a61e70cc689b541d5a2979;hpb=be53e78f163ec7e0e5271d41650476bf5e1de571;p=tpg%2Facess2.git diff --git a/Kernel/binary.c b/Kernel/binary.c index eb7094d2..aa5d9547 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -10,7 +10,6 @@ // === CONSTANTS === #define BIN_LOWEST MM_USER_MIN // 1MiB #define BIN_GRANUALITY 0x10000 // 64KiB -//! \todo Move 0xBC000000 to mm_virt.h #define BIN_HIGHEST (USER_LIB_MAX-BIN_GRANUALITY) // Just below the kernel #define KLIB_LOWEST MM_MODULE_MIN #define KLIB_GRANUALITY 0x10000 // 32KiB @@ -46,11 +45,11 @@ Uint Binary_GetSymbolEx(char *Name, Uint *Value); Uint Binary_FindSymbol(void *Base, char *Name, Uint *Val); // === GLOBALS === - int glBinListLock = 0; +tShortSpinlock glBinListLock; tBinary *glLoadedBinaries = NULL; char **gsaRegInterps = NULL; int giRegInterps = 0; - int glKBinListLock = 0; +tShortSpinlock glKBinListLock; tKernelBin *glLoadedKernelLibs; tBinaryType *gRegBinTypes = &gELF_Info; @@ -122,6 +121,7 @@ int Proc_Execve(char *File, char **ArgV, char **EnvP) argenvBuf = malloc(argenvBytes); if(argenvBuf == NULL) { Log_Error("BIN", "Proc_Execve - What the hell? The kernel is out of heap space"); + LEAVE('i', 0); return 0; } strBuf = argenvBuf + (argc+1)*sizeof(void*) + (envc+1)*sizeof(void*); @@ -159,6 +159,7 @@ int Proc_Execve(char *File, char **ArgV, char **EnvP) if(bases[0] == 0) { Log_Warning("BIN", "Proc_Execve - Unable to load '%s'", Threads_GetName(-1)); + LEAVE('-'); Threads_Exit(0, 0); for(;;); } @@ -172,6 +173,9 @@ int Proc_Execve(char *File, char **ArgV, char **EnvP) /** * \fn Uint Binary_Load(char *file, Uint *entryPoint) + * \brief Load a binary into the current address space + * \param file Path to binary to load + * \param entryPoint Pointer for exectuable entry point */ Uint Binary_Load(char *file, Uint *entryPoint) { @@ -179,7 +183,7 @@ Uint Binary_Load(char *file, Uint *entryPoint) tBinary *pBinary; Uint base = -1; - ENTER("sfile", file); + ENTER("sfile pentryPoint", file, entryPoint); // Sanity Check Argument if(file == NULL) { @@ -189,6 +193,7 @@ Uint Binary_Load(char *file, Uint *entryPoint) // Get True File Path sTruePath = VFS_GetTruePath(file); + LOG("sTruePath = %p", sTruePath); if(sTruePath == NULL) { Log_Warning("BIN", "'%s' does not exist.", file); @@ -197,6 +202,8 @@ Uint Binary_Load(char *file, Uint *entryPoint) } LOG("sTruePath = '%s'", sTruePath); + + // TODO: Also get modifcation time // Check if the binary has already been loaded if( !(pBinary = Binary_GetInfo(sTruePath)) ) @@ -434,7 +441,7 @@ tBinary *Binary_DoLoad(char *truePath) LOG("NumPages: %i", pBinary->NumPages); // Read Data - for(i=0;iNumPages;i++) + for(i = 0; i < pBinary->NumPages; i ++) { Uint dest; tPAddr paddr; @@ -461,12 +468,34 @@ tBinary *Binary_DoLoad(char *truePath) else { VFS_Seek( fp, pBinary->Pages[i].Physical, 1 ); - if(pBinary->Pages[i].Size != 0x1000) { + // If the address is not aligned, or the page is not full + // sized, copy part of it + if( (dest & 0xFFF) > 0 || pBinary->Pages[i].Size < 0x1000) + { + // Validate the size to prevent Kernel page faults + // Clips to one page and prints a warning + if( pBinary->Pages[i].Size + (dest & 0xFFF) > 0x1000) { + Log_Warning("Binary", "Loader error: Page %i (%p) of '%s' is %i bytes (> 4096)", + i, pBinary->Pages[i].Virtual, truePath, + (dest&0xFFF) + pBinary->Pages[i].Size); + pBinary->Pages[i].Size = 0x1000 - (dest & 0xFFF); + } LOG("%i - 0x%llx - 0x%x bytes", i, pBinary->Pages[i].Physical, pBinary->Pages[i].Size); - memset( (void*)dest, 0, 0x1000 -(dest&0xFFF) ); + // Zero from `dest` to the end of the page + memset( (void*)dest, 0, 0x1000 - (dest&0xFFF) ); + // Read in the data VFS_Read( fp, pBinary->Pages[i].Size, (void*)dest ); - } else { + } + // Full page + else + { + // Check if the page is oversized + if(pBinary->Pages[i].Size > 0x1000) + Log_Warning("Binary", "Loader error - Page %i (%p) of '%s' is %i bytes (> 4096)", + i, pBinary->Pages[i].Virtual, truePath, + pBinary->Pages[i].Size); + // Read data LOG("%i - 0x%x", i, pBinary->Pages[i].Physical); VFS_Read( fp, 0x1000, (void*)dest ); } @@ -480,10 +509,10 @@ tBinary *Binary_DoLoad(char *truePath) VFS_Close(fp); // Add to the list - LOCK(&glBinListLock); + SHORTLOCK(&glBinListLock); pBinary->Next = glLoadedBinaries; glLoadedBinaries = pBinary; - RELEASE(&glBinListLock); + SHORTREL(&glBinListLock); // Return LEAVE('p', pBinary); @@ -724,10 +753,10 @@ void *Binary_LoadKernel(char *File) pKBinary = malloc(sizeof(*pKBinary)); pKBinary->Base = (void*)base; pKBinary->Info = pBinary; - LOCK( &glKBinListLock ); + SHORTLOCK( &glKBinListLock ); pKBinary->Next = glLoadedKernelLibs; glLoadedKernelLibs = pKBinary; - RELEASE( &glKBinListLock ); + SHORTREL( &glKBinListLock ); LEAVE('p', base); return (void*)base;