File tree Expand file tree Collapse file tree
core/shared/mem-alloc/ems Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -552,6 +552,23 @@ alloc_hmu_ex(gc_heap_t *heap, gc_size_t size)
552552 return alloc_hmu (heap , size );
553553}
554554
555+ /* Convert object pointer to HMU pointer - handles aligned allocations */
556+ MEM_ALLOC_API_INTER hmu_t *
557+ obj_to_hmu (gc_object_t obj )
558+ {
559+ uint32_t * magic_ptr = (uint32_t * )((char * )obj - 4 );
560+
561+ /* Check for aligned allocation magic signature */
562+ if ((* magic_ptr & ALIGNED_ALLOC_MAGIC_MASK ) == ALIGNED_ALLOC_MAGIC_VALUE ) {
563+ /* This is an aligned allocation, read offset */
564+ uint32_t * offset_ptr = (uint32_t * )((char * )obj - 8 );
565+ return (hmu_t * )((char * )obj - * offset_ptr );
566+ }
567+
568+ /* Normal allocation: standard offset */
569+ return (hmu_t * )((gc_uint8 * )(obj ) - OBJ_PREFIX_SIZE ) - 1 ;
570+ }
571+
555572#if BH_ENABLE_GC_VERIFY == 0
556573gc_object_t
557574gc_alloc_vo (void * vheap , gc_size_t size )
Original file line number Diff line number Diff line change @@ -127,7 +127,10 @@ hmu_verify(void *vheap, hmu_t *hmu);
127127#define HMU_SIZE (sizeof(hmu_t))
128128
129129#define hmu_to_obj (hmu ) (gc_object_t)(SKIP_OBJ_PREFIX((hmu_t *)(hmu) + 1))
130- #define obj_to_hmu (obj ) ((hmu_t *)((gc_uint8 *)(obj)-OBJ_PREFIX_SIZE) - 1)
130+
131+ /* obj_to_hmu function - handles both normal and aligned allocations */
132+ MEM_ALLOC_API_INTER hmu_t *
133+ obj_to_hmu (gc_object_t obj );
131134
132135#define HMU_UT_SIZE 2
133136#define HMU_UT_OFFSET 30
You can’t perform that action at this time.
0 commit comments