// === 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
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;
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 );
}
VFS_Close(fp);
// Add to the list
- LOCK(&glBinListLock);
+ SHORTLOCK(&glBinListLock);
pBinary->Next = glLoadedBinaries;
glLoadedBinaries = pBinary;
- RELEASE(&glBinListLock);
+ SHORTREL(&glBinListLock);
// Return
LEAVE('p', pBinary);
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;