Chez Scheme: make pb build accomocate WRITE_XOR_EXECUTE_CODE

Although W^X is useless to pb, allowing it to build with
`-DWRITE_XOR_EXECUTE_CODE` can be helpful.
This commit is contained in:
Matthew Flatt 2021-05-01 09:26:59 -06:00
parent 1f0223fef1
commit 406dcc9ff3

View File

@ -46,7 +46,7 @@ static seginfo *sort_seginfo PROTO((seginfo *si, uptr n));
static seginfo *merge_seginfo PROTO((seginfo *si1, seginfo *si2)); static seginfo *merge_seginfo PROTO((seginfo *si1, seginfo *si2));
#if defined(WRITE_XOR_EXECUTE_CODE) #if defined(WRITE_XOR_EXECUTE_CODE)
static void enable_code_write PROTO((ptr tc, IGEN maxg, IBOOL on, IBOOL current, ptr hint, uptr hint_len)); static void enable_code_write PROTO((ptr tc, IGEN maxg, IBOOL on, IBOOL current, void *hint, uptr hint_len));
#endif #endif
void S_segment_init() { void S_segment_init() {
@ -628,8 +628,8 @@ static IBOOL is_unused_seg(chunkinfo *chunk, seginfo *si) {
static void enable_code_write(ptr tc, IGEN maxg, IBOOL on, IBOOL current, void *hint, uptr hint_len) { static void enable_code_write(ptr tc, IGEN maxg, IBOOL on, IBOOL current, void *hint, uptr hint_len) {
thread_gc *tgc; thread_gc *tgc;
chunkinfo *chunk; chunkinfo *chunk;
seginfo si, *sip; seginfo *sip;
iptr i, j, bytes; iptr i, bytes;
void *addr; void *addr;
INT flags = (on ? PROT_WRITE : PROT_EXEC) | PROT_READ; INT flags = (on ? PROT_WRITE : PROT_EXEC) | PROT_READ;
@ -650,7 +650,7 @@ static void enable_code_write(ptr tc, IGEN maxg, IBOOL on, IBOOL current, void *
/* Flip only the current allocation segments. */ /* Flip only the current allocation segments. */
tgc = THREAD_GC(tc); tgc = THREAD_GC(tc);
if (maxg == 0 && current) { if (maxg == 0 && current) {
addr = tgc->base_loc[0][space_code]; addr = TO_VOIDP(tgc->base_loc[0][space_code]);
if (addr == NULL) { if (addr == NULL) {
return; return;
} }
@ -665,7 +665,7 @@ static void enable_code_write(ptr tc, IGEN maxg, IBOOL on, IBOOL current, void *
if (!on) { if (!on) {
while ((sip = tgc->sweep_next[0][space_code]) != NULL) { while ((sip = tgc->sweep_next[0][space_code]) != NULL) {
tgc->sweep_next[0][space_code] = sip->sweep_next; tgc->sweep_next[0][space_code] = sip->sweep_next;
addr = sip->sweep_start; addr = TO_VOIDP(sip->sweep_start);
bytes = sip->sweep_bytes; bytes = sip->sweep_bytes;
if (mprotect(addr, bytes, flags) != 0) { if (mprotect(addr, bytes, flags) != 0) {
S_error_abort("failed to protect recent allocation segments"); S_error_abort("failed to protect recent allocation segments");
@ -688,8 +688,9 @@ static void enable_code_write(ptr tc, IGEN maxg, IBOOL on, IBOOL current, void *
} else { } else {
/* Flip bits for whole runs of segs that are either unused or /* Flip bits for whole runs of segs that are either unused or
whose generation is within the range [0, maxg]. */ whose generation is within the range [0, maxg]. */
int j;
for (j = 0; j < chunk->segs; j++) { for (j = 0; j < chunk->segs; j++) {
si = chunk->sis[j]; seginfo si = chunk->sis[j];
/* When maxg is 0, limit the search to unused segments and /* When maxg is 0, limit the search to unused segments and
segments that belong to the current thread. */ segments that belong to the current thread. */
if ((maxg == 0 && si.generation == 0 && si.creator == tgc) || if ((maxg == 0 && si.generation == 0 && si.creator == tgc) ||