hare

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

commit 9bedb017e94feed235c1fd63466a2ceb9ee03f48
parent 3f16c35884173128b1ac21577cd1a13576384034
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 23 May 2021 14:20:52 -0400

linux::signalfd: new module

This is not the final state of signal handling for Hare.

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

Diffstat:
Alinux/signalfd/signalfd.ha | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mscripts/gen-stdlib | 7+++++++
Mstdlib.mk | 28++++++++++++++++++++++++++++
3 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/linux/signalfd/signalfd.ha b/linux/signalfd/signalfd.ha @@ -0,0 +1,55 @@ +// 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::opaque) = { + return match (rt::signalfd(fd, mask, flags)) { + fd: int => fd, + err: rt::errno => errors::errno(err), + }; +}; + +// Reads pending signal info from a signalfd. +export fn readsignal(fd: int) (siginfo | errors::opaque) = { + let si = siginfo { ... }; + return match (rt::read(fd, &si, size(siginfo))) { + err: rt::errno => errors::errno(err), + z: size => { + assert(z == size(siginfo)); + return si; + }, + }; +}; diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -517,6 +517,12 @@ linux() { gen_ssa linux format::elf } +linux_signalfd() { + gen_srcs linux::signalfd \ + signalfd.ha + gen_ssa linux::signalfd errors +} + linux_io_uring() { gen_srcs linux::io_uring \ cqe.ha \ @@ -780,6 +786,7 @@ hash::crc64 hash::fnv io linux +linux::signalfd linux::io_uring linux::vdso net diff --git a/stdlib.mk b/stdlib.mk @@ -229,6 +229,10 @@ hare_stdlib_deps+=$(stdlib_io) stdlib_linux=$(HARECACHE)/linux/linux.o hare_stdlib_deps+=$(stdlib_linux) +# gen_lib linux::signalfd +stdlib_linux_signalfd=$(HARECACHE)/linux/signalfd/linux_signalfd.o +hare_stdlib_deps+=$(stdlib_linux_signalfd) + # gen_lib linux::io_uring stdlib_linux_io_uring=$(HARECACHE)/linux/io_uring/linux_io_uring.o hare_stdlib_deps+=$(stdlib_linux_io_uring) @@ -756,6 +760,16 @@ $(HARECACHE)/linux/linux.ssa: $(stdlib_linux_srcs) $(stdlib_rt) $(stdlib_format_ @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nlinux \ -t$(HARECACHE)/linux/linux.td $(stdlib_linux_srcs) +# linux::signalfd +stdlib_linux_signalfd_srcs= \ + $(STDLIB)/linux/signalfd/signalfd.ha + +$(HARECACHE)/linux/signalfd/linux_signalfd.ssa: $(stdlib_linux_signalfd_srcs) $(stdlib_rt) $(stdlib_errors) + @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_srcs) + # linux::io_uring stdlib_linux_io_uring_srcs= \ $(STDLIB)/linux/io_uring/cqe.ha \ @@ -1264,6 +1278,10 @@ hare_testlib_deps+=$(testlib_io) testlib_linux=$(TESTCACHE)/linux/linux.o hare_testlib_deps+=$(testlib_linux) +# gen_lib linux::signalfd +testlib_linux_signalfd=$(TESTCACHE)/linux/signalfd/linux_signalfd.o +hare_testlib_deps+=$(testlib_linux_signalfd) + # gen_lib linux::io_uring testlib_linux_io_uring=$(TESTCACHE)/linux/io_uring/linux_io_uring.o hare_testlib_deps+=$(testlib_linux_io_uring) @@ -1810,6 +1828,16 @@ $(TESTCACHE)/linux/linux.ssa: $(testlib_linux_srcs) $(testlib_rt) $(testlib_form @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nlinux \ -t$(TESTCACHE)/linux/linux.td $(testlib_linux_srcs) +# linux::signalfd +testlib_linux_signalfd_srcs= \ + $(STDLIB)/linux/signalfd/signalfd.ha + +$(TESTCACHE)/linux/signalfd/linux_signalfd.ssa: $(testlib_linux_signalfd_srcs) $(testlib_rt) $(testlib_errors) + @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_srcs) + # linux::io_uring testlib_linux_io_uring_srcs= \ $(STDLIB)/linux/io_uring/cqe.ha \