X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fbinary.c;h=a98e192488afd4aa2b709375e0d5b929f10ce46e;hb=1c2a87ec67d332b6a165c79398693eac1eb1166e;hp=1884af8a16521b7f7a632fc217f03f3022518669;hpb=eb80b37c619769496f3fca58d54c4a4b8d8fac4a;p=tpg%2Facess2.git diff --git a/Kernel/binary.c b/Kernel/binary.c index 1884af8a..a98e1924 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -3,15 +3,16 @@ * Common Binary Loader */ #define DEBUG 0 -#include +#include #include // === CONSTANTS === #define BIN_LOWEST MM_USER_MIN // 1MiB #define BIN_GRANUALITY 0x10000 // 64KiB +//! \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 === @@ -25,8 +26,8 @@ typedef struct sKernelBin { extern int Proc_Clone(Uint *Err, Uint Flags); extern void Threads_SetName(char *Name); extern char *Threads_GetName(int ID); +extern void Threads_Exit(int, int); extern Uint MM_ClearUser(); -extern void Threads_Exit(); extern void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize); extern tKernelSymbol gKernelSymbols[]; extern void gKernelSymbolsEnd; @@ -54,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) */ @@ -147,7 +158,7 @@ int Proc_Execve(char *File, char **ArgV, char **EnvP) if(bases[0] == 0) { Warning("Proc_Execve - Unable to load '%s'", Threads_GetName(-1)); - Threads_Exit(); + Threads_Exit(0, 0); for(;;); } @@ -316,12 +327,23 @@ 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); + //LOG("*0x%x = 0x%x\n", binary->Pages[0].Virtual, *(Uint*)binary->Pages[0].Virtual); return base; @@ -417,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 ); @@ -675,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 @@ -725,7 +750,7 @@ Uint Binary_Relocate(void *Base) } Warning("[BIN ] 0x%x is an unknown file type. (0x%x 0x%x 0x%x 0x%x)", - Base, ident&0xFF, ident>>8, ident>>16, ident>>24); + Base, ident&0xFF, (ident>>8)&0xFF, (ident>>16)&0xFF, (ident>>24)&0xFF); return 0; } @@ -801,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);