From: John Hodge Date: Sun, 7 Oct 2012 08:57:15 +0000 (+0800) Subject: AcessNative - Added message length to simplfy message reception X-Git-Tag: rel0.15~695 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c366e1c60e7c6c3fc12be52583dda26ca9fd2b00;p=tpg%2Facess2.git AcessNative - Added message length to simplfy message reception --- diff --git a/AcessNative/acesskernel_src/syscalls.c b/AcessNative/acesskernel_src/syscalls.c index 446da3de..9cee8e36 100644 --- a/AcessNative/acesskernel_src/syscalls.c +++ b/AcessNative/acesskernel_src/syscalls.c @@ -384,11 +384,12 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) } // Allocate the return - ret = malloc(sizeof(tRequestHeader) + retValueCount * sizeof(tRequestValue) - + retDataLen); + size_t msglen = sizeof(tRequestHeader) + retValueCount * sizeof(tRequestValue) + retDataLen; + ret = malloc(msglen); ret->ClientID = Request->ClientID; ret->CallID = Request->CallID; ret->NParams = retValueCount; + ret->MessageLength = msglen; inData = (char*)&ret->Params[ ret->NParams ]; // Static Uint64 return value diff --git a/AcessNative/ld-acess_src/request.c b/AcessNative/ld-acess_src/request.c index 7a9b3b39..1560eb7b 100644 --- a/AcessNative/ld-acess_src/request.c +++ b/AcessNative/ld-acess_src/request.c @@ -190,6 +190,7 @@ int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize) printf("\n"); } #endif + #if DEBUG { int i; char *data = (char*)&Request->Params[Request->NParams]; @@ -219,6 +220,7 @@ int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize) } DEBUG_S("\n"); } + #endif // Send it off SendData(Request, RequestSize); @@ -226,7 +228,23 @@ int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize) if( Request->CallID == SYS_EXIT ) return 0; // Wait for a response (no timeout) - return ReadData(Request, ResponseSize, 0); + ReadData(Request, sizeof(*Request), 0); + // TODO: Sanity + size_t recvbytes = sizeof(*Request), expbytes = Request->MessageLength; + char *ptr = (void*)Request->Params; + while( recvbytes < expbytes ) + { + size_t len = ReadData(ptr, expbytes - recvbytes, 1000); + if( len == -1 ) { + return -1; + } + recvbytes += len; + ptr += len; + } + if( recvbytes > expbytes ) { + // TODO: Warning + } + return recvbytes; } void SendData(void *Data, int Length) diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index a5ec8dea..5c268702 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -206,6 +206,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) req->ClientID = 0; //< Filled later req->CallID = SyscallID; req->NParams = paramCount; + req->MessageLength = dataLength; dataPtr = &req->Params[paramCount]; // Fill `output` and `input` @@ -253,6 +254,11 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) } // Write changes to buffers + if( req->NParams - 1 != retCount ) { + fprintf(stderr, "syscalls.c: Return count inbalance (%i - 1 != exp %i) [Call %i]\n", + req->NParams, retCount, SyscallID); + exit(127); + } retCount = 0; for( i = 1; i < req->NParams; i ++ ) { diff --git a/AcessNative/syscalls.h b/AcessNative/syscalls.h index e6dbd285..d7ee2d59 100644 --- a/AcessNative/syscalls.h +++ b/AcessNative/syscalls.h @@ -29,6 +29,7 @@ typedef struct sRequestValue { typedef struct sRequestHeader { uint16_t ClientID; uint16_t CallID; //!< \see eSyscalls + uint32_t MessageLength; uint16_t NParams; tRequestValue Params[]; diff --git a/BuildConf/x86/Makefile.cfg b/BuildConf/x86/Makefile.cfg index 76c3d3ce..7d5dcc1a 100644 --- a/BuildConf/x86/Makefile.cfg +++ b/BuildConf/x86/Makefile.cfg @@ -2,10 +2,10 @@ # Acess2 Build Configuration # -#CC = i586-elf-gcc -#LD = i586-elf-ld -CC = gcc -LD = ld +CC = i586-elf-gcc +LD = i586-elf-ld +#CC = gcc +#LD = ld AS = nasm #OBJDUMP = i586-elf-objdump OBJDUMP = objdump diff --git a/BuildConf/x86_64/Makefile.cfg b/BuildConf/x86_64/Makefile.cfg index 6aa3afc6..ebca2d9f 100644 --- a/BuildConf/x86_64/Makefile.cfg +++ b/BuildConf/x86_64/Makefile.cfg @@ -1,6 +1,6 @@ -PREFIX := x86_64-pc-elf -#PREFIX := x86_64-none-elf +#PREFIX := x86_64-pc-elf +PREFIX := x86_64-none-elf CC := $(PREFIX)-gcc LD := $(PREFIX)-ld