mirror of
https://github.com/decompals/wibo.git
synced 2025-12-17 17:05:29 +00:00
Add getThreadId helper using pthread_{gettid,threadid}_np/gettid
This commit is contained in:
@@ -271,6 +271,13 @@ else()
|
||||
endif()
|
||||
install(TARGETS wibo DESTINATION bin)
|
||||
|
||||
# Check for features
|
||||
include(CheckSymbolExists)
|
||||
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
|
||||
set(CMAKE_REQUIRED_LIBRARIES pthread)
|
||||
check_symbol_exists(pthread_gettid_np "pthread.h" HAVE_PTHREAD_GETTID_NP)
|
||||
target_compile_definitions(wibo PRIVATE -DHAVE_PTHREAD_GETTID_NP=${HAVE_PTHREAD_GETTID_NP})
|
||||
|
||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
||||
|
||||
# Track down libclang for trampoline generation.
|
||||
|
||||
@@ -182,7 +182,7 @@ BOOL WINAPI IsProcessorFeaturePresent(DWORD ProcessorFeature) {
|
||||
|
||||
HANDLE WINAPI GetCurrentProcess() {
|
||||
HOST_CONTEXT_GUARD();
|
||||
DEBUG_LOG("GetCurrentProcess() -> %p\n", reinterpret_cast<void *>(static_cast<uintptr_t>(-1)));
|
||||
DEBUG_LOG("GetCurrentProcess() -> %d\n", kPseudoCurrentProcessHandleValue);
|
||||
return kPseudoCurrentProcessHandleValue;
|
||||
}
|
||||
|
||||
@@ -195,12 +195,7 @@ DWORD WINAPI GetCurrentProcessId() {
|
||||
|
||||
DWORD WINAPI GetCurrentThreadId() {
|
||||
HOST_CONTEXT_GUARD();
|
||||
pthread_t thread = pthread_self();
|
||||
#ifdef __linux__
|
||||
const auto threadId = static_cast<DWORD>(thread);
|
||||
#else
|
||||
const auto threadId = static_cast<DWORD>(reinterpret_cast<uintptr_t>(thread));
|
||||
#endif
|
||||
DWORD threadId = wibo::getThreadId();
|
||||
DEBUG_LOG("GetCurrentThreadId() -> %u\n", threadId);
|
||||
return threadId;
|
||||
}
|
||||
|
||||
@@ -36,12 +36,7 @@ void wibo::debug_log(const char *fmt, ...) {
|
||||
if (wibo::debugEnabled) {
|
||||
for (size_t i = 0; i < wibo::debugIndent; i++)
|
||||
fprintf(stderr, "\t");
|
||||
pthread_t threadId = pthread_self();
|
||||
#ifdef __APPLE__
|
||||
fprintf(stderr, "[thread %p] ", threadId);
|
||||
#else
|
||||
fprintf(stderr, "[thread %lu] ", threadId);
|
||||
#endif
|
||||
fprintf(stderr, "[thread %x] ", getThreadId());
|
||||
vfprintf(stderr, fmt, args);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
@@ -55,4 +55,6 @@ int spawnWithArgv(const std::string &applicationName, const std::vector<std::str
|
||||
Pin<kernel32::ProcessObject> &pinOut);
|
||||
std::vector<std::string> splitCommandLine(const char *commandLine);
|
||||
|
||||
DWORD getThreadId();
|
||||
|
||||
} // namespace wibo
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
extern char **environ;
|
||||
#endif
|
||||
|
||||
using kernel32::ProcessObject;
|
||||
|
||||
@@ -46,9 +50,7 @@ bool ProcessManager::addProcess(Pin<ProcessObject> po) {
|
||||
return mImpl->addProcess(std::move(po));
|
||||
}
|
||||
|
||||
bool ProcessManager::running() const {
|
||||
return mImpl && mImpl->running();
|
||||
}
|
||||
bool ProcessManager::running() const { return mImpl && mImpl->running(); }
|
||||
|
||||
ProcessManager &processes() {
|
||||
static ProcessManager mgr;
|
||||
@@ -350,5 +352,18 @@ std::vector<std::string> splitCommandLine(const char *commandLine) {
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace wibo
|
||||
DWORD getThreadId() {
|
||||
#if HAVE_PTHREAD_GETTID_NP
|
||||
pid_t threadId = pthread_gettid_np(pthread_self());
|
||||
#elif defined(__linux__)
|
||||
pid_t threadId = gettid();
|
||||
#elif defined(__APPLE__)
|
||||
uint64_t threadId = 0;
|
||||
pthread_threadid_np(nullptr, &threadId);
|
||||
#else
|
||||
#error "Unknown platform"
|
||||
#endif
|
||||
return static_cast<DWORD>(threadId);
|
||||
}
|
||||
|
||||
} // namespace wibo
|
||||
|
||||
Reference in New Issue
Block a user