AcessNative - Fixing a couple of bugs exposed by AxWin
authorJohn Hodge <[email protected]>
Sun, 19 Feb 2012 14:31:37 +0000 (22:31 +0800)
committerJohn Hodge <[email protected]>
Sun, 19 Feb 2012 14:31:37 +0000 (22:31 +0800)
AcessNative/acesskernel_src/syscalls.c
AcessNative/ld-acess_src/Makefile
AcessNative/ld-acess_src/binary.c
AcessNative/ld-acess_src/exports.c
AcessNative/ld-acess_src/main.c
AcessNative/ld-acess_src/memory.c
AcessNative/syscalls.h

index 7932cca..a469277 100644 (file)
@@ -177,6 +177,11 @@ SYSCALL1(Syscall_SetGID, "i", int,
        return Threads_SetGID(a0);
 );
 
+SYSCALL0(Syscall_GetTID, return Threads_GetTID());
+SYSCALL0(Syscall_GetPID, return Threads_GetPID());
+SYSCALL0(Syscall_GetUID, return Threads_GetUID());
+SYSCALL0(Syscall_GetGID, return Threads_GetGID());
+
 SYSCALL1(Syscall_AN_Fork, "d", int *,
        if(Sizes[0] < sizeof(int))
                return -1;
@@ -206,6 +211,11 @@ const tSyscallHandler      caSyscalls[] = {
        Syscall_SetUID,
        Syscall_SetGID,
        
+       Syscall_GetTID,
+       Syscall_GetPID,
+       Syscall_GetUID,
+       Syscall_GetGID,
+
        Syscall_Sleep,
        Syscall_AN_Fork,
 
index 7d82132..af7f8c8 100644 (file)
@@ -14,6 +14,7 @@ ifeq ($(PLATFORM),win)
 endif
 ifeq ($(PLATFORM),lin)
        BIN := ../ld-acess
+       LINKADDR := 0x200000
 #      LD += -m elf_i386
 endif
 
@@ -46,7 +47,7 @@ obj-$(PLATFORM)/%.o: %.c
 obj-lin/link.ld:
        @mkdir -p $(dir $@)
        @echo "Making Linker Script ($@)"
-       $(LD) --verbose | awk '{ if( substr($$0,0,5) == "====="){ bPrint = !bPrint; } else { if(bPrint){ print $$0;} } }' | sed 's/\b0x[048][0-9]*\b/0x00200000/g' > $@
+       $(LD) --verbose | awk '{ if( substr($$0,0,5) == "====="){ bPrint = !bPrint; } else { if(bPrint){ print $$0;} } }' | sed 's/\b0x[048][0-9]*\b/$(LINKADDR)/g' | sed 's/CONSTANT (MAXPAGESIZE)/0x1000/g' > $@
 
 -include $(DEPFILES)
 
index e9408ef..fa2af0c 100644 (file)
@@ -252,6 +252,7 @@ int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size)
        }
 
        //printf("Binary_GetSymbol: RETURN 0, not found\n");
+       printf("--- ERROR: Unable to find symbol '%s'\n", SymbolName);
        
        return 0;
 }
index 7131e63..0c87bda 100644 (file)
@@ -112,17 +112,24 @@ int acess_readdir(int fd, char *dest) {
        return _Syscall(SYS_READDIR, ">i <d", fd, 256, dest);
 }
 
-int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, time_t *timeout)
+int acess__SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *error, time_t *timeout, uint32_t events)
 {
-       DEBUG("select(%i, %p, %p, %p, %p)", nfds, read, write, error, timeout);
-       return _Syscall(SYS_SELECT, ">i ?d ?d ?d >d", nfds,
+       DEBUG("_SysSelect(%i, %p, %p, %p, %p, 0x%x)", nfds, read, write, error, timeout, events);
+       return _Syscall(SYS_SELECT, ">i ?d ?d ?d >d >i", nfds,
                read ? (nfds+7)/8 : 0, read,
                write ? (nfds+7)/8 : 0, write,
                error ? (nfds+7)/8 : 0, error,
-               sizeof(*timeout), timeout
+               sizeof(*timeout), timeout,
+               events
                );
 }
 
+int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, time_t *timeout)
+{
+       return acess__SysSelect(nfds, read, write, error, timeout, 0);
+}
+
+
 int acess__SysOpenChild(int fd, char *name, int flags) {
        return _Syscall(SYS_OPENCHILD, ">i >s >i", fd, name, flags);
 }
