(*[2]uint64)(x)[1] = 0
// See if we need to replace the existing tiny block with the new one
// based on amount of remaining free space.
- if size < c.tinyoffset || c.tiny == 0 {
+ if !raceenabled && (size < c.tinyoffset || c.tiny == 0) {
+ // Note: disabled when race detector is on, see comment near end of this function.
c.tiny = uintptr(x)
c.tinyoffset = size
}
}
}
+ if raceenabled && noscan && dataSize < maxTinySize {
+ // Pad tinysize allocations so they are aligned with the end
+ // of the tinyalloc region. This ensures that any arithmetic
+ // that goes off the top end of the object will be detectable
+ // by checkptr (issue 38872).
+ // Note that we disable tinyalloc when raceenabled for this to work.
+ // TODO: This padding is only performed when the race detector
+ // is enabled. It would be nice to enable it if any package
+ // was compiled with checkptr, but there's no easy way to
+ // detect that (especially at compile time).
+ // TODO: enable this padding for all allocations, not just
+ // tinyalloc ones. It's tricky because of pointer maps.
+ // Maybe just all noscan objects?
+ x = add(x, size-dataSize)
+ }
+
return x
}
}
func TestTinyAlloc(t *testing.T) {
+ if runtime.Raceenabled {
+ t.Skip("tinyalloc suppressed when running in race mode")
+ }
const N = 16
var v [N]unsafe.Pointer
for i := range v {
}
func TestTinyAllocIssue37262(t *testing.T) {
+ if runtime.Raceenabled {
+ t.Skip("tinyalloc suppressed when running in race mode")
+ }
// Try to cause an alignment access fault
// by atomically accessing the first 64-bit
// value of a tiny-allocated object.