syscall

package
v0.0.0-...-833ed6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2019 License: GPL-2.0, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package syscall contains an interface to the low-level operating system primitives. The details vary depending on the underlying system, and by default, godoc will display the syscall documentation for the current system. If you want godoc to display syscall documentation for another system, set $GOOS and $GOARCH to the desired system. For example, if you want to view documentation for freebsd/arm on linux/amd64, set $GOOS to freebsd and $GOARCH to arm. The primary use of syscall is inside other packages that provide a more portable interface to the system, such as "os", "time" and "net". Use those packages rather than this one if you can. For details of the functions and data types in this package consult the manuals for the appropriate operating system. These calls return err == nil to indicate success; otherwise err is an operating system error describing the failure. On most systems, that error has type syscall.Errno.

Deprecated: this package is locked down. Callers should use the corresponding package in the golang.org/x/sys repository instead. That is also where updates required by new systems or versions should be applied. See https://golang.org/s/go1.4-syscall for more information.

Index

Constants

View Source
const ImplementsGetwd = true
View Source
const SizeofSockaddrAny = 0x6c
View Source
const SizeofSockaddrInet4 = 16
View Source
const SizeofSockaddrInet6 = 28
View Source
const SizeofSockaddrLinklayer = 20
View Source
const SizeofSockaddrNetlink = 12
View Source
const SizeofSockaddrUnix = 110

Variables

View Source
var (
	Stdin  = 0
	Stdout = 1
	Stderr = 2
)
View Source
var ForkLock sync.RWMutex
View Source
var SocketDisableIPv6 bool

For testing: clients can set this flag to force creation of IPv6 sockets to return EAFNOSUPPORT.

Functions

func AttachLsf deprecated

func AttachLsf(fd int, i []SockFilter) error

Deprecated: Use golang.org/x/net/bpf instead.

func Bind

func Bind(fd int, sa Sockaddr) (err error)

func BindToDevice

func BindToDevice(fd int, device string) (err error)

BindToDevice binds the socket associated with fd to device.

func BytePtrFromString

func BytePtrFromString(s string) (*byte, error)

BytePtrFromString returns a pointer to a NUL-terminated array of bytes containing the text of s. If s contains a NUL byte at any location, it returns (nil, EINVAL).

func ByteSliceFromString

func ByteSliceFromString(s string) ([]byte, error)

ByteSliceFromString returns a NUL-terminated slice of bytes containing the text of s. If s contains a NUL byte at any location, it returns (nil, EINVAL).

func Cgocall

func Cgocall()

These functions are used by CGO and SWIG.

func CgocallBack

func CgocallBack()

func CgocallBackDone

func CgocallBackDone()

func CgocallDone

func CgocallDone()

func Clearenv

func Clearenv()

func CloseOnExec

func CloseOnExec(fd int)

func CmsgLen

func CmsgLen(datalen int) int

CmsgLen returns the value to store in the Len field of the Cmsghdr structure, taking into account any necessary alignment.

func CmsgSpace

func CmsgSpace(datalen int) int

CmsgSpace returns the number of bytes an ancillary element with payload of the passed data length occupies.

func Connect

func Connect(fd int, sa Sockaddr) (err error)

func DetachLsf deprecated

func DetachLsf(fd int) error

Deprecated: Use golang.org/x/net/bpf instead.

func Entersyscall

func Entersyscall()

func Environ

func Environ() []string

func Errstr

func Errstr(errnum int) string

func Exec

func Exec(argv0 string, argv []string, envv []string) (err error)

Exec invokes the execve(2) system call.

func Exit

func Exit(code int)

func Exitsyscall

func Exitsyscall()

func FDClr

func FDClr(fd int, set *FdSet)

func FDIsSet

func FDIsSet(fd int, set *FdSet) bool

func FDSet

func FDSet(fd int, set *FdSet)

func FDZero

func FDZero(set *FdSet)

func ForkExec

func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)

Combination of fork and exec, careful to be thread safe.

func Futimes

func Futimes(fd int, tv []Timeval) (err error)

func Futimesat

func Futimesat(dirfd int, path string, tv []Timeval) (err error)

sys futimesat(dirfd int, path *byte, times *[2]Timeval) (err error) futimesat(dirfd _C_int, path *byte, times *[2]Timeval) _C_int

func Getcwd

func Getcwd(buf []byte) (n int, err error)

func Getdents

func Getdents(fd int, buf []byte) (n int, err error)

func Getenv

