* Common Binary Loader\r
*/\r
#define DEBUG 0\r
-#include <common.h>\r
+#include <acess.h>\r
#include <binary.h>\r
\r
// === CONSTANTS ===\r
tBinaryType *gRegBinTypes = &gELF_Info;\r
\r
// === FUNCTIONS ===\r
+/**\r
+ * \brief Registers a binary type\r
+ */\r
+int Binary_RegisterType(tBinaryType *Type)\r
+{\r
+ Type->Next = gRegBinTypes;\r
+ gRegBinTypes = Type;\r
+ return 1;\r
+}\r
+\r
/**\r
* \fn int Proc_Spawn(char *Path)\r
*/\r
addr += base;\r
LOG("%i - 0x%x to 0x%x", i, addr, binary->Pages[i].Physical);\r
MM_Map( addr, (Uint) (binary->Pages[i].Physical) );\r
- if( binary->Pages[i].Physical & 1) // Read-Only\r
+ \r
+ // Read-Only?\r
+ if( binary->Pages[i].Flags & BIN_PAGEFLAG_RO)\r
MM_SetFlags( addr, MM_PFLAG_RO, -1 );\r
else\r
MM_SetFlags( addr, MM_PFLAG_COW, -1 );\r
+ \r
+ // Execute?\r
+ if( binary->Pages[i].Flags & BIN_PAGEFLAG_EXEC )\r
+ MM_SetFlags( addr, MM_PFLAG_EXEC, -1 );\r
+ else\r
+ MM_SetFlags( addr, MM_PFLAG_EXEC, 0 );\r
+ \r
}\r
\r
//Log("Mapped '%s' to 0x%x", binary->TruePath, base);\r
Uint dest;\r
tPAddr paddr;\r
paddr = (Uint)MM_AllocPhys();\r
+ if(paddr == 0) {\r
+ Warning("Binary_DoLoad - Physical memory allocation failed");\r
+ for( ; i--; ) {\r
+ MM_DerefPhys( pBinary->Pages[i].Physical );\r
+ }\r
+ return NULL;\r
+ }\r
MM_RefPhys( paddr ); // Make sure it is _NOT_ freed until we want it to be\r
dest = MM_MapTemp( paddr );\r
dest += pBinary->Pages[i].Virtual & 0xFFF;\r
LOG("dest = 0x%x, paddr = 0x%x", dest, paddr);\r
- LOG("Pages[%i]={Physical:0x%x,Virtual:0x%x,Size:0x%x}",\r
+ LOG("Pages[%i]={Physical:0x%llx,Virtual:%p,Size:0x%x}",\r
i, pBinary->Pages[i].Physical, pBinary->Pages[i].Virtual, pBinary->Pages[i].Size);\r
\r
// Pure Empty Page\r
if(pBinary->Pages[i].Physical == -1) {\r
LOG("%i - ZERO", i);\r
- memsetd( (void*)dest, 0, 1024 );\r
+ memsetd( (void*)dest, 0, 1024 - (pBinary->Pages[i].Virtual & 0xFFF)/4 );\r
}\r
else\r
{\r
VFS_Seek( fp, pBinary->Pages[i].Physical, 1 );\r
if(pBinary->Pages[i].Size != 0x1000) {\r
- LOG("%i - 0x%x - 0x%x bytes",\r
+ LOG("%i - 0x%llx - 0x%x bytes",\r
i, pBinary->Pages[i].Physical, pBinary->Pages[i].Size);\r
memset( (void*)dest, 0, 0x1000 -(dest&0xFFF) );\r
VFS_Read( fp, pBinary->Pages[i].Size, (void*)dest );\r
LOG("%i - 0x%x to 0x%x", i, addr, pBinary->Pages[i].Physical);\r
MM_Map( addr, (Uint) (pBinary->Pages[i].Physical) );\r
MM_SetFlags( addr, MM_PFLAG_KERNEL, MM_PFLAG_KERNEL );\r
- #if 0 // Why was this here? It's the kernel\r
- if( pBinary->Pages[i].Physical & 1) // Read-Only\r
+ \r
+ if( pBinary->Pages[i].Flags & BIN_PAGEFLAG_RO) // Read-Only?\r
MM_SetFlags( addr, MM_PFLAG_RO, MM_PFLAG_KERNEL );\r
- else\r
- MM_SetFlags( addr, MM_PFLAG_COW, MM_PFLAG_KERNEL );\r
- //MM_SetCOW( addr );\r
- #endif\r
}
\r
// Relocate Library\r
Base, ident&0xFF, ident>>8, ident>>16, ident>>24);\r
return 0;\r
}\r
+\r
+// === EXPORTS ===\r
+EXPORT(Binary_FindSymbol);\r
+EXPORT(Binary_Unload);\r