AcessNative - Bugfixes 'r' us, GUI can start and render (partially)
authorJohn Hodge <[email protected]>
Thu, 4 Oct 2012 13:47:03 +0000 (21:47 +0800)
committerJohn Hodge <[email protected]>
Thu, 4 Oct 2012 13:47:03 +0000 (21:47 +0800)
AcessNative/acesskernel_src/main.c
AcessNative/acesskernel_src/server.c
AcessNative/acesskernel_src/syscalls.c
AcessNative/acesskernel_src/threads.c
AcessNative/ld-acess_src/Makefile
AcessNative/ld-acess_src/exports.c
AcessNative/ld-acess_src/main.c
AcessNative/ld-acess_src/syscalls.c
AcessNative/syscalls.h

index 8f03f9a..609ea2a 100644 (file)
@@ -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);
 }
 
index bdc9879..1c03d30 100644 (file)
@@ -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 :)
index b945df8..b636d81 100644 (file)
@@ -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;
 );
 
index c31c5d0..9de6140 100644 (file)
@@ -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);
        }
index 77cd2d1..805b3a5 100644 (file)
@@ -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 [email protected] $<
 
 # 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' > $@
index 9ee04f1..cd1924b 100644 (file)
@@ -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 <d", fd, sizeof(t_sysACL), dest);
 }
 
 int acess__SysMount(const char *Device, const char *Directory, const char *Type, const char *Options) {
+       DEBUG("%s('%s', '%s', '%s', '%s')", __func__, Device, Directory, Type, Options);
        return _Syscall(SYS_MOUNT, ">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, "<d", sizeof(int), &kernel_tid);
                ret = fork();
@@ -246,11 +250,13 @@ int acess_execve(char *path, char **argv, char **envp)
 
 void acess_sleep(void)
 {
+       DEBUG("%s()", __func__);
        _Syscall(SYS_SLEEP, "");
 }
 
 int acess_waittid(int TID, int *ExitStatus)
 {
+       DEBUG("%s(%i, %p)", __func__, TID, ExitStatus);
        return _Syscall(SYS_WAITTID, ">i <d", TID, sizeof(int), &ExitStatus);
 }
 
@@ -263,23 +269,22 @@ int acess_getgid(void) { return _Syscall(SYS_GETGID, ""); }
 
 int acess_SysSendMessage(int DestTID, int Length, void *Data)
 {
+       DEBUG("%s(%i, 0x%x, %p)", __func__, DestTID, Length, Data);
        return _Syscall(SYS_SENDMSG, ">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, "<d <d",
+       DEBUG("%s(%p, %p)", __func__, SourceTID, Data);
+       return _Syscall(SYS_GETMSG, "<d <d",
                SourceTID ? sizeof(uint32_t) : 0, SourceTID,
-               Data ? 1024 : 0, Data
+               BufLen, Data
                );
-       return lastlen;
 }
 
 int acess__SysWaitEvent(int Mask)
 {
+       DEBUG("%s(%x)", __func__, Mask);
        return _Syscall(SYS_WAITEVENT, ">i", Mask);
 }
 
index 0c9b743..e4acbf0 100644 (file)
@@ -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);
index 3c691aa..91b8de6 100644 (file)
@@ -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;
 }
index 37bc88c..e6dbd28 100644 (file)
@@ -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 {

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