mark page management error code paths as unlikely

pull/50/head
Daniel Micay 2018-09-02 02:08:44 -04:00
parent e4648192c0
commit 89c624b755
1 changed files with 6 additions and 7 deletions

13
pages.c
View File

@ -14,11 +14,11 @@ void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect) {
return NULL; return NULL;
} }
void *real = memory_map(real_size); void *real = memory_map(real_size);
if (real == NULL) { if (unlikely(real == NULL)) {
return NULL; return NULL;
} }
void *usable = (char *)real + guard_size; void *usable = (char *)real + guard_size;
if (unprotect && 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);
return NULL; return NULL;
} }
@ -49,7 +49,7 @@ void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_
} }
void *real = memory_map(real_alloc_size); void *real = memory_map(real_alloc_size);
if (real == NULL) { if (unlikely(real == NULL)) {
return NULL; return NULL;
} }
@ -59,20 +59,20 @@ void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_
size_t trail_size = alloc_size - lead_size - usable_size; size_t trail_size = alloc_size - lead_size - usable_size;
void *base = (char *)usable + lead_size; void *base = (char *)usable + lead_size;
if (memory_protect_rw(base, usable_size)) { if (unlikely(memory_protect_rw(base, usable_size))) {
memory_unmap(real, real_alloc_size); memory_unmap(real, real_alloc_size);
return NULL; return NULL;
} }
if (lead_size) { if (lead_size) {
if (memory_unmap(real, lead_size)) { if (unlikely(memory_unmap(real, lead_size))) {
memory_unmap(real, real_alloc_size); memory_unmap(real, real_alloc_size);
return NULL; return NULL;
} }
} }
if (trail_size) { if (trail_size) {
if (memory_unmap((char *)base + usable_size + guard_size, trail_size)) { if (unlikely(memory_unmap((char *)base + usable_size + guard_size, trail_size))) {
memory_unmap(real, real_alloc_size); memory_unmap(real, real_alloc_size);
return NULL; return NULL;
} }
@ -80,4 +80,3 @@ void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_
return base; return base;
} }