blob: 7aa3bff2ba05f0e2a6a5d396b5f4d164cf905ded (
plain) (
tree)
|
|
#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"
|