xref: /freebsd/lib/libsys/sigfastblock.2 (revision dab59af3bcc7cb7ba01569d3044894b3e860ad56)
1*dab59af3SLi-Wen Hsu.\" Copyright (c) 2016 The FreeBSD Foundation
28269e767SBrooks Davis.\"
38269e767SBrooks Davis.\" This documentation was written by
48269e767SBrooks Davis.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
58269e767SBrooks Davis.\" from the FreeBSD Foundation.
68269e767SBrooks Davis.\"
78269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
88269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
98269e767SBrooks Davis.\" are met:
108269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
118269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
128269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
138269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
148269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
158269e767SBrooks Davis.\"
168269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
178269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
188269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
198269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
208269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
218269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
228269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
238269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
248269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268269e767SBrooks Davis.\" SUCH DAMAGE.
278269e767SBrooks Davis.\"
288269e767SBrooks Davis.Dd December 13, 2019
298269e767SBrooks Davis.Dt SIGFASTBLOCK 2
308269e767SBrooks Davis.Os
318269e767SBrooks Davis.Sh NAME
328269e767SBrooks Davis.Nm sigfastblock
338269e767SBrooks Davis.Nd controls signals blocking with a simple memory write
348269e767SBrooks Davis.Sh LIBRARY
358269e767SBrooks Davis.Lb libc
368269e767SBrooks Davis.Sh SYNOPSIS
378269e767SBrooks Davis.In sys/signalvar.h
388269e767SBrooks Davis.Ft int
398269e767SBrooks Davis.Fn sigfastblock "int cmd" "void *ptr"
408269e767SBrooks Davis.Sh DESCRIPTION
418269e767SBrooks Davis.Bf -symbolic
428269e767SBrooks DavisThis function is not intended for a direct usage by applications.
438269e767SBrooks DavisThe functionality is provided for implementing some optimizations in
448269e767SBrooks Davis.Xr ld-elf.so.1 8
458269e767SBrooks Davisand
468269e767SBrooks Davis.Lb libthr .
478269e767SBrooks Davis.Ef
488269e767SBrooks Davis.Pp
498269e767SBrooks DavisThe function configures the kernel facility that allows a thread to
508269e767SBrooks Davisblock asynchronous signals delivery with a single write to userspace
518269e767SBrooks Davismemory, avoiding overhead of system calls like
528269e767SBrooks Davis.Xr sigprocmask 2
538269e767SBrooks Davisfor establishing critical sections.
548269e767SBrooks DavisThe C runtime uses it to optimize implementation of async-signal-safe
558269e767SBrooks Davisfunctionality.
568269e767SBrooks Davis.Pp
578269e767SBrooks DavisA thread might register a
588269e767SBrooks Davis.Dv sigblock
598269e767SBrooks Davisvariable of type
608269e767SBrooks Davis.Vt int
618269e767SBrooks Davisas a location which is consulted by kernel when calculating the
628269e767SBrooks Davisblocked signal mask for delivery of asynchronous signals.
638269e767SBrooks DavisIf the variable indicates that blocking is requested, then the kernel
648269e767SBrooks Daviseffectively operates as if the mask containing all blockable signals was
658269e767SBrooks Davissupplied to
668269e767SBrooks Davis.Xr sigprocmask 2 .
678269e767SBrooks Davis.Pp
688269e767SBrooks DavisThe variable is supposed to be modified only from the owning thread,
698269e767SBrooks Davisthere is no way to guarantee visibility of update from other thread
708269e767SBrooks Davisto kernel when signals are delivered.
718269e767SBrooks Davis.Pp
728269e767SBrooks DavisLower bits of the sigblock variable are reserved as flags,
738269e767SBrooks Daviswhich might be set or cleared by kernel at arbitrary moments.
748269e767SBrooks DavisUserspace code should use
758269e767SBrooks Davis.Xr atomic 9
768269e767SBrooks Davisoperations of incrementing and decrementing by
778269e767SBrooks Davis.Dv SIGFASTBLOCK_INC
788269e767SBrooks Davisquantity to recursively block or unblock signals delivery.
798269e767SBrooks Davis.Pp
808269e767SBrooks DavisIf a signal would be delivered when unmasked, kernel might set the
818269e767SBrooks Davis.Dv SIGFASTBLOCK_PEND
828269e767SBrooks Davis.Dq pending signal
838269e767SBrooks Davisflag in the sigblock variable.
848269e767SBrooks DavisUserspace should perform
858269e767SBrooks Davis.Dv SIGFASTBLOCK_UNBLOCK
868269e767SBrooks Davisoperation when clearing the variable if it notes the pending signal
878269e767SBrooks Davisbit is set, which would deliver the pending signals immediately.
888269e767SBrooks DavisOtherwise, signals delivery might be postponed.
898269e767SBrooks Davis.Pp
908269e767SBrooks DavisThe
918269e767SBrooks Davis.Fa cmd
928269e767SBrooks Davisargument specifies one of the following operations:
938269e767SBrooks Davis.Bl -tag -width SIGFASTBLOCK_UNSETPTR
948269e767SBrooks Davis.It Dv SIGFASTBLOCK_SETPTR
958269e767SBrooks DavisRegister the variable of type
968269e767SBrooks Davis.Vt int
978269e767SBrooks Davisat location pointed to by the
988269e767SBrooks Davis.Fa ptr
998269e767SBrooks Davisargument as sigblock variable for the calling thread.
1008269e767SBrooks Davis.It Dv SIGFASTBLOCK_UNSETPTR
1018269e767SBrooks DavisUnregister the currently registered sigblock location.
1028269e767SBrooks DavisKernel stops inferring the blocked mask from non-zero value of its
1038269e767SBrooks Davisblocked count.
1048269e767SBrooks DavisNew location can be registered after previous one is deregistered.
1058269e767SBrooks Davis.It Dv SIGFASTBLOCK_UNBLOCK
1068269e767SBrooks DavisIf there are pending signals which should be delivered to the calling
1078269e767SBrooks Davisthread, they are delivered before returning from the call.
1088269e767SBrooks DavisThe sigblock variable should have zero blocking count, and indicate
1098269e767SBrooks Davisthat the pending signal exists.
1108269e767SBrooks DavisEffectively this means that the variable should have the value
1118269e767SBrooks Davis.Dv SIGFASTBLOCK_PEND .
1128269e767SBrooks Davis.El
1138269e767SBrooks Davis.Sh RETURN VALUES
1148269e767SBrooks Davis.Rv -std
1158269e767SBrooks Davis.Sh ERRORS
1168269e767SBrooks DavisThe operation may fail with the following errors:
1178269e767SBrooks Davis.Bl -tag -width Er
1188269e767SBrooks Davis.It Bq Er EBUSY
1198269e767SBrooks DavisThe
1208269e767SBrooks Davis.Dv SIGFASTBLOCK_SETPTR
1218269e767SBrooks Davisattempted while the sigblock address was already registered.
1228269e767SBrooks DavisThe
1238269e767SBrooks Davis.Dv SIGFASTBLOCK_UNBLOCK
1248269e767SBrooks Daviswas called while sigblock variable value is not equal to
1258269e767SBrooks Davis.Dv SIGFASTBLOCK_PEND .
1268269e767SBrooks Davis.It Bq Er EINVAL
1278269e767SBrooks DavisThe variable address passed to
1288269e767SBrooks Davis.Dv SIGFASTBLOCK_SETPTR
1298269e767SBrooks Davisis not aligned naturally.
1308269e767SBrooks DavisThe
1318269e767SBrooks Davis.Dv SIGFASTBLOCK_UNSETPTR
1328269e767SBrooks Davisoperation was attempted without prior successful call to
1338269e767SBrooks Davis.Dv SIGFASTBLOCK_SETPTR .
1348269e767SBrooks Davis.It Bq Er EFAULT
1358269e767SBrooks DavisAttempt to read or write to the sigblock variable failed.
1368269e767SBrooks DavisNote that kernel generates the
1378269e767SBrooks Davis.Dv SIGSEGV
1388269e767SBrooks Davissignal if an attempt to read from the sigblock variable faulted
1398269e767SBrooks Davisduring implicit accesses from syscall entry.
1408269e767SBrooks Davis.El
1418269e767SBrooks Davis.Sh SEE ALSO
1428269e767SBrooks Davis.Xr kill 2 ,
1438269e767SBrooks Davis.Xr signal 2 ,
1448269e767SBrooks Davis.Xr sigprocmask 2 ,
1458269e767SBrooks Davis.Xr libthr 3 ,
1468269e767SBrooks Davis.Xr ld-elf.so.1 8
1478269e767SBrooks Davis.Sh STANDARDS
1488269e767SBrooks DavisThe
1498269e767SBrooks Davis.Nm
1508269e767SBrooks Davisfunction is non-standard, although a similar functionality is a common
1518269e767SBrooks Davisoptimization provided by several other systems.
1528269e767SBrooks Davis.Sh HISTORY
1538269e767SBrooks DavisThe
1548269e767SBrooks Davis.Nm
1558269e767SBrooks Davisfunction was introduced in
1568269e767SBrooks Davis.Fx 13.0 .
1578269e767SBrooks Davis.Sh BUGS
1588269e767SBrooks DavisThe
1598269e767SBrooks Davis.Nm
1608269e767SBrooks Davissymbol is currently not exported by libc, on purpose.
1618269e767SBrooks DavisConsumers should either use the
1628269e767SBrooks Davis.Dv __sys_fast_sigblock
1638269e767SBrooks Davissymbol from the private libc namespace, or utilize
1648269e767SBrooks Davis.Xr syscall 2 .
165