ATLAS Offline Software
Loading...
Searching...
No Matches
PageAccessControl.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef CXXUTILS_PAGEACCESSCONTROL_H
8#define CXXUTILS_PAGEACCESSCONTROL_H 1
9
21
22#include <vector>
23#include <sys/mman.h> /*PROT_NONE*/
24
25#include "CxxUtils/procmaps.h"
26
28public:
29 PageAccessControl(size_t reservedSize=65535) :
30 m_pmaps(),
32 {
33 //we must reserve enough elements, or we risk vector allocating in a protected page during handle()...
34 m_protected.reserve(reservedSize);
35 }
36 PageAccessControl(procmaps& pmaps, size_t reservedSize=65535) :
37 m_pmaps(pmaps),
39 {
40 //we must reserve enough elements, or we risk vector allocating in a protected page during handle()...
41 m_protected.reserve(reservedSize);
42 }
43
48 template <typename T>
49 bool protectPage(T* addr, int prot) {
50 return protectPage(addr, sizeof(T), prot);
51 }
52
54 template <typename T>
55 bool forbidPage(const T* addr) {
56 return forbidPage(addr, sizeof(T));
57 }
58
60 bool forbidPage(const void* addr, size_t objSize) {
61 return protectPage(addr, objSize, PROT_NONE);
62 }
63
65 bool forbidPage(const void* addr) {
66 return protectPage(addr, 4, PROT_NONE);
67 }
68
70 bool protectPage(const void* addr, size_t objSize, int prot);
71
72 bool restorePageProt(const void * addr);
73 void sort();
74
76 struct Entry {
77 Entry(const void* a, size_t l, int p, void* pl);
79 const void* addr;
81 size_t lenProt;
82 int prot;
84 void* leak;
88 };
89
91 typedef std::vector<Entry> protected_t;
92 typedef protected_t::const_iterator const_iterator;
93 const protected_t& protectedPtrs() const { return m_protected; }
94 const_iterator beginProtectedPtrs() const { return m_protected.begin(); }
96 void reset() { m_protected.clear(); }
97
99 bool accessed(const void* address) const;
100
101private:
102
105
106 // can not preallocate map
107 // typedef std::map<void*, size_t, std::less<void*>,
108 // boost::pool_allocator<std::map<void*, size_t>::value_type > > protected_t;
111};
112inline
114 return lhs.addr < rhs.addr;
115}
116#endif
static Double_t a
bool operator<(const PageAccessControl::Entry &lhs, const PageAccessControl::Entry &rhs)
FIXME Access to the underlying protect/restore page access.
bool forbidPage(const void *addr)
FIXME this will not work well for objects spanning across pages.
procmaps m_pmaps
the content of /proc/self/maps
bool accessed(const void *address) const
was the page containing address accessed?
bool restorePageProt(const void *addr)
bool forbidPage(const T *addr)
forbid access to the page containing addr, setting its prot to PROT_NONE
PageAccessControl(size_t reservedSize=65535)
const_iterator beginProtectedPtrs() const
bool protectPage(T *addr, int prot)
protect the page containing addr, record the amount of memory we protected NOTE To avoid SEGV,...
PageAccessControl(procmaps &pmaps, size_t reservedSize=65535)
std::vector< Entry > protected_t
the list of protected pages
bool forbidPage(const void *addr, size_t objSize)
forbid access to the page containing addr, setting its prot to PROT_NONE
protected_t::const_iterator const_iterator
const protected_t & protectedPtrs() const
const_iterator endProtectedPtrs() const
On stopMonitoring/finalize the handler is uninstalled.
Definition procmaps.h:18
protection of a memory region (see mprotect(2))
void * leak
pointer to the heap fragment we leaked before protecting the page
size_t lenProt
length of the protected region, from page addr to end of protected obj
const void * addr
address of page for which protection was requested. Used as key
Entry(const void *a, size_t l, int p, void *pl)