]> git.corax.cc Git - corax/commitdiff
Implement functions for manipulating sigset_t types in klibc
authorMatthias Kruk <m@m10k.eu>
Tue, 14 Jan 2020 11:27:24 +0000 (20:27 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 14 Jan 2020 11:27:24 +0000 (20:27 +0900)
 - sigemptyset()
 - sigfillset()
 - sigaddset()
 - sigdelset()
 - sigismember()

kernel/klibc/Makefile
kernel/klibc/signal.c [new file with mode: 0644]

index c18bc92b2a99fc7c917976dada5c2ab808dfc4f0..f029acd26be81dd75e5b3cda91fb86aabd052534 100644 (file)
@@ -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 (file)
index 0000000..07891fa
--- /dev/null
@@ -0,0 +1,77 @@
+#include <corax/errno.h>
+#include <signal.h>
+#include <string.h>
+
+/* 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);
+}