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