]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/htl/pt-thread-terminate.c
1 /* Deallocate the kernel thread resources. Mach version.
2 Copyright (C) 2000-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
23 #include <mach/mig_support.h>
25 #include <pt-internal.h>
27 /* Terminate the kernel thread associated with THREAD, and deallocate its
28 right reference and its stack. The function also drops a reference
31 __pthread_thread_terminate (struct __pthread
*thread
)
33 thread_t kernel_thread
, self_ktid
;
34 mach_port_t wakeup_port
, reply_port
;
39 kernel_thread
= thread
->kernel_thread
;
43 stackaddr
= thread
->stackaddr
;
44 stacksize
= ((thread
->guardsize
+ __vm_page_size
- 1)
45 / __vm_page_size
) * __vm_page_size
+ thread
->stacksize
;
53 wakeup_port
= thread
->wakeupmsg
.msgh_remote_port
;
55 /* Each thread has its own reply port, allocated from MiG stub code calling
56 __mig_get_reply_port. Destroying it is a bit tricky because the calls
57 involved are also RPCs, causing the creation of a new reply port if
58 currently null. The __thread_terminate_release call is actually a one way
59 simple routine designed not to require a reply port. */
60 self_ktid
= __mach_thread_self ();
61 reply_port
= (self_ktid
== kernel_thread
)
62 ? __mig_get_reply_port () : MACH_PORT_NULL
;
63 __mach_port_deallocate (__mach_task_self (), self_ktid
);
65 /* Finally done with the thread structure. */
66 __pthread_dealloc (thread
);
68 /* The wake up port is now no longer needed. */
69 __mach_port_destroy (__mach_task_self (), wakeup_port
);
71 /* Terminate and release all that's left. */
72 err
= __thread_terminate_release (kernel_thread
, mach_task_self (),
73 kernel_thread
, reply_port
,
74 (vm_address_t
) stackaddr
, stacksize
);
76 /* The kernel does not support it yet. Leak but at least terminate
78 err
= __thread_terminate (kernel_thread
);
80 /* We are out of luck. */