Mercurial > repos > blastem
comparison mem.c @ 883:9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 13 Nov 2015 19:15:37 -0800 |
parents | c3e3a0d734e2 |
children | 6bafe1988e8c |
comparison
equal
deleted
inserted
replaced
882:75453bf2ffac | 883:9f149f0e98b7 |
---|---|
1 /* | 1 /* |
2 Copyright 2013 Michael Pavone | 2 Copyright 2013 Michael Pavone |
3 This file is part of BlastEm. | 3 This file is part of BlastEm. |
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. | 4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
5 */ | 5 */ |
6 #include <sys/mman.h> | 6 #include <sys/mman.h> |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
11 #include <errno.h> | 11 #include <errno.h> |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 | 13 |
14 #include "mem.h" | 14 #include "mem.h" |
15 #include "arena.h" | |
15 #ifndef MAP_ANONYMOUS | 16 #ifndef MAP_ANONYMOUS |
16 #define MAP_ANONYMOUS MAP_ANON | 17 #define MAP_ANONYMOUS MAP_ANON |
17 #endif | 18 #endif |
18 | 19 |
19 #ifndef MAP_32BIT | 20 #ifndef MAP_32BIT |
23 void * alloc_code(size_t *size) | 24 void * alloc_code(size_t *size) |
24 { | 25 { |
25 //start at the 1GB mark to allow plenty of room for sbrk based malloc implementations | 26 //start at the 1GB mark to allow plenty of room for sbrk based malloc implementations |
26 //while still keeping well within 32-bit displacement range for calling code compiled into the executable | 27 //while still keeping well within 32-bit displacement range for calling code compiled into the executable |
27 static uint8_t *next = (uint8_t *)0x40000000; | 28 static uint8_t *next = (uint8_t *)0x40000000; |
29 uint8_t *ret = try_alloc_arena(); | |
30 if (ret) { | |
31 return ret; | |
32 } | |
28 *size += PAGE_SIZE - (*size & (PAGE_SIZE - 1)); | 33 *size += PAGE_SIZE - (*size & (PAGE_SIZE - 1)); |
29 uint8_t *ret = mmap(NULL, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0); | 34 ret = mmap(NULL, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0); |
30 if (ret == MAP_FAILED) { | 35 if (ret == MAP_FAILED) { |
31 perror("alloc_code"); | 36 perror("alloc_code"); |
32 return NULL; | 37 return NULL; |
33 } | 38 } |
34 next = ret + *size; | 39 next = ret + *size; |