9
9
#include " SubprocessMemory.h"
10
10
#include " Error.h"
11
11
#include " llvm/Support/Error.h"
12
- #include " llvm/Support/FormatVariadic.h"
13
12
#include < cerrno>
14
13
15
14
#ifdef __linux__
16
15
#include < fcntl.h>
17
16
#include < sys/mman.h>
18
- #include < sys/syscall.h>
19
17
#include < unistd.h>
20
18
#endif
21
19
@@ -24,21 +22,12 @@ namespace exegesis {
24
22
25
23
#if defined(__linux__) && !defined(__ANDROID__)
26
24
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
25
Error SubprocessMemory::initializeSubprocessMemory (pid_t ProcessID) {
35
26
// Add the PID to the shared memory name so that if we're running multiple
36
27
// processes at the same time, they won't interfere with each other.
37
28
// This comes up particularly often when running the exegesis tests with
38
- // llvm-lit. Additionally add the TID so that downstream consumers
39
- // using multiple threads don't run into conflicts.
40
- std::string AuxiliaryMemoryName =
41
- formatv (" /{0}auxmem{1}" , getCurrentTID (), ProcessID);
29
+ // llvm-lit
30
+ std::string AuxiliaryMemoryName = " /auxmem" + std::to_string (ProcessID);
42
31
int AuxiliaryMemoryFD = shm_open (AuxiliaryMemoryName.c_str (),
43
32
O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
44
33
if (AuxiliaryMemoryFD == -1 )
@@ -58,8 +47,8 @@ Error SubprocessMemory::addMemoryDefinition(
58
47
pid_t ProcessPID) {
59
48
SharedMemoryNames.reserve (MemoryDefinitions.size ());
60
49
for (auto &[Name, MemVal] : MemoryDefinitions) {
61
- std::string SharedMemoryName =
62
- formatv ( " /{0}t{1}memdef{2} " , ProcessPID, getCurrentTID (), MemVal.Index );
50
+ std::string SharedMemoryName = " / " + std::to_string (ProcessPID) + " memdef " +
51
+ std::to_string ( MemVal.Index );
63
52
SharedMemoryNames.push_back (SharedMemoryName);
64
53
int SharedMemoryFD =
65
54
shm_open (SharedMemoryName.c_str (), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
@@ -93,9 +82,8 @@ Error SubprocessMemory::addMemoryDefinition(
93
82
94
83
Expected<int > SubprocessMemory::setupAuxiliaryMemoryInSubprocess (
95
84
std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
96
- pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
97
- std::string AuxiliaryMemoryName =
98
- formatv (" /{0}auxmem{1}" , ParentTID, ParentPID);
85
+ pid_t ParentPID, int CounterFileDescriptor) {
86
+ std::string AuxiliaryMemoryName = " /auxmem" + std::to_string (ParentPID);
99
87
int AuxiliaryMemoryFileDescriptor =
100
88
shm_open (AuxiliaryMemoryName.c_str (), O_RDWR, S_IRUSR | S_IWUSR);
101
89
if (AuxiliaryMemoryFileDescriptor == -1 )
@@ -109,8 +97,8 @@ Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
109
97
return make_error<Failure>(" Mapping auxiliary memory failed" );
110
98
AuxiliaryMemoryMapping[0 ] = CounterFileDescriptor;
111
99
for (auto &[Name, MemVal] : MemoryDefinitions) {
112
- std::string MemoryValueName =
113
- formatv ( " /{0}t{1}memdef{2} " , ParentPID, ParentTID, MemVal.Index );
100
+ std::string MemoryValueName = " / " + std::to_string (ParentPID) + " memdef " +
101
+ std::to_string ( MemVal.Index );
114
102
AuxiliaryMemoryMapping[AuxiliaryMemoryOffset + MemVal.Index ] =
115
103
shm_open (MemoryValueName.c_str (), O_RDWR, S_IRUSR | S_IWUSR);
116
104
if (AuxiliaryMemoryMapping[AuxiliaryMemoryOffset + MemVal.Index ] == -1 )
0 commit comments