From 3fa7d6cc40675dca9a5d3ef0005e158d91df104b Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Mon, 31 Jan 2022 10:31:57 -0800 Subject: [PATCH] src/runtime: assert that a gc block addr isn't inside the metadata --- src/runtime/gc_conservative.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/runtime/gc_conservative.go b/src/runtime/gc_conservative.go index ae675be18..b1ac1eb4d 100644 --- a/src/runtime/gc_conservative.go +++ b/src/runtime/gc_conservative.go @@ -110,7 +110,11 @@ func (b gcBlock) pointer() unsafe.Pointer { // Return the address of the start of the allocated object. func (b gcBlock) address() uintptr { - return heapStart + uintptr(b)*bytesPerBlock + addr := heapStart + uintptr(b)*bytesPerBlock + if gcAsserts && addr > uintptr(metadataStart) { + runtimePanic("gc: block pointing inside metadata") + } + return addr } // findHead returns the head (first block) of an object, assuming the block