X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fsyscalls.c;h=9b9fda4280af62a355d83979fe7042a5368bf975;hb=a4b09792dd93b75b022f5f6dfcfe632baf8fdee2;hp=84eb416fd7f99e50e77c00f725b86b494e3ae413;hpb=a4d8188f730bcc25cd4a6f4799ac7d65eb707cf2;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/syscalls.c b/AcessNative/acesskernel_src/syscalls.c index 84eb416f..9b9fda42 100644 --- a/AcessNative/acesskernel_src/syscalls.c +++ b/AcessNative/acesskernel_src/syscalls.c @@ -4,9 +4,10 @@ * * Syscall Distribution */ -#define DEBUG 1 +#define DEBUG 0 #include #include +#include #include "../syscalls.h" // === IMPORTS === @@ -16,6 +17,18 @@ extern int Threads_Fork(void); // AcessNative only function typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int *Sizes); // === MACROS === +#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;\ + a0 = *(_t0*)Args;Args+=sizeof(_t0);\ + a1 = *(_t1*)Args;Args+=sizeof(_t1);\ + a2 = *(_t2*)Args;Args+=sizeof(_t2);\ + a3 = *(_t3*)Args;Args+=sizeof(_t3);\ + a4 = *(_t4*)Args;Args+=sizeof(_t4);\ + a5 = *(_t5*)Args;Args+=sizeof(_t5);\ + LOG("SYSCALL5 '%s' %p %p %p %p %p %p", Fmt, (intptr_t)a0,(intptr_t)a1,(intptr_t)a2,(intptr_t)a3,(intptr_t)a4,(intptr_t)a5);\ + _call\ +} #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;\ @@ -124,8 +137,8 @@ SYSCALL2(Syscall_ReadDir, "id", int, char *, return -1; return VFS_ReadDir(a0, a1); ); -SYSCALL5(Syscall_select, "idddd", int, fd_set *, fd_set *, fd_set *, time_t *, - return VFS_Select(a0, a1, a2, a3, a4, 0); +SYSCALL6(Syscall_select, "iddddi", int, fd_set *, fd_set *, fd_set *, time_t *, unsigned int, + return VFS_Select(a0, a1, a2, a3, a4, a5, 0); ); SYSCALL3(Syscall_OpenChild, "isi", int, const char *, int, return VFS_OpenChild(a0, a1, a2|VFS_OPENFLAG_USER); @@ -155,23 +168,53 @@ SYSCALL1(Syscall_SetUID, "i", int, *Errno = -EINVAL; // TODO: Better message return -1; } - return Threads_SetUID(Errno, a0); + return Threads_SetUID(a0); ); SYSCALL1(Syscall_SetGID, "i", int, if(Sizes[0] < sizeof(int)) { *Errno = -EINVAL; // TODO: Better message return -1; } - return Threads_SetGID(Errno, a0); + return Threads_SetGID(a0); ); -SYSCALL1(Syscall_Fork, "d", int *, +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; *a0 = Threads_Fork(); 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, @@ -194,12 +237,18 @@ const tSyscallHandler caSyscalls[] = { Syscall_SetUID, Syscall_SetGID, + Syscall_GetTID, + Syscall_GetPID, + Syscall_GetUID, + Syscall_GetGID, + Syscall_Sleep, - Syscall_Fork, + Syscall_AN_Fork, - NULL, - NULL, - Syscall_select + Syscall_SendMessage, + Syscall_GetMessage, + Syscall_select, + Syscall_WaitEvent }; const int ciNumSyscalls = sizeof(caSyscalls)/sizeof(caSyscalls[0]); /** @@ -274,19 +323,19 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) case ARG_TYPE_VOID: break; case ARG_TYPE_INT32: - LOG("%i INT32: 0x%x", i, *(Uint32*)inData); + //LOG("%i INT32: 0x%x", i, *(Uint32*)inData); *(Uint32*)&argListData[argListLen] = *(Uint32*)inData; argListLen += sizeof(Uint32); inData += sizeof(Uint32); break; case ARG_TYPE_INT64: - LOG("%i INT64: 0x%llx", i, *(Uint64*)inData); + //LOG("%i INT64: 0x%llx", i, *(Uint64*)inData); *(Uint64*)&argListData[argListLen] = *(Uint64*)inData; argListLen += sizeof(Uint64); inData += sizeof(Uint64); break; case ARG_TYPE_STRING: - LOG("%i STR: '%s'", i, (char*)inData); + //LOG("%i STR: '%s'", i, (char*)inData); *(char**)&argListData[argListLen] = (char*)inData; argListLen += sizeof(void*); inData += Request->Params[i].Length; @@ -303,20 +352,26 @@ 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); - LOG("%i ZDAT: %i %p", i, - Request->Params[i].Length, returnData[i]); + //LOG("%i ZDAT: %i %p", i, + // Request->Params[i].Length, returnData[i]); *(void**)&argListData[argListLen] = returnData[i]; argListLen += sizeof(void*); } else { returnData[i] = (void*)inData; - LOG("%i DATA: %i %p", i, - Request->Params[i].Length, returnData[i]); + //LOG("%i DATA: %i %p", i, + // Request->Params[i].Length, returnData[i]); *(void**)&argListData[argListLen] = (void*)inData; argListLen += sizeof(void*); inData += Request->Params[i].Length; @@ -355,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);