| 51 | /******************************************************************************/ |
| 52 | |
| 53 | static void * |
| 54 | os_pages_map(void *addr, size_t size, size_t alignment, bool *commit) { |
| 55 | assert(ALIGNMENT_ADDR2BASE(addr, os_page) == addr); |
| 56 | assert(ALIGNMENT_CEILING(size, os_page) == size); |
| 57 | assert(size != 0); |
| 58 | |
| 59 | if (os_overcommits) { |
| 60 | *commit = true; |
| 61 | } |
| 62 | |
| 63 | void *ret; |
| 64 | #ifdef _WIN32 |
| 65 | /* |
| 66 | * If VirtualAlloc can't allocate at the given address when one is |
| 67 | * given, it fails and returns NULL. |
| 68 | */ |
| 69 | ret = VirtualAlloc(addr, size, MEM_RESERVE | (*commit ? MEM_COMMIT : 0), |
| 70 | PAGE_READWRITE); |
| 71 | #else |
| 72 | /* |
| 73 | * We don't use MAP_FIXED here, because it can cause the *replacement* |
| 74 | * of existing mappings, and we only want to create new mappings. |
| 75 | */ |
| 76 | { |
| 77 | int prot = *commit ? PAGES_PROT_COMMIT : PAGES_PROT_DECOMMIT; |
| 78 | |
| 79 | ret = mmap(addr, size, prot, mmap_flags, -1, 0); |
| 80 | } |
| 81 | assert(ret != NULL); |
| 82 | |
| 83 | if (ret == MAP_FAILED) { |
| 84 | ret = NULL; |
| 85 | } else if (addr != NULL && ret != addr) { |
| 86 | /* |
| 87 | * We succeeded in mapping memory, but not in the right place. |
| 88 | */ |
| 89 | os_pages_unmap(ret, size); |
| 90 | ret = NULL; |
| 91 | } |
| 92 | #endif |
| 93 | assert(ret == NULL || (addr == NULL && ret != addr) || (addr != NULL && |
| 94 | ret == addr)); |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | static void * |
| 99 | os_pages_trim(void *addr, size_t alloc_size, size_t leadsize, size_t size, |
no outgoing calls
no test coverage detected