MCPcopy Create free account
hub / github.com/F-Stack/f-stack / os_pages_map

Function os_pages_map

app/redis-6.2.6/deps/jemalloc/src/pages.c:53–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51/******************************************************************************/
52
53static void *
54os_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
98static void *
99os_pages_trim(void *addr, size_t alloc_size, size_t leadsize, size_t size,

Callers 4

os_pages_trimFunction · 0.85
pages_map_slowFunction · 0.85
pages_mapFunction · 0.85
pages_bootFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected