@@ -1400,6 +1400,9 @@ DECLARE_REAL(hsa_status_t, hsa_amd_ipc_memory_detach, void *mapped_ptr)
14001400DECLARE_REAL(hsa_status_t , hsa_amd_vmem_address_reserve_align, void ** ptr,
14011401 size_t size, uint64_t address, uint64_t alignment, uint64_t flags)
14021402DECLARE_REAL(hsa_status_t , hsa_amd_vmem_address_free, void * ptr, size_t size)
1403+ DECLARE_REAL(hsa_status_t , hsa_amd_pointer_info, const void * ptr,
1404+ hsa_amd_pointer_info_t * info, void * (*alloc)(size_t ),
1405+ uint32_t* num_agents_accessible, hsa_agent_t** accessible)
14031406
14041407namespace __asan {
14051408
@@ -1454,21 +1457,18 @@ static struct AP32<LocalAddressSpaceView> AP_;
14541457
14551458hsa_status_t asan_hsa_amd_ipc_memory_create (void * ptr, size_t len,
14561459 hsa_amd_ipc_memory_t * handle) {
1457- static_assert (AP_.kMetadataSize == 0 , " Expression below requires this" );
14581460 void * ptr_ = get_allocator ().GetBlockBegin (ptr);
1459- size_t len_ = get_allocator ().GetActuallyAllocatedSize (ptr);
1460-
1461- uptr p = reinterpret_cast <uptr>(ptr);
1462- uptr p_ = reinterpret_cast <uptr>(ptr_);
1463-
1464- if (p == p_)
1461+ AsanChunk* m = ptr_
1462+ ? instance.GetAsanChunkByAddr (reinterpret_cast <uptr>(ptr_))
1463+ : nullptr ;
1464+ if (ptr_ && m) {
1465+ static_assert (AP_.kMetadataSize == 0 , " Expression below requires this" );
1466+ uptr p = reinterpret_cast <uptr>(ptr);
1467+ uptr p_ = reinterpret_cast <uptr>(ptr_);
1468+ size_t len_ = len;
1469+ if (p == p_ + kPageSize_ && len == m->UsedSize ())
1470+ len_ = get_allocator ().GetActuallyAllocatedSize (ptr);
14651471 return REAL (hsa_amd_ipc_memory_create)(ptr_, len_, handle);
1466-
1467- if (p == p_ + kPageSize_ ) {
1468- AsanChunk* m = instance.GetAsanChunkByAddr (p_);
1469- if (m && len == m->UsedSize ())
1470- return REAL (hsa_amd_ipc_memory_create)(ptr_, len_, handle);
1471- return REAL (hsa_amd_ipc_memory_create)(ptr_, len, handle);
14721472 }
14731473 return REAL (hsa_amd_ipc_memory_create)(ptr, len, handle);
14741474}
@@ -1547,5 +1547,28 @@ hsa_status_t asan_hsa_amd_vmem_address_free(void* ptr, size_t size,
15471547 }
15481548 return REAL (hsa_amd_vmem_address_free)(ptr, size);
15491549}
1550+
1551+ hsa_status_t asan_hsa_amd_pointer_info (const void * ptr,
1552+ hsa_amd_pointer_info_t * info,
1553+ void * (*alloc)(size_t ),
1554+ uint32_t * num_agents_accessible,
1555+ hsa_agent_t ** accessible) {
1556+ void * p = get_allocator ().GetBlockBegin (ptr);
1557+ AsanChunk* m = instance.GetAsanChunkByAddr (reinterpret_cast <uptr>(p));
1558+ hsa_status_t status;
1559+ if (p && m)
1560+ status = REAL (hsa_amd_pointer_info)(ptr, info, alloc, num_agents_accessible,
1561+ accessible);
1562+ if (status == HSA_STATUS_SUCCESS && info && p && m) {
1563+ static_assert (AP_.kMetadataSize == 0 , " Expression below requires this" );
1564+ info->agentBaseAddress = reinterpret_cast <void *>(
1565+ reinterpret_cast <uptr>(info->agentBaseAddress ) + kPageSize_ );
1566+ info->hostBaseAddress = reinterpret_cast <void *>(
1567+ reinterpret_cast <uptr>(info->hostBaseAddress ) + kPageSize_ );
1568+ info->sizeInBytes = m->UsedSize ();
1569+ }
1570+ return status;
1571+ }
1572+
15501573} // namespace __asan
15511574#endif
0 commit comments