Allow the user to construct slices that are larger than the Go heap as
long as they don't overflow the address space.
Updates #48798.
Change-Id: I659c8334d04676e1f253b9c3cd499eab9b9f989a
Reviewed-on: https://go-review.googlesource.com/c/go/+/355489
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
}
mem, overflow := math.MulUintptr(et.size, uintptr(len))
- if overflow || mem > maxAlloc || len < 0 {
+ if overflow || mem > -uintptr(ptr) || len < 0 {
panicunsafeslicelen()
}
}
// size overflows address space
mustPanic(func() { _ = unsafe.Slice(new(uint64), maxUintptr/8) })
mustPanic(func() { _ = unsafe.Slice(new(uint64), maxUintptr/8+1) })
+
+ // sliced memory overflows address space
+ last := (*byte)(unsafe.Pointer(^uintptr(0)))
+ _ = unsafe.Slice(last, 1)
+ mustPanic(func() { _ = unsafe.Slice(last, 2) })
}
}