diff --git a/h_malloc.c b/h_malloc.c index 39ba84d..6acdab3 100644 --- a/h_malloc.c +++ b/h_malloc.c @@ -154,7 +154,7 @@ static const u16 size_class_slots[] = { #endif }; -static size_t get_slots(unsigned class) { +CONST static size_t get_slots(unsigned class) { return size_class_slots[class]; } @@ -187,7 +187,7 @@ struct size_info { size_t class; }; -static inline struct size_info get_size_info(size_t size) { +CONST static inline struct size_info get_size_info(size_t size) { if (unlikely(size == 0)) { return (struct size_info){0, 0}; } @@ -218,7 +218,7 @@ static inline struct size_info get_size_info_align(size_t size, size_t alignment fatal_error("invalid size for slabs"); } -static size_t get_slab_size(size_t slots, size_t size) { +CONST static size_t get_slab_size(size_t slots, size_t size) { return page_align(slots * size); } @@ -283,7 +283,7 @@ static void *get_slab(const struct size_class *c, size_t slab_size, const struct #define MAX_METADATA_MAX (CLASS_REGION_SIZE / PAGE_SIZE) -static size_t get_metadata_max(size_t slab_size) { +CONST static size_t get_metadata_max(size_t slab_size) { return CLASS_REGION_SIZE / slab_size; } @@ -356,7 +356,7 @@ static bool is_quarantine_slot(const struct slab_metadata *metadata, size_t inde } #endif -static u64 get_mask(size_t slots) { +CONST static u64 get_mask(size_t slots) { return slots < U64_WIDTH ? ~0UL << slots : 0; } @@ -1190,7 +1190,7 @@ COLD __attribute__((constructor(101))) static void trigger_early_init(void) { } // Returns 0 on overflow. -static size_t get_large_size_class(size_t size) { +CONST static size_t get_large_size_class(size_t size) { if (CONFIG_LARGE_SIZE_CLASSES) { // Continue small size class growth pattern of power of 2 spacing classes: // @@ -1313,7 +1313,7 @@ static int allocate_aligned(unsigned arena, void **memptr, size_t alignment, siz return 0; } -static size_t adjust_size_for_canary(size_t size) { +CONST static size_t adjust_size_for_canary(size_t size) { if (size > 0 && size <= max_slab_size_class) { return size + canary_size; } diff --git a/pages.h b/pages.h index 8795ddc..42209aa 100644 --- a/pages.h +++ b/pages.h @@ -16,11 +16,11 @@ void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect, cons 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); -static inline size_t page_align(size_t size) { +CONST static inline size_t page_align(size_t size) { return align(size, PAGE_SIZE); } -static inline size_t hash_page(const void *p) { +CONST static inline size_t hash_page(const void *p) { uintptr_t u = (uintptr_t)p >> PAGE_SHIFT; size_t sum = u; sum = (sum << 7) - sum + (u >> 16); diff --git a/util.h b/util.h index 3d0b653..569f2a7 100644 --- a/util.h +++ b/util.h @@ -29,6 +29,8 @@ #define STRINGIFY(s) #s #define ALIAS(f) __attribute__((alias(STRINGIFY(f)))) +#define CONST __attribute__ ((const)) + typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; @@ -42,16 +44,16 @@ static inline int ffz64(u64 x) { } // parameter must not be 0 -static inline int clz64(u64 x) { +CONST static inline int clz64(u64 x) { return __builtin_clzll(x); } // parameter must not be 0 -static inline u64 log2u64(u64 x) { +CONST static inline u64 log2u64(u64 x) { return U64_WIDTH - clz64(x) - 1; } -static inline size_t align(size_t size, size_t align) { +CONST static inline size_t align(size_t size, size_t align) { size_t mask = align - 1; return (size + mask) & ~mask; }