AcessNative - Fixes for recent userland changes, cleanups
authorJohn Hodge (sonata) <[email protected]>
Sat, 19 Jan 2013 11:40:27 +0000 (19:40 +0800)
committerJohn Hodge (sonata) <[email protected]>
Sat, 19 Jan 2013 11:40:27 +0000 (19:40 +0800)
12 files changed:
AcessNative/acesskernel_src/helpers.c
AcessNative/acesskernel_src/nativefs.c
AcessNative/acesskernel_src/syscalls.c
AcessNative/ld-acess_src/binary.c
AcessNative/ld-acess_src/common.h
AcessNative/ld-acess_src/elf_load.c
AcessNative/ld-acess_src/exports.c
AcessNative/ld-acess_src/exports.h
AcessNative/ld-acess_src/main.c
AcessNative/ld-acess_src/syscalls.c
AcessNative/syscalls.h
AcessNative/syscalls_list.h [new file with mode: 0644]

index 51b9653..6396d16 100644 (file)
@@ -144,7 +144,6 @@ int strpos(const char *str, char ch)
 {
        const char *retptr = strchr(str, ch);
        int rv = retptr ? retptr - str : -1;
-       fprintf(stderr, "strpos: str = %p'%s', retptr = %p, rv = %i\n", str, str, retptr, rv);
        return rv;
 }
 
@@ -152,7 +151,6 @@ int CheckString(const char *string)
 {
        if( (intptr_t)string < 0x1000 )
                return 0;
-       strlen(string);
        return 1;
 }
 
@@ -163,3 +161,38 @@ int CheckMem(const void *buf, size_t len)
        return 1;
 }
 
+void itoa(char *buf, Uint64 num, int base, int minLength, char pad)
+{
+       static const char cUCDIGITS[] = "0123456789ABCDEF";
+       char    tmpBuf[64+1];
+        int    pos=0, i;
+       Uint64  rem;
+
+       // Sanity check
+       if(!buf)        return;
+       
+       // Sanity Check
+       if(base > 16 || base < 2) {
+               buf[0] = 0;
+               return;
+       }
+       
+       // Convert 
+       while(num > base-1) {
+               rem = num % base;
+               num = num / base;       // Shift `num` and get remainder
+               tmpBuf[pos] = cUCDIGITS[ rem ];
+               pos++;
+       }
+       tmpBuf[pos++] = cUCDIGITS[ num ];               // Last digit of `num`
+       
+       // Put in reverse
+       i = 0;
+       minLength -= pos;
+       while(minLength-- > 0)
+               buf[i++] = pad;
+       while(pos-- > 0)
+               buf[i++] = tmpBuf[pos]; // Reverse the order of characters
+       buf[i] = 0;
+}
+
index af25e3c..cca9e7d 100644 (file)
@@ -205,8 +205,9 @@ size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *
                LEAVE('i', 0);\r
                return 0;\r
        }\r
-       LEAVE('-');\r
-       return fread( Buffer, 1, Length, (FILE *)(tVAddr)Node->Inode );\r
+       size_t ret = fread( Buffer, 1, Length, (FILE *)(tVAddr)Node->Inode );\r
+       LEAVE('x', ret);\r
+       return ret;\r
 }\r
 \r
 size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer)\r
index 827d611..4458846 100644 (file)
@@ -30,7 +30,7 @@ typedef int   (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int
        a3 = *(_t3*)Args;Args+=sizeof(_t3);\
        a4 = *(_t4*)Args;Args+=sizeof(_t4);\
        a5 = *(_t5*)Args;Args+=sizeof(_t5);\
-       LOG("SYSCALL5 '%s' %p %p %p %p %p %p", Fmt, (intptr_t)a0,(intptr_t)a1,(intptr_t)a2,(intptr_t)a3,(intptr_t)a4,(intptr_t)a5);\
+       LOG("SYSCALL6 '%s' %p %p %p %p %p %p", Fmt, (intptr_t)a0,(intptr_t)a1,(intptr_t)a2,(intptr_t)a3,(intptr_t)a4,(intptr_t)a5);\
        _call\
 }
 #define SYSCALL5(_name, _fmtstr, _t0, _t1, _t2, _t3, _t4, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
