X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fbinary.c;h=a98e192488afd4aa2b709375e0d5b929f10ce46e;hb=1c2a87ec67d332b6a165c79398693eac1eb1166e;hp=43d8cb35e33db0669cf3c4918f38fa7939df1ce5;hpb=47e9dfd89189fc6b150bd6b20229cb047c7e0858;p=tpg%2Facess2.git diff --git a/Kernel/binary.c b/Kernel/binary.c index 43d8cb35..a98e1924 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -3,7 +3,7 @@ * Common Binary Loader */ #define DEBUG 0 -#include +#include #include // === CONSTANTS === @@ -12,7 +12,7 @@ //! \todo Move 0xBC000000 to mm_virt.h #define BIN_HIGHEST (0xBC000000-BIN_GRANUALITY) // Just below the kernel #define KLIB_LOWEST MM_MODULE_MIN -#define KLIB_GRANUALITY 0x8000 // 32KiB +#define KLIB_GRANUALITY 0x10000 // 32KiB #define KLIB_HIGHEST (MM_MODULE_MAX-KLIB_GRANUALITY) // === TYPES === @@ -55,6 +55,16 @@ tKernelBin *glLoadedKernelLibs; tBinaryType *gRegBinTypes = &gELF_Info; // === FUNCTIONS === +/** + * \brief Registers a binary type + */ +int Binary_RegisterType(tBinaryType *Type) +{ + Type->Next = gRegBinTypes; + gRegBinTypes = Type; + return 1; +} + /** * \fn int Proc_Spawn(char *Path) */ @@ -317,10 +327,19 @@ Uint Binary_MapIn(tBinary *binary) addr += base; LOG("%i - 0x%x to 0x%x", i, addr, binary->Pages[i].Physical); MM_Map( addr, (Uint) (binary->Pages[i].Physical) ); - if( binary->Pages[i].Physical & 1) // Read-Only + + // Read-Only? + if( binary->Pages[i].Flags & BIN_PAGEFLAG_RO) MM_SetFlags( addr, MM_PFLAG_RO, -1 ); else MM_SetFlags( addr, MM_PFLAG_COW, -1 ); + + // Execute? + if( binary->Pages[i].Flags & BIN_PAGEFLAG_EXEC ) + MM_SetFlags( addr, MM_PFLAG_EXEC, -1 ); + else + MM_SetFlags( addr, MM_PFLAG_EXEC, 0 ); + } //Log("Mapped '%s' to 0x%x", binary->TruePath, base); @@ -420,23 +439,30 @@ tBinary *Binary_DoLoad(char *truePath) Uint dest; tPAddr paddr; paddr = (Uint)MM_AllocPhys(); + if(paddr == 0) { + Warning("Binary_DoLoad - Physical memory allocation failed"); + for( ; i--; ) { + MM_DerefPhys( pBinary->Pages[i].Physical ); + } + return NULL; + } MM_RefPhys( paddr ); // Make sure it is _NOT_ freed until we want it to be dest = MM_MapTemp( paddr ); dest += pBinary->Pages[i].Virtual & 0xFFF; LOG("dest = 0x%x, paddr = 0x%x", dest, paddr); - LOG("Pages[%i]={Physical:0x%x,Virtual:0x%x,Size:0x%x}", + LOG("Pages[%i]={Physical:0x%llx,Virtual:%p,Size:0x%x}", i, pBinary->Pages[i].Physical, pBinary->Pages[i].Virtual, pBinary->Pages[i].Size); // Pure Empty Page if(pBinary->Pages[i].Physical == -1) { LOG("%i - ZERO", i); - memsetd( (void*)dest, 0, 1024 ); + memsetd( (void*)dest, 0, 1024 - (pBinary->Pages[i].Virtual & 0xFFF)/4 ); } else { VFS_Seek( fp, pBinary->Pages[i].Physical, 1 ); if(pBinary->Pages[i].Size != 0x1000) { - LOG("%i - 0x%x - 0x%x bytes", + LOG("%i - 0x%llx - 0x%x bytes", i, pBinary->Pages[i].Physical, pBinary->Pages[i].Size); memset( (void*)dest, 0, 0x1000 -(dest&0xFFF) ); VFS_Read( fp, pBinary->Pages[i].Size, (void*)dest ); @@ -678,13 +704,9 @@ void *Binary_LoadKernel(char *file) LOG("%i - 0x%x to 0x%x", i, addr, pBinary->Pages[i].Physical); MM_Map( addr, (Uint) (pBinary->Pages[i].Physical) ); MM_SetFlags( addr, MM_PFLAG_KERNEL, MM_PFLAG_KERNEL ); - #if 0 // Why was this here? It's the kernel - if( pBinary->Pages[i].Physical & 1) // Read-Only + + if( pBinary->Pages[i].Flags & BIN_PAGEFLAG_RO) // Read-Only? MM_SetFlags( addr, MM_PFLAG_RO, MM_PFLAG_KERNEL ); - else - MM_SetFlags( addr, MM_PFLAG_COW, MM_PFLAG_KERNEL ); - //MM_SetCOW( addr ); - #endif } // Relocate Library @@ -804,3 +826,7 @@ Uint Binary_FindSymbol(void *Base, char *Name, Uint *val) Base, ident&0xFF, ident>>8, ident>>16, ident>>24); return 0; } + +// === EXPORTS === +EXPORT(Binary_FindSymbol); +EXPORT(Binary_Unload);