1*8269e767SBrooks Davis.\" Copyright (c) 2016 The FreeBSD Foundation, Inc. 2*8269e767SBrooks Davis.\" 3*8269e767SBrooks Davis.\" This documentation was written by 4*8269e767SBrooks Davis.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship 5*8269e767SBrooks Davis.\" from the FreeBSD Foundation. 6*8269e767SBrooks Davis.\" 7*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 8*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 9*8269e767SBrooks Davis.\" are met: 10*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 11*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 12*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 13*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 14*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 15*8269e767SBrooks Davis.\" 16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*8269e767SBrooks Davis.\" SUCH DAMAGE. 27*8269e767SBrooks Davis.\" 28*8269e767SBrooks Davis.Dd December 13, 2019 29*8269e767SBrooks Davis.Dt SIGFASTBLOCK 2 30*8269e767SBrooks Davis.Os 31*8269e767SBrooks Davis.Sh NAME 32*8269e767SBrooks Davis.Nm sigfastblock 33*8269e767SBrooks Davis.Nd controls signals blocking with a simple memory write 34*8269e767SBrooks Davis.Sh LIBRARY 35*8269e767SBrooks Davis.Lb libc 36*8269e767SBrooks Davis.Sh SYNOPSIS 37*8269e767SBrooks Davis.In sys/signalvar.h 38*8269e767SBrooks Davis.Ft int 39*8269e767SBrooks Davis.Fn sigfastblock "int cmd" "void *ptr" 40*8269e767SBrooks Davis.Sh DESCRIPTION 41*8269e767SBrooks Davis.Bf -symbolic 42*8269e767SBrooks DavisThis function is not intended for a direct usage by applications. 43*8269e767SBrooks DavisThe functionality is provided for implementing some optimizations in 44*8269e767SBrooks Davis.Xr ld-elf.so.1 8 45*8269e767SBrooks Davisand 46*8269e767SBrooks Davis.Lb libthr . 47*8269e767SBrooks Davis.Ef 48*8269e767SBrooks Davis.Pp 49*8269e767SBrooks DavisThe function configures the kernel facility that allows a thread to 50*8269e767SBrooks Davisblock asynchronous signals delivery with a single write to userspace 51*8269e767SBrooks Davismemory, avoiding overhead of system calls like 52*8269e767SBrooks Davis.Xr sigprocmask 2 53*8269e767SBrooks Davisfor establishing critical sections. 54*8269e767SBrooks DavisThe C runtime uses it to optimize implementation of async-signal-safe 55*8269e767SBrooks Davisfunctionality. 56*8269e767SBrooks Davis.Pp 57*8269e767SBrooks DavisA thread might register a 58*8269e767SBrooks Davis.Dv sigblock 59*8269e767SBrooks Davisvariable of type 60*8269e767SBrooks Davis.Vt int 61*8269e767SBrooks Davisas a location which is consulted by kernel when calculating the 62*8269e767SBrooks Davisblocked signal mask for delivery of asynchronous signals. 63*8269e767SBrooks DavisIf the variable indicates that blocking is requested, then the kernel 64*8269e767SBrooks Daviseffectively operates as if the mask containing all blockable signals was 65*8269e767SBrooks Davissupplied to 66*8269e767SBrooks Davis.Xr sigprocmask 2 . 67*8269e767SBrooks Davis.Pp 68*8269e767SBrooks DavisThe variable is supposed to be modified only from the owning thread, 69*8269e767SBrooks Davisthere is no way to guarantee visibility of update from other thread 70*8269e767SBrooks Davisto kernel when signals are delivered. 71*8269e767SBrooks Davis.Pp 72*8269e767SBrooks DavisLower bits of the sigblock variable are reserved as flags, 73*8269e767SBrooks Daviswhich might be set or cleared by kernel at arbitrary moments. 74*8269e767SBrooks DavisUserspace code should use 75*8269e767SBrooks Davis.Xr atomic 9 76*8269e767SBrooks Davisoperations of incrementing and decrementing by 77*8269e767SBrooks Davis.Dv SIGFASTBLOCK_INC 78*8269e767SBrooks Davisquantity to recursively block or unblock signals delivery. 79*8269e767SBrooks Davis.Pp 80*8269e767SBrooks DavisIf a signal would be delivered when unmasked, kernel might set the 81*8269e767SBrooks Davis.Dv SIGFASTBLOCK_PEND 82*8269e767SBrooks Davis.Dq pending signal 83*8269e767SBrooks Davisflag in the sigblock variable. 84*8269e767SBrooks DavisUserspace should perform 85*8269e767SBrooks Davis.Dv SIGFASTBLOCK_UNBLOCK 86*8269e767SBrooks Davisoperation when clearing the variable if it notes the pending signal 87*8269e767SBrooks Davisbit is set, which would deliver the pending signals immediately. 88*8269e767SBrooks DavisOtherwise, signals delivery might be postponed. 89*8269e767SBrooks Davis.Pp 90*8269e767SBrooks DavisThe 91*8269e767SBrooks Davis.Fa cmd 92*8269e767SBrooks Davisargument specifies one of the following operations: 93*8269e767SBrooks Davis.Bl -tag -width SIGFASTBLOCK_UNSETPTR 94*8269e767SBrooks Davis.It Dv SIGFASTBLOCK_SETPTR 95*8269e767SBrooks DavisRegister the variable of type 96*8269e767SBrooks Davis.Vt int 97*8269e767SBrooks Davisat location pointed to by the 98*8269e767SBrooks Davis.Fa ptr 99*8269e767SBrooks Davisargument as sigblock variable for the calling thread. 100*8269e767SBrooks Davis.It Dv SIGFASTBLOCK_UNSETPTR 101*8269e767SBrooks DavisUnregister the currently registered sigblock location. 102*8269e767SBrooks DavisKernel stops inferring the blocked mask from non-zero value of its 103*8269e767SBrooks Davisblocked count. 104*8269e767SBrooks DavisNew location can be registered after previous one is deregistered. 105*8269e767SBrooks Davis.It Dv SIGFASTBLOCK_UNBLOCK 106*8269e767SBrooks DavisIf there are pending signals which should be delivered to the calling 107*8269e767SBrooks Davisthread, they are delivered before returning from the call. 108*8269e767SBrooks DavisThe sigblock variable should have zero blocking count, and indicate 109*8269e767SBrooks Davisthat the pending signal exists. 110*8269e767SBrooks DavisEffectively this means that the variable should have the value 111*8269e767SBrooks Davis.Dv SIGFASTBLOCK_PEND . 112*8269e767SBrooks Davis.El 113*8269e767SBrooks Davis.Sh RETURN VALUES 114*8269e767SBrooks Davis.Rv -std 115*8269e767SBrooks Davis.Sh ERRORS 116*8269e767SBrooks DavisThe operation may fail with the following errors: 117*8269e767SBrooks Davis.Bl -tag -width Er 118*8269e767SBrooks Davis.It Bq Er EBUSY 119*8269e767SBrooks DavisThe 120*8269e767SBrooks Davis.Dv SIGFASTBLOCK_SETPTR 121*8269e767SBrooks Davisattempted while the sigblock address was already registered. 122*8269e767SBrooks DavisThe 123*8269e767SBrooks Davis.Dv SIGFASTBLOCK_UNBLOCK 124*8269e767SBrooks Daviswas called while sigblock variable value is not equal to 125*8269e767SBrooks Davis.Dv SIGFASTBLOCK_PEND . 126*8269e767SBrooks Davis.It Bq Er EINVAL 127*8269e767SBrooks DavisThe variable address passed to 128*8269e767SBrooks Davis.Dv SIGFASTBLOCK_SETPTR 129*8269e767SBrooks Davisis not aligned naturally. 130*8269e767SBrooks DavisThe 131*8269e767SBrooks Davis.Dv SIGFASTBLOCK_UNSETPTR 132*8269e767SBrooks Davisoperation was attempted without prior successful call to 133*8269e767SBrooks Davis.Dv SIGFASTBLOCK_SETPTR . 134*8269e767SBrooks Davis.It Bq Er EFAULT 135*8269e767SBrooks DavisAttempt to read or write to the sigblock variable failed. 136*8269e767SBrooks DavisNote that kernel generates the 137*8269e767SBrooks Davis.Dv SIGSEGV 138*8269e767SBrooks Davissignal if an attempt to read from the sigblock variable faulted 139*8269e767SBrooks Davisduring implicit accesses from syscall entry. 140*8269e767SBrooks Davis.El 141*8269e767SBrooks Davis.Sh SEE ALSO 142*8269e767SBrooks Davis.Xr kill 2 , 143*8269e767SBrooks Davis.Xr signal 2 , 144*8269e767SBrooks Davis.Xr sigprocmask 2 , 145*8269e767SBrooks Davis.Xr libthr 3 , 146*8269e767SBrooks Davis.Xr ld-elf.so.1 8 147*8269e767SBrooks Davis.Sh STANDARDS 148*8269e767SBrooks DavisThe 149*8269e767SBrooks Davis.Nm 150*8269e767SBrooks Davisfunction is non-standard, although a similar functionality is a common 151*8269e767SBrooks Davisoptimization provided by several other systems. 152*8269e767SBrooks Davis.Sh HISTORY 153*8269e767SBrooks DavisThe 154*8269e767SBrooks Davis.Nm 155*8269e767SBrooks Davisfunction was introduced in 156*8269e767SBrooks Davis.Fx 13.0 . 157*8269e767SBrooks Davis.Sh BUGS 158*8269e767SBrooks DavisThe 159*8269e767SBrooks Davis.Nm 160*8269e767SBrooks Davissymbol is currently not exported by libc, on purpose. 161*8269e767SBrooks DavisConsumers should either use the 162*8269e767SBrooks Davis.Dv __sys_fast_sigblock 163*8269e767SBrooks Davissymbol from the private libc namespace, or utilize 164*8269e767SBrooks Davis.Xr syscall 2 . 165