@@ -236,15 +243,12 @@ int acess_waittid(int TID, int *ExitStatus)
        return _Syscall(SYS_WAITTID, ">i <d", TID, sizeof(int), &ExitStatus);
 }
 
-int acess_setuid(int ID)
-{
-       return _Syscall(SYS_SETUID, ">i", ID);
-}
-
-int acess_setgid(int ID)
-{
-       return _Syscall(SYS_SETGID, ">i", ID);
-}
+int acess_setuid(int ID) { return _Syscall(SYS_SETUID, ">i", ID); }
+int acess_setgid(int ID) { return _Syscall(SYS_SETGID, ">i", ID); }
+int acess_gettid(void) { return _Syscall(SYS_GETTID, ""); }
+int acess_getpid(void) { return _Syscall(SYS_GETPID, ""); }
+int acess_getuid(void) { return _Syscall(SYS_GETUID, ""); }
+int acess_getgid(void) { return _Syscall(SYS_GETGID, ""); }
 
 int acess_SysSendMessage(int DestTID, int Length, void *Data)
 {
@@ -301,6 +305,7 @@ const tSym  caBuiltinSymbols[] = {
        DEFSYM(_SysOpenChild),
        DEFSYM(_SysGetACL),
        DEFSYM(_SysMount),
+       DEFSYM(_SysSelect),
        
        DEFSYM(clone),
        DEFSYM(execve),
@@ -309,6 +314,7 @@ const tSym  caBuiltinSymbols[] = {
        DEFSYM(waittid),
        DEFSYM(setuid),
        DEFSYM(setgid),
+       DEFSYM(gettid),
 
        DEFSYM(SysSendMessage),
        DEFSYM(SysGetMessage),
index ae13021..80c5b7a 100644 (file)
@@ -83,7 +83,7 @@ int main(int argc, char *argv[], char **envp)
        if( !base )     return 127;
        
        printf("==============================\n");
-       printf("[DEBUG %i] %i %p ", giSyscall_ClientID, appArgc, appArgv);
+       printf("[DEBUG %i] %i ", giSyscall_ClientID, appArgc);
        for(i = 0; i < appArgc; i ++)
                printf("\"%s\" ", appArgv[i]);
        printf("\n");
index 072d326..872cb2c 100644 (file)
@@ -27,10 +27,14 @@ int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount)
                return -1;
        }
        #else
+       printf("AllocateMemory: mmap(%p, %lx, ...)\n", (void*)base, ByteCount);
        tmp = mmap((void*)base, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
        if( tmp == MAP_FAILED ) {
+               printf("ERROR: Unable to allocate memory\n");
+               perror("AllocateMemory");
                return -1;
        }
+       printf("AllocateMemory: RETURN 0\n");
        #endif
        return 0;
 }
index 0adb51f..3c7bd85 100644 (file)
@@ -52,7 +52,12 @@ enum eSyscalls {
        SYS_WAITTID,
        SYS_SETUID,
        SYS_SETGID,
-       
+
+       SYS_GETTID,
+       SYS_GETPID,
+       SYS_GETUID,
+       SYS_GETGID,
+
        // IPC
        SYS_SLEEP,
        SYS_AN_FORK,
@@ -88,6 +93,11 @@ static const char * casSYSCALL_NAMES[] = {
        "SYS_SETUID",
        "SYS_SETGID",
        
+       "SYS_GETTID",
+       "SYS_GETPID",
+       "SYS_GETUID",
+       "SYS_GETGID",
+       
        // IPC
        "SYS_SLEEP",
        "SYS_AN_FORK",

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