// DisableFlags disables the terminal flags specified in the function // argument 'flags', and returns the previous state of the terminal // so that it can be restored. func DisableFlags(fd FileDescriptor, flags Flag) (*State, error) { var oldState State if _, _, err := unix.Syscall6(unix.SYS_IOCTL, fd.Fd(), ioctlReadTermios, uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 { return nil, err } newState := oldState.termios newState.Lflag &^= uint32(flags) if _, _, err := unix.Syscall6(unix.SYS_IOCTL, fd.Fd(), ioctlWriteTermios, uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 { return nil, err } return &oldState, nil }
func PtraceDetach(tid, sig int) error { _, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PT_DETACH, uintptr(tid), 1, uintptr(sig), 0, 0) if err != syscall.Errno(0) { return err } return nil }
func PtraceSingleStep(tid int) error { _, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PT_STEP, uintptr(tid), 1, 0, 0, 0) if err != syscall.Errno(0) { return err } return nil }
func PtraceCont(tid, sig int) error { _, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PTRACE_CONT, uintptr(tid), 1, uintptr(sig), 0, 0) if err != syscall.Errno(0) { return err } return nil }
func getxattr(path string, attr string, dest []byte) (sz int, err error) { var _p0 *byte _p0, err = unix.BytePtrFromString(path) if err != nil { return } var _p1 *byte _p1, err = unix.BytePtrFromString(attr) if err != nil { return } var _p2 unsafe.Pointer if len(dest) > 0 { _p2 = unsafe.Pointer(&dest[0]) } else { _p2 = unsafe.Pointer(&_zero) } r0, _, e1 := unix.Syscall6(unix.SYS_GETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0) use(unsafe.Pointer(_p0)) use(unsafe.Pointer(_p1)) sz = int(r0) if e1 != 0 { err = syscall.Errno(e1) } return }
// PtracePokeUser execute ptrace PTRACE_POKE_USER. func PtracePokeUser(tid int, off, addr uintptr) error { _, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PTRACE_POKEUSR, uintptr(tid), uintptr(off), uintptr(addr), 0, 0) if err != syscall.Errno(0) { return err } return nil }
func setxattr(path string, attr string, data []byte, flags int) (err error) { var _p0 *byte _p0, err = unix.BytePtrFromString(path) if err != nil { return } var _p1 *byte _p1, err = unix.BytePtrFromString(attr) if err != nil { return } var _p2 unsafe.Pointer if len(data) > 0 { _p2 = unsafe.Pointer(&data[0]) } else { _p2 = unsafe.Pointer(&_zero) } _, _, e1 := unix.Syscall6(unix.SYS_SETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0) use(unsafe.Pointer(_p0)) use(unsafe.Pointer(_p1)) if e1 != 0 { err = syscall.Errno(e1) } return }
func Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error) { oldPtr, err := unix.BytePtrFromString(oldpath) if err != nil { return } newPtr, err := unix.BytePtrFromString(newpath) if err != nil { return } _, _, errno := unix.Syscall6( SYS_RENAMEAT2, uintptr(olddirfd), uintptr(unsafe.Pointer(oldPtr)), uintptr(newdirfd), uintptr(unsafe.Pointer(newPtr)), uintptr(flags), 0, ) use(unsafe.Pointer(oldPtr)) use(unsafe.Pointer(newPtr)) if errno != 0 { // In the syscall module the authors box a couple of common errors // (i.e EAGAIN, EINVAL, and ENOENT). Is that worth doing here? err = errno } return }
func getTTYWidth() int { var fd uintptr fh, err := os.Open("/dev/tty") if err == nil { fd = fh.Fd() defer fh.Close() } else { fd = uintptr(unix.Stdin) } var dimensions [4]uint16 if _, _, err := unix.Syscall6(unix.SYS_IOCTL, fd, uintptr(unix.TIOCGWINSZ), uintptr(unsafe.Pointer(&dimensions)), 0, 0, 0); err != 0 { return 0 } return int(dimensions[1]) }
func listxattr(path string, dest []byte, flags int) (sz int, err error) { var _p0 *byte _p0, err = unix.BytePtrFromString(path) if err != nil { return } var _p1 unsafe.Pointer if len(dest) > 0 { _p1 = unsafe.Pointer(&dest[0]) } else { _p1 = unsafe.Pointer(&_zero) } r0, _, e1 := unix.Syscall6(unix.SYS_LISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)), uintptr(flags), 0, 0) use(unsafe.Pointer(_p0)) sz = int(r0) if e1 != 0 { err = syscall.Errno(e1) } return }
// Restore restores the terminal connected to the given file descriptor to a // previous state. func Restore(fd FileDescriptor, state *State) error { _, _, err := unix.Syscall6(unix.SYS_IOCTL, fd.Fd(), ioctlWriteTermios, uintptr(unsafe.Pointer(&state.termios)), 0, 0, 0) return err }
// IsTerminal returns true if the given file descriptor is a terminal. func IsTerminal(fd FileDescriptor) bool { var termios unix.Termios _, _, err := unix.Syscall6(unix.SYS_IOCTL, fd.Fd(), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0) return err == 0 }
func ptrace(request, pid int, addr uintptr, data uintptr) (err error) { _, _, err = sys.Syscall6(sys.SYS_PTRACE, uintptr(request), uintptr(pid), uintptr(addr), uintptr(data), 0, 0) return }