Kernel/VTerm - "Fix" wrapping issue in VTerm (why was old behavior there?)
[tpg/acess2.git] / AcessNative / ld-acess_src / syscalls.c
index c649f28..9822972 100644 (file)
 #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, __FILE__, __LINE__);\
+               fprintf(stderr, "%s:%i - assert failed - " #cnd"\n", __FILE__, __LINE__);\
                exit(-1); \
        } \
 }while(0)
@@ -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);
        }
        
-       Debug("req->NParams = %i", req->NParams);
-       assert(req->NParams >= 2);
+       if( !(req->NParams >= 2) ) {
+               fprintf(stderr, "syscalls.c: Too few return params (%i)", req->NParams);
+               exit(127);
+       }
+       dataPtr = (void*)&req->Params[req->NParams];
        // 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,7 +283,9 @@ 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;
 }
@@ -345,12 +344,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;
 }

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