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/config.h"
13 #include "src/__support/macros/properties/architectures.h"
17 namespace LIBC_NAMESPACE_DECL
{
19 // Data structure to capture properties of the linux/ELF TLS image.
21 // The load address of the TLS.
24 // The byte size of the TLS image consisting of both initialized and
25 // uninitialized memory. In ELF executables, it is size of .tdata + size of
26 // .tbss. Put in another way, it is the memsz field of the PT_TLS header.
29 // The byte size of initialized memory in the TLS image. In ELF exectubles,
30 // this is the size of .tdata. Put in another way, it is the filesz of the
34 // The alignment of the TLS layout. It assumed that the alignment
35 // value is a power of 2.
39 // Linux manpage on `proc(5)` says that the aux vector is an array of
40 // unsigned long pairs.
41 // (see: https://man7.org/linux/man-pages/man5/proc.5.html)
42 using AuxEntryType
= unsigned long;
43 // Using the naming convention from `proc(5)`.
44 // TODO: Would be nice to use the aux entry structure from elf.h when available.
53 // A flexible length array would be more suitable here, but C++ doesn't have
54 // flexible arrays: P1039 proposes to fix this. So, for now we just fake it.
55 // Even if argc is zero, "argv[argc] shall be a null pointer"
56 // (ISO C 5.1.2.2.1) so one is fine. Also, length of 1 is not really wrong as
57 // |argc| is guaranteed to be atleast 1, and there is an 8-byte null entry at
58 // the end of the argv array.
62 // Data structure which captures properties of a linux application.
63 struct AppProperties
{
64 // Page size used for the application.
69 // The properties of an application's TLS image.
75 // Auxiliary vector data.
79 [[gnu::weak
]] extern AppProperties app
;
81 // The descriptor of a thread's TLS area.
82 struct TLSDescriptor
{
83 // The size of the TLS area.
86 // The address of the TLS area. This address can be passed to cleanup
87 // functions like munmap.
90 // The value the thread pointer register should be initialized to.
91 // Note that, dependending the target architecture ABI, it can be the
92 // same as |addr| or something else.
95 constexpr TLSDescriptor() = default;
98 // Create and initialize the TLS area for the current thread. Should not
99 // be called before app.tls has been initialized.
100 void init_tls(TLSDescriptor
&tls
);
102 // Cleanup the TLS area as described in |tls_descriptor|.
103 void cleanup_tls(uintptr_t tls_addr
, uintptr_t tls_size
);
105 // Set the thread pointer for the current thread.
106 bool set_thread_ptr(uintptr_t val
);
108 } // namespace LIBC_NAMESPACE_DECL
110 #endif // LLVM_LIBC_CONFIG_LINUX_APP_H