@@ -281,12 +281,15 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
         int    argListLen = 0;
         int    i, retVal;
        tRequestHeader  *ret;
-        int    retValueCount = 1;
-        int    retDataLen = sizeof(Uint64);
+        int    retValueCount;
+        int    retDataLen;
        void    *returnData[Request->NParams];
         int    argSizes[Request->NParams];
        Uint    ret_errno = 0;
        
+       // Clear errno (Acess verson) at the start of the request
+       errno = 0;
+       
        // Sanity check
        if( Request->CallID >= ciNumSyscalls ) {
                Log_Notice("Syscalls", "Unknown syscall number %i", Request->CallID);
@@ -297,7 +300,11 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
                Log_Notice("Syscalls", "Unimplemented syscall %i", Request->CallID);
                return NULL;
        }
-       
+
+       // Init return count/size
+       retValueCount = 2;
+       retDataLen = sizeof(Uint64) + sizeof(Uint32);   
+
        // Get size of argument list
        for( i = 0; i < Request->NParams; i ++ )
        {
@@ -318,12 +325,19 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
                case ARG_TYPE_DATA:
                        formatString[i] = 'd';
                        argListLen += sizeof(void*);
+                       // Prepare the return values
+                       if( Request->Params[i].Flags & ARG_FLAG_RETURN )
+                       {
+                               retDataLen += Request->Params[i].Length;
+                               retValueCount ++;
+                       }
                        break;
                case ARG_TYPE_STRING:
                        formatString[i] = 's';
                        argListLen += sizeof(char*);
                        break;
                default:
+                       Log_Error("Syscalls", "Unknown param type %i", Request->Params[i].Type);
                        return NULL;    // ERROR!
                }
        }
@@ -364,13 +378,6 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
                        // Data gets special handling, because only it can be returned to the user
                        // (ARG_TYPE_DATA is a pointer)
                        case ARG_TYPE_DATA:
-                               // Prepare the return values
-                               if( Request->Params[i].Flags & ARG_FLAG_RETURN )
-                               {
-                                       retDataLen += Request->Params[i].Length;
-                                       retValueCount ++;
-                               }
-                               
                                // Check for non-resident data
                                if( Request->Params[i].Length == 0 )
                                {
@@ -406,9 +413,9 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
        
        // ---------- Return
        
-       if( ret_errno == 0 ) {
-               perror("Syscall?");
+       if( ret_errno == 0 && errno != 0 ) {
                ret_errno = errno;
+               LOG("errno = %i", errno);
        }
        
        // Allocate the return
@@ -427,9 +434,18 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
        *(Uint64*)inData = retVal;
        inData += sizeof(Uint64);
        
+       // Static Uint32 errno value
+       ret->Params[1].Type = ARG_TYPE_INT32;
+       ret->Params[1].Flags = 0;
+       ret->Params[1].Length = sizeof(Uint32);
+       *(Uint32*)inData = ret_errno;
+       inData += sizeof(Uint32);
+
+       LOG("Ret: %llx, errno=%i", retVal, ret_errno);  
+
        //Log_Debug("Syscalls", "Return 0x%llx", retVal);
        
-       retValueCount = 1;
+       retValueCount = 2;
        for( i = 0; i < Request->NParams; i ++ )
        {
                if( Request->Params[i].Type != ARG_TYPE_DATA )  continue;
@@ -450,9 +466,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
                retValueCount ++;
        }
        
-       *ReturnLength = sizeof(tRequestHeader)
-               + retValueCount * sizeof(tRequestValue)
-               + retDataLen;
+       *ReturnLength = ret->MessageLength;
        
        return ret;
 }
index d04ac6d..59be829 100644 (file)
@@ -65,9 +65,9 @@ char *Binary_LocateLibrary(const char *Name)
                strcat(tmp, "/");
                strcat(tmp, Name);
                
-               fd = acess_open(tmp, 4);        // OPENFLAG_EXEC
+               fd = acess__SysOpen(tmp, 4);    // OPENFLAG_EXEC
                if(fd != -1) {
-                       acess_close(fd);
+                       acess__SysClose(fd);
                        return strdup(tmp);
                }
        }               
