label allocate_aligned_pages mappings

pull/87/head
Daniel Micay 2019-03-23 22:29:04 -04:00
parent c8b948e202
commit 1d62075291
3 changed files with 8 additions and 7 deletions

View File

@ -1304,7 +1304,7 @@ static int alloc_aligned(void **memptr, size_t alignment, size_t size, size_t mi
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_aligned(size, alignment, guard_size); void *p = allocate_pages_aligned(size, alignment, guard_size, "malloc large");
if (p == NULL) { if (p == NULL) {
return ENOMEM; return ENOMEM;
} }

11
pages.c
View File

@ -27,11 +27,7 @@ void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect, cons
return usable; return usable;
} }
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, const char *name) {
memory_unmap((char *)usable - guard_size, usable_size + guard_size * 2);
}
void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_size) {
usable_size = PAGE_CEILING(usable_size); usable_size = PAGE_CEILING(usable_size);
if (unlikely(!usable_size)) { if (unlikely(!usable_size)) {
errno = ENOMEM; errno = ENOMEM;
@ -54,6 +50,7 @@ void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_
if (unlikely(real == NULL)) { if (unlikely(real == NULL)) {
return NULL; return NULL;
} }
memory_set_name(real, real_alloc_size, name);
void *usable = (char *)real + guard_size; void *usable = (char *)real + guard_size;
@ -82,3 +79,7 @@ void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_
return base; return base;
} }
void deallocate_pages(void *usable, size_t usable_size, size_t guard_size) {
memory_unmap((char *)usable - guard_size, usable_size + guard_size * 2);
}

View File

@ -11,7 +11,7 @@
#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, const char *name); void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect, const char *name);
void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_size, 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);
#endif #endif