AcessNative - Hexdump sycall, stub shm
authorJohn Hodge (sonata) <[email protected]>
Thu, 6 Nov 2014 23:11:36 +0000 (07:11 +0800)
committerJohn Hodge (sonata) <[email protected]>
Thu, 6 Nov 2014 23:11:36 +0000 (07:11 +0800)
AcessNative/RunNative
AcessNative/acesskernel_src/Makefile
AcessNative/ld-acess_src/exports.c
AcessNative/ld-acess_src/exports.h
AcessNative/ld-acess_src/syscalls.c
AcessNative/libacess-native.so_src/exports.c

index 255cf83..f22ed7f 100755 (executable)
@@ -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
+
index a55910c..1197604 100644 (file)
@@ -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\r
 KERNEL_OBJ += vfs/nodecache.o vfs/mount.o vfs/memfile.o vfs/select.o\r
 KERNEL_OBJ += vfs/fs/root.o vfs/fs/devfs.o\r
-KERNEL_OBJ += drv/fifo.o drv/proc.o drv/dgram_pipe.o   # drv/shm.o\r
+KERNEL_OBJ += drv/fifo.o drv/proc.o drv/dgram_pipe.o\r
 KERNEL_OBJ += drv/vterm.o drv/vterm_font.o drv/vterm_output.o drv/vterm_input.o drv/vterm_termbuf.o\r
 KERNEL_OBJ += drv/vterm_vt100.o drv/vterm_2d.o\r
 KERNEL_OBJ += drv/pty.o\r
@@ -30,6 +30,7 @@ N_OBJ := main.o net_wrap.o
 # - Local objects (use the kernel includes)\r
 OBJ := helpers.o threads.o threads_glue.o server.o syscalls.o time.o\r
 OBJ += video.o keyboard.o mouse.o nativefs.o vfs_handle.o ui_sdl.o\r
+#OBJ += shm.o\r
 OBJ += net.o syscall_getpath.o\r
 \r
 BUILDINFO_OBJ := obj-$(PLATFORM)/buildinfo.o\r
index 10dc7bd..62451ec 100644 (file)
@@ -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),
        
index e8f2e4c..788e0d2 100644 (file)
@@ -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);
index 9822972..965cc4a 100644 (file)
@@ -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/<TAG>";
+       // int FD = shm_open(path, O_RDWD);
+       //shm_unlink(path);
+       //gaSyscall_LocalFPs[ret] = 
+       return -1;
+}
+
 void native_close(int FD)
 {
        fclose( gaSyscall_LocalFPs[FD] );
index 0f71f21..ad5aac4 100644 (file)
@@ -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
 

UCC git Repository :: git.ucc.asn.au