From: Matthias Kruk Date: Tue, 14 Jan 2020 11:27:24 +0000 (+0900) Subject: Implement functions for manipulating sigset_t types in klibc X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=3a164ff652f52bda737c17c00e79bbbd8af742c3;p=corax Implement functions for manipulating sigset_t types in klibc - sigemptyset() - sigfillset() - sigaddset() - sigdelset() - sigismember() --- diff --git a/kernel/klibc/Makefile b/kernel/klibc/Makefile index c18bc92..f029acd 100644 --- a/kernel/klibc/Makefile +++ b/kernel/klibc/Makefile @@ -1,5 +1,5 @@ OUTPUT = klibc.a -OBJECTS = string.o spinlock.o mutex.o posixcall.o coraxcall.o heap.o stdio.o +OBJECTS = string.o spinlock.o mutex.o posixcall.o coraxcall.o heap.o stdio.o signal.o PHONY = clean INCLUDES = -I../include -I../../include -I../.. CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding $(INCLUDES) diff --git a/kernel/klibc/signal.c b/kernel/klibc/signal.c new file mode 100644 index 0000000..07891fa --- /dev/null +++ b/kernel/klibc/signal.c @@ -0,0 +1,77 @@ +#include +#include +#include + +/* FIXME: Update errno so that callers can tell what went wrong */ + +#define __SIGIDX(i) ((i) / (sizeof(((sigset_t*)0)->val[0]) * 8)) +#define __SIGBIT(i) ((i) & ((sizeof(((sigset_t*)0)->val[0]) * 8) - 1)) + +int sigemptyset(sigset_t *set) +{ + int error; + + error = EINVAL; + + if(set) { + memset(set, 0, sizeof(*set)); + error = 0; + } + + return(error ? -1 : 0); +} + +int sigfillset(sigset_t *set) +{ + int error; + + error = EINVAL; + + if(set) { + memset(set, 0xff, sizeof(*set)); + error = 0; + } + + return(error ? -1 : 0); +} + +int sigaddset(sigset_t *set, int sig) +{ + int error; + + error = EINVAL; + + if(set) { + set->val[__SIGIDX(sig)] |= (1 << __SIGBIT(sig)); + error = 0; + } + + return(error ? -1 : 0); +} + +int sigdelset(sigset_t *set, int sig) +{ + int error; + + error = EINVAL; + + if(set) { + set->val[__SIGIDX(sig)] &= ~(1 << __SIGBIT(sig)); + error = 0; + } + + return(error ? -1 : 0); +} + +int sigismember(const sigset_t *set, int sig) +{ + int ret_val; + + ret_val = -1; + + if(set) { + ret_val = set->val[__SIGIDX(sig)] & (1 << __SIGBIT(sig)) ? 1 : 0; + } + + return(ret_val); +}