99#include " SubprocessMemory.h"
1010#include " Error.h"
1111#include " llvm/Support/Error.h"
12- #include " llvm/Support/FormatVariadic.h"
1312#include < cerrno>
1413
1514#ifdef __linux__
1615#include < fcntl.h>
1716#include < sys/mman.h>
18- #include < sys/syscall.h>
1917#include < unistd.h>
2018#endif
2119
@@ -24,21 +22,12 @@ namespace exegesis {
2422
2523#if defined(__linux__) && !defined(__ANDROID__)
2624
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-
3425Error SubprocessMemory::initializeSubprocessMemory (pid_t ProcessID) {
3526 // Add the PID to the shared memory name so that if we're running multiple
3627 // processes at the same time, they won't interfere with each other.
3728 // 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);
4231 int AuxiliaryMemoryFD = shm_open (AuxiliaryMemoryName.c_str (),
4332 O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
4433 if (AuxiliaryMemoryFD == -1 )
@@ -58,8 +47,8 @@ Error SubprocessMemory::addMemoryDefinition(
5847 pid_t ProcessPID) {
5948 SharedMemoryNames.reserve (MemoryDefinitions.size ());
6049 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 );
6352 SharedMemoryNames.push_back (SharedMemoryName);
6453 int SharedMemoryFD =
6554 shm_open (SharedMemoryName.c_str (), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
@@ -93,9 +82,8 @@ Error SubprocessMemory::addMemoryDefinition(
9382
9483Expected<int > SubprocessMemory::setupAuxiliaryMemoryInSubprocess (
9584 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);
9987 int AuxiliaryMemoryFileDescriptor =
10088 shm_open (AuxiliaryMemoryName.c_str (), O_RDWR, S_IRUSR | S_IWUSR);
10189 if (AuxiliaryMemoryFileDescriptor == -1 )
@@ -109,8 +97,8 @@ Expected<int> SubprocessMemory::setupAuxiliaryMemoryInSubprocess(
10997 return make_error<Failure>(" Mapping auxiliary memory failed" );
11098 AuxiliaryMemoryMapping[0 ] = CounterFileDescriptor;
11199 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 );
114102 AuxiliaryMemoryMapping[AuxiliaryMemoryOffset + MemVal.Index ] =
115103 shm_open (MemoryValueName.c_str (), O_RDWR, S_IRUSR | S_IWUSR);
116104 if (AuxiliaryMemoryMapping[AuxiliaryMemoryOffset + MemVal.Index ] == -1 )
@@ -145,7 +133,7 @@ Error SubprocessMemory::addMemoryDefinition(
145133
146134Expected<int > SubprocessMemory::setupAuxiliaryMemoryInSubprocess (
147135 std::unordered_map<std::string, MemoryValue> MemoryDefinitions,
148- pid_t ParentPID, long ParentTID, int CounterFileDescriptor) {
136+ pid_t ParentPID, int CounterFileDescriptor) {
149137 return make_error<Failure>(
150138 " setupAuxiliaryMemoryInSubprocess is only supported on Linux" );
151139}
0 commit comments