Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions libc/src/__support/OSUtil/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ add_object_library(
libc.src.__support.CPP.string_view
libc.src.__support.threads.callonce
libc.src.__support.threads.linux.futex_word_type
libc.src.__support.OSUtil.linux.auxv
libc.hdr.types.struct_timeval
libc.hdr.types.struct_timespec
libc.hdr.types.clockid_t
libc.hdr.types.time_t
libc.hdr.link_macros
libc.src.errno.errno
libc.src.sys.auxv.getauxval
)
13 changes: 4 additions & 9 deletions libc/src/__support/OSUtil/linux/vdso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
#include "src/__support/CPP/array.h"
#include "src/__support/CPP/optional.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/libc_errno.h"
#include "src/__support/OSUtil/linux/auxv.h"
#include "src/__support/threads/callonce.h"
#include "src/__support/threads/linux/futex_word.h"
#include "src/sys/auxv/getauxval.h"
#include <linux/auxvec.h>

// TODO: This is a temporary workaround to avoid including elf.h
Expand Down Expand Up @@ -189,17 +188,13 @@ void Symbol::initialize_vdso_global_cache() {
for (auto &i : global_cache)
i = nullptr;

// get the address of the VDSO, protect errno since getauxval may change
// it
int errno_backup = libc_errno;
uintptr_t vdso_ehdr_addr = getauxval(AT_SYSINFO_EHDR);
cpp::optional<unsigned long> auxv_res = auxv::get(AT_SYSINFO_EHDR);
uintptr_t vdso_ehdr_addr = auxv_res ? static_cast<uintptr_t>(*auxv_res) : 0;
// Get the memory address of the vDSO ELF header.
auto vdso_ehdr = reinterpret_cast<ElfW(Ehdr) *>(vdso_ehdr_addr);
// leave the table unpopulated if we don't have vDSO
if (vdso_ehdr == nullptr) {
libc_errno = errno_backup;
if (vdso_ehdr == nullptr)
return;
}

// locate the section header inside the elf using the section header
// offset
Expand Down
4 changes: 2 additions & 2 deletions libc/src/unistd/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ add_entrypoint_object(
DEPENDS
libc.include.unistd
libc.include.sys_auxv
libc.src.errno.errno
libc.src.sys.auxv.getauxval
libc.src.__support.libc_errno
libc.src.__support.OSUtil.linux.auxv
)

add_entrypoint_object(
Expand Down
11 changes: 7 additions & 4 deletions libc/src/unistd/linux/sysconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
#include "src/__support/common.h"

#include "hdr/unistd_macros.h"
#include "src/__support/OSUtil/linux/auxv.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/sys/auxv/getauxval.h"
#include <sys/auxv.h>

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(long, sysconf, (int name)) {
long ret = 0;
if (name == _SC_PAGESIZE)
return static_cast<long>(getauxval(AT_PAGESZ));
if (name == _SC_PAGESIZE) {
cpp::optional<unsigned long> page_size = auxv::get(AT_PAGESZ);
if (page_size)
return static_cast<long>(*page_size);
ret = -1;
}

// TODO: Complete the rest of the sysconf options.
if (ret < 0) {
Expand Down
Loading