X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Fld-acess_src%2Fsyscalls.c;h=965cc4aedd0edac99aacb0112ac8ef3b51c1c09b;hb=63895b4261593e7891a28db441a54615d0374c8b;hp=48305e3568d2c9a7707ae9a9e3da191fae49cf0e;hpb=5b5ee32779c93bf44c03d91ea6476eb9a711d231;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index 48305e35..965cc4ae 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -14,12 +14,6 @@ #endif #include "request.h" -#if SYSCALL_TRACE -#define DEBUG(str, x...) Debug(str, x) -#else -#define DEBUG(...) do{}while(0) -#endif - #define assert(cnd) do{ \ if( !(cnd) ) { \ fprintf(stderr, "%s:%i - assert failed - " #cnd"\n", __FILE__, __LINE__);\ @@ -32,6 +26,7 @@ // === Types === // === IMPORTS === +extern int gbSyscallDebugEnabled; // === GLOBALS === FILE *gaSyscall_LocalFPs[MAX_FPS]; @@ -176,7 +171,6 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) tRequestHeader *req; void *dataPtr; uint64_t retValue; - int i; // DEBUG! // printf("&tRequestHeader->Params = %i\n", offsetof(tRequestHeader, Params)); @@ -249,8 +243,11 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) exit(127); } + if( !(req->NParams >= 2) ) { + fprintf(stderr, "syscalls.c: Too few return params (%i)", req->NParams); + exit(127); + } dataPtr = (void*)&req->Params[req->NParams]; - assert(req->NParams >= 2); // return assert(req->Params[0].Type == ARG_TYPE_INT64); assert(req->Params[0].Length == sizeof(uint64_t)); @@ -269,7 +266,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) exit(127); } retCount = 0; - for( i = 2; i < req->NParams; i ++ ) + for( unsigned int i = 2; i < req->NParams; i ++ ) { #if 0 int j; @@ -286,23 +283,47 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) free( req ); free( retPtrs ); - DEBUG(": %i 0x%llx", SyscallID, retValue); + if( gbSyscallDebugEnabled ) { + SYSTRACE(": %i 0x%llx", SyscallID, retValue); + } return retValue; } +int native_int_getfd(void) +{ + for(int ret = 0; ret < MAX_FPS; ret ++ ) + if( gaSyscall_LocalFPs[ret] == NULL ) + return ret; + return -1; +} 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; + int ret = native_int_getfd(); + if(ret == -1) return -1; // TODO: Handle directories - gaSyscall_LocalFPs[ret] = fopen(&Path[4], "r+"); + gaSyscall_LocalFPs[ret] = fopen(Path, "r+"); if(!gaSyscall_LocalFPs[ret]) return -1; return ret; } +int native_shm(const char *Tag, int Flags) +{ + // int ret = native_int_getfd(); + //if(ret == -1) return -1; + //if( strcmp(Tag, "anon") == 0 ) + // path = "/AcessNative/anon/RAND"; + // FD = shm_open(path, O_RDWD); + //shm_unlink(path); + //else + // path = "/Acessnative/named/"; + // int FD = shm_open(path, O_RDWD); + //shm_unlink(path); + //gaSyscall_LocalFPs[ret] = + return -1; +} + void native_close(int FD) { fclose( gaSyscall_LocalFPs[FD] ); @@ -345,12 +366,18 @@ int native_execve(const char *filename, const char *const argv[], const char *co int native_spawn(const char *filename, const char *const argv[], const char *const envp[]) { int rv; - + + fprintf(stderr, "native_spawn('%s')\n", filename); + #if __WIN32__ rv = _spawnve(_P_NOWAIT, filename, argv, envp); #else rv = posix_spawn(NULL, filename, NULL, NULL, (void*)argv, (void*)envp); #endif + if( rv == 0 ) { + perror("native_spawn"); + } + return rv; }