xref: /llvm-project/libc/src/__support/OSUtil/linux/exit.cpp (revision 68112f0f5b2209e14aae9a891481cba5709873a2)
107bd4394SRoseZhang03 //===------------ Linux implementation of an exit function ------*- C++ -*-===//
207bd4394SRoseZhang03 //
307bd4394SRoseZhang03 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
407bd4394SRoseZhang03 // See https://llvm.org/LICENSE.txt for license information.
507bd4394SRoseZhang03 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
607bd4394SRoseZhang03 //
707bd4394SRoseZhang03 //===----------------------------------------------------------------------===//
807bd4394SRoseZhang03 
9*68112f0fSNick Desaulniers #include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
1007bd4394SRoseZhang03 #include "src/__support/common.h"
115ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
1207bd4394SRoseZhang03 #include <sys/syscall.h> // For syscall numbers.
1307bd4394SRoseZhang03 
145ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
155ff3ff33SPetr Hosek namespace internal {
1607bd4394SRoseZhang03 
1707bd4394SRoseZhang03 // mark as no_stack_protector for x86 since TLS can be torn down before calling
1807bd4394SRoseZhang03 // exit so that the stack protector canary cannot be loaded.
1907bd4394SRoseZhang03 #ifdef LIBC_TARGET_ARCH_IS_X86
20435e5c10SRoseZhang03 __attribute__((no_stack_protector))
2107bd4394SRoseZhang03 #endif
22435e5c10SRoseZhang03 __attribute__((noreturn)) void
2307bd4394SRoseZhang03 exit(int status) {
2407bd4394SRoseZhang03   for (;;) {
2507bd4394SRoseZhang03     LIBC_NAMESPACE::syscall_impl<long>(SYS_exit_group, status);
2607bd4394SRoseZhang03     LIBC_NAMESPACE::syscall_impl<long>(SYS_exit, status);
2707bd4394SRoseZhang03   }
2807bd4394SRoseZhang03 }
2907bd4394SRoseZhang03 
305ff3ff33SPetr Hosek } // namespace internal
315ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
32