shithub: mc

Download patch

ref: bc9308b1a6a9255d43113e5d4ee30b16e688c159
parent: f97eb726adadbde0e2d855b8b59f4f84f403d491
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Nov 21 11:34:49 EST 2016

Add signals on Linux.

    ...I think it works.

--- a/lib/sys/setup+posixy.myr
+++ b/lib/sys/setup+posixy.myr
@@ -10,7 +10,6 @@
 	sa = [
 		.handler = ({;} : byte#),
 		.flags = sys.Sarestart,
-		.mask = [.bits = [0,0,0,0]]
 	]
 	sys.sigaction(Sigpipe, &sa, &osa)
 }
--- a/lib/sys/sys+linux-x64.myr
+++ b/lib/sys/sys+linux-x64.myr
@@ -28,6 +28,8 @@
 	type pollevt	= uint16
 
 	type futexop	= uint32
+	type signo	= int32
+	type sigflags	= int64
 
 	type clock = union
 		`Clockrealtime
@@ -49,6 +51,17 @@
 		`Waitfail int32
 	;;
 
+	type sigset = struct
+		bits : uint32[2]
+	;;
+
+	type sigaction = struct
+		handler	: byte#	/* code pointer */
+		flags	: sigflags
+		restore	: byte#	/* code pointer */
+		mask	: sigset
+	;;
+
 	type timespec = struct
 		sec	: uint64
 		nsec	: uint64
@@ -320,6 +333,50 @@
 	/* return value for a failed mapping */
 	const Mapbad	: byte# = (-1 : byte#)
 
+	/* signal flags */
+	const Sanocldstop	: sigflags = 0x00000001
+	const Sanocldwait	: sigflags = 0x00000002
+	const Sasiginfo		: sigflags = 0x00000004
+	const Saonstack		: sigflags = 0x08000000
+	const Sarestart		: sigflags = 0x10000000
+	const Sanodefer		: sigflags = 0x40000000
+	const Saresethand	: sigflags = 0x80000000
+	const Sanomask		: sigflags = Sanodefer
+	const Saoneshot		: sigflags = Saresethand
+
+	/* signal numbers */
+	const Sighup	: signo = 1
+	const Sigint	: signo = 2
+	const Sigquit	: signo = 3
+	const Sigill	: signo = 4
+	const Sigtrap	: signo = 5
+	const Sigabrt	: signo = 6
+	const Sigiot	: signo = 6
+	const Sigbus	: signo = 7
+	const Sigfpe	: signo = 8
+	const Sigkill	: signo = 9
+	const Sigusr1	: signo = 10
+	const Sigsegv	: signo = 11
+	const Sigusr2	: signo = 12
+	const Sigpipe	: signo = 13
+	const Sigalrm	: signo = 14
+	const Sigterm	: signo = 15
+	const Sigstkflt	: signo = 16
+	const Sigchld	: signo = 17
+	const Sigcont	: signo = 18
+	const Sigstop	: signo = 19
+	const Sigtstp	: signo = 20
+	const Sigttin	: signo = 21
+	const Sigttou	: signo = 22
+	const Sigurg	: signo = 23
+	const Sigxcpu	: signo = 24
+	const Sigxfsz	: signo = 25
+	const Sigvtalrm	: signo = 26
+	const Sigprof	: signo = 27
+	const Sigwinch	: signo = 28
+	const Sigio	: signo = 29
+	const Sigpoll	: signo = Sigio
+
 	/* syscalls */
 	const Sysread			: scno = 0
 	const Syswrite			: scno = 1
@@ -679,6 +736,10 @@
 	const chdir	: (p : byte[:] -> int64)
 	const getcwd	: (buf : byte[:] -> int64)
 
+	/* signals */
+	const sigaction	: (sig : signo, act : sigaction#, oact : sigaction# -> int)
+	const sigprocmask	: (how : int32, set : sigset#, oset : sigset# -> int)
+
 	/* fd stuff */
 	const pipe	: (fds : fd[2]# -> int64)
 	const dup	: (fd : fd -> fd)
@@ -808,6 +869,9 @@
 const pipe	= {fds;	-> syscall(Syspipe, a(fds))}
 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 sigprocmask	= {sig, act, oact;	-> (syscall(Sysrt_sigprocmask, a(sig), a(act), a(oact), a(sizeof(sigflags))) : int)}
 
 /* threading */
 const futex	= {uaddr, op, val, timeout, uaddr2, val3