shithub: mc

Download patch

ref: 8fffc0be8c026118884aa4685246c797927f38b9
parent: 99e1677b6bf577fb4db18f50a92df79ea47e9e0e
author: Ori Bernstein <ori@markovcorp.com>
date: Mon Jun 12 13:39:34 EDT 2017

Signals now work right on linux.

	We weren't calling the restorer. Linux really wants this. Oops.

--- a/lib/sys/sys+linux-x64.myr
+++ b/lib/sys/sys+linux-x64.myr
@@ -52,7 +52,7 @@
 	;;
 
 	type sigset = struct
-		bits : uint32[2]
+		bits	: uint32[2]
 	;;
 
 	type sigaction = struct
@@ -343,6 +343,7 @@
 	const Sanocldstop	: sigflags = 0x00000001
 	const Sanocldwait	: sigflags = 0x00000002
 	const Sasiginfo		: sigflags = 0x00000004
+	const Sarestorer	: sigflags = 0x04000000
 	const Saonstack		: sigflags = 0x08000000
 	const Sarestart		: sigflags = 0x10000000
 	const Sanodefer		: sigflags = 0x40000000
@@ -699,6 +700,7 @@
 
 	/* getting to the os */
 	extern const syscall	: (sc:scno, args:... -> int64)
+	extern const sigreturn	: (-> void)
 
 	/* process management */
 	const exit	: (status:int -> void)
@@ -879,7 +881,13 @@
 const dup 	= {fd;	-> (syscall(Sysdup, a(fd)) : fd)}
 const dup2 	= {src, dst;	-> (syscall(Sysdup2, a(src), a(dst)) : fd)}
 
-const sigaction	= {sig, act, oact;	-> (syscall(Sysrt_sigaction, a(sig), a(act), a(oact), a(sizeof(sigflags))) : int)}
+const sigaction	= {sig, act, oact;
+	if act.restore == (0 : byte#)
+		act.flags |= Sarestorer
+		act.restore = (sys.sigreturn : byte#)
+	;;
+	-> (syscall(Sysrt_sigaction, a(sig), a(act), a(oact), a(sizeof(sigflags))) : int)
+}
 const sigprocmask	= {sig, act, oact;	-> (syscall(Sysrt_sigprocmask, a(sig), a(act), a(oact), a(sizeof(sigflags))) : int)}
 
 /* threading */
--- a/lib/sys/syscall+linux-x64.s
+++ b/lib/sys/syscall+linux-x64.s
@@ -50,3 +50,7 @@
 	popq %r15
 	ret
 
+.globl sys$sigreturn
+sys$sigreturn:
+	movq $15,%rax
+	syscall