Raman Tenneti f2a7f83595 Introduce getenv to LLVM libc
Add support for getenv as defined by the Open Group's "System Interface &
 Header" in https://pubs.opengroup.org/onlinepubs/7908799/xsh/getenv.html

getenv requires a standard way of accessing the environment,
so a pointer to the environment is added to the startup in crt1.
Consquently, this function is not usable on top of other libcs.

Added starts_with method to StringView. getenv function uses it.

Co-authored-by: Jeff Bailey <jeffbailey@google.com>

Reviewed By: sivachandra, rtenneti

Differential Revision: https://reviews.llvm.org/D119403
2022-02-14 10:10:13 -08:00

50 lines
1.3 KiB
C++

//===-- Classes to capture properites of linux applications -----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_CONFIG_LINUX_APP_H
#define LLVM_LIBC_CONFIG_LINUX_APP_H
#include <stdint.h>
namespace __llvm_libc {
// Data structure to capture properties of the linux/ELF TLS.
struct TLS {
// The load address of the TLS.
uintptr_t address;
// The bytes size of the TLS.
uintptr_t size;
// The alignment of the TLS layout. It assumed that the alignment
// value is a power of 2.
uintptr_t align;
};
// Data structure which captures properties of a linux application.
struct AppProperties {
// Page size used for the application.
uintptr_t pageSize;
// The properties of an application's TLS.
TLS tls;
// Environment data.
uint64_t *envPtr;
};
extern AppProperties app;
// Creates and initializes the TLS area for the current thread. Should not
// be called before app.tls has been initialized.
void initTLS();
} // namespace __llvm_libc
#endif // LLVM_LIBC_CONFIG_LINUX_APP_H