android stuff

This commit is contained in:
DH 2025-02-24 01:21:21 +03:00 committed by Megamouse
parent 11e214f332
commit 798c194025
11 changed files with 304 additions and 236 deletions

View file

@ -1997,7 +1997,7 @@ static void signal_handler(int /*sig*/, siginfo_t* info, void* uct) noexcept
#else
const u32 insn = is_executing ? 0 : *reinterpret_cast<u32*>(RIP(context));
const bool is_writing =
const bool is_writing =
(insn & 0xbfff0000) == 0x0c000000 || // STR <Wt>, [<Xn>, #<imm>] (store word with immediate offset)
(insn & 0xbfe00000) == 0x0c800000 || // STP <Wt1>, <Wt2>, [<Xn>, #<imm>] (store pair of registers with immediate offset)
(insn & 0xbfdf0000) == 0x0d000000 || // STR <Wt>, [<Xn>, <Xm>] (store word with register offset)
@ -2172,7 +2172,11 @@ void thread_base::start()
void thread_base::initialize(void (*error_cb)())
{
#ifndef _WIN32
#ifdef ANDROID
m_thread.release(pthread_self());
#else
m_thread.release(reinterpret_cast<u64>(pthread_self()));
#endif
#endif
// Initialize TLS variables
@ -2617,6 +2621,8 @@ thread_base::~thread_base() noexcept
const HANDLE handle0 = reinterpret_cast<HANDLE>(m_thread.load());
WaitForSingleObject(handle0, INFINITE);
CloseHandle(handle0);
#elif defined(ANDROID)
pthread_join(m_thread.load(), nullptr);
#else
pthread_join(reinterpret_cast<pthread_t>(m_thread.load()), nullptr);
#endif
@ -2691,7 +2697,13 @@ u64 thread_base::get_cycles()
#else
clockid_t _clock;
struct timespec thread_time;
if (!pthread_getcpuclockid(reinterpret_cast<pthread_t>(handle), &_clock) && !clock_gettime(_clock, &thread_time))
pthread_t thread_id;
#ifdef ANDROID
thread_id = handle;
#else
thread_id = reinterpret_cast<pthread_t>(handle);
#endif
if (!pthread_getcpuclockid(thread_id, &_clock) && !clock_gettime(_clock, &thread_time))
{
cycles = static_cast<u64>(thread_time.tv_sec) * 1'000'000'000 + thread_time.tv_nsec;
#endif
@ -3194,7 +3206,7 @@ void thread_ctrl::set_thread_affinity_mask(u64 mask)
thread_affinity_policy_data_t policy = { static_cast<integer_t>(std::countr_zero(mask)) };
thread_port_t mach_thread = pthread_mach_thread_np(pthread_self());
thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, reinterpret_cast<thread_policy_t>(&policy), !mask ? 0 : 1);
#elif defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__)
#elif !defined(ANDROID) && (defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__))
if (!mask)
{
// Reset affinity mask
@ -3246,7 +3258,7 @@ u64 thread_ctrl::get_thread_affinity_mask()
sig_log.error("Failed to get thread affinity mask.");
return 0;
#elif defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__)
#elif !defined(ANDROID) && (defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__))
cpu_set_t cs;
CPU_ZERO(&cs);
@ -3313,6 +3325,8 @@ u64 thread_ctrl::get_tid()
{
#ifdef _WIN32
return GetCurrentThreadId();
#elif defined(ANDROID)
return static_cast<u64>(pthread_self());
#elif defined(__linux__)
return syscall(SYS_gettid);
#else

View file

@ -126,15 +126,17 @@ namespace utils
std::vector<void*> get_backtrace(int max_depth)
{
std::vector<void*> result(max_depth);
#ifndef ANDROID
int depth = backtrace(result.data(), max_depth);
result.resize(depth);
#endif
return result;
}
std::vector<std::string> get_backtrace_symbols(const std::vector<void*>& stack)
{
std::vector<std::string> result;
#ifndef ANDROID
result.reserve(stack.size());
const auto symbols = backtrace_symbols(stack.data(), static_cast<int>(stack.size()));
@ -144,6 +146,7 @@ namespace utils
}
free(symbols);
#endif
return result;
}
#endif