X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Fld-acess_src%2Fsyscalls.c;h=d659fe553f608a112388ccd164175ff384de8b8c;hb=3ee2be420147b69f6d8bfca559f1edab1303455b;hp=3c691aa10eb7ca3024965ac5032bfc691d82ead0;hpb=c84c6acf1e8be4fb6e76ef0f8fd275400be8d5ae;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index 3c691aa1..d659fe55 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -9,9 +9,16 @@ #include #include #include +#ifndef __WIN32__ +# include // posix_spawn +#endif #include "request.h" +#if SYSCALL_TRACE #define DEBUG(str, x...) Debug(str, x) +#else +#define DEBUG(...) do{}while(0) +#endif #define MAX_FPS 16 @@ -108,7 +115,7 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const break; // Data (special handling) case 'd': - len = va_arg(*Args, int); + len = va_arg(*Args, size_t); str = va_arg(*Args, char*); // Save the pointer for later @@ -116,7 +123,7 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const // Create parameter block Dest->Type = ARG_TYPE_DATA; - Dest->Length = len; + Dest->Length = str ? len : 0; Dest->Flags = 0; if( direction & 2 ) Dest->Flags |= ARG_FLAG_RETURN; @@ -124,7 +131,7 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const // Has data? if( direction & 1 ) { - if( DataDest ) + if( DataDest && str ) memcpy(DataDest, str, len); } else @@ -206,6 +213,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) req->ClientID = 0; //< Filled later req->CallID = SyscallID; req->NParams = paramCount; + req->MessageLength = dataLength; dataPtr = &req->Params[paramCount]; // Fill `output` and `input` @@ -253,6 +261,11 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) } // Write changes to buffers + if( req->NParams - 1 != 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 ++ ) { @@ -270,7 +283,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) free( req ); free( retPtrs ); - DEBUG(": %llx", retValue); + DEBUG(": %i 0x%llx", SyscallID, retValue); return retValue; } @@ -318,10 +331,23 @@ uint64_t native_tell(int FD) return ftell( gaSyscall_LocalFPs[FD] ); } -int native_execve(const char *filename, char *const argv[], char *const envp[]) +int native_execve(const char *filename, const char *const argv[], const char *const envp[]) { int ret; - ret = execve(filename, argv, envp); + ret = execve(filename, (void*)argv, (void*)envp); perror("native_execve"); return ret; } + +int native_spawn(const char *filename, const char *const argv[], const char *const envp[]) +{ + int rv; + + #if __WIN32__ + rv = _spawnve(_P_NOWAIT, filename, argv, envp); + #else + rv = posix_spawn(NULL, filename, NULL, NULL, (void*)argv, (void*)envp); + #endif + + return rv; +}