X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Fld-acess_src%2Fexports.c;h=8064bb8bb1f54ab13c33fed52ccd4ac1ef504a12;hb=5f8480455a9e2172b15dfc7fb96480a68506c30d;hp=d7e49227d652ca08b11a2fed950aa63a1f95a9fb;hpb=9d101ee5f5231954a7102da36997aa8d568a6157;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index d7e49227..8064bb8b 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -11,10 +11,11 @@ #include #include -#define DEBUG(v...) Debug(v) -//#define DEBUG(v...) do{}while(0)//Debug(v) +#define DEBUG(v...) do{if(gbSyscallDebugEnabled)Debug(v);}while(0) #define PAGE_SIZE 4096 +#define TODO() Warning("TODO: %s", __func__) + typedef struct sFILE FILE; extern void exit(int) __attribute__ ((noreturn)); @@ -38,82 +39,99 @@ extern int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount); // === GLOBALS === int acess__errno; + int gbSyscallDebugEnabled = 0; char *gsExecutablePath = "./ld-acess"; // === CODE === // --- VFS Calls -int acess_chdir(const char *Path) +int acess__SysChdir(const char *Path) { return _Syscall(SYS_CHDIR, ">s", Path); } -int acess_open(const char *Path, int Flags) +int acess__SysOpen(const char *Path, unsigned int Flags) { if( strncmp(Path, "$$$$", 4) == 0 ) { - return native_open(Path, Flags) | NATIVE_FILE_MASK; + return native_open(Path+4, Flags) | NATIVE_FILE_MASK; + } + if( strncmp(Path, "/Devices/shm/", 13) == 0 ) + { + const char* tag = Path + 13; + Warning("TODO: Handle open SHM \"%s\"", tag); + return native_shm(tag, Flags) | NATIVE_FILE_MASK; } - DEBUG("open(\"%s\", 0x%x)", Path, Flags); + SYSTRACE("open(\"%s\", 0x%x)", Path, Flags); return _Syscall(SYS_OPEN, ">s >i", Path, Flags); } -void acess_close(int FD) { +void acess__SysClose(int FD) +{ if(FD & NATIVE_FILE_MASK) { return native_close(FD & (NATIVE_FILE_MASK-1)); } - DEBUG("close(%i)", FD); + SYSTRACE("close(%i)", FD); _Syscall(SYS_CLOSE, ">i", FD); } -int acess_reopen(int FD, const char *Path, int Flags) { - DEBUG("reopen(0x%x, \"%s\", 0x%x)", FD, Path, Flags); +int acess__SysReopen(int FD, const char *Path, int Flags) { + SYSTRACE("reopen(0x%x, \"%s\", 0x%x)", FD, Path, Flags); return _Syscall(SYS_REOPEN, ">i >s >i", FD, Path, Flags); } -size_t acess_read(int FD, void *Dest, size_t Bytes) { +int acess__SysCopyFD(int srcfd, int dstfd) { + SYSTRACE("_SysCopyFD(%i, %i)", srcfd, dstfd); + return _Syscall(SYS_COPYFD, ">i >i", srcfd, dstfd); +} + +int acess__SysFDFlags(int fd, int mask, int newflags) { + return _Syscall(SYS_FDFLAGS, ">i >i >i", fd, mask, newflags); +} + +size_t acess__SysRead(int FD, void *Dest, size_t Bytes) { if(FD & NATIVE_FILE_MASK) return native_read(FD & (NATIVE_FILE_MASK-1), Dest, Bytes); -// if( FD > 2 ) - DEBUG("read(0x%x, 0x%x, *%p)", FD, Bytes, Dest); + SYSTRACE("_SysRead(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); + SYSTRACE("_SysWrite(0x%x, 0x%x, %p\"%.*s\")", FD, Bytes, Src, Bytes, (char*)Src); return _Syscall(SYS_WRITE, ">i >i >d", FD, Bytes, Bytes, Src); } +uint64_t acess__SysTruncate(int fd, uint64_t size) { + TODO(); + return 0; +} -int acess_seek(int FD, int64_t Ofs, int Dir) { +int acess__SysSeek(int FD, int64_t Ofs, int Dir) +{ if(FD & NATIVE_FILE_MASK) { return native_seek(FD & (NATIVE_FILE_MASK-1), Ofs, Dir); } - DEBUG("seek(0x%x, 0x%llx, %i)", FD, Ofs, Dir); + SYSTRACE("_SysSeek(0x%x, 0x%llx, %i)", FD, Ofs, Dir); return _Syscall(SYS_SEEK, ">i >I >i", FD, Ofs, Dir); } -uint64_t acess_tell(int FD) { +uint64_t acess__SysTell(int FD) +{ if(FD & NATIVE_FILE_MASK) return native_tell( FD & (NATIVE_FILE_MASK-1) ); - DEBUG("tell(0x%x)", FD); + SYSTRACE("_SysTell(0x%x)", FD); return _Syscall(SYS_TELL, ">i", FD); } -int acess_ioctl(int fd, int id, void *data) { +int acess__SysIOCtl(int fd, int id, void *data) { int len; - DEBUG("ioctl(%i, %i, %p)", fd, id, data); + SYSTRACE("_SysIOCtl(%i, %i, %p)", fd, id, data); // NOTE: The length here is hacky and could break - if( data == NULL ) - len = 0; - else - len = PAGE_SIZE - ((uintptr_t)data % PAGE_SIZE); + len = (data == NULL ? 0 : 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); +int acess__SysFInfo(int fd, t_sysFInfo *info, int maxacls) { + SYSTRACE("_SysFInfo(%i, %p, %i)", fd, info, maxacls); return _Syscall(SYS_FINFO, ">i i", fd, sizeof(t_sysFInfo)+maxacls*sizeof(t_sysACL), info, @@ -121,14 +139,14 @@ int acess_finfo(int fd, t_sysFInfo *info, int maxacls) { ); } -int acess_SysReadDir(int fd, char *dest) { - DEBUG("SysReadDir(%i, %p)", fd, dest); +int acess__SysReadDir(int fd, char *dest) { + SYSTRACE("_SysReadDir(%i, %p)", fd, dest); return _Syscall(SYS_READDIR, ">i i ?d ?d ?d >d >i", nfds, read ? (nfds+7)/8 : 0, read, write ? (nfds+7)/8 : 0, write, @@ -137,25 +155,50 @@ int acess__SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *error, int64 events ); } - -int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, int64_t *timeout) +int acess__SysMkDir(const char *pathname) +{ + TODO(); + return 0; +} +int acess__SysUnlink(const char *pathname) { - return acess__SysSelect(nfds, read, write, error, timeout, 0); + // TODO: + TODO(); + return 0; +} +void* acess__SysMMap(void *addr, size_t length, unsigned int _flags, int fd, uint64_t offset) +{ + TODO(); + return NULL; +} +int acess__SysMUnMap(void *addr, size_t length) +{ + TODO(); + return 0; +} +uint64_t acess__SysMarshalFD(int FD) +{ + TODO(); + return 0; +} +int acess__SysUnMarshalFD(uint64_t Handle) +{ + TODO(); + return -1; } - int acess__SysOpenChild(int fd, char *name, int flags) { - DEBUG("_SysOpenChild(0x%x, '%s', 0x%x)", fd, name, flags); + SYSTRACE("_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); + SYSTRACE("%s(0x%x, %p)", __func__, fd, dest); return _Syscall(SYS_GETACL, ">i s >s >s >s", Device, Directory, Type, Options); } @@ -166,7 +209,62 @@ int acess__SysSetFaultHandler(int (*Handler)(int)) { return 0; } +void acess__SysSetName(const char *Name) +{ + // TODO: + TODO(); +} + +int acess__SysGetName(char *NameDest) +{ + // TODO: + TODO(); + return 0; +} + +int acess__SysSetPri(int Priority) +{ + // TODO: + TODO(); + return 0; +} + +// --- Binaries? --- +void *acess_SysLoadBin(const char *path, void **entry) +{ + // ERROR! + TODO(); + return NULL; +} + +int acess__SysUnloadBin(void *base) +{ + // ERROR! + TODO(); + return -1; +} + +// --- System --- +int acess__SysLoadModule(const char *Path) +{ + TODO(); + return -1; +} + +// --- Timekeeping --- +int64_t acess__SysTimestamp(void) +{ + return native_timestamp(); +} + // --- Memory Management --- +uint64_t acess__SysGetPhys(uintptr_t vaddr) +{ + // TODO: + TODO(); + return 0; +} + uint64_t acess__SysAllocate(uintptr_t vaddr) { if( AllocateMemory(vaddr, 0x1000) == -1 ) // Allocate a page @@ -176,7 +274,7 @@ uint64_t acess__SysAllocate(uintptr_t vaddr) } // --- Process Management --- -int acess_clone(int flags, void *stack) +int acess__SysClone(int flags, void *stack) { #ifdef __WIN32__ Warning("Win32 does not support anything like fork(2), cannot emulate"); @@ -212,7 +310,13 @@ int acess_clone(int flags, void *stack) #endif } -int acess_execve(char *path, char **argv, const char **envp) +int acess__SysKill(int pid, int sig) +{ + // TODO: Impliment SysKill + return -1; +} + +int acess__SysExecVE(char *path, char **argv, const char **envp) { int i, argc; @@ -265,7 +369,8 @@ int acess__SysSpawn(const char *binary, const char **argv, const char **envp, in int kernel_tid; int newID; - newID = _Syscall(SYS_AN_SPAWN, "d >d", sizeof(int), &kernel_tid, + newID = _Syscall(SYS_AN_SPAWN, "d >d", + sizeof(int), &kernel_tid, nfd*sizeof(int), fds, info ? sizeof(*info) : 0, info); @@ -289,13 +394,22 @@ int acess__SysSpawn(const char *binary, const char **argv, const char **envp, in return kernel_tid; } -void acess_sleep(void) +//void acess_sleep(void) +//{ +// DEBUG("%s()", __func__); +// _Syscall(SYS_SLEEP, ""); +//} + +void acess__SysTimedSleep(int64_t Delay) { - DEBUG("%s()", __func__); - _Syscall(SYS_SLEEP, ""); + DEBUG("%s(%lli)", __func__, Delay); + // Not accurate, but fuck it + //if( Delay > 1000 ) sleep(Delay / 1000); + //if( Delay % 1000 ) usleep( (Delay % 1000) * 1000 ); + //_Syscall(SYS_TIMEDSLEEP, ">I", Delay); } -int acess_waittid(int TID, int *ExitStatus) +int acess__SysWaitTID(int TID, int *ExitStatus) { DEBUG("%s(%i, %p)", __func__, TID, ExitStatus); return _Syscall(SYS_WAITTID, ">i 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__SysGetPID(void) { return _Syscall(SYS_GETPID, ""); } +int acess__SysGetUID(void) { return _Syscall(SYS_GETUID, ""); } +int acess__SysGetGID(void) { return _Syscall(SYS_GETGID, ""); } int acess_getgid(void) { return _Syscall(SYS_GETGID, ""); } -int acess_SysSendMessage(int DestTID, int Length, void *Data) +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, int BufLen, void *Data) +int acess__SysGetMessage(int *SourceTID, int BufLen, void *Data) { DEBUG("%s(%p, %p)", __func__, SourceTID, Data); return _Syscall(SYS_GETMSG, "= 16) + { + int_dbgheader(); + printf("%04x:" + " %02x %02x %02x %02x %02x %02x %02x %02x " + " %02x %02x %02x %02x %02x %02x %02x %02x " + " %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c\r\n", + pos, + cdat[ 0], cdat[ 1], cdat[ 2], cdat[ 3], cdat[ 4], cdat[ 5], cdat[ 6], cdat[ 7], + cdat[ 8], cdat[ 9], cdat[10], cdat[11], cdat[12], cdat[13], cdat[14], cdat[15], + CH(0), CH(1), CH(2), CH(3), CH(4), CH(5), CH(6), CH(7), + CH(8), CH(9), CH(10), CH(11), CH(12), CH(13), CH(14), CH(15) + ); + size -= 16; + cdat += 16; + pos += 16; + } + + { + int_dbgheader(); + printf("%04x: ", pos); + for(int i = 0; i < size; i ++) + printf("%02x ", cdat[i]); + for(int i = size; i < 16; i ++) + printf(" "); + printf(" "); + for(int i = 0; i < size; i ++) + { + if( i == 8 ) + printf(" "); + printf("%c", CH(i)); + } + + printf("\n"); + } +} + void acess__exit(int Status) { DEBUG("_exit(%i)", Status); @@ -358,45 +523,52 @@ uint32_t acess__SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask) // === Symbol List === -#define DEFSYM(name) {#name, &acess_##name} +#ifndef DEFSYM +# define DEFSYM(name) {#name, &acess_##name} +#endif const tSym caBuiltinSymbols[] = { DEFSYM(_exit), - DEFSYM(chdir), - DEFSYM(open), - DEFSYM(close), - DEFSYM(reopen), - DEFSYM(read), - DEFSYM(write), - DEFSYM(seek), - DEFSYM(tell), - DEFSYM(ioctl), - DEFSYM(finfo), - DEFSYM(SysReadDir), - DEFSYM(select), + DEFSYM(_SysChdir), + DEFSYM(_SysOpen), DEFSYM(_SysOpenChild), + DEFSYM(_SysReopen), + DEFSYM(_SysClose), + DEFSYM(_SysRead), + DEFSYM(_SysWrite), + DEFSYM(_SysSeek), + DEFSYM(_SysTell), + DEFSYM(_SysIOCtl), + DEFSYM(_SysFInfo), + DEFSYM(_SysReadDir), DEFSYM(_SysGetACL), DEFSYM(_SysMount), DEFSYM(_SysSelect), + DEFSYM(_SysMkDir), + DEFSYM(_SysUnlink), - DEFSYM(clone), - DEFSYM(execve), + DEFSYM(_SysClone), + DEFSYM(_SysExecVE), DEFSYM(_SysSpawn), - DEFSYM(sleep), +// DEFSYM(sleep), - DEFSYM(waittid), + DEFSYM(_SysWaitTID), DEFSYM(gettid), + DEFSYM(_SysGetPID), DEFSYM(setuid), DEFSYM(setgid), - DEFSYM(getuid), + DEFSYM(_SysGetUID), DEFSYM(getgid), - DEFSYM(SysSendMessage), - DEFSYM(SysGetMessage), + DEFSYM(_SysSendMessage), + DEFSYM(_SysGetMessage), DEFSYM(_SysAllocate), DEFSYM(_SysSetMemFlags), DEFSYM(_SysDebug), + {"_ZN4_sys5debugEPKcz", &acess__SysDebug}, + DEFSYM(_SysDebugHex), + {"_ZN4_sys7hexdumpEPKcPKvj", &acess__SysDebugHex}, DEFSYM(_SysSetFaultHandler), DEFSYM(_SysWaitEvent),