ARMv7 - Fix compiler and partial compilation
[tpg/acess2.git] / AcessNative / acesskernel_src / syscalls.c
index 4194a36..344745f 100644 (file)
 // === IMPORTS ===
 extern int     Threads_Fork(void);     // AcessNative only function
 extern int     Threads_Spawn(int nFD, int FDs[], const void *info);
+extern int     Syscall_AN_GetPath_Real(char *Dest, size_t DstLen, const char *Path);
 
 // === TYPES ===
 typedef int    (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int *Sizes);
 
 // === MACROS ===
+#define _SYSCALL_CHKFMT(_name,_fmtstr,Fmt) do{ \
+       if(strcmp(Fmt,_fmtstr) != 0) {\
+               *Errno = EINVAL;\
+               Log_Error("Syscalls", "Call %s takes args '%s', given '%s'", #_name, _fmtstr, Fmt);\
+               return -1;\
+       }\
+} while(0)
 #define SYSCALL6(_name, _fmtstr, _t0, _t1, _t2, _t3, _t4, _t5, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
        _t0 a0;_t1 a1;_t2 a2;_t3 a3;_t4 a4;_t5 a5;\
-       if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+       _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
        a0 = *(_t0*)Args;Args+=sizeof(_t0);\
        a1 = *(_t1*)Args;Args+=sizeof(_t1);\
        a2 = *(_t2*)Args;Args+=sizeof(_t2);\
@@ -35,7 +43,7 @@ typedef int   (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int
 }
 #define SYSCALL5(_name, _fmtstr, _t0, _t1, _t2, _t3, _t4, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
        _t0 a0;_t1 a1;_t2 a2;_t3 a3;_t4 a4;\
-       if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+       _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
        a0 = *(_t0*)Args;Args+=sizeof(_t0);\
        a1 = *(_t1*)Args;Args+=sizeof(_t1);\
        a2 = *(_t2*)Args;Args+=sizeof(_t2);\
@@ -46,7 +54,7 @@ typedef int   (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int
 }
 #define SYSCALL4(_name, _fmtstr, _t0, _t1, _t2, _t3, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
        _t0 a0;_t1 a1;_t2 a2;_t3 a3;\
-       if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+       _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
        a0 = *(_t0*)Args;Args+=sizeof(_t0);\
        a1 = *(_t1*)Args;Args+=sizeof(_t1);\
        a2 = *(_t2*)Args;Args+=sizeof(_t2);\
@@ -57,7 +65,7 @@ typedef int   (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int
 
 #define SYSCALL3(_name, _fmtstr, _t0, _t1, _t2, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
        _t0 a0;_t1 a1;_t2 a2;\
-       if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+       _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
        a0 = *(_t0*)Args;Args+=sizeof(_t0);\
        a1 = *(_t1*)Args;Args+=sizeof(_t1);\
        a2 = *(_t2*)Args;Args+=sizeof(_t2);\
@@ -67,7 +75,7 @@ typedef int   (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int
 
 #define SYSCALL2(_name, _fmtstr, _t0, _t1, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
        _t0 a0;_t1 a1;\
-       if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+       _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
        a0 = *(_t0*)Args;Args+=sizeof(_t0);\
        a1 = *(_t1*)Args;Args+=sizeof(_t1);\
        LOG("SYSCALL2 '%s' %p %p", Fmt, (intptr_t)a0,(intptr_t)a1);\
@@ -76,14 +84,14 @@ typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int
 
 #define SYSCALL1(_name, _fmtstr, _t0, _call) int _name(Uint*Errno,const char*Fmt, void*Args,int*Sizes){\
        _t0 a0;\
-       if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+       _SYSCALL_CHKFMT(_name,_fmtstr,Fmt);\
        a0 = *(_t0*)Args;Args+=sizeof(_t0);\
        LOG("SYSCALL1 '%s' %p", Fmt,(intptr_t)a0);\
        _call;\
 }
 
 #define SYSCALL0(_name, _call) int _name(Uint*Errno,const char*Fmt, void*Args,int*Sizes){\
-       if(strcmp(Fmt,"")!=0)return 0;\
+       _SYSCALL_CHKFMT(_name,"",Fmt);\
        LOG("SYSCALL0");\
        _call;\
 }
