Blame man7/attributes.7

Packit 7cfc04
.\" Copyright (c) 2014, Red Hat, Inc
Packit 7cfc04
.\"     Written by Alexandre Oliva <aoliva@redhat.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
Packit 7cfc04
.\" This is free documentation; you can redistribute it and/or
Packit 7cfc04
.\" modify it under the terms of the GNU General Public License as
Packit 7cfc04
.\" published by the Free Software Foundation; either version 2 of
Packit 7cfc04
.\" the License, or (at your option) any later version.
Packit 7cfc04
.\"
Packit 7cfc04
.\" The GNU General Public License's references to "object code"
Packit 7cfc04
.\" and "executables" are to be interpreted as the output of any
Packit 7cfc04
.\" document formatting or typesetting system, including
Packit 7cfc04
.\" intermediate and printed output.
Packit 7cfc04
.\"
Packit 7cfc04
.\" This manual is distributed in the hope that it will be useful,
Packit 7cfc04
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 7cfc04
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 7cfc04
.\" GNU General Public License for more details.
Packit 7cfc04
.\"
Packit 7cfc04
.\" You should have received a copy of the GNU General Public
Packit 7cfc04
.\" License along with this manual; if not, see
Packit 7cfc04
.\" <http://www.gnu.org/licenses/>.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.TH ATTRIBUTES 7 2015-03-02 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
attributes \- POSIX safety concepts
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.\"
Packit 7cfc04
.\"
Packit 7cfc04
.IR Note :
Packit 7cfc04
the text of this man page is based on the material taken from
Packit 7cfc04
the "POSIX Safety Concepts" section of the GNU C Library manual.
Packit 7cfc04
Further details on the topics described here can be found in that
Packit 7cfc04
manual.
Packit 7cfc04
.PP
Packit 7cfc04
Various function manual pages include a section ATTRIBUTES
Packit 7cfc04
that describes the safety of calling the function in various contexts.
Packit 7cfc04
This section annotates functions with the following safety markings:
Packit 7cfc04
.TP
Packit 7cfc04
.I MT-Safe
Packit 7cfc04
.I MT-Safe
Packit 7cfc04
or
Packit 7cfc04
Thread-Safe functions are safe to call in the presence
Packit 7cfc04
of other threads.
Packit 7cfc04
MT, in MT-Safe, stands for Multi Thread.
Packit 7cfc04
.IP
Packit 7cfc04
Being MT-Safe does not imply a function is atomic, nor that it uses any
Packit 7cfc04
of the memory synchronization mechanisms POSIX exposes to users.
Packit 7cfc04
It is even possible that calling MT-Safe functions in sequence
Packit 7cfc04
does not yield an MT-Safe combination.
Packit 7cfc04
For example, having a thread call two MT-Safe
Packit 7cfc04
functions one right after the other does not guarantee behavior
Packit 7cfc04
equivalent to atomic execution of a combination of both functions,
Packit 7cfc04
since concurrent calls in other threads may interfere in a destructive way.
Packit 7cfc04
.IP
Packit 7cfc04
Whole-program optimizations that could inline functions across library
Packit 7cfc04
interfaces may expose unsafe reordering, and so performing inlining
Packit 7cfc04
across the GNU C Library interface is not recommended.
Packit 7cfc04
The documented
Packit 7cfc04
MT-Safety status is not guaranteed under whole-program optimization.
Packit 7cfc04
However, functions defined in user-visible headers are designed to be
Packit 7cfc04
safe for inlining.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I AS-Safe
Packit 7cfc04
.\" .I AS-Safe
Packit 7cfc04
.\" or Async-Signal-Safe functions are safe to call from
Packit 7cfc04
.\" asynchronous signal handlers.
Packit 7cfc04
.\" AS, in AS-Safe, stands for Asynchronous Signal.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Many functions that are AS-Safe may set
Packit 7cfc04
.\" .IR errno ,
Packit 7cfc04
.\" or modify the floating-point environment,
Packit 7cfc04
.\" because their doing so does not make them
Packit 7cfc04
.\" unsuitable for use in signal handlers.
Packit 7cfc04
.\" However, programs could misbehave should asynchronous signal handlers
Packit 7cfc04
.\" modify this thread-local state,
Packit 7cfc04
.\" and the signal handling machinery cannot be counted on to
Packit 7cfc04
.\" preserve it.
Packit 7cfc04
.\" Therefore, signal handlers that call functions that may set
Packit 7cfc04
.\" .I errno
Packit 7cfc04
.\" or modify the floating-point environment
Packit 7cfc04
.\" .I must
Packit 7cfc04
.\" save their original values, and restore them before returning.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I AC-Safe
Packit 7cfc04
.\" .I AC-Safe
Packit 7cfc04
.\" or Async-Cancel-Safe functions are safe to call when
Packit 7cfc04
.\" asynchronous cancellation is enabled.
Packit 7cfc04
.\" AC in AC-Safe stands for Asynchronous Cancellation.
Packit 7cfc04
.\"
Packit 7cfc04
.\" The POSIX standard defines only three functions to be AC-Safe, namely
Packit 7cfc04
.\" .BR pthread_cancel (3),
Packit 7cfc04
.\" .BR pthread_setcancelstate (3),
Packit 7cfc04
.\" and
Packit 7cfc04
.\" .BR pthread_setcanceltype (3).
Packit 7cfc04
.\" At present the GNU C Library provides no
Packit 7cfc04
.\" guarantees beyond these three functions,
Packit 7cfc04
.\" but does document which functions are presently AC-Safe.
Packit 7cfc04
.\" This documentation is provided for use
Packit 7cfc04
.\" by the GNU C Library developers.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Just like signal handlers, cancellation cleanup routines must configure
Packit 7cfc04
.\" the floating point environment they require.
Packit 7cfc04
.\" The routines cannot assume a floating point environment,
Packit 7cfc04
.\" particularly when asynchronous cancellation is enabled.
Packit 7cfc04
.\" If the configuration of the floating point
Packit 7cfc04
.\" environment cannot be performed atomically then it is also possible that
Packit 7cfc04
.\" the environment encountered is internally inconsistent.
Packit 7cfc04
.TP
Packit 7cfc04
.IR MT-Unsafe \" ", " AS-Unsafe ", " AC-Unsafe
Packit 7cfc04
.IR MT-Unsafe \" ", " AS-Unsafe ", " AC-Unsafe
Packit 7cfc04
functions are not safe to call in a multithreaded programs.
Packit 7cfc04
.\" functions are not
Packit 7cfc04
.\" safe to call within the safety contexts described above.
Packit 7cfc04
.\" Calling them
Packit 7cfc04
.\" within such contexts invokes undefined behavior.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Functions not explicitly documented as safe in a safety context should
Packit 7cfc04
.\" be regarded as Unsafe.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I Preliminary
Packit 7cfc04
.\" .I Preliminary
Packit 7cfc04
.\" safety properties are documented, indicating these
Packit 7cfc04
.\" properties may
Packit 7cfc04
.\" .I not
Packit 7cfc04
.\" be counted on in future releases of
Packit 7cfc04
.\" the GNU C Library.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Such preliminary properties are the result of an assessment of the
Packit 7cfc04
.\" properties of our current implementation,
Packit 7cfc04
.\" rather than of what is mandated and permitted
Packit 7cfc04
.\" by current and future standards.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Although we strive to abide by the standards, in some cases our
Packit 7cfc04
.\" implementation is safe even when the standard does not demand safety,
Packit 7cfc04
.\" and in other cases our implementation does not meet the standard safety
Packit 7cfc04
.\" requirements.
Packit 7cfc04
.\" The latter are most likely bugs; the former, when marked
Packit 7cfc04
.\" as
Packit 7cfc04
.\" .IR Preliminary ,
Packit 7cfc04
.\" should not be counted on: future standards may
Packit 7cfc04
.\" require changes that are not compatible with the additional safety
Packit 7cfc04
.\" properties afforded by the current implementation.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Furthermore,
Packit 7cfc04
.\" the POSIX standard does not offer a detailed definition of safety.
Packit 7cfc04
.\" We assume that, by "safe to call", POSIX means that,
Packit 7cfc04
.\" as long as the program does not invoke undefined behavior,
Packit 7cfc04
.\" the "safe to call" function behaves as specified,
Packit 7cfc04
.\" and does not cause other functions to deviate from their specified behavior.
Packit 7cfc04
.\" We have chosen to use its loose
Packit 7cfc04
.\" definitions of safety, not because they are the best definitions to use,
Packit 7cfc04
.\" but because choosing them harmonizes this manual with POSIX.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Please keep in mind that these are preliminary definitions and annotations,
Packit 7cfc04
.\" and certain aspects of the definitions are still under
Packit 7cfc04
.\" discussion and might be subject to clarification or change.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Over time,
Packit 7cfc04
.\" we envision evolving the preliminary safety notes into stable commitments,
Packit 7cfc04
.\" as stable as those of our interfaces.
Packit 7cfc04
.\" As we do, we will remove the
Packit 7cfc04
.\" .I Preliminary
Packit 7cfc04
.\" keyword from safety notes.
Packit 7cfc04
.\" As long as the keyword remains, however,
Packit 7cfc04
.\" they are not to be regarded as a promise of future behavior.
Packit 7cfc04
.PP
Packit 7cfc04
Other keywords that appear in safety notes are defined in subsequent sections.
Packit 7cfc04
.\"
Packit 7cfc04
.\"
Packit 7cfc04
.\" .SS Unsafe features
Packit 7cfc04
.\" Functions that are unsafe to call in certain contexts are annotated with
Packit 7cfc04
.\" keywords that document their features that make them unsafe to call.
Packit 7cfc04
.\" AS-Unsafe features in this section indicate the functions are never safe
Packit 7cfc04
.\" to call when asynchronous signals are enabled.
Packit 7cfc04
.\" AC-Unsafe features
Packit 7cfc04
.\" indicate they are never safe to call when asynchronous cancellation is
Packit 7cfc04
.\" .\" enabled.
Packit 7cfc04
.\" There are no MT-Unsafe marks in this section.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .\" .I code
Packit 7cfc04
.\" Functions marked with
Packit 7cfc04
.\" .I lock
Packit 7cfc04
.\" as an AS-Unsafe feature may be
Packit 7cfc04
.\" .\" interrupted by a signal while holding a non-recursive lock.
Packit 7cfc04
.\" If the signal handler calls another such function that takes the same lock,
Packit 7cfc04
.\" the result is a deadlock.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Functions annotated with
Packit 7cfc04
.\" .I lock
Packit 7cfc04
.\" as an AC-Unsafe feature may, if canceled asynchronously,
Packit 7cfc04
.\" fail to release a lock that would have been released if their execution
Packit 7cfc04
.\" had not been interrupted by asynchronous thread cancellation.
Packit 7cfc04
.\" Once a lock is left taken,
Packit 7cfc04
.\" attempts to take that lock will block indefinitely.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I corrupt
Packit 7cfc04
.\" Functions marked with
Packit 7cfc04
.\" .\" .I corrupt
Packit 7cfc04
.\" as an AS-Unsafe feature may corrupt
Packit 7cfc04
.\" data structures and misbehave when they interrupt,
Packit 7cfc04
.\" or are interrupted by, another such function.
Packit 7cfc04
.\" Unlike functions marked with
Packit 7cfc04
.\" .IR lock ,
Packit 7cfc04
.\" these take recursive locks to avoid MT-Safety problems,
Packit 7cfc04
.\" but this is not enough to stop a signal handler from observing
Packit 7cfc04
.\" a partially-updated data structure.
Packit 7cfc04
.\" Further corruption may arise from the interrupted function's
Packit 7cfc04
.\" failure to notice updates made by signal handlers.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Functions marked with
Packit 7cfc04
.\" .I corrupt
Packit 7cfc04
.\" as an AC-Unsafe feature may leave
Packit 7cfc04
.\" data structures in a corrupt, partially updated state.
Packit 7cfc04
.\" Subsequent uses of the data structure may misbehave.
Packit 7cfc04
.\"
Packit 7cfc04
.\" .\" A special case, probably not worth documenting separately, involves
Packit 7cfc04
.\" .\" reallocing, or even freeing pointers.  Any case involving free could
Packit 7cfc04
.\" .\" be easily turned into an ac-safe leak by resetting the pointer before
Packit 7cfc04
.\" .\" releasing it; I don't think we have any case that calls for this sort
Packit 7cfc04
.\" .\" of fixing.  Fixing the realloc cases would require a new interface:
Packit 7cfc04
.\" .\" instead of @code{ptr=realloc(ptr,size)} we'd have to introduce
Packit 7cfc04
.\" .\" @code{acsafe_realloc(&ptr,size)} that would modify ptr before
Packit 7cfc04
.\" .\" releasing the old memory.  The ac-unsafe realloc could be implemented
Packit 7cfc04
.\" .\" in terms of an internal interface with this semantics (say
Packit 7cfc04
.\" .\" __acsafe_realloc), but since realloc can be overridden, the function
Packit 7cfc04
.\" .\" we call to implement realloc should not be this internal interface,
Packit 7cfc04
.\" .\" but another internal interface that calls __acsafe_realloc if realloc
Packit 7cfc04
.\" .\" was not overridden, and calls the overridden realloc with async
Packit 7cfc04
.\" .\" cancel disabled.  --lxoliva
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I heap
Packit 7cfc04
.\" Functions marked with
Packit 7cfc04
.\" .I heap
Packit 7cfc04
.\" may call heap memory management functions from the
Packit 7cfc04
.\" .BR malloc (3)/ free (3)
Packit 7cfc04
.\" family of functions and are only as safe as those functions.
Packit 7cfc04
.\" This note is thus equivalent to:
Packit 7cfc04
.\"
Packit 7cfc04
.\"     | AS-Unsafe lock | AC-Unsafe lock fd mem |
Packit 7cfc04
.\" .\" @sampsafety{@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{} @acsmem{}}}
Packit 7cfc04
.\" .\"
Packit 7cfc04
.\" .\" Check for cases that should have used plugin instead of or in
Packit 7cfc04
.\" .\" addition to this.  Then, after rechecking gettext, adjust i18n if
Packit 7cfc04
.\" .\" needed.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I dlopen
Packit 7cfc04
.\" Functions marked with
Packit 7cfc04
.\" .I dlopen
Packit 7cfc04
.\" use the dynamic loader to load
Packit 7cfc04
.\" shared libraries into the current execution image.
Packit 7cfc04
.\" This involves opening files, mapping them into memory,
Packit 7cfc04
.\" allocating additional memory, resolving symbols,
Packit 7cfc04
.\" applying relocations and more,
Packit 7cfc04
.\" all of this while holding internal dynamic loader locks.
Packit 7cfc04
.\"
Packit 7cfc04
.\" The locks are enough for these functions to be AS-Unsafe and AC-Unsafe,
Packit 7cfc04
.\" but other issues may arise.
Packit 7cfc04
.\" At present this is a placeholder for all
Packit 7cfc04
.\" potential safety issues raised by
Packit 7cfc04
.\" .BR dlopen (3).
Packit 7cfc04
.\"
Packit 7cfc04
.\" .\" dlopen runs init and fini sections of the module; does this mean
Packit 7cfc04
.\" .\" dlopen always implies plugin?
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I plugin
Packit 7cfc04
.\" Functions annotated with
Packit 7cfc04
.\" .I plugin
Packit 7cfc04
.\" may run code from plugins that
Packit 7cfc04
.\" may be external to the GNU C Library.
Packit 7cfc04
.\" Such plugin functions are assumed to be
Packit 7cfc04
.\" MT-Safe, AS-Unsafe and AC-Unsafe.
Packit 7cfc04
.\" Examples of such plugins are stack unwinding libraries,
Packit 7cfc04
.\" name service switch (NSS) and character set conversion (iconv) back-ends.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Although the plugins mentioned as examples are all brought in by means
Packit 7cfc04
.\" of dlopen, the
Packit 7cfc04
.\" .I plugin
Packit 7cfc04
.\" keyword does not imply any direct
Packit 7cfc04
.\" involvement of the dynamic loader or the
Packit 7cfc04
.\" .I libdl
Packit 7cfc04
.\" interfaces,
Packit 7cfc04
.\" those are covered by
Packit 7cfc04
.\" .IR dlopen .
Packit 7cfc04
.\" For example, if one function loads a module and finds the addresses
Packit 7cfc04
.\" of some of its functions,
Packit 7cfc04
.\" while another just calls those already-resolved functions,
Packit 7cfc04
.\" the former will be marked with
Packit 7cfc04
.\" .IR dlopen ,
Packit 7cfc04
.\" whereas the latter will get the
Packit 7cfc04
.\" .IR plugin .
Packit 7cfc04
.\" When a single function takes all of these actions, then it gets both marks.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I i18n
Packit 7cfc04
.\" Functions marked with
Packit 7cfc04
.\" .I i18n
Packit 7cfc04
.\" may call internationalization
Packit 7cfc04
.\" functions of the
Packit 7cfc04
.\" .BR gettext (3)
Packit 7cfc04
.\" family and will be only as safe as those
Packit 7cfc04
.\" functions.
Packit 7cfc04
.\" This note is thus equivalent to:
Packit 7cfc04
.\"
Packit 7cfc04
.\"     | MT-Safe env | AS-Unsafe corrupt heap dlopen | AC-Unsafe corrupt |
Packit 7cfc04
.\"
Packit 7cfc04
.\" .\" @sampsafety{@mtsafe{@mtsenv{}}@asunsafe{@asucorrupt{} @ascuheap{} @ascudlopen{}}@acunsafe{@acucorrupt{}}}
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I timer
Packit 7cfc04
.\" Functions marked with
Packit 7cfc04
.\" .I timer
Packit 7cfc04
.\" use the
Packit 7cfc04
.\" .BR alarm (3)
Packit 7cfc04
.\" function or
Packit 7cfc04
.\" similar to set a time-out for a system call or a long-running operation.
Packit 7cfc04
.\" In a multi-threaded program, there is a risk that the time-out signal
Packit 7cfc04
.\" will be delivered to a different thread,
Packit 7cfc04
.\" thus failing to interrupt the intended thread.
Packit 7cfc04
.\" Besides being MT-Unsafe, such functions are always
Packit 7cfc04
.\" AS-Unsafe, because calling them in signal handlers may interfere with
Packit 7cfc04
.\" timers set in the interrupted code, and AC-Unsafe,
Packit 7cfc04
.\" because there is no safe way to guarantee an earlier timer
Packit 7cfc04
.\" will be reset in case of asynchronous cancellation.
Packit 7cfc04
.\"
Packit 7cfc04
.\"
Packit 7cfc04
.SS Conditionally safe features
Packit 7cfc04
For some features that make functions unsafe to call in certain contexts,
Packit 7cfc04
there are known ways to avoid the safety problem other than
Packit 7cfc04
refraining from calling the function altogether.
Packit 7cfc04
The keywords that follow refer to such features,
Packit 7cfc04
and each of their definitions indicates
Packit 7cfc04
how the whole program needs to be constrained in order to remove the
Packit 7cfc04
safety problem indicated by the keyword.
Packit 7cfc04
Only when all the reasons that
Packit 7cfc04
make a function unsafe are observed and addressed,
Packit 7cfc04
by applying the documented constraints,
Packit 7cfc04
does the function become safe to call in a context.
Packit 7cfc04
.TP
Packit 7cfc04
.I init
Packit 7cfc04
Functions marked with
Packit 7cfc04
.I init
Packit 7cfc04
as an MT-Unsafe feature perform
Packit 7cfc04
MT-Unsafe initialization when they are first called.
Packit 7cfc04
.IP
Packit 7cfc04
Calling such a function at least once in single-threaded mode removes
Packit 7cfc04
this specific cause for the function to be regarded as MT-Unsafe.
Packit 7cfc04
If no other cause for that remains,
Packit 7cfc04
the function can then be safely called after other threads are started.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Functions marked with
Packit 7cfc04
.\" .I init
Packit 7cfc04
.\" as an AS-Unsafe or AC-Unsafe feature use the GNU C Library internal
Packit 7cfc04
.\" .I libc_once
Packit 7cfc04
.\" machinery or similar to initialize internal data structures.
Packit 7cfc04
.\"
Packit 7cfc04
.\" If a signal handler interrupts such an initializer,
Packit 7cfc04
.\" and calls any function that also performs
Packit 7cfc04
.\" .I libc_once
Packit 7cfc04
.\" initialization, it will deadlock if the thread library has been loaded.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Furthermore, if an initializer is partially complete before it is canceled
Packit 7cfc04
.\" or interrupted by a signal whose handler requires the same initialization,
Packit 7cfc04
.\" some or all of the initialization may be performed more than once,
Packit 7cfc04
.\" leaking resources or even resulting in corrupt internal data.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Applications that need to call functions marked with
Packit 7cfc04
.\" .I init
Packit 7cfc04
.\" as an AS-Safety or AC-Unsafe feature should ensure
Packit 7cfc04
.\" the initialization is performed
Packit 7cfc04
.\" before configuring signal handlers or enabling cancellation,
Packit 7cfc04
.\" so that the AS-Safety and AC-Safety issues related with
Packit 7cfc04
.\" .I libc_once
Packit 7cfc04
.\" do not arise.
Packit 7cfc04
.\"
Packit 7cfc04
.\" .\" We may have to extend the annotations to cover conditions in which
Packit 7cfc04
.\" .\" initialization may or may not occur, since an initial call in a safe
Packit 7cfc04
.\" .\" context is no use if the initialization doesn't take place at that
Packit 7cfc04
.\" .\" time: it doesn't remove the risk for later calls.
Packit 7cfc04
.TP
Packit 7cfc04
.I race
Packit 7cfc04
Functions annotated with
Packit 7cfc04
.I race
Packit 7cfc04
as an MT-Safety issue operate on
Packit 7cfc04
objects in ways that may cause data races or similar forms of
Packit 7cfc04
destructive interference out of concurrent execution.
Packit 7cfc04
In some cases,
Packit 7cfc04
the objects are passed to the functions by users;
Packit 7cfc04
in others, they are used by the functions to return values to users;
Packit 7cfc04
in others, they are not even exposed to users.
Packit 7cfc04
.\"
Packit 7cfc04
.\" We consider access to objects passed as (indirect) arguments to
Packit 7cfc04
.\" functions to be data race free.
Packit 7cfc04
.\" The assurance of data race free objects
Packit 7cfc04
.\" is the caller's responsibility.
Packit 7cfc04
.\" We will not mark a function as MT-Unsafe or AS-Unsafe
Packit 7cfc04
.\" if it misbehaves when users fail to take the measures required by
Packit 7cfc04
.\" POSIX to avoid data races when dealing with such objects.
Packit 7cfc04
.\" As a general rule, if a function is documented as reading from
Packit 7cfc04
.\" an object passed (by reference) to it, or modifying it,
Packit 7cfc04
.\" users ought to use memory synchronization primitives
Packit 7cfc04
.\" to avoid data races just as they would should they perform
Packit 7cfc04
.\" the accesses themselves rather than by calling the library function.
Packit 7cfc04
.\" Standard I/O
Packit 7cfc04
.\" .RI ( "FILE *" )
Packit 7cfc04
.\" streams are the exception to the general rule,
Packit 7cfc04
.\" in that POSIX mandates the library to guard against data races
Packit 7cfc04
.\" in many functions that manipulate objects of this specific opaque type.
Packit 7cfc04
.\" We regard this as a convenience provided to users,
Packit 7cfc04
.\" rather than as a general requirement whose expectations
Packit 7cfc04
.\" should extend to other types.
Packit 7cfc04
.\"
Packit 7cfc04
.\" In order to remind users that guarding certain arguments is their
Packit 7cfc04
.\" responsibility, we will annotate functions that take objects of certain
Packit 7cfc04
.\" types as arguments.
Packit 7cfc04
.\" We draw the line for objects passed by users as follows:
Packit 7cfc04
.\" objects whose types are exposed to users,
Packit 7cfc04
.\" and that users are expected to access directly,
Packit 7cfc04
.\" such as memory buffers, strings,
Packit 7cfc04
.\" and various user-visible structured types, do
Packit 7cfc04
.\" .I not
Packit 7cfc04
.\" give reason for functions to be annotated with
Packit 7cfc04
.\" .IR race .
Packit 7cfc04
.\" It would be noisy and redundant with the general requirement,
Packit 7cfc04
.\" and not many would be surprised by the library's lack of internal
Packit 7cfc04
.\" guards when accessing objects that can be accessed directly by users.
Packit 7cfc04
.\"
Packit 7cfc04
.\" As for objects that are opaque or opaque-like,
Packit 7cfc04
.\" in that they are to be manipulated only by passing them
Packit 7cfc04
.\" to library functions (e.g.,
Packit 7cfc04
.\" .IR FILE ,
Packit 7cfc04
.\" .IR DIR ,
Packit 7cfc04
.\" .IR obstack ,
Packit 7cfc04
.\" .IR iconv_t ),
Packit 7cfc04
.\" there might be additional expectations as to internal coordination
Packit 7cfc04
.\" of access by the library.
Packit 7cfc04
.\" We will annotate, with
Packit 7cfc04
.\" .I race
Packit 7cfc04
.\" followed by a colon and the argument name,
Packit 7cfc04
.\" functions that take such objects but that do not take
Packit 7cfc04
.\" care of synchronizing access to them by default.
Packit 7cfc04
.\" For example,
Packit 7cfc04
.\" .I FILE
Packit 7cfc04
.\" stream
Packit 7cfc04
.\" .I unlocked
Packit 7cfc04
.\" functions
Packit 7cfc04
.\" .RB ( unlocked_stdio (3))
Packit 7cfc04
.\" will be annotated,
Packit 7cfc04
.\" but those that perform implicit locking on
Packit 7cfc04
.\" .I FILE
Packit 7cfc04
.\" streams by default will not,
Packit 7cfc04
.\" even though the implicit locking may be disabled on a per-stream basis.
Packit 7cfc04
.\"
Packit 7cfc04
.\" In either case, we will not regard as MT-Unsafe functions that may
Packit 7cfc04
.\" access user-supplied objects in unsafe ways should users fail to ensure
Packit 7cfc04
.\" the accesses are well defined.
Packit 7cfc04
.\" The notion prevails that users are expected to safeguard against
Packit 7cfc04
.\" data races any user-supplied objects that the library accesses
Packit 7cfc04
.\" on their behalf.
Packit 7cfc04
.\"
Packit 7cfc04
.\" .\" The above describes @mtsrace; @mtasurace is described below.
Packit 7cfc04
.\"
Packit 7cfc04
.\" This user responsibility does not apply, however,
Packit 7cfc04
.\" to objects controlled by the library itself,
Packit 7cfc04
.\" such as internal objects and static buffers used
Packit 7cfc04
.\" to return values from certain calls.
Packit 7cfc04
.\" When the library doesn't guard them against concurrent uses,
Packit 7cfc04
.\" these cases are regarded as MT-Unsafe and AS-Unsafe (although the
Packit 7cfc04
.\" .I race
Packit 7cfc04
.\" mark under AS-Unsafe will be omitted
Packit 7cfc04
.\" as redundant with the one under MT-Unsafe).
Packit 7cfc04
.\" As in the case of user-exposed objects,
Packit 7cfc04
.\" the mark may be followed by a colon and an identifier.
Packit 7cfc04
.\" The identifier groups all functions that operate on a
Packit 7cfc04
.\" certain unguarded object; users may avoid the MT-Safety issues related
Packit 7cfc04
.\" with unguarded concurrent access to such internal objects by creating a
Packit 7cfc04
.\" non-recursive mutex related with the identifier,
Packit 7cfc04
.\" and always holding the mutex when calling any function marked
Packit 7cfc04
.\" as racy on that identifier,
Packit 7cfc04
.\" as they would have to should the identifier be
Packit 7cfc04
.\" an object under user control.
Packit 7cfc04
.\" The non-recursive mutex avoids the MT-Safety issue,
Packit 7cfc04
.\" but it trades one AS-Safety issue for another,
Packit 7cfc04
.\" so use in asynchronous signals remains undefined.
Packit 7cfc04
.\"
Packit 7cfc04
.\" When the identifier relates to a static buffer used to hold return values,
Packit 7cfc04
.\" the mutex must be held for as long as the buffer remains in use
Packit 7cfc04
.\" by the caller.
Packit 7cfc04
.\" Many functions that return pointers to static buffers offer reentrant
Packit 7cfc04
.\" variants that store return values in caller-supplied buffers instead.
Packit 7cfc04
.\" In some cases, such as
Packit 7cfc04
.\" .BR tmpname (3),
Packit 7cfc04
.\" the variant is chosen not by calling an alternate entry point,
Packit 7cfc04
.\" but by passing a non-NULL pointer to the buffer in which the
Packit 7cfc04
.\" returned values are to be stored.
Packit 7cfc04
.\" These variants are generally preferable in multi-threaded programs,
Packit 7cfc04
.\" although some of them are not MT-Safe because of other internal buffers,
Packit 7cfc04
.\" also documented with
Packit 7cfc04
.\" .I race
Packit 7cfc04
.\" notes.
Packit 7cfc04
.TP
Packit 7cfc04
.I const
Packit 7cfc04
Functions marked with
Packit 7cfc04
.I const
Packit 7cfc04
as an MT-Safety issue non-atomically
Packit 7cfc04
modify internal objects that are better regarded as constant,
Packit 7cfc04
because a substantial portion of the GNU C Library accesses them without
Packit 7cfc04
synchronization.
Packit 7cfc04
Unlike
Packit 7cfc04
.IR race ,
Packit 7cfc04
which causes both readers and
Packit 7cfc04
writers of internal objects to be regarded as MT-Unsafe, \" and AS-Unsafe,
Packit 7cfc04
this mark is applied to writers only.
Packit 7cfc04
Writers remain \" equally
Packit 7cfc04
MT-Unsafe \" and AS-Unsafe
Packit 7cfc04
to call,
Packit 7cfc04
but the then-mandatory constness of objects they
Packit 7cfc04
modify enables readers to be regarded as MT-Safe \" and AS-Safe
Packit 7cfc04
(as long as no other reasons for them to be unsafe remain),
Packit 7cfc04
since the lack of synchronization is not a problem when the
Packit 7cfc04
objects are effectively constant.
Packit 7cfc04
.IP
Packit 7cfc04
The identifier that follows the
Packit 7cfc04
.I const
Packit 7cfc04
mark will appear by itself as a safety note in readers.
Packit 7cfc04
Programs that wish to work around this safety issue,
Packit 7cfc04
so as to call writers, may use a non-recursive
Packit 7cfc04
read-write lock
Packit 7cfc04
associated with the identifier, and guard
Packit 7cfc04
.I all
Packit 7cfc04
calls to functions marked with
Packit 7cfc04
.I const
Packit 7cfc04
followed by the identifier with a write lock, and
Packit 7cfc04
.I all
Packit 7cfc04
calls to functions marked with the identifier
Packit 7cfc04
by itself with a read lock.
Packit 7cfc04
.\" The non-recursive locking removes the MT-Safety problem,
Packit 7cfc04
.\" but it trades one AS-Safety problem for another,
Packit 7cfc04
.\" so use in asynchronous signals remains undefined.
Packit 7cfc04
.\"
Packit 7cfc04
.\" .\" But what if, instead of marking modifiers with const:id and readers
Packit 7cfc04
.\" .\" with just id, we marked writers with race:id and readers with ro:id?
Packit 7cfc04
.\" .\" Instead of having to define each instance of 'id', we'd have a
Packit 7cfc04
.\" .\" general pattern governing all such 'id's, wherein race:id would
Packit 7cfc04
.\" .\" suggest the need for an exclusive/write lock to make the function
Packit 7cfc04
.\" .\" safe, whereas ro:id would indicate 'id' is expected to be read-only,
Packit 7cfc04
.\" .\" but if any modifiers are called (while holding an exclusive lock),
Packit 7cfc04
.\" .\" then ro:id-marked functions ought to be guarded with a read lock for
Packit 7cfc04
.\" .\" safe operation.  ro:env or ro:locale, for example, seems to convey
Packit 7cfc04
.\" .\" more clearly the expectations and the meaning, than just env or
Packit 7cfc04
.\" .\" locale.
Packit 7cfc04
.TP
Packit 7cfc04
.I sig
Packit 7cfc04
Functions marked with
Packit 7cfc04
.I sig
Packit 7cfc04
as a MT-Safety issue
Packit 7cfc04
.\" (that implies an identical AS-Safety issue, omitted for brevity)
Packit 7cfc04
may temporarily install a signal handler for internal purposes,
Packit 7cfc04
which may interfere with other uses of the signal,
Packit 7cfc04
identified after a colon.
Packit 7cfc04
.IP
Packit 7cfc04
This safety problem can be worked around by ensuring that no other uses
Packit 7cfc04
of the signal will take place for the duration of the call.
Packit 7cfc04
Holding a non-recursive mutex while calling all functions that use the same
Packit 7cfc04
temporary signal;
Packit 7cfc04
blocking that signal before the call and resetting its
Packit 7cfc04
handler afterwards is recommended.
Packit 7cfc04
.\"
Packit 7cfc04
.\" There is no safe way to guarantee the original signal handler is
Packit 7cfc04
.\" restored in case of asynchronous cancellation,
Packit 7cfc04
.\" therefore so-marked functions are also AC-Unsafe.
Packit 7cfc04
.\"
Packit 7cfc04
.\" .\" fixme: at least deferred cancellation should get it right, and would
Packit 7cfc04
.\" .\" obviate the restoring bit below, and the qualifier above.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Besides the measures recommended to work around the
Packit 7cfc04
.\" MT-Safety and AS-Safety problem,
Packit 7cfc04
.\" in order to avert the cancellation problem,
Packit 7cfc04
.\" disabling asynchronous cancellation
Packit 7cfc04
.\" .I and
Packit 7cfc04
.\" installing a cleanup handler to restore the signal to the desired state
Packit 7cfc04
.\" and to release the mutex are recommended.
Packit 7cfc04
.TP
Packit 7cfc04
.I term
Packit 7cfc04
Functions marked with
Packit 7cfc04
.I term
Packit 7cfc04
as an MT-Safety issue may change the
Packit 7cfc04
terminal settings in the recommended way, namely: call
Packit 7cfc04
.BR tcgetattr (3),
Packit 7cfc04
modify some flags, and then call
Packit 7cfc04
.BR tcsetattr (3),
Packit 7cfc04
this creates a window in which changes made by other threads are lost.
Packit 7cfc04
Thus, functions marked with
Packit 7cfc04
.I term
Packit 7cfc04
are MT-Unsafe.
Packit 7cfc04
.\" The same window enables changes made by asynchronous signals to be lost.
Packit 7cfc04
.\" These functions are also AS-Unsafe,
Packit 7cfc04
.\" but the corresponding mark is omitted as redundant.
Packit 7cfc04
.IP
Packit 7cfc04
It is thus advisable for applications using the terminal to avoid
Packit 7cfc04
concurrent and reentrant interactions with it,
Packit 7cfc04
by not using it in signal handlers or blocking signals that might use it,
Packit 7cfc04
and holding a lock while calling these functions and interacting
Packit 7cfc04
with the terminal.
Packit 7cfc04
This lock should also be used for mutual exclusion with
Packit 7cfc04
functions marked with
Packit 7cfc04
.IR race:tcattr(fd) ,
Packit 7cfc04
where
Packit 7cfc04
.I fd
Packit 7cfc04
is a file descriptor for the controlling terminal.
Packit 7cfc04
The caller may use a single mutex for simplicity,
Packit 7cfc04
or use one mutex per terminal,
Packit 7cfc04
even if referenced by different file descriptors.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Functions marked with
Packit 7cfc04
.\" .I term
Packit 7cfc04
.\" as an AC-Safety issue are supposed to
Packit 7cfc04
.\" restore terminal settings to their original state,
Packit 7cfc04
.\" after temporarily changing them, but they may fail to do so if canceled.
Packit 7cfc04
.\"
Packit 7cfc04
.\" .\" fixme: at least deferred cancellation should get it right, and would
Packit 7cfc04
.\" .\" obviate the restoring bit below, and the qualifier above.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Besides the measures recommended to work around the
Packit 7cfc04
.\" MT-Safety and AS-Safety problem,
Packit 7cfc04
.\" in order to avert the cancellation problem,
Packit 7cfc04
.\" disabling asynchronous cancellation
Packit 7cfc04
.\" .I and
Packit 7cfc04
.\" installing a cleanup handler to
Packit 7cfc04
.\" restore the terminal settings to the original state and to release the
Packit 7cfc04
.\" mutex are recommended.
Packit 7cfc04
.\"
Packit 7cfc04
.\"
Packit 7cfc04
.SS Other safety remarks
Packit 7cfc04
Additional keywords may be attached to functions,
Packit 7cfc04
indicating features that do not make a function unsafe to call,
Packit 7cfc04
but that may need to be taken into account in certain classes of programs:
Packit 7cfc04
.TP
Packit 7cfc04
.I locale
Packit 7cfc04
Functions annotated with
Packit 7cfc04
.I locale
Packit 7cfc04
as an MT-Safety issue read from
Packit 7cfc04
the locale object without any form of synchronization.
Packit 7cfc04
Functions
Packit 7cfc04
annotated with
Packit 7cfc04
.I locale
Packit 7cfc04
called concurrently with locale changes may
Packit 7cfc04
behave in ways that do not correspond to any of the locales active
Packit 7cfc04
during their execution, but an unpredictable mix thereof.
Packit 7cfc04
.IP
Packit 7cfc04
We do not mark these functions as MT-Unsafe, \" or AS-Unsafe,
Packit 7cfc04
however,
Packit 7cfc04
because functions that modify the locale object are marked with
Packit 7cfc04
.I const:locale
Packit 7cfc04
and regarded as unsafe.
Packit 7cfc04
Being unsafe, the latter are not to be called when multiple threads
Packit 7cfc04
are running or asynchronous signals are enabled,
Packit 7cfc04
and so the locale can be considered effectively constant
Packit 7cfc04
in these contexts,
Packit 7cfc04
which makes the former safe.
Packit 7cfc04
.\" Should the locking strategy suggested under @code{const} be used,
Packit 7cfc04
.\" failure to guard locale uses is not as fatal as data races in
Packit 7cfc04
.\" general: unguarded uses will @emph{not} follow dangling pointers or
Packit 7cfc04
.\" access uninitialized, unmapped or recycled memory.  Each access will
Packit 7cfc04
.\" read from a consistent locale object that is or was active at some
Packit 7cfc04
.\" point during its execution.  Without synchronization, however, it
Packit 7cfc04
.\" cannot even be assumed that, after a change in locale, earlier
Packit 7cfc04
.\" locales will no longer be used, even after the newly-chosen one is
Packit 7cfc04
.\" used in the thread.  Nevertheless, even though unguarded reads from
Packit 7cfc04
.\" the locale will not violate type safety, functions that access the
Packit 7cfc04
.\" locale multiple times may invoke all sorts of undefined behavior
Packit 7cfc04
.\" because of the unexpected locale changes.
Packit 7cfc04
.TP
Packit 7cfc04
.I env
Packit 7cfc04
Functions marked with
Packit 7cfc04
.I env
Packit 7cfc04
as an MT-Safety issue access the
Packit 7cfc04
environment with
Packit 7cfc04
.BR getenv (3)
Packit 7cfc04
or similar, without any guards to ensure
Packit 7cfc04
safety in the presence of concurrent modifications.
Packit 7cfc04
.IP
Packit 7cfc04
We do not mark these functions as MT-Unsafe, \" or AS-Unsafe,
Packit 7cfc04
however,
Packit 7cfc04
because functions that modify the environment are all marked with
Packit 7cfc04
.I const:env
Packit 7cfc04
and regarded as unsafe.
Packit 7cfc04
Being unsafe, the latter are not to be called when multiple threads
Packit 7cfc04
are running or asynchronous signals are enabled,
Packit 7cfc04
and so the environment can be considered
Packit 7cfc04
effectively constant in these contexts,
Packit 7cfc04
which makes the former safe.
Packit 7cfc04
.TP
Packit 7cfc04
.I hostid
Packit 7cfc04
The function marked with
Packit 7cfc04
.I hostid
Packit 7cfc04
as an MT-Safety issue reads from the system-wide data structures that
Packit 7cfc04
hold the "host ID" of the machine.
Packit 7cfc04
These data structures cannot generally be modified atomically.
Packit 7cfc04
Since it is expected that the "host ID" will not normally change,
Packit 7cfc04
the function that reads from it
Packit 7cfc04
.RB ( gethostid (3))
Packit 7cfc04
is regarded as safe,
Packit 7cfc04
whereas the function that modifies it
Packit 7cfc04
.RB ( sethostid (3))
Packit 7cfc04
is marked with
Packit 7cfc04
.IR const:hostid ,
Packit 7cfc04
indicating it may require special care if it is to be called.
Packit 7cfc04
In this specific case,
Packit 7cfc04
the special care amounts to system-wide
Packit 7cfc04
(not merely intra-process) coordination.
Packit 7cfc04
.TP
Packit 7cfc04
.I sigintr
Packit 7cfc04
Functions marked with
Packit 7cfc04
.I sigintr
Packit 7cfc04
as an MT-Safety issue access the
Packit 7cfc04
GNU C Library
Packit 7cfc04
.I _sigintr
Packit 7cfc04
internal data structure without any guards to ensure
Packit 7cfc04
safety in the presence of concurrent modifications.
Packit 7cfc04
.IP
Packit 7cfc04
We do not mark these functions as MT-Unsafe, \" or AS-Unsafe,
Packit 7cfc04
however,
Packit 7cfc04
because functions that modify this data structure are all marked with
Packit 7cfc04
.I const:sigintr
Packit 7cfc04
and regarded as unsafe.
Packit 7cfc04
Being unsafe,
Packit 7cfc04
the latter are not to be called when multiple threads are
Packit 7cfc04
running or asynchronous signals are enabled,
Packit 7cfc04
and so the data structure can be considered
Packit 7cfc04
effectively constant in these contexts,
Packit 7cfc04
which makes the former safe.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I fd
Packit 7cfc04
.\" Functions annotated with
Packit 7cfc04
.\" .I fd
Packit 7cfc04
.\" as an AC-Safety issue may leak file
Packit 7cfc04
.\" descriptors if asynchronous thread cancellation interrupts their
Packit 7cfc04
.\" execution.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Functions that allocate or deallocate file descriptors will generally be
Packit 7cfc04
.\" marked as such.
Packit 7cfc04
.\" Even if they attempted to protect the file descriptor
Packit 7cfc04
.\" allocation and deallocation with cleanup regions,
Packit 7cfc04
.\" allocating a new descriptor and storing its number where the cleanup region
Packit 7cfc04
.\" could release it cannot be performed as a single atomic operation.
Packit 7cfc04
.\" Similarly,
Packit 7cfc04
.\" releasing the descriptor and taking it out of the data structure
Packit 7cfc04
.\" normally responsible for releasing it cannot be performed atomically.
Packit 7cfc04
.\" There will always be a window in which the descriptor cannot be released
Packit 7cfc04
.\" because it was not stored in the cleanup handler argument yet,
Packit 7cfc04
.\" or it was already taken out before releasing it.
Packit 7cfc04
.\" .\" It cannot be taken out after release:
Packit 7cfc04
.\" an open descriptor could mean either that the descriptor still
Packit 7cfc04
.\" has to be closed,
Packit 7cfc04
.\" or that it already did so but the descriptor was
Packit 7cfc04
.\" reallocated by another thread or signal handler.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Such leaks could be internally avoided, with some performance penalty,
Packit 7cfc04
.\" by temporarily disabling asynchronous thread cancellation.
Packit 7cfc04
.\" However,
Packit 7cfc04
.\" since callers of allocation or deallocation functions would have to do
Packit 7cfc04
.\" this themselves, to avoid the same sort of leak in their own layer,
Packit 7cfc04
.\" it makes more sense for the library to assume they are taking care of it
Packit 7cfc04
.\" than to impose a performance penalty that is redundant when the problem
Packit 7cfc04
.\" is solved in upper layers, and insufficient when it is not.
Packit 7cfc04
.\"
Packit 7cfc04
.\" This remark by itself does not cause a function to be regarded as
Packit 7cfc04
.\" AC-Unsafe.
Packit 7cfc04
.\" However, cumulative effects of such leaks may pose a
Packit 7cfc04
.\" problem for some programs.
Packit 7cfc04
.\" If this is the case,
Packit 7cfc04
.\" suspending asynchronous cancellation for the duration of calls
Packit 7cfc04
.\" to such functions is recommended.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I mem
Packit 7cfc04
.\" Functions annotated with
Packit 7cfc04
.\" .I mem
Packit 7cfc04
.\" as an AC-Safety issue may leak
Packit 7cfc04
.\" memory if asynchronous thread cancellation interrupts their execution.
Packit 7cfc04
.\"
Packit 7cfc04
.\" The problem is similar to that of file descriptors: there is no atomic
Packit 7cfc04
.\" interface to allocate memory and store its address in the argument to a
Packit 7cfc04
.\" cleanup handler,
Packit 7cfc04
.\" or to release it and remove its address from that argument,
Packit 7cfc04
.\" without at least temporarily disabling asynchronous cancellation,
Packit 7cfc04
.\" which these functions do not do.
Packit 7cfc04
.\"
Packit 7cfc04
.\" This remark does not by itself cause a function to be regarded as
Packit 7cfc04
.\" generally AC-Unsafe.
Packit 7cfc04
.\" However, cumulative effects of such leaks may be
Packit 7cfc04
.\" severe enough for some programs that disabling asynchronous cancellation
Packit 7cfc04
.\" for the duration of calls to such functions may be required.
Packit 7cfc04
.TP
Packit 7cfc04
.I cwd
Packit 7cfc04
Functions marked with
Packit 7cfc04
.I cwd
Packit 7cfc04
as an MT-Safety issue may temporarily
Packit 7cfc04
change the current working directory during their execution,
Packit 7cfc04
which may cause relative pathnames to be resolved in unexpected ways in
Packit 7cfc04
other threads or within asynchronous signal or cancellation handlers.
Packit 7cfc04
.IP
Packit 7cfc04
This is not enough of a reason to mark so-marked functions as MT-Unsafe,
Packit 7cfc04
.\" or AS-Unsafe,
Packit 7cfc04
but when this behavior is optional (e.g.,
Packit 7cfc04
.BR nftw (3)
Packit 7cfc04
with
Packit 7cfc04
.BR FTW_CHDIR ),
Packit 7cfc04
avoiding the option may be a good alternative to
Packit 7cfc04
using full pathnames or file descriptor-relative (e.g.,
Packit 7cfc04
.BR openat (2))
Packit 7cfc04
system calls.
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .I !posix
Packit 7cfc04
.\" This remark, as an MT-Safety, AS-Safety or AC-Safety
Packit 7cfc04
.\" note to a function,
Packit 7cfc04
.\" indicates the safety status of the function is known to differ
Packit 7cfc04
.\" from the specified status in the POSIX standard.
Packit 7cfc04
.\" For example, POSIX does not require a function to be Safe,
Packit 7cfc04
.\" but our implementation is, or vice-versa.
Packit 7cfc04
.\"
Packit 7cfc04
.\" For the time being, the absence of this remark does not imply the safety
Packit 7cfc04
.\" properties we documented are identical to those mandated by POSIX for
Packit 7cfc04
.\" the corresponding functions.
Packit 7cfc04
.TP
Packit 7cfc04
.I :identifier
Packit 7cfc04
Annotations may sometimes be followed by identifiers,
Packit 7cfc04
intended to group several functions that, for example,
Packit 7cfc04
access the data structures in an unsafe way, as in
Packit 7cfc04
.I race
Packit 7cfc04
and
Packit 7cfc04
.IR const ,
Packit 7cfc04
or to provide more specific information,
Packit 7cfc04
such as naming a signal in a function marked with
Packit 7cfc04
.IR sig .
Packit 7cfc04
It is envisioned that it may be applied to
Packit 7cfc04
.I lock
Packit 7cfc04
and
Packit 7cfc04
.I corrupt
Packit 7cfc04
as well in the future.
Packit 7cfc04
.IP
Packit 7cfc04
In most cases, the identifier will name a set of functions,
Packit 7cfc04
but it may name global objects or function arguments,
Packit 7cfc04
or identifiable properties or logical components associated with them,
Packit 7cfc04
with a notation such as, for example,
Packit 7cfc04
.I :buf(arg)
Packit 7cfc04
to denote a buffer associated with the argument
Packit 7cfc04
.IR arg ,
Packit 7cfc04
or
Packit 7cfc04
.I :tcattr(fd)
Packit 7cfc04
to denote the terminal attributes of a file descriptor
Packit 7cfc04
.IR fd .
Packit 7cfc04
.IP
Packit 7cfc04
The most common use for identifiers is to provide logical groups of
Packit 7cfc04
functions and arguments that need to be protected by the same
Packit 7cfc04
synchronization primitive in order to ensure safe operation in a given
Packit 7cfc04
context.
Packit 7cfc04
.TP
Packit 7cfc04
.I /condition
Packit 7cfc04
Some safety annotations may be conditional,
Packit 7cfc04
in that they only apply if a boolean expression involving arguments,
Packit 7cfc04
global variables or even the underlying kernel evaluates to true.
Packit 7cfc04
.\" Such conditions as
Packit 7cfc04
.\" .I /hurd
Packit 7cfc04
.\" or
Packit 7cfc04
.\" .I /!linux!bsd
Packit 7cfc04
.\" indicate the preceding marker only
Packit 7cfc04
.\" applies when the underlying kernel is the HURD,
Packit 7cfc04
.\" or when it is neither Linux nor a BSD kernel, respectively.
Packit 7cfc04
For example,
Packit 7cfc04
.I /!ps
Packit 7cfc04
and
Packit 7cfc04
.I /one_per_line
Packit 7cfc04
indicate the preceding marker only applies when argument
Packit 7cfc04
.I ps
Packit 7cfc04
is NULL, or global variable
Packit 7cfc04
.I one_per_line
Packit 7cfc04
is nonzero.
Packit 7cfc04
.IP
Packit 7cfc04
When all marks that render a function unsafe are
Packit 7cfc04
adorned with such conditions,
Packit 7cfc04
and none of the named conditions hold,
Packit 7cfc04
then the function can be regarded as safe.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR pthreads (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.