github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/wazevoapi/ptr.go (about) 1 package wazevoapi 2 3 import "unsafe" 4 5 // PtrFromUintptr resurrects the original *T from the given uintptr. 6 // The caller of this function MUST be sure that ptr is valid. 7 func PtrFromUintptr[T any](ptr uintptr) *T { 8 // Wraps ptrs as the double pointer in order to avoid the unsafe access as detected by race detector. 9 // 10 // For example, if we have (*function)(unsafe.Pointer(ptr)) instead, then the race detector's "checkptr" 11 // subroutine wanrs as "checkptr: pointer arithmetic result points to invalid allocation" 12 // https://github.com/golang/go/blob/1ce7fcf139417d618c2730010ede2afb41664211/src/runtime/checkptr.go#L69 13 var wrapped *uintptr = &ptr 14 return *(**T)(unsafe.Pointer(wrapped)) 15 }