mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
Since `arch.Context64` is the only concrete implementation of `arch.Context`, this does not functionally change anything. While `arch.Context64` *can* mean multiple things in the codebase, since the `arch` module uses conditional compilation to create different builds for AMD64 vs ARM64, the `Context64` type is still singular within each possible version this can compile to. This avoids the overhead involved in calling interface functions in Go: https://github.com/teh-cmc/go-internals/blob/master/chapter2_interfaces/README.md#dynamic-dispatch This overhead is particularly painful for functions like `SyscallSaveOrig` which is a no-op on AMD64. On KVM, this reduces syscall latency by 4~5%: ``` name old wall_ns/op new wall_ns/op delta Getpid 602 ± 4% 579 ± 3% -3.94% (p=0.000 n=66+195) GetpidOpt 604 ± 3% 573 ± 3% -5.10% (p=0.000 n=71+194) name old cpu_ns/op new cpu_ns/op delta Getpid 604 ± 5% 581 ± 0% -3.81% (p=0.000 n=75+130) GetpidOpt 604 ± 2% 574 ± 3% -4.95% (p=0.000 n=71+196) ``` PiperOrigin-RevId: 461742893
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
// Copyright 2018 The gVisor Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
//go:build amd64
|
|
// +build amd64
|
|
|
|
package arch
|
|
|
|
const restartSyscallNr = uintptr(219)
|
|
|
|
// SyscallSaveOrig save the value of the register which is clobbered in
|
|
// syscall handler(doSyscall()).
|
|
//
|
|
// Noop on x86.
|
|
func (c *Context64) SyscallSaveOrig() {
|
|
}
|
|
|
|
// SyscallNo returns the syscall number according to the 64-bit convention.
|
|
func (c *Context64) SyscallNo() uintptr {
|
|
return uintptr(c.Regs.Orig_rax)
|
|
}
|
|
|
|
// SyscallArgs provides syscall arguments according to the 64-bit convention.
|
|
//
|
|
// Due to the way addresses are mapped for the sentry this binary *must* be
|
|
// built in 64-bit mode. So we can just assume the syscall numbers that come
|
|
// back match the expected host system call numbers.
|
|
func (c *Context64) SyscallArgs() SyscallArguments {
|
|
return SyscallArguments{
|
|
SyscallArgument{Value: uintptr(c.Regs.Rdi)},
|
|
SyscallArgument{Value: uintptr(c.Regs.Rsi)},
|
|
SyscallArgument{Value: uintptr(c.Regs.Rdx)},
|
|
SyscallArgument{Value: uintptr(c.Regs.R10)},
|
|
SyscallArgument{Value: uintptr(c.Regs.R8)},
|
|
SyscallArgument{Value: uintptr(c.Regs.R9)},
|
|
}
|
|
}
|
|
|
|
// RestartSyscall implements Context.RestartSyscall.
|
|
func (c *Context64) RestartSyscall() {
|
|
c.Regs.Rip -= SyscallWidth
|
|
c.Regs.Rax = c.Regs.Orig_rax
|
|
}
|
|
|
|
// RestartSyscallWithRestartBlock implements Context.RestartSyscallWithRestartBlock.
|
|
func (c *Context64) RestartSyscallWithRestartBlock() {
|
|
c.Regs.Rip -= SyscallWidth
|
|
c.Regs.Rax = uint64(restartSyscallNr)
|
|
}
|