1 //===-- Classes to capture properites of linux applications -----*- 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_CONFIG_LINUX_APP_H
10 #define LLVM_LIBC_CONFIG_LINUX_APP_H
12 #include "src/__support/macros/properties/architectures.h"
16 namespace __llvm_libc
{
18 // Data structure to capture properties of the linux/ELF TLS image.
20 // The load address of the TLS.
23 // The byte size of the TLS image consisting of both initialized and
24 // uninitialized memory. In ELF executables, it is size of .tdata + size of
25 // .tbss. Put in another way, it is the memsz field of the PT_TLS header.
28 // The byte size of initialized memory in the TLS image. In ELF exectubles,
29 // this is the size of .tdata. Put in another way, it is the filesz of the
33 // The alignment of the TLS layout. It assumed that the alignment
34 // value is a power of 2.
38 #if defined(LIBC_TARGET_ARCH_IS_X86_64) || \
39 defined(LIBC_TARGET_ARCH_IS_AARCH64) || \
40 defined(LIBC_TARGET_ARCH_IS_RISCV64)
41 // At the language level, argc is an int. But we use uint64_t as the x86_64
42 // ABI specifies it as an 8 byte value. Likewise, in the ARM64 ABI, arguments
43 // are usually passed in registers. x0 is a doubleword register, so this is
44 // 64 bit for aarch64 as well.
45 typedef uintptr_t ArgcType
;
47 // At the language level, argv is a char** value. However, we use uint64_t as
48 // ABIs specify the argv vector be an |argc| long array of 8-byte values.
49 typedef uintptr_t ArgVEntryType
;
51 typedef uintptr_t EnvironType
;
52 typedef uintptr_t AuxEntryType
;
54 #error "argc and argv types are not defined for the target platform."
60 // A flexible length array would be more suitable here, but C++ doesn't have
61 // flexible arrays: P1039 proposes to fix this. So, for now we just fake it.
62 // Even if argc is zero, "argv[argc] shall be a null pointer"
63 // (ISO C 5.1.2.2.1) so one is fine. Also, length of 1 is not really wrong as
64 // |argc| is guaranteed to be atleast 1, and there is an 8-byte null entry at
65 // the end of the argv array.
66 ArgVEntryType argv
[1];
69 // Data structure which captures properties of a linux application.
70 struct AppProperties
{
71 // Page size used for the application.
76 // The properties of an application's TLS image.
83 extern AppProperties app
;
85 // The descriptor of a thread's TLS area.
86 struct TLSDescriptor
{
87 // The size of the TLS area.
90 // The address of the TLS area. This address can be passed to cleanup
91 // functions like munmap.
94 // The value the thread pointer register should be initialized to.
95 // Note that, dependending the target architecture ABI, it can be the
96 // same as |addr| or something else.
99 constexpr TLSDescriptor() = default;
102 // Create and initialize the TLS area for the current thread. Should not
103 // be called before app.tls has been initialized.
104 void init_tls(TLSDescriptor
&tls
);
106 // Cleanup the TLS area as described in |tls_descriptor|.
107 void cleanup_tls(uintptr_t tls_addr
, uintptr_t tls_size
);
109 } // namespace __llvm_libc
111 #endif // LLVM_LIBC_CONFIG_LINUX_APP_H