From 295e0e815703a17d0df3b17cd0a4639c0bf549fd Mon Sep 17 00:00:00 2001 From: Lorenz Bauer Date: Mon, 26 Sep 2022 20:36:51 +0000 Subject: [PATCH] unix: add PthreadSigmask for Linux Add a syscall wrapper for SYS_RT_SIGPROCMASK and export it as PthreadSigmask. The latter is defined by POSIX and can therefore be implemented by Darwin, etc. later on. Follow the approach used by Signalfd of passing _C__NSIG/8 as sigsetsize. This avoids exporting _C__NSIG and allows the syscall to work with the current definition of Sigset_t, which doesn't match the kernel definition of Sigset_t. Updates golang/go#55349 --- unix/syscall_linux.go | 11 ++++++++++- unix/zsyscall_linux.go | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 47146911f..583ff00d5 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -2368,6 +2368,16 @@ func Setitimer(which ItimerWhich, it Itimerval) (Itimerval, error) { return prev, nil } +//sysnb rtSigprocmask(how int, set *Sigset_t, oldset *Sigset_t, sigsetsize uintptr) (err error) = SYS_RT_SIGPROCMASK + +func PthreadSigmask(how int, set, oldset *Sigset_t) error { + if oldset != nil { + // Explicitly clear in case Sigset_t is larger than _C__NSIG. + *oldset = Sigset_t{} + } + return rtSigprocmask(how, set, oldset, _C__NSIG/8) +} + /* * Unimplemented */ @@ -2426,7 +2436,6 @@ func Setitimer(which ItimerWhich, it Itimerval) (Itimerval, error) { // RestartSyscall // RtSigaction // RtSigpending -// RtSigprocmask // RtSigqueueinfo // RtSigreturn // RtSigsuspend diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index bc4a27531..293cf3680 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -2151,3 +2151,13 @@ func setitimer(which int, newValue *Itimerval, oldValue *Itimerval) (err error) } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func rtSigprocmask(how int, set *Sigset_t, oldset *Sigset_t, sigsetsize uintptr) (err error) { + _, _, e1 := RawSyscall6(SYS_RT_SIGPROCMASK, uintptr(how), uintptr(unsafe.Pointer(set)), uintptr(unsafe.Pointer(oldset)), uintptr(sigsetsize), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +}