X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Fld-acess_src%2Fexports.c;h=7e13134bc6dd06f56b194d842fda58e54ada9518;hb=9d234f984c149fcc6b1f5aab21a0ca227c060e32;hp=533c25b36e4c0964c2df0240f72b156d0b47b4a8;hpb=b4e2712f6a0849de53207ad50a38c9f468f22651;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index 533c25b3..7e13134b 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -5,16 +5,17 @@ * - Exported functions */ #define DONT_INCLUDE_SYSCALL_NAMES 1 -#include "../../Usermode/include/acess/sys.h" +#include "../../Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h" #include "../syscalls.h" #include "exports.h" #include +#include -#define DEBUG(v...) Debug(v) +#define DEBUG(v...) do{}while(0)//Debug(v) +#define PAGE_SIZE 4096 typedef struct sFILE FILE; -extern FILE *stderr; extern void exit(int) __attribute__ ((noreturn)); extern int printf(const char *, ...); extern int fprintf(FILE *,const char *, ...); @@ -22,13 +23,21 @@ extern int sprintf(char *,const char *, ...); extern int vprintf(const char *, va_list); extern int strncmp(const char *, const char *, size_t); +extern int gSocket; extern int giSyscall_ClientID; // Needed for execve +extern void _InitSyscalls(void); +extern void _CloseSyscalls(void); + +extern void Warning(const char *Format, ...); extern void Debug(const char *Format, ...); extern int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount); // === CONSTANTS === #define NATIVE_FILE_MASK 0x40000000 +// === GLOBALS === +int acess__errno; + // === CODE === // --- VFS Calls int acess_chdir(const char *Path) @@ -62,14 +71,16 @@ int acess_reopen(int FD, const char *Path, int Flags) { size_t acess_read(int FD, void *Dest, size_t Bytes) { if(FD & NATIVE_FILE_MASK) return native_read(FD & (NATIVE_FILE_MASK-1), Dest, Bytes); - DEBUG("read(0x%x, 0x%x, *%p)", FD, Bytes, Dest); +// if( FD > 2 ) + DEBUG("read(0x%x, 0x%x, *%p)", FD, Bytes, Dest); return _Syscall(SYS_READ, ">i >i 2 ) + DEBUG("write(0x%x, 0x%x, %p\"%.*s\")", FD, Bytes, Src, Bytes, (char*)Src); return _Syscall(SYS_WRITE, ">i >i >d", FD, Bytes, Bytes, Src); } @@ -84,52 +95,71 @@ int acess_seek(int FD, int64_t Ofs, int Dir) { uint64_t acess_tell(int FD) { if(FD & NATIVE_FILE_MASK) return native_tell( FD & (NATIVE_FILE_MASK-1) ); + DEBUG("tell(0x%x)", FD); return _Syscall(SYS_TELL, ">i", FD); } int acess_ioctl(int fd, int id, void *data) { - // NOTE: 1024 byte size is a hack + int len; DEBUG("ioctl(%i, %i, %p)", fd, id, data); - return _Syscall(SYS_IOCTL, ">i >i ?d", fd, id, 1024, data); + // NOTE: The length here is hacky and could break + if( data == NULL ) + len = 0; + else + len = PAGE_SIZE - ((uintptr_t)data % PAGE_SIZE); + return _Syscall(SYS_IOCTL, ">i >i ?d", fd, id, len, data); } int acess_finfo(int fd, t_sysFInfo *info, int maxacls) { +// DEBUG("offsetof(size, t_sysFInfo) = %i", offsetof(t_sysFInfo, size)); + DEBUG("finfo(%i, %p, %i)", fd, info, maxacls); return _Syscall(SYS_FINFO, ">i i", fd, sizeof(t_sysFInfo)+maxacls*sizeof(t_sysACL), info, - maxacls); + maxacls + ); } -int acess_readdir(int fd, char *dest) { - DEBUG("readdir(%i, %p)", fd, dest); +int acess_SysReadDir(int fd, char *dest) { + DEBUG("SysReadDir(%i, %p)", fd, dest); return _Syscall(SYS_READDIR, ">i i ?d ?d ?d >d", nfds, + DEBUG("_SysSelect(%i, %p, %p, %p, %p, 0x%x)", nfds, read, write, error, timeout, events); + return _Syscall(SYS_SELECT, ">i ?d ?d ?d >d >i", nfds, read ? (nfds+7)/8 : 0, read, write ? (nfds+7)/8 : 0, write, error ? (nfds+7)/8 : 0, error, - sizeof(*timeout), timeout + sizeof(*timeout), timeout, + events ); } +int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, time_t *timeout) +{ + return acess__SysSelect(nfds, read, write, error, timeout, 0); +} + + int acess__SysOpenChild(int fd, char *name, int flags) { + DEBUG("_SysOpenChild(0x%x, '%s', 0x%x)", fd, name, flags); return _Syscall(SYS_OPENCHILD, ">i >s >i", fd, name, flags); } int acess__SysGetACL(int fd, t_sysACL *dest) { - return _Syscall(SYS_GETACL, "i i s >s >s >s", Device, Directory, Type, Options); } // --- Error Handler -int acess__SysSetFaultHandler(int (*Handler)(int)) { +int acess__SysSetFaultHandler(int (*Handler)(int)) { printf("TODO: Set fault handler (asked to set to %p)\n", Handler); return 0; } @@ -146,18 +176,26 @@ uint64_t acess__SysAllocate(uint vaddr) // --- Process Management --- int acess_clone(int flags, void *stack) { + #ifdef __WIN32__ + Warning("Win32 does not support anything like fork(2), cannot emulate"); + exit(-1); + #else extern int fork(void); if(flags & CLONE_VM) { int ret, newID, kernel_tid=0; - printf("fork()"); + Debug("USERSIDE fork()"); - newID = _Syscall(SYS_FORK, "i i", ID); -} - -int acess_setgid(int ID) -{ - return _Syscall(SYS_SETGID, ">i", ID); -} +int acess_setuid(int ID) { return _Syscall(SYS_SETUID, ">i", ID); } +int acess_setgid(int ID) { return _Syscall(SYS_SETGID, ">i", ID); } +int acess_gettid(void) { return _Syscall(SYS_GETTID, ""); } +int acess_getpid(void) { return _Syscall(SYS_GETPID, ""); } +int acess_getuid(void) { return _Syscall(SYS_GETUID, ""); } +int acess_getgid(void) { return _Syscall(SYS_GETGID, ""); } int acess_SysSendMessage(int DestTID, int Length, void *Data) { + DEBUG("%s(%i, 0x%x, %p)", __func__, DestTID, Length, Data); return _Syscall(SYS_SENDMSG, ">i >d", DestTID, Length, Data); } -int acess_SysGetMessage(int *SourceTID, void *Data) +int acess_SysGetMessage(int *SourceTID, int BufLen, void *Data) { + DEBUG("%s(%p, %p)", __func__, SourceTID, Data); return _Syscall(SYS_GETMSG, "i", Mask); +} + // --- Logging void acess__SysDebug(const char *Format, ...) { @@ -243,7 +300,7 @@ void acess__SysDebug(const char *Format, ...) va_start(args, Format); - printf("[_SysDebug %i]", giSyscall_ClientID); + printf("[_SysDebug %i] ", giSyscall_ClientID); vprintf(Format, args); printf("\n"); @@ -259,7 +316,7 @@ void acess__exit(int Status) // === Symbol List === -#define DEFSYM(name) {#name, acess_##name} +#define DEFSYM(name) {#name, &acess_##name} const tSym caBuiltinSymbols[] = { DEFSYM(_exit), @@ -273,11 +330,12 @@ const tSym caBuiltinSymbols[] = { DEFSYM(tell), DEFSYM(ioctl), DEFSYM(finfo), - DEFSYM(readdir), + DEFSYM(SysReadDir), DEFSYM(select), DEFSYM(_SysOpenChild), DEFSYM(_SysGetACL), DEFSYM(_SysMount), + DEFSYM(_SysSelect), DEFSYM(clone), DEFSYM(execve), @@ -286,13 +344,17 @@ const tSym caBuiltinSymbols[] = { DEFSYM(waittid), DEFSYM(setuid), DEFSYM(setgid), + DEFSYM(gettid), DEFSYM(SysSendMessage), DEFSYM(SysGetMessage), DEFSYM(_SysAllocate), DEFSYM(_SysDebug), - DEFSYM(_SysSetFaultHandler) + DEFSYM(_SysSetFaultHandler), + DEFSYM(_SysWaitEvent), + + DEFSYM(_errno) }; const int ciNumBuiltinSymbols = sizeof(caBuiltinSymbols)/sizeof(caBuiltinSymbols[0]);