@@ -84,9 +84,9 @@ char *Binary_LocateLibrary(const char *Name)
                printf("Binary_LocateLibrary: tmp = '%s'\n", tmp);
                #endif
 
-               fd = acess_open(tmp, 4);        // OPENFLAG_EXEC
+               fd = acess__SysOpen(tmp, 4);    // OPENFLAG_EXEC
                if(fd != -1) {
-                       acess_close(fd);
+                       acess__SysClose(fd);
                        return strdup(tmp);
                }
        }               
@@ -156,22 +156,22 @@ void *Binary_Load(const char *Filename, uintptr_t *EntryPoint)
                }
        }
 
-       fd = acess_open(Filename, 2|1); // Execute and Read
+       fd = acess__SysOpen(Filename, 2|1);     // Execute and Read
        if( fd == -1 ) {
                // TODO: Handle libary directories
                perror("Opening binary");
                return NULL;
        }
 
-       acess_read(fd, &dword, 4);
-       acess_seek(fd, 0, ACESS_SEEK_SET);
+       acess__SysRead(fd, &dword, 4);
+       acess__SysSeek(fd, 0, ACESS_SEEK_SET);
        
        if( memcmp(&dword, "\x7F""ELF", 4) == 0 ) {
                fmt = &gElf_FormatDef;
        }
        else {
                fprintf(stderr, "Unknown executable format (0x%08x)\n", dword);
-               acess_close(fd);
+               acess__SysClose(fd);
                return NULL;
        }
        
@@ -179,7 +179,7 @@ void *Binary_Load(const char *Filename, uintptr_t *EntryPoint)
        printf("fmt->Load(0x%x)...\n", fd);
        #endif
        ret = fmt->Load(fd);
-       acess_close(fd);
+       acess__SysClose(fd);
        #if DEBUG
        printf("fmt->Load(0x%x): %p\n", fd, ret);
        #endif
index 376faa5..9f67e9c 100644 (file)
@@ -36,6 +36,7 @@ static inline int _SysSetMemFlags(uintptr_t Addr, unsigned int flags, unsigned i
        return 0;
 }
 
+
 extern int     AllocateMemory(uintptr_t VirtAddr, size_t ByteCount);
 extern uintptr_t       FindFreeRange(size_t ByteCount, int MaxBits);
 
index d661622..19a8c13 100644 (file)
@@ -42,7 +42,7 @@ void *Elf_Load(int FD)
        Elf64_Ehdr      hdr;\r
        \r
        // Read ELF Header\r
-       acess_read(FD, &hdr, sizeof(hdr));\r
+       acess__SysRead(FD, &hdr, sizeof(hdr));\r
        \r
        // Check the file type\r
        if(hdr.e_ident[0] != 0x7F || hdr.e_ident[1] != 'E' || hdr.e_ident[2] != 'L' || hdr.e_ident[3] != 'F') {\r
@@ -89,8 +89,8 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr)
                return NULL;\r
        }\r
        LOG("hdr.phoff = 0x%08x\n", hdr->phoff);\r
-       acess_seek(FD, hdr->phoff, ACESS_SEEK_SET);\r
-       acess_read(FD, phtab, sizeof(Elf32_Phdr) * hdr->phentcount);\r
+       acess__SysSeek(FD, hdr->phoff, ACESS_SEEK_SET);\r
+       acess__SysRead(FD, phtab, sizeof(Elf32_Phdr) * hdr->phentcount);\r
        \r
        // Count Pages\r
        iPageCount = 0;\r
@@ -146,8 +146,8 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr)
                        char *tmp;\r
                        //if(ret->Interpreter)  continue;\r
                        tmp = malloc(phtab[i].FileSize);\r
-                       acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
-                       acess_read(FD, tmp, phtab[i].FileSize);\r
+                       acess__SysSeek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
+                       acess__SysRead(FD, tmp, phtab[i].FileSize);\r
                        //ret->Interpreter = Binary_RegInterp(tmp);\r
                        LOG("Interpreter '%s'\n", tmp);\r
                        free(tmp);\r
@@ -168,8 +168,8 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr)
                        return NULL;\r
                }\r
                \r
