Skip to content

Commit

Permalink
ipc: refined signal handler structures
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Nov 20, 2024
1 parent 95197ac commit c102c4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/include/kernel/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct sigaction {
union {
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t *, void *);
} handler;
};

sigset_t sa_mask;
int sa_flags;
Expand Down
12 changes: 6 additions & 6 deletions src/ipc/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ int sigismember(sigset_t *set, int signum) {
*/

void *signalDefaults() {
uintptr_t *ptr = malloc((MAX_SIGNAL+1) * sizeof(uintptr_t));
struct sigaction *ptr = malloc((MAX_SIGNAL+1) * sizeof(struct sigaction));
if(!ptr) return NULL;

for(int i = 0; i < MAX_SIGNAL; i++)
ptr[i] = (uintptr_t) SIG_DFL; // default
ptr[i].sa_handler = SIG_DFL; // default

return (void *) ptr;
}
Expand Down Expand Up @@ -148,10 +148,10 @@ int signalDefaultHandler(int signum) {
void *signalClone(const void *h) {
if(!h) return signalDefaults();

void *new = malloc((MAX_SIGNAL+1) * sizeof(uintptr_t));
void *new = malloc((MAX_SIGNAL+1) * sizeof(struct sigaction));
if(!new) return NULL;

return memcpy(new, h, (MAX_SIGNAL+1) * sizeof(uintptr_t));
return memcpy(new, h, (MAX_SIGNAL+1) * sizeof(struct sigaction));
}

/* kill(): sends a signal to a process or thread
Expand Down Expand Up @@ -258,8 +258,8 @@ void signalHandle(Thread *t) {
releaseLock(&t->lock);

int signum = s->signum;
uintptr_t *handlers = (uintptr_t *) t->signals;
uintptr_t handler = handlers[signum];
struct sigaction *handlers = (struct sigaction *) t->signals;
uintptr_t handler = (uintptr_t) handlers[signum].sa_handler;
int def = 0;

free(s);
Expand Down

0 comments on commit c102c4b

Please sign in to comment.