1# zx_vmar_unmap_handle_close_thread_exit
2
3## NAME
4
5<!-- Updated by update-docs-from-abigen, do not edit. -->
6
7vmar_unmap_handle_close_thread_exit - unmap memory, close handle, exit
8
9## SYNOPSIS
10
11<!-- Updated by update-docs-from-abigen, do not edit. -->
12
13```
14#include <zircon/syscalls.h>
15
16zx_status_t zx_vmar_unmap_handle_close_thread_exit(zx_handle_t vmar_handle,
17                                                   zx_vaddr_t addr,
18                                                   size_t size,
19                                                   zx_handle_t close_handle);
20```
21
22## DESCRIPTION
23
24`zx_vmar_unmap_handle_close_thread_exit()` does a sequence of three operations:
251. `zx_vmar_unmap(vmar_handle, addr, size)`
262. `zx_handle_close(close_handle)`
273. `zx_thread_exit()`
28
29The expectation is that the first operation unmaps a region including the
30calling thread's own stack.  (It's not required, but it's permitted.)  This
31is valid for this call, though it would be invalid for [`zx_vmar_unmap()`] or
32any other call.
33
34If the [`zx_vmar_unmap()`] operation is successful, then this call never returns.
35If *close_handle* is an invalid handle so that the [`zx_handle_close()`] operation
36fails, then the thread takes a trap (as if by `__builtin_trap();`).
37
38## RIGHTS
39
40<!-- Updated by update-docs-from-abigen, do not edit. -->
41
42TODO(ZX-2399)
43
44## RETURN VALUE
45
46`zx_vmar_unmap_handle_close_thread_exit()` does not return on success.
47
48## ERRORS
49
50Same as [`zx_vmar_unmap()`].
51
52## NOTES
53
54The intended use for this is for a dying thread to unmap its own stack,
55close its own thread handle, and exit.  The thread handle cannot be closed
56beforehand because closing the last handle to a thread kills that thread.
57The stack cannot be unmapped beforehand because the thread must have some
58stack space on which to make its final system calls.
59
60This call is used for detached threads, while
61[`zx_futex_wake_handle_close_thread_exit()`]
62is used for joinable threads.
63
64## SEE ALSO
65
66 - [`zx_futex_wake_handle_close_thread_exit()`]
67 - [`zx_handle_close()`]
68 - [`zx_thread_exit()`]
69 - [`zx_vmar_unmap()`]
70
71<!-- References updated by update-docs-from-abigen, do not edit. -->
72
73[`zx_futex_wake_handle_close_thread_exit()`]: futex_wake_handle_close_thread_exit.md
74[`zx_handle_close()`]: handle_close.md
75[`zx_thread_exit()`]: thread_exit.md
76[`zx_vmar_unmap()`]: vmar_unmap.md
77