brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 11ac6ee Raw
96 lines · c
1//===-- Classes to capture properites of linux applications -----*- 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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_CONFIG_LINUX_APP_H10#define LLVM_LIBC_CONFIG_LINUX_APP_H11 12#include "hdr/stdint_proxy.h"13#include "src/__support/macros/config.h"14#include "src/__support/macros/properties/architectures.h"15 16namespace LIBC_NAMESPACE_DECL {17 18// Data structure to capture properties of the linux/ELF TLS image.19struct TLSImage {20  // The load address of the TLS.21  uintptr_t address;22 23  // The byte size of the TLS image consisting of both initialized and24  // uninitialized memory. In ELF executables, it is size of .tdata + size of25  // .tbss. Put in another way, it is the memsz field of the PT_TLS header.26  uintptr_t size;27 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 the30  // PT_TLS header.31  uintptr_t init_size;32 33  // The alignment of the TLS layout. It assumed that the alignment34  // value is a power of 2.35  uintptr_t align;36};37 38struct Args {39  uintptr_t argc;40 41  // A flexible length array would be more suitable here, but C++ doesn't have42  // flexible arrays: P1039 proposes to fix this. So, for now we just fake it.43  // Even if argc is zero, "argv[argc] shall be a null pointer"44  // (ISO C 5.1.2.2.1) so one is fine. Also, length of 1 is not really wrong as45  // |argc| is guaranteed to be atleast 1, and there is an 8-byte null entry at46  // the end of the argv array.47  uintptr_t argv[1];48};49 50// Data structure which captures properties of a linux application.51struct AppProperties {52  // Page size used for the application.53  uintptr_t page_size;54 55  Args *args;56 57  // The properties of an application's TLS image.58  TLSImage tls;59 60  // Environment data.61  uintptr_t *env_ptr;62};63 64[[gnu::weak]] extern AppProperties app;65 66// The descriptor of a thread's TLS area.67struct TLSDescriptor {68  // The size of the TLS area.69  uintptr_t size = 0;70 71  // The address of the TLS area. This address can be passed to cleanup72  // functions like munmap.73  uintptr_t addr = 0;74 75  // The value the thread pointer register should be initialized to.76  // Note that, dependending the target architecture ABI, it can be the77  // same as |addr| or something else.78  uintptr_t tp = 0;79 80  constexpr TLSDescriptor() = default;81};82 83// Create and initialize the TLS area for the current thread. Should not84// be called before app.tls has been initialized.85void init_tls(TLSDescriptor &tls);86 87// Cleanup the TLS area as described in |tls_descriptor|.88void cleanup_tls(uintptr_t tls_addr, uintptr_t tls_size);89 90// Set the thread pointer for the current thread.91bool set_thread_ptr(uintptr_t val);92 93} // namespace LIBC_NAMESPACE_DECL94 95#endif // LLVM_LIBC_CONFIG_LINUX_APP_H96