]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/_umtx_op.2
Update to bmake-20220724
[FreeBSD/FreeBSD.git] / lib / libc / sys / _umtx_op.2
1 .\" Copyright (c) 2016 The FreeBSD Foundation, Inc.
2 .\"
3 .\" This documentation was written by
4 .\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
5 .\" from the FreeBSD Foundation.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\" $FreeBSD$
29 .\"
30 .Dd November 23, 2020
31 .Dt _UMTX_OP 2
32 .Os
33 .Sh NAME
34 .Nm _umtx_op
35 .Nd interface for implementation of userspace threading synchronization primitives
36 .Sh LIBRARY
37 .Lb libc
38 .Sh SYNOPSIS
39 .In sys/types.h
40 .In sys/umtx.h
41 .Ft int
42 .Fn _umtx_op "void *obj" "int op" "u_long val" "void *uaddr" "void *uaddr2"
43 .Sh DESCRIPTION
44 The
45 .Fn _umtx_op
46 system call provides kernel support for userspace implementation of
47 the threading synchronization primitives.
48 The
49 .Lb libthr
50 uses the syscall to implement
51 .St -p1003.1-2001
52 pthread locks, like mutexes, condition variables and so on.
53 .Ss STRUCTURES
54 The operations, performed by the
55 .Fn _umtx_op
56 syscall, operate on userspace objects which are described
57 by the following structures.
58 Reserved fields and paddings are omitted.
59 All objects require ABI-mandated alignment, but this is not currently
60 enforced consistently on all architectures.
61 .Pp
62 The following flags are defined for flag fields of all structures:
63 .Bl -tag -width indent
64 .It Dv USYNC_PROCESS_SHARED
65 Allow selection of the process-shared sleep queue for the thread sleep
66 container, when the lock ownership cannot be granted immediately,
67 and the operation must sleep.
68 The process-shared or process-private sleep queue is selected based on
69 the attributes of the memory mapping which contains the first byte of
70 the structure, see
71 .Xr mmap 2 .
72 Otherwise, if the flag is not specified, the process-private sleep queue
73 is selected regardless of the memory mapping attributes, as an optimization.
74 .Pp
75 See the
76 .Sx SLEEP QUEUES
77 subsection below for more details on sleep queues.
78 .El
79 .Bl -hang -offset indent
80 .It Sy Mutex
81 .Bd -literal
82 struct umutex {
83         volatile lwpid_t m_owner;
84         uint32_t         m_flags;
85         uint32_t         m_ceilings[2];
86         uintptr_t        m_rb_lnk;
87 };
88 .Ed
89 .Pp
90 The
91 .Dv m_owner
92 field is the actual lock.
93 It contains either the thread identifier of the lock owner in the
94 locked state, or zero when the lock is unowned.
95 The highest bit set indicates that there is contention on the lock.
96 The constants are defined for special values:
97 .Bl -tag -width indent
98 .It Dv UMUTEX_UNOWNED
99 Zero, the value stored in the unowned lock.
100 .It Dv UMUTEX_CONTESTED
101 The contention indicator.
102 .It Dv UMUTEX_RB_OWNERDEAD
103 A thread owning the robust mutex terminated.
104 The mutex is in unlocked state.
105 .It Dv UMUTEX_RB_NOTRECOV
106 The robust mutex is in a non-recoverable state.
107 It cannot be locked until reinitialized.
108 .El
109 .Pp
110 The
111 .Dv m_flags
112 field may contain the following umutex-specific flags, in addition to
113 the common flags:
114 .Bl -tag -width indent
115 .It Dv UMUTEX_PRIO_INHERIT
116 Mutex implements
117 .Em Priority Inheritance
118 protocol.
119 .It Dv UMUTEX_PRIO_PROTECT
120 Mutex implements
121 .Em Priority Protection
122 protocol.
123 .It Dv UMUTEX_ROBUST
124 Mutex is robust, as described in the
125 .Sx ROBUST UMUTEXES
126 section below.
127 .It Dv UMUTEX_NONCONSISTENT
128 Robust mutex is in a transient non-consistent state.
129 Not used by kernel.
130 .El
131 .Pp
132 In the manual page, mutexes not having
133 .Dv UMUTEX_PRIO_INHERIT
134 and
135 .Dv UMUTEX_PRIO_PROTECT
136 flags set, are called normal mutexes.
137 Each type of mutex
138 .Pq normal, priority-inherited, and priority-protected
139 has a separate sleep queue associated
140 with the given key.
141 .Pp
142 For priority protected mutexes, the
143 .Dv m_ceilings
144 array contains priority ceiling values.
145 The
146 .Dv m_ceilings[0]
147 is the ceiling value for the mutex, as specified by
148 .St -p1003.1-2008
149 for the
150 .Em Priority Protected
151 mutex protocol.
152 The
153 .Dv m_ceilings[1]
154 is used only for the unlock of a priority protected mutex, when
155 unlock is done in an order other than the reversed lock order.
156 In this case,
157 .Dv m_ceilings[1]
158 must contain the ceiling value for the last locked priority protected
159 mutex, for proper priority reassignment.
160 If, instead, the unlocking mutex was the last priority propagated
161 mutex locked by the thread,
162 .Dv m_ceilings[1]
163 should contain \-1.
164 This is required because kernel does not maintain the ordered lock list.
165 .It Sy Condition variable
166 .Bd -literal
167 struct ucond {
168         volatile uint32_t c_has_waiters;
169         uint32_t          c_flags;
170         uint32_t          c_clockid;
171 };
172 .Ed
173 .Pp
174 A non-zero
175 .Dv c_has_waiters
176 value indicates that there are in-kernel waiters for the condition,
177 executing the
178 .Dv UMTX_OP_CV_WAIT
179 request.
180 .Pp
181 The
182 .Dv c_flags
183 field contains flags.
184 Only the common flags
185 .Pq Dv USYNC_PROCESS_SHARED
186 are defined for ucond.
187 .Pp
188 The
189 .Dv c_clockid
190 member provides the clock identifier to use for timeout, when the
191 .Dv UMTX_OP_CV_WAIT
192 request has both the
193 .Dv CVWAIT_CLOCKID
194 flag and the timeout specified.
195 Valid clock identifiers are a subset of those for
196 .Xr clock_gettime 2 :
197 .Bl -bullet -compact
198 .It
199 .Dv CLOCK_MONOTONIC
200 .It
201 .Dv CLOCK_MONOTONIC_FAST
202 .It
203 .Dv CLOCK_MONOTONIC_PRECISE
204 .It
205 .Dv CLOCK_PROF
206 .It
207 .Dv CLOCK_REALTIME
208 .It
209 .Dv CLOCK_REALTIME_FAST
210 .It
211 .Dv CLOCK_REALTIME_PRECISE
212 .It
213 .Dv CLOCK_SECOND
214 .It
215 .Dv CLOCK_UPTIME
216 .It
217 .Dv CLOCK_UPTIME_FAST
218 .It
219 .Dv CLOCK_UPTIME_PRECISE
220 .It
221 .Dv CLOCK_VIRTUAL
222 .El
223 .It Sy Reader/writer lock
224 .Bd -literal
225 struct urwlock {
226         volatile int32_t rw_state;
227         uint32_t         rw_flags;
228         uint32_t         rw_blocked_readers;
229         uint32_t         rw_blocked_writers;
230 };
231 .Ed
232 .Pp
233 The
234 .Dv rw_state
235 field is the actual lock.
236 It contains both the flags and counter of the read locks which were
237 granted.
238 Names of the
239 .Dv rw_state
240 bits are following:
241 .Bl -tag -width indent
242 .It Dv URWLOCK_WRITE_OWNER
243 Write lock was granted.
244 .It Dv URWLOCK_WRITE_WAITERS
245 There are write lock waiters.
246 .It Dv URWLOCK_READ_WAITERS
247 There are read lock waiters.
248 .It Dv URWLOCK_READER_COUNT(c)
249 Returns the count of currently granted read locks.
250 .El
251 .Pp
252 At any given time there may be only one thread to which the writer lock
253 is granted on the
254 .Vt struct rwlock ,
255 and no threads are granted read lock.
256 Or, at the given time, up to
257 .Dv URWLOCK_MAX_READERS
258 threads may be granted the read lock simultaneously, but write lock is
259 not granted to any thread.
260 .Pp
261 The following flags for the
262 .Dv rw_flags
263 member of
264 .Vt struct urwlock
265 are defined, in addition to the common flags:
266 .Bl -tag -width indent
267 .It Dv URWLOCK_PREFER_READER
268 If specified, immediately grant read lock requests when
269 .Dv urwlock
270 is already read-locked, even in presence of unsatisfied write
271 lock requests.
272 By default, if there is a write lock waiter, further read requests are
273 not granted, to prevent unfair write lock waiter starvation.
274 .El
275 .Pp
276 The
277 .Dv rw_blocked_readers
278 and
279 .Dv rw_blocked_writers
280 members contain the count of threads which are sleeping in kernel,
281 waiting for the associated request type to be granted.
282 The fields are used by kernel to update the
283 .Dv URWLOCK_READ_WAITERS
284 and
285 .Dv URWLOCK_WRITE_WAITERS
286 flags of the
287 .Dv rw_state
288 lock after requesting thread was woken up.
289 .It Sy Semaphore
290 .Bd -literal
291 struct _usem2 {
292         volatile uint32_t _count;
293         uint32_t          _flags;
294 };
295 .Ed
296 .Pp
297 The
298 .Dv _count
299 word represents a counting semaphore.
300 A non-zero value indicates an unlocked (posted) semaphore, while zero
301 represents the locked state.
302 The maximal supported semaphore count is
303 .Dv USEM_MAX_COUNT .
304 .Pp
305 The
306 .Dv _count
307 word, besides the counter of posts (unlocks), also contains the
308 .Dv USEM_HAS_WAITERS
309 bit, which indicates that locked semaphore has waiting threads.
310 .Pp
311 The
312 .Dv USEM_COUNT()
313 macro, applied to the
314 .Dv _count
315 word, returns the current semaphore counter, which is the number of posts
316 issued on the semaphore.
317 .Pp
318 The following bits for the
319 .Dv _flags
320 member of
321 .Vt struct _usem2
322 are defined, in addition to the common flags:
323 .Bl -tag -width indent
324 .It Dv USEM_NAMED
325 Flag is ignored by kernel.
326 .El
327 .It Sy Timeout parameter
328 .Bd -literal
329 struct _umtx_time {
330         struct timespec _timeout;
331         uint32_t        _flags;
332         uint32_t        _clockid;
333 };
334 .Ed
335 .Pp
336 Several
337 .Fn _umtx_op
338 operations allow the blocking time to be limited, failing the request
339 if it cannot be satisfied in the specified time period.
340 The timeout is specified by passing either the address of
341 .Vt struct timespec ,
342 or its extended variant,
343 .Vt struct _umtx_time ,
344 as the
345 .Fa uaddr2
346 argument of
347 .Fn _umtx_op .
348 They are distinguished by the
349 .Fa uaddr
350 value, which must be equal to the size of the structure pointed to by
351 .Fa uaddr2 ,
352 casted to
353 .Vt uintptr_t .
354 .Pp
355 The
356 .Dv _timeout
357 member specifies the time when the timeout should occur.
358 Legal values for clock identifier
359 .Dv _clockid
360 are shared with the
361 .Fa clock_id
362 argument to the
363 .Xr clock_gettime 2
364 function,
365 and use the same underlying clocks.
366 The specified clock is used to obtain the current time value.
367 Interval counting is always performed by the monotonic wall clock.
368 .Pp
369 The
370 .Dv _flags
371 argument allows the following flags to further define the timeout behaviour:
372 .Bl -tag -width indent
373 .It Dv UMTX_ABSTIME
374 The
375 .Dv _timeout
376 value is the absolute time.
377 The thread will be unblocked and the request failed when specified
378 clock value is equal or exceeds the
379 .Dv _timeout.
380 .Pp
381 If the flag is absent, the timeout value is relative, that is the amount
382 of time, measured by the monotonic wall clock from the moment of the request
383 start.
384 .El
385 .El
386 .Ss SLEEP QUEUES
387 When a locking request cannot be immediately satisfied, the thread is
388 typically put to
389 .Em sleep ,
390 which is a non-runnable state terminated by the
391 .Em wake
392 operation.
393 Lock operations include a
394 .Em try
395 variant which returns an error rather than sleeping if the lock cannot
396 be obtained.
397 Also,
398 .Fn _umtx_op
399 provides requests which explicitly put the thread to sleep.
400 .Pp
401 Wakes need to know which threads to make runnable, so sleeping threads
402 are grouped into containers called
403 .Em sleep queues .
404 A sleep queue is identified by a key, which for
405 .Fn _umtx_op
406 is defined as the physical address of some variable.
407 Note that the
408 .Em physical
409 address is used, which means that same variable mapped multiple
410 times will give one key value.
411 This mechanism enables the construction of
412 .Em process-shared
413 locks.
414 .Pp
415 A related attribute of the key is shareability.
416 Some requests always interpret keys as private for the current process,
417 creating sleep queues with the scope of the current process even if
418 the memory is shared.
419 Others either select the shareability automatically from the
420 mapping attributes, or take additional input as the
421 .Dv USYNC_PROCESS_SHARED
422 common flag.
423 This is done as optimization, allowing the lock scope to be limited
424 regardless of the kind of backing memory.
425 .Pp
426 Only the address of the start byte of the variable specified as key is
427 important for determining corresponding sleep queue.
428 The size of the variable does not matter, so, for example, sleep on the same
429 address interpeted as
430 .Vt uint32_t
431 and
432 .Vt long
433 on a little-endian 64-bit platform would collide.
434 .Pp
435 The last attribute of the key is the object type.
436 The sleep queue to which a sleeping thread is assigned is an individual
437 one for simple wait requests, mutexes, rwlocks, condvars and other
438 primitives, even when the physical address of the key is same.
439 .Pp
440 When waking up a limited number of threads from a given sleep queue,
441 the highest priority threads that have been blocked for the longest on
442 the queue are selected.
443 .Ss ROBUST UMUTEXES
444 The
445 .Em robust umutexes
446 are provided as a substrate for a userspace library to implement
447 .Tn POSIX
448 robust mutexes.
449 A robust umutex must have the
450 .Dv UMUTEX_ROBUST
451 flag set.
452 .Pp
453 On thread termination, the kernel walks two lists of mutexes.
454 The two lists head addresses must be provided by a prior call to
455 .Dv UMTX_OP_ROBUST_LISTS
456 request.
457 The lists are singly-linked.
458 The link to next element is provided by the
459 .Dv m_rb_lnk
460 member of the
461 .Vt struct umutex .
462 .Pp
463 Robust list processing is aborted if the kernel finds a mutex
464 with any of the following conditions:
465 .Bl -dash -offset indent -compact
466 .It
467 the
468 .Dv UMUTEX_ROBUST
469 flag is not set
470 .It
471 not owned by the current thread, except when the mutex is pointed to
472 by the
473 .Dv robust_inactive
474 member of the
475 .Vt struct umtx_robust_lists_params ,
476 registered for the current thread
477 .It
478 the combination of mutex flags is invalid
479 .It
480 read of the umutex memory faults
481 .It
482 the list length limit described in
483 .Xr libthr 3
484 is reached.
485 .El
486 .Pp
487 Every mutex in both lists is unlocked as if the
488 .Dv UMTX_OP_MUTEX_UNLOCK
489 request is performed on it, but instead of the
490 .Dv UMUTEX_UNOWNED
491 value, the
492 .Dv m_owner
493 field is written with the
494 .Dv UMUTEX_RB_OWNERDEAD
495 value.
496 When a mutex in the
497 .Dv UMUTEX_RB_OWNERDEAD
498 state is locked by kernel due to the
499 .Dv UMTX_OP_MUTEX_TRYLOCK
500 and
501 .Dv UMTX_OP_MUTEX_LOCK
502 requests, the lock is granted and
503 .Er EOWNERDEAD
504 error is returned.
505 .Pp
506 Also, the kernel handles the
507 .Dv UMUTEX_RB_NOTRECOV
508 value of
509 .Dv the m_owner
510 field specially, always returning the
511 .Er ENOTRECOVERABLE
512 error for lock attempts, without granting the lock.
513 .Ss OPERATIONS
514 The following operations, requested by the
515 .Fa op
516 argument to the function, are implemented:
517 .Bl -tag -width indent
518 .It Dv UMTX_OP_WAIT
519 Wait.
520 The arguments for the request are:
521 .Bl -tag -width "obj"
522 .It Fa obj
523 Pointer to a variable of type
524 .Vt long .
525 .It Fa val
526 Current value of the
527 .Dv *obj .
528 .El
529 .Pp
530 The current value of the variable pointed to by the
531 .Fa obj
532 argument is compared with the
533 .Fa val .
534 If they are equal, the requesting thread is put to interruptible sleep
535 until woken up or the optionally specified timeout expires.
536 .Pp
537 The comparison and sleep are atomic.
538 In other words, if another thread writes a new value to
539 .Dv *obj
540 and then issues
541 .Dv UMTX_OP_WAKE ,
542 the request is guaranteed to not miss the wakeup,
543 which might otherwise happen between comparison and blocking.
544 .Pp
545 The physical address of memory where the
546 .Fa *obj
547 variable is located, is used as a key to index sleeping threads.
548 .Pp
549 The read of the current value of the
550 .Dv *obj
551 variable is not guarded by barriers.
552 In particular, it is the user's duty to ensure the lock acquire
553 and release memory semantics, if the
554 .Dv UMTX_OP_WAIT
555 and
556 .Dv UMTX_OP_WAKE
557 requests are used as a substrate for implementing a simple lock.
558 .Pp
559 The request is not restartable.
560 An unblocked signal delivered during the wait always results in sleep
561 interruption and
562 .Er EINTR
563 error.
564 .Pp
565 Optionally, a timeout for the request may be specified.
566 .It Dv UMTX_OP_WAKE
567 Wake the threads possibly sleeping due to
568 .Dv UMTX_OP_WAIT .
569 The arguments for the request are:
570 .Bl -tag -width "obj"
571 .It Fa obj
572 Pointer to a variable, used as a key to find sleeping threads.
573 .It Fa val
574 Up to
575 .Fa val
576 threads are woken up by this request.
577 Specify
578 .Dv INT_MAX
579 to wake up all waiters.
580 .El
581 .It Dv UMTX_OP_MUTEX_TRYLOCK
582 Try to lock umutex.
583 The arguments to the request are:
584 .Bl -tag -width "obj"
585 .It Fa obj
586 Pointer to the umutex.
587 .El
588 .Pp
589 Operates same as the
590 .Dv UMTX_OP_MUTEX_LOCK
591 request, but returns
592 .Er EBUSY
593 instead of sleeping if the lock cannot be obtained immediately.
594 .It Dv UMTX_OP_MUTEX_LOCK
595 Lock umutex.
596 The arguments to the request are:
597 .Bl -tag -width "obj"
598 .It Fa obj
599 Pointer to the umutex.
600 .El
601 .Pp
602 Locking is performed by writing the current thread id into the
603 .Dv m_owner
604 word of the
605 .Vt struct umutex .
606 The write is atomic, preserves the
607 .Dv UMUTEX_CONTESTED
608 contention indicator, and provides the acquire barrier for
609 lock entrance semantic.
610 .Pp
611 If the lock cannot be obtained immediately because another thread owns
612 the lock, the current thread is put to sleep, with
613 .Dv UMUTEX_CONTESTED
614 bit set before.
615 Upon wake up, the lock conditions are re-tested.
616 .Pp
617 The request adheres to the priority protection or inheritance protocol
618 of the mutex, specified by the
619 .Dv UMUTEX_PRIO_PROTECT
620 or
621 .Dv UMUTEX_PRIO_INHERIT
622 flag, respectively.
623 .Pp
624 Optionally, a timeout for the request may be specified.
625 .Pp
626 A request with a timeout specified is not restartable.
627 An unblocked signal delivered during the wait always results in sleep
628 interruption and
629 .Er EINTR
630 error.
631 A request without timeout specified is always restarted after return
632 from a signal handler.
633 .It Dv UMTX_OP_MUTEX_UNLOCK
634 Unlock umutex.
635 The arguments to the request are:
636 .Bl -tag -width "obj"
637 .It Fa obj
638 Pointer to the umutex.
639 .El
640 .Pp
641 Unlocks the mutex, by writing
642 .Dv UMUTEX_UNOWNED
643 (zero) value into
644 .Dv m_owner
645 word of the
646 .Vt struct umutex .
647 The write is done with a release barrier, to provide lock leave semantic.
648 .Pp
649 If there are threads sleeping in the sleep queue associated with the
650 umutex, one thread is woken up.
651 If more than one thread sleeps in the sleep queue, the
652 .Dv UMUTEX_CONTESTED
653 bit is set together with the write of the
654 .Dv UMUTEX_UNOWNED
655 value into
656 .Dv m_owner .
657 .Pp
658 The request adheres to the priority protection or inheritance protocol
659 of the mutex, specified by the
660 .Dv UMUTEX_PRIO_PROTECT
661 or
662 .Dv UMUTEX_PRIO_INHERIT
663 flag, respectively.
664 See description of the
665 .Dv m_ceilings
666 member of the
667 .Vt struct umutex
668 structure for additional details of the request operation on the
669 priority protected protocol mutex.
670 .It Dv UMTX_OP_SET_CEILING
671 Set ceiling for the priority protected umutex.
672 The arguments to the request are:
673 .Bl -tag -width "uaddr"
674 .It Fa obj
675 Pointer to the umutex.
676 .It Fa val
677 New ceiling value.
678 .It Fa uaddr
679 Address of a variable of type
680 .Vt uint32_t .
681 If not
682 .Dv NULL
683 and the update was successful, the previous ceiling value is
684 written to the location pointed to by
685 .Fa uaddr .
686 .El
687 .Pp
688 The request locks the umutex pointed to by the
689 .Fa obj
690 parameter, waiting for the lock if not immediately available.
691 After the lock is obtained, the new ceiling value
692 .Fa val
693 is written to the
694 .Dv m_ceilings[0]
695 member of the
696 .Vt struct umutex,
697 after which the umutex is unlocked.
698 .Pp
699 The locking does not adhere to the priority protect protocol,
700 to conform to the
701 .Tn POSIX
702 requirements for the
703 .Xr pthread_mutex_setprioceiling 3
704 interface.
705 .It Dv UMTX_OP_CV_WAIT
706 Wait for a condition.
707 The arguments to the request are:
708 .Bl -tag -width "uaddr2"
709 .It Fa obj
710 Pointer to the
711 .Vt struct ucond .
712 .It Fa val
713 Request flags, see below.
714 .It Fa uaddr
715 Pointer to the umutex.
716 .It Fa uaddr2
717 Optional pointer to a
718 .Vt struct timespec
719 for timeout specification.
720 .El
721 .Pp
722 The request must be issued by the thread owning the mutex pointed to
723 by the
724 .Fa uaddr
725 argument.
726 The
727 .Dv c_hash_waiters
728 member of the
729 .Vt struct ucond ,
730 pointed to by the
731 .Fa obj
732 argument, is set to an arbitrary non-zero value, after which the
733 .Fa uaddr
734 mutex is unlocked (following the appropriate protocol), and
735 the current thread is put to sleep on the sleep queue keyed by
736 the
737 .Fa obj
738 argument.
739 The operations are performed atomically.
740 It is guaranteed to not miss a wakeup from
741 .Dv UMTX_OP_CV_SIGNAL
742 or
743 .Dv UMTX_OP_CV_BROADCAST
744 sent between mutex unlock and putting the current thread on the sleep queue.
745 .Pp
746 Upon wakeup, if the timeout expired and no other threads are sleeping in
747 the same sleep queue, the
748 .Dv c_hash_waiters
749 member is cleared.
750 After wakeup, the
751 .Fa uaddr
752 umutex is not relocked.
753 .Pp
754 The following flags are defined:
755 .Bl -tag -width "CVWAIT_CLOCKID"
756 .It Dv CVWAIT_ABSTIME
757 Timeout is absolute.
758 .It Dv CVWAIT_CLOCKID
759 Clockid is provided.
760 .El
761 .Pp
762 Optionally, a timeout for the request may be specified.
763 Unlike other requests, the timeout value is specified directly by a
764 .Vt struct timespec ,
765 pointed to by the
766 .Fa uaddr2
767 argument.
768 If the
769 .Dv CVWAIT_CLOCKID
770 flag is provided, the timeout uses the clock from the
771 .Dv c_clockid
772 member of the
773 .Vt struct ucond ,
774 pointed to by
775 .Fa obj
776 argument.
777 Otherwise,
778 .Dv CLOCK_REALTIME
779 is used, regardless of the clock identifier possibly specified in the
780 .Vt struct _umtx_time .
781 If the
782 .Dv CVWAIT_ABSTIME
783 flag is supplied, the timeout specifies absolute time value, otherwise
784 it denotes a relative time interval.
785 .Pp
786 The request is not restartable.
787 An unblocked signal delivered during
788 the wait always results in sleep interruption and
789 .Er EINTR
790 error.
791 .It Dv UMTX_OP_CV_SIGNAL
792 Wake up one condition waiter.
793 The arguments to the request are:
794 .Bl -tag -width "obj"
795 .It Fa obj
796 Pointer to
797 .Vt struct ucond .
798 .El
799 .Pp
800 The request wakes up at most one thread sleeping on the sleep queue keyed
801 by the
802 .Fa obj
803 argument.
804 If the woken up thread was the last on the sleep queue, the
805 .Dv c_has_waiters
806 member of the
807 .Vt struct ucond
808 is cleared.
809 .It Dv UMTX_OP_CV_BROADCAST
810 Wake up all condition waiters.
811 The arguments to the request are:
812 .Bl -tag -width "obj"
813 .It Fa obj
814 Pointer to
815 .Vt struct ucond .
816 .El
817 .Pp
818 The request wakes up all threads sleeping on the sleep queue keyed by the
819 .Fa obj
820 argument.
821 The
822 .Dv c_has_waiters
823 member of the
824 .Vt struct ucond
825 is cleared.
826 .It Dv UMTX_OP_WAIT_UINT
827 Same as
828 .Dv UMTX_OP_WAIT ,
829 but the type of the variable pointed to by
830 .Fa obj
831 is
832 .Vt u_int
833 .Pq a 32-bit integer .
834 .It Dv UMTX_OP_RW_RDLOCK
835 Read-lock a
836 .Vt struct rwlock
837 lock.
838 The arguments to the request are:
839 .Bl -tag -width "obj"
840 .It Fa obj
841 Pointer to the lock (of type
842 .Vt struct rwlock )
843 to be read-locked.
844 .It Fa val
845 Additional flags to augment locking behaviour.
846 The valid flags in the
847 .Fa val
848 argument are:
849 .Bl -tag -width indent
850 .It Dv URWLOCK_PREFER_READER
851 .El
852 .El
853 .Pp
854 The request obtains the read lock on the specified
855 .Vt struct rwlock
856 by incrementing the count of readers in the
857 .Dv rw_state
858 word of the structure.
859 If the
860 .Dv URWLOCK_WRITE_OWNER
861 bit is set in the word
862 .Dv rw_state ,
863 the lock was granted to a writer which has not yet relinquished
864 its ownership.
865 In this case the current thread is put to sleep until it makes sense to
866 retry.
867 .Pp
868 If the
869 .Dv URWLOCK_PREFER_READER
870 flag is set either in the
871 .Dv rw_flags
872 word of the structure, or in the
873 .Fa val
874 argument of the request, the presence of the threads trying to obtain
875 the write lock on the same structure does not prevent the current thread
876 from trying to obtain the read lock.
877 Otherwise, if the flag is not set, and the
878 .Dv URWLOCK_WRITE_WAITERS
879 flag is set in
880 .Dv rw_state ,
881 the current thread does not attempt to obtain read-lock.
882 Instead it sets the
883 .Dv URWLOCK_READ_WAITERS
884 in the
885 .Dv rw_state
886 word and puts itself to sleep on corresponding sleep queue.
887 Upon wakeup, the locking conditions are re-evaluated.
888 .Pp
889 Optionally, a timeout for the request may be specified.
890 .Pp
891 The request is not restartable.
892 An unblocked signal delivered during the wait always results in sleep
893 interruption and
894 .Er EINTR
895 error.
896 .It Dv UMTX_OP_RW_WRLOCK
897 Write-lock a
898 .Vt struct rwlock
899 lock.
900 The arguments to the request are:
901 .Bl -tag -width "obj"
902 .It Fa obj
903 Pointer to the lock (of type
904 .Vt struct rwlock )
905 to be write-locked.
906 .El
907 .Pp
908 The request obtains a write lock on the specified
909 .Vt struct rwlock ,
910 by setting the
911 .Dv URWLOCK_WRITE_OWNER
912 bit in the
913 .Dv rw_state
914 word of the structure.
915 If there is already a write lock owner, as indicated by the
916 .Dv URWLOCK_WRITE_OWNER
917 bit being set, or there are read lock owners, as indicated
918 by the read-lock counter, the current thread does not attempt to
919 obtain the write-lock.
920 Instead it sets the
921 .Dv URWLOCK_WRITE_WAITERS
922 in the
923 .Dv rw_state
924 word and puts itself to sleep on corresponding sleep queue.
925 Upon wakeup, the locking conditions are re-evaluated.
926 .Pp
927 Optionally, a timeout for the request may be specified.
928 .Pp
929 The request is not restartable.
930 An unblocked signal delivered during the wait always results in sleep
931 interruption and
932 .Er EINTR
933 error.
934 .It Dv UMTX_OP_RW_UNLOCK
935 Unlock rwlock.
936 The arguments to the request are:
937 .Bl -tag -width "obj"
938 .It Fa obj
939 Pointer to the lock (of type
940 .Vt struct rwlock )
941 to be unlocked.
942 .El
943 .Pp
944 The unlock type (read or write) is determined by the
945 current lock state.
946 Note that the
947 .Vt struct rwlock
948 does not save information about the identity of the thread which
949 acquired the lock.
950 .Pp
951 If there are pending writers after the unlock, and the
952 .Dv URWLOCK_PREFER_READER
953 flag is not set in the
954 .Dv rw_flags
955 member of the
956 .Fa *obj
957 structure, one writer is woken up, selected as described in the
958 .Sx SLEEP QUEUES
959 subsection.
960 If the
961 .Dv URWLOCK_PREFER_READER
962 flag is set, a pending writer is woken up only if there is
963 no pending readers.
964 .Pp
965 If there are no pending writers, or, in the case that the
966 .Dv URWLOCK_PREFER_READER
967 flag is set, then all pending readers are woken up by unlock.
968 .It Dv UMTX_OP_WAIT_UINT_PRIVATE
969 Same as
970 .Dv UMTX_OP_WAIT_UINT ,
971 but unconditionally select the process-private sleep queue.
972 .It Dv UMTX_OP_WAKE_PRIVATE
973 Same as
974 .Dv UMTX_OP_WAKE ,
975 but unconditionally select the process-private sleep queue.
976 .It Dv UMTX_OP_MUTEX_WAIT
977 Wait for mutex availability.
978 The arguments to the request are:
979 .Bl -tag -width "obj"
980 .It Fa obj
981 Address of the mutex.
982 .El
983 .Pp
984 Similarly to the
985 .Dv UMTX_OP_MUTEX_LOCK ,
986 put the requesting thread to sleep if the mutex lock cannot be obtained
987 immediately.
988 The
989 .Dv UMUTEX_CONTESTED
990 bit is set in the
991 .Dv m_owner
992 word of the mutex to indicate that there is a waiter, before the thread
993 is added to the sleep queue.
994 Unlike the
995 .Dv UMTX_OP_MUTEX_LOCK
996 request, the lock is not obtained.
997 .Pp
998 The operation is not implemented for priority protected and
999 priority inherited protocol mutexes.
1000 .Pp
1001 Optionally, a timeout for the request may be specified.
1002 .Pp
1003 A request with a timeout specified is not restartable.
1004 An unblocked signal delivered during the wait always results in sleep
1005 interruption and
1006 .Er EINTR
1007 error.
1008 A request without a timeout automatically restarts if the signal disposition
1009 requested restart via the
1010 .Dv SA_RESTART
1011 flag in
1012 .Vt struct sigaction
1013 member
1014 .Dv sa_flags .
1015 .It Dv UMTX_OP_NWAKE_PRIVATE
1016 Wake up a batch of sleeping threads.
1017 The arguments to the request are:
1018 .Bl -tag -width "obj"
1019 .It Fa obj
1020 Pointer to the array of pointers.
1021 .It Fa val
1022 Number of elements in the array pointed to by
1023 .Fa obj .
1024 .El
1025 .Pp
1026 For each element in the array pointed to by
1027 .Fa obj ,
1028 wakes up all threads waiting on the
1029 .Em private
1030 sleep queue with the key
1031 being the byte addressed by the array element.
1032 .It Dv UMTX_OP_MUTEX_WAKE
1033 Check if a normal umutex is unlocked and wake up a waiter.
1034 The arguments for the request are:
1035 .Bl -tag -width "obj"
1036 .It Fa obj
1037 Pointer to the umutex.
1038 .El
1039 .Pp
1040 If the
1041 .Dv m_owner
1042 word of the mutex pointed to by the
1043 .Fa obj
1044 argument indicates unowned mutex, which has its contention indicator bit
1045 .Dv UMUTEX_CONTESTED
1046 set, clear the bit and wake up one waiter in the sleep queue associated
1047 with the byte addressed by the
1048 .Fa obj ,
1049 if any.
1050 Only normal mutexes are supported by the request.
1051 The sleep queue is always one for a normal mutex type.
1052 .Pp
1053 This request is deprecated in favor of
1054 .Dv UMTX_OP_MUTEX_WAKE2
1055 since mutexes using it cannot synchronize their own destruction.
1056 That is, the
1057 .Dv m_owner
1058 word has already been set to
1059 .Dv UMUTEX_UNOWNED
1060 when this request is made,
1061 so that another thread can lock, unlock and destroy the mutex
1062 (if no other thread uses the mutex afterwards).
1063 Clearing the
1064 .Dv UMUTEX_CONTESTED
1065 bit may then modify freed memory.
1066 .It Dv UMTX_OP_MUTEX_WAKE2
1067 Check if a umutex is unlocked and wake up a waiter.
1068 The arguments for the request are:
1069 .Bl -tag -width "obj"
1070 .It Fa obj
1071 Pointer to the umutex.
1072 .It Fa val
1073 The umutex flags.
1074 .El
1075 .Pp
1076 The request does not read the
1077 .Dv m_flags
1078 member of the
1079 .Vt struct umutex ;
1080 instead, the
1081 .Fa val
1082 argument supplies flag information, in particular, to determine the
1083 sleep queue where the waiters are found for wake up.
1084 .Pp
1085 If the mutex is unowned, one waiter is woken up.
1086 .Pp
1087 If the mutex memory cannot be accessed, all waiters are woken up.
1088 .Pp
1089 If there is more than one waiter on the sleep queue, or there is only
1090 one waiter but the mutex is owned by a thread, the
1091 .Dv UMUTEX_CONTESTED
1092 bit is set in the
1093 .Dv m_owner
1094 word of the
1095 .Vt struct umutex .
1096 .It Dv UMTX_OP_SEM2_WAIT
1097 Wait until semaphore is available.
1098 The arguments to the request are:
1099 .Bl -tag -width "obj"
1100 .It Fa obj
1101 Pointer to the semaphore (of type
1102 .Vt struct _usem2 ) .
1103 .It Fa uaddr
1104 Size of the memory passed in via the
1105 .Fa uaddr2
1106 argument.
1107 .It Fa uaddr2
1108 Optional pointer to a structure of type
1109 .Vt struct _umtx_time ,
1110 which may be followed by a structure of type
1111 .Vt struct timespec .
1112 .El
1113 .Pp
1114 Put the requesting thread onto a sleep queue if the semaphore counter
1115 is zero.
1116 If the thread is put to sleep, the
1117 .Dv USEM_HAS_WAITERS
1118 bit is set in the
1119 .Dv _count
1120 word to indicate waiters.
1121 The function returns either due to
1122 .Dv _count
1123 indicating the semaphore is available (non-zero count due to post),
1124 or due to a wakeup.
1125 The return does not guarantee that the semaphore is available,
1126 nor does it consume the semaphore lock on successful return.
1127 .Pp
1128 Optionally, a timeout for the request may be specified.
1129 .Pp
1130 A request with non-absolute timeout value is not restartable.
1131 An unblocked signal delivered during such wait results in sleep
1132 interruption and
1133 .Er EINTR
1134 error.
1135 .Pp
1136 If
1137 .Dv UMTX_ABSTIME
1138 was not set, and the operation was interrupted and the caller passed in a
1139 .Fa uaddr2
1140 large enough to hold a
1141 .Vt struct timespec
1142 following the initial
1143 .Vt struct _umtx_time ,
1144 then the
1145 .Vt struct timespec
1146 is updated to contain the unslept amount.
1147 .It Dv UMTX_OP_SEM2_WAKE
1148 Wake up waiters on semaphore lock.
1149 The arguments to the request are:
1150 .Bl -tag -width "obj"
1151 .It Fa obj
1152 Pointer to the semaphore (of type
1153 .Vt struct _usem2 ) .
1154 .El
1155 .Pp
1156 The request wakes up one waiter for the semaphore lock.
1157 The function does not increment the semaphore lock count.
1158 If the
1159 .Dv USEM_HAS_WAITERS
1160 bit was set in the
1161 .Dv _count
1162 word, and the last sleeping thread was woken up, the bit is cleared.
1163 .It Dv UMTX_OP_SHM
1164 Manage anonymous
1165 .Tn POSIX
1166 shared memory objects (see
1167 .Xr shm_open 2 ) ,
1168 which can be attached to a byte of physical memory, mapped into the
1169 process address space.
1170 The objects are used to implement process-shared locks in
1171 .Dv libthr .
1172 .Pp
1173 The
1174 .Fa val
1175 argument specifies the sub-request of the
1176 .Dv UMTX_OP_SHM
1177 request:
1178 .Bl -tag -width indent
1179 .It Dv UMTX_SHM_CREAT
1180 Creates the anonymous shared memory object, which can be looked up
1181 with the specified key
1182 .Fa uaddr .
1183 If the object associated with the
1184 .Fa uaddr
1185 key already exists, it is returned instead of creating a new object.
1186 The object's size is one page.
1187 On success, the file descriptor referencing the object is returned.
1188 The descriptor can be used for mapping the object using
1189 .Xr mmap 2 ,
1190 or for other shared memory operations.
1191 .It Dv UMTX_SHM_LOOKUP
1192 Same as
1193 .Dv UMTX_SHM_CREATE
1194 request, but if there is no shared memory object associated with
1195 the specified key
1196 .Fa uaddr ,
1197 an error is returned, and no new object is created.
1198 .It Dv UMTX_SHM_DESTROY
1199 De-associate the shared object with the specified key
1200 .Fa uaddr .
1201 The object is destroyed after the last open file descriptor is closed
1202 and the last mapping for it is destroyed.
1203 .It Dv UMTX_SHM_ALIVE
1204 Checks whether there is a live shared object associated with the
1205 supplied key
1206 .Fa uaddr .
1207 Returns zero if there is, and an error otherwise.
1208 This request is an optimization of the
1209 .Dv UMTX_SHM_LOOKUP
1210 request.
1211 It is cheaper when only the liveness of the associated object is asked
1212 for, since no file descriptor is installed in the process fd table
1213 on success.
1214 .El
1215 .Pp
1216 The
1217 .Fa uaddr
1218 argument specifies the virtual address, which backing physical memory
1219 byte identity is used as a key for the anonymous shared object
1220 creation or lookup.
1221 .It Dv UMTX_OP_ROBUST_LISTS
1222 Register the list heads for the current thread's robust mutex lists.
1223 The arguments to the request are:
1224 .Bl -tag -width "uaddr"
1225 .It Fa val
1226 Size of the structure passed in the
1227 .Fa uaddr
1228 argument.
1229 .It Fa uaddr
1230 Pointer to the structure of type
1231 .Vt struct umtx_robust_lists_params .
1232 .El
1233 .Pp
1234 The structure is defined as
1235 .Bd -literal
1236 struct umtx_robust_lists_params {
1237         uintptr_t       robust_list_offset;
1238         uintptr_t       robust_priv_list_offset;
1239         uintptr_t       robust_inact_offset;
1240 };
1241 .Ed
1242 .Pp
1243 The
1244 .Dv robust_list_offset
1245 member contains address of the first element in the list of locked
1246 robust shared mutexes.
1247 The
1248 .Dv robust_priv_list_offset
1249 member contains address of the first element in the list of locked
1250 robust private mutexes.
1251 The private and shared robust locked lists are split to allow fast
1252 termination of the shared list on fork, in the child.
1253 .Pp
1254 The
1255 .Dv robust_inact_offset
1256 contains a pointer to the mutex which might be locked in nearby future,
1257 or might have been just unlocked.
1258 It is typically set by the lock or unlock mutex implementation code
1259 around the whole operation, since lists can be only changed race-free
1260 when the thread owns the mutex.
1261 The kernel inspects the
1262 .Dv robust_inact_offset
1263 in addition to walking the shared and private lists.
1264 Also, the mutex pointed to by
1265 .Dv robust_inact_offset
1266 is handled more loosely at the thread termination time,
1267 than other mutexes on the list.
1268 That mutex is allowed to be not owned by the current thread,
1269 in which case list processing is continued.
1270 See
1271 .Sx ROBUST UMUTEXES
1272 subsection for details.
1273 .El
1274 .Pp
1275 The
1276 .Fa op
1277 argument may be a bitwise OR of a single command from above with one or more of
1278 the following flags:
1279 .Bl -tag -width indent
1280 .It Dv UMTX_OP__I386
1281 Request i386 ABI compatibility from the native
1282 .Nm
1283 system call.
1284 Specifically, this implies that:
1285 .Bl -hang -offset indent
1286 .It
1287 .Fa obj
1288 arguments that point to a word, point to a 32-bit integer.
1289 .It
1290 The
1291 .Dv UMTX_OP_NWAKE_PRIVATE
1292 .Fa obj
1293 argument is a pointer to an array of 32-bit pointers.
1294 .It
1295 The
1296 .Dv m_rb_lnk
1297 member of
1298 .Vt struct umutex
1299 is a 32-bit pointer.
1300 .It
1301 .Vt struct timespec
1302 uses a 32-bit time_t.
1303 .El
1304 .Pp
1305 .Dv UMTX_OP__32BIT
1306 has no effect if this flag is set.
1307 This flag is valid for all architectures, but it is ignored on i386.
1308 .It Dv UMTX_OP__32BIT
1309 Request non-i386, 32-bit ABI compatibility from the native
1310 .Nm
1311 system call.
1312 Specifically, this implies that:
1313 .Bl -hang -offset indent
1314 .It
1315 .Fa obj
1316 arguments that point to a word, point to a 32-bit integer.
1317 .It
1318 The
1319 .Dv UMTX_OP_NWAKE_PRIVATE
1320 .Fa obj
1321 argument is a pointer to an array of 32-bit pointers.
1322 .It
1323 The
1324 .Dv m_rb_lnk
1325 member of
1326 .Vt struct umutex
1327 is a 32-bit pointer.
1328 .It
1329 .Vt struct timespec
1330 uses a 64-bit time_t.
1331 .El
1332 .Pp
1333 This flag has no effect if
1334 .Dv UMTX_OP__I386
1335 is set.
1336 This flag is valid for all architectures.
1337 .El
1338 .Pp
1339 Note that if any 32-bit ABI compatibility is being requested, then care must be
1340 taken with robust lists.
1341 A single thread may not mix 32-bit compatible robust lists with native
1342 robust lists.
1343 The first
1344 .Dv UMTX_OP_ROBUST_LISTS
1345 call in a given thread determines which ABI that thread will use for robust
1346 lists going forward.
1347 .Sh RETURN VALUES
1348 If successful,
1349 all requests, except
1350 .Dv UMTX_SHM_CREAT
1351 and
1352 .Dv UMTX_SHM_LOOKUP
1353 sub-requests of the
1354 .Dv UMTX_OP_SHM
1355 request, will return zero.
1356 The
1357 .Dv UMTX_SHM_CREAT
1358 and
1359 .Dv UMTX_SHM_LOOKUP
1360 return a shared memory file descriptor on success.
1361 On error \-1 is returned, and the
1362 .Va errno
1363 variable is set to indicate the error.
1364 .Sh ERRORS
1365 The
1366 .Fn _umtx_op
1367 operations can fail with the following errors:
1368 .Bl -tag -width "[ETIMEDOUT]"
1369 .It Bq Er EFAULT
1370 One of the arguments point to invalid memory.
1371 .It Bq Er EINVAL
1372 The clock identifier, specified for the
1373 .Vt struct _umtx_time
1374 timeout parameter, or in the
1375 .Dv c_clockid
1376 member of
1377 .Vt struct ucond,
1378 is invalid.
1379 .It Bq Er EINVAL
1380 The type of the mutex, encoded by the
1381 .Dv m_flags
1382 member of
1383 .Vt struct umutex ,
1384 is invalid.
1385 .It Bq Er EINVAL
1386 The
1387 .Dv m_owner
1388 member of the
1389 .Vt struct umutex
1390 has changed the lock owner thread identifier during unlock.
1391 .It Bq Er EINVAL
1392 The
1393 .Dv timeout.tv_sec
1394 or
1395 .Dv timeout.tv_nsec
1396 member of
1397 .Vt struct _umtx_time
1398 is less than zero, or
1399 .Dv timeout.tv_nsec
1400 is greater than 1000000000.
1401 .It Bq Er EINVAL
1402 The
1403 .Fa op
1404 argument specifies invalid operation.
1405 .It Bq Er EINVAL
1406 The
1407 .Fa uaddr
1408 argument for the
1409 .Dv UMTX_OP_SHM
1410 request specifies invalid operation.
1411 .It Bq Er EINVAL
1412 The
1413 .Dv UMTX_OP_SET_CEILING
1414 request specifies non priority protected mutex.
1415 .It Bq Er EINVAL
1416 The new ceiling value for the
1417 .Dv UMTX_OP_SET_CEILING
1418 request, or one or more of the values read from the
1419 .Dv m_ceilings
1420 array during lock or unlock operations, is greater than
1421 .Dv RTP_PRIO_MAX .
1422 .It Bq Er EPERM
1423 Unlock attempted on an object not owned by the current thread.
1424 .It Bq Er EOWNERDEAD
1425 The lock was requested on an umutex where the
1426 .Dv m_owner
1427 field was set to the
1428 .Dv UMUTEX_RB_OWNERDEAD
1429 value, indicating terminated robust mutex.
1430 The lock was granted to the caller, so this error in fact
1431 indicates success with additional conditions.
1432 .It Bq Er ENOTRECOVERABLE
1433 The lock was requested on an umutex which
1434 .Dv m_owner
1435 field is equal to the
1436 .Dv UMUTEX_RB_NOTRECOV
1437 value, indicating abandoned robust mutex after termination.
1438 The lock was not granted to the caller.
1439 .It Bq Er ENOTTY
1440 The shared memory object, associated with the address passed to the
1441 .Dv UMTX_SHM_ALIVE
1442 sub-request of
1443 .Dv UMTX_OP_SHM
1444 request, was destroyed.
1445 .It Bq Er ESRCH
1446 For the
1447 .Dv UMTX_SHM_LOOKUP ,
1448 .Dv UMTX_SHM_DESTROY ,
1449 and
1450 .Dv UMTX_SHM_ALIVE
1451 sub-requests of the
1452 .Dv UMTX_OP_SHM
1453 request, there is no shared memory object associated with the provided key.
1454 .It Bq Er ENOMEM
1455 The
1456 .Dv UMTX_SHM_CREAT
1457 sub-request of the
1458 .Dv UMTX_OP_SHM
1459 request cannot be satisfied, because allocation of the shared memory object
1460 would exceed the
1461 .Dv RLIMIT_UMTXP
1462 resource limit, see
1463 .Xr setrlimit 2 .
1464 .It Bq Er EAGAIN
1465 The maximum number of readers
1466 .Dv ( URWLOCK_MAX_READERS )
1467 were already granted ownership of the given
1468 .Vt struct rwlock
1469 for read.
1470 .It Bq Er EBUSY
1471 A try mutex lock operation was not able to obtain the lock.
1472 .It Bq Er ETIMEDOUT
1473 The request specified a timeout in the
1474 .Fa uaddr
1475 and
1476 .Fa uaddr2
1477 arguments, and timed out before obtaining the lock or being woken up.
1478 .It Bq Er EINTR
1479 A signal was delivered during wait, for a non-restartable operation.
1480 Operations with timeouts are typically non-restartable, but timeouts
1481 specified in absolute time may be restartable.
1482 .It Bq Er ERESTART
1483 A signal was delivered during wait, for a restartable operation.
1484 Mutex lock requests without timeout specified are restartable.
1485 The error is not returned to userspace code since restart
1486 is handled by usual adjustment of the instruction counter.
1487 .El
1488 .Sh SEE ALSO
1489 .Xr clock_gettime 2 ,
1490 .Xr mmap 2 ,
1491 .Xr setrlimit 2 ,
1492 .Xr shm_open 2 ,
1493 .Xr sigaction 2 ,
1494 .Xr thr_exit 2 ,
1495 .Xr thr_kill 2 ,
1496 .Xr thr_kill2 2 ,
1497 .Xr thr_new 2 ,
1498 .Xr thr_self 2 ,
1499 .Xr thr_set_name 2 ,
1500 .Xr signal 3
1501 .Sh STANDARDS
1502 The
1503 .Fn _umtx_op
1504 system call is non-standard and is used by the
1505 .Lb libthr
1506 to implement
1507 .St -p1003.1-2001
1508 .Xr pthread 3
1509 functionality.
1510 .Sh BUGS
1511 A window between a unlocking robust mutex and resetting the pointer in the
1512 .Dv robust_inact_offset
1513 member of the registered
1514 .Vt struct umtx_robust_lists_params
1515 allows another thread to destroy the mutex, thus making the kernel inspect
1516 freed or reused memory.
1517 The
1518 .Li libthr
1519 implementation is only vulnerable to this race when operating on
1520 a shared mutex.
1521 A possible fix for the current implementation is to strengthen the checks
1522 for shared mutexes before terminating them, in particular, verifying
1523 that the mutex memory is mapped from a shared memory object allocated
1524 by the
1525 .Dv UMTX_OP_SHM
1526 request.
1527 This is not done because it is believed that the race is adequately
1528 covered by other consistency checks, while adding the check would
1529 prevent alternative implementations of
1530 .Li libpthread .