@@ -167,6 +175,11 @@ SYSCALL4(Syscall_Mount, "ssss", const char *, const char *, const char *, const
 SYSCALL1(Syscall_Chdir, "s", const char *,
        return VFS_ChDir(a0);
 );
+
+SYSCALL2(Syscall_AN_Getpath, "ds", char *, const char *,
+       return Syscall_AN_GetPath_Real(a0, Sizes[0], a1);
+);
+
 SYSCALL0(Syscall_Sleep,
        Threads_Sleep();
        return 0;
@@ -254,6 +267,7 @@ const tSyscallHandler       caSyscalls[] = {
        [SYS_MOUNT]     = Syscall_Mount,
        [SYS_REOPEN]    = NULL, // SYS_REOPEN
        [SYS_CHDIR]     = Syscall_Chdir,
+       [SYS_AN_GETPATH] = Syscall_AN_Getpath,
        
        [SYS_WAITTID]   = Syscall_WaitTID,
        [SYS_SETUID]    = Syscall_SetUID,
@@ -265,8 +279,8 @@ const tSyscallHandler       caSyscalls[] = {
        Syscall_GetGID,
 
        Syscall_Sleep,
-       Syscall_AN_Fork,
-       Syscall_AN_Spawn,
+       [SYS_AN_FORK]  = Syscall_AN_Fork,
+       [SYS_AN_SPAWN] = Syscall_AN_Spawn,
 
        Syscall_SendMessage,
        Syscall_GetMessage,
@@ -277,12 +291,12 @@ const int ciNumSyscalls = sizeof(caSyscalls)/sizeof(caSyscalls[0]);
 /**
  * \brief Recieve a syscall structure from the server code
  */
-tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
+tRequestHeader *SyscallRecieve(tRequestHeader *Request, size_t *ReturnLength)
 {
        char    formatString[Request->NParams+1];
        char    *inData = (char*)&Request->Params[Request->NParams];
         int    argListLen = 0;
-        int    i, retVal;
+        int    retVal;
        tRequestHeader  *ret;
         int    retValueCount;
         int    retDataLen;
@@ -309,7 +323,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
        retDataLen = sizeof(Uint64) + sizeof(Uint32);   
 
        // Get size of argument list
-       for( i = 0; i < Request->NParams; i ++ )
+       for( int i = 0; i < Request->NParams; i ++ )
        {
                argSizes[i] = Request->Params[i].Length;
                switch(Request->Params[i].Type)
@@ -344,7 +358,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
                        return NULL;    // ERROR!
                }
        }
-       formatString[i] = '\0';
+       formatString[Request->NParams] = '\0';
        
        LOG("Request %i(%s) '%s'", Request->CallID, casSYSCALL_NAMES[Request->CallID], formatString);
        
@@ -352,7 +366,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
                char    argListData[argListLen];
                argListLen = 0;
                // Build argument list
-               for( i = 0; i < Request->NParams; i ++ )
+               for( int i = 0; i < Request->NParams; i ++ )
                {
                        returnData[i] = NULL;
                        switch(Request->Params[i].Type)
@@ -449,7 +463,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength)
        //Log_Debug("Syscalls", "Return 0x%llx", retVal);
        
        retValueCount = 2;
-       for( i = 0; i < Request->NParams; i ++ )
+       for( int i = 0; i < Request->NParams; i ++ )
        {
                if( Request->Params[i].Type != ARG_TYPE_DATA )  continue;
                if( !(Request->Params[i].Flags & ARG_FLAG_RETURN) )     continue;

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