1 /* Internal definitions for pthreads library.
2 Copyright (C) 2000-2022 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 #ifndef _PT_SYSDEP_H
20 #define _PT_SYSDEP_H 1
21
22 #include <mach.h>
23
24 /* XXX */
25 #define _POSIX_THREAD_THREADS_MAX 64
26
27 /* The default stack size. */
28 #define PTHREAD_STACK_DEFAULT (8 * 1024 * 1024)
29
30 #define PTHREAD_SYSDEP_MEMBERS \
31 thread_t kernel_thread; \
32 mach_msg_header_t wakeupmsg;
33
34 extern __thread struct __pthread *___pthread_self;
35 #ifdef DEBUG
36 #define _pthread_self() \
37 ({ \
38 struct __pthread *thread; \
39 \
40 assert (GL (dl_pthread_threads)); \
41 thread = ___pthread_self; \
42 \
43 assert (thread); \
44 assert (({ mach_port_t ktid = __mach_thread_self (); \
45 int ok = thread->kernel_thread == ktid; \
46 __mach_port_deallocate (__mach_task_self (), ktid);\
47 ok; })); \
48 thread; \
49 })
50 #else
51 #define _pthread_self() ___pthread_self
52 #endif
53
54 extern inline void
55 __attribute__ ((__always_inline__))
__pthread_stack_dealloc(void * stackaddr,size_t stacksize)56 __pthread_stack_dealloc (void *stackaddr, size_t stacksize)
57 {
58 __vm_deallocate (__mach_task_self (), (vm_offset_t) stackaddr, stacksize);
59 }
60
61 /* Change thread THREAD's program counter to PC if SET_PC is true,
62 its stack pointer to SP if SET_IP is true, and its thread pointer
63 to TP if SET_TP is true. */
64 extern int __thread_set_pcsptp (thread_t thread,
65 int set_pc, void *pc,
66 int set_sp, void *sp, int set_tp, void *tp);
67
68
69 #endif /* pt-sysdep.h */
70