X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=AcessNative%2Fld-acess_src%2Fexports.c;h=d7e49227d652ca08b11a2fed950aa63a1f95a9fb;hb=36b950d17b828c7cd2e5e9dbe5fb4cbded89889c;hp=0c87bda674ef882eae453f55e7928a90d797fd8a;hpb=a41f3e5efdf853726d078dc03550de40e9d63bdd;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index 0c87bda6..d7e49227 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -5,17 +5,18 @@ * - 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 *, ...); @@ -28,12 +29,17 @@ 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; +char *gsExecutablePath = "./ld-acess"; + // === CODE === // --- VFS Calls int acess_chdir(const char *Path) @@ -67,14 +73,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 +97,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,12 +121,12 @@ 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 >i", nfds, @@ -124,21 +138,24 @@ int acess__SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *error, time_ ); } -int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, time_t *timeout) +int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, int64_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); } @@ -150,7 +167,7 @@ int acess__SysSetFaultHandler(int (*Handler)(int)) { } // --- Memory Management --- -uint64_t acess__SysAllocate(uint vaddr) +uint64_t acess__SysAllocate(uintptr_t vaddr) { if( AllocateMemory(vaddr, 0x1000) == -1 ) // Allocate a page return 0; @@ -161,10 +178,14 @@ 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("USERSIDE fork()\n"); + Debug("USERSIDE fork()"); newID = _Syscall(SYS_AN_FORK, "d >d", sizeof(int), &kernel_tid, + nfd*sizeof(int), fds, + info ? sizeof(*info) : 0, info); + + const char *new_argv[5+argc+1]; + int new_argc = 0, i; + char client_id_str[11]; + sprintf(client_id_str, "%i", newID); + new_argv[new_argc++] = gsExecutablePath; // TODO: Get path to ld-acess executable + new_argv[new_argc++] = "--key"; + new_argv[new_argc++] = client_id_str; + new_argv[new_argc++] = "--binary"; + new_argv[new_argc++] = binary; + for( i = 0; argv[i]; i ++) + new_argv[new_argc++] = argv[i]; + new_argv[new_argc++] = NULL; + + // TODO: Debug output? + + native_spawn(gsExecutablePath, new_argv, envp); + + return kernel_tid; +} + void acess_sleep(void) { + DEBUG("%s()", __func__); _Syscall(SYS_SLEEP, ""); } int acess_waittid(int TID, int *ExitStatus) { + DEBUG("%s(%i, %p)", __func__, TID, ExitStatus); return _Syscall(SYS_WAITTID, ">i 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, ...) { @@ -270,7 +336,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"); @@ -284,9 +350,15 @@ void acess__exit(int Status) exit(Status); } +uint32_t acess__SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask) +{ + // TODO: Impliment acess__SysSetMemFlags? + return 0; +} + // === Symbol List === -#define DEFSYM(name) {#name, acess_##name} +#define DEFSYM(name) {#name, &acess_##name} const tSym caBuiltinSymbols[] = { DEFSYM(_exit), @@ -300,7 +372,7 @@ const tSym caBuiltinSymbols[] = { DEFSYM(tell), DEFSYM(ioctl), DEFSYM(finfo), - DEFSYM(readdir), + DEFSYM(SysReadDir), DEFSYM(select), DEFSYM(_SysOpenChild), DEFSYM(_SysGetACL), @@ -309,19 +381,26 @@ const tSym caBuiltinSymbols[] = { DEFSYM(clone), DEFSYM(execve), + DEFSYM(_SysSpawn), DEFSYM(sleep), DEFSYM(waittid), + DEFSYM(gettid), DEFSYM(setuid), DEFSYM(setgid), - DEFSYM(gettid), + DEFSYM(getuid), + DEFSYM(getgid), DEFSYM(SysSendMessage), DEFSYM(SysGetMessage), DEFSYM(_SysAllocate), + DEFSYM(_SysSetMemFlags), DEFSYM(_SysDebug), - DEFSYM(_SysSetFaultHandler) + DEFSYM(_SysSetFaultHandler), + DEFSYM(_SysWaitEvent), + + DEFSYM(_errno) }; const int ciNumBuiltinSymbols = sizeof(caBuiltinSymbols)/sizeof(caBuiltinSymbols[0]);