ATLAS Offline Software
procmaps.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <algorithm>
6 #include <cstdlib>
7 #include <cstring>
8 #include <cstdint>
9 #include <fstream>
10 #include "CxxUtils/procmaps.h"
11 procmaps::Entry::Entry(const char* procMapsLine) :
12  begAddress(0),endAddress(0),
13  readable(false), writable(false), executable(false), isPrivate(false),
14  offset(0), inode(0)
15 {
16  dev[0]=0; dev[1]=0;
17  char pageProts[5];
18  memset(pageProts,' ', 4);
19  uint64_t inode_tmp;
20  char path[2048] = "";
21  sscanf(procMapsLine,
22  "%80lx-%80lx %4s %80x %4x:%4x %80lu %2047s",
23  &this->begAddress,
24  &this->endAddress,
25  pageProts,
26  &this->offset,
27  &this->dev[0],
28  &this->dev[1],
29  &inode_tmp,
30  path
31  );
32  this->inode = inode_tmp;
33  this->pathname = std::string (path);
34  //printf("pageProts %s pathname <%s> \n", pageProts, pathname);
35  this->readable = (pageProts[0] == 'r');
36  this->writable = (pageProts[1] == 'w');
37  this->executable = (pageProts[2] == 'x');
38  this->isPrivate = (pageProts[3] == 'p');
39 }
40 
42  m_pmaps.reserve(entries);
43  loadMaps(false);
44 }
45 
46 void
48  m_pmaps.clear();
49  std::ifstream f("/proc/self/maps");
50  const int LMAX=256;
51  char line[LMAX];
52  while ( f.getline(line,LMAX) ) {
53  if (dump) printf("%s",line);
54  m_pmaps.emplace_back(line);
55  }
56 }
57 
58 const procmaps::Entry*
59 procmaps::getEntry(const void * address, bool refreshMaps) {
60  unsigned long toMatch = reinterpret_cast<unsigned long>(address);
61  auto i = std::upper_bound (this->begin(), this->end(),
62  toMatch,
63  [] (unsigned long addr, const Entry& ent)
64  { return addr < ent.begAddress; });
65 
66  if (i > this->begin()) {
67  --i;
68  if (toMatch >= i->begAddress && toMatch < i->endAddress) {
69  return &*i;
70  }
71  }
72 
73  if (refreshMaps) {
74  //if ! found recurse once by calling getEntry with refreshMaps false
75  loadMaps();
76  return getEntry(address,false);
77  }
78 
79  return nullptr;
80 }
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
checkFileSG.line
line
Definition: checkFileSG.py:75
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
procmaps::end
const_iterator end() const
Definition: procmaps.h:47
procmaps::Entry::writable
bool writable
Definition: procmaps.h:25
procmaps::m_pmaps
procmaps_t m_pmaps
Definition: procmaps.h:53
procmaps.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
procmaps::Entry::isPrivate
bool isPrivate
Definition: procmaps.h:27
procmaps::Entry::readable
bool readable
Definition: procmaps.h:24
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
procmaps::Entry::executable
bool executable
Definition: procmaps.h:26
procmaps::Entry::endAddress
unsigned long endAddress
Definition: procmaps.h:23
procmaps::Entry::dev
unsigned int dev[2]
Definition: procmaps.h:29
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
procmaps::Entry::Entry
Entry(const char *line)
Definition: procmaps.cxx:11
procmaps::Entry::pathname
std::string pathname
Definition: procmaps.h:31
procmaps::loadMaps
void loadMaps(bool dump=false)
load/refresh info from /proc/self/map
Definition: procmaps.cxx:47
procmaps::Entry::begAddress
unsigned long begAddress
Definition: procmaps.h:22
procmaps::Entry
Definition: procmaps.h:20
PowhegControl_bblvlv_Beta_modified_SemiLep_Common.executable
executable
Definition: PowhegControl_bblvlv_Beta_modified_SemiLep_Common.py:6
procmaps::procmaps
procmaps(size_t entries=1024)
Definition: procmaps.cxx:41
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
procmaps::Entry::offset
unsigned int offset
=true page is private(COW), =false page is shared
Definition: procmaps.h:28
entries
double entries
Definition: listroot.cxx:49
procmaps::getEntry
const Entry * getEntry(const void *address, bool tryReloadMaps=true)
main entry point: get info for the page range containing address by default tries to reload /proc/sel...
Definition: procmaps.cxx:59
procmaps::begin
const_iterator begin() const
Definition: procmaps.h:46
FourMomUtils::dump
std::ostream & dump(std::ostream &out, const I4MomIter iBeg, const I4MomIter iEnd)
Helper to stream out a range of I4Momentum objects.
Definition: P4Dumper.h:24
inode
Definition: listroot.cxx:155