diff --git a/TODO b/TODO index d3b707e..d2ba510 100644 --- a/TODO +++ b/TODO @@ -2,6 +2,7 @@ CHECK - Implement guardians. CHECK - clean up after file ports are dead by flushing/closing the underlying file handle. + - Flush and close output-port on exit. * Interrupts: - pcb should have an engine-counter field that's decremented on diff --git a/lab/interrupts/Makefile b/lab/interrupts/Makefile new file mode 100644 index 0000000..aa1bc1d --- /dev/null +++ b/lab/interrupts/Makefile @@ -0,0 +1,6 @@ + +all: main + +main: inf_loop.s main.c + gcc -o main inf_loop.s main.c + diff --git a/lab/interrupts/inf_loop.s b/lab/interrupts/inf_loop.s new file mode 100644 index 0000000..a46cefe --- /dev/null +++ b/lab/interrupts/inf_loop.s @@ -0,0 +1,8 @@ + +.globl _inf_loop + +_inf_loop: + movl %esp, %eax + movl $0, %esp +L_loop: + jmp L_loop diff --git a/lab/interrupts/main b/lab/interrupts/main new file mode 100755 index 0000000..bb8c24d Binary files /dev/null and b/lab/interrupts/main differ diff --git a/lab/interrupts/main.c b/lab/interrupts/main.c new file mode 100644 index 0000000..96c2959 --- /dev/null +++ b/lab/interrupts/main.c @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +extern void inf_loop(); +void register_handlers(); +void register_alt_stack(); + +int main(int argc, char** argv){ + fprintf(stderr, "Entering ... \n"); + register_handlers(); + register_alt_stack(); + inf_loop(); + fprintf(stderr, "Done\n"); + return 0; +} + +#if 0 + #include + + struct sigaction { + union { + void (*__sa_handler)(int); + void (*__sa_sigaction)(int, struct __siginfo *, void *); + } __sigaction_u; /* signal handler */ + int sa_flags; /* see signal options below */ + sigset_t sa_mask; /* signal mask to apply */ + }; + + #define sa_handler __sigaction_u.__sa_handler + #define sa_sigaction __sigaction_u.__sa_sigaction + + int + sigaction(int sig, const struct sigaction * restrict act, + struct sigaction * restrict oact); +#endif + +void handler(int signo, struct __siginfo* info, ucontext_t* uap){ + fprintf(stderr, "Handler Called!\n"); +} + +void +register_handlers(){ + struct sigaction sa; + sa.sa_sigaction = (void(*)(int,struct __siginfo*,void*)) handler; + sa.sa_flags = SA_SIGINFO | SA_ONSTACK; + sa.sa_mask = 0; + int err = sigaction(SIGINT, &sa, 0); + if(err){ + fprintf(stderr, "Sigaction Failed: %s\n", strerror(errno)); + exit(-1); + } +} + + +#if 0 +SYNOPSIS + #include + #include + + struct sigaltstack { + char *ss_sp; + int ss_size; + int ss_flags; + }; + + int + sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss); +#endif + +void +register_alt_stack(){ + char* stk = malloc(SIGSTKSZ); + if(stk == 0){ + fprintf(stderr, "Cannot maloc an alt stack\n"); + exit(-1); + } + + struct sigaltstack sa; + sa.ss_sp = stk; + sa.ss_size = SIGSTKSZ; + sa.ss_flags = 0; + int err = sigaltstack(&sa, 0); + if(err){ + fprintf(stderr, "Cannot set alt stack: %s\n", strerror(errno)); + exit(-1); + } + fprintf(stderr, "alt-stack of size %d set\n", SIGSTKSZ); +}