github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/sentry/fsimpl/host/ioctl_unsafe.go (about)

     1  // Copyright 2020 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  package host
    16  
    17  import (
    18  	"unsafe"
    19  
    20  	"golang.org/x/sys/unix"
    21  	"github.com/metacubex/gvisor/pkg/abi/linux"
    22  )
    23  
    24  func ioctlGetTermios(fd int) (*linux.Termios, error) {
    25  	var t linux.Termios
    26  	_, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), linux.TCGETS, uintptr(unsafe.Pointer(&t)))
    27  	if errno != 0 {
    28  		return nil, errno
    29  	}
    30  	return &t, nil
    31  }
    32  
    33  func ioctlSetTermios(fd int, req uint64, t *linux.Termios) error {
    34  	_, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(unsafe.Pointer(t)))
    35  	if errno != 0 {
    36  		return errno
    37  	}
    38  	return nil
    39  }
    40  
    41  func ioctlGetWinsize(fd int) (*linux.Winsize, error) {
    42  	var w linux.Winsize
    43  	_, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), linux.TIOCGWINSZ, uintptr(unsafe.Pointer(&w)))
    44  	if errno != 0 {
    45  		return nil, errno
    46  	}
    47  	return &w, nil
    48  }
    49  
    50  func ioctlSetWinsize(fd int, w *linux.Winsize) error {
    51  	_, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), linux.TIOCSWINSZ, uintptr(unsafe.Pointer(w)))
    52  	if errno != 0 {
    53  		return errno
    54  	}
    55  	return nil
    56  }