mirror of
				https://github.com/GrapheneOS/hardened_malloc.git
				synced 2025-11-03 01:06:33 +01:00 
			
		
		
		
	mte: add untag_pointer() variant for const pointers
This commit is contained in:
		
							parent
							
								
									99ab17364e
								
							
						
					
					
						commit
						452ff8a878
					
				
					 2 changed files with 10 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -1762,7 +1762,7 @@ EXPORT size_t h_malloc_usable_size(H_MALLOC_USABLE_SIZE_CONST void *arg) {
 | 
			
		|||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void *p = untag_pointer((void *) (uintptr_t) arg);
 | 
			
		||||
    const void *p = untag_const_pointer(arg);
 | 
			
		||||
 | 
			
		||||
    if (p < get_slab_region_end() && p >= ro.slab_region_start) {
 | 
			
		||||
        thread_unseal_metadata();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								memtag.h
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								memtag.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -19,6 +19,15 @@ static inline void *untag_pointer(void *ptr) {
 | 
			
		|||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline const void *untag_const_pointer(const void *ptr) {
 | 
			
		||||
#ifdef HAS_ARM_MTE
 | 
			
		||||
    const uintptr_t mask = UINTPTR_MAX >> 8;
 | 
			
		||||
    return (const void *) ((uintptr_t) ptr & mask);
 | 
			
		||||
#else
 | 
			
		||||
    return ptr;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void *set_pointer_tag(void *ptr, u8 tag) {
 | 
			
		||||
#ifdef HAS_ARM_MTE
 | 
			
		||||
    return (void *) (((uintptr_t) tag << 56) | (uintptr_t) untag_pointer(ptr));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue