unistd: Improve fortify with clang
[glibc.git] / sysdeps / mach / hurd / gai_misc.h
blobbd26ec319562f8c070880f287539d132cd9744f0
1 /* Copyright (C) 2006-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <assert.h>
19 #include <signal.h>
20 #include <pthread.h>
22 #define gai_start_notify_thread __gai_start_notify_thread
23 #define gai_create_helper_thread __gai_create_helper_thread
25 extern inline void
26 __gai_start_notify_thread (void)
28 sigset_t ss;
29 sigemptyset (&ss);
30 int sigerr __attribute__ ((unused));
31 sigerr = pthread_sigmask (SIG_SETMASK, &ss, NULL);
32 assert_perror (sigerr);
35 extern inline int
36 __gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
37 void *arg)
39 pthread_attr_t attr;
41 /* Make sure the thread is created detached. */
42 pthread_attr_init (&attr);
43 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
45 /* The helper thread needs only very little resources. */
46 (void) pthread_attr_setstacksize (&attr, 0x10000);
48 /* Block all signals in the helper thread. To do this thoroughly we
49 temporarily have to block all signals here. */
50 sigset_t ss;
51 sigset_t oss;
52 sigfillset (&ss);
53 int sigerr __attribute__ ((unused));
54 sigerr = pthread_sigmask (SIG_SETMASK, &ss, &oss);
55 assert_perror (sigerr);
57 int ret = pthread_create (threadp, &attr, tf, arg);
59 /* Restore the signal mask. */
60 sigerr = pthread_sigmask (SIG_SETMASK, &oss, NULL);
61 assert_perror (sigerr);
63 (void) pthread_attr_destroy (&attr);
64 return ret;
67 #include_next <gai_misc.h>