hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 78568e8f209304c3378c3361aa2a20218dbe8d3a
parent 8349e34943dce950ce2eb8f9cf84c1a4f2425733
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 11 Apr 2022 16:49:36 +0200

Merge linux::signalfd into unix::signal

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Dlinux/signalfd/signalfd.ha | 61-------------------------------------------------------------
Mscripts/gen-stdlib | 7-------
Mstdlib.mk | 28----------------------------
Munix/signal/+linux.ha | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Munix/signal/types.ha | 3+++
5 files changed, 73 insertions(+), 96 deletions(-)

diff --git a/linux/signalfd/signalfd.ha b/linux/signalfd/signalfd.ha @@ -1,61 +0,0 @@ -// License: MPL-2.0 -// (c) 2021 Drew DeVault <sir@cmpwn.com> -// (c) 2021 Eyal Sawady <ecs@d2evs.net> - -// TODO: Incorporate this model into a top-level 'signal' module and generalize -// it a bit. -use errors; -use rt; - -// Value populated by calls to read(2) for the signalfd. -export type siginfo = struct { - signo: u32, - errno: i32, - code: i32, - pid: u32, - uid: u32, - fd: int, - tid: u32, - band: u32, - overrun: u32, - trapno: u32, - status: i32, - int_: i32, - ptr: u64, - utime: u64, - stime: u64, - addr: u64, - addr_lsb: u16, - pad2: u16, - ssi_syscall: i32, - call_addr: u64, - arch: u32, - pad: [128 - 14 * 4 - 5 * 8 - 2 * 2]u8, -}; - -// Creates or updates a signalfd. Pass -1 to create a new signalfd, or an -// existing signalfd to update it. -export fn signalfd( - fd: int, - mask: *const rt::sigset, - flags: int, -) (int | errors::error) = { - match (rt::signalfd(fd, mask, flags)) { - case let fd: int => - return fd; - case let err: rt::errno => - return errors::errno(err); - }; -}; - -// Reads pending signal info from a signalfd. -export fn readsignal(fd: int) (siginfo | errors::error) = { - let si = siginfo { ... }; - match (rt::read(fd, &si, size(siginfo))) { - case let err: rt::errno => - return errors::errno(err); - case let z: size => - assert(z == size(siginfo)); - return si; - }; -}; diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -797,12 +797,6 @@ linux_keyctl() { gen_ssa -plinux linux::keyctl rt errors strings bytes } -linux_signalfd() { - gen_srcs -plinux linux::signalfd \ - signalfd.ha - gen_ssa -plinux linux::signalfd errors -} - linux_io_uring() { gen_srcs -plinux linux::io_uring \ cqe.ha \ @@ -1312,7 +1306,6 @@ io linux freebsd iobus::io_uring linux linux linux linux::keyctl linux -linux::signalfd linux linux::io_uring linux linux::vdso linux math diff --git a/stdlib.mk b/stdlib.mk @@ -452,10 +452,6 @@ stdlib_deps_linux+=$(stdlib_linux_linux) stdlib_linux_keyctl_linux=$(HARECACHE)/linux/keyctl/linux_keyctl-linux.o stdlib_deps_linux+=$(stdlib_linux_keyctl_linux) -# gen_lib linux::signalfd (linux) -stdlib_linux_signalfd_linux=$(HARECACHE)/linux/signalfd/linux_signalfd-linux.o -stdlib_deps_linux+=$(stdlib_linux_signalfd_linux) - # gen_lib linux::io_uring (linux) stdlib_linux_io_uring_linux=$(HARECACHE)/linux/io_uring/linux_io_uring-linux.o stdlib_deps_linux+=$(stdlib_linux_io_uring_linux) @@ -1332,16 +1328,6 @@ $(HARECACHE)/linux/keyctl/linux_keyctl-linux.ssa: $(stdlib_linux_keyctl_linux_sr @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nlinux::keyctl \ -t$(HARECACHE)/linux/keyctl/linux_keyctl.td $(stdlib_linux_keyctl_linux_srcs) -# linux::signalfd (+linux) -stdlib_linux_signalfd_linux_srcs= \ - $(STDLIB)/linux/signalfd/signalfd.ha - -$(HARECACHE)/linux/signalfd/linux_signalfd-linux.ssa: $(stdlib_linux_signalfd_linux_srcs) $(stdlib_rt) $(stdlib_errors_$(PLATFORM)) - @printf 'HAREC \t$@\n' - @mkdir -p $(HARECACHE)/linux/signalfd - @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nlinux::signalfd \ - -t$(HARECACHE)/linux/signalfd/linux_signalfd.td $(stdlib_linux_signalfd_linux_srcs) - # linux::io_uring (+linux) stdlib_linux_io_uring_linux_srcs= \ $(STDLIB)/linux/io_uring/cqe.ha \ @@ -2374,10 +2360,6 @@ testlib_deps_linux+=$(testlib_linux_linux) testlib_linux_keyctl_linux=$(TESTCACHE)/linux/keyctl/linux_keyctl-linux.o testlib_deps_linux+=$(testlib_linux_keyctl_linux) -# gen_lib linux::signalfd (linux) -testlib_linux_signalfd_linux=$(TESTCACHE)/linux/signalfd/linux_signalfd-linux.o -testlib_deps_linux+=$(testlib_linux_signalfd_linux) - # gen_lib linux::io_uring (linux) testlib_linux_io_uring_linux=$(TESTCACHE)/linux/io_uring/linux_io_uring-linux.o testlib_deps_linux+=$(testlib_linux_io_uring_linux) @@ -3290,16 +3272,6 @@ $(TESTCACHE)/linux/keyctl/linux_keyctl-linux.ssa: $(testlib_linux_keyctl_linux_s @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nlinux::keyctl \ -t$(TESTCACHE)/linux/keyctl/linux_keyctl.td $(testlib_linux_keyctl_linux_srcs) -# linux::signalfd (+linux) -testlib_linux_signalfd_linux_srcs= \ - $(STDLIB)/linux/signalfd/signalfd.ha - -$(TESTCACHE)/linux/signalfd/linux_signalfd-linux.ssa: $(testlib_linux_signalfd_linux_srcs) $(testlib_rt) $(testlib_errors_$(PLATFORM)) - @printf 'HAREC \t$@\n' - @mkdir -p $(TESTCACHE)/linux/signalfd - @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nlinux::signalfd \ - -t$(TESTCACHE)/linux/signalfd/linux_signalfd.td $(testlib_linux_signalfd_linux_srcs) - # linux::io_uring (+linux) testlib_linux_io_uring_linux_srcs= \ $(STDLIB)/linux/io_uring/cqe.ha \ diff --git a/unix/signal/+linux.ha b/unix/signal/+linux.ha @@ -1,3 +1,7 @@ +// License: MPL-2.0 +// (c) 2022 Drew DeVault <sir@cmpwn.com> +use errors; +use io; use rt; // Configures a new signal handler, returning the old details (which can be @@ -136,6 +140,72 @@ export type flag = enum int { export type signal = int; +// Value populated by calls to read(2) for the signalfd. +export type sigfdinfo = struct { + signo: u32, + errno: i32, + code: i32, + pid: u32, + uid: u32, + fd: int, + tid: u32, + band: u32, + overrun: u32, + trapno: u32, + status: i32, + int_: i32, + ptr: u64, + utime: u64, + stime: u64, + addr: u64, + addr_lsb: u16, + pad2: u16, + ssi_syscall: i32, + call_addr: u64, + arch: u32, + pad: [128 - 14 * 4 - 5 * 8 - 2 * 2]u8, +}; + +// Creates or updates a signal file. Pass -1 to create a new signalfd, or an +// existing signalfd to update it. +export fn signalfd( + fd: io::file, + opt: (flag | sigset)... +) (io::file | errors::error) = { + let sa_mask = newset(); + + let sa_flags = 0, nmask = 0; + for (let i = 0z; i < len(opt); i += 1) { + match (opt[i]) { + case let flag: flag => + sa_flags |= flag; + case let mask: sigset => + assert(nmask == 0, "Multiple signal masks provided to signal::handle"); + nmask += 1; + sa_mask = mask; + }; + }; + + match (rt::signalfd(fd, &sa_mask, sa_flags)) { + case let fd: int => + return fd; + case let err: rt::errno => + return errors::errno(err); + }; +}; + +// Reads pending signal info from a signalfd. +export fn readsignal(fd: io::file) (sigfdinfo | errors::error) = { + let si = sigfdinfo { ... }; + match (rt::read(fd, &si, size(sigfdinfo))) { + case let err: rt::errno => + return errors::errno(err); + case let z: size => + assert(z == size(sigfdinfo)); + return si; + }; +}; + // Hangup. export def SIGHUP: signal = rt::SIGHUP; // Terminal signalerrupt signal. diff --git a/unix/signal/types.ha b/unix/signal/types.ha @@ -1,3 +1,6 @@ +// License: MPL-2.0 +// (c) 2022 Drew DeVault <sir@cmpwn.com> + // A function which handles a signal. The first argument is the signal number // which was caught, the second provides information about the signal, and the // third argument is the ucontext, which is usually ignored by most signal