X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fbinary.c;h=8b7e7448325974ca267618cf0abbfb7a015203d9;hb=c865bd1ebd2e33f0477f3f0145acb98786b1cc41;hp=f00e8518e1966d9c395ce7befddf828d7d52f265;hpb=a29ad3fcf4e0f52348fccbeb88add8031ca7e531;p=tpg%2Facess2.git diff --git a/Kernel/binary.c b/Kernel/binary.c index f00e8518..8b7e7448 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -2,7 +2,7 @@ * Acess2 * Common Binary Loader */ -#define DEBUG 1 +#define DEBUG 0 #include #include #include @@ -76,13 +76,13 @@ int Proc_Spawn(const char *Path) strcpy(stackPath, Path); - LOG("stackPath = '%s'\n", stackPath); + LOG("stackPath = '%s'", stackPath); if(Proc_Clone(CLONE_VM) == 0) { // CHILD const char *args[2] = {stackPath, NULL}; - LOG("stackPath = '%s'\n", stackPath); + LOG("stackPath = '%s'", stackPath); Proc_Execve(stackPath, args, &args[1]); for(;;); } @@ -169,6 +169,9 @@ int Proc_Execve(const char *File, const char **ArgV, const char **EnvP) } LOG("entry = 0x%x, bases[0] = 0x%x", entry, bases[0]); + +// MM_DumpTables(0, KERNEL_BASE); + LEAVE('-'); // --- And... Jump to it Proc_StartUser(entry, bases, argc, argvSaved, envpSaved, argenvBytes); @@ -281,6 +284,9 @@ tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo { tVAddr base; int i, fd; + + ENTER("pBinary sPath pLoadMin pLoadMax", Binary, Path, LoadMin, LoadMax); + // Reference Executable (Makes sure that it isn't unloaded) Binary->ReferenceCount ++; @@ -290,6 +296,7 @@ tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo // Check if base is free if(base != 0) { + LOG("Checking base %p", base); for(i=0;iNumSections;i++) { if( Binary_int_CheckMemFree( Binary->LoadSections[i].Virtual, Binary->LoadSections[i].MemSize ) ) @@ -319,11 +326,13 @@ tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo // Else decrement pointer and try again base -= BIN_GRANUALITY; } + LOG("Allocated base %p", base); } // Error Check if(base < LoadMin) { Log_Warning("Binary", "Executable '%s' cannot be loaded, no space", Path); + LEAVE('i', 0); return 0; } @@ -334,7 +343,7 @@ tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo tBinarySection *sect = &Binary->LoadSections[i]; Uint protflags, mapflags; tVAddr addr = sect->Virtual - Binary->Base + base; - LOG("%i - 0x%x to 0x%x", i, addr, sect->Offset); + LOG("%i - %p to 0x%llx (%x)", i, addr, sect->Offset, sect->Flags); protflags = MMAP_PROT_READ; mapflags = MMAP_MAP_FIXED; @@ -355,13 +364,16 @@ tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo protflags, MMAP_MAP_PRIVATE|mapflags, 0, 0 ); +// memset((void*)(addr + sect->FileSize), 0, sect->MemSize - sect->FileSize); } } Log_Debug("Binary", "PID %i - Mapped '%s' to 0x%x", Threads_GetPID(), Path, base); + VFS_Close(fd); //LOG("*0x%x = 0x%x\n", binary->Pages[0].Virtual, *(Uint*)binary->Pages[0].Virtual); + LEAVE('p', base); return base; } @@ -402,10 +414,10 @@ tBinary *Binary_DoLoad(tMount MountID, tInode Inode, const char *Path) { tBinary *pBinary; int fp; - Uint ident; + Uint32 ident; tBinaryType *bt = gRegBinTypes; - ENTER("iMountID XInode sPath", Path); + ENTER("iMountID XInode sPath", MountID, Inode, Path); // Open File fp = VFS_OpenInode(MountID, Inode, VFS_OPENFLAG_READ); @@ -414,19 +426,26 @@ tBinary *Binary_DoLoad(tMount MountID, tInode Inode, const char *Path) LEAVE('n'); return NULL; } + + LOG("fp = 0x%x", fp); // Read File Type VFS_Read(fp, 4, &ident); VFS_Seek(fp, 0, SEEK_SET); + LOG("ident = 0x%x", ident); + // Determine the type for(; bt; bt = bt->Next) { - if( (ident & bt->Mask) != (Uint)bt->Ident ) + if( (ident & bt->Mask) != (Uint32)bt->Ident ) continue; + LOG("bt = %p (%s)", bt, bt->Name); pBinary = bt->Load(fp); break; } + + LOG("pBinary = %p", pBinary); // Close File VFS_Close(fp); @@ -756,6 +775,7 @@ Uint Binary_FindSymbol(void *Base, const char *Name, Uint *Val) int Binary_int_CheckMemFree( tVAddr _start, size_t _len ) { _len += _start & (PAGE_SIZE-1); + _len = (_len + PAGE_SIZE - 1) & ~(PAGE_SIZE-1); _start &= ~(PAGE_SIZE-1); for( ; _len > PAGE_SIZE; _len -= PAGE_SIZE, _start += PAGE_SIZE ) { if( MM_GetPhysAddr(_start) != 0 )