diff options
Diffstat (limited to 'src/runtime/mfinal.go')
| -rw-r--r-- | src/runtime/mfinal.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/runtime/mfinal.go b/src/runtime/mfinal.go index 18cd93e77e..be501e6fca 100644 --- a/src/runtime/mfinal.go +++ b/src/runtime/mfinal.go @@ -9,6 +9,7 @@ package runtime import ( "internal/abi" "internal/goarch" + "internal/goexperiment" "runtime/internal/atomic" "runtime/internal/sys" "unsafe" @@ -410,7 +411,7 @@ func SetFinalizer(obj any, finalizer any) { } // find the containing object - base, _, _ := findObject(uintptr(e.data), 0, 0) + base, span, _ := findObject(uintptr(e.data), 0, 0) if base == 0 { if isGoPointerWithoutSpan(e.data) { @@ -419,6 +420,11 @@ func SetFinalizer(obj any, finalizer any) { throw("runtime.SetFinalizer: pointer not in allocated block") } + // Move base forward if we've got an allocation header. + if goexperiment.AllocHeaders && !span.spanclass.noscan() && !heapBitsInSpan(span.elemsize) && span.spanclass.sizeclass() != 0 { + base += mallocHeaderSize + } + if uintptr(e.data) != base { // As an implementation detail we allow to set finalizers for an inner byte // of an object if it could come from tiny alloc (see mallocgc for details). |
