Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / platform / mmap-protect.c
1 void *GC_mmapAnon_safe_protect (void *start, size_t length, int prot,
2 size_t dead_low, size_t dead_high) {
3 void *base,*low,*result,*high;
4
5 base = GC_mmapAnon_safe (start, length + dead_low + dead_high);
6 low = base;
7 if (mprotect (low, dead_low, PROT_NONE))
8 diee ("mprotect failed");
9 result = (void*)((pointer)low + dead_low);
10 if (mprotect (result, length, prot))
11 diee ("mprotect failed");
12 high = (void*)((pointer)result + length);
13 if (mprotect (high, dead_high, PROT_NONE))
14 diee ("mprotect failed");
15 return result;
16 }