X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Fld-acess_src%2Fsyscalls.c;h=3c691aa10eb7ca3024965ac5032bfc691d82ead0;hb=695800da5d26cd12d5dfa0a93d0ef1eed0533c78;hp=ff299973e320a871d0c2e8bd1fe0218e51257d78;hpb=9ed2477f5f7e5b01501368719e93259aa336932f;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index ff299973..3c691aa1 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -1,19 +1,27 @@ /* */ -#include "../../Usermode/include/acess/sys.h" +#define DONT_INCLUDE_SYSCALL_NAMES 1 #include "common.h" #include #include #include #include #include +#include +#include #include "request.h" -#include "../syscalls.h" + +#define DEBUG(str, x...) Debug(str, x) + +#define MAX_FPS 16 // === Types === // === IMPORTS === +// === GLOBALS === +FILE *gaSyscall_LocalFPs[MAX_FPS]; + // === CODE === const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const char *ArgTypes, va_list *Args) { @@ -22,11 +30,13 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const int direction = 0; // 0: Invalid, 1: Out, 2: In, 3: Out char *str; int len; - + // Eat whitespace while(*ArgTypes && *ArgTypes == ' ') ArgTypes ++; if( *ArgTypes == '\0' ) return ArgTypes; +// DEBUG("ArgTypes = '%s'", ArgTypes); + // Get direction switch(*ArgTypes) { @@ -48,12 +58,11 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const case 'i': if( direction != 1 ) { - fprintf(stderr, "ReadEntry: Recieving an integer is not defined\n"); + Warning("ReadEntry: Recieving an integer is not defined"); return NULL; } val32 = va_arg(*Args, uint32_t); - printf("val32 = 0x%x\n", val32); Dest->Type = ARG_TYPE_INT32; Dest->Length = sizeof(uint32_t); @@ -71,7 +80,6 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const } val64 = va_arg(*Args, uint64_t); - printf("val64 = 0x%llx\n", val64); Dest->Type = ARG_TYPE_INT64; Dest->Length = sizeof(uint64_t); @@ -88,7 +96,6 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const } str = va_arg(*Args, char*); - printf("str = %p '%s'\n", str, str); Dest->Type = ARG_TYPE_STRING; Dest->Length = strlen(str) + 1; @@ -104,8 +111,6 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const len = va_arg(*Args, int); str = va_arg(*Args, char*); - printf("len = %i, str = %p\n", len, str); - // Save the pointer for later if( PtrDest ) *PtrDest = str; @@ -159,6 +164,11 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) uint64_t retValue; int i; + // DEBUG! +// printf("&tRequestHeader->Params = %i\n", offsetof(tRequestHeader, Params)); +// printf("&tRequestValue->Flags = %i\n", offsetof(tRequestValue, Flags)); +// printf("&tRequestValue->Length = %i\n", offsetof(tRequestValue, Length)); + // Get data size va_start(args, ArgTypes); str = ArgTypes; @@ -219,7 +229,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) va_end(args); // Send syscall request - if( SendRequest(req, dataLength) < 0 ) { + if( SendRequest(req, dataLength, retLength) < 0 ) { fprintf(stderr, "syscalls.c: SendRequest failed (SyscallID = %i)\n", SyscallID); exit(127); } @@ -227,7 +237,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) // Parse return value dataPtr = &req->Params[req->NParams]; retValue = 0; - if( req->NParams > 1 ) + if( req->NParams >= 1 ) { switch(req->Params[0].Type) { @@ -243,98 +253,75 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) } // Write changes to buffers - va_start(args, ArgTypes); + retCount = 0; for( i = 1; i < req->NParams; i ++ ) { - memcpy( retPtrs[i-1], dataPtr, req->Params[i].Length ); + #if 0 + int j; + printf("Return Data %i: (%i)", i, req->Params[i].Length); + for( j = 0; j < req->Params[i].Length; j ++ ) + printf(" %02x", ((uint8_t*)dataPtr)[j]); + printf("\n"); + #endif + memcpy( retPtrs[retCount++], dataPtr, req->Params[i].Length ); dataPtr += req->Params[i].Length; } - va_end(args); free( req ); + free( retPtrs ); - return 0; -} - -// --- VFS Calls -int open(const char *Path, int Flags) { - return _Syscall(SYS_OPEN, ">s >i", Path, Flags); -} - -void close(int FD) { - _Syscall(SYS_CLOSE, ">i", FD); -} - -size_t read(int FD, size_t Bytes, void *Dest) { - return _Syscall(SYS_READ, "i >i i >i >d", FD, Bytes, Bytes, Src); + DEBUG(": %llx", retValue); + + return retValue; } -int seek(int FD, int64_t Ofs, int Dir) { - return _Syscall(SYS_SEEK, ">i >I >i", FD, Ofs, Dir); -} -uint64_t tell(int FD) { - return _Syscall(SYS_TELL, ">i", FD); +int native_open(const char *Path, int Flags) +{ + int ret; + for(ret = 0; ret < MAX_FPS && gaSyscall_LocalFPs[ret]; ret ++ ) ; + if(ret == MAX_FPS) return -1; + // TODO: Handle directories + gaSyscall_LocalFPs[ret] = fopen(&Path[4], "r+"); + if(!gaSyscall_LocalFPs[ret]) return -1; + return ret; } -int ioctl(int fd, int id, void *data) { - // NOTE: 1024 byte size is a hack - return _Syscall(SYS_IOCTL, ">i >i ?d", fd, id, 1024, data); -} -int finfo(int fd, t_sysFInfo *info, int maxacls) { - return _Syscall(SYS_FINFO, ">i i", - fd, - sizeof(t_sysFInfo)+maxacls*sizeof(t_sysACL), info, - maxacls); +void native_close(int FD) +{ + fclose( gaSyscall_LocalFPs[FD] ); + gaSyscall_LocalFPs[FD] = NULL; } -int readdir(int fd, char *dest) { - return _Syscall(SYS_READDIR, ">i i >s >i", fd, name, flags); +size_t native_write(int FD, const void *Src, size_t Bytes) +{ + return fwrite( Src, Bytes, 1, gaSyscall_LocalFPs[FD] ); } -int _SysGetACL(int fd, t_sysACL *dest) { - return _Syscall(SYS_GETACL, "i 0) + return fseek( gaSyscall_LocalFPs[FD], Ofs, SEEK_SET ); + else + return fseek( gaSyscall_LocalFPs[FD], Ofs, SEEK_END ); } -int _SysMount(const char *Device, const char *Directory, const char *Type, const char *Options) { - return _Syscall(SYS_MOUNT, ">s >s >s >s", Device, Directory, Type, Options); +uint64_t native_tell(int FD) +{ + return ftell( gaSyscall_LocalFPs[FD] ); } - -// --- Error Handler -int _SysSetFaultHandler(int (*Handler)(int)) { - return 0; +int native_execve(const char *filename, char *const argv[], char *const envp[]) +{ + int ret; + ret = execve(filename, argv, envp); + perror("native_execve"); + return ret; } - - -// === Symbol List === -#define DEFSYM(name) {#name, name} -const tSym caBuiltinSymbols[] = { - {"_exit", exit}, - - DEFSYM(open), - DEFSYM(close), - DEFSYM(read), - DEFSYM(write), - DEFSYM(seek), - DEFSYM(tell), - DEFSYM(ioctl), - DEFSYM(finfo), - DEFSYM(readdir), - DEFSYM(_SysOpenChild), - DEFSYM(_SysGetACL), - DEFSYM(_SysMount), - - {"_SysSetFaultHandler", _SysSetFaultHandler} -}; - -const int ciNumBuiltinSymbols = sizeof(caBuiltinSymbols)/sizeof(caBuiltinSymbols[0]); -