3 * - Acess kernel emulation on another OS using SDL and UDP
8 #include "../syscalls.h"
11 typedef int (*tSyscallHandler)(const char *Format, void *Args);
14 #define SYSCALL3(_name, _call, _fmtstr, _t1, _t2, _t3) int _name(const char *fmt,void*args){\
15 _t1 a1;_t2 a2;_t3 a3;\
16 if(strcmp(fmt,_fmtstr)!=0)return 0;\
17 a1 = *(_t1*)args;args+=sizeof(_t1);\
18 a2 = *(_t2*)args;args+=sizeof(_t2);\
19 a3 = *(_t3*)args;args+=sizeof(_t3);\
20 return _call(a1,a2,a3);\
23 #define SYSCALL2(_name, _call, _fmtstr, _t1, _t2) int _name(const char *fmt,void*args){\
25 if(strcmp(fmt,_fmtstr)!=0)return 0;\
26 a1 = *(_t1*)args;args+=sizeof(_t1);\
27 a2 = *(_t2*)args;args+=sizeof(_t2);\
31 #define SYSCALL1V(_name, _call, _fmtstr, _t1) int _name(const char *fmt, void*args){\
33 if(strcmp(fmt,_fmtstr)!=0)return 0;\
34 a1 = *(_t1*)args;args+=sizeof(_t1);\
40 int Syscall_Null(const char *Format, void *Args)
45 SYSCALL2(Syscall_Open, VFS_Open, "di", const char *, int);
46 SYSCALL1V(Syscall_Close, VFS_Close, "i", int);
47 SYSCALL3(Syscall_Read, VFS_Read, "iid", int, int, void *);
48 SYSCALL3(Syscall_Write, VFS_Write, "iid", int, int, const void *);
51 const tSyscallHandler caSyscalls[] = {
58 const int ciNumSyscalls = sizeof(caSyscalls)/sizeof(caSyscalls[0]);
60 * \brief Recieve a syscall structure from the server code
62 tRequestHeader *SyscallRecieve(tRequestHeader *Request)
64 char formatString[Request->NParams+1];
65 char *inData = (char*)&Request->Params[Request->NParams+Request->NReturn];
69 if( Request->CallID > ciNumSyscalls ) {
73 // Get size of argument list
74 for( i = 0; i < Request->NParams; i ++ )
76 switch(Request->Params[i].Type)
79 formatString[i] = '-';
82 formatString[i] = 'i';
83 argListLen += sizeof(Uint32);
86 formatString[i] = 'I';
87 argListLen += sizeof(Uint64);
90 formatString[i] = 'd';
91 argListLen += sizeof(void*);
94 return NULL; // ERROR!
99 char argListData[argListLen];
101 // Build argument list
102 for( i = 0; i < Request->NParams; i ++ )
104 switch(Request->Params[i].Type)
109 *(Uint32*)&argListData[argListLen] = *(Uint32*)inData;
110 argListLen += sizeof(Uint32);
111 inData += sizeof(Uint32);
114 *(Uint64*)&argListData[argListLen] = *(Uint64*)inData;
115 argListLen += sizeof(Uint64);
116 inData += sizeof(Uint64);
119 case ARG_TYPE_STRING:
120 *(void**)&argListData[argListLen] = *(void**)inData;
121 argListLen += sizeof(void*);
122 inData += sizeof(void*);
127 retVal = caSyscalls[Request->CallID](formatString, argListData);