func Getenv(key string) (value string, found bool)

func Getgroups

func Getgroups() (gids []int, err error)

func Getpagesize

func Getpagesize() int

func GetsockoptByte

func GetsockoptByte(fd, level, opt int) (value byte, err error)

func GetsockoptInet4Addr

func GetsockoptInet4Addr(fd, level, opt int) (value [4]byte, err error)

func GetsockoptInt

func GetsockoptInt(fd, level, opt int) (value int, err error)

func Gettid

func Gettid() (tid int)

func Gettimeofday

func Gettimeofday(tv *Timeval) (err error)

sysnb gettimeofday(tv *Timeval, tz *byte) (err error) gettimeofday(tv *Timeval, tz *byte) _C_int

func Getwd

func Getwd() (ret string, err error)

func LsfSocket deprecated

func LsfSocket(ifindex, proto int) (int, error)

Deprecated: Use golang.org/x/net/bpf instead.

func Mmap

func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error)

func Munmap

func Munmap(b []byte) (err error)

func NetlinkRIB

func NetlinkRIB(proto, family int) ([]byte, error)

NetlinkRIB returns routing information base, as known as RIB, which consists of network facility information, states and parameters.

func ParseDirent

func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string)

ParseDirent parses up to max directory entries in buf, appending the names to names. It returns the number of bytes consumed from buf, the number of entries added to names, and the new names slice.

func ParseUnixRights

func ParseUnixRights(m *SocketControlMessage) ([]int, error)

ParseUnixRights decodes a socket control message that contains an integer array of open file descriptors from another process.

func Pipe

func Pipe(p []int) (err error)

sysnb pipe(p *[2]_C_int) (err error) pipe(p *[2]_C_int) _C_int

func Pipe2

func Pipe2(p []int, flags int) (err error)

sysnb pipe2(p *[2]_C_int, flags int) (err error) pipe2(p *[2]_C_int, flags _C_int) _C_int

func PtraceAttach

func PtraceAttach(pid int) (err error)

func PtraceCont

func PtraceCont(pid int, signal int) (err error)

func PtraceDetach

func PtraceDetach(pid int) (err error)

func PtraceGetEventMsg

func PtraceGetEventMsg(pid int) (msg uint, err error)

func PtraceGetRegs

func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error)

func PtracePeekData

func PtracePeekData(pid int, addr uintptr, out []byte) (count int, err error)

func PtracePeekText

func PtracePeekText(pid int, addr uintptr, out []byte) (count int, err error)

func PtracePokeData

func PtracePokeData(pid int, addr uintptr, data []byte) (count int, err error)

func PtracePokeText

func PtracePokeText(pid int, addr uintptr, data []byte) (count int, err error)

func PtraceSetOptions

func PtraceSetOptions(pid int, options int) (err error)

func PtraceSetRegs

func PtraceSetRegs(pid int, regs *PtraceRegs) (err error)

func PtraceSingleStep

func PtraceSingleStep(pid int) (err error)

func Read

func Read(fd int, p []byte) (n int, err error)

func ReadDirent

func ReadDirent(fd int, buf []byte) (n int, err error)

func Reboot

func Reboot(cmd int) (err error)

sys reboot(magic1 uint, magic2 uint, cmd int, arg string) (err error) reboot(magic1 _C_uint, magic2 _C_uint, cmd _C_int, arg *byte) _C_int

func Sendfile

func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)

sys sendfile(outfd int, infd int, offset *Offset_t, count int) (written int, err error) sendfile64(outfd _C_int, infd _C_int, offset *Offset_t, count Size_t) Ssize_t

func Sendmsg

func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error)

func SendmsgN

func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error)

func Sendto

func Sendto(fd int, p []byte, flags int, to Sockaddr) (err error)

func SetErrno

func SetErrno(Errno)

func SetLsfPromisc deprecated

func SetLsfPromisc(name string, m bool) error

Deprecated: Use golang.org/x/net/bpf instead.

func SetNonblock

func SetNonblock(fd int, nonblocking bool) (err error)

func Setenv

func Setenv(key, value string) error

func Setgroups

func Setgroups(gids []int) (err error)

func SetsockoptByte

func SetsockoptByte(fd, level, opt int, value byte) (err error)

func SetsockoptICMPv6Filter

func SetsockoptICMPv6Filter(fd, level, opt int, filter *ICMPv6Filter) error

func SetsockoptIPMreq

func SetsockoptIPMreq(fd, level, opt int, mreq *IPMreq) (err error)

