• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "syscall.h"     // For internal syscall function.
11 #include <sys/syscall.h> // For syscall numbers.
12 
13 namespace LIBC_NAMESPACE::internal {
14 
15 // mark as no_stack_protector for x86 since TLS can be torn down before calling
16 // exit so that the stack protector canary cannot be loaded.
17 #ifdef LIBC_TARGET_ARCH_IS_X86
18 __attribute__((no_stack_protector))
19 #endif
20 __attribute__((noreturn)) void
exit(int status)21 exit(int status) {
22   for (;;) {
23     LIBC_NAMESPACE::syscall_impl<long>(SYS_exit_group, status);
24     LIBC_NAMESPACE::syscall_impl<long>(SYS_exit, status);
25   }
26 }
27 
28 } // namespace LIBC_NAMESPACE::internal
29