From: John Hodge (sonata) Date: Wed, 5 Nov 2014 07:07:33 +0000 (+0800) Subject: AcessNative - Fixing bad handling of errors, add run script for ARCH=native X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=commitdiff_plain;h=feb0895318d823867b858ec841589ca3ab81f510;ds=sidebyside AcessNative - Fixing bad handling of errors, add run script for ARCH=native --- diff --git a/AcessNative/Makefile b/AcessNative/Makefile index 7448f4fd..c7090be7 100644 --- a/AcessNative/Makefile +++ b/AcessNative/Makefile @@ -4,3 +4,4 @@ all clean: @$(MAKE) -C acesskernel_src $@ @$(MAKE) -C ld-acess_src $@ + @$(MAKE) -C libacess-native.so_src $@ diff --git a/AcessNative/RunNative b/AcessNative/RunNative new file mode 100755 index 00000000..255cf83f --- /dev/null +++ b/AcessNative/RunNative @@ -0,0 +1,14 @@ +#!/bin/sh +# +# 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 + +# 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 & +sleep 1 +LD_LIBRARY_PATH=${DIR}:${DISTROOT}Libs AN_PREOPEN=$VTERM:$VTERM:$VTERM ${DBG} ${DISTROOT}Apps/AxWin/4.0/AxWinServer diff --git a/AcessNative/RunRootApp b/AcessNative/RunRootApp index 39a30fac..a3d31abc 100755 --- a/AcessNative/RunRootApp +++ b/AcessNative/RunRootApp @@ -1,3 +1,7 @@ #!/bin/sh +# +# Spin up an application bound to VTerm 0 using ./ld-acess +# + $DBG ./ld-acess --open /Devices/VTerm/0 --open /Devices/VTerm/0 --open /Devices/VTerm/0 $* diff --git a/AcessNative/RunTest b/AcessNative/RunTest index 6ea88b67..069ea14f 100755 --- a/AcessNative/RunTest +++ b/AcessNative/RunTest @@ -1,4 +1,7 @@ #!/bin/sh +# +# Runs the AcessNative kernel and spawns a native executable using ./ld-acess +# trap '' 2 #$1 ./AcessKernel --rootapp /Acess/SBin/login $1 ./AcessKernel --rootapp /Acess/Apps/AxWin/3.0/AxWinWM diff --git a/AcessNative/acesskernel_src/Makefile b/AcessNative/acesskernel_src/Makefile index d2a22c69..4f388a21 100644 --- a/AcessNative/acesskernel_src/Makefile +++ b/AcessNative/acesskernel_src/Makefile @@ -46,6 +46,7 @@ KCPPFLAGS = -I include/ -I $(KERNEL_SRC)include/ -I$(LDACESS_SRC)include_exp/ -D CFLAGS += -Wall -g -std=gnu99 CPPFLAGS += $(shell sdl-config --cflags) -I /usr/include/ LDFLAGS += $(shell sdl-config --libs) -g -Wl,--defsym,__buildnum=$(BUILD_NUM) +LDFLAGS += -Wl,-Map,obj-$(PLATFORM)/Map.txt ifeq ($(PLATFORM),win) BIN := ../AcessKernel.exe diff --git a/AcessNative/ld-acess_src/request.c b/AcessNative/ld-acess_src/request.c index c516a225..690c7f7f 100644 --- a/AcessNative/ld-acess_src/request.c +++ b/AcessNative/ld-acess_src/request.c @@ -229,12 +229,12 @@ int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize) // Send it off SendData(Request, RequestSize); - if( Request->CallID == SYS_EXIT ) return 0; - // Wait for a response (no timeout) ReadData(Request, sizeof(*Request), 0); + + size_t recvbytes = sizeof(*Request); // TODO: Sanity - size_t recvbytes = sizeof(*Request), expbytes = Request->MessageLength; + size_t expbytes = Request->MessageLength; char *ptr = (void*)Request->Params; while( recvbytes < expbytes ) { diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index 60b7d952..98229728 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -171,7 +171,6 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) tRequestHeader *req; void *dataPtr; uint64_t retValue; - int i; // DEBUG! // printf("&tRequestHeader->Params = %i\n", offsetof(tRequestHeader, Params)); @@ -244,8 +243,11 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) exit(127); } + if( !(req->NParams >= 2) ) { + fprintf(stderr, "syscalls.c: Too few return params (%i)", req->NParams); + exit(127); + } dataPtr = (void*)&req->Params[req->NParams]; - assert(req->NParams >= 2); // return assert(req->Params[0].Type == ARG_TYPE_INT64); assert(req->Params[0].Length == sizeof(uint64_t)); @@ -264,7 +266,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) exit(127); } retCount = 0; - for( i = 2; i < req->NParams; i ++ ) + for( unsigned int i = 2; i < req->NParams; i ++ ) { #if 0 int j; diff --git a/AcessNative/libacess-native.so_src/Makefile b/AcessNative/libacess-native.so_src/Makefile index 92783114..2a0f0c4c 100644 --- a/AcessNative/libacess-native.so_src/Makefile +++ b/AcessNative/libacess-native.so_src/Makefile @@ -20,7 +20,7 @@ $(warning $(BINLINK)) CFLAGS += -Wall CFLAGS += -Werror -CFLAGS += -g -shared -fPIC +CFLAGS += -g -shared -fPIC -std=c99 CPPFLAGS += -DARCHDIR_is_x86_64=1 LDFLAGS += -g -shared -Wl,--no-undefined -lc diff --git a/AcessNative/libacess-native.so_src/main.c b/AcessNative/libacess-native.so_src/main.c index 74d9d3c6..7f62545f 100644 --- a/AcessNative/libacess-native.so_src/main.c +++ b/AcessNative/libacess-native.so_src/main.c @@ -59,7 +59,7 @@ int libacessnative_init(int argc, char *argv[], char **envp) path[len] = 0; int fd = acess__SysOpen(path, 6); // WRITE,READ,no EXEC if( fd == -1 ) { - fprintf(stderr, "Unable to preopen '%s'\n", path); + fprintf(stderr, "Unable to preopen '%s' errno=%i\n", path, acess__errno); } if( !splitter ) @@ -77,7 +77,7 @@ int libacessnative_init(int argc, char *argv[], char **envp) int acessnative_spawn(const char *Binary, int SyscallID, const char * const * argv, const char * const * envp) { int envc = 0; - while( envp[envc++] ) + while( envp && envp[envc++] ) envc ++; // Set environment variables for libacess-native @@ -89,7 +89,7 @@ int acessnative_spawn(const char *Binary, int SyscallID, const char * const * ar const char *newenv[envc+2+1]; int i = 0; - for( ; envp[i]; i ++ ) + for( ; envp && envp[i]; i ++ ) { const char *ev = envp[i]; if( strncmp(ev, ENV_VAR_KEY"=", sizeof(ENV_VAR_KEY"=")) == 0 ) { @@ -100,7 +100,7 @@ int acessnative_spawn(const char *Binary, int SyscallID, const char * const * ar } if( !bKeyHit ) newenv[i++] = keystr; - newenv[i++] = "LD_LIBRARY_PATH=Libs/"; // HACK + newenv[i++] = getenv("LD_LIBRARY_PATH") - (sizeof("LD_LIBRARY_PATH=")-1); // VERY hacky newenv[i] = NULL; // TODO: Detect native_spawn failing