X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fsyscalls.c;h=84eb416fd7f99e50e77c00f725b86b494e3ae413;hb=015bc57d9df5f9d073950a4cdfd1100c3ce6f954;hp=f48b1a98ae3921115bc34a3f2d6ca3b4943e38ee;hpb=3764c294f21229bdf700f436fa4884f5e76e0d3a;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/syscalls.c b/AcessNative/acesskernel_src/syscalls.c index f48b1a98..84eb416f 100644 --- a/AcessNative/acesskernel_src/syscalls.c +++ b/AcessNative/acesskernel_src/syscalls.c @@ -4,6 +4,7 @@ * * Syscall Distribution */ +#define DEBUG 1 #include #include #include "../syscalls.h" @@ -15,6 +16,17 @@ extern int Threads_Fork(void); // AcessNative only function typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int *Sizes); // === MACROS === +#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;\ + 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);\ + LOG("SYSCALL5 '%s' %p %p %p %p %p", Fmt, (intptr_t)a0,(intptr_t)a1,(intptr_t)a2,(intptr_t)a3,(intptr_t)a4);\ + _call\ +} #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;\ @@ -22,6 +34,7 @@ typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int a1 = *(_t1*)Args;Args+=sizeof(_t1);\ a2 = *(_t2*)Args;Args+=sizeof(_t2);\ a3 = *(_t3*)Args;Args+=sizeof(_t3);\ + LOG("SYSCALL4 '%s' %p %p %p %p", Fmt, (intptr_t)a0,(intptr_t)a1,(intptr_t)a2,(intptr_t)a3);\ _call\ } @@ -31,6 +44,7 @@ typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int a0 = *(_t0*)Args;Args+=sizeof(_t0);\ a1 = *(_t1*)Args;Args+=sizeof(_t1);\ a2 = *(_t2*)Args;Args+=sizeof(_t2);\ + LOG("SYSCALL3 '%s' %p %p %p", Fmt, (intptr_t)a0,(intptr_t)a1,(intptr_t)a2);\ _call\ } @@ -39,6 +53,7 @@ typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int if(strcmp(Fmt,_fmtstr)!=0)return 0;\ a0 = *(_t0*)Args;Args+=sizeof(_t0);\ a1 = *(_t1*)Args;Args+=sizeof(_t1);\ + LOG("SYSCALL2 '%s' %p %p", Fmt, (intptr_t)a0,(intptr_t)a1);\ _call;\ } @@ -46,11 +61,13 @@ typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int _t0 a0;\ if(strcmp(Fmt,_fmtstr)!=0)return 0;\ 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;\ + LOG("SYSCALL0");\ _call;\ } @@ -73,8 +90,10 @@ SYSCALL1(Syscall_Close, "i", int, return 0; ); SYSCALL3(Syscall_Read, "iid", int, int, void *, - if( Sizes[2] < a1 ) + if( Sizes[2] < a1 ) { + Log_Warning("Syscalls", "Read - %i < %i", Sizes[2], a1); return -1; + } return VFS_Read(a0, a1, a2); ); SYSCALL3(Syscall_Write, "iid", int, int, const void *, @@ -92,8 +111,12 @@ SYSCALL3(Syscall_IOCtl, "iid", int, int, void *, return VFS_IOCtl(a0, a1, a2); ); SYSCALL3(Syscall_FInfo, "idi", int, void *, int, - if( Sizes[1] < sizeof(tFInfo)+a2*sizeof(tVFS_ACL)) + if( Sizes[1] < sizeof(tFInfo)+a2*sizeof(tVFS_ACL)) { + LOG("offsetof(size) = %i", offsetof(tFInfo, size)); + LOG("Bad size %i < %i", Sizes[1], sizeof(tFInfo)+a2*sizeof(tVFS_ACL)); + *Errno = -EINVAL; return -1; + } return VFS_FInfo(a0, a1, a2); ); SYSCALL2(Syscall_ReadDir, "id", int, char *, @@ -101,8 +124,11 @@ 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); +); SYSCALL3(Syscall_OpenChild, "isi", int, const char *, int, - return VFS_OpenChild(NULL, a0, a1, a2|VFS_OPENFLAG_USER); + return VFS_OpenChild(a0, a1, a2|VFS_OPENFLAG_USER); ); SYSCALL2(Syscall_GetACL, "id", int, void *, if(Sizes[1] < sizeof(tVFS_ACL)) @@ -112,6 +138,9 @@ SYSCALL2(Syscall_GetACL, "id", int, void *, SYSCALL4(Syscall_Mount, "ssss", const char *, const char *, const char *, const char *, return VFS_Mount(a0, a1, a2, a3); ); +SYSCALL1(Syscall_Chdir, "s", const char *, + return VFS_ChDir(a0); +); SYSCALL0(Syscall_Sleep, Threads_Sleep(); return 0; @@ -136,8 +165,11 @@ SYSCALL1(Syscall_SetGID, "i", int, return Threads_SetGID(Errno, a0); ); -SYSCALL0(Syscall_Fork, - return Threads_Fork(); +SYSCALL1(Syscall_Fork, "d", int *, + if(Sizes[0] < sizeof(int)) + return -1; + *a0 = Threads_Fork(); + return *a0; ); const tSyscallHandler caSyscalls[] = { @@ -156,13 +188,18 @@ const tSyscallHandler caSyscalls[] = { Syscall_GetACL, Syscall_Mount, NULL, // SYS_REOPEN + Syscall_Chdir, Syscall_WaitTID, Syscall_SetUID, Syscall_SetGID, Syscall_Sleep, - Syscall_Fork + Syscall_Fork, + + NULL, + NULL, + Syscall_select }; const int ciNumSyscalls = sizeof(caSyscalls)/sizeof(caSyscalls[0]); /** @@ -237,19 +274,19 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) case ARG_TYPE_VOID: break; case ARG_TYPE_INT32: - LOG("Syscalls", "%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("Syscalls", "%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("Syscalls", "%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; @@ -270,7 +307,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) { // Allocate and zero the buffer returnData[i] = calloc(1, Request->Params[i].Length); - LOG("Syscalls", "%i ZDAT: %i %p", i, + LOG("%i ZDAT: %i %p", i, Request->Params[i].Length, returnData[i]); *(void**)&argListData[argListLen] = returnData[i]; argListLen += sizeof(void*); @@ -278,7 +315,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) else { returnData[i] = (void*)inData; - LOG("Syscalls", "%i DATA: %i %p", i, + LOG("%i DATA: %i %p", i, Request->Params[i].Length, returnData[i]); *(void**)&argListData[argListLen] = (void*)inData; argListLen += sizeof(void*); @@ -306,7 +343,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) *(Uint64*)inData = retVal; inData += sizeof(Uint64); - LOG("Syscalls", "Return 0x%llx", retVal); + Log_Debug("Syscalls", "Return 0x%llx", retVal); retValueCount = 1; for( i = 0; i < Request->NParams; i ++ )