-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryRegion.cpp
More file actions
43 lines (32 loc) · 1.29 KB
/
MemoryRegion.cpp
File metadata and controls
43 lines (32 loc) · 1.29 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
/*******************************************************************************
* libunix++: C++ wrapper for Linux system calls
* Memory operations
*
* © 2019—2025, Sauron <libunixpp@saur0n.science>
******************************************************************************/
#include <sys/mman.h>
#include "exception.hppi"
#include "MemoryRegion.hpp"
using namespace upp;
/******************************************************************************/
ProtectionKey::ProtectionKey(unsigned int accessRights) :
pkey(pkey_alloc(0, accessRights)) {}
ProtectionKey::ProtectionKey(unsigned int flags, unsigned int accessRights) :
pkey(pkey_alloc(flags, accessRights)) {}
ProtectionKey::~ProtectionKey() {
pkey_free(pkey);
}
MemoryRegion::MemoryRegion(void * address, size_t length) :
address(address), length(length) {}
void MemoryRegion::advise(int advise) {
NORMAL_OP_WRAPPER(madvise(address, length, advise));
}
void MemoryRegion::incore(unsigned char * result) {
NORMAL_OP_WRAPPER(mincore(address, length, result));
}
void MemoryRegion::protect(int prot) {
NORMAL_OP_WRAPPER(mprotect(address, length, prot));
}
void MemoryRegion::protect(int prot, const ProtectionKey &pkey) {
NORMAL_OP_WRAPPER(pkey_mprotect(address, length, prot, pkey.pkey));
}