From: John Hodge Date: Tue, 24 Jan 2012 14:20:02 +0000 (+0800) Subject: Integrating new event handling into userspace X-Git-Tag: rel0.15~792^2~16 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=29378c749590d455fd0931577e569d8584c26c90;p=tpg%2Facess2.git Integrating new event handling into userspace - GUI now should start nicely in SMP --- diff --git a/Kernel/include/syscalls.h b/Kernel/include/syscalls.h index 98bb9796..5ce28149 100644 --- a/Kernel/include/syscalls.h +++ b/Kernel/include/syscalls.h @@ -14,10 +14,10 @@ #define SYS_SETFAULTHANDLER 3 // Set signal Handler #define SYS_YIELD 4 // Yield remainder of timestamp #define SYS_SLEEP 5 // Sleep until messaged or signaled -#define SYS_WAIT 6 // Wait for a time or a message +#define SYS_WAITEVENT 6 // Wait for an event #define SYS_WAITTID 7 // Wait for a thread to do something -#define SYS_SETNAME 8 // Set's the name of the current thread -#define SYS_GETNAME 9 // Get's the name of a thread +#define SYS_SETNAME 8 // Sets the name of the current thread +#define SYS_GETNAME 9 // Gets the name of a thread #define SYS_GETTID 10 // Get current thread ID #define SYS_GETPID 11 // Get current thread group ID #define SYS_SETPRI 12 // Set process priority @@ -73,7 +73,7 @@ static const char *cSYSCALL_NAMES[] = { "SYS_SETFAULTHANDLER", "SYS_YIELD", "SYS_SLEEP", - "SYS_WAIT", + "SYS_WAITEVENT", "SYS_WAITTID", "SYS_SETNAME", "SYS_GETNAME", diff --git a/Kernel/include/syscalls.inc.asm b/Kernel/include/syscalls.inc.asm index 307e5829..149fe373 100644 --- a/Kernel/include/syscalls.inc.asm +++ b/Kernel/include/syscalls.inc.asm @@ -8,10 +8,10 @@ %define SYS_SETFAULTHANDLER 3 ;Set signal Handler %define SYS_YIELD 4 ;Yield remainder of timestamp %define SYS_SLEEP 5 ;Sleep until messaged or signaled -%define SYS_WAIT 6 ;Wait for a time or a message +%define SYS_WAITEVENT 6 ;Wait for an event %define SYS_WAITTID 7 ;Wait for a thread to do something -%define SYS_SETNAME 8 ;Set's the name of the current thread -%define SYS_GETNAME 9 ;Get's the name of a thread +%define SYS_SETNAME 8 ;Sets the name of the current thread +%define SYS_GETNAME 9 ;Gets the name of a thread %define SYS_GETTID 10 ;Get current thread ID %define SYS_GETPID 11 ;Get current thread group ID %define SYS_SETPRI 12 ;Set process priority diff --git a/Kernel/include/vfs_ext.h b/Kernel/include/vfs_ext.h index d7d74c40..a56d4557 100644 --- a/Kernel/include/vfs_ext.h +++ b/Kernel/include/vfs_ext.h @@ -353,10 +353,11 @@ extern int VFS_ReadDir(int FD, char *Dest); * \param WriteHandles Handles to wait to write to * \param ErrHandles Handle to wait for errors on * \param Timeout Timeout for select() (if null, there is no timeout), if zero select() is non blocking + * \param ExtraEvents Extra event set to wait on * \param IsKernel Use kernel handles as opposed to user handles * \return Number of handles that actioned */ -extern int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, BOOL IsKernel); +extern int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, Uint32 ExtraEvents, BOOL IsKernel); /** * \brief Map a file into memory diff --git a/Kernel/syscalls.c b/Kernel/syscalls.c index 35e48902..9c9737e6 100644 --- a/Kernel/syscalls.c +++ b/Kernel/syscalls.c @@ -10,6 +10,7 @@ #include #include #include +#include #define CHECK_NUM_NULLOK(v,size) \ if((v)&&!Syscall_Valid((size),(v))){ret=-1;err=-EINVAL;break;} @@ -75,7 +76,13 @@ void SyscallHandler(tSyscallRegs *Regs) err = -ENOSYS; ret = -1; break; - + + // -- Wait fr an event + case SYS_WAITEVENT: + // Message mask + ret = Threads_WaitEvents(Regs->Arg1); + break; + // -- Wait for a thread case SYS_WAITTID: // Sanity Check (Status can be NULL) @@ -307,6 +314,7 @@ void SyscallHandler(tSyscallRegs *Regs) (fd_set *)Regs->Arg3, // Write (fd_set *)Regs->Arg4, // Errors (tTime *)Regs->Arg5, // Timeout + (Uint32)Regs->Arg6, // Extra wakeup events 0 // User handles ); break; diff --git a/Kernel/syscalls.lst b/Kernel/syscalls.lst index 826249dc..283caf9c 100644 --- a/Kernel/syscalls.lst +++ b/Kernel/syscalls.lst @@ -6,11 +6,11 @@ SYS_KILL Send a signal SYS_SETFAULTHANDLER Set signal Handler SYS_YIELD Yield remainder of timestamp SYS_SLEEP Sleep until messaged or signaled -SYS_WAIT Wait for a time or a message +SYS_WAITEVENT Wait for an event SYS_WAITTID Wait for a thread to do something -SYS_SETNAME Set's the name of the current thread -SYS_GETNAME Get's the name of a thread +SYS_SETNAME Sets the name of the current thread +SYS_GETNAME Gets the name of a thread SYS_GETTID Get current thread ID SYS_GETPID Get current thread group ID SYS_SETPRI Set process priority diff --git a/Kernel/vfs/select.c b/Kernel/vfs/select.c index c87e316b..e8658bac 100644 --- a/Kernel/vfs/select.c +++ b/Kernel/vfs/select.c @@ -42,7 +42,7 @@ struct sVFS_SelectList // === PROTOTYPES === // int VFS_SelectNode(tVFS_Node *Node, enum eVFS_SelectTypes Type, tTime *Timeout); -// int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, BOOL IsKernel); +// int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, Uint32 ExtraEvents, BOOL IsKernel); // int VFS_MarkFull(tVFS_Node *Node, BOOL IsBufferFull); // int VFS_MarkAvaliable(tVFS_Node *Node, BOOL IsDataAvaliable); // int VFS_MarkError(tVFS_Node *Node, BOOL IsErrorState); @@ -114,7 +114,7 @@ int VFS_SelectNode(tVFS_Node *Node, int TypeFlags, tTime *Timeout, const char *N return ret; } -int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, BOOL IsKernel) +int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, Uint32 ExtraEvents, BOOL IsKernel) { tThread *thisthread = Proc_GetCurThread(); int ret; @@ -154,7 +154,7 @@ int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set { // TODO: Timeout // TODO: Allow extra events to be waited upon - Threads_WaitEvents( THREAD_EVENT_VFS ); + Threads_WaitEvents( THREAD_EVENT_VFS|ExtraEvents ); } // Fill output (modify *Handles) diff --git a/Usermode/Applications/axwin3_src/WM/main.c b/Usermode/Applications/axwin3_src/WM/main.c index a9c34b74..b8f3065c 100644 --- a/Usermode/Applications/axwin3_src/WM/main.c +++ b/Usermode/Applications/axwin3_src/WM/main.c @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) IPC_FillSelect(&nfds, &fds); nfds ++; - if( select(nfds, &fds, NULL, NULL, NULL) == -1 ) { + if( _SysSelect(nfds, &fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG) == -1 ) { _SysDebug("ERROR: select() returned -1"); return -1; } diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c index c1d562f3..b03d64d0 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c @@ -122,7 +122,7 @@ tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(void) { case CONNTYPE_SENDMESSAGE: // TODO: Less hack, I need a version of select for GetMessage etc - if(SysGetMessage(NULL, NULL) == 0) sleep(); + if(SysGetMessage(NULL, NULL) == 0) _SysWaitEvent(THREAD_EVENT_IPCMSG); while(SysGetMessage(NULL, NULL)) { pid_t tid; diff --git a/Usermode/Libraries/ld-acess.so_src/Makefile b/Usermode/Libraries/ld-acess.so_src/Makefile index 585e7108..49afb1e1 100644 --- a/Usermode/Libraries/ld-acess.so_src/Makefile +++ b/Usermode/Libraries/ld-acess.so_src/Makefile @@ -5,7 +5,7 @@ -include ../Makefile.cfg OBJ := main.o lib.o loadlib.o export.o elf.o pe.o -OBJ += arch/$(ARCHDIR).ao +OBJ += arch/$(ARCHDIR).ao_ BIN = ld-acess.so EXTRABIN := libld-acess.so EXTRACLEAN := $(_OBJPREFIX)_stublib.o @@ -24,16 +24,18 @@ $(_XBIN): $(_OBJPREFIX)_stublib.o # Override .ao to look in the object prefix for the source -%.ao: %.$(ASSUFFIX) +$(_OBJPREFIX)arch/$(ARCHDIR).ao_: $(_OBJPREFIX)arch/$(ARCHDIR).$(ASSUFFIX) @echo [AS] -o $@ @mkdir -p $(dir $@) @$(AS) $(ASFLAGS) -o $@ $< -.PRECIOUS: $(OBJ:%.ao=%.asm) +#.PRECIOUS: $(OBJ:%.ao=%.asm) # Preprocessing objects if needed -$(_OBJPREFIX)%: %.h +$(_OBJPREFIX)arch/$(ARCHDIR).$(ASSUFFIX): arch/$(ARCHDIR).$(ASSUFFIX).h arch/syscalls.s.h @echo [CPP] -o $@ @mkdir -p $(dir $@) @$(CPP) $(CPPFLAGS) -P -D__ASSEMBLER__ $< -o $@ +$(_OBJPREFIX)_stublib.o: arch/syscalls.s.h + diff --git a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h index 1c7a5bb0..b27fa71e 100644 --- a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h +++ b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h @@ -5,6 +5,7 @@ SYSCALL2(clone, SYS_CLONE) SYSCALL2(kill, SYS_KILL) SYSCALL0(yield, SYS_YIELD) SYSCALL0(sleep, SYS_SLEEP) +SYSCALL1(_SysWaitEvent, SYS_WAITEVENT) SYSCALL2(waittid, SYS_WAITTID) SYSCALL0(gettid, SYS_GETTID) @@ -47,6 +48,6 @@ SYSCALL2(_SysGetACL,SYS_GETACL) // int, void* SYSCALL1(chdir, SYS_CHDIR) // char* SYSCALL3(ioctl, SYS_IOCTL) // int, int, void* SYSCALL4(_SysMount, SYS_MOUNT) // char*, char*, char*, char* -SYSCALL5(select, SYS_SELECT) // int, fd_set*, fd_set*, fd_set*, tTime* +SYSCALL6(_SysSelect, SYS_SELECT) // int, fd_set*, fd_set*, fd_set*, tTime*, uint32_t SYSCALL3(_SysOpenChild, SYS_OPENCHILD) diff --git a/Usermode/Libraries/ld-acess.so_src/export.c b/Usermode/Libraries/ld-acess.so_src/export.c index 2da0e6b2..5e614e1e 100644 --- a/Usermode/Libraries/ld-acess.so_src/export.c +++ b/Usermode/Libraries/ld-acess.so_src/export.c @@ -27,6 +27,7 @@ const struct { EXP(kill), EXP(yield), EXP(sleep), + EXP(_SysWaitEvent), EXP(waittid), EXP(gettid), EXP(getpid), @@ -64,7 +65,7 @@ const struct { EXP(chdir), EXP(ioctl), EXP(_SysMount), - EXP(select), + EXP(_SysSelect), EXP(_SysOpenChild), diff --git a/Usermode/include/acess/sys.h b/Usermode/include/acess/sys.h index 6d7751b9..e1a78a7f 100644 --- a/Usermode/include/acess/sys.h +++ b/Usermode/include/acess/sys.h @@ -12,6 +12,10 @@ # define NULL ((void*)0) #endif +#define THREAD_EVENT_VFS 0x0001 +#define THREAD_EVENT_IPCMSG 0x0002 +#define THREAD_EVENT_SIGNAL 0x0004 + #define OPENFLAG_EXEC 0x01 #define OPENFLAG_READ 0x02 #define OPENFLAG_WRITE 0x04 @@ -38,7 +42,8 @@ extern void _exit(int status) __attribute__((noreturn)); extern void sleep(void); extern void yield(void); extern int kill(int pid, int sig); -extern void wait(int miliseconds); +//extern void wait(int miliseconds); +extern int _SysWaitEvent(int EventMask); extern int waittid(int id, int *status); extern int clone(int flags, void *stack); extern int execve(char *path, char **argv, char **envp); @@ -69,7 +74,8 @@ extern int readdir(int fd, char *dest); extern int _SysOpenChild(int fd, char *name, int flags); extern int _SysGetACL(int fd, t_sysACL *dest); extern int _SysMount(const char *Device, const char *Directory, const char *Type, const char *Options); -extern int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errfds, time_t *timeout); +extern int _SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *err, time_t *timeout, int extraevents); +#define select(nfs, rdfds, wrfds, erfds, timeout) _SysSelect(nfs, rdfds, wrfds, erfds, timeout, 0) // --- IPC --- extern int SysSendMessage(pid_t dest, uint length, const void *Data);