github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/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  //go:build amd64
    16  // +build amd64
    17  
    18  package arch
    19  
    20  const restartSyscallNr = uintptr(219)
    21  
    22  // SyscallSaveOrig save the value of the register which is clobbered in
    23  // syscall handler(doSyscall()).
    24  //
    25  // Noop on x86.
    26  func (c *Context64) SyscallSaveOrig() {
    27  }
    28  
    29  // SyscallNo returns the syscall number according to the 64-bit convention.
    30  func (c *Context64) SyscallNo() uintptr {
    31  	return uintptr(c.Regs.Orig_rax)
    32  }
    33  
    34  // SyscallArgs provides syscall arguments according to the 64-bit convention.
    35  //
    36  // Due to the way addresses are mapped for the sentry this binary *must* be
    37  // built in 64-bit mode. So we can just assume the syscall numbers that come
    38  // back match the expected host system call numbers.
    39  func (c *Context64) SyscallArgs() SyscallArguments {
    40  	return SyscallArguments{
    41  		SyscallArgument{Value: uintptr(c.Regs.Rdi)},
    42  		SyscallArgument{Value: uintptr(c.Regs.Rsi)},
    43  		SyscallArgument{Value: uintptr(c.Regs.Rdx)},
    44  		SyscallArgument{Value: uintptr(c.Regs.R10)},
    45  		SyscallArgument{Value: uintptr(c.Regs.R8)},
    46  		SyscallArgument{Value: uintptr(c.Regs.R9)},
    47  	}
    48  }
    49  
    50  // RestartSyscall implements Context.RestartSyscall.
    51  func (c *Context64) RestartSyscall() {
    52  	c.Regs.Rip -= SyscallWidth
    53  	c.Regs.Rax = c.Regs.Orig_rax
    54  }
    55  
    56  // RestartSyscallWithRestartBlock implements Context.RestartSyscallWithRestartBlock.
    57  func (c *Context64) RestartSyscallWithRestartBlock() {
    58  	c.Regs.Rip -= SyscallWidth
    59  	c.Regs.Rax = uint64(restartSyscallNr)
    60  }