label allocate_pages mappings
parent
65311a5df2
commit
45337ebe07
|
@ -972,7 +972,7 @@ COLD static void init_slow_path(void) {
|
||||||
fatal_error("page size mismatch");
|
fatal_error("page size mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct random_state *rng = allocate_pages(sizeof(struct random_state), PAGE_SIZE, true);
|
struct random_state *rng = allocate_pages(sizeof(struct random_state), PAGE_SIZE, true, "malloc init rng");
|
||||||
if (rng == NULL) {
|
if (rng == NULL) {
|
||||||
fatal_error("failed to allocate init rng");
|
fatal_error("failed to allocate init rng");
|
||||||
}
|
}
|
||||||
|
@ -982,11 +982,10 @@ COLD static void init_slow_path(void) {
|
||||||
(get_random_u64_uniform(rng, REAL_CLASS_REGION_SIZE / PAGE_SIZE) + 1) * PAGE_SIZE;
|
(get_random_u64_uniform(rng, REAL_CLASS_REGION_SIZE / PAGE_SIZE) + 1) * PAGE_SIZE;
|
||||||
|
|
||||||
struct allocator_state *allocator_state =
|
struct allocator_state *allocator_state =
|
||||||
allocate_pages(sizeof(struct allocator_state), metadata_guard_size, false);
|
allocate_pages(sizeof(struct allocator_state), metadata_guard_size, false, "malloc allocator_state");
|
||||||
if (allocator_state == NULL) {
|
if (allocator_state == NULL) {
|
||||||
fatal_error("failed to reserve allocator state");
|
fatal_error("failed to reserve allocator state");
|
||||||
}
|
}
|
||||||
memory_set_name(allocator_state, sizeof(struct allocator_state), "malloc allocator_state");
|
|
||||||
if (memory_protect_rw_metadata(allocator_state, offsetof(struct allocator_state, regions_a))) {
|
if (memory_protect_rw_metadata(allocator_state, offsetof(struct allocator_state, regions_a))) {
|
||||||
fatal_error("failed to unprotect allocator state");
|
fatal_error("failed to unprotect allocator state");
|
||||||
}
|
}
|
||||||
|
@ -1076,7 +1075,7 @@ static void *allocate(size_t size) {
|
||||||
size_t guard_size = get_guard_size(&ra->rng, size);
|
size_t guard_size = get_guard_size(&ra->rng, size);
|
||||||
mutex_unlock(&ra->lock);
|
mutex_unlock(&ra->lock);
|
||||||
|
|
||||||
void *p = allocate_pages(size, guard_size, true);
|
void *p = allocate_pages(size, guard_size, true, "malloc large");
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
3
pages.c
3
pages.c
|
@ -8,7 +8,7 @@ static uintptr_t alignment_ceiling(uintptr_t s, uintptr_t alignment) {
|
||||||
return ((s) + (alignment - 1)) & ((~alignment) + 1);
|
return ((s) + (alignment - 1)) & ((~alignment) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect) {
|
void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect, const char *name) {
|
||||||
size_t real_size;
|
size_t real_size;
|
||||||
if (unlikely(__builtin_add_overflow(usable_size, guard_size * 2, &real_size))) {
|
if (unlikely(__builtin_add_overflow(usable_size, guard_size * 2, &real_size))) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
|
@ -18,6 +18,7 @@ void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect) {
|
||||||
if (unlikely(real == NULL)) {
|
if (unlikely(real == NULL)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
memory_set_name(real, real_size, name);
|
||||||
void *usable = (char *)real + guard_size;
|
void *usable = (char *)real + guard_size;
|
||||||
if (unprotect && unlikely(memory_protect_rw(usable, usable_size))) {
|
if (unprotect && unlikely(memory_protect_rw(usable, usable_size))) {
|
||||||
memory_unmap(real, real_size);
|
memory_unmap(real, real_size);
|
||||||
|
|
2
pages.h
2
pages.h
|
@ -10,7 +10,7 @@
|
||||||
#endif
|
#endif
|
||||||
#define PAGE_CEILING(s) (((s) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
|
#define PAGE_CEILING(s) (((s) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
|
||||||
|
|
||||||
void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect);
|
void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect, const char *name);
|
||||||
void deallocate_pages(void *usable, size_t usable_size, size_t guard_size);
|
void deallocate_pages(void *usable, size_t usable_size, size_t guard_size);
|
||||||
void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_size);
|
void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue