X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fsyscalls.c;h=4458846372d5d2031f60c80ee6a2bbd0d6421cc6;hb=c7acbe49842c871244d76ce9dd7e4e9e70ec3a97;hp=a46927769e462648c2b83e1475702e6c4a08a08c;hpb=a41f3e5efdf853726d078dc03550de40e9d63bdd;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/syscalls.c b/AcessNative/acesskernel_src/syscalls.c index a4692776..44588463 100644 --- a/AcessNative/acesskernel_src/syscalls.c +++ b/AcessNative/acesskernel_src/syscalls.c @@ -7,10 +7,15 @@ #define DEBUG 1 #include #include +#include +#if DEBUG == 0 +# define DONT_INCLUDE_SYSCALL_NAMES +#endif #include "../syscalls.h" // === IMPORTS === extern int Threads_Fork(void); // AcessNative only function +extern int Threads_Spawn(int nFD, int FDs[], const void *info); // === TYPES === typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int *Sizes); @@ -25,7 +30,7 @@ typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int 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);\ + LOG("SYSCALL6 '%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){\ @@ -84,7 +89,7 @@ typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int } // === CODE === -int Syscall_Null(Uint*Errno, const char *Format, void *Args, int *Sizes) +int Syscall_Null(Uint *Errno, const char *Format, void *Args, int *Sizes) { return 0; } @@ -95,7 +100,9 @@ SYSCALL1(Syscall_Exit, "i", int, ); SYSCALL2(Syscall_Open, "si", const char *, int, - return VFS_Open(a0, a1|VFS_OPENFLAG_USER); + int rv = VFS_Open(a0, a1|VFS_OPENFLAG_USER); + if(rv == -1) *Errno = errno; + return rv; ); SYSCALL1(Syscall_Close, "i", int, VFS_Close(a0); @@ -106,12 +113,18 @@ SYSCALL3(Syscall_Read, "iid", int, int, void *, Log_Warning("Syscalls", "Read - %i < %i", Sizes[2], a1); return -1; } - return VFS_Read(a0, a1, a2); + size_t rv = VFS_Read(a0, a1, a2); + if(rv == -1) *Errno = errno; + return rv; ); SYSCALL3(Syscall_Write, "iid", int, int, const void *, - if( Sizes[2] < a1 ) + if( Sizes[2] < a1 ) { + *Errno = EINVAL; return -1; - return VFS_Write(a0, a1, a2); + } + size_t rv = VFS_Write(a0, a1, a2); + if(rv == -1) *Errno = errno; + return rv; ); SYSCALL3(Syscall_Seek, "iIi", int, int64_t, int, return VFS_Seek(a0, a1, a2); @@ -124,7 +137,7 @@ SYSCALL3(Syscall_IOCtl, "iid", int, int, void *, ); SYSCALL3(Syscall_FInfo, "idi", int, void *, int, if( Sizes[1] < sizeof(tFInfo)+a2*sizeof(tVFS_ACL)) { - LOG("offsetof(size) = %i", offsetof(tFInfo, size)); + //LOG("offsetof(size) = %i", offsetof(tFInfo, size)); LOG("Bad size %i < %i", Sizes[1], sizeof(tFInfo)+a2*sizeof(tVFS_ACL)); *Errno = -EINVAL; return -1; @@ -136,7 +149,7 @@ SYSCALL2(Syscall_ReadDir, "id", int, char *, return -1; return VFS_ReadDir(a0, a1); ); -SYSCALL6(Syscall_select, "iddddi", int, fd_set *, fd_set *, fd_set *, time_t *, unsigned int, +SYSCALL6(Syscall_select, "iddddi", int, fd_set *, fd_set *, fd_set *, tTime *, unsigned int, return VFS_Select(a0, a1, a2, a3, a4, a5, 0); ); SYSCALL3(Syscall_OpenChild, "isi", int, const char *, int, @@ -189,6 +202,38 @@ SYSCALL1(Syscall_AN_Fork, "d", int *, return *a0; ); +SYSCALL3(Syscall_AN_Spawn, "ddd", int *, int *, void *, + if(Sizes[0] < sizeof(int)) + return -1; + *a0 = Threads_Spawn(Sizes[1] / sizeof(int), a1, a2); + 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, Sizes[1], a1); + *a0 = tmp; + } + else + rv = Proc_GetMessage(NULL, Sizes[1], a1); + return rv; +); + +SYSCALL1(Syscall_WaitEvent, "i", int, + return Threads_WaitEvents(a0); +); + const tSyscallHandler caSyscalls[] = { Syscall_Null, Syscall_Exit, @@ -218,10 +263,12 @@ const tSyscallHandler caSyscalls[] = { Syscall_Sleep, Syscall_AN_Fork, + Syscall_AN_Spawn, - NULL, - NULL, - Syscall_select + Syscall_SendMessage, + Syscall_GetMessage, + Syscall_select, + Syscall_WaitEvent }; const int ciNumSyscalls = sizeof(caSyscalls)/sizeof(caSyscalls[0]); /** @@ -234,12 +281,15 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) int argListLen = 0; int i, retVal; tRequestHeader *ret; - int retValueCount = 1; - int retDataLen = sizeof(Uint64); + int retValueCount; + int retDataLen; void *returnData[Request->NParams]; int argSizes[Request->NParams]; Uint ret_errno = 0; + // Clear errno (Acess verson) at the start of the request + errno = 0; + // Sanity check if( Request->CallID >= ciNumSyscalls ) { Log_Notice("Syscalls", "Unknown syscall number %i", Request->CallID); @@ -250,7 +300,11 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) Log_Notice("Syscalls", "Unimplemented syscall %i", Request->CallID); return NULL; } - + + // Init return count/size + retValueCount = 2; + retDataLen = sizeof(Uint64) + sizeof(Uint32); + // Get size of argument list for( i = 0; i < Request->NParams; i ++ ) { @@ -271,18 +325,25 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) case ARG_TYPE_DATA: formatString[i] = 'd'; argListLen += sizeof(void*); + // Prepare the return values + if( Request->Params[i].Flags & ARG_FLAG_RETURN ) + { + retDataLen += Request->Params[i].Length; + retValueCount ++; + } break; case ARG_TYPE_STRING: formatString[i] = 's'; argListLen += sizeof(char*); break; default: + Log_Error("Syscalls", "Unknown param type %i", Request->Params[i].Type); return NULL; // ERROR! } } 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]; @@ -317,15 +378,14 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) // Data gets special handling, because only it can be returned to the user // (ARG_TYPE_DATA is a pointer) case ARG_TYPE_DATA: - // Prepare the return values - if( Request->Params[i].Flags & ARG_FLAG_RETURN ) + // Check for non-resident data + if( Request->Params[i].Length == 0 ) { - retDataLen += Request->Params[i].Length; - retValueCount ++; + returnData[i] = NULL; + *(void**)&argListData[argListLen] = NULL; + argListLen += sizeof(void*); } - - // Check for non-resident data - if( Request->Params[i].Flags & ARG_FLAG_ZEROED ) + else if( Request->Params[i].Flags & ARG_FLAG_ZEROED ) { // Allocate and zero the buffer returnData[i] = calloc(1, Request->Params[i].Length); @@ -347,15 +407,24 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) } } + // --- Perform request retVal = caSyscalls[Request->CallID](&ret_errno, formatString, argListData, argSizes); } + // ---------- Return + + if( ret_errno == 0 && errno != 0 ) { + ret_errno = errno; + LOG("errno = %i", errno); + } + // Allocate the return - ret = malloc(sizeof(tRequestHeader) + retValueCount * sizeof(tRequestValue) - + retDataLen); + size_t msglen = sizeof(tRequestHeader) + retValueCount * sizeof(tRequestValue) + retDataLen; + ret = malloc(msglen); ret->ClientID = Request->ClientID; ret->CallID = Request->CallID; ret->NParams = retValueCount; + ret->MessageLength = msglen; inData = (char*)&ret->Params[ ret->NParams ]; // Static Uint64 return value @@ -365,9 +434,18 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) *(Uint64*)inData = retVal; inData += sizeof(Uint64); - Log_Debug("Syscalls", "Return 0x%llx", retVal); + // Static Uint32 errno value + ret->Params[1].Type = ARG_TYPE_INT32; + ret->Params[1].Flags = 0; + ret->Params[1].Length = sizeof(Uint32); + *(Uint32*)inData = ret_errno; + inData += sizeof(Uint32); + + LOG("Ret: %llx, errno=%i", retVal, ret_errno); + + //Log_Debug("Syscalls", "Return 0x%llx", retVal); - retValueCount = 1; + retValueCount = 2; for( i = 0; i < Request->NParams; i ++ ) { if( Request->Params[i].Type != ARG_TYPE_DATA ) continue; @@ -377,7 +455,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); @@ -388,9 +466,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) retValueCount ++; } - *ReturnLength = sizeof(tRequestHeader) - + retValueCount * sizeof(tRequestValue) - + retDataLen; + *ReturnLength = ret->MessageLength; return ret; }