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;
void AcessNative_Exit(void)
{
// TODO: Close client applications too
+ Server_Shutdown();
exit(0);
}
;
Threads_SetThread( Client->ClientID );
- for( ;; )
+ while( Client->ClientID != -1 )
{
fd_set fds;
int nfd = Client->Socket+1;
// Oops.
Log_Warning("Server", "FD%i too many params (%i > max %i)",
Client->Socket, hdr->NParams, ciMaxParamCount);
- continue ;
+ break ;
}
if( hdr->NParams > 0 )
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
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
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);
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 :)
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;
);
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);
}
endif
ifeq ($(PLATFORM),lin)
BIN := ../ld-acess
- LINKADDR := 0x200000
+ LINKADDR := 0x70000000
# LD += -m elf_i386
endif
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)
# 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' > $@
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);
}
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);
}
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();
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);
}
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);
}
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);
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
// 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;
// Has data?
if( direction & 1 )
{
- if( DataDest )
+ if( DataDest && str )
memcpy(DataDest, str, len);
}
else
free( req );
free( retPtrs );
- DEBUG(": %llx", retValue);
+ DEBUG(": %i 0x%llx", SyscallID, retValue);
return retValue;
}
/// \see eArgumentTypes
uint16_t Type;
uint16_t Flags;
- uint16_t Length;
+ uint32_t Length;
} tRequestValue;
typedef struct sRequestHeader {