From: John Hodge (sonata) Date: Thu, 6 Nov 2014 23:11:36 +0000 (+0800) Subject: AcessNative - Hexdump sycall, stub shm X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=63895b4261593e7891a28db441a54615d0374c8b;p=tpg%2Facess2.git AcessNative - Hexdump sycall, stub shm --- diff --git a/AcessNative/RunNative b/AcessNative/RunNative index 255cf83f..f22ed7fe 100755 --- a/AcessNative/RunNative +++ b/AcessNative/RunNative @@ -1,14 +1,29 @@ -#!/bin/sh +#!/bin/bash # # Execute the specified root application using the ARCH=native build # _=$PWD; cd $(dirname $0); DIR=$PWD; cd $_ DISTROOT=$(dirname $DIR)/Usermode/Output/native/ VTERM=/Devices/pts/vt0 +echo $DISTROOT + +KERNEL_PID=$$ +function cleanup { + trap '' SIGINT + echo Cleaning up $KERNEL_PID + kill $KERNEL_PID +} + +trap cleanup SIGINT # 1. Start up AcessKernel # - Set DISTROOT to the output directory of ARCH=native # - Don't start a root application -${DIR}/AcessKernel --distroot $DISTROOT > ${DIR}/log/native_AcessKernel.log & +${DIR}/AcessKernel --distroot $DISTROOT > ${DIR}/log/native_AcessKernel.log 2>&1 & +KERNEL_PID=$! +echo Kernel is $KERNEL_PID sleep 1 LD_LIBRARY_PATH=${DIR}:${DISTROOT}Libs AN_PREOPEN=$VTERM:$VTERM:$VTERM ${DBG} ${DISTROOT}Apps/AxWin/4.0/AxWinServer + +cleanup + diff --git a/AcessNative/acesskernel_src/Makefile b/AcessNative/acesskernel_src/Makefile index a55910cf..11976045 100644 --- a/AcessNative/acesskernel_src/Makefile +++ b/AcessNative/acesskernel_src/Makefile @@ -21,7 +21,7 @@ KERNEL_OBJ += mutex.o semaphore.o rwlock.o workqueue.o events.o KERNEL_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o KERNEL_OBJ += vfs/nodecache.o vfs/mount.o vfs/memfile.o vfs/select.o KERNEL_OBJ += vfs/fs/root.o vfs/fs/devfs.o -KERNEL_OBJ += drv/fifo.o drv/proc.o drv/dgram_pipe.o # drv/shm.o +KERNEL_OBJ += drv/fifo.o drv/proc.o drv/dgram_pipe.o KERNEL_OBJ += drv/vterm.o drv/vterm_font.o drv/vterm_output.o drv/vterm_input.o drv/vterm_termbuf.o KERNEL_OBJ += drv/vterm_vt100.o drv/vterm_2d.o KERNEL_OBJ += drv/pty.o @@ -30,6 +30,7 @@ N_OBJ := main.o net_wrap.o # - Local objects (use the kernel includes) OBJ := helpers.o threads.o threads_glue.o server.o syscalls.o time.o OBJ += video.o keyboard.o mouse.o nativefs.o vfs_handle.o ui_sdl.o +#OBJ += shm.o OBJ += net.o syscall_getpath.o BUILDINFO_OBJ := obj-$(PLATFORM)/buildinfo.o diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index 10dc7bde..62451ece 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -53,7 +53,13 @@ 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); @@ -442,19 +448,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); @@ -514,6 +570,8 @@ const tSym caBuiltinSymbols[] = { DEFSYM(_SysSetMemFlags), DEFSYM(_SysDebug), {"_ZN4_sys5debugEPKcz", &acess__SysDebug}, + DEFSYM(_SysDebugHex), + {"_ZN4_sys7hexdumpEPKcPKvj", &acess__SysDebugHex}, DEFSYM(_SysSetFaultHandler), DEFSYM(_SysWaitEvent), diff --git a/AcessNative/ld-acess_src/exports.h b/AcessNative/ld-acess_src/exports.h index e8f2e4c8..788e0d27 100644 --- a/AcessNative/ld-acess_src/exports.h +++ b/AcessNative/ld-acess_src/exports.h @@ -17,6 +17,7 @@ extern uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...); extern int acess__errno; extern int native_open(const char *Path, int Flags); +extern int native_shm(const char *Tag, int Flags); extern void native_close(int FD); extern size_t native_read(int FD, void *Dest, size_t Bytes); extern size_t native_write(int FD, const void *Src, size_t Bytes); diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index 98229728..965cc4ae 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -290,18 +290,40 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) return retValue; } +int native_int_getfd(void) +{ + for(int ret = 0; ret < MAX_FPS; ret ++ ) + if( gaSyscall_LocalFPs[ret] == NULL ) + return ret; + return -1; +} int native_open(const char *Path, int Flags) { - int ret; - for(ret = 0; ret < MAX_FPS && gaSyscall_LocalFPs[ret]; ret ++ ) ; - if(ret == MAX_FPS) return -1; + int ret = native_int_getfd(); + if(ret == -1) return -1; // TODO: Handle directories - gaSyscall_LocalFPs[ret] = fopen(&Path[4], "r+"); + gaSyscall_LocalFPs[ret] = fopen(Path, "r+"); if(!gaSyscall_LocalFPs[ret]) return -1; return ret; } +int native_shm(const char *Tag, int Flags) +{ + // int ret = native_int_getfd(); + //if(ret == -1) return -1; + //if( strcmp(Tag, "anon") == 0 ) + // path = "/AcessNative/anon/RAND"; + // FD = shm_open(path, O_RDWD); + //shm_unlink(path); + //else + // path = "/Acessnative/named/"; + // int FD = shm_open(path, O_RDWD); + //shm_unlink(path); + //gaSyscall_LocalFPs[ret] = + return -1; +} + void native_close(int FD) { fclose( gaSyscall_LocalFPs[FD] ); diff --git a/AcessNative/libacess-native.so_src/exports.c b/AcessNative/libacess-native.so_src/exports.c index 0f71f212..ad5aac49 100644 --- a/AcessNative/libacess-native.so_src/exports.c +++ b/AcessNative/libacess-native.so_src/exports.c @@ -11,6 +11,7 @@ int *libc_geterrno(void) } void _ZN4_sys5debugEPKcz(const char *fmt, ...) __attribute__((alias("acess__SysDebug"))); +void _ZN4_sys7hexdumpEPKcPKvj(const char *tag, const void *ptr, size_t size) __attribute__((alias("acess__SysDebugHex"))); #undef acess__SysSpawn