From 902abebefe10e5e8bc9d80b73e46bcb1635f0be8 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Mon, 30 Jul 2018 02:09:12 +1000 Subject: Fixed a bug where the tick_handler() and sigret() functions did not pass a pointer to the saved state information to check_signals(). This bug would have only manifested itself if multiple signals were to be processed (sigret) or if a signal had been set during the handling of a timer interrupt (tick_handler) and *ONLY* if switching to the user's own handler since the state information is not needed to invoke the kernel's default signal handler. Implemented alarms for userspace processes. This required significant modification of the scheduler algorithm. When idling waiting for a process that can run, the scheduler now continually checks the alarms and signals of each process and updates their state accordingly. Implemented the sys_alarm system call to set the new 'alarm' field for the calling process. Created the sys_pause system call which changes the state of the calling process to TSTATE_INTERRUPTIBLE, effectively removing it from the scheduler's run queue, putting it to sleep until a signal arrives. --- include/kernel/sched.h | 2 ++ include/kernel/sys.h | 6 ++++-- include/time.h | 2 ++ include/unistd.h | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/kernel/sched.h b/include/kernel/sched.h index 3d6699c..6b0488e 100644 --- a/include/kernel/sched.h +++ b/include/kernel/sched.h @@ -50,6 +50,7 @@ struct task_struct { pid_t pid; int state; uint32_t signal; + unsigned int alarm; void *sig_handlers[NRSIG]; struct tss_struct tss; } __attribute__((packed)); @@ -58,5 +59,6 @@ extern struct task_struct *ctask; extern uint32_t ticks; void sched_init(void); +void reschedule(void); #endif diff --git a/include/kernel/sys.h b/include/kernel/sys.h index 2ec4490..ba2dc0c 100644 --- a/include/kernel/sys.h +++ b/include/kernel/sys.h @@ -6,6 +6,8 @@ extern int sys_getpid(void); extern int sys_getpdir(void); extern int sys_signal(void); extern int sys_rsputs(void); +extern int sys_alarm(void); +extern int sys_pause(void); extern int sys_dummy(void); syscall_t call_table[256] = { @@ -15,8 +17,8 @@ syscall_t call_table[256] = { [3] = &sys_getpdir, [4] = &sys_signal, [5] = &sys_rsputs, - [6] = &sys_dummy, - [7] = &sys_dummy, + [6] = &sys_alarm, + [7] = &sys_pause, [8] = &sys_dummy, [9] = &sys_dummy, [10] = &sys_dummy, diff --git a/include/time.h b/include/time.h index 732d33f..feb2225 100644 --- a/include/time.h +++ b/include/time.h @@ -10,6 +10,8 @@ typedef int32_t time_t; time_t time(void); +int alarm(unsigned int seconds); + void sleep(time_t); #endif diff --git a/include/unistd.h b/include/unistd.h index a784e22..30d41c6 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -11,6 +11,8 @@ typedef uint16_t pid_t; #define __SYS_getpdir 3 #define __SYS_signal 4 #define __SYS_rsputs 5 +#define __SYS_alarm 6 +#define __SYS_pause 7 #define _syscall0(type, name) \ type name(void) { \ @@ -37,4 +39,6 @@ typedef uint16_t pid_t; pid_t getpid(void); void *getpdir(void); +int pause(void); + #endif -- cgit v1.3