1010#include " Error.h"
1111#include " llvm/Support/Error.h"
1212#include " llvm/Support/FormatVariadic.h"
13- #include " llvm/Support/Threading.h"
1413#include < cerrno>
1514
1615#ifdef __linux__
@@ -25,14 +24,21 @@ namespace exegesis {
2524
2625#if defined(__linux__) && !defined(__ANDROID__)
2726
27+ long SubprocessMemory::getCurrentTID () {
28+ // We're using the raw syscall here rather than the gettid() function provided
29+ // by most libcs for compatibility as gettid() was only added to glibc in
30+ // version 2.30.
31+ return syscall (SYS_gettid);
32+ }
33+
2834Error SubprocessMemory::initializeSubprocessMemory (pid_t ProcessID) {
2935 // Add the PID to the shared memory name so that if we're running multiple
3036 // processes at the same time, they won't interfere with each other.
3137 // This comes up particularly often when running the exegesis tests with
3238 // llvm-lit. Additionally add the TID so that downstream consumers
3339 // using multiple threads don't run into conflicts.
3440 std::string AuxiliaryMemoryName =
35- formatv (" /{0}auxmem{1}" , get_threadid (), ProcessID);
41+ formatv (" /{0}auxmem{1}" , getCurrentTID (), ProcessID);
3642 int AuxiliaryMemoryFD = shm_open (AuxiliaryMemoryName.c_str (),
3743 O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
3844 if (AuxiliaryMemoryFD == -1 )
@@ -53,7 +59,7 @@ Error SubprocessMemory::addMemoryDefinition(
5359 SharedMemoryNames.reserve (MemoryDefinitions.size ());
5460 for (auto &[Name, MemVal] : MemoryDefinitions) {
5561 std::string SharedMemoryName =
56- formatv (" /{0}t{1}memdef{2}" , ProcessPID, get_threadid (), MemVal.Index );
62+ formatv (" /{0}t{1}memdef{2}" , ProcessPID, getCurrentTID (), MemVal.Index );
5763 SharedMemoryNames.push_back (SharedMemoryName);
5864 int SharedMemoryFD =
5965 shm_open (SharedMemoryName.c_str (), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
@@ -87,7 +93,7 @@ Error SubprocessMemory::addMemoryDefinition(
8793
8894Expected<int > SubprocessMemory::setupAuxiliaryMemoryInSubprocess (
8995 std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
90- pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor) {
96+ pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
9197 std::string AuxiliaryMemoryName =
9298 formatv (" /{0}auxmem{1}" , ParentTID, ParentPID);
9399 int AuxiliaryMemoryFileDescriptor =
@@ -139,7 +145,7 @@ Error SubprocessMemory::addMemoryDefinition(
139145
140146Expected<int > SubprocessMemory::setupAuxiliaryMemoryInSubprocess (
141147 std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
142- pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor) {
148+ pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
143149 return make_error<Failure>(
144150 " setupAuxiliaryMemoryInSubprocess is only supported on Linux" );
145151}
0 commit comments