mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: separate error result for mmap
Currently mmap returns an unsafe.Pointer that encodes OS errors as values less than 4096. In practice this is okay, but it borders on being really unsafe: for example, the value has to be checked immediately after return and if stack copying were ever to observe such a value, it would panic. It's also not remotely idiomatic. Fix this by making mmap return a separate pointer value and error, like a normal Go function. Updates #22218. Change-Id: Iefd965095ffc82cc91118872753a5d39d785c3a6 Reviewed-on: https://go-review.googlesource.com/71270 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
3ba818c894
commit
193088b246
35 changed files with 237 additions and 103 deletions
|
|
@ -402,12 +402,12 @@ func madvise(addr unsafe.Pointer, n uintptr, flags int32) {
|
|||
}
|
||||
|
||||
//go:nosplit
|
||||
func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer {
|
||||
func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (unsafe.Pointer, int) {
|
||||
p, err := doMmap(uintptr(addr), n, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(off))
|
||||
if p == ^uintptr(0) {
|
||||
return unsafe.Pointer(err)
|
||||
return nil, int(err)
|
||||
}
|
||||
return unsafe.Pointer(p)
|
||||
return unsafe.Pointer(p), 0
|
||||
}
|
||||
|
||||
//go:nosplit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue