CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
64 lines
2.2 KiB
C++
64 lines
2.2 KiB
C++
//===-- Implementation of tls for riscv -----------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "hdr/sys_mman_macros.h"
|
|
#include "src/__support/OSUtil/linux/syscall_wrappers/mmap.h"
|
|
#include "src/__support/OSUtil/linux/syscall_wrappers/munmap.h"
|
|
#include "src/__support/OSUtil/syscall.h"
|
|
#include "src/__support/macros/config.h"
|
|
#include "src/__support/threads/thread.h"
|
|
#include "src/string/memory_utils/inline_memcpy.h"
|
|
#include "startup/linux/do_start.h"
|
|
#include <sys/syscall.h>
|
|
|
|
namespace LIBC_NAMESPACE_DECL {
|
|
|
|
void init_tls(TLSDescriptor &tls_descriptor) {
|
|
if (app.tls.size == 0) {
|
|
tls_descriptor.size = 0;
|
|
tls_descriptor.tp = 0;
|
|
return;
|
|
}
|
|
|
|
// riscv64 follows the variant 1 TLS layout:
|
|
const uintptr_t size_of_pointers = 2 * sizeof(uintptr_t);
|
|
uintptr_t padding = 0;
|
|
const uintptr_t ALIGNMENT_MASK = app.tls.align - 1;
|
|
uintptr_t diff = size_of_pointers & ALIGNMENT_MASK;
|
|
if (diff != 0)
|
|
padding += (ALIGNMENT_MASK - diff) + 1;
|
|
|
|
uintptr_t alloc_size = size_of_pointers + padding + app.tls.size;
|
|
|
|
ErrorOr<void *> mmap_ret =
|
|
linux_syscalls::mmap(nullptr, alloc_size, PROT_READ | PROT_WRITE,
|
|
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
|
|
if (!mmap_ret.has_value())
|
|
syscall_impl<long>(SYS_exit, 1);
|
|
uintptr_t thread_ptr = uintptr_t(mmap_ret.value());
|
|
uintptr_t tls_addr = thread_ptr + size_of_pointers + padding;
|
|
inline_memcpy(reinterpret_cast<char *>(tls_addr),
|
|
reinterpret_cast<const char *>(app.tls.address),
|
|
app.tls.init_size);
|
|
tls_descriptor.size = alloc_size;
|
|
tls_descriptor.addr = thread_ptr;
|
|
tls_descriptor.tp = tls_addr;
|
|
}
|
|
|
|
void cleanup_tls(uintptr_t addr, uintptr_t size) {
|
|
if (size == 0)
|
|
return;
|
|
linux_syscalls::munmap(reinterpret_cast<void *>(addr), size);
|
|
}
|
|
|
|
bool set_thread_ptr(uintptr_t val) {
|
|
LIBC_INLINE_ASM("mv tp, %0\n\t" : : "r"(val));
|
|
return true;
|
|
}
|
|
} // namespace LIBC_NAMESPACE_DECL
|