blob: 9d0752d2e1612d8ebfe22c1b24f91278bcb67930 (
plain)
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
|
#include <limits.h>
#include <stdlib.h>
#include "_readonly.h"
#include "stdlib/_jkmalloc.h"
#include "_forced/mprotect.h"
#ifndef PAGESIZE
#define PAGESIZE 4096
#endif
void* __readonly(ro_action_t action, void *ptr)
{
switch (action) {
case RO_ALLOC:
return __jkmalloc(NULL, 1, PAGESIZE, 0, ptr);
case RO_FREE:
free(ptr);
return NULL;
case RO_LOCK:
mprotect(ptr, PAGESIZE, PROT_READ);
break;
case RO_UNLOCK:
mprotect(ptr, PAGESIZE, PROT_READ | PROT_WRITE);
break;
}
return ptr;
}
|