mirror of
https://github.com/golang/go
synced 2024-11-18 08:14:41 -07:00
cmd/link/internal/ld, syscall: use libc based msync on darwin for Go ≥ 1.20
Direct syscalls should no longer be used on darwin. Instead, directly call libc's msync when using Go ≥ 1.20 for bootstrap. For #54265 Change-Id: Ie3f1e6ccd1a06e7f0ddd88cdef5067393a69e8db Reviewed-on: https://go-review.googlesource.com/c/go/+/430336 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
parent
8df21a7802
commit
d36466fe2a
12
src/cmd/link/internal/ld/msync_darwin_libc.go
Normal file
12
src/cmd/link/internal/ld/msync_darwin_libc.go
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build darwin && go1.20
|
||||
|
||||
package ld
|
||||
|
||||
import _ "unsafe" // for go:linkname
|
||||
|
||||
//go:linkname msync syscall.msync
|
||||
func msync(b []byte, flags int) (err error)
|
24
src/cmd/link/internal/ld/msync_darwin_syscall.go
Normal file
24
src/cmd/link/internal/ld/msync_darwin_syscall.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build darwin && !go1.20
|
||||
|
||||
package ld
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func msync(b []byte, flags int) (err error) {
|
||||
var p unsafe.Pointer
|
||||
if len(b) > 0 {
|
||||
p = unsafe.Pointer(&b[0])
|
||||
}
|
||||
_, _, errno := syscall.Syscall(syscall.SYS_MSYNC, uintptr(p), uintptr(len(b)), uintptr(flags))
|
||||
if errno != 0 {
|
||||
return errno
|
||||
}
|
||||
return nil
|
||||
}
|
@ -43,6 +43,6 @@ func (out *OutBuf) purgeSignatureCache() {
|
||||
// When we mmap the output buffer, it doesn't have a code signature
|
||||
// (as we haven't generated one). Invalidate the kernel cache now that
|
||||
// we have generated the signature. See issue #42684.
|
||||
syscall.Syscall(syscall.SYS_MSYNC, uintptr(unsafe.Pointer(&out.buf[0])), uintptr(len(out.buf)), syscall.MS_INVALIDATE)
|
||||
msync(out.buf, syscall.MS_INVALIDATE)
|
||||
// Best effort. Ignore error.
|
||||
}
|
||||
|
@ -171,6 +171,7 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1)
|
||||
//sys Mlock(b []byte) (err error)
|
||||
//sys Mlockall(flags int) (err error)
|
||||
//sys Mprotect(b []byte, prot int) (err error)
|
||||
//sys msync(b []byte, flags int) (err error)
|
||||
//sys Munlock(b []byte) (err error)
|
||||
//sys Munlockall() (err error)
|
||||
//sys Open(path string, mode int, perm uint32) (fd int, err error)
|
||||
|
@ -1063,6 +1063,26 @@ func libc_mprotect_trampoline()
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func msync(b []byte, flags int) (err error) {
|
||||
var _p0 unsafe.Pointer
|
||||
if len(b) > 0 {
|
||||
_p0 = unsafe.Pointer(&b[0])
|
||||
} else {
|
||||
_p0 = unsafe.Pointer(&_zero)
|
||||
}
|
||||
_, _, e1 := syscall(abi.FuncPCABI0(libc_msync_trampoline), uintptr(_p0), uintptr(len(b)), uintptr(flags))
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func libc_msync_trampoline()
|
||||
|
||||
//go:cgo_import_dynamic libc_msync msync "/usr/lib/libSystem.B.dylib"
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func Munlock(b []byte) (err error) {
|
||||
var _p0 unsafe.Pointer
|
||||
if len(b) > 0 {
|
||||
|
@ -143,6 +143,8 @@ TEXT ·libc_mlockall_trampoline(SB),NOSPLIT,$0-0
|
||||
JMP libc_mlockall(SB)
|
||||
TEXT ·libc_mprotect_trampoline(SB),NOSPLIT,$0-0
|
||||
JMP libc_mprotect(SB)
|
||||
TEXT ·libc_msync_trampoline(SB),NOSPLIT,$0-0
|
||||
JMP libc_msync(SB)
|
||||
TEXT ·libc_munlock_trampoline(SB),NOSPLIT,$0-0
|
||||
JMP libc_munlock(SB)
|
||||
TEXT ·libc_munlockall_trampoline(SB),NOSPLIT,$0-0
|
||||
|
@ -1063,6 +1063,26 @@ func libc_mprotect_trampoline()
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func msync(b []byte, flags int) (err error) {
|
||||
var _p0 unsafe.Pointer
|
||||
if len(b) > 0 {
|
||||
_p0 = unsafe.Pointer(&b[0])
|
||||
} else {
|
||||
_p0 = unsafe.Pointer(&_zero)
|
||||
}
|
||||
_, _, e1 := syscall(abi.FuncPCABI0(libc_msync_trampoline), uintptr(_p0), uintptr(len(b)), uintptr(flags))
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func libc_msync_trampoline()
|
||||
|
||||
//go:cgo_import_dynamic libc_msync msync "/usr/lib/libSystem.B.dylib"
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func Munlock(b []byte) (err error) {
|
||||
var _p0 unsafe.Pointer
|
||||
if len(b) > 0 {
|
||||
|
@ -143,6 +143,8 @@ TEXT ·libc_mlockall_trampoline(SB),NOSPLIT,$0-0
|
||||
JMP libc_mlockall(SB)
|
||||
TEXT ·libc_mprotect_trampoline(SB),NOSPLIT,$0-0
|
||||
JMP libc_mprotect(SB)
|
||||
TEXT ·libc_msync_trampoline(SB),NOSPLIT,$0-0
|
||||
JMP libc_msync(SB)
|
||||
TEXT ·libc_munlock_trampoline(SB),NOSPLIT,$0-0
|
||||
JMP libc_munlock(SB)
|
||||
TEXT ·libc_munlockall_trampoline(SB),NOSPLIT,$0-0
|
||||
|
Loading…
Reference in New Issue
Block a user