From 57e4db716b3e7db0be336abd9f256962e3b19aa3 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 4 Oct 2012 21:47:03 +0800 Subject: [PATCH] AcessNative - Bugfixes 'r' us, GUI can start and render (partially) --- AcessNative/acesskernel_src/main.c | 2 + AcessNative/acesskernel_src/server.c | 52 ++++++++++++++++++++++---- AcessNative/acesskernel_src/syscalls.c | 4 +- AcessNative/acesskernel_src/threads.c | 2 +- AcessNative/ld-acess_src/Makefile | 7 ++-- AcessNative/ld-acess_src/exports.c | 21 +++++++---- AcessNative/ld-acess_src/main.c | 3 +- AcessNative/ld-acess_src/syscalls.c | 8 ++-- AcessNative/syscalls.h | 2 +- 9 files changed, 72 insertions(+), 29 deletions(-) diff --git a/AcessNative/acesskernel_src/main.c b/AcessNative/acesskernel_src/main.c index 8f03f9a4..609ea2ad 100644 --- a/AcessNative/acesskernel_src/main.c +++ b/AcessNative/acesskernel_src/main.c @@ -28,6 +28,7 @@ extern int VT_Install(char **Arguments); extern int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options); extern int VFS_MkDir(const char *Path); extern int SyscallServer(void); +extern int Server_Shutdown(void); extern const char gsKernelVersion[]; extern const char gsGitHash[]; extern int giBuildNumber; @@ -140,6 +141,7 @@ int main(int argc, char *argv[]) void AcessNative_Exit(void) { // TODO: Close client applications too + Server_Shutdown(); exit(0); } diff --git a/AcessNative/acesskernel_src/server.c b/AcessNative/acesskernel_src/server.c index bdc98795..1c03d307 100644 --- a/AcessNative/acesskernel_src/server.c +++ b/AcessNative/acesskernel_src/server.c @@ -138,7 +138,7 @@ int Server_WorkerThread(void *ClientPtr) ; Threads_SetThread( Client->ClientID ); - for( ;; ) + while( Client->ClientID != -1 ) { fd_set fds; int nfd = Client->Socket+1; @@ -176,7 +176,7 @@ int Server_WorkerThread(void *ClientPtr) // Oops. Log_Warning("Server", "FD%i too many params (%i > max %i)", Client->Socket, hdr->NParams, ciMaxParamCount); - continue ; + break ; } if( hdr->NParams > 0 ) @@ -185,6 +185,9 @@ int Server_WorkerThread(void *ClientPtr) Log_Debug("Server", "%i bytes of params", len); if( len != hdr->NParams*sizeof(tRequestValue) ) { // Oops. + perror("recv params"); + Log_Warning("Sever", "Recieving params failed"); + break ; } } else @@ -210,10 +213,23 @@ int Server_WorkerThread(void *ClientPtr) memcpy(hdr, lbuf, hdrsize); if( bufsize > hdrsize ) { - len = recv(Client->Socket, hdr->Params + hdr->NParams, bufsize - hdrsize, 0); - Log_Debug("Server", "%i bytes of data", len); - if( len != bufsize - hdrsize ) { - // Oops? + size_t rem = bufsize - hdrsize; + char *ptr = (void*)( hdr->Params + hdr->NParams ); + while( rem ) + { + len = recv(Client->Socket, ptr, rem, 0); + Log_Debug("Server", "%i bytes of data", len); + if( len == -1 ) { + // Oops? + perror("recv data"); + Log_Warning("Sever", "Recieving data failed"); + break ; + } + rem -= len; + ptr += len; + } + if( rem ) { + break; } } else @@ -240,11 +256,13 @@ int Server_WorkerThread(void *ClientPtr) int retSize = 0; int sentSize; int cur_client_id = 0; - for( ;; ) + while( Client->ClientID != -1 ) { // Wait for something to do - while( Client->CurrentRequest == NULL ) + if( Client->CurrentRequest == NULL ) SDL_CondWait(Client->WaitFlag, Client->Mutex); + if( Client->CurrentRequest == NULL ) + continue ; // Log_Debug("AcessSrv", "Worker got message %p", Client->CurrentRequest); @@ -364,6 +382,24 @@ int SyscallServer(void) return 0; } +int Server_Shutdown(void) +{ + close(gSocket); + for( int i = 0; i < MAX_CLIENTS; i ++ ) + { + if( gaServer_Clients[i].ClientID == 0 ) + continue ; + Threads_PostEvent( Threads_GetThread(gaServer_Clients[i].ClientID), 0 ); + gaServer_Clients[i].ClientID = -1; + #if USE_TCP + close(gaServer_Clients[i].Socket); + #else + SDL_CondSignal(gaServer_Clients[i].WaitFlag); + #endif + } + return 0; +} + int Server_ListenThread(void *Unused) { // Wait for something to do :) diff --git a/AcessNative/acesskernel_src/syscalls.c b/AcessNative/acesskernel_src/syscalls.c index b945df81..b636d81a 100644 --- a/AcessNative/acesskernel_src/syscalls.c +++ b/AcessNative/acesskernel_src/syscalls.c @@ -203,11 +203,11 @@ SYSCALL2(Syscall_GetMessage, "dd", uint32_t *, void *, Uint tmp; int rv; if( a0 ) { - rv = Proc_GetMessage(&tmp, a1); + rv = Proc_GetMessage(&tmp, Sizes[1], a1); *a0 = tmp; } else - rv = Proc_GetMessage(NULL, a1); + rv = Proc_GetMessage(NULL, Sizes[1], a1); return rv; ); diff --git a/AcessNative/acesskernel_src/threads.c b/AcessNative/acesskernel_src/threads.c index c31c5d05..9de6140b 100644 --- a/AcessNative/acesskernel_src/threads.c +++ b/AcessNative/acesskernel_src/threads.c @@ -400,7 +400,7 @@ void Threads_PostEvent(tThread *Thread, Uint32 Events) Thread->Events |= Events; Log_Debug("Threads", "Trigger event %x (->Events = %p)", Events, Thread->Events); - if( Thread->WaitMask & Events ) { + if( Events == 0 || Thread->WaitMask & Events ) { SDL_SemPost( Thread->EventSem ); // Log_Debug("Threads", "Waking %p(%i %s)", Thread, Thread->TID, Thread->ThreadName); } diff --git a/AcessNative/ld-acess_src/Makefile b/AcessNative/ld-acess_src/Makefile index 77cd2d17..805b3a5f 100644 --- a/AcessNative/ld-acess_src/Makefile +++ b/AcessNative/ld-acess_src/Makefile @@ -14,7 +14,7 @@ ifeq ($(PLATFORM),win) endif ifeq ($(PLATFORM),lin) BIN := ../ld-acess - LINKADDR := 0x200000 + LINKADDR := 0x70000000 # LD += -m elf_i386 endif @@ -22,8 +22,7 @@ CFLAGS += -Wall CFLAGS += -Werror CFLAGS += -g CPPFLAGS += -DARCHDIR_is_x86_64=1 -LDFLAGS += -g -# -Wl,-T,obj-$(PLATFORM)/link.ld +LDFLAGS += -g -Wl,-T,obj-$(PLATFORM)/link.ld DEPFILES = $(filter %.o,$(OBJ)) DEPFILES := $(DEPFILES:%=%.dep) @@ -46,7 +45,7 @@ obj-$(PLATFORM)/%.o: %.c @$(CC) -M $(CPPFLAGS) -MT $@ -o $@.dep $< # Modify the default makefile to put the executable at 1MB instead -obj-lin/link.ld: +obj-lin/link.ld: Makefile @mkdir -p $(dir $@) @echo "Making Linker Script ($@)" $(LD) -g --verbose | awk '{ if( substr($$1,0,5) == "====="){ bPrint = !bPrint; } else { if(bPrint){ print $$0;} } }' | sed 's/\b0x[048][0-9]*\b/$(LINKADDR)/g' | sed 's/CONSTANT (MAXPAGESIZE)/0x1000/g' > $@ diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index 9ee04f17..cd1924b2 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -95,6 +95,7 @@ int acess_seek(int FD, int64_t Ofs, int Dir) { uint64_t acess_tell(int FD) { if(FD & NATIVE_FILE_MASK) return native_tell( FD & (NATIVE_FILE_MASK-1) ); + DEBUG("tell(0x%x)", FD); return _Syscall(SYS_TELL, ">i", FD); } @@ -142,14 +143,17 @@ int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, time_t *t int acess__SysOpenChild(int fd, char *name, int flags) { + DEBUG("_SysOpenChild(0x%x, '%s', 0x%x)", fd, name, flags); return _Syscall(SYS_OPENCHILD, ">i >s >i", fd, name, flags); } int acess__SysGetACL(int fd, t_sysACL *dest) { + DEBUG("%s(0x%x, %p)", __func__, fd, dest); return _Syscall(SYS_GETACL, ">i s >s >s >s", Device, Directory, Type, Options); } @@ -175,7 +179,7 @@ int acess_clone(int flags, void *stack) extern int fork(void); if(flags & CLONE_VM) { int ret, newID, kernel_tid=0; - printf("USERSIDE fork()\n"); + Debug("USERSIDE fork()"); newID = _Syscall(SYS_AN_FORK, "i i >d", DestTID, Length, Data); } -int acess_SysGetMessage(int *SourceTID, void *Data) +int acess_SysGetMessage(int *SourceTID, int BufLen, void *Data) { -// static __thread int lastlen = 1024; - int lastlen; - - lastlen = _Syscall(SYS_GETMSG, "i", Mask); } diff --git a/AcessNative/ld-acess_src/main.c b/AcessNative/ld-acess_src/main.c index 0c9b7437..e4acbf06 100644 --- a/AcessNative/ld-acess_src/main.c +++ b/AcessNative/ld-acess_src/main.c @@ -137,7 +137,8 @@ void Notice(const char *Format, ...) void Debug(const char *Format, ...) { va_list args; - printf("[DEBUG %i] ", giSyscall_ClientID); + printf("[DEBUG "); + printf("%2i] ", giSyscall_ClientID); va_start(args, Format); vprintf(Format, args); va_end(args); diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index 3c691aa1..91b8de62 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -108,7 +108,7 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const break; // Data (special handling) case 'd': - len = va_arg(*Args, int); + len = va_arg(*Args, size_t); str = va_arg(*Args, char*); // Save the pointer for later @@ -116,7 +116,7 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const // Create parameter block Dest->Type = ARG_TYPE_DATA; - Dest->Length = len; + Dest->Length = str ? len : 0; Dest->Flags = 0; if( direction & 2 ) Dest->Flags |= ARG_FLAG_RETURN; @@ -124,7 +124,7 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const // Has data? if( direction & 1 ) { - if( DataDest ) + if( DataDest && str ) memcpy(DataDest, str, len); } else @@ -270,7 +270,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) free( req ); free( retPtrs ); - DEBUG(": %llx", retValue); + DEBUG(": %i 0x%llx", SyscallID, retValue); return retValue; } diff --git a/AcessNative/syscalls.h b/AcessNative/syscalls.h index 37bc88cc..e6dbd285 100644 --- a/AcessNative/syscalls.h +++ b/AcessNative/syscalls.h @@ -23,7 +23,7 @@ typedef struct sRequestValue { /// \see eArgumentTypes uint16_t Type; uint16_t Flags; - uint16_t Length; + uint32_t Length; } tRequestValue; typedef struct sRequestHeader { -- 2.20.1