1 //===-- Implementation header for errno -------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H
10 #define LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H
12 #include "src/__support/macros/attributes.h"
13 #include "src/__support/macros/properties/architectures.h"
17 // If we are targeting the GPU we currently don't support 'errno'. We simply
19 #ifdef LIBC_TARGET_ARCH_IS_GPU
20 namespace LIBC_NAMESPACE
{
21 struct ErrnoConsumer
{
22 void operator=(int) {}
24 } // namespace LIBC_NAMESPACE
27 // All of the libc runtime and test code should use the "libc_errno" macro. They
28 // should not refer to the "errno" macro directly.
29 #ifdef LIBC_COPT_PUBLIC_PACKAGING
30 #ifdef LIBC_TARGET_ARCH_IS_GPU
31 extern "C" LIBC_NAMESPACE::ErrnoConsumer __llvmlibc_errno
;
32 #define libc_errno __llvmlibc_errno
34 // This macro will resolve to errno from the errno.h file included above. Under
35 // full build, this will be LLVM libc's errno. In overlay build, it will be
36 // system libc's errno.
37 #define libc_errno errno
40 namespace LIBC_NAMESPACE
{
42 // TODO: On the GPU build this will be mapped to a single global value. We need
43 // to ensure that tests are not run with multiple threads that depend on errno
44 // until we have true 'thread_local' support on the GPU.
45 extern "C" LIBC_THREAD_LOCAL
int __llvmlibc_internal_errno
;
47 // TODO: After all of libc/src and libc/test are switched over to use
48 // libc_errno, this header file will be "shipped" via an add_entrypoint_object
49 // target. At which point libc_errno, should point to __llvmlibc_internal_errno
50 // if LIBC_COPT_PUBLIC_PACKAGING is not defined.
51 #define libc_errno LIBC_NAMESPACE::__llvmlibc_internal_errno
53 } // namespace LIBC_NAMESPACE
56 #endif // LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H