mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-11-01 00:26:33 +01:00 
			
		
		
		
	avoid trying to use mremap outside of Linux
This commit is contained in:
		
							parent
							
								
									934ab4cb59
								
							
						
					
					
						commit
						a32e26b8e9
					
				
					 3 changed files with 10 additions and 0 deletions
				
			
		|  | @ -1416,6 +1416,7 @@ EXPORT void *h_realloc(void *old, size_t size) { | ||||||
|                 return old; |                 return old; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  | #ifdef HAVE_COMPATIBLE_MREMAP | ||||||
|             static const bool vma_merging_reliable = false; |             static const bool vma_merging_reliable = false; | ||||||
|             if (vma_merging_reliable) { |             if (vma_merging_reliable) { | ||||||
|                 // in-place growth
 |                 // in-place growth
 | ||||||
|  | @ -1465,6 +1466,7 @@ EXPORT void *h_realloc(void *old, size_t size) { | ||||||
|                 thread_seal_metadata(); |                 thread_seal_metadata(); | ||||||
|                 return new; |                 return new; | ||||||
|             } |             } | ||||||
|  | #endif | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								memory.c
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								memory.c
									
										
									
									
									
								
							|  | @ -68,6 +68,7 @@ int memory_protect_rw_metadata(void *ptr, size_t size) { | ||||||
|     return memory_protect_prot(ptr, size, PROT_READ|PROT_WRITE, get_metadata_key()); |     return memory_protect_prot(ptr, size, PROT_READ|PROT_WRITE, get_metadata_key()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | #ifdef HAVE_COMPATIBLE_MREMAP | ||||||
| int memory_remap(void *old, size_t old_size, size_t new_size) { | int memory_remap(void *old, size_t old_size, size_t new_size) { | ||||||
|     void *ptr = mremap(old, old_size, new_size, 0); |     void *ptr = mremap(old, old_size, new_size, 0); | ||||||
|     if (unlikely(ptr == MAP_FAILED)) { |     if (unlikely(ptr == MAP_FAILED)) { | ||||||
|  | @ -89,6 +90,7 @@ int memory_remap_fixed(void *old, size_t old_size, void *new, size_t new_size) { | ||||||
|     } |     } | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  | #endif | ||||||
| 
 | 
 | ||||||
| void memory_set_name(UNUSED void *ptr, UNUSED size_t size, UNUSED const char *name) { | void memory_set_name(UNUSED void *ptr, UNUSED size_t size, UNUSED const char *name) { | ||||||
| #ifdef LABEL_MEMORY | #ifdef LABEL_MEMORY | ||||||
|  |  | ||||||
							
								
								
									
										6
									
								
								memory.h
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								memory.h
									
										
									
									
									
								
							|  | @ -3,6 +3,10 @@ | ||||||
| 
 | 
 | ||||||
| #include <stddef.h> | #include <stddef.h> | ||||||
| 
 | 
 | ||||||
|  | #ifdef __linux__ | ||||||
|  | #define HAVE_COMPATIBLE_MREMAP | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| int get_metadata_key(void); | int get_metadata_key(void); | ||||||
| 
 | 
 | ||||||
| void *memory_map(size_t size); | void *memory_map(size_t size); | ||||||
|  | @ -11,8 +15,10 @@ int memory_unmap(void *ptr, size_t size); | ||||||
| int memory_protect_ro(void *ptr, size_t size); | int memory_protect_ro(void *ptr, size_t size); | ||||||
| int memory_protect_rw(void *ptr, size_t size); | int memory_protect_rw(void *ptr, size_t size); | ||||||
| int memory_protect_rw_metadata(void *ptr, size_t size); | int memory_protect_rw_metadata(void *ptr, size_t size); | ||||||
|  | #ifdef HAVE_COMPATIBLE_MREMAP | ||||||
| int memory_remap(void *old, size_t old_size, size_t new_size); | int memory_remap(void *old, size_t old_size, size_t new_size); | ||||||
| int memory_remap_fixed(void *old, size_t old_size, void *new, size_t new_size); | int memory_remap_fixed(void *old, size_t old_size, void *new, size_t new_size); | ||||||
|  | #endif | ||||||
| void memory_set_name(void *ptr, size_t size, const char *name); | void memory_set_name(void *ptr, size_t size, const char *name); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue