1//===-- SubprocessMemory.h --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Defines a class that automatically handles auxiliary memory and the
11/// underlying shared memory backings for memory definitions
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TOOLS_LLVM_EXEGESIS_SUBPROCESSMEMORY_H
16#define LLVM_TOOLS_LLVM_EXEGESIS_SUBPROCESSMEMORY_H
17
18#include "BenchmarkResult.h"
19#include "llvm/ADT/StringMap.h"
20#include <string>
21#include <vector>
22
23#ifdef _MSC_VER
24typedef int pid_t;
25#else
26#include <sys/types.h>
27#endif // _MSC_VER
28
29
30namespace llvm {
31namespace exegesis {
32
33class SubprocessMemory {
34public:
35 static constexpr size_t AuxiliaryMemoryOffset = 1;
36 static constexpr size_t AuxiliaryMemorySize = 4096;
37
38 // Gets the thread ID for the calling thread.
39 static long getCurrentTID();
40
41 Error initializeSubprocessMemory(pid_t ProcessID);
42
43 // The following function sets up memory definitions. It creates shared
44 // memory objects for the definitions and fills them with the specified
45 // values. Arguments: MemoryDefinitions - A map from memory value names to
46 // MemoryValues, ProcessID - The ID of the current process.
47 Error addMemoryDefinition(StringMap<MemoryValue> MemoryDefinitions,
48 pid_t ProcessID);
49
50 // The following function sets up the auxiliary memory by opening shared
51 // memory objects backing memory definitions and putting file descriptors
52 // into appropriate places. Arguments: MemoryDefinitions - A map from memory
53 // values names to Memoryvalues, ParentPID - The ID of the process that
54 // setup the memory definitions, CounterFileDescriptor - The file descriptor
55 // for the performance counter that will be placed in the auxiliary memory
56 // section.
57 static Expected<int>
58 setupAuxiliaryMemoryInSubprocess(StringMap<MemoryValue> MemoryDefinitions,
59 pid_t ParentPID, long ParentTID,
60 int CounterFileDescriptor);
61
62 ~SubprocessMemory();
63
64private:
65 std::vector<std::string> SharedMemoryNames;
66};
67
68} // namespace exegesis
69} // namespace llvm
70
71#endif
72