#include "src/__support/threads/thread.h"
#include "config/app.h"
#include "src/__support/CPP/atomic.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/CPP/stringstream.h"
#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include "src/__support/threads/linux/futex_utils.h"
#include "src/errno/libc_errno.h"
#ifdef LIBC_TARGET_ARCH_IS_AARCH64
#include <arm_acle.h>
#endif
#include <fcntl.h>
#include <linux/param.h>
#include <linux/prctl.h>
#include <linux/sched.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/syscall.h>
namespace LIBC_NAMESPACE_DECL {
#ifdef SYS_mmap2
static constexpr long MMAP_SYSCALL_NUMBER = SYS_mmap2;
#elif defined(SYS_mmap)
static constexpr long MMAP_SYSCALL_NUMBER = …;
#else
#error "mmap or mmap2 syscalls not available."
#endif
static constexpr size_t NAME_SIZE_MAX = …;
static constexpr uint32_t CLEAR_TID_VALUE = …;
static constexpr unsigned CLONE_SYSCALL_FLAGS = …;
#ifdef LIBC_TARGET_ARCH_IS_AARCH64
#define CLONE_RESULT_REGISTER …
#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
#define CLONE_RESULT_REGISTER …
#elif defined(LIBC_TARGET_ARCH_IS_X86_64)
#define CLONE_RESULT_REGISTER …
#else
#error "CLONE_RESULT_REGISTER not defined for your target architecture"
#endif
static constexpr ErrorOr<size_t> add_no_overflow(size_t lhs, size_t rhs) { … }
static constexpr ErrorOr<size_t> round_to_page(size_t v) { … }
LIBC_INLINE ErrorOr<void *> alloc_stack(size_t stacksize, size_t guardsize) { … }
[[gnu::always_inline]] LIBC_INLINE void
free_stack(void *stack, size_t stacksize, size_t guardsize) { … }
struct Thread;
struct alignas(STACK_ALIGNMENT) StartArgs { … };
[[gnu::always_inline]] LIBC_INLINE void
cleanup_thread_resources(ThreadAttributes *attrib) { … }
[[gnu::always_inline]] LIBC_INLINE uintptr_t get_start_args_addr() { … }
[[gnu::noinline]] void start_thread() { … }
int Thread::run(ThreadStyle style, ThreadRunner runner, void *arg, void *stack,
size_t stacksize, size_t guardsize, bool detached) { … }
int Thread::join(ThreadReturnValue &retval) { … }
int Thread::detach() { … }
void Thread::wait() { … }
bool Thread::operator==(const Thread &thread) const { … }
static constexpr cpp::string_view THREAD_NAME_PATH_PREFIX("/proc/self/task/");
static constexpr size_t THREAD_NAME_PATH_SIZE = …;
static void construct_thread_name_file_path(cpp::StringStream &stream,
int tid) { … }
int Thread::set_name(const cpp::string_view &name) { … }
int Thread::get_name(cpp::StringStream &name) const { … }
void thread_exit(ThreadReturnValue retval, ThreadStyle style) { … }
}