-               acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
-               acess_read(FD, PTRMK(void, addr), phtab[i].FileSize);\r
+               acess__SysSeek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
+               acess__SysRead(FD, PTRMK(void, addr), phtab[i].FileSize);\r
                memset( PTRMK(char, addr) + phtab[i].FileSize, 0, phtab[i].MemSize - phtab[i].FileSize );\r
        }\r
        \r
@@ -211,8 +211,8 @@ void *Elf64Load(int FD, Elf64_Ehdr *hdr)
                return NULL;\r
        }\r
        LOG("hdr.phoff = 0x%08llx\n", (long long)hdr->e_phoff);\r
-       acess_seek(FD, hdr->e_phoff, ACESS_SEEK_SET);\r
-       acess_read(FD, phtab, sizeof(Elf64_Phdr) * hdr->e_phnum);\r
+       acess__SysSeek(FD, hdr->e_phoff, ACESS_SEEK_SET);\r
+       acess__SysRead(FD, phtab, sizeof(Elf64_Phdr) * hdr->e_phnum);\r
        \r
        // Count Pages\r
        iPageCount = 0;\r
@@ -270,8 +270,8 @@ void *Elf64Load(int FD, Elf64_Ehdr *hdr)
                        //if(ret->Interpreter)  continue;\r
                        tmp = malloc(phtab[i].p_filesz+1);\r
                        tmp[ phtab[i].p_filesz ] = 0;\r
-                       acess_seek(FD, phtab[i].p_offset, ACESS_SEEK_SET);\r
-                       acess_read(FD, tmp, phtab[i].p_filesz);\r
+                       acess__SysSeek(FD, phtab[i].p_offset, ACESS_SEEK_SET);\r
+                       acess__SysRead(FD, tmp, phtab[i].p_filesz);\r
                        //ret->Interpreter = Binary_RegInterp(tmp);\r
                        LOG("Interpreter '%s'\n", tmp);\r
                        free(tmp);\r
@@ -295,8 +295,8 @@ void *Elf64Load(int FD, Elf64_Ehdr *hdr)
                        return NULL;\r
                }\r
                \r
-               acess_seek(FD, phtab[i].p_offset, ACESS_SEEK_SET);\r
-               acess_read(FD, PTRMK(void, addr), phtab[i].p_filesz);\r
+               acess__SysSeek(FD, phtab[i].p_offset, ACESS_SEEK_SET);\r
+               acess__SysRead(FD, PTRMK(void, addr), phtab[i].p_filesz);\r
                memset( PTRMK(char, addr) + phtab[i].p_filesz, 0, phtab[i].p_memsz - phtab[i].p_filesz );\r
        }\r
        \r
index d7e4922..dcfc526 100644 (file)
@@ -42,12 +42,12 @@ char        *gsExecutablePath = "./ld-acess";
 
 // === CODE ===
 // --- VFS Calls
-int acess_chdir(const char *Path)
+int acess__SysChdir(const char *Path)
 {
        return _Syscall(SYS_CHDIR, ">s", Path);
 }
 
