]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/attributes.7
attributes.7: spfix [*]
[thirdparty/man-pages.git] / man7 / attributes.7
CommitLineData
d95411aa
MK
1.\" Copyright (c) 2014, Red Hat, Inc.
2.\"
3.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4.\" This is free documentation; you can redistribute it and/or
5.\" modify it under the terms of the GNU General Public License as
6.\" published by the Free Software Foundation; either version 2 of
7.\" the License, or (at your option) any later version.
8.\"
9.\" The GNU General Public License's references to "object code"
10.\" and "executables" are to be interpreted as the output of any
11.\" document formatting or typesetting system, including
12.\" intermediate and printed output.
13.\"
14.\" This manual is distributed in the hope that it will be useful,
15.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.\" GNU General Public License for more details.
18.\"
19.\" You should have received a copy of the GNU General Public
20.\" License along with this manual; if not, see
21.\" <http://www.gnu.org/licenses/>.
22.\" %%%LICENSE_END
23.TH ATTRIBUTES 7 2014-10-16 "Linux" "Linux Programmer's Manual"
24.SH NAME
25attributes \- POSIX safety concepts
26.SH DESCRIPTION
27.\"
28.\"
29.SS POSIX safety concepts
30This manual documents various safety properties of GNU C Library
31functions, in lines that follow their prototypes and look like:
32
33@sampsafety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
34
35The properties are assessed according to the criteria set forth in the
36POSIX standard for such safety contexts as
37Thread-Safety, Async-Signal-Safety and Async-Cancel-Safety.
38Intuitive definitions of these properties,
39attempting to capture the meaning of the standard definitions, follow.
40.TP
41.I MT-Safe
42.I MT-Safe
43or
44Thread-Safe functions are safe to call in the presence
45of other threads.
46MT, in MT-Safe, stands for Multi Thread.
47
48Being MT-Safe does not imply a function is atomic, nor that it uses any
49of the memory synchronization mechanisms POSIX exposes to users.
50It is even possible that calling MT-Safe functions in sequence does not yield
51an MT-Safe combination.
52For example, having a thread call two MT-Safe
53functions one right after the other does not guarantee behavior
54equivalent to atomic execution of a combination of both functions,
55since concurrent calls in other threads may interfere in a destructive way.
56
57Whole-program optimizations that could inline functions across library
58interfaces may expose unsafe reordering, and so performing inlining
59across the GNU C Library interface is not recommended.
60The documented
61MT-Safety status is not guaranteed under whole-program optimization.
62However, functions defined in user-visible headers are designed to be
63safe for inlining.
64.TP
65.I AS-Safe
66.I AS-Safe
67or Async-Signal-Safe functions are safe to call from
68asynchronous signal handlers.
69AS, in AS-Safe, stands for Asynchronous Signal.
70
71Many functions that are AS-Safe may set
72.IR errno ,
73or modify the floating-point environment,
74because their doing so does not make them
75unsuitable for use in signal handlers.
76However, programs could misbehave should asynchronous signal handlers
77modify this thread-local state,
78and the signal handling machinery cannot be counted on to
79preserve it.
80Therefore, signal handlers that call functions that may set
81.I errno
82or modify the floating-point environment
83.I must
84save their original values, and restore them before returning.
85.TP
86.I AC-Safe
87.I AC-Safe
88or Async-Cancel-Safe functions are safe to call when
89asynchronous cancellation is enabled.
90AC in AC-Safe stands for Asynchronous Cancellation.
91
92The POSIX standard defines only three functions to be AC-Safe, namely
93.BR pthread_cancel (3),
94.BR pthread_setcancelstate (3),
95and
96.BR pthread_setcanceltype (3).
97At present the GNU C Library provides no
98guarantees beyond these three functions,
99but does document which functions are presently AC-Safe.
100This documentation is provided for use
101by the GNU C Library developers.
102
103Just like signal handlers, cancellation cleanup routines must configure
104the floating point environment they require.
105The routines cannot assume a floating point environment,
106particularly when asynchronous cancellation is enabled.
107If the configuration of the floating point
108environment cannot be performed atomically then it is also possible that
109the environment encountered is internally inconsistent.
110.TP
111.IR MT-Unsafe ", " AS-Unsafe ", " AC-Unsafe
112.IR MT-Unsafe ", " AS-Unsafe ", " AC-Unsafe
113functions are not
114safe to call within the safety contexts described above.
115Calling them
116within such contexts invokes undefined behavior.
117
118Functions not explicitly documented as safe in a safety context should
119be regarded as Unsafe.
120.TP
121.I Preliminary
122.I Preliminary
123safety properties are documented, indicating these
124properties may
125.I not
126be counted on in future releases of
127the GNU C Library.
128
129Such preliminary properties are the result of an assessment of the
130properties of our current implementation,
131rather than of what is mandated and permitted by current and future standards.
132
133Although we strive to abide by the standards, in some cases our
134implementation is safe even when the standard does not demand safety,
135and in other cases our implementation does not meet the standard safety
136requirements.
137The latter are most likely bugs; the former, when marked
138as
139.IR Preliminary ,
140should not be counted on: future standards may
141require changes that are not compatible with the additional safety
142properties afforded by the current implementation.
143
144Furthermore,
145the POSIX standard does not offer a detailed definition of safety.
146We assume that, by "safe to call", POSIX means that,
147as long as the program does not invoke undefined behavior,
148the "safe to call" function behaves as specified,
149and does not cause other functions to deviate from their specified behavior.
150We have chosen to use its loose
151definitions of safety, not because they are the best definitions to use,
152but because choosing them harmonizes this manual with POSIX.
153
154Please keep in mind that these are preliminary definitions and annotations,
155and certain aspects of the definitions are still under
156discussion and might be subject to clarification or change.
157
158Over time,
159we envision evolving the preliminary safety notes into stable commitments,
160as stable as those of our interfaces.
161As we do, we will remove the
162.I Preliminary
163keyword from safety notes.
164As long as the keyword remains, however,
165they are not to be regarded as a promise of future behavior.
166.PP
167Other keywords that appear in safety notes are defined in subsequent sections.
168.\"
169.\"
170.SS Unsafe features
171Functions that are unsafe to call in certain contexts are annotated with
172keywords that document their features that make them unsafe to call.
173AS-Unsafe features in this section indicate the functions are never safe
174to call when asynchronous signals are enabled.
175AC-Unsafe features
176indicate they are never safe to call when asynchronous cancellation is
177enabled.
178There are no MT-Unsafe marks in this section.
179.TP
180.I code
181Functions marked with
182.I lock
183as an AS-Unsafe feature may be
184interrupted by a signal while holding a non-recursive lock.
185If the signal handler calls another such function that takes the same lock,
186the result is a deadlock.
187
188Functions annotated with
189.I lock
a6f8ea6a 190as an AC-Unsafe feature may, if canceled asynchronously,
d95411aa
MK
191fail to release a lock that would have been released if their execution
192had not been interrupted by asynchronous thread cancellation.
193Once a lock is left taken, attempts to take that lock will block indefinitely.
194.TP
195.I corrupt
196Functions marked with
197.I corrupt
198as an AS-Unsafe feature may corrupt
199data structures and misbehave when they interrupt,
200or are interrupted by, another such function.
201Unlike functions marked with
202.IR lock ,
203these take recursive locks to avoid MT-Safety problems,
204but this is not enough to stop a signal handler from observing
205a partially-updated data structure.
206Further corruption may arise from the interrupted function's
207failure to notice updates made by signal handlers.
208
209Functions marked with
210.I corrupt
211as an AC-Unsafe feature may leave
212data structures in a corrupt, partially updated state.
213Subsequent uses of the data structure may misbehave.
214
215.\" A special case, probably not worth documenting separately, involves
216.\" reallocing, or even freeing pointers. Any case involving free could
217.\" be easily turned into an ac-safe leak by resetting the pointer before
218.\" releasing it; I don't think we have any case that calls for this sort
219.\" of fixing. Fixing the realloc cases would require a new interface:
220.\" instead of @code{ptr=realloc(ptr,size)} we'd have to introduce
221.\" @code{acsafe_realloc(&ptr,size)} that would modify ptr before
222.\" releasing the old memory. The ac-unsafe realloc could be implemented
223.\" in terms of an internal interface with this semantics (say
224.\" __acsafe_realloc), but since realloc can be overridden, the function
225.\" we call to implement realloc should not be this internal interface,
226.\" but another internal interface that calls __acsafe_realloc if realloc
227.\" was not overridden, and calls the overridden realloc with async
228.\" cancel disabled. --lxoliva
229.TP
230.I heap
231Functions marked with
232.I heap
233may call heap memory management functions from the
234.BR malloc (3)/ free (3)
235family of functions and are only as safe as those functions.
236This note is thus equivalent to:
237
238 | AS-Unsafe lock | AC-Unsafe lock fd mem |
239.\" @sampsafety{@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{} @acsmem{}}}
240.\"
241.\" Check for cases that should have used plugin instead of or in
242.\" addition to this. Then, after rechecking gettext, adjust i18n if
243.\" needed.
244.TP
245.I dlopen
246Functions marked with
247.I dlopen
248use the dynamic loader to load
249shared libraries into the current execution image.
250This involves opening files, mapping them into memory,
251allocating additional memory, resolving symbols,
252applying relocations and more,
253all of this while holding internal dynamic loader locks.
254
255The locks are enough for these functions to be AS- and AC-Unsafe,
256but other issues may arise.
257At present this is a placeholder for all
258potential safety issues raised by
259.BR dlopen (3).
260
261.\" dlopen runs init and fini sections of the module; does this mean
262.\" dlopen always implies plugin?
263.TP
264.I plugin
265Functions annotated with
266.I plugin
267may run code from plugins that
268may be external to the GNU C Library.
269Such plugin functions are assumed to be
270MT-Safe, AS-Unsafe and AC-Unsafe.
271Examples of such plugins are stack unwinding libraries,
272name service switch (NSS) and character set conversion (iconv) back-ends.
273
274Although the plugins mentioned as examples are all brought in by means
275of dlopen, the
276.I plugin
277keyword does not imply any direct
278involvement of the dynamic loader or the
279.I libdl
280interfaces,
281those are covered by
282.IR dlopen .
283For example, if one function loads a module and finds the addresses
284of some of its functions,
285while another just calls those already-resolved functions,
286the former will be marked with
287.IR dlopen ,
288whereas the latter will get the
289.IR plugin .
290When a single function takes all of these actions, then it gets both marks.
291.TP
292.I i18n
293Functions marked with
294.I i18n
295may call internationalization
296functions of the
297.BR gettext (3)
298family and will be only as safe as those
299functions.
300This note is thus equivalent to:
301
302 | MT-Safe env | AS-Unsafe corrupt heap dlopen | AC-Unsafe corrupt |
303
304.\" @sampsafety{@mtsafe{@mtsenv{}}@asunsafe{@asucorrupt{} @ascuheap{} @ascudlopen{}}@acunsafe{@acucorrupt{}}}
305.TP
306.I timer
307Functions marked with
308.I timer
309use the
310.BR alarm (3)
311function or
312similar to set a time-out for a system call or a long-running operation.
313In a multi-threaded program, there is a risk that the time-out signal
314will be delivered to a different thread,
315thus failing to interrupt the intended thread.
316Besides being MT-Unsafe, such functions are always
317AS-Unsafe, because calling them in signal handlers may interfere with
318timers set in the interrupted code, and AC-Unsafe,
319because there is no safe way to guarantee an earlier timer
320will be reset in case of asynchronous cancellation.
321.\"
322.\"
323.SS Conditionally safe features
324For some features that make functions unsafe to call in certain contexts,
325there are known ways to avoid the safety problem other than
326refraining from calling the function altogether.
327The keywords that follow refer to such features,
328and each of their definitions indicate
329how the whole program needs to be constrained in order to remove the
330safety problem indicated by the keyword.
331Only when all the reasons that
332make a function unsafe are observed and addressed,
333by applying the documented constraints,
334does the function become safe to call in a context.
335.TP
336.I init
337Functions marked with
338.I init
339as an MT-Unsafe feature perform
340MT-Unsafe initialization when they are first called.
341
342Calling such a function at least once in single-threaded mode removes
343this specific cause for the function to be regarded as MT-Unsafe.
344If no other cause for that remains,
345the function can then be safely called after other threads are started.
346
347Functions marked with
348.I init
349as an AS- or AC-Unsafe feature use the GNU C Library internal
350.I libc_once
351machinery or similar to initialize internal data structures.
352
353If a signal handler interrupts such an initializer,
354and calls any function that also performs
355.I libc_once
356initialization, it will deadlock if the thread library has been loaded.
357
358Furthermore, if an initializer is partially complete before it is canceled
359or interrupted by a signal whose handler requires the same initialization,
360some or all of the initialization may be performed more than once,
361leaking resources or even resulting in corrupt internal data.
362
363Applications that need to call functions marked with
364.I init
365as an AS-Safety or AC-Unsafe feature should ensure
366the initialization is performed
367before configuring signal handlers or enabling cancellation,
368so that the AS-Safety and AC-Safety issues related with
369.I libc_once
370do not arise.
371
372.\" We may have to extend the annotations to cover conditions in which
373.\" initialization may or may not occur, since an initial call in a safe
374.\" context is no use if the initialization doesn't take place at that
375.\" time: it doesn't remove the risk for later calls.
376.TP
377.I race
378Functions annotated with
379.I race
380as an MT-Safety issue operate on
381objects in ways that may cause data races or similar forms of
382destructive interference out of concurrent execution.
383In some cases,
384the objects are passed to the functions by users;
385in others, they are used by the functions to return values to users;
386in others, they are not even exposed to users.
387
388We consider access to objects passed as (indirect) arguments to
389functions to be data race free.
390The assurance of data race free objects
391is the caller's responsibility.
392We will not mark a function as MT-Unsafe or AS-Unsafe
393if it misbehaves when users fail to take the measures required by
394POSIX to avoid data races when dealing with such objects.
395As a general rule, if a function is documented as reading from
396an object passed (by reference) to it, or modifying it,
397users ought to use memory synchronization primitives
398to avoid data races just as they would should they perform
399the accesses themselves rather than by calling the library function.
400Standard I/O
401.RI ( "FILE *" )
402streams are the exception to the general rule,
403in that POSIX mandates the library to guard against data races
404in many functions that manipulate objects of this specific opaque type.
405We regard this as a convenience provided to users,
406rather than as a general requirement whose expectations
407should extend to other types.
408
409In order to remind users that guarding certain arguments is their
410responsibility, we will annotate functions that take objects of certain
411types as arguments.
412We draw the line for objects passed by users as follows:
413objects whose types are exposed to users,
414and that users are expected to access directly,
415such as memory buffers, strings,
416and various user-visible structured types, do
417.I not
418give reason for functions to be annotated with
419.IR race .
420It would be noisy and redundant with the general requirement,
421and not many would be surprised by the library's lack of internal
422guards when accessing objects that can be accessed directly by users.
423
424As for objects that are opaque or opaque-like,
425in that they are to be manipulated only by passing them
426to library functions (e.g.,
427.IR FILE ,
428.IR DIR ,
429.IR obstack ,
430.IR iconv_t ),
431there might be additional expectations as to internal coordination
432of access by the library.
433We will annotate, with
434.I race
435followed by a colon and the argument name,
436functions that take such objects but that do not take
437care of synchronizing access to them by default.
438For example,
439.I FILE
440stream
441.I unlocked
442functions
443.RB ( unlocked_stdio (3))
444will be annotated,
445but those that perform implicit locking on
446.I FILE
447streams by default will not,
448even though the implicit locking may be disabled on a per-stream basis.
449
450In either case, we will not regard as MT-Unsafe functions that may
451access user-supplied objects in unsafe ways should users fail to ensure
452the accesses are well defined.
453The notion prevails that users are expected to safeguard against data races
454any user-supplied objects that the library accesses on their behalf.
455
456.\" The above describes @mtsrace; @mtasurace is described below.
457
458This user responsibility does not apply, however,
459to objects controlled by the library itself,
460such as internal objects and static buffers used
461to return values from certain calls.
462When the library doesn't guard them against concurrent uses,
463these cases are regarded as MT-Unsafe and AS-Unsafe (although the
464.I race
465mark under AS-Unsafe will be omitted
466as redundant with the one under MT-Unsafe).
467As in the case of user-exposed objects,
468the mark may be followed by a colon and an identifier.
469The identifier groups all functions that operate on a
470certain unguarded object; users may avoid the MT-Safety issues related
471with unguarded concurrent access to such internal objects by creating a
472non-recursive mutex related with the identifier,
473and always holding the mutex when calling any function marked
474as racy on that identifier,
475as they would have to should the identifier be an object under user control.
476The non-recursive mutex avoids the MT-Safety issue,
477but it trades one AS-Safety issue for another,
478so use in asynchronous signals remains undefined.
479
480When the identifier relates to a static buffer used to hold return values,
481the mutex must be held for as long as the buffer remains in use by the caller.
482Many functions that return pointers to static buffers offer reentrant
483variants that store return values in caller-supplied buffers instead.
484In some cases, such as
485.BR tmpname (3),
486the variant is chosen not by calling an alternate entry point,
487but by passing a non-NULL pointer to the buffer in which the
488returned values are to be stored.
489These variants are generally preferable in multi-threaded programs,
490although some of them are not MT-Safe because of other internal buffers,
491also documented with
492.I race
493notes.
494.TP
495.I const
496Functions marked with
497.I const
498as an MT-Safety issue non-atomically
499modify internal objects that are better regarded as constant,
500because a substantial portion of the GNU C Library accesses them without
501synchronization.
502Unlike
503.IR race ,
504that causes both readers and
505writers of internal objects to be regarded as MT-Unsafe and AS-Unsafe,
506this mark is applied to writers only.
507Writers remain equally MT-Unsafe and AS-Unsafe to call,
508but the then-mandatory constness of objects they
509modify enables readers to be regarded as MT-Safe and AS-Safe (as long as
510no other reasons for them to be unsafe remain),
511since the lack of synchronization is not a problem when the
512objects are effectively constant.
513
514The identifier that follows the
515.I const
516mark will appear by itself as a safety note in readers.
517Programs that wish to work around this safety issue,
a6f8ea6a 518so as to call writers, may use a non-recursive
d95411aa
MK
519.I rwlock
520associated with the identifier, and guard
521.I all
522calls to functions marked with
523.I const
524followed by the identifier with a write lock, and
525.I all
526calls to functions marked with the identifier
527by itself with a read lock.
528The non-recursive locking removes the MT-Safety problem,
529but it trades one AS-Safety problem for another,
530so use in asynchronous signals remains undefined.
531
532.\" But what if, instead of marking modifiers with const:id and readers
533.\" with just id, we marked writers with race:id and readers with ro:id?
534.\" Instead of having to define each instance of 'id', we'd have a
535.\" general pattern governing all such 'id's, wherein race:id would
536.\" suggest the need for an exclusive/write lock to make the function
537.\" safe, whereas ro:id would indicate 'id' is expected to be read-only,
538.\" but if any modifiers are called (while holding an exclusive lock),
539.\" then ro:id-marked functions ought to be guarded with a read lock for
540.\" safe operation. ro:env or ro:locale, for example, seems to convey
541.\" more clearly the expectations and the meaning, than just env or
542.\" locale.
543.TP
544.I sig
545Functions marked with
546.I sig
547as a MT-Safety issue
548(that implies an identical AS-Safety issue, omitted for brevity)
549may temporarily install a signal handler for internal purposes,
550which may interfere with other uses of the signal, identified after a colon.
551
552This safety problem can be worked around by ensuring that no other uses
553of the signal will take place for the duration of the call.
554Holding a non-recursive mutex while calling all functions that use the same
555temporary signal;
556blocking that signal before the call and resetting its
557handler afterwards is recommended.
558
559There is no safe way to guarantee the original signal handler is
560restored in case of asynchronous cancellation,
561therefore so-marked functions are also AC-Unsafe.
562
563.\" fixme: at least deferred cancellation should get it right, and would
564.\" obviate the restoring bit below, and the qualifier above.
565
566Besides the measures recommended to work around the
567MT-Safety and AS-Safety problem,
568in order to avert the cancellation problem,
569disabling asynchronous cancellation
570.I and
571installing a cleanup handler to restore the signal to the desired state
572and to release the mutex are recommended.
573.TP
574.I term
575Functions marked with
576.I term
577as an MT-Safety issue may change the
578terminal settings in the recommended way, namely: call
579.BR tcgetattr (3),
580modify some flags, and then call
581.BR tcsetattr (3),
582this creates a window in which changes made by other threads are lost.
583Thus, functions marked with
584.I term
585are MT-Unsafe.
586The same window enables changes made by asynchronous signals to be lost.
587These functions are also AS-Unsafe,
588but the corresponding mark is omitted as redundant.
589
590It is thus advisable for applications using the terminal to avoid
591concurrent and reentrant interactions with it,
592by not using it in signal handlers or blocking signals that might use it,
593and holding a lock while calling these functions and interacting
594with the terminal.
595This lock should also be used for mutual exclusion with functions marked with
596.IR race:tcattr(fd) ,
597where
598.I fd
599is a file descriptor for the controlling terminal.
600The caller may use a single mutex for simplicity,
601or use one mutex per terminal,
602even if referenced by different file descriptors.
603
604Functions marked with
605.I term
606as an AC-Safety issue are supposed to
607restore terminal settings to their original state,
a6f8ea6a 608after temporarily changing them, but they may fail to do so if canceled.
d95411aa
MK
609
610.\" fixme: at least deferred cancellation should get it right, and would
611.\" obviate the restoring bit below, and the qualifier above.
612
613Besides the measures recommended to work around the
614MT-Safety and AS-Safety problem,
615in order to avert the cancellation problem,
616disabling asynchronous cancellation
617.I and
618installing a cleanup handler to
619restore the terminal settings to the original state and to release the
620mutex are recommended.
621.\"
622.\"
623.SS Other safety remarks
624Additional keywords may be attached to functions,
625indicating features that do not make a function unsafe to call,
626but that may need to be taken into account in certain classes of programs:
627.TP
628.I locale
629Functions annotated with
630.I locale
631as an MT-Safety issue read from
632the locale object without any form of synchronization.
633Functions
634annotated with
635.I locale
636called concurrently with locale changes may
637behave in ways that do not correspond to any of the locales active
638during their execution, but an unpredictable mix thereof.
639
640We do not mark these functions as MT-Unsafe or AS-Unsafe, however,
641because functions that modify the locale object are marked with
642.I const:locale
643and regarded as unsafe.
644Being unsafe, the latter are not to be called when multiple threads
645are running or asynchronous signals are enabled,
646and so the locale can be considered effectively constant in these contexts,
647which makes the former safe.
648
649.\" Should the locking strategy suggested under @code{const} be used,
650.\" failure to guard locale uses is not as fatal as data races in
651.\" general: unguarded uses will @emph{not} follow dangling pointers or
652.\" access uninitialized, unmapped or recycled memory. Each access will
653.\" read from a consistent locale object that is or was active at some
654.\" point during its execution. Without synchronization, however, it
655.\" cannot even be assumed that, after a change in locale, earlier
656.\" locales will no longer be used, even after the newly-chosen one is
657.\" used in the thread. Nevertheless, even though unguarded reads from
658.\" the locale will not violate type safety, functions that access the
659.\" locale multiple times may invoke all sorts of undefined behavior
660.\" because of the unexpected locale changes.
661.TP
662.I env
663Functions marked with
664.I env
665as an MT-Safety issue access the
666environment with
667.BR getenv (3)
668or similar, without any guards to ensure
669safety in the presence of concurrent modifications.
670
671We do not mark these functions as MT- or AS-Unsafe, however,
672because functions that modify the environment are all marked with
673.I const:env
674and regarded as unsafe.
675Being unsafe, the latter are not to be called when multiple threads
676are running or asynchronous signals are enabled,
677and so the environment can be considered
678effectively constant in these contexts,
679which makes the former safe.
680.TP
681.I hostid
682The function marked with
683.I hostid
684as an MT-Safety issue reads from the system-wide data structures that
685hold the "host ID" of the machine.
686These data structures cannot generally be modified atomically.
687Since it is expected that the "host ID" will not normally change,
688the function that reads from it
689.RB ( gethostid (3))
690is regarded as safe,
691whereas the function that modifies it
692.RB ( sethostid (3))
693is marked with
694.IR const:hostid ,
695indicating it may require special care if it is to be called.
696In this specific case,
697the special care amounts to system-wide
698(not merely intra-process) coordination.
699.TP
700.I sigintr
701Functions marked with
702.I sigintr
703as an MT-Safety issue access the
704GNU C Library
705.I _sigintr
706internal data structure without any guards to ensure
707safety in the presence of concurrent modifications.
708
709We do not mark these functions as MT-Unsafe or AS-Unsafe, however,
710because functions that modify the this data structure are all marked with
711.I const:sigintr
712and regarded as unsafe.
713Being unsafe,
714the latter are not to be called when multiple threads are
715running or asynchronous signals are enabled,
716and so the data structure can be considered
717effectively constant in these contexts,
718which makes the former safe.
719.TP
720.I fd
721Functions annotated with
722.I fd
723as an AC-Safety issue may leak file
724descriptors if asynchronous thread cancellation interrupts their
725execution.
726
727Functions that allocate or deallocate file descriptors will generally be
728marked as such.
729Even if they attempted to protect the file descriptor
730allocation and deallocation with cleanup regions,
731allocating a new descriptor and storing its number where the cleanup region
732could release it cannot be performed as a single atomic operation.
733Similarly,
734releasing the descriptor and taking it out of the data structure
735normally responsible for releasing it cannot be performed atomically.
736There will always be a window in which the descriptor cannot be released
737because it was not stored in the cleanup handler argument yet,
738or it was already taken out before releasing it.
739It cannot be taken out after release:
740an open descriptor could mean either that the descriptor still
741has to be closed,
742or that it already did so but the descriptor was
743reallocated by another thread or signal handler.
744
745Such leaks could be internally avoided, with some performance penalty,
746by temporarily disabling asynchronous thread cancellation.
747However,
748since callers of allocation or deallocation functions would have to do
749this themselves, to avoid the same sort of leak in their own layer,
750it makes more sense for the library to assume they are taking care of it
751than to impose a performance penalty that is redundant when the problem
752is solved in upper layers, and insufficient when it is not.
753
754This remark by itself does not cause a function to be regarded as
755AC-Unsafe.
756However, cumulative effects of such leaks may pose a
757problem for some programs.
758If this is the case,
759suspending asynchronous cancellation for the duration of calls
760to such functions is recommended.
761.TP
762.I mem
763Functions annotated with
764.I mem
765as an AC-Safety issue may leak
766memory if asynchronous thread cancellation interrupts their execution.
767
768The problem is similar to that of file descriptors: there is no atomic
769interface to allocate memory and store its address in the argument to a
770cleanup handler,
771or to release it and remove its address from that argument,
772without at least temporarily disabling asynchronous cancellation,
773which these functions do not do.
774
775This remark does not by itself cause a function to be regarded as
776generally AC-Unsafe.
777However, cumulative effects of such leaks may be
778severe enough for some programs that disabling asynchronous cancellation
779for the duration of calls to such functions may be required.
780.TP
781.I cwd
782Functions marked with
783.I cwd
784as an MT-Safety issue may temporarily
785change the current working directory during their execution,
786which may cause relative pathnames to be resolved in unexpected ways in other
787threads or within asynchronous signal or cancellation handlers.
788
789This is not enough of a reason to mark so-marked functions as MT-Unsafe or
790AS-Unsafe, but when this behavior is optional (e.g.,
791.BR nftw (3)
792with
793.BR FTW_CHDIR ),
794avoiding the option may be a good alternative to
795using full pathnames or file descriptor-relative (e.g.,
796.BR openat (2))
797system calls.
798.TP
799.I !posix
800This remark, as an MT-Safety, AS-Safety or AC-Safety note to a function,
801indicates the safety status of the function is known to differ
802from the specified status in the POSIX standard.
803For example, POSIX does not require a function to be Safe,
804but our implementation is, or vice-versa.
805
806For the time being, the absence of this remark does not imply the safety
807properties we documented are identical to those mandated by POSIX for
808the corresponding functions.
809.TP
810.I :identifier
811Annotations may sometimes be followed by identifiers,
812intended to group several functions that, for example,
813access the data structures in an unsafe way, as in
814.I race
815and
816.IR const ,
817or to provide more specific information,
818such as naming a signal in a function marked with
819.IR sig .
820It is envisioned that it may be applied to
821.I lock
822and
823.I corrupt
824as well in the future.
825
826In most cases, the identifier will name a set of functions,
827but it may name global objects or function arguments,
828or identifiable properties or logical components associated with them,
829with a notation such as, for example,
830.I :buf(arg)
831to denote a buffer associated with the argument
832.IR arg ,
833or
834.I :tcattr(fd)
835to denote the terminal attributes of a file descriptor
836.IR fd .
837
838The most common use for identifiers is to provide logical groups of
839functions and arguments that need to be protected by the same
840synchronization primitive in order to ensure safe operation in a given
841context.
842.TP
843.I /condition
844Some safety annotations may be conditional,
845in that they only apply if a boolean expression involving arguments,
846global variables or even the underlying kernel evaluates evaluates to true.
847Such conditions as
848.I /hurd
849or
850.I /!linux!bsd
851indicate the preceding marker only
852applies when the underlying kernel is the HURD,
853or when it is neither Linux nor a BSD kernel, respectively.
854.I !ps
855and
856.I /one_per_line
857indicate the preceding marker only applies when argument
858.I ps
859is NULL, or global variable
860.I one_per_line
861is nonzero.
862
863When all marks that render a function unsafe are adorned with such conditions,
864and none of the named conditions hold,
865then the function can be regarded as safe.