1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup POSIXAPI |
---|
7 | * |
---|
8 | * @brief Examine and/or change the calling thread's signal mask |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * 3.3.5 Examine and Change Blocked Signals, P1003.1b-1993, p. 73 |
---|
13 | * |
---|
14 | * NOTE: P1003.1c/D10, p. 37 adds pthread_sigmask(). |
---|
15 | * |
---|
16 | * COPYRIGHT (c) 1989-1999. |
---|
17 | * On-Line Applications Research Corporation (OAR). |
---|
18 | * |
---|
19 | * Redistribution and use in source and binary forms, with or without |
---|
20 | * modification, are permitted provided that the following conditions |
---|
21 | * are met: |
---|
22 | * 1. Redistributions of source code must retain the above copyright |
---|
23 | * notice, this list of conditions and the following disclaimer. |
---|
24 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
25 | * notice, this list of conditions and the following disclaimer in the |
---|
26 | * documentation and/or other materials provided with the distribution. |
---|
27 | * |
---|
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
38 | * POSSIBILITY OF SUCH DAMAGE. |
---|
39 | */ |
---|
40 | |
---|
41 | #ifdef HAVE_CONFIG_H |
---|
42 | #include "config.h" |
---|
43 | #endif |
---|
44 | |
---|
45 | #include <pthread.h> |
---|
46 | #include <signal.h> |
---|
47 | #include <errno.h> |
---|
48 | |
---|
49 | #include <rtems/posix/pthreadimpl.h> |
---|
50 | #include <rtems/posix/psignalimpl.h> |
---|
51 | #include <rtems/seterr.h> |
---|
52 | |
---|
53 | int pthread_sigmask( |
---|
54 | int how, |
---|
55 | const sigset_t *__restrict set, |
---|
56 | sigset_t *__restrict oset |
---|
57 | ) |
---|
58 | { |
---|
59 | POSIX_API_Control *api; |
---|
60 | |
---|
61 | if ( !set && !oset ) |
---|
62 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
63 | |
---|
64 | api = _Thread_Get_executing()->API_Extensions[ THREAD_API_POSIX ]; |
---|
65 | |
---|
66 | if ( oset ) |
---|
67 | *oset = ~api->signals_unblocked; |
---|
68 | |
---|
69 | if ( !set ) |
---|
70 | return 0; |
---|
71 | |
---|
72 | switch ( how ) { |
---|
73 | case SIG_BLOCK: |
---|
74 | api->signals_unblocked &= ~*set; |
---|
75 | break; |
---|
76 | case SIG_UNBLOCK: |
---|
77 | api->signals_unblocked |= *set; |
---|
78 | break; |
---|
79 | case SIG_SETMASK: |
---|
80 | api->signals_unblocked = ~*set; |
---|
81 | break; |
---|
82 | default: |
---|
83 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
84 | } |
---|
85 | |
---|
86 | /* XXX are there critical section problems here? */ |
---|
87 | |
---|
88 | /* XXX evaluate the new set */ |
---|
89 | |
---|
90 | if ( api->signals_unblocked & |
---|
91 | (api->signals_pending | _POSIX_signals_Pending) ) { |
---|
92 | _Thread_Dispatch(); |
---|
93 | } |
---|
94 | |
---|
95 | return 0; |
---|
96 | } |
---|