From c366e1c60e7c6c3fc12be52583dda26ca9fd2b00 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 7 Oct 2012 16:57:15 +0800 Subject: [PATCH] AcessNative - Added message length to simplfy message reception --- AcessNative/acesskernel_src/syscalls.c | 5 +++-- AcessNative/ld-acess_src/request.c | 20 +++++++++++++++++++- AcessNative/ld-acess_src/syscalls.c | 6 ++++++ AcessNative/syscalls.h | 1 + BuildConf/x86/Makefile.cfg | 8 ++++---- BuildConf/x86_64/Makefile.cfg | 4 ++-- 6 files changed, 35 insertions(+), 9 deletions(-) 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 -- 2.20.1