mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-10-31 08:16:31 +01:00 
			
		
		
		
	Merge 815dae1ad3 into 2250130c53
				
					
				
			This commit is contained in:
		
						commit
						545fcdb9b5
					
				
					 3 changed files with 14 additions and 12 deletions
				
			
		
							
								
								
									
										14
									
								
								h_malloc.c
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								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; | ||||
| } | ||||
| 
 | ||||
|  | @ -1192,7 +1192,7 @@ COLD __attribute__((constructor(101))) static void trigger_early_init(void) { | |||
| #endif | ||||
| 
 | ||||
| // 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:
 | ||||
|         //
 | ||||
|  | @ -1315,7 +1315,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; | ||||
|     } | ||||
|  |  | |||
							
								
								
									
										4
									
								
								pages.h
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								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); | ||||
|  |  | |||
							
								
								
									
										8
									
								
								util.h
									
										
									
									
									
								
							
							
						
						
									
										8
									
								
								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; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue