xref: /aosp_15_r20/external/llvm-libc/src/__support/OSUtil/linux/exit.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===------------ Linux implementation of an exit function ------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "src/__support/common.h"
10 #include "src/__support/macros/config.h"
11 #include "syscall.h"     // For internal syscall function.
12 #include <sys/syscall.h> // For syscall numbers.
13 
14 namespace LIBC_NAMESPACE_DECL {
15 namespace internal {
16 
17 // mark as no_stack_protector for x86 since TLS can be torn down before calling
18 // exit so that the stack protector canary cannot be loaded.
19 #ifdef LIBC_TARGET_ARCH_IS_X86
20 __attribute__((no_stack_protector))
21 #endif
22 __attribute__((noreturn)) void
exit(int status)23 exit(int status) {
24   for (;;) {
25     LIBC_NAMESPACE::syscall_impl<long>(SYS_exit_group, status);
26     LIBC_NAMESPACE::syscall_impl<long>(SYS_exit, status);
27   }
28 }
29 
30 } // namespace internal
31 } // namespace LIBC_NAMESPACE_DECL
32