X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Fld-acess_src%2Fexports.c;h=8064bb8bb1f54ab13c33fed52ccd4ac1ef504a12;hb=8b72370eae1a3cfa8916136fd8ffc1460e9291ba;hp=3f5f295c21953e66c00a0c37ac5f782e71116155;hpb=336ba8b200f6ca1d5d25f09a9d7ddac2e59b26d9;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index 3f5f295c..8064bb8b 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -11,8 +11,7 @@ #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__) @@ -40,6 +39,7 @@ extern int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount); // === GLOBALS === int acess__errno; + int gbSyscallDebugEnabled = 0; char *gsExecutablePath = "./ld-acess"; // === CODE === @@ -49,11 +49,17 @@ int acess__SysChdir(const char *Path) return _Syscall(SYS_CHDIR, ">s", Path); } -int acess__SysOpen(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; } SYSTRACE("open(\"%s\", 0x%x)", Path, Flags); return _Syscall(SYS_OPEN, ">s >i", Path, Flags); @@ -95,6 +101,10 @@ size_t acess__SysWrite(int FD, const void *Src, size_t Bytes) { 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__SysSeek(int FD, int64_t Ofs, int Dir) { @@ -121,7 +131,6 @@ int acess__SysIOCtl(int fd, int id, void *data) { return _Syscall(SYS_IOCTL, ">i >i ?d", fd, id, len, data); } int acess__SysFInfo(int fd, t_sysFInfo *info, int maxacls) { -// DEBUG("offsetof(size, t_sysFInfo) = %i", offsetof(t_sysFInfo, size)); SYSTRACE("_SysFInfo(%i, %p, %i)", fd, info, maxacls); return _Syscall(SYS_FINFO, ">i i", fd, @@ -157,6 +166,26 @@ int acess__SysUnlink(const char *pathname) 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) { SYSTRACE("_SysOpenChild(0x%x, '%s', 0x%x)", fd, name, flags); @@ -215,13 +244,17 @@ int acess__SysUnloadBin(void *base) return -1; } +// --- System --- +int acess__SysLoadModule(const char *Path) +{ + TODO(); + return -1; +} + // --- Timekeeping --- int64_t acess__SysTimestamp(void) { - // TODO: Better impl - TODO(); -// return now()*1000; - return 0; + return native_timestamp(); } // --- Memory Management --- @@ -336,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); @@ -366,6 +400,15 @@ int acess__SysSpawn(const char *binary, const char **argv, const char **envp, in // _Syscall(SYS_SLEEP, ""); //} +void acess__SysTimedSleep(int64_t Delay) +{ + 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__SysWaitTID(int TID, int *ExitStatus) { DEBUG("%s(%i, %p)", __func__, TID, ExitStatus); @@ -377,6 +420,7 @@ int acess_setgid(int ID) { return _Syscall(SYS_SETGID, ">i", ID); } int acess_gettid(void) { return _Syscall(SYS_GETTID, ""); } 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) @@ -401,19 +445,69 @@ int acess__SysWaitEvent(int Mask) } // --- Logging +static void int_dbgheader(void ) +{ + printf("[_SysDebug %i] ", giSyscall_ClientID); +} void acess__SysDebug(const char *Format, ...) { va_list args; va_start(args, Format); - - printf("[_SysDebug %i] ", giSyscall_ClientID); + int_dbgheader(); vprintf(Format, args); printf("\n"); va_end(args); } +void acess__SysDebugHex(const char *tag, const void *data, size_t size) +{ + int_dbgheader(); + printf("%s (Hexdump of %p+%zi)\r\n", tag, data, size); + + #define CH(n) ((' '<=cdat[(n)]&&cdat[(n)]<0x7F) ? cdat[(n)] : '.') + + const uint8_t *cdat = data; + unsigned int pos = 0; + + while(size >= 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); @@ -472,6 +566,9 @@ const tSym caBuiltinSymbols[] = { DEFSYM(_SysAllocate), DEFSYM(_SysSetMemFlags), DEFSYM(_SysDebug), + {"_ZN4_sys5debugEPKcz", &acess__SysDebug}, + DEFSYM(_SysDebugHex), + {"_ZN4_sys7hexdumpEPKcPKvj", &acess__SysDebugHex}, DEFSYM(_SysSetFaultHandler), DEFSYM(_SysWaitEvent),