aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/obscuren/qml/cpp/mmemwin.cpp
blob: 7aa3bff2ba05f0e2a6a5d396b5f4d164cf905ded (plain) (blame)
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
#include <windows.h>

#define protREAD  1
#define protWRITE 2
#define protEXEC  4

extern "C" {

int mprotect(void *addr, size_t len, int prot)
{
    DWORD wprot = 0;
    if (prot & protWRITE) {
        wprot = PAGE_READWRITE;
    } else if (prot & protREAD) {
        wprot = PAGE_READONLY;
    }
    if (prot & protEXEC) {
        wprot <<= 4;
    }
    DWORD oldwprot;
    if (!VirtualProtect(addr, len, wprot, &oldwprot)) {
        return -1;
    }
    return 0;
}

} // extern "C"