annotate libc/config/linux/app.h @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1f2b6ac9f198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 //===-- Classes to capture properites of linux applications -----*- C++ -*-===//
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #ifndef LLVM_LIBC_CONFIG_LINUX_APP_H
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #define LLVM_LIBC_CONFIG_LINUX_APP_H
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
12 #include "src/__support/macros/properties/architectures.h"
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
13
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include <stdint.h>
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 namespace __llvm_libc {
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
18 // Data structure to capture properties of the linux/ELF TLS image.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
19 struct TLSImage {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 // The load address of the TLS.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 uintptr_t address;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
23 // The byte size of the TLS image consisting of both initialized and
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
24 // uninitialized memory. In ELF executables, it is size of .tdata + size of
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
25 // .tbss. Put in another way, it is the memsz field of the PT_TLS header.
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 uintptr_t size;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
28 // The byte size of initialized memory in the TLS image. In ELF exectubles,
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
29 // this is the size of .tdata. Put in another way, it is the filesz of the
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
30 // PT_TLS header.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
31 uintptr_t init_size;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
32
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 // The alignment of the TLS layout. It assumed that the alignment
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 // value is a power of 2.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 uintptr_t align;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 };
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
38 #if defined(LIBC_TARGET_ARCH_IS_X86_64) || \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
39 defined(LIBC_TARGET_ARCH_IS_AARCH64) || \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
40 defined(LIBC_TARGET_ARCH_IS_RISCV64)
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
41 // At the language level, argc is an int. But we use uint64_t as the x86_64
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
42 // ABI specifies it as an 8 byte value. Likewise, in the ARM64 ABI, arguments
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
43 // are usually passed in registers. x0 is a doubleword register, so this is
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
44 // 64 bit for aarch64 as well.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
45 typedef uint64_t ArgcType;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
46
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
47 // At the language level, argv is a char** value. However, we use uint64_t as
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
48 // ABIs specify the argv vector be an |argc| long array of 8-byte values.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
49 typedef uint64_t ArgVEntryType;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
50 #else
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
51 #error "argc and argv types are not defined for the target platform."
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
52 #endif
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
53
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
54 struct Args {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
55 ArgcType argc;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
56
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
57 // A flexible length array would be more suitable here, but C++ doesn't have
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
58 // flexible arrays: P1039 proposes to fix this. So, for now we just fake it.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
59 // Even if argc is zero, "argv[argc] shall be a null pointer"
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
60 // (ISO C 5.1.2.2.1) so one is fine. Also, length of 1 is not really wrong as
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
61 // |argc| is guaranteed to be atleast 1, and there is an 8-byte null entry at
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
62 // the end of the argv array.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
63 ArgVEntryType argv[1];
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
64 };
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
65
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 // Data structure which captures properties of a linux application.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 struct AppProperties {
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 // Page size used for the application.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 uintptr_t pageSize;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
71 Args *args;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
72
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
73 // The properties of an application's TLS image.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
74 TLSImage tls;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
75
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
76 // Environment data.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
77 uint64_t *envPtr;
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 };
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
80 extern AppProperties app;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
81
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
82 // The descriptor of a thread's TLS area.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
83 struct TLSDescriptor {
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
84 // The size of the TLS area.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
85 uintptr_t size = 0;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
86
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
87 // The address of the TLS area. This address can be passed to cleanup
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
88 // functions like munmap.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
89 uintptr_t addr = 0;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
90
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
91 // The value the thread pointer register should be initialized to.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
92 // Note that, dependending the target architecture ABI, it can be the
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
93 // same as |addr| or something else.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
94 uintptr_t tp = 0;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
95
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
96 constexpr TLSDescriptor() = default;
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
97 };
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
98
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
99 // Create and initialize the TLS area for the current thread. Should not
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 // be called before app.tls has been initialized.
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
101 void init_tls(TLSDescriptor &tls);
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
102
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
103 // Cleanup the TLS area as described in |tls_descriptor|.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
104 void cleanup_tls(uintptr_t tls_addr, uintptr_t tls_size);
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 } // namespace __llvm_libc
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 #endif // LLVM_LIBC_CONFIG_LINUX_APP_H