-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryRegion.hpp
More file actions
62 lines (52 loc) · 1.72 KB
/
MemoryRegion.hpp
File metadata and controls
62 lines (52 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
* libunix++: C++ wrapper for Linux system calls
* Memory operations
*
* © 2019—2025, Sauron <libunixpp@saur0n.science>
******************************************************************************/
#ifndef __UNIXPP_MEMORYREGION_HPP
#define __UNIXPP_MEMORYREGION_HPP
#include <sys/mman.h>
namespace upp {
/**/
class ProtectionKey {
friend class MemoryRegion;
public:
/**/
static const int DISABLE_ACCESS;
/**/
static const int DISABLE_WRITE;
/** Allocate a protection key **/
explicit ProtectionKey(unsigned int accessRights);
/** Allocate a protection key **/
ProtectionKey(unsigned int flags, unsigned int accessRights);
/** Free the protection key **/
~ProtectionKey();
private:
ProtectionKey(const ProtectionKey &other)=delete;
ProtectionKey &operator =(const ProtectionKey &other)=delete;
int pkey;
};
/** A contiguous region of memory **/
class MemoryRegion {
public:
/** Create a memory region with defined start address and length **/
MemoryRegion(void * address, size_t length);
/** Give advice about use of memory **/
void advise(int advise);
/** Determine whether pages are resident in memory **/
void incore(unsigned char * result);
/** Set protection on a region of memory **/
void protect(int prot);
/** Set protection on a region of memory **/
void protect(int prot, const ProtectionKey &pkey);
/** Returns the initial address **/
void * getAddress() const { return address; }
/** Returns the length in bytes **/
size_t getLength() const { return length; }
protected:
void * address;
size_t length;
};
}
#endif