mirror of
https://github.com/golang/go
synced 2024-11-23 16:20:04 -07:00
runtime: fix -d=checkptr failure for testing/quick
This CL extends checkptrBase to recognize pointers into the stack and data/bss sections. I was meaning to do this eventually anyway, but it's also an easy way to workaround #35068. Updates #35068. Change-Id: Ib47f0aa800473a4fbc249da52ff03bec32c3ebe2 Reviewed-on: https://go-review.googlesource.com/c/go/+/202639 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
7d84245a9c
commit
5a5854c2d1
@ -64,9 +64,41 @@ func checkptrArithmetic(p unsafe.Pointer, originals []unsafe.Pointer) {
|
||||
panic(ptrArithError{p, originals})
|
||||
}
|
||||
|
||||
// checkptrBase returns the base address for the allocation containing
|
||||
// the address p.
|
||||
//
|
||||
// Importantly, if p1 and p2 point into the same variable, then
|
||||
// checkptrBase(p1) == checkptrBase(p2). However, the converse/inverse
|
||||
// is not necessarily true as allocations can have trailing padding,
|
||||
// and multiple variables may be packed into a single allocation.
|
||||
func checkptrBase(p unsafe.Pointer) uintptr {
|
||||
base, _, _ := findObject(uintptr(p), 0, 0)
|
||||
// TODO(mdempsky): If base == 0, then check if p points to the
|
||||
// stack or a global variable.
|
||||
// stack
|
||||
if gp := getg(); gp.stack.lo <= uintptr(p) && uintptr(p) < gp.stack.hi {
|
||||
// TODO(mdempsky): Walk the stack to identify the
|
||||
// specific stack frame or even stack object that p
|
||||
// points into.
|
||||
//
|
||||
// In the mean time, use "1" as a pseudo-address to
|
||||
// represent the stack. This is an invalid address on
|
||||
// all platforms, so it's guaranteed to be distinct
|
||||
// from any of the addresses we might return below.
|
||||
return 1
|
||||
}
|
||||
|
||||
// heap (must check after stack because of #35068)
|
||||
if base, _, _ := findObject(uintptr(p), 0, 0); base != 0 {
|
||||
return base
|
||||
}
|
||||
|
||||
// data or bss
|
||||
for _, datap := range activeModules() {
|
||||
if datap.data <= uintptr(p) && uintptr(p) < datap.edata {
|
||||
return datap.data
|
||||
}
|
||||
if datap.bss <= uintptr(p) && uintptr(p) < datap.ebss {
|
||||
return datap.bss
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user