AcessNative - Fixing crashes
[tpg/acess2.git] / AcessNative / acesskernel_src / syscalls.c
index 7932cca..b945df8 100644 (file)
@@ -7,6 +7,7 @@
 #define DEBUG  1
 #include <acess.h>
 #include <threads.h>
+#include <events.h>
 #include "../syscalls.h"
 
 // === IMPORTS ===
@@ -177,6 +178,11 @@ SYSCALL1(Syscall_SetGID, "i", int,
        return Threads_SetGID(a0);
 );
 
+SYSCALL0(Syscall_GetTID, return Threads_GetTID());
+SYSCALL0(Syscall_GetPID, return Threads_GetPID());
+SYSCALL0(Syscall_GetUID, return Threads_GetUID());
+SYSCALL0(Syscall_GetGID, return Threads_GetGID());
+
 SYSCALL1(Syscall_AN_Fork, "d", int *,
        if(Sizes[0] < sizeof(int))
                return -1;
@@ -184,6 +190,31 @@ SYSCALL1(Syscall_AN_Fork, "d", int *,
        return *a0;
 );
 
+SYSCALL2(Syscall_SendMessage, "id", int, void *,
+       return Proc_SendMessage(a0, Sizes[1], a1);
+);
+
+SYSCALL2(Syscall_GetMessage, "dd", uint32_t *, void *,
+       if( a0 && Sizes[0] < sizeof(*a0) ) {
+               Log_Notice("Syscalls", "Syscall_GetMessage - Arg 1 Undersize (%i < %i)",
+                       Sizes[0], sizeof(*a0));
+               return -1;
+       }
+       Uint    tmp;
+        int    rv;
+       if( a0 ) {
+               rv = Proc_GetMessage(&tmp, a1);
+               *a0 = tmp;
+       }
+       else
+               rv = Proc_GetMessage(NULL, a1);
+       return rv;
+);
+
+SYSCALL1(Syscall_WaitEvent, "i", int,
+       return Threads_WaitEvents(a0);
+);
+
 const tSyscallHandler  caSyscalls[] = {
        Syscall_Null,
        Syscall_Exit,
@@ -206,12 +237,18 @@ const tSyscallHandler     caSyscalls[] = {
        Syscall_SetUID,
        Syscall_SetGID,
        
+       Syscall_GetTID,
+       Syscall_GetPID,
+       Syscall_GetUID,
+       Syscall_GetGID,
+
        Syscall_Sleep,
        Syscall_AN_Fork,
 
-       NULL,
-       NULL,
-       Syscall_select
+       Syscall_SendMessage,
+       Syscall_GetMessage,
+       Syscall_select,
+       Syscall_WaitEvent
 };
 const int      ciNumSyscalls = sizeof(caSyscalls)/sizeof(caSyscalls[0]);
 /**
@@ -272,7 +309,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
        }
        formatString[i] = '\0';
        
-       //LOG("Request %i(%s) '%s'", Request->CallID, casSYSCALL_NAMES[Request->CallID], formatString);
+       LOG("Request %i(%s) '%s'", Request->CallID, casSYSCALL_NAMES[Request->CallID], formatString);
        
        {
                char    argListData[argListLen];
@@ -315,7 +352,13 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
                                }
                                
                                // Check for non-resident data
-                               if( Request->Params[i].Flags & ARG_FLAG_ZEROED )
+                               if( Request->Params[i].Length == 0 )
+                               {
+                                       returnData[i] = NULL;
+                                       *(void**)&argListData[argListLen] = NULL;
+                                       argListLen += sizeof(void*);
+                               }
+                               else if( Request->Params[i].Flags & ARG_FLAG_ZEROED )
                                {
                                        // Allocate and zero the buffer
                                        returnData[i] = calloc(1, Request->Params[i].Length);
@@ -367,7 +410,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
                ret->Params[retValueCount].Flags = 0;
                ret->Params[retValueCount].Length = Request->Params[i].Length;
                
-               LOG("Syscalls", "Ret %i: Type %i, Len %i",
+               LOG("Ret %i: Type %i, Len %i",
                        i, Request->Params[i].Type, Request->Params[i].Length);
                
                memcpy(inData, returnData[i], Request->Params[i].Length);

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