func SetsockoptIPMreqn

func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error)

func SetsockoptIPv6Mreq

func SetsockoptIPv6Mreq(fd, level, opt int, mreq *IPv6Mreq) (err error)

func SetsockoptInet4Addr

func SetsockoptInet4Addr(fd, level, opt int, value [4]byte) (err error)

func SetsockoptInt

func SetsockoptInt(fd, level, opt int, value int) (err error)

func SetsockoptLinger

func SetsockoptLinger(fd, level, opt int, l *Linger) (err error)

func SetsockoptString

func SetsockoptString(fd, level, opt int, s string) (err error)

func SetsockoptTimeval

func SetsockoptTimeval(fd, level, opt int, tv *Timeval) (err error)

func Settimeofday

func Settimeofday(tv *Timeval) (err error)

func Signame

func Signame(s Signal) string

func Sleep

func Sleep(nsec int64) (err error)

func SlicePtrFromStrings

func SlicePtrFromStrings(ss []string) ([]*byte, error)

SlicePtrFromStrings converts a slice of strings to a slice of pointers to NUL-terminated byte arrays. If any string contains a NUL byte, it returns (nil, EINVAL).

func Socket

func Socket(domain, typ, proto int) (fd int, err error)

func Socketpair

func Socketpair(domain, typ, proto int) (fd [2]int, err error)

func Splice

func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)

sys splice(rfd int, roff *_loff_t, wfd int, woff *_loff_t, len int, flags int) (n int64, err error) splice(rfd _C_int, roff *_loff_t, wfd _C_int, woff *_loff_t, len Size_t, flags _C_uint) Ssize_t

func StartProcess

func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error)

StartProcess wraps ForkExec for package os.

func StringBytePtr deprecated

func StringBytePtr(s string) *byte

StringBytePtr returns a pointer to a NUL-terminated array of bytes. If s contains a NUL byte this function panics instead of returning an error.

Deprecated: Use BytePtrFromString instead.

func StringByteSlice deprecated

func StringByteSlice(s string) []byte

StringByteSlice converts a string to a NUL-terminated []byte, If s contains a NUL byte this function panics instead of returning an error.

Deprecated: Use ByteSliceFromString instead.

func StringSlicePtr deprecated

func StringSlicePtr(ss []string) []*byte

StringSlicePtr converts a slice of strings to a slice of pointers to NUL-terminated byte arrays. If any string contains a NUL byte this function panics instead of returning an error.

Deprecated: Use SlicePtrFromStrings instead.

func Sysconf

func Sysconf(name int) (ret int64, err error)

func Tgkill

func Tgkill(tgid int, tid int, sig Signal) error

func TimespecToNsec

func TimespecToNsec(ts Timespec) int64

TimespecToNsec converts a Timespec value into a number of nanoseconds since the Unix epoch.

func TimevalToNsec

func TimevalToNsec(tv Timeval) int64

TimevalToNsec converts a Timeval value into a number of nanoseconds since the Unix epoch.

func UnixCredentials

func UnixCredentials(ucred *Ucred) []byte

UnixCredentials encodes credentials into a socket control message for sending to another process. This can be used for authentication.

func UnixRights

func UnixRights(fds ...int) []byte

UnixRights encodes a set of open file descriptors into a socket control message for sending to another process.

func Unlinkat

func Unlinkat(dirfd int, path string) (err error)

func Unsetenv

func Unsetenv(key string) error

func Utimes

func Utimes(path string, tv []Timeval) (err error)

sys utimes(path string, times *[2]Timeval) (err error) utimes(path *byte, times *[2]Timeval) _C_int

func UtimesNano

func UtimesNano(path string, ts []Timespec) (err error)

sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) utimensat(dirfd _C_int, path *byte, times *[2]Timespec, flags _C_int) _C_int

func Wait4

func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error)

func Write

func Write(fd int, p []byte) (n int, err error)

Types

type Conn

type Conn interface {
	// SyscallConn returns a raw network connection.
	SyscallConn() (RawConn, error)
}

Conn is implemented by some types in the net and os packages to provide access to the underlying file descriptor or handle.

type Credential

type Credential struct {
	Uid         uint32   // User ID.
	Gid         uint32   // Group ID.
	Groups      []uint32 // Supplementary group IDs.
	NoSetGroups bool     // If true, don't set supplementary groups
}

Credential holds user and group identities to be assumed by a child process started by StartProcess.

type Errno

type Errno uintptr

