mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +00:00
runtime: call mmap with MAP_FIXED on BSDs in race mode
This change makes it so that reserving more of the address space for the heap calls mmap with MAP_FIXED in race mode. Race mode requires certain guarantees on where the heap is located in the address space, and on Darwin 10.10 it appears that the kernel may end up ignoring the hint quite often (#26475). Using MAP_FIXED is relatively OK in race mode because nothing else should be mapped in the memory region provided by the initial hints. Fixes #26475. Change-Id: Id7ac1534ee74f6de491bc04441f27dbda09f0285 Reviewed-on: https://go-review.googlesource.com/c/153897 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
d689946302
commit
7ef718f16f
|
@ -42,7 +42,19 @@ func sysFault(v unsafe.Pointer, n uintptr) {
|
|||
}
|
||||
|
||||
func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
|
||||
p, err := mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
|
||||
flags := int32(_MAP_ANON | _MAP_PRIVATE)
|
||||
if raceenabled {
|
||||
// Currently the race detector expects memory to live within a certain
|
||||
// range, and on Darwin 10.10 mmap is prone to ignoring hints, moreso
|
||||
// than later versions and other BSDs (#26475). So, even though it's
|
||||
// potentially dangerous to MAP_FIXED, we do it in the race detection
|
||||
// case because it'll help maintain the race detector's invariants.
|
||||
//
|
||||
// TODO(mknyszek): Drop this once support for Darwin 10.10 is dropped,
|
||||
// and reconsider this when #24133 is addressed.
|
||||
flags |= _MAP_FIXED
|
||||
}
|
||||
p, err := mmap(v, n, _PROT_NONE, flags, -1, 0)
|
||||
if err != 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue