10
10
#include " Error.h"
11
11
#include " llvm/Support/Error.h"
12
12
#include " llvm/Support/FormatVariadic.h"
13
- #include " llvm/Support/Threading.h"
14
13
#include < cerrno>
15
14
16
15
#ifdef __linux__
@@ -25,14 +24,21 @@ namespace exegesis {
25
24
26
25
#if defined(__linux__) && !defined(__ANDROID__)
27
26
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
+
28
34
Error SubprocessMemory::initializeSubprocessMemory (pid_t ProcessID) {
29
35
// Add the PID to the shared memory name so that if we're running multiple
30
36
// processes at the same time, they won't interfere with each other.
31
37
// This comes up particularly often when running the exegesis tests with
32
38
// llvm-lit. Additionally add the TID so that downstream consumers
33
39
// using multiple threads don't run into conflicts.
34
40
std::string AuxiliaryMemoryName =
35
- formatv (" /{0}auxmem{1}" , get_threadid (), ProcessID);
41
+ formatv (" /{0}auxmem{1}" , getCurrentTID (), ProcessID);
36
42
int AuxiliaryMemoryFD = shm_open (AuxiliaryMemoryName.c_str (),
37
43
O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
38
44
if (AuxiliaryMemoryFD == -1 )
@@ -53,7 +59,7 @@ Error SubprocessMemory::addMemoryDefinition(
53
59
SharedMemoryNames.reserve (MemoryDefinitions.size ());
54
60
for (auto &[Name, MemVal] : MemoryDefinitions) {
55
61
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 );
57
63
SharedMemoryNames.push_back (SharedMemoryName);
58
64
int SharedMemoryFD =
59
65
shm_open (SharedMemoryName.c_str (), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
@@ -87,7 +93,7 @@ Error SubprocessMemory::addMemoryDefinition(
87
93
88
94
Expected<int > SubprocessMemory::setupAuxiliaryMemoryInSubprocess (
89
95
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
90
- pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor) {
96
+ pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
91
97
std::string AuxiliaryMemoryName =
92
98
formatv (" /{0}auxmem{1}" , ParentTID, ParentPID);
93
99
int AuxiliaryMemoryFileDescriptor =
@@ -139,7 +145,7 @@ Error SubprocessMemory::addMemoryDefinition(
139
145
140
146
Expected<int > SubprocessMemory::setupAuxiliaryMemoryInSubprocess (
141
147
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
142
- pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor) {
148
+ pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
143
149
return make_error<Failure>(
144
150
" setupAuxiliaryMemoryInSubprocess is only supported on Linux" );
145
151
}
0 commit comments