An Errno is an unsigned number describing an error condition. It implements the error interface. The zero Errno is by convention a non-error, so code to convert from Errno to error should use:

err = nil
if errno != 0 {
	err = errno
}

func GetErrno

func GetErrno() Errno

func RawSyscall

func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)

func RawSyscall6

func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)

func Syscall

func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)

Do a system call. We look at the size of uintptr to see how to pass the arguments, so that we don't pass a 64-bit value when the function expects a 32-bit one.

func Syscall6

func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)

func (Errno) Error

func (e Errno) Error() string

func (Errno) Temporary

func (e Errno) Temporary() bool

func (Errno) Timeout

func (e Errno) Timeout() bool

type FdSet

type FdSet struct {
	Bits [(FD_SETSIZE + nfdbits - 1) / nfdbits]fds_bits_type
}

type Linger

type Linger struct {
	Onoff  int32
	Linger int32
}

type NetlinkMessage

type NetlinkMessage struct {
	Header NlMsghdr
	Data   []byte
}

NetlinkMessage represents a netlink message.

func ParseNetlinkMessage

func ParseNetlinkMessage(b []byte) ([]NetlinkMessage, error)

ParseNetlinkMessage parses b as an array of netlink messages and returns the slice containing the NetlinkMessage structures.

type NetlinkRouteAttr

type NetlinkRouteAttr struct {
	Attr  RtAttr
	Value []byte
}

NetlinkRouteAttr represents a netlink route attribute.

func ParseNetlinkRouteAttr

func ParseNetlinkRouteAttr(m *NetlinkMessage) ([]NetlinkRouteAttr, error)

ParseNetlinkRouteAttr parses m's payload as an array of netlink route attributes and returns the slice containing the NetlinkRouteAttr structures.

type NetlinkRouteRequest

type NetlinkRouteRequest struct {
	Header NlMsghdr
	Data   RtGenmsg
}

NetlinkRouteRequest represents a request message to receive routing and link states from the kernel.

type ProcAttr

type ProcAttr struct {
	Dir   string    // Current working directory.
	Env   []string  // Environment.
	Files []uintptr // File descriptors.
	Sys   *SysProcAttr
}

ProcAttr holds attributes that will be applied to a new process started by StartProcess.

type RawConn

type RawConn interface {
	// Control invokes f on the underlying connection's file
	// descriptor or handle.
	// The file descriptor fd is guaranteed to remain valid while
	// f executes but not after f returns.
	Control(f func(fd uintptr)) error

	// Read invokes f on the underlying connection's file
	// descriptor or handle; f is expected to try to read from the
	// file descriptor.
	// If f returns true, Read returns. Otherwise Read blocks
	// waiting for the connection to be ready for reading and
	// tries again repeatedly.
	// The file descriptor is guaranteed to remain valid while f
	// executes but not after f returns.
	Read(f func(fd uintptr) (done bool)) error

	// Write is like Read but for writing.
	Write(f func(fd uintptr) (done bool)) error
}

A RawConn is a raw network connection.

type RawSockaddr

type RawSockaddr struct {
	Family uint16
	Data   [14]int8
}

type RawSockaddrAny

type RawSockaddrAny struct {
	Addr RawSockaddr
	Pad  [96]int8
}

type RawSockaddrInet4

type RawSockaddrInet4 struct {
	Family uint16
	Port   uint16
	Addr   [4]byte /* in_addr */
	Zero   [8]uint8
}

type RawSockaddrInet6

type RawSockaddrInet6 struct {
	Family   uint16
	Port     uint16
	Flowinfo uint32
	Addr     [16]byte /* in6_addr */
	Scope_id uint32
}

type RawSockaddrLinklayer

type RawSockaddrLinklayer struct {
	Family   uint16
	Protocol uint16
	Ifindex  int32
	Hatype   uint16
	Pkttype  uint8
	Halen    uint8
	Addr     [8]uint8
}
type RawSockaddrNetlink struct {
	Family uint16
	Pad    uint16
	Pid    uint32
	Groups uint32
}

type RawSockaddrUnix

type RawSockaddrUnix struct {
	Family uint16
	Path   [108]int8
}

type Signal

type Signal int

A Signal is a number describing a process signal. It implements the os.Signal interface.

func (Signal) Signal

func (s Signal) Signal()

func (Signal) String

func (s Signal) String() string

type Sockaddr

type Sockaddr interface {
	// contains filtered or unexported methods
}

func Accept

