* Acess v0.1\r
* ELF Executable Loader Code\r
*/\r
-#define DEBUG 0\r
+#define DEBUG 1\r
#include <acess.h>\r
#include <binary.h>\r
#include "elf.h"\r
int iPageCount;\r
int count;\r
\r
- ENTER("ifp", fp);\r
+ ENTER("xfp", fp);\r
\r
// Read ELF Header\r
VFS_Read(fp, sizeof(hdr), &hdr);\r
LOG("phtab[%i] = {VAddr:0x%x,Offset:0x%x,FileSize:0x%x}",\r
i, phtab[i].VAddr, phtab[i].Offset, phtab[i].FileSize);\r
\r
- if( (phtab[i].FileSize & 0xFFF) < 0x1000 - (phtab[i].VAddr & 0xFFF) )\r
- lastSize = phtab[i].FileSize;\r
- else\r
+ //if( (phtab[i].FileSize & 0xFFF) < 0x1000 - (phtab[i].VAddr & 0xFFF) )\r
+ // lastSize = phtab[i].FileSize;\r
+ //else\r
lastSize = (phtab[i].FileSize & 0xFFF) + (phtab[i].VAddr & 0xFFF);\r
- lastSize &= 0xFFF;\r
+ //lastSize &= 0xFFF;\r
+ \r
+ //LOG("lastSize = 0x%x", lastSize);\r
\r
- LOG("lastSize = 0x%x", lastSize);\r
+ lastSize = phtab[i].FileSize;\r
\r
// Get Pages\r
count = ( (phtab[i].VAddr&0xFFF) + phtab[i].FileSize + 0xFFF) >> 12;\r
ret->Pages[j+k].Size = 4096;\r
LOG("ret->Pages[%i].Size = 0x%x", j+k, ret->Pages[j+k].Size);\r
ret->Pages[j+k].Flags = 0;\r
+ lastSize -= ret->Pages[j+k].Size;\r
}\r
count = (phtab[i].MemSize + 0xFFF) >> 12;\r
for(;k<count;k++)\r
// === 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
LOG("NumPages: %i", pBinary->NumPages);
// Read Data
- for(i=0;i<pBinary->NumPages;i++)
+ for(i = 0; i < pBinary->NumPages; i ++)
{
Uint dest;
tPAddr paddr;
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 );
}