comparison mem.c @ 1340:101b5ce682fe

Fix some inconsequential issues in code for executable memory allocation noticed while tracking down a different issue
author Michael Pavone <pavone@retrodev.com>
date Thu, 04 May 2017 21:00:25 -0700
parents 6bafe1988e8c
children 8e86cd581620
comparison
equal deleted inserted replaced
1339:35e6a93b4586 1340:101b5ce682fe
28 static uint8_t *next = (uint8_t *)0x40000000; 28 static uint8_t *next = (uint8_t *)0x40000000;
29 uint8_t *ret = try_alloc_arena(); 29 uint8_t *ret = try_alloc_arena();
30 if (ret) { 30 if (ret) {
31 return ret; 31 return ret;
32 } 32 }
33 *size += PAGE_SIZE - (*size & (PAGE_SIZE - 1)); 33 if (*size & (PAGE_SIZE -1)) {
34 ret = mmap(NULL, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0); 34 *size += PAGE_SIZE - (*size & (PAGE_SIZE - 1));
35 }
36 ret = mmap(next, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
35 if (ret == MAP_FAILED) { 37 if (ret == MAP_FAILED) {
36 perror("alloc_code"); 38 perror("alloc_code");
37 return NULL; 39 return NULL;
38 } 40 }
39 track_block(ret); 41 track_block(ret);