git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Misc - Fixed all-install not setting up destination dirs/static files
[tpg/acess2.git]
/
Kernel
/
binary.c
diff --git
a/Kernel/binary.c
b/Kernel/binary.c
index
f00e851
..
76893a3
100644
(file)
--- a/
Kernel/binary.c
+++ b/
Kernel/binary.c
@@
-2,7
+2,7
@@
* Acess2
* Common Binary Loader
*/
* Acess2
* Common Binary Loader
*/
-#define DEBUG
1
+#define DEBUG
0
#include <acess.h>
#include <binary.h>
#include <mm_virt.h>
#include <acess.h>
#include <binary.h>
#include <mm_virt.h>
@@
-76,13
+76,13
@@
int Proc_Spawn(const char *Path)
strcpy(stackPath, 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};
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(;;);
}
Proc_Execve(stackPath, args, &args[1]);
for(;;);
}
@@
-106,7
+106,7
@@
int Proc_Execve(const char *File, const char **ArgV, const char **EnvP)
char **argvSaved, **envpSaved;
char *savedFile;
tVAddr entry;
char **argvSaved, **envpSaved;
char *savedFile;
tVAddr entry;
- Uint base
s[2] = {0};
// Uint because Proc_StartUser wants it
+ Uint base
;
// Uint because Proc_StartUser wants it
ENTER("sFile pArgV pEnvP", File, ArgV, EnvP);
ENTER("sFile pArgV pEnvP", File, ArgV, EnvP);
@@
-158,28
+158,32
@@
int Proc_Execve(const char *File, const char **ArgV, const char **EnvP)
MM_ClearUser();
// --- Load new binary
MM_ClearUser();
// --- Load new binary
- base
s[0]
= Binary_Load(savedFile, &entry);
+ base = Binary_Load(savedFile, &entry);
free(savedFile);
free(savedFile);
- if(base
s[0]
== 0)
+ if(base == 0)
{
{
+ free(argvSaved);
Log_Warning("Binary", "Proc_Execve - Unable to load '%s'", Threads_GetName(-1));
LEAVE('-');
Threads_Exit(0, -10);
for(;;);
}
Log_Warning("Binary", "Proc_Execve - Unable to load '%s'", Threads_GetName(-1));
LEAVE('-');
Threads_Exit(0, -10);
for(;;);
}
- LOG("entry = 0x%x, bases[0] = 0x%x", entry, bases[0]);
+ LOG("entry = 0x%x, base = 0x%x", entry, base);
+
+// MM_DumpTables(0, KERNEL_BASE);
+
LEAVE('-');
// --- And... Jump to it
LEAVE('-');
// --- And... Jump to it
- Proc_StartUser(entry, base
s, argc, argvSaved, envp
Saved, argenvBytes);
+ Proc_StartUser(entry, base
, argc, argv
Saved, argenvBytes);
for(;;); // Tell GCC that we never return
}
/**
for(;;); // Tell GCC that we never return
}
/**
- * \fn tVAddr Binary_Load(char *Path, tVAddr *EntryPoint)
* \brief Load a binary into the current address space
* \param Path Path to binary to load
* \param EntryPoint Pointer for exectuable entry point
* \brief Load a binary into the current address space
* \param Path Path to binary to load
* \param EntryPoint Pointer for exectuable entry point
+ * \return Virtual address where the binary has been loaded
*/
tVAddr Binary_Load(const char *Path, tVAddr *EntryPoint)
{
*/
tVAddr Binary_Load(const char *Path, tVAddr *EntryPoint)
{
@@
-214,6
+218,7
@@
tVAddr Binary_Load(const char *Path, tVAddr *EntryPoint)
VFS_Close(fd);
mount_id = info.mount;
inode = info.inode;
VFS_Close(fd);
mount_id = info.mount;
inode = info.inode;
+ LOG("mount_id = %i, inode = %i", mount_id, inode);
}
// TODO: Also get modifcation time?
}
// TODO: Also get modifcation time?
@@
-281,6
+286,9
@@
tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo
{
tVAddr base;
int i, fd;
{
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 ++;
// Reference Executable (Makes sure that it isn't unloaded)
Binary->ReferenceCount ++;
@@
-290,6
+298,7
@@
tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo
// Check if base is free
if(base != 0)
{
// 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 ) )
for(i=0;i<Binary->NumSections;i++)
{
if( Binary_int_CheckMemFree( Binary->LoadSections[i].Virtual, Binary->LoadSections[i].MemSize ) )
@@
-319,11
+328,13
@@
tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo
// Else decrement pointer and try again
base -= BIN_GRANUALITY;
}
// 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);
}
// Error Check
if(base < LoadMin) {
Log_Warning("Binary", "Executable '%s' cannot be loaded, no space", Path);
+ LEAVE('i', 0);
return 0;
}
return 0;
}
@@
-334,7
+345,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;
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 offset 0x%llx (%x)", i, addr, sect->Offset, sect->Flags
);
protflags = MMAP_PROT_READ;
mapflags = MMAP_MAP_FIXED;
protflags = MMAP_PROT_READ;
mapflags = MMAP_MAP_FIXED;
@@
-355,13
+366,16
@@
tVAddr Binary_MapIn(tBinary *Binary, const char *Path, tVAddr LoadMin, tVAddr Lo
protflags, MMAP_MAP_PRIVATE|mapflags,
0, 0
);
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);
}
}
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);
//LOG("*0x%x = 0x%x\n", binary->Pages[0].Virtual, *(Uint*)binary->Pages[0].Virtual);
+ LEAVE('p', base);
return base;
}
return base;
}
@@
-402,10
+416,10
@@
tBinary *Binary_DoLoad(tMount MountID, tInode Inode, const char *Path)
{
tBinary *pBinary;
int fp;
{
tBinary *pBinary;
int fp;
- Uint
ident;
+ Uint
32
ident;
tBinaryType *bt = gRegBinTypes;
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);
// Open File
fp = VFS_OpenInode(MountID, Inode, VFS_OPENFLAG_READ);
@@
-414,19
+428,26
@@
tBinary *Binary_DoLoad(tMount MountID, tInode Inode, const char *Path)
LEAVE('n');
return NULL;
}
LEAVE('n');
return NULL;
}
+
+ LOG("fp = 0x%x", fp);
// Read File Type
VFS_Read(fp, 4, &ident);
VFS_Seek(fp, 0, SEEK_SET);
// 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)
{
// Determine the type
for(; bt; bt = bt->Next)
{
- if( (ident & bt->Mask) != (Uint)bt->Ident )
+ if( (ident & bt->Mask) != (Uint
32
)bt->Ident )
continue;
continue;
+ LOG("bt = %p (%s)", bt, bt->Name);
pBinary = bt->Load(fp);
break;
}
pBinary = bt->Load(fp);
break;
}
+
+ LOG("pBinary = %p", pBinary);
// Close File
VFS_Close(fp);
// Close File
VFS_Close(fp);
@@
-756,6
+777,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);
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 )
_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