Debian Codegraph @

internal/engine/wazevo/wazevoapi/ptr.go

raw
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 warns as "checkptr: pointer arithmetic result points to invalid allocation"
12 // https://github.com/golang/go/blob/go1.24.0/src/runtime/checkptr.go#L69
13 var wrapped *uintptr = &ptr
14 return *(**T)(unsafe.Pointer(wrapped))
15 }