]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/htl/pt-sigstate.c
8b4a8760946fdb3449fb3bc90da932625e4fabc7
[thirdparty/glibc.git] / sysdeps / mach / hurd / htl / pt-sigstate.c
1 /* Set a thread's signal state. Hurd on Mach version.
2 Copyright (C) 2002-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <pthread.h>
20 #include <assert.h>
21 #include <signal.h>
22 #include <hurd/signal.h>
23 #include <hurd/msg.h>
24
25 #include <pt-internal.h>
26
27 error_t
28 __pthread_sigstate (struct __pthread *thread, int how,
29 const sigset_t *set, sigset_t *oset, int clear_pending)
30 {
31 error_t err = 0;
32 struct hurd_sigstate *ss;
33 sigset_t pending;
34
35 ss = _hurd_thread_sigstate (thread->kernel_thread);
36 assert (ss);
37
38 _hurd_sigstate_lock (ss);
39
40 if (oset != NULL)
41 *oset = ss->blocked;
42
43 if (set != NULL)
44 {
45 switch (how)
46 {
47 case SIG_BLOCK:
48 ss->blocked |= *set;
49 break;
50
51 case SIG_SETMASK:
52 ss->blocked = *set;
53 break;
54
55 case SIG_UNBLOCK:
56 ss->blocked &= ~*set;
57 break;
58
59 default:
60 err = EINVAL;
61 break;
62 }
63 ss->blocked &= ~_SIG_CANT_MASK;
64 }
65
66 if (!err && clear_pending)
67 __sigemptyset (&ss->pending);
68
69 pending = _hurd_sigstate_pending (ss) & ~ss->blocked;
70 _hurd_sigstate_unlock (ss);
71
72 if (!err && pending)
73 /* Send a message to the signal thread so it
74 will wake up and check for pending signals. */
75 __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
76
77 return err;
78 }