SpiderScript - Light speedups, planning for smarter operation code
[tpg/acess2.git] / Kernel / binary.c
index fb31fc3..fdb4dba 100644 (file)
@@ -2,7 +2,7 @@
  * Acess2
  * Common Binary Loader
  */
-#define DEBUG  1
+#define DEBUG  0
 #include <acess.h>
 #include <binary.h>
 #include <mm_virt.h>
@@ -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);
@@ -293,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;i<Binary->NumSections;i++)
                {
                        if( Binary_int_CheckMemFree( Binary->LoadSections[i].Virtual, Binary->LoadSections[i].MemSize ) )
@@ -322,6 +326,7 @@ 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
@@ -338,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;
@@ -359,10 +364,12 @@ 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);
        
@@ -761,6 +768,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 )

UCC git Repository :: git.ucc.asn.au