func Accept(fd int) (nfd int, sa Sockaddr, err error)

func Accept4

func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error)

func Getpeername

func Getpeername(fd int) (sa Sockaddr, err error)

func Getsockname

func Getsockname(fd int) (sa Sockaddr, err error)

func Recvfrom

func Recvfrom(fd int, p []byte, flags int) (n int, from Sockaddr, err error)

func Recvmsg

func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error)

type SockaddrInet4

type SockaddrInet4 struct {
	Port int
	Addr [4]byte
	// contains filtered or unexported fields
}

type SockaddrInet6

type SockaddrInet6 struct {
	Port   int
	ZoneId uint32
	Addr   [16]byte
	// contains filtered or unexported fields
}

type SockaddrLinklayer

type SockaddrLinklayer struct {
	Protocol uint16
	Ifindex  int
	Hatype   uint16
	Pkttype  uint8
	Halen    uint8
	Addr     [8]byte
	// contains filtered or unexported fields
}
type SockaddrNetlink struct {
	Family uint16
	Pad    uint16
	Pid    uint32
	Groups uint32
	// contains filtered or unexported fields
}

type SockaddrUnix

type SockaddrUnix struct {
	Name string
	// contains filtered or unexported fields
}

type SocketControlMessage

type SocketControlMessage struct {
	Header Cmsghdr
	Data   []byte
}

SocketControlMessage represents a socket control message.

func ParseSocketControlMessage

func ParseSocketControlMessage(b []byte) ([]SocketControlMessage, error)

ParseSocketControlMessage parses b as an array of socket control messages.

type SysProcAttr

type SysProcAttr struct {
	Chroot     string      // Chroot.
	Credential *Credential // Credential.
	// Ptrace tells the child to call ptrace(PTRACE_TRACEME).
	// Call runtime.LockOSThread before starting a process with this set,
	// and don't call UnlockOSThread until done with PtraceSyscall calls.
	Ptrace       bool
	Setsid       bool           // Create session.
	Setpgid      bool           // Set process group ID to Pgid, or, if Pgid == 0, to new pid.
	Setctty      bool           // Set controlling terminal to fd Ctty (only meaningful if Setsid is set)
	Noctty       bool           // Detach fd 0 from controlling terminal
	Ctty         int            // Controlling TTY fd
	Foreground   bool           // Place child's process group in foreground. (Implies Setpgid. Uses Ctty as fd of controlling TTY)
	Pgid         int            // Child's process group ID if Setpgid.
	Pdeathsig    Signal         // Signal that the process will get when its parent dies (Linux only)
	Cloneflags   uintptr        // Flags for clone calls (Linux only)
	Unshareflags uintptr        // Flags for unshare calls (Linux only)
	UidMappings  []SysProcIDMap // User ID mappings for user namespaces.
	GidMappings  []SysProcIDMap // Group ID mappings for user namespaces.
	// GidMappingsEnableSetgroups enabling setgroups syscall.
	// If false, then setgroups syscall will be disabled for the child process.
	// This parameter is no-op if GidMappings == nil. Otherwise for unprivileged
	// users this should be set to false for mappings work.
	GidMappingsEnableSetgroups bool
	AmbientCaps                []uintptr // Ambient capabilities (Linux only)
}

type SysProcIDMap

type SysProcIDMap struct {
	ContainerID int // Container ID.
	HostID      int // Host ID.
	Size        int // Size.
}

SysProcIDMap holds Container ID to Host ID mappings used for User Namespaces in Linux. See user_namespaces(7).

type WaitStatus

type WaitStatus uint32

func (WaitStatus) Continued

func (w WaitStatus) Continued() bool

func (WaitStatus) CoreDump

func (w WaitStatus) CoreDump() bool

func (WaitStatus) ExitStatus

func (w WaitStatus) ExitStatus() int

func (WaitStatus) Exited

func (w WaitStatus) Exited() bool

func (WaitStatus) Signal

func (w WaitStatus) Signal() Signal

func (WaitStatus) Signaled

func (w WaitStatus) Signaled() bool

func (WaitStatus) StopSignal

func (w WaitStatus) StopSignal() Signal

func (WaitStatus) Stopped

func (w WaitStatus) Stopped() bool

func (WaitStatus) TrapCause

func (w WaitStatus) TrapCause() int

Directories

Path Synopsis
Package js gives access to the WebAssembly host environment when using the js/wasm architecture.
Package js gives access to the WebAssembly host environment when using the js/wasm architecture.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL