ref: 9765e95b59e0b020c32609b69cf573c597857abf
parent: 54289f10c0e558019e9ffd49274f8008c909680d
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Oct 2 17:42:30 EDT 2021
libc: Fix sigaction() for OpenBSD OpenBSD had the same sigaction() implementation than NetBSD, but the implementation of OpenBSD is much simpler and we only have to call the syscall.
--- /dev/null
+++ b/include/bits/openbsd/amd64/arch/sigaction.h
@@ -1,0 +1,15 @@
+typedef unsigned int sigset_t;
+typedef struct siginfo siginfo_t;
+
+struct sigaction {
+ union {
+ void (*__sa_handler)(int);
+ void (*__sa_sigaction)(int, siginfo_t *, void *);
+ } __sigaction_u;
+
+ sigset_t sa_mask;
+ int sa_flags;
+};
+
+#define sa_handler __sigaction_u.__sa_handler
+#define sa_sigaction __sigaction_u.__sa_sigaction
--- /dev/null
+++ b/include/bits/openbsd/amd64/arch/stdint.h
@@ -1,0 +1,115 @@
+#define INT8_MAX 0x7F
+#define INT8_MIN (-INT8_MAX-1)
+#define UINT8_MAX 0xFF
+
+#define INT16_MAX 0x7FFF
+#define INT16_MIN (-INT16_MAX-1)
+#define UINT16_MAX 0xFFFF
+
+#define INT32_MAX 0x7FFFFFFF
+#define INT32_MIN (-INT32_MAX-1)
+#define UINT32_MAX 0xFFFFFFFF
+
+#define INT64_MAX 0x7FFFFFFFFFFFFFFF
+#define INT64_MIN (-INT64_MAX-1)
+#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
+
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+
+#define INT_LEAST16_MIN INT32_MIN
+#define INT_LEAST16_MAX INT32_MAX
+#define UINT_LEAST16_MAX UINT32_MAX
+
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INT_FAST8_MIN INT32_MIN
+#define INT_FAST8_MAX INT32_MAX
+#define UINT_FAST8_MAX UINT32_MAX
+
+#define INT_FAST16_MIN INT32_MIN
+#define INT_FAST16_MAX INT32_MAX
+#define UINT_FAST16_MAX UINT32_MAX
+
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define INTPTR_MIN INT64_MIN
+#define INTPTR_MAX INT64_MAX
+#define UINTPTR_MAX UINT64_MAX
+
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define PTRDIFF_MIN INT64_MIN
+#define PTRDIFF_MAX INT64_MAX
+
+#define SIG_ATOMIC_MIN INT32_MIN
+#define SIG_ATOMIC_MAX INT32_MAX
+
+#define SIZE_MAX UINT64_MAX
+
+#define WCHAR_MIN INT32_MIN
+#define WCHAR_MAX INT32_MAX
+
+#define INT8_C(x) x
+#define INT16_C(x) x
+#define INT32_C(x) x
+#define INT64_C(x) x ## LL
+
+#define UINT8_C(x) x
+#define UINT16_C(x) x
+#define UINT32_C(x) x ## U
+#define UINT64_C(x) x ## ULL
+
+#define INTMAX_C(x) x ## LL
+#define UINTMAX_C(x) x ## ULL
+
+typedef signed char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned uint32_t;
+typedef unsigned long uint64_t;
+
+typedef signed char int_least8_t;
+typedef short int_least16_t;
+typedef int int_least32_t;
+typedef long int_least64_t;
+
+typedef unsigned char uint_least8_t;
+typedef unsigned short uint_least16_t;
+typedef unsigned uint_least32_t;
+typedef unsigned long uint_least64_t;
+
+typedef int int_fast8_t;
+typedef int int_fast16_t;
+typedef int int_fast32_t;
+typedef int int_fast64_t;
+
+typedef unsigned uint_fast8_t;
+typedef unsigned uint_fast16_t;
+typedef unsigned uint_fast32_t;
+typedef unsigned long uint_fast64_t;
+
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+
+typedef long intmax_t;
+typedef unsigned long uintmax_t;
--- /dev/null
+++ b/include/bits/openbsd/amd64/arch/time.h
@@ -1,0 +1,5 @@
+#define _MAXYEAR 9999
+
+typedef long time_t;
+typedef long clock_t;
+typedef long __suseconds_t;
--- a/include/bits/openbsd/amd64/stdint.h
+++ /dev/null
@@ -1,115 +1,0 @@
-#define INT8_MAX 0x7F
-#define INT8_MIN (-INT8_MAX-1)
-#define UINT8_MAX 0xFF
-
-#define INT16_MAX 0x7FFF
-#define INT16_MIN (-INT16_MAX-1)
-#define UINT16_MAX 0xFFFF
-
-#define INT32_MAX 0x7FFFFFFF
-#define INT32_MIN (-INT32_MAX-1)
-#define UINT32_MAX 0xFFFFFFFF
-
-#define INT64_MAX 0x7FFFFFFFFFFFFFFF
-#define INT64_MIN (-INT64_MAX-1)
-#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
-
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-
-#define INT_LEAST16_MIN INT32_MIN
-#define INT_LEAST16_MAX INT32_MAX
-#define UINT_LEAST16_MAX UINT32_MAX
-
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN INT32_MIN
-#define INT_FAST8_MAX INT32_MAX
-#define UINT_FAST8_MAX UINT32_MAX
-
-#define INT_FAST16_MIN INT32_MIN
-#define INT_FAST16_MAX INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTPTR_MIN INT64_MIN
-#define INTPTR_MAX INT64_MAX
-#define UINTPTR_MAX UINT64_MAX
-
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT64_MIN
-#define PTRDIFF_MAX INT64_MAX
-
-#define SIG_ATOMIC_MIN INT32_MIN
-#define SIG_ATOMIC_MAX INT32_MAX
-
-#define SIZE_MAX UINT64_MAX
-
-#define WCHAR_MIN INT32_MIN
-#define WCHAR_MAX INT32_MAX
-
-#define INT8_C(x) x
-#define INT16_C(x) x
-#define INT32_C(x) x
-#define INT64_C(x) x ## LL
-
-#define UINT8_C(x) x
-#define UINT16_C(x) x
-#define UINT32_C(x) x ## U
-#define UINT64_C(x) x ## ULL
-
-#define INTMAX_C(x) x ## LL
-#define UINTMAX_C(x) x ## ULL
-
-typedef signed char int8_t;
-typedef short int16_t;
-typedef int int32_t;
-typedef long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned uint32_t;
-typedef unsigned long uint64_t;
-
-typedef signed char int_least8_t;
-typedef short int_least16_t;
-typedef int int_least32_t;
-typedef long int_least64_t;
-
-typedef unsigned char uint_least8_t;
-typedef unsigned short uint_least16_t;
-typedef unsigned uint_least32_t;
-typedef unsigned long uint_least64_t;
-
-typedef int int_fast8_t;
-typedef int int_fast16_t;
-typedef int int_fast32_t;
-typedef int int_fast64_t;
-
-typedef unsigned uint_fast8_t;
-typedef unsigned uint_fast16_t;
-typedef unsigned uint_fast32_t;
-typedef unsigned long uint_fast64_t;
-
-typedef long intptr_t;
-typedef unsigned long uintptr_t;
-
-typedef long intmax_t;
-typedef unsigned long uintmax_t;
--- a/include/bits/openbsd/amd64/time.h
+++ /dev/null
@@ -1,5 +1,0 @@
-#define _MAXYEAR 9999
-
-typedef long time_t;
-typedef long clock_t;
-typedef long __suseconds_t;
--- a/include/bits/openbsd/sys.h
+++ b/include/bits/openbsd/sys.h
@@ -12,11 +12,7 @@
typedef int pid_t;
-struct sigaction {
- void (*sa_handler)(int);
- int sa_mask;
- int sa_flags;
-};
+struct sigaction;
extern pid_t _getpid(void);
extern int _kill(pid_t pid, int signum);
--- a/src/libc/arch/Makefile
+++ b/src/libc/arch/Makefile
@@ -3,24 +3,27 @@
PROJECTDIR = ../../..
DIRS =\
+ $(ARCHS)\
+ $(SYSTEMS)\
+ posix\
+
+ARCHS =\
amd64\
arm64\
arm\
- darwin\
- dragonfly\
i386\
- linux\
- netbsd\
- openbsd\
- posix\
ppc\
-BSD =\
+POSIX =\
netbsd\
openbsd\
darwin\
dragonfly\
+ linux\
+SYSTEM =\
+ $(POSIX)\
+
include $(PROJECTDIR)/scripts/rules.mk
include ../rules.mk
@@ -28,6 +31,4 @@
all: $(ARCH) $(SYS)
-linux: posix
-
-$(BSD): bsd
+$(POSIX): posix
--- a/src/libc/arch/amd64/openbsd/.gitignore
+++ b/src/libc/arch/amd64/openbsd/.gitignore
@@ -7,6 +7,5 @@
_open.s
_read.s
_sigaction.s
-_sigaction2.s
_sys_errlist.c
_write.s
--- a/src/libc/arch/amd64/openbsd/Makefile
+++ b/src/libc/arch/amd64/openbsd/Makefile
@@ -13,27 +13,23 @@
_lseek.$O\
_open.$O\
_read.$O\
- _sigaction2.$O\
+ _sigaction.$O\
_write.$O\
-GENSRC = $(GENOBJS:.$O=.s)
-
OBJS =\
$(GENOBJS)\
_sys_errlist.$O\
-all: $(LIBC) $(CRT)
+GENSRC = $(GENOBJS:.$O=.s)
-$(LIBC): $(OBJS)
- $(MKLST)
+all: $(OBJS) $(CRT)
-crt.$O: ../crt-posix.s ../openbsd/crt.s
+$(CRT): ../crt-posix.s ../openbsd/crt.s
$(GENSRC): syscall.lst
./gensys.sh $(@:.s=)
clean:
- rm -f $(GENSRC)
- rm -f syscall _sys_errlist.c
+ rm -f $(GENSRC) _sys_errlist.c
include deps.mk
--- a/src/libc/arch/amd64/openbsd/syscall.lst
+++ b/src/libc/arch/amd64/openbsd/syscall.lst
@@ -7,6 +7,6 @@
6 _close 1
17 _brk 1
20 _getpid 0
-46 _sigaction2 5
+46 _sigaction 3
122 _kill 2
198 _lseek 3
--- a/src/libc/arch/bsd/_sigaction.c
+++ /dev/null
@@ -1,17 +1,0 @@
-#include <stddef.h>
-#include <sys.h>
-
-typedef struct ucontext_t ucontext_t;
-
-extern int _sigaction2(int,
- struct sigaction *, struct sigaction *,
- const void *,
- int);
-
-extern int _setcontext(ucontext_t *);
-
-int
-_sigaction(int sig, struct sigaction *new, struct sigaction *old)
-{
- return _sigaction2(sig, new, old, _setcontext, 2);
-}
--- a/src/libc/arch/netbsd/Makefile
+++ b/src/libc/arch/netbsd/Makefile
@@ -3,4 +3,9 @@
include $(PROJECTDIR)/scripts/rules.mk
include ../../rules.mk
+OBJS =\
+ sigaction.$O\
+
NODEP = 1
+
+all: $(OBJS)
--- /dev/null
+++ b/src/libc/arch/netbsd/_sigaction.c
@@ -1,0 +1,17 @@
+#include <stddef.h>
+#include <sys.h>
+
+typedef struct ucontext_t ucontext_t;
+
+extern int _sigaction2(int,
+ struct sigaction *, struct sigaction *,
+ const void *,
+ int);
+
+extern int _setcontext(ucontext_t *);
+
+int
+_sigaction(int sig, struct sigaction *new, struct sigaction *old)
+{
+ return _sigaction2(sig, new, old, _setcontext, 2);
+}
--- a/src/libc/objs/amd64-openbsd.mk
+++ b/src/libc/objs/amd64-openbsd.mk
@@ -2,3 +2,35 @@
OBJS =\
$(COMMON_OBJS)\
+ arch/amd64/openbsd/_brk.$O\
+ arch/amd64/openbsd/_close.$O\
+ arch/amd64/openbsd/_exit.$O\
+ arch/amd64/openbsd/_getpid.$O\
+ arch/amd64/openbsd/_kill.$O\
+ arch/amd64/openbsd/_lseek.$O\
+ arch/amd64/openbsd/_open.$O\
+ arch/amd64/openbsd/_read.$O\
+ arch/amd64/openbsd/_sigaction.$O\
+ arch/amd64/openbsd/_write.$O\
+ arch/amd64/openbsd/crt.$O\
+ arch/amd64/openbsd/_sys_errlist.$O\
+ arch/amd64/longjmp.$O\
+ arch/amd64/memchr.$O\
+ arch/amd64/memcmp.$O\
+ arch/amd64/memcpy.$O\
+ arch/amd64/memmove.$O\
+ arch/amd64/memset.$O\
+ arch/amd64/setjmp.$O\
+ arch/amd64/strchr.$O\
+ arch/amd64/strcmp.$O\
+ arch/amd64/strcpy.$O\
+ arch/posix/_getheap.$O\
+ arch/posix/_open.$O\
+ arch/posix/_systime.$O\
+ arch/posix/_tzone.$O\
+ arch/posix/clock.$O\
+ arch/posix/getenv.$O\
+ arch/posix/raise.$O\
+ arch/posix/signal.$O\
+ arch/posix/time.$O\
+ string/strlen.$O\