-int acess_open(const char *Path, int Flags)
+int acess__SysOpen(const char *Path, int Flags)
 {
        if( strncmp(Path, "$$$$", 4) == 0 )
        {
@@ -57,7 +57,8 @@ int acess_open(const char *Path, int Flags)
        return _Syscall(SYS_OPEN, ">s >i", Path, Flags);
 }
 
-void acess_close(int FD) {
+void acess__SysClose(int FD)
+{
        if(FD & NATIVE_FILE_MASK) {
                return native_close(FD & (NATIVE_FILE_MASK-1));
        }
@@ -65,12 +66,12 @@ void acess_close(int FD) {
        _Syscall(SYS_CLOSE, ">i", FD);
 }
 
-int acess_reopen(int FD, const char *Path, int Flags) {
+int acess__SysReopen(int FD, const char *Path, int Flags) {
        DEBUG("reopen(0x%x, \"%s\", 0x%x)", FD, Path, Flags);
        return _Syscall(SYS_REOPEN, ">i >s >i", FD, Path, Flags);
 }
 
-size_t acess_read(int FD, void *Dest, size_t Bytes) {
+size_t acess__SysRead(int FD, void *Dest, size_t Bytes) {
        if(FD & NATIVE_FILE_MASK)
                return native_read(FD & (NATIVE_FILE_MASK-1), Dest, Bytes);
 //     if( FD > 2 )
@@ -78,7 +79,7 @@ size_t acess_read(int FD, void *Dest, size_t Bytes) {
        return _Syscall(SYS_READ, ">i >i <d", FD, Bytes, Bytes, Dest);
 }
 
-size_t acess_write(int FD, const void *Src, size_t Bytes) {
+size_t acess__SysWrite(int FD, const void *Src, size_t Bytes) {
        if(FD & NATIVE_FILE_MASK)
                return native_write(FD & (NATIVE_FILE_MASK-1), Src, Bytes);
 //     if( FD > 2 )
@@ -86,7 +87,8 @@ size_t acess_write(int FD, const void *Src, size_t Bytes) {
        return _Syscall(SYS_WRITE, ">i >i >d", FD, Bytes, Bytes, Src);
 }
 
-int acess_seek(int FD, int64_t Ofs, int Dir) {
+int acess__SysSeek(int FD, int64_t Ofs, int Dir)
+{
        if(FD & NATIVE_FILE_MASK) {
                return native_seek(FD & (NATIVE_FILE_MASK-1), Ofs, Dir);
        }
@@ -94,14 +96,15 @@ int acess_seek(int FD, int64_t Ofs, int Dir) {
        return _Syscall(SYS_SEEK, ">i >I >i", FD, Ofs, Dir);
 }
 
-uint64_t acess_tell(int FD) {
+uint64_t acess__SysTell(int FD)
+{
        if(FD & NATIVE_FILE_MASK)
                return native_tell( FD & (NATIVE_FILE_MASK-1) );
        DEBUG("tell(0x%x)", FD);
        return _Syscall(SYS_TELL, ">i", FD);
 }
 
-int acess_ioctl(int fd, int id, void *data) {
+int acess__SysIOCtl(int fd, int id, void *data) {
         int    len;
        DEBUG("ioctl(%i, %i, %p)", fd, id, data);
        // NOTE: The length here is hacky and could break
@@ -111,7 +114,7 @@ int acess_ioctl(int fd, int id, void *data) {
                len = PAGE_SIZE - ((uintptr_t)data % PAGE_SIZE);
        return _Syscall(SYS_IOCTL, ">i >i ?d", fd, id, len, data);
 }
-int acess_finfo(int fd, t_sysFInfo *info, int maxacls) {
+int acess__SysFInfo(int fd, t_sysFInfo *info, int maxacls) {
 //     DEBUG("offsetof(size, t_sysFInfo) = %i", offsetof(t_sysFInfo, size));
        DEBUG("finfo(%i, %p, %i)", fd, info, maxacls);
        return _Syscall(SYS_FINFO, ">i <d >i",
@@ -121,7 +124,7 @@ int acess_finfo(int fd, t_sysFInfo *info, int maxacls) {
                );
 }
 
-int acess_SysReadDir(int fd, char *dest) {
+int acess__SysReadDir(int fd, char *dest) {
        DEBUG("SysReadDir(%i, %p)", fd, dest);
        return _Syscall(SYS_READDIR, ">i <d", fd, 256, dest);
 }
@@ -138,12 +141,6 @@ int acess__SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *error, int64
                );
 }
 
-int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, int64_t *timeout)
-{
-       return acess__SysSelect(nfds, read, write, error, timeout, 0);
-}
-
-
 int acess__SysOpenChild(int fd, char *name, int flags) {
        DEBUG("_SysOpenChild(0x%x, '%s', 0x%x)", fd, name, flags);
        return _Syscall(SYS_OPENCHILD, ">i >s >i", fd, name, flags);
@@ -176,7 +173,7 @@ uint64_t acess__SysAllocate(uintptr_t vaddr)
 }
 
 // --- Process Management ---
-int acess_clone(int flags, void *stack)
+int acess__SysClone(int flags, void *stack)
 {
        #ifdef __WIN32__
        Warning("Win32 does not support anything like fork(2), cannot emulate");
@@ -212,7 +209,7 @@ int acess_clone(int flags, void *stack)
        #endif
 }
 
-int acess_execve(char *path, char **argv, const char **envp)
+int acess__SysExecVE(char *path, char **argv, const char **envp)
 {
         int    i, argc;
        
@@ -289,13 +286,13 @@ int acess__SysSpawn(const char *binary, const char **argv, const char **envp, in
        return kernel_tid;
 }
 
-void acess_sleep(void)
-{
-       DEBUG("%s()", __func__);
-       _Syscall(SYS_SLEEP, "");
-}
+//void acess_sleep(void)
+//{
+//     DEBUG("%s()", __func__);
+//     _Syscall(SYS_SLEEP, "");
+//}
 
-int acess_waittid(int TID, int *ExitStatus)
+int acess__SysWaitTID(int TID, int *ExitStatus)
 {
        DEBUG("%s(%i, %p)", __func__, TID, ExitStatus);
        return _Syscall(SYS_WAITTID, ">i <d", TID, sizeof(int), &ExitStatus);
@@ -308,13 +305,13 @@ 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)
+int acess__SysSendMessage(int DestTID, int Length, void *Data)
 {
        DEBUG("%s(%i, 0x%x, %p)", __func__, DestTID, Length, Data);
        return _Syscall(SYS_SENDMSG, ">i >d", DestTID, Length, Data);
 }
 
-int acess_SysGetMessage(int *SourceTID, int BufLen, void *Data)
+int acess__SysGetMessage(int *SourceTID, int BufLen, void *Data)
 {
        DEBUG("%s(%p, %p)", __func__, SourceTID, Data);
        return _Syscall(SYS_GETMSG, "<d <d",
@@ -362,37 +359,36 @@ uint32_t acess__SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask)
 const tSym     caBuiltinSymbols[] = {
        DEFSYM(_exit),
        
-       DEFSYM(chdir),
-       DEFSYM(open),
-       DEFSYM(close),
-       DEFSYM(reopen),
-       DEFSYM(read),
-       DEFSYM(write),
-       DEFSYM(seek),
-       DEFSYM(tell),
-       DEFSYM(ioctl),
-       DEFSYM(finfo),
-       DEFSYM(SysReadDir),
-       DEFSYM(select),
+       DEFSYM(_SysChdir),
+       DEFSYM(_SysOpen),
        DEFSYM(_SysOpenChild),
+       DEFSYM(_SysReopen),
+       DEFSYM(_SysClose),
+       DEFSYM(_SysRead),
+       DEFSYM(_SysWrite),
+       DEFSYM(_SysSeek),
+       DEFSYM(_SysTell),
+       DEFSYM(_SysIOCtl),
+       DEFSYM(_SysFInfo),
+       DEFSYM(_SysReadDir),
        DEFSYM(_SysGetACL),
        DEFSYM(_SysMount),
        DEFSYM(_SysSelect),
        
-       DEFSYM(clone),
-       DEFSYM(execve),
+       DEFSYM(_SysClone),
+       DEFSYM(_SysExecVE),
        DEFSYM(_SysSpawn),
-       DEFSYM(sleep),
+//     DEFSYM(sleep),
        
-       DEFSYM(waittid),
+       DEFSYM(_SysWaitTID),
        DEFSYM(gettid),
        DEFSYM(setuid),
        DEFSYM(setgid),
        DEFSYM(getuid),
        DEFSYM(getgid),
 
-       DEFSYM(SysSendMessage),
-       DEFSYM(SysGetMessage),
+       DEFSYM(_SysSendMessage),
+       DEFSYM(_SysGetMessage),
        
        DEFSYM(_SysAllocate),
        DEFSYM(_SysSetMemFlags),
index dc319ac..e9a4b3b 100644 (file)
@@ -13,6 +13,8 @@
 // Syscall request (used by acess_*)
 extern uint64_t        _Syscall(int SyscallID, const char *ArgTypes, ...);
 
+extern int     acess__errno;
+
 extern int     native_open(const char *Path, int Flags);
 extern void    native_close(int FD);
 extern size_t  native_read(int FD, void *Dest, size_t Bytes);
@@ -24,10 +26,10 @@ extern int  native_execve(const char *filename, const char *const argv[], const c
 extern int     native_spawn(const char *filename, const char *const argv[], const char *const envp[]);
 
 // Syscalls used by the linker
-extern int     acess_open(const char *Path, int Flags);
-extern void    acess_close(int FD);
-extern size_t  acess_read(int FD, void *Dest, size_t Bytes);
-extern int     acess_seek(int FD, int64_t Offset, int Dir);
+extern int     acess__SysOpen(const char *Path, int Flags);
+extern void    acess__SysClose(int FD);
+extern size_t  acess__SysRead(int FD, void *Dest, size_t Bytes);
+extern int     acess__SysSeek(int FD, int64_t Offset, int Dir);
 
 // Symbol type
 typedef struct {
index 3f1cb2b..a03e963 100644 (file)
@@ -53,7 +53,7 @@ int main(int argc, char *argv[], char **envp)
                }
                
                if(strcmp(argv[i], "--open") == 0) {
-                       if( acess_open(argv[++i], 6) == -1 ) {  // Read/Write
+                       if( acess__SysOpen(argv[++i], 6) == -1 ) {      // Read/Write
                                fprintf(stderr, "Unable to open '%s'\n", argv[i]);
                                exit(1);
                        }
index d659fe5..c649f28 100644 (file)
 #define DEBUG(...)     do{}while(0)
 #endif
 
+#define assert(cnd) do{ \
+       if( !(cnd) ) { \
+               fprintf(stderr, "%s:%i - assert failed - " #cnd, __FILE__, __LINE__);\
+               exit(-1); \
+       } \
+}while(0)
+
 #define        MAX_FPS 16
 
 // === Types ===
@@ -163,7 +170,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...)
 {
        va_list args;
         int    paramCount, dataLength;
-        int    retCount = 1, retLength = sizeof(uint64_t);
+        int    retCount = 2, retLength = sizeof(uint64_t) + sizeof(uint32_t);
        void    **retPtrs;      // Pointers to return buffers
        const char      *str;
        tRequestHeader  *req;
@@ -236,38 +243,33 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...)
        }
        va_end(args);
        
-       // Send syscall request
+       // --- Send syscall request
        if( SendRequest(req, dataLength, retLength) < 0 ) {
                fprintf(stderr, "syscalls.c: SendRequest failed (SyscallID = %i)\n", SyscallID);
                exit(127);
        }
        
-       // Parse return value
-       dataPtr = &req->Params[req->NParams];
-       retValue = 0;
-       if( req->NParams >= 1 )
-       {
-               switch(req->Params[0].Type)
-               {
-               case ARG_TYPE_INT64:
-                       retValue = *(uint64_t*)dataPtr;
-                       dataPtr += req->Params[0].Length;
-                       break;
-               case ARG_TYPE_INT32:
-                       retValue = *(uint32_t*)dataPtr;
-                       dataPtr += req->Params[0].Length;
-                       break;
-               }       
-       }
+       Debug("req->NParams = %i", req->NParams);
+       assert(req->NParams >= 2);
+       // return
+       assert(req->Params[0].Type == ARG_TYPE_INT64);
+       assert(req->Params[0].Length == sizeof(uint64_t));
+       retValue = *(uint64_t*)dataPtr;
+       dataPtr += sizeof(uint64_t);
+       // errno
+       assert(req->Params[1].Type == ARG_TYPE_INT32);
+       assert(req->Params[1].Length == sizeof(uint32_t));
+       acess__errno = *(uint32_t*)dataPtr;
+       dataPtr += sizeof(uint32_t);
        
        // Write changes to buffers
-       if( req->NParams - 1 != retCount ) {
+       if( req->NParams - 2 != retCount ) {
                fprintf(stderr, "syscalls.c: Return count inbalance (%i - 1 != exp %i) [Call %i]\n",
                        req->NParams, retCount, SyscallID);
                exit(127);
        }
        retCount = 0;
-       for( i = 1; i < req->NParams; i ++ )
+       for( i = 2; i < req->NParams; i ++ )
        {
                #if 0
                 int     j;
@@ -276,6 +278,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...)
                        printf(" %02x", ((uint8_t*)dataPtr)[j]);
                printf("\n");
                #endif
+               assert( req->Params[i].Type == ARG_TYPE_DATA );
                memcpy( retPtrs[retCount++], dataPtr, req->Params[i].Length );
                dataPtr += req->Params[i].Length;
        }
index 21a9cb5..b9661bc 100644 (file)
@@ -35,84 +35,20 @@ typedef struct sRequestHeader {
        tRequestValue   Params[];
 }      tRequestHeader;
 
-enum eSyscalls {
-       SYS_NULL,
-       
-       SYS_EXIT,
-       
-       SYS_OPEN,
-       SYS_CLOSE,
-       SYS_READ,
-       SYS_WRITE,
-       SYS_SEEK,
-       SYS_TELL,
-       SYS_IOCTL,
-       SYS_FINFO,
-       SYS_READDIR,
-       SYS_OPENCHILD,
-       SYS_GETACL,
-       SYS_MOUNT,
-       SYS_REOPEN,
-       SYS_CHDIR,
-       
-       SYS_WAITTID,
-       SYS_SETUID,
-       SYS_SETGID,
-
-       SYS_GETTID,
-       SYS_GETPID,
-       SYS_GETUID,
-       SYS_GETGID,
 
-       // IPC
-       SYS_SLEEP,
-       SYS_AN_FORK,
-       SYS_AN_SPAWN,
-       SYS_SENDMSG,
-       SYS_GETMSG,
-       SYS_SELECT,
-       SYS_WAITEVENT,
-       
+enum eSyscalls {
+       #define _(n) n
+       #include "syscalls_list.h"
+       #undef _
        N_SYSCALLS
 };
 
 #ifndef DONT_INCLUDE_SYSCALL_NAMES
 static const char * casSYSCALL_NAMES[] = {
-       "SYS_NULL",
-       
-       "SYS_EXIT",
-       
-       "SYS_OPEN",
-       "SYS_CLOSE",
-       "SYS_READ",
-       "SYS_WRITE",
-       "SYS_SEEK",
-       "SYS_TELL",
-       "SYS_IOCTL",
-       "SYS_FINFO",
-       "SYS_READDIR",
-       "SYS_OPENCHILD",
-       "SYS_GETACL",
-       "SYS_MOUNT",
-       "SYS_REOPEN",
-       "SYS_CHDIR",
-       
-       "SYS_WAITTID",
-       "SYS_SETUID",
-       "SYS_SETGID",
-       
-       "SYS_GETTID",
-       "SYS_GETPID",
-       "SYS_GETUID",
-       "SYS_GETGID",
-       
-       // IPC
-       "SYS_SLEEP",
-       "SYS_AN_FORK",
-       "SYS_SENDMSG",
-       "SYS_GETMSG",
-       "SYS_SELECT",
-       "SYS_WAITEVENT"
+       #define _(n) #n
+       #include "syscalls_list.h"
+       #undef _
+       "-"
 };
 #endif
 
diff --git a/AcessNative/syscalls_list.h b/AcessNative/syscalls_list.h
new file mode 100644 (file)
index 0000000..9ab9098
--- /dev/null
@@ -0,0 +1,37 @@
+_(SYS_NULL),
+
+_(SYS_EXIT),
+
+_(SYS_OPEN),
+_(SYS_CLOSE),
+_(SYS_READ),
+_(SYS_WRITE),
+_(SYS_SEEK),
+_(SYS_TELL),
+_(SYS_IOCTL),
+_(SYS_FINFO),
+_(SYS_READDIR),
+_(SYS_OPENCHILD),
+_(SYS_GETACL),
+_(SYS_MOUNT),
+_(SYS_REOPEN),
+_(SYS_CHDIR),
+
+_(SYS_WAITTID),
+_(SYS_SETUID),
+_(SYS_SETGID),
+
+_(SYS_GETTID),
+_(SYS_GETPID),
+_(SYS_GETUID),
+_(SYS_GETGID),
+
+// IPC
+_(SYS_SLEEP),
+_(SYS_AN_FORK),
+_(SYS_AN_SPAWN),
+_(SYS_SENDMSG),
+_(SYS_GETMSG),
+_(SYS_SELECT),
+_(SYS_WAITEVENT),
+

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