diff options
Diffstat (limited to 'src/syscall/syscall_linux.go')
-rw-r--r-- | src/syscall/syscall_linux.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go index 74322caea1..f9adecdd5e 100644 --- a/src/syscall/syscall_linux.go +++ b/src/syscall/syscall_linux.go @@ -16,6 +16,78 @@ import ( "unsafe" ) +// N.B. RawSyscall6 is provided via linkname by runtime/internal/syscall. +// +// Errno is uintptr and thus compatible with the runtime/internal/syscall +// definition. + +func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) + +// Pull in entersyscall/exitsyscall for Syscall/Syscall6. +// +// Note that this can't be a push linkname because the runtime already has a +// nameless linkname to export to assembly here and in x/sys. Additionally, +// entersyscall fetches the caller PC and SP and thus can't have a wrapper +// inbetween. + +//go:linkname runtime_entersyscall runtime.entersyscall +func runtime_entersyscall() +//go:linkname runtime_exitsyscall runtime.exitsyscall +func runtime_exitsyscall() + +// N.B. For the Syscall functions below: +// +// //go:uintptrkeepalive because the uintptr argument may be converted pointers +// that need to be kept alive in the caller (this is implied for RawSyscall6 +// since it has no body). +// +// //go:nosplit because stack copying does not account for uintptrkeepalive, so +// the stack must not grow. Stack copying cannot blindly assume that all +// uintptr arguments are pointers, because some values may look like pointers, +// but not really be pointers, and adjusting their value would break the call. +// +// //go:linkname to ensure ABI wrappers are generated for external callers +// (notably x/sys/unix assembly). + +//go:uintptrkeepalive +//go:nosplit +//go:linkname RawSyscall +func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) { + return RawSyscall6(trap, a1, a2, a3, 0, 0, 0) +} + +//go:uintptrkeepalive +//go:nosplit +//go:linkname Syscall +func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) { + runtime_entersyscall() + // N.B. Calling RawSyscall here is unsafe with atomic coverage + // instrumentation and race mode. + // + // Coverage instrumentation will add a sync/atomic call to RawSyscall. + // Race mode will add race instrumentation to sync/atomic. Race + // instrumentation requires a P, which we no longer have. + // + // RawSyscall6 is fine because it is implemented in assembly and thus + // has no coverage instrumentation. + // + // This is typically not a problem in the runtime because cmd/go avoids + // adding coverage instrumentation to the runtime in race mode. + r1, r2, err = RawSyscall6(trap, a1, a2, a3, 0, 0, 0) + runtime_exitsyscall() + return +} + +//go:uintptrkeepalive +//go:nosplit +//go:linkname Syscall6 +func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) { + runtime_entersyscall() + r1, r2, err = RawSyscall6(trap, a1, a2, a3, a4, a5, a6) + runtime_exitsyscall() + return +} + func rawSyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr) /* |