summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/signal
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
commit8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch)
treedf55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/signal
parentInitial commit. (diff)
downloadwasi-libc-b0f726bfa464c79fdf040fa7daed6094ddbffb4c.tar.xz
wasi-libc-b0f726bfa464c79fdf040fa7daed6094ddbffb4c.zip
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/signal')
-rw-r--r--libc-top-half/musl/src/signal/aarch64/restore.s10
-rw-r--r--libc-top-half/musl/src/signal/aarch64/sigsetjmp.s21
-rw-r--r--libc-top-half/musl/src/signal/arm/restore.s15
-rw-r--r--libc-top-half/musl/src/signal/arm/sigsetjmp.s24
-rw-r--r--libc-top-half/musl/src/signal/block.c44
-rw-r--r--libc-top-half/musl/src/signal/getitimer.c18
-rw-r--r--libc-top-half/musl/src/signal/i386/restore.s14
-rw-r--r--libc-top-half/musl/src/signal/i386/sigsetjmp.s26
-rw-r--r--libc-top-half/musl/src/signal/kill.c7
-rw-r--r--libc-top-half/musl/src/signal/killpg.c11
-rw-r--r--libc-top-half/musl/src/signal/m68k/sigsetjmp.s29
-rw-r--r--libc-top-half/musl/src/signal/microblaze/restore.s13
-rw-r--r--libc-top-half/musl/src/signal/microblaze/sigsetjmp.s22
-rw-r--r--libc-top-half/musl/src/signal/mips/restore.s15
-rw-r--r--libc-top-half/musl/src/signal/mips/sigsetjmp.s33
-rw-r--r--libc-top-half/musl/src/signal/mips64/restore.s11
-rw-r--r--libc-top-half/musl/src/signal/mips64/sigsetjmp.s38
-rw-r--r--libc-top-half/musl/src/signal/mipsn32/restore.s11
-rw-r--r--libc-top-half/musl/src/signal/mipsn32/sigsetjmp.s38
-rw-r--r--libc-top-half/musl/src/signal/or1k/sigsetjmp.s24
-rw-r--r--libc-top-half/musl/src/signal/powerpc/restore.s13
-rw-r--r--libc-top-half/musl/src/signal/powerpc/sigsetjmp.s27
-rw-r--r--libc-top-half/musl/src/signal/powerpc64/restore.s13
-rw-r--r--libc-top-half/musl/src/signal/powerpc64/sigsetjmp.s37
-rw-r--r--libc-top-half/musl/src/signal/psiginfo.c6
-rw-r--r--libc-top-half/musl/src/signal/psignal.c27
-rw-r--r--libc-top-half/musl/src/signal/raise.c13
-rw-r--r--libc-top-half/musl/src/signal/restore.c12
-rw-r--r--libc-top-half/musl/src/signal/riscv64/restore.s8
-rw-r--r--libc-top-half/musl/src/signal/riscv64/sigsetjmp.s23
-rw-r--r--libc-top-half/musl/src/signal/s390x/restore.s11
-rw-r--r--libc-top-half/musl/src/signal/s390x/sigsetjmp.s23
-rw-r--r--libc-top-half/musl/src/signal/setitimer.c26
-rw-r--r--libc-top-half/musl/src/signal/sh/restore.s24
-rw-r--r--libc-top-half/musl/src/signal/sh/sigsetjmp.s41
-rw-r--r--libc-top-half/musl/src/signal/sigaction.c84
-rw-r--r--libc-top-half/musl/src/signal/sigaddset.c13
-rw-r--r--libc-top-half/musl/src/signal/sigaltstack.c18
-rw-r--r--libc-top-half/musl/src/signal/sigandset.c12
-rw-r--r--libc-top-half/musl/src/signal/sigdelset.c13
-rw-r--r--libc-top-half/musl/src/signal/sigemptyset.c13
-rw-r--r--libc-top-half/musl/src/signal/sigfillset.c18
-rw-r--r--libc-top-half/musl/src/signal/sighold.c10
-rw-r--r--libc-top-half/musl/src/signal/sigignore.c11
-rw-r--r--libc-top-half/musl/src/signal/siginterrupt.c12
-rw-r--r--libc-top-half/musl/src/signal/sigisemptyset.c10
-rw-r--r--libc-top-half/musl/src/signal/sigismember.c8
-rw-r--r--libc-top-half/musl/src/signal/siglongjmp.c9
-rw-r--r--libc-top-half/musl/src/signal/signal.c13
-rw-r--r--libc-top-half/musl/src/signal/sigorset.c12
-rw-r--r--libc-top-half/musl/src/signal/sigpause.c9
-rw-r--r--libc-top-half/musl/src/signal/sigpending.c7
-rw-r--r--libc-top-half/musl/src/signal/sigprocmask.c10
-rw-r--r--libc-top-half/musl/src/signal/sigqueue.c22
-rw-r--r--libc-top-half/musl/src/signal/sigrelse.c10
-rw-r--r--libc-top-half/musl/src/signal/sigrtmax.c6
-rw-r--r--libc-top-half/musl/src/signal/sigrtmin.c6
-rw-r--r--libc-top-half/musl/src/signal/sigset.c27
-rw-r--r--libc-top-half/musl/src/signal/sigsetjmp.c0
-rw-r--r--libc-top-half/musl/src/signal/sigsetjmp_tail.c10
-rw-r--r--libc-top-half/musl/src/signal/sigsuspend.c7
-rw-r--r--libc-top-half/musl/src/signal/sigtimedwait.c32
-rw-r--r--libc-top-half/musl/src/signal/sigwait.c10
-rw-r--r--libc-top-half/musl/src/signal/sigwaitinfo.c6
-rw-r--r--libc-top-half/musl/src/signal/x32/getitimer.c7
-rw-r--r--libc-top-half/musl/src/signal/x32/restore.s8
-rw-r--r--libc-top-half/musl/src/signal/x32/setitimer.c7
-rw-r--r--libc-top-half/musl/src/signal/x32/sigsetjmp.s25
-rw-r--r--libc-top-half/musl/src/signal/x86_64/restore.s8
-rw-r--r--libc-top-half/musl/src/signal/x86_64/sigsetjmp.s24
70 files changed, 1225 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/signal/aarch64/restore.s b/libc-top-half/musl/src/signal/aarch64/restore.s
new file mode 100644
index 0000000..d4e5fcf
--- /dev/null
+++ b/libc-top-half/musl/src/signal/aarch64/restore.s
@@ -0,0 +1,10 @@
+.global __restore
+.hidden __restore
+.type __restore,%function
+__restore:
+.global __restore_rt
+.hidden __restore_rt
+.type __restore_rt,%function
+__restore_rt:
+ mov x8,#139 // SYS_rt_sigreturn
+ svc 0
diff --git a/libc-top-half/musl/src/signal/aarch64/sigsetjmp.s b/libc-top-half/musl/src/signal/aarch64/sigsetjmp.s
new file mode 100644
index 0000000..75910c4
--- /dev/null
+++ b/libc-top-half/musl/src/signal/aarch64/sigsetjmp.s
@@ -0,0 +1,21 @@
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,%function
+.type __sigsetjmp,%function
+sigsetjmp:
+__sigsetjmp:
+ cbz x1,setjmp
+
+ str x30,[x0,#176]
+ str x19,[x0,#176+8+8]
+ mov x19,x0
+
+ bl setjmp
+
+ mov w1,w0
+ mov x0,x19
+ ldr x30,[x0,#176]
+ ldr x19,[x0,#176+8+8]
+
+.hidden __sigsetjmp_tail
+ b __sigsetjmp_tail
diff --git a/libc-top-half/musl/src/signal/arm/restore.s b/libc-top-half/musl/src/signal/arm/restore.s
new file mode 100644
index 0000000..fb086d9
--- /dev/null
+++ b/libc-top-half/musl/src/signal/arm/restore.s
@@ -0,0 +1,15 @@
+.syntax unified
+
+.global __restore
+.hidden __restore
+.type __restore,%function
+__restore:
+ mov r7,#119
+ swi 0x0
+
+.global __restore_rt
+.hidden __restore_rt
+.type __restore_rt,%function
+__restore_rt:
+ mov r7,#173
+ swi 0x0
diff --git a/libc-top-half/musl/src/signal/arm/sigsetjmp.s b/libc-top-half/musl/src/signal/arm/sigsetjmp.s
new file mode 100644
index 0000000..69ebbf4
--- /dev/null
+++ b/libc-top-half/musl/src/signal/arm/sigsetjmp.s
@@ -0,0 +1,24 @@
+.syntax unified
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,%function
+.type __sigsetjmp,%function
+sigsetjmp:
+__sigsetjmp:
+ tst r1,r1
+ bne 1f
+ b setjmp
+
+1: str lr,[r0,#256]
+ str r4,[r0,#260+8]
+ mov r4,r0
+
+ bl setjmp
+
+ mov r1,r0
+ mov r0,r4
+ ldr lr,[r0,#256]
+ ldr r4,[r0,#260+8]
+
+.hidden __sigsetjmp_tail
+ b __sigsetjmp_tail
diff --git a/libc-top-half/musl/src/signal/block.c b/libc-top-half/musl/src/signal/block.c
new file mode 100644
index 0000000..cc8698f
--- /dev/null
+++ b/libc-top-half/musl/src/signal/block.c
@@ -0,0 +1,44 @@
+#include "pthread_impl.h"
+#include "syscall.h"
+#include <signal.h>
+
+static const unsigned long all_mask[] = {
+#if ULONG_MAX == 0xffffffff && _NSIG > 65
+ -1UL, -1UL, -1UL, -1UL
+#elif ULONG_MAX == 0xffffffff || _NSIG > 65
+ -1UL, -1UL
+#else
+ -1UL
+#endif
+};
+
+static const unsigned long app_mask[] = {
+#if ULONG_MAX == 0xffffffff
+#if _NSIG == 65
+ 0x7fffffff, 0xfffffffc
+#else
+ 0x7fffffff, 0xfffffffc, -1UL, -1UL
+#endif
+#else
+#if _NSIG == 65
+ 0xfffffffc7fffffff
+#else
+ 0xfffffffc7fffffff, -1UL
+#endif
+#endif
+};
+
+void __block_all_sigs(void *set)
+{
+ __syscall(SYS_rt_sigprocmask, SIG_BLOCK, &all_mask, set, _NSIG/8);
+}
+
+void __block_app_sigs(void *set)
+{
+ __syscall(SYS_rt_sigprocmask, SIG_BLOCK, &app_mask, set, _NSIG/8);
+}
+
+void __restore_sigs(void *set)
+{
+ __syscall(SYS_rt_sigprocmask, SIG_SETMASK, set, 0, _NSIG/8);
+}
diff --git a/libc-top-half/musl/src/signal/getitimer.c b/libc-top-half/musl/src/signal/getitimer.c
new file mode 100644
index 0000000..36d1eb9
--- /dev/null
+++ b/libc-top-half/musl/src/signal/getitimer.c
@@ -0,0 +1,18 @@
+#include <sys/time.h>
+#include "syscall.h"
+
+int getitimer(int which, struct itimerval *old)
+{
+ if (sizeof(time_t) > sizeof(long)) {
+ long old32[4];
+ int r = __syscall(SYS_getitimer, which, old32);
+ if (!r) {
+ old->it_interval.tv_sec = old32[0];
+ old->it_interval.tv_usec = old32[1];
+ old->it_value.tv_sec = old32[2];
+ old->it_value.tv_usec = old32[3];
+ }
+ return __syscall_ret(r);
+ }
+ return syscall(SYS_getitimer, which, old);
+}
diff --git a/libc-top-half/musl/src/signal/i386/restore.s b/libc-top-half/musl/src/signal/i386/restore.s
new file mode 100644
index 0000000..ccc9430
--- /dev/null
+++ b/libc-top-half/musl/src/signal/i386/restore.s
@@ -0,0 +1,14 @@
+.global __restore
+.hidden __restore
+.type __restore,@function
+__restore:
+ popl %eax
+ movl $119, %eax
+ int $0x80
+
+.global __restore_rt
+.hidden __restore_rt
+.type __restore_rt,@function
+__restore_rt:
+ movl $173, %eax
+ int $0x80
diff --git a/libc-top-half/musl/src/signal/i386/sigsetjmp.s b/libc-top-half/musl/src/signal/i386/sigsetjmp.s
new file mode 100644
index 0000000..690b251
--- /dev/null
+++ b/libc-top-half/musl/src/signal/i386/sigsetjmp.s
@@ -0,0 +1,26 @@
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+ mov 8(%esp),%ecx
+ jecxz 1f
+
+ mov 4(%esp),%eax
+ popl 24(%eax)
+ mov %ebx,28+8(%eax)
+ mov %eax,%ebx
+
+.hidden ___setjmp
+ call ___setjmp
+
+ pushl 24(%ebx)
+ mov %ebx,4(%esp)
+ mov %eax,8(%esp)
+ mov 28+8(%ebx),%ebx
+
+.hidden __sigsetjmp_tail
+ jmp __sigsetjmp_tail
+
+1: jmp ___setjmp
diff --git a/libc-top-half/musl/src/signal/kill.c b/libc-top-half/musl/src/signal/kill.c
new file mode 100644
index 0000000..0580573
--- /dev/null
+++ b/libc-top-half/musl/src/signal/kill.c
@@ -0,0 +1,7 @@
+#include <signal.h>
+#include "syscall.h"
+
+int kill(pid_t pid, int sig)
+{
+ return syscall(SYS_kill, pid, sig);
+}
diff --git a/libc-top-half/musl/src/signal/killpg.c b/libc-top-half/musl/src/signal/killpg.c
new file mode 100644
index 0000000..315ed44
--- /dev/null
+++ b/libc-top-half/musl/src/signal/killpg.c
@@ -0,0 +1,11 @@
+#include <signal.h>
+#include <errno.h>
+
+int killpg(pid_t pgid, int sig)
+{
+ if (pgid < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ return kill(-pgid, sig);
+}
diff --git a/libc-top-half/musl/src/signal/m68k/sigsetjmp.s b/libc-top-half/musl/src/signal/m68k/sigsetjmp.s
new file mode 100644
index 0000000..09bfa64
--- /dev/null
+++ b/libc-top-half/musl/src/signal/m68k/sigsetjmp.s
@@ -0,0 +1,29 @@
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+ move.l 8(%sp),%d0
+ beq 1f
+
+ movea.l 4(%sp),%a1
+ move.l (%sp)+,156(%a1)
+ move.l %a2,156+4+8(%a1)
+ movea.l %a1,%a2
+
+.hidden ___setjmp
+ lea ___setjmp-.-8,%a1
+ jsr (%pc,%a1)
+
+ move.l 156(%a2),-(%sp)
+ move.l %a2,4(%sp)
+ move.l %d0,8(%sp)
+ movea.l 156+4+8(%a2),%a2
+
+.hidden __sigsetjmp_tail
+ lea __sigsetjmp_tail-.-8,%a1
+ jmp (%pc,%a1)
+
+1: lea ___setjmp-.-8,%a1
+ jmp (%pc,%a1)
diff --git a/libc-top-half/musl/src/signal/microblaze/restore.s b/libc-top-half/musl/src/signal/microblaze/restore.s
new file mode 100644
index 0000000..b3c9f57
--- /dev/null
+++ b/libc-top-half/musl/src/signal/microblaze/restore.s
@@ -0,0 +1,13 @@
+.global __restore
+.hidden __restore
+.type __restore,@function
+__restore:
+ ori r12, r0, 119
+ brki r14, 0x8
+
+.global __restore_rt
+.hidden __restore_rt
+.type __restore_rt,@function
+__restore_rt:
+ ori r12, r0, 173
+ brki r14, 0x8
diff --git a/libc-top-half/musl/src/signal/microblaze/sigsetjmp.s b/libc-top-half/musl/src/signal/microblaze/sigsetjmp.s
new file mode 100644
index 0000000..d1dd24c
--- /dev/null
+++ b/libc-top-half/musl/src/signal/microblaze/sigsetjmp.s
@@ -0,0 +1,22 @@
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+.hidden ___setjmp
+ beqi r6, ___setjmp
+
+ swi r15,r5,72
+ swi r19,r5,72+4+8
+
+ brlid r15,___setjmp
+ ori r19,r5,0
+
+ ori r6,r3,0
+ ori r5,r19,0
+ lwi r15,r5,72
+ lwi r19,r5,72+4+8
+
+.hidden __sigsetjmp_tail
+ bri __sigsetjmp_tail
diff --git a/libc-top-half/musl/src/signal/mips/restore.s b/libc-top-half/musl/src/signal/mips/restore.s
new file mode 100644
index 0000000..b6dadce
--- /dev/null
+++ b/libc-top-half/musl/src/signal/mips/restore.s
@@ -0,0 +1,15 @@
+.set noreorder
+
+.global __restore_rt
+.hidden __restore_rt
+.type __restore_rt,@function
+__restore_rt:
+ li $2, 4193
+ syscall
+
+.global __restore
+.hidden __restore
+.type __restore,@function
+__restore:
+ li $2, 4119
+ syscall
diff --git a/libc-top-half/musl/src/signal/mips/sigsetjmp.s b/libc-top-half/musl/src/signal/mips/sigsetjmp.s
new file mode 100644
index 0000000..74b65ff
--- /dev/null
+++ b/libc-top-half/musl/src/signal/mips/sigsetjmp.s
@@ -0,0 +1,33 @@
+.set noreorder
+
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+ lui $gp, %hi(_gp_disp)
+ addiu $gp, %lo(_gp_disp)
+ beq $5, $0, 1f
+ addu $gp, $gp, $25
+
+ sw $ra, 104($4)
+ sw $16, 104+4+16($4)
+
+ lw $25, %call16(setjmp)($gp)
+ jalr $25
+ move $16, $4
+
+ move $5,$2
+ move $4,$16
+ lw $ra, 104($4)
+ lw $16, 104+4+16($4)
+
+.hidden __sigsetjmp_tail
+ lw $25, %call16(__sigsetjmp_tail)($gp)
+ jr $25
+ nop
+
+1: lw $25, %call16(setjmp)($gp)
+ jr $25
+ nop
diff --git a/libc-top-half/musl/src/signal/mips64/restore.s b/libc-top-half/musl/src/signal/mips64/restore.s
new file mode 100644
index 0000000..401f8e7
--- /dev/null
+++ b/libc-top-half/musl/src/signal/mips64/restore.s
@@ -0,0 +1,11 @@
+.set noreorder
+.global __restore_rt
+.global __restore
+.hidden __restore_rt
+.hidden __restore
+.type __restore_rt,@function
+.type __restore,@function
+__restore_rt:
+__restore:
+ li $2,5211
+ syscall
diff --git a/libc-top-half/musl/src/signal/mips64/sigsetjmp.s b/libc-top-half/musl/src/signal/mips64/sigsetjmp.s
new file mode 100644
index 0000000..156e70b
--- /dev/null
+++ b/libc-top-half/musl/src/signal/mips64/sigsetjmp.s
@@ -0,0 +1,38 @@
+.set noreorder
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+ lui $3, %hi(%neg(%gp_rel(sigsetjmp)))
+ daddiu $3, $3, %lo(%neg(%gp_rel(sigsetjmp)))
+
+ # comparing save mask with 0, if equals to 0 then
+ # sigsetjmp is equal to setjmp.
+ beq $5, $0, 1f
+ daddu $3, $3, $25
+ sd $ra, 160($4)
+ sd $16, 168($4)
+
+ # save base of got so that we can use it later
+ # once we return from 'longjmp'
+ sd $3, 176($4)
+ ld $25, %got_disp(setjmp)($3)
+ jalr $25
+ move $16, $4
+
+ move $5, $2 # Return from 'setjmp' or 'longjmp'
+ move $4, $16 # Restore the pointer-to-sigjmp_buf
+ ld $ra, 160($4) # Restore ra of sigsetjmp
+ ld $16, 168($4) # Restore $16 of sigsetjmp
+ ld $3, 176($4) # Restore base of got
+
+.hidden __sigsetjmp_tail
+ ld $25, %got_disp(__sigsetjmp_tail)($3)
+ jr $25
+ nop
+1:
+ ld $25, %got_disp(setjmp)($3)
+ jr $25
+ nop
diff --git a/libc-top-half/musl/src/signal/mipsn32/restore.s b/libc-top-half/musl/src/signal/mipsn32/restore.s
new file mode 100644
index 0000000..4cd4e1b
--- /dev/null
+++ b/libc-top-half/musl/src/signal/mipsn32/restore.s
@@ -0,0 +1,11 @@
+.set noreorder
+.global __restore_rt
+.global __restore
+.hidden __restore_rt
+.hidden __restore
+.type __restore_rt,@function
+.type __restore,@function
+__restore_rt:
+__restore:
+ li $2,6211
+ syscall
diff --git a/libc-top-half/musl/src/signal/mipsn32/sigsetjmp.s b/libc-top-half/musl/src/signal/mipsn32/sigsetjmp.s
new file mode 100644
index 0000000..c0c6961
--- /dev/null
+++ b/libc-top-half/musl/src/signal/mipsn32/sigsetjmp.s
@@ -0,0 +1,38 @@
+.set noreorder
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+ lui $3, %hi(%neg(%gp_rel(sigsetjmp)))
+ addiu $3, $3, %lo(%neg(%gp_rel(sigsetjmp)))
+
+ # comparing save mask with 0, if equals to 0 then
+ # sigsetjmp is equal to setjmp.
+ beq $5, $0, 1f
+ addu $3, $3, $25
+ sd $ra, 160($4)
+ sd $16, 168($4)
+
+ # save base of got so that we can use it later
+ # once we return from 'longjmp'
+ sd $3, 176($4)
+ lw $25, %got_disp(setjmp)($3)
+ jalr $25
+ move $16, $4
+
+ move $5, $2 # Return from 'setjmp' or 'longjmp'
+ move $4, $16 # Restore the pointer-to-sigjmp_buf
+ ld $ra, 160($4) # Restore ra of sigsetjmp
+ ld $16, 168($4) # Restore $16 of sigsetjmp
+ ld $3, 176($4) # Restore base of got
+
+.hidden __sigsetjmp_tail
+ lw $25, %got_disp(__sigsetjmp_tail)($3)
+ jr $25
+ nop
+1:
+ lw $25, %got_disp(setjmp)($3)
+ jr $25
+ nop
diff --git a/libc-top-half/musl/src/signal/or1k/sigsetjmp.s b/libc-top-half/musl/src/signal/or1k/sigsetjmp.s
new file mode 100644
index 0000000..b9bcdae
--- /dev/null
+++ b/libc-top-half/musl/src/signal/or1k/sigsetjmp.s
@@ -0,0 +1,24 @@
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+ l.sfeq r4, r0
+.hidden ___setjmp
+ l.bf ___setjmp
+
+ l.sw 52(r3), r9
+ l.sw 52+4+8(r3), r20
+
+ l.jal ___setjmp
+ l.ori r20, r3, 0
+
+ l.ori r4, r11, 0
+ l.ori r3, r20, 0
+
+ l.lwz r9, 52(r3)
+
+.hidden __sigsetjmp_tail
+ l.j __sigsetjmp_tail
+ l.lwz r20, 52+4+8(r3)
diff --git a/libc-top-half/musl/src/signal/powerpc/restore.s b/libc-top-half/musl/src/signal/powerpc/restore.s
new file mode 100644
index 0000000..29c8afd
--- /dev/null
+++ b/libc-top-half/musl/src/signal/powerpc/restore.s
@@ -0,0 +1,13 @@
+ .global __restore
+ .hidden __restore
+ .type __restore,%function
+__restore:
+ li 0, 119 #__NR_sigreturn
+ sc
+
+ .global __restore_rt
+ .hidden __restore_rt
+ .type __restore_rt,%function
+__restore_rt:
+ li 0, 172 # __NR_rt_sigreturn
+ sc
diff --git a/libc-top-half/musl/src/signal/powerpc/sigsetjmp.s b/libc-top-half/musl/src/signal/powerpc/sigsetjmp.s
new file mode 100644
index 0000000..152c3fe
--- /dev/null
+++ b/libc-top-half/musl/src/signal/powerpc/sigsetjmp.s
@@ -0,0 +1,27 @@
+ .global sigsetjmp
+ .global __sigsetjmp
+ .type sigsetjmp,%function
+ .type __sigsetjmp,%function
+sigsetjmp:
+__sigsetjmp:
+ cmpwi cr7, 4, 0
+ beq- cr7, 1f
+
+ mflr 5
+ stw 5, 448(3)
+ stw 16, 448+4+8(3)
+ mr 16, 3
+
+.hidden ___setjmp
+ bl ___setjmp
+
+ mr 4, 3
+ mr 3, 16
+ lwz 5, 448(3)
+ mtlr 5
+ lwz 16, 448+4+8(3)
+
+.hidden __sigsetjmp_tail
+ b __sigsetjmp_tail
+
+1: b ___setjmp
diff --git a/libc-top-half/musl/src/signal/powerpc64/restore.s b/libc-top-half/musl/src/signal/powerpc64/restore.s
new file mode 100644
index 0000000..29c8afd
--- /dev/null
+++ b/libc-top-half/musl/src/signal/powerpc64/restore.s
@@ -0,0 +1,13 @@
+ .global __restore
+ .hidden __restore
+ .type __restore,%function
+__restore:
+ li 0, 119 #__NR_sigreturn
+ sc
+
+ .global __restore_rt
+ .hidden __restore_rt
+ .type __restore_rt,%function
+__restore_rt:
+ li 0, 172 # __NR_rt_sigreturn
+ sc
diff --git a/libc-top-half/musl/src/signal/powerpc64/sigsetjmp.s b/libc-top-half/musl/src/signal/powerpc64/sigsetjmp.s
new file mode 100644
index 0000000..410c283
--- /dev/null
+++ b/libc-top-half/musl/src/signal/powerpc64/sigsetjmp.s
@@ -0,0 +1,37 @@
+ .global sigsetjmp
+ .global __sigsetjmp
+ .type sigsetjmp,%function
+ .type __sigsetjmp,%function
+ .hidden __setjmp_toc
+sigsetjmp:
+__sigsetjmp:
+ addis 2, 12, .TOC.-__sigsetjmp@ha
+ addi 2, 2, .TOC.-__sigsetjmp@l
+ ld 5, 24(1) # load from the TOC slot in the caller's stack frame
+ b 1f
+
+ .localentry sigsetjmp,.-sigsetjmp
+ .localentry __sigsetjmp,.-__sigsetjmp
+ mr 5, 2
+
+1:
+ cmpwi cr7, 4, 0
+ beq- cr7, __setjmp_toc
+
+ mflr 6
+ std 6, 512(3)
+ std 2, 512+16(3)
+ std 16, 512+24(3)
+ mr 16, 3
+
+ bl __setjmp_toc
+
+ mr 4, 3
+ mr 3, 16
+ ld 5, 512(3)
+ mtlr 5
+ ld 2, 512+16(3)
+ ld 16, 512+24(3)
+
+.hidden __sigsetjmp_tail
+ b __sigsetjmp_tail
diff --git a/libc-top-half/musl/src/signal/psiginfo.c b/libc-top-half/musl/src/signal/psiginfo.c
new file mode 100644
index 0000000..2b15982
--- /dev/null
+++ b/libc-top-half/musl/src/signal/psiginfo.c
@@ -0,0 +1,6 @@
+#include <signal.h>
+
+void psiginfo(const siginfo_t *si, const char *msg)
+{
+ psignal(si->si_signo, msg);
+}
diff --git a/libc-top-half/musl/src/signal/psignal.c b/libc-top-half/musl/src/signal/psignal.c
new file mode 100644
index 0000000..138dbe0
--- /dev/null
+++ b/libc-top-half/musl/src/signal/psignal.c
@@ -0,0 +1,27 @@
+#include "stdio_impl.h"
+#include <string.h>
+#include <signal.h>
+#include <errno.h>
+
+void psignal(int sig, const char *msg)
+{
+ FILE *f = stderr;
+ char *s = strsignal(sig);
+
+ FLOCK(f);
+
+ /* Save stderr's orientation and encoding rule, since psignal is not
+ * permitted to change them. Save errno and restore it if there is no
+ * error since fprintf might change it even on success but psignal is
+ * not permitted to do so. */
+ void *old_locale = f->locale;
+ int old_mode = f->mode;
+ int old_errno = errno;
+
+ if (fprintf(f, "%s%s%s\n", msg?msg:"", msg?": ":"", s)>=0)
+ errno = old_errno;
+ f->mode = old_mode;
+ f->locale = old_locale;
+
+ FUNLOCK(f);
+}
diff --git a/libc-top-half/musl/src/signal/raise.c b/libc-top-half/musl/src/signal/raise.c
new file mode 100644
index 0000000..f051201
--- /dev/null
+++ b/libc-top-half/musl/src/signal/raise.c
@@ -0,0 +1,13 @@
+#include <signal.h>
+#include <stdint.h>
+#include "syscall.h"
+#include "pthread_impl.h"
+
+int raise(int sig)
+{
+ sigset_t set;
+ __block_app_sigs(&set);
+ int ret = syscall(SYS_tkill, __pthread_self()->tid, sig);
+ __restore_sigs(&set);
+ return ret;
+}
diff --git a/libc-top-half/musl/src/signal/restore.c b/libc-top-half/musl/src/signal/restore.c
new file mode 100644
index 0000000..5ec4f5d
--- /dev/null
+++ b/libc-top-half/musl/src/signal/restore.c
@@ -0,0 +1,12 @@
+#include <features.h>
+
+/* These functions will not work, but suffice for targets where the
+ * kernel sigaction structure does not actually use sa_restorer. */
+
+hidden void __restore()
+{
+}
+
+hidden void __restore_rt()
+{
+}
diff --git a/libc-top-half/musl/src/signal/riscv64/restore.s b/libc-top-half/musl/src/signal/riscv64/restore.s
new file mode 100644
index 0000000..40012c7
--- /dev/null
+++ b/libc-top-half/musl/src/signal/riscv64/restore.s
@@ -0,0 +1,8 @@
+.global __restore
+.type __restore, %function
+__restore:
+.global __restore_rt
+.type __restore_rt, %function
+__restore_rt:
+ li a7, 139 # SYS_rt_sigreturn
+ ecall
diff --git a/libc-top-half/musl/src/signal/riscv64/sigsetjmp.s b/libc-top-half/musl/src/signal/riscv64/sigsetjmp.s
new file mode 100644
index 0000000..f9bc162
--- /dev/null
+++ b/libc-top-half/musl/src/signal/riscv64/sigsetjmp.s
@@ -0,0 +1,23 @@
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp, %function
+.type __sigsetjmp, %function
+sigsetjmp:
+__sigsetjmp:
+ bnez a1, 1f
+ tail setjmp
+1:
+
+ sd ra, 208(a0)
+ sd s0, 224(a0)
+ mv s0, a0
+
+ call setjmp
+
+ mv a1, a0
+ mv a0, s0
+ ld s0, 224(a0)
+ ld ra, 208(a0)
+
+.hidden __sigsetjmp_tail
+ tail __sigsetjmp_tail
diff --git a/libc-top-half/musl/src/signal/s390x/restore.s b/libc-top-half/musl/src/signal/s390x/restore.s
new file mode 100644
index 0000000..88e33db
--- /dev/null
+++ b/libc-top-half/musl/src/signal/s390x/restore.s
@@ -0,0 +1,11 @@
+ .global __restore
+ .hidden __restore
+ .type __restore,%function
+__restore:
+ svc 119 #__NR_sigreturn
+
+ .global __restore_rt
+ .hidden __restore_rt
+ .type __restore_rt,%function
+__restore_rt:
+ svc 173 # __NR_rt_sigreturn
diff --git a/libc-top-half/musl/src/signal/s390x/sigsetjmp.s b/libc-top-half/musl/src/signal/s390x/sigsetjmp.s
new file mode 100644
index 0000000..41b1bd9
--- /dev/null
+++ b/libc-top-half/musl/src/signal/s390x/sigsetjmp.s
@@ -0,0 +1,23 @@
+ .global sigsetjmp
+ .global __sigsetjmp
+ .type sigsetjmp,%function
+ .type __sigsetjmp,%function
+ .hidden ___setjmp
+sigsetjmp:
+__sigsetjmp:
+ ltgr %r3, %r3
+ jz ___setjmp
+
+ stg %r14, 18*8(%r2)
+ stg %r6, 20*8(%r2)
+ lgr %r6, %r2
+
+ brasl %r14, ___setjmp
+
+ lgr %r3, %r2
+ lgr %r2, %r6
+ lg %r14, 18*8(%r2)
+ lg %r6, 20*8(%r2)
+
+.hidden __sigsetjmp_tail
+ jg __sigsetjmp_tail
diff --git a/libc-top-half/musl/src/signal/setitimer.c b/libc-top-half/musl/src/signal/setitimer.c
new file mode 100644
index 0000000..0dfbeb4
--- /dev/null
+++ b/libc-top-half/musl/src/signal/setitimer.c
@@ -0,0 +1,26 @@
+#include <sys/time.h>
+#include <errno.h>
+#include "syscall.h"
+
+#define IS32BIT(x) !((x)+0x80000000ULL>>32)
+
+int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old)
+{
+ if (sizeof(time_t) > sizeof(long)) {
+ time_t is = new->it_interval.tv_sec, vs = new->it_value.tv_sec;
+ long ius = new->it_interval.tv_usec, vus = new->it_value.tv_usec;
+ if (!IS32BIT(is) || !IS32BIT(vs))
+ return __syscall_ret(-ENOTSUP);
+ long old32[4];
+ int r = __syscall(SYS_setitimer, which,
+ ((long[]){is, ius, vs, vus}), old32);
+ if (!r && old) {
+ old->it_interval.tv_sec = old32[0];
+ old->it_interval.tv_usec = old32[1];
+ old->it_value.tv_sec = old32[2];
+ old->it_value.tv_usec = old32[3];
+ }
+ return __syscall_ret(r);
+ }
+ return syscall(SYS_setitimer, which, new, old);
+}
diff --git a/libc-top-half/musl/src/signal/sh/restore.s b/libc-top-half/musl/src/signal/sh/restore.s
new file mode 100644
index 0000000..3a92199
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sh/restore.s
@@ -0,0 +1,24 @@
+.global __restore
+.hidden __restore
+__restore:
+ mov #119, r3 !__NR_sigreturn
+ trapa #31
+
+ or r0, r0
+ or r0, r0
+ or r0, r0
+ or r0, r0
+ or r0, r0
+
+.global __restore_rt
+.hidden __restore_rt
+__restore_rt:
+ mov #100, r3 !__NR_rt_sigreturn
+ add #73, r3
+ trapa #31
+
+ or r0, r0
+ or r0, r0
+ or r0, r0
+ or r0, r0
+ or r0, r0
diff --git a/libc-top-half/musl/src/signal/sh/sigsetjmp.s b/libc-top-half/musl/src/signal/sh/sigsetjmp.s
new file mode 100644
index 0000000..1e2270b
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sh/sigsetjmp.s
@@ -0,0 +1,41 @@
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+ tst r5, r5
+ bt 9f
+
+ mov r4, r6
+ add #60, r6
+ sts pr, r0
+ mov.l r0, @r6
+ mov.l r8, @(4+8,r6)
+
+ mov.l 1f, r0
+2: bsrf r0
+ mov r4, r8
+
+ mov r0, r5
+ mov r8, r4
+ mov r4, r6
+ add #60, r6
+
+ mov.l @r6, r0
+ lds r0, pr
+
+ mov.l 3f, r0
+4: braf r0
+ mov.l @(4+8,r4), r8
+
+9: mov.l 5f, r0
+6: braf r0
+ nop
+
+.align 2
+.hidden ___setjmp
+1: .long ___setjmp@PLT-(2b+4-.)
+.hidden __sigsetjmp_tail
+3: .long __sigsetjmp_tail@PLT-(4b+4-.)
+5: .long ___setjmp@PLT-(6b+4-.)
diff --git a/libc-top-half/musl/src/signal/sigaction.c b/libc-top-half/musl/src/signal/sigaction.c
new file mode 100644
index 0000000..2203471
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigaction.c
@@ -0,0 +1,84 @@
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include "syscall.h"
+#include "pthread_impl.h"
+#include "libc.h"
+#include "lock.h"
+#include "ksigaction.h"
+
+static int unmask_done;
+static unsigned long handler_set[_NSIG/(8*sizeof(long))];
+
+void __get_handler_set(sigset_t *set)
+{
+ memcpy(set, handler_set, sizeof handler_set);
+}
+
+volatile int __eintr_valid_flag;
+
+int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
+{
+ struct k_sigaction ksa, ksa_old;
+ if (sa) {
+ if ((uintptr_t)sa->sa_handler > 1UL) {
+ a_or_l(handler_set+(sig-1)/(8*sizeof(long)),
+ 1UL<<(sig-1)%(8*sizeof(long)));
+
+ /* If pthread_create has not yet been called,
+ * implementation-internal signals might not
+ * yet have been unblocked. They must be
+ * unblocked before any signal handler is
+ * installed, so that an application cannot
+ * receive an illegal sigset_t (with them
+ * blocked) as part of the ucontext_t passed
+ * to the signal handler. */
+ if (!libc.threaded && !unmask_done) {
+ __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
+ SIGPT_SET, 0, _NSIG/8);
+ unmask_done = 1;
+ }
+
+ if (!(sa->sa_flags & SA_RESTART)) {
+ a_store(&__eintr_valid_flag, 1);
+ }
+ }
+ ksa.handler = sa->sa_handler;
+ ksa.flags = sa->sa_flags | SA_RESTORER;
+ ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore;
+ memcpy(&ksa.mask, &sa->sa_mask, _NSIG/8);
+ }
+ int r = __syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa_old:0, _NSIG/8);
+ if (old && !r) {
+ old->sa_handler = ksa_old.handler;
+ old->sa_flags = ksa_old.flags;
+ memcpy(&old->sa_mask, &ksa_old.mask, _NSIG/8);
+ }
+ return __syscall_ret(r);
+}
+
+int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
+{
+ unsigned long set[_NSIG/(8*sizeof(long))];
+
+ if (sig-32U < 3 || sig-1U >= _NSIG-1) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* Doing anything with the disposition of SIGABRT requires a lock,
+ * so that it cannot be changed while abort is terminating the
+ * process and so any change made by abort can't be observed. */
+ if (sig == SIGABRT) {
+ __block_all_sigs(&set);
+ LOCK(__abort_lock);
+ }
+ int r = __libc_sigaction(sig, sa, old);
+ if (sig == SIGABRT) {
+ UNLOCK(__abort_lock);
+ __restore_sigs(&set);
+ }
+ return r;
+}
+
+weak_alias(__sigaction, sigaction);
diff --git a/libc-top-half/musl/src/signal/sigaddset.c b/libc-top-half/musl/src/signal/sigaddset.c
new file mode 100644
index 0000000..085d1f4
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigaddset.c
@@ -0,0 +1,13 @@
+#include <signal.h>
+#include <errno.h>
+
+int sigaddset(sigset_t *set, int sig)
+{
+ unsigned s = sig-1;
+ if (s >= _NSIG-1 || sig-32U < 3) {
+ errno = EINVAL;
+ return -1;
+ }
+ set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1);
+ return 0;
+}
diff --git a/libc-top-half/musl/src/signal/sigaltstack.c b/libc-top-half/musl/src/signal/sigaltstack.c
new file mode 100644
index 0000000..d3a6e82
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigaltstack.c
@@ -0,0 +1,18 @@
+#include <signal.h>
+#include <errno.h>
+#include "syscall.h"
+
+int sigaltstack(const stack_t *restrict ss, stack_t *restrict old)
+{
+ if (ss) {
+ if (!(ss->ss_flags & SS_DISABLE) && ss->ss_size < MINSIGSTKSZ) {
+ errno = ENOMEM;
+ return -1;
+ }
+ if (ss->ss_flags & SS_ONSTACK) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ return syscall(SYS_sigaltstack, ss, old);
+}
diff --git a/libc-top-half/musl/src/signal/sigandset.c b/libc-top-half/musl/src/signal/sigandset.c
new file mode 100644
index 0000000..974186f
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigandset.c
@@ -0,0 +1,12 @@
+#define _GNU_SOURCE
+#include <signal.h>
+
+#define SST_SIZE (_NSIG/8/sizeof(long))
+
+int sigandset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
+{
+ unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right;
+ for(; i < SST_SIZE; i++) d[i] = l[i] & r[i];
+ return 0;
+}
+
diff --git a/libc-top-half/musl/src/signal/sigdelset.c b/libc-top-half/musl/src/signal/sigdelset.c
new file mode 100644
index 0000000..ce69280
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigdelset.c
@@ -0,0 +1,13 @@
+#include <signal.h>
+#include <errno.h>
+
+int sigdelset(sigset_t *set, int sig)
+{
+ unsigned s = sig-1;
+ if (s >= _NSIG-1 || sig-32U < 3) {
+ errno = EINVAL;
+ return -1;
+ }
+ set->__bits[s/8/sizeof *set->__bits] &=~(1UL<<(s&8*sizeof *set->__bits-1));
+ return 0;
+}
diff --git a/libc-top-half/musl/src/signal/sigemptyset.c b/libc-top-half/musl/src/signal/sigemptyset.c
new file mode 100644
index 0000000..1d07471
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigemptyset.c
@@ -0,0 +1,13 @@
+#include <signal.h>
+#include <string.h>
+
+int sigemptyset(sigset_t *set)
+{
+ set->__bits[0] = 0;
+ if (sizeof(long)==4 || _NSIG > 65) set->__bits[1] = 0;
+ if (sizeof(long)==4 && _NSIG > 65) {
+ set->__bits[2] = 0;
+ set->__bits[3] = 0;
+ }
+ return 0;
+}
diff --git a/libc-top-half/musl/src/signal/sigfillset.c b/libc-top-half/musl/src/signal/sigfillset.c
new file mode 100644
index 0000000..16e7b4f
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigfillset.c
@@ -0,0 +1,18 @@
+#include <signal.h>
+#include <limits.h>
+
+int sigfillset(sigset_t *set)
+{
+#if ULONG_MAX == 0xffffffff
+ set->__bits[0] = 0x7ffffffful;
+ set->__bits[1] = 0xfffffffcul;
+ if (_NSIG > 65) {
+ set->__bits[2] = 0xfffffffful;
+ set->__bits[3] = 0xfffffffful;
+ }
+#else
+ set->__bits[0] = 0xfffffffc7ffffffful;
+ if (_NSIG > 65) set->__bits[1] = 0xfffffffffffffffful;
+#endif
+ return 0;
+}
diff --git a/libc-top-half/musl/src/signal/sighold.c b/libc-top-half/musl/src/signal/sighold.c
new file mode 100644
index 0000000..cfa2306
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sighold.c
@@ -0,0 +1,10 @@
+#include <signal.h>
+
+int sighold(int sig)
+{
+ sigset_t mask;
+
+ sigemptyset(&mask);
+ if (sigaddset(&mask, sig) < 0) return -1;
+ return sigprocmask(SIG_BLOCK, &mask, 0);
+}
diff --git a/libc-top-half/musl/src/signal/sigignore.c b/libc-top-half/musl/src/signal/sigignore.c
new file mode 100644
index 0000000..5ba05e1
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigignore.c
@@ -0,0 +1,11 @@
+#include <signal.h>
+
+int sigignore(int sig)
+{
+ struct sigaction sa;
+
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = SIG_IGN;
+ sa.sa_flags = 0;
+ return sigaction(sig, &sa, 0);
+}
diff --git a/libc-top-half/musl/src/signal/siginterrupt.c b/libc-top-half/musl/src/signal/siginterrupt.c
new file mode 100644
index 0000000..7006340
--- /dev/null
+++ b/libc-top-half/musl/src/signal/siginterrupt.c
@@ -0,0 +1,12 @@
+#include <signal.h>
+
+int siginterrupt(int sig, int flag)
+{
+ struct sigaction sa;
+
+ sigaction(sig, 0, &sa);
+ if (flag) sa.sa_flags &= ~SA_RESTART;
+ else sa.sa_flags |= SA_RESTART;
+
+ return sigaction(sig, &sa, 0);
+}
diff --git a/libc-top-half/musl/src/signal/sigisemptyset.c b/libc-top-half/musl/src/signal/sigisemptyset.c
new file mode 100644
index 0000000..68b8662
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigisemptyset.c
@@ -0,0 +1,10 @@
+#define _GNU_SOURCE
+#include <signal.h>
+#include <string.h>
+
+int sigisemptyset(const sigset_t *set)
+{
+ for (size_t i=0; i<_NSIG/8/sizeof *set->__bits; i++)
+ if (set->__bits[i]) return 0;
+ return 1;
+}
diff --git a/libc-top-half/musl/src/signal/sigismember.c b/libc-top-half/musl/src/signal/sigismember.c
new file mode 100644
index 0000000..ab87d62
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigismember.c
@@ -0,0 +1,8 @@
+#include <signal.h>
+
+int sigismember(const sigset_t *set, int sig)
+{
+ unsigned s = sig-1;
+ if (s >= _NSIG-1) return 0;
+ return !!(set->__bits[s/8/sizeof *set->__bits] & 1UL<<(s&8*sizeof *set->__bits-1));
+}
diff --git a/libc-top-half/musl/src/signal/siglongjmp.c b/libc-top-half/musl/src/signal/siglongjmp.c
new file mode 100644
index 0000000..bc317ac
--- /dev/null
+++ b/libc-top-half/musl/src/signal/siglongjmp.c
@@ -0,0 +1,9 @@
+#include <setjmp.h>
+#include <signal.h>
+#include "syscall.h"
+#include "pthread_impl.h"
+
+_Noreturn void siglongjmp(sigjmp_buf buf, int ret)
+{
+ longjmp(buf, ret);
+}
diff --git a/libc-top-half/musl/src/signal/signal.c b/libc-top-half/musl/src/signal/signal.c
new file mode 100644
index 0000000..7a6dd17
--- /dev/null
+++ b/libc-top-half/musl/src/signal/signal.c
@@ -0,0 +1,13 @@
+#include <signal.h>
+#include "syscall.h"
+
+void (*signal(int sig, void (*func)(int)))(int)
+{
+ struct sigaction sa_old, sa = { .sa_handler = func, .sa_flags = SA_RESTART };
+ if (__sigaction(sig, &sa, &sa_old) < 0)
+ return SIG_ERR;
+ return sa_old.sa_handler;
+}
+
+weak_alias(signal, bsd_signal);
+weak_alias(signal, __sysv_signal);
diff --git a/libc-top-half/musl/src/signal/sigorset.c b/libc-top-half/musl/src/signal/sigorset.c
new file mode 100644
index 0000000..ed48873
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigorset.c
@@ -0,0 +1,12 @@
+#define _GNU_SOURCE
+#include <signal.h>
+
+#define SST_SIZE (_NSIG/8/sizeof(long))
+
+int sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
+{
+ unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right;
+ for(; i < SST_SIZE; i++) d[i] = l[i] | r[i];
+ return 0;
+}
+
diff --git a/libc-top-half/musl/src/signal/sigpause.c b/libc-top-half/musl/src/signal/sigpause.c
new file mode 100644
index 0000000..363d2fe
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigpause.c
@@ -0,0 +1,9 @@
+#include <signal.h>
+
+int sigpause(int sig)
+{
+ sigset_t mask;
+ sigprocmask(0, 0, &mask);
+ sigdelset(&mask, sig);
+ return sigsuspend(&mask);
+}
diff --git a/libc-top-half/musl/src/signal/sigpending.c b/libc-top-half/musl/src/signal/sigpending.c
new file mode 100644
index 0000000..3d193df
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigpending.c
@@ -0,0 +1,7 @@
+#include <signal.h>
+#include "syscall.h"
+
+int sigpending(sigset_t *set)
+{
+ return syscall(SYS_rt_sigpending, set, _NSIG/8);
+}
diff --git a/libc-top-half/musl/src/signal/sigprocmask.c b/libc-top-half/musl/src/signal/sigprocmask.c
new file mode 100644
index 0000000..297e20c
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigprocmask.c
@@ -0,0 +1,10 @@
+#include <signal.h>
+#include <errno.h>
+
+int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
+{
+ int r = pthread_sigmask(how, set, old);
+ if (!r) return r;
+ errno = r;
+ return -1;
+}
diff --git a/libc-top-half/musl/src/signal/sigqueue.c b/libc-top-half/musl/src/signal/sigqueue.c
new file mode 100644
index 0000000..b75f0c5
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigqueue.c
@@ -0,0 +1,22 @@
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include "syscall.h"
+#include "pthread_impl.h"
+
+int sigqueue(pid_t pid, int sig, const union sigval value)
+{
+ siginfo_t si;
+ sigset_t set;
+ int r;
+ memset(&si, 0, sizeof si);
+ si.si_signo = sig;
+ si.si_code = SI_QUEUE;
+ si.si_value = value;
+ si.si_uid = getuid();
+ __block_app_sigs(&set);
+ si.si_pid = getpid();
+ r = syscall(SYS_rt_sigqueueinfo, pid, sig, &si);
+ __restore_sigs(&set);
+ return r;
+}
diff --git a/libc-top-half/musl/src/signal/sigrelse.c b/libc-top-half/musl/src/signal/sigrelse.c
new file mode 100644
index 0000000..b4c5a00
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigrelse.c
@@ -0,0 +1,10 @@
+#include <signal.h>
+
+int sigrelse(int sig)
+{
+ sigset_t mask;
+
+ sigemptyset(&mask);
+ if (sigaddset(&mask, sig) < 0) return -1;
+ return sigprocmask(SIG_UNBLOCK, &mask, 0);
+}
diff --git a/libc-top-half/musl/src/signal/sigrtmax.c b/libc-top-half/musl/src/signal/sigrtmax.c
new file mode 100644
index 0000000..44dc88f
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigrtmax.c
@@ -0,0 +1,6 @@
+#include <signal.h>
+
+int __libc_current_sigrtmax()
+{
+ return _NSIG-1;
+}
diff --git a/libc-top-half/musl/src/signal/sigrtmin.c b/libc-top-half/musl/src/signal/sigrtmin.c
new file mode 100644
index 0000000..c5a1fd9
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigrtmin.c
@@ -0,0 +1,6 @@
+#include <signal.h>
+
+int __libc_current_sigrtmin()
+{
+ return 35;
+}
diff --git a/libc-top-half/musl/src/signal/sigset.c b/libc-top-half/musl/src/signal/sigset.c
new file mode 100644
index 0000000..f3e8c40
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigset.c
@@ -0,0 +1,27 @@
+#include <signal.h>
+
+void (*sigset(int sig, void (*handler)(int)))(int)
+{
+ struct sigaction sa, sa_old;
+ sigset_t mask, mask_old;
+
+ sigemptyset(&mask);
+ if (sigaddset(&mask, sig) < 0)
+ return SIG_ERR;
+
+ if (handler == SIG_HOLD) {
+ if (sigaction(sig, 0, &sa_old) < 0)
+ return SIG_ERR;
+ if (sigprocmask(SIG_BLOCK, &mask, &mask_old) < 0)
+ return SIG_ERR;
+ } else {
+ sa.sa_handler = handler;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ if (sigaction(sig, &sa, &sa_old) < 0)
+ return SIG_ERR;
+ if (sigprocmask(SIG_UNBLOCK, &mask, &mask_old) < 0)
+ return SIG_ERR;
+ }
+ return sigismember(&mask_old, sig) ? SIG_HOLD : sa_old.sa_handler;
+}
diff --git a/libc-top-half/musl/src/signal/sigsetjmp.c b/libc-top-half/musl/src/signal/sigsetjmp.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigsetjmp.c
diff --git a/libc-top-half/musl/src/signal/sigsetjmp_tail.c b/libc-top-half/musl/src/signal/sigsetjmp_tail.c
new file mode 100644
index 0000000..f2aa288
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigsetjmp_tail.c
@@ -0,0 +1,10 @@
+#include <setjmp.h>
+#include <signal.h>
+#include "syscall.h"
+
+hidden int __sigsetjmp_tail(sigjmp_buf jb, int ret)
+{
+ void *p = jb->__ss;
+ __syscall(SYS_rt_sigprocmask, SIG_SETMASK, ret?p:0, ret?0:p, _NSIG/8);
+ return ret;
+}
diff --git a/libc-top-half/musl/src/signal/sigsuspend.c b/libc-top-half/musl/src/signal/sigsuspend.c
new file mode 100644
index 0000000..36e0602
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigsuspend.c
@@ -0,0 +1,7 @@
+#include <signal.h>
+#include "syscall.h"
+
+int sigsuspend(const sigset_t *mask)
+{
+ return syscall_cp(SYS_rt_sigsuspend, mask, _NSIG/8);
+}
diff --git a/libc-top-half/musl/src/signal/sigtimedwait.c b/libc-top-half/musl/src/signal/sigtimedwait.c
new file mode 100644
index 0000000..1287174
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigtimedwait.c
@@ -0,0 +1,32 @@
+#include <signal.h>
+#include <errno.h>
+#include "syscall.h"
+
+#define IS32BIT(x) !((x)+0x80000000ULL>>32)
+#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
+
+static int do_sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict ts)
+{
+#ifdef SYS_rt_sigtimedwait_time64
+ time_t s = ts ? ts->tv_sec : 0;
+ long ns = ts ? ts->tv_nsec : 0;
+ int r = -ENOSYS;
+ if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || !IS32BIT(s))
+ r = __syscall_cp(SYS_rt_sigtimedwait_time64, mask, si,
+ ts ? ((long long[]){s, ns}) : 0, _NSIG/8);
+ if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || r!=-ENOSYS)
+ return r;
+ return __syscall_cp(SYS_rt_sigtimedwait, mask, si,
+ ts ? ((long[]){CLAMP(s), ns}) : 0, _NSIG/8);;
+#else
+ return __syscall_cp(SYS_rt_sigtimedwait, mask, si, ts, _NSIG/8);
+#endif
+}
+
+int sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict timeout)
+{
+ int ret;
+ do ret = do_sigtimedwait(mask, si, timeout);
+ while (ret==-EINTR);
+ return __syscall_ret(ret);
+}
diff --git a/libc-top-half/musl/src/signal/sigwait.c b/libc-top-half/musl/src/signal/sigwait.c
new file mode 100644
index 0000000..c8822ee
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigwait.c
@@ -0,0 +1,10 @@
+#include <signal.h>
+
+int sigwait(const sigset_t *restrict mask, int *restrict sig)
+{
+ siginfo_t si;
+ if (sigtimedwait(mask, &si, 0) < 0)
+ return -1;
+ *sig = si.si_signo;
+ return 0;
+}
diff --git a/libc-top-half/musl/src/signal/sigwaitinfo.c b/libc-top-half/musl/src/signal/sigwaitinfo.c
new file mode 100644
index 0000000..bb51f8b
--- /dev/null
+++ b/libc-top-half/musl/src/signal/sigwaitinfo.c
@@ -0,0 +1,6 @@
+#include <signal.h>
+
+int sigwaitinfo(const sigset_t *restrict mask, siginfo_t *restrict si)
+{
+ return sigtimedwait(mask, si, 0);
+}
diff --git a/libc-top-half/musl/src/signal/x32/getitimer.c b/libc-top-half/musl/src/signal/x32/getitimer.c
new file mode 100644
index 0000000..8a8046a
--- /dev/null
+++ b/libc-top-half/musl/src/signal/x32/getitimer.c
@@ -0,0 +1,7 @@
+#include <sys/time.h>
+#include "syscall.h"
+
+int getitimer(int which, struct itimerval *old)
+{
+ return syscall(SYS_getitimer, which, old);
+}
diff --git a/libc-top-half/musl/src/signal/x32/restore.s b/libc-top-half/musl/src/signal/x32/restore.s
new file mode 100644
index 0000000..1117446
--- /dev/null
+++ b/libc-top-half/musl/src/signal/x32/restore.s
@@ -0,0 +1,8 @@
+ nop
+.global __restore_rt
+.hidden __restore_rt
+.type __restore_rt,@function
+__restore_rt:
+ mov $0x40000201, %rax /* SYS_rt_sigreturn */
+ syscall
+.size __restore_rt,.-__restore_rt
diff --git a/libc-top-half/musl/src/signal/x32/setitimer.c b/libc-top-half/musl/src/signal/x32/setitimer.c
new file mode 100644
index 0000000..21b1f45
--- /dev/null
+++ b/libc-top-half/musl/src/signal/x32/setitimer.c
@@ -0,0 +1,7 @@
+#include <sys/time.h>
+#include "syscall.h"
+
+int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old)
+{
+ return syscall(SYS_setitimer, which, new, old);
+}
diff --git a/libc-top-half/musl/src/signal/x32/sigsetjmp.s b/libc-top-half/musl/src/signal/x32/sigsetjmp.s
new file mode 100644
index 0000000..1f02b0e
--- /dev/null
+++ b/libc-top-half/musl/src/signal/x32/sigsetjmp.s
@@ -0,0 +1,25 @@
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+ test %esi,%esi
+ jz 1f
+
+ popq 64(%rdi)
+ mov %rbx,72+8(%rdi)
+ mov %rdi,%rbx
+
+ call setjmp@PLT
+
+ pushq 64(%rbx)
+ movl $0, 4(%rsp)
+ mov %rbx,%rdi
+ mov %eax,%esi
+ mov 72+8(%rbx),%rbx
+
+.hidden __sigsetjmp_tail
+ jmp __sigsetjmp_tail
+
+1: jmp setjmp@PLT
diff --git a/libc-top-half/musl/src/signal/x86_64/restore.s b/libc-top-half/musl/src/signal/x86_64/restore.s
new file mode 100644
index 0000000..27d6cf3
--- /dev/null
+++ b/libc-top-half/musl/src/signal/x86_64/restore.s
@@ -0,0 +1,8 @@
+ nop
+.global __restore_rt
+.hidden __restore_rt
+.type __restore_rt,@function
+__restore_rt:
+ mov $15, %rax
+ syscall
+.size __restore_rt,.-__restore_rt
diff --git a/libc-top-half/musl/src/signal/x86_64/sigsetjmp.s b/libc-top-half/musl/src/signal/x86_64/sigsetjmp.s
new file mode 100644
index 0000000..9a7695f
--- /dev/null
+++ b/libc-top-half/musl/src/signal/x86_64/sigsetjmp.s
@@ -0,0 +1,24 @@
+.global sigsetjmp
+.global __sigsetjmp
+.type sigsetjmp,@function
+.type __sigsetjmp,@function
+sigsetjmp:
+__sigsetjmp:
+ test %esi,%esi
+ jz 1f
+
+ popq 64(%rdi)
+ mov %rbx,72+8(%rdi)
+ mov %rdi,%rbx
+
+ call setjmp@PLT
+
+ pushq 64(%rbx)
+ mov %rbx,%rdi
+ mov %eax,%esi
+ mov 72+8(%rbx),%rbx
+
+.hidden __sigsetjmp_tail
+ jmp __sigsetjmp_tail
+
+1: jmp setjmp@PLT