X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=inline;f=AcessNative%2Fld-acess_src%2Fexports.c;h=cd1924b2502eed00f81bc02256f166d12079e78d;hb=57e4db716b3e7db0be336abd9f256962e3b19aa3;hp=7131e632d9d6fb72cf6c7b978c2887b9aee7b3b0;hpb=6d32a3c22e659994d7ae6164ba3722ab12d11421;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index 7131e632..cd1924b2 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -5,13 +5,14 @@ * - 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 PAGE_SIZE 4096 typedef struct sFILE FILE; @@ -34,6 +35,9 @@ 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) @@ -67,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); } @@ -89,13 +95,19 @@ 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)); @@ -107,31 +119,41 @@ int acess_finfo(int fd, t_sysFInfo *info, int 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) { + DEBUG("%s(0x%x, %p)", __func__, fd, dest); return _Syscall(SYS_GETACL, ">i s >s >s >s", Device, Directory, Type, Options); } @@ -157,7 +179,7 @@ int acess_clone(int flags, void *stack) extern int fork(void); if(flags & CLONE_VM) { int ret, newID, kernel_tid=0; - printf("USERSIDE fork()\n"); + Debug("USERSIDE fork()"); newID = _Syscall(SYS_AN_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, ...) { @@ -266,7 +295,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"); @@ -282,7 +311,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), @@ -296,11 +325,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), @@ -309,13 +339,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]);