github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/arch/syscalls_amd64.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // +build amd64 16 17 package arch 18 19 const restartSyscallNr = uintptr(219) 20 21 // SyscallSaveOrig save the value of the register which is clobbered in 22 // syscall handler(doSyscall()). 23 // 24 // Noop on x86. 25 func (c *context64) SyscallSaveOrig() { 26 } 27 28 // SyscallNo returns the syscall number according to the 64-bit convention. 29 func (c *context64) SyscallNo() uintptr { 30 return uintptr(c.Regs.Orig_rax) 31 } 32 33 // SyscallArgs provides syscall arguments according to the 64-bit convention. 34 // 35 // Due to the way addresses are mapped for the sentry this binary *must* be 36 // built in 64-bit mode. So we can just assume the syscall numbers that come 37 // back match the expected host system call numbers. 38 func (c *context64) SyscallArgs() SyscallArguments { 39 return SyscallArguments{ 40 SyscallArgument{Value: uintptr(c.Regs.Rdi)}, 41 SyscallArgument{Value: uintptr(c.Regs.Rsi)}, 42 SyscallArgument{Value: uintptr(c.Regs.Rdx)}, 43 SyscallArgument{Value: uintptr(c.Regs.R10)}, 44 SyscallArgument{Value: uintptr(c.Regs.R8)}, 45 SyscallArgument{Value: uintptr(c.Regs.R9)}, 46 } 47 } 48 49 // RestartSyscall implements Context.RestartSyscall. 50 func (c *context64) RestartSyscall() { 51 c.Regs.Rip -= SyscallWidth 52 c.Regs.Rax = c.Regs.Orig_rax 53 } 54 55 // RestartSyscallWithRestartBlock implements Context.RestartSyscallWithRestartBlock. 56 func (c *context64) RestartSyscallWithRestartBlock() { 57 c.Regs.Rip -= SyscallWidth 58 c.Regs.Rax = uint64(restartSyscallNr) 59 }