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
- Variables
- func AttachLsf(fd int, i []SockFilter) errordeprecated
- func Bind(fd int, sa Sockaddr) (err error)
- func BindToDevice(fd int, device string) (err error)
- func BytePtrFromString(s string) (*byte, error)
- func ByteSliceFromString(s string) ([]byte, error)
- func Cgocall()
- func CgocallBack()
- func CgocallBackDone()
- func CgocallDone()
- func Clearenv()
- func CloseOnExec(fd int)
- func CmsgLen(datalen int) int
- func CmsgSpace(datalen int) int
- func Connect(fd int, sa Sockaddr) (err error)
- func DetachLsf(fd int) errordeprecated
- func Entersyscall()
- func Environ() []string
- func Errstr(errnum int) string
- func Exec(argv0 string, argv []string, envv []string) (err error)
- func Exit(code int)
- func Exitsyscall()
- func FDClr(fd int, set *FdSet)
- func FDIsSet(fd int, set *FdSet) bool
- func FDSet(fd int, set *FdSet)
- func FDZero(set *FdSet)
- func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
- func Futimes(fd int, tv []Timeval) (err error)
- func Futimesat(dirfd int, path string, tv []Timeval) (err error)
- func Getcwd(buf []byte) (n int, err error)
- func Getdents(fd int, buf []byte) (n int, err error)
- func Getenv(key string) (value string, found bool)
- func Getgroups() (gids []int, err error)
- func Getpagesize() int
- func GetsockoptByte(fd, level, opt int) (value byte, err error)
- func GetsockoptInet4Addr(fd, level, opt int) (value [4]byte, err error)
- func GetsockoptInt(fd, level, opt int) (value int, err error)
- func Gettid() (tid int)
- func Gettimeofday(tv *Timeval) (err error)
- func Getwd() (ret string, err error)
- func LsfSocket(ifindex, proto int) (int, error)deprecated
- func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error)
- func Munmap(b []byte) (err error)
- func NetlinkRIB(proto, family int) ([]byte, error)
- func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string)
- func ParseUnixRights(m *SocketControlMessage) ([]int, error)
- func Pipe(p []int) (err error)
- func Pipe2(p []int, flags int) (err error)
- func PtraceAttach(pid int) (err error)
- func PtraceCont(pid int, signal int) (err error)
- func PtraceDetach(pid int) (err error)
- func PtraceGetEventMsg(pid int) (msg uint, err error)
- func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error)
- func PtracePeekData(pid int, addr uintptr, out []byte) (count int, err error)
- func PtracePeekText(pid int, addr uintptr, out []byte) (count int, err error)
- func PtracePokeData(pid int, addr uintptr, data []byte) (count int, err error)
- func PtracePokeText(pid int, addr uintptr, data []byte) (count int, err error)
- func PtraceSetOptions(pid int, options int) (err error)
- func PtraceSetRegs(pid int, regs *PtraceRegs) (err error)
- func PtraceSingleStep(pid int) (err error)
- func Read(fd int, p []byte) (n int, err error)
- func ReadDirent(fd int, buf []byte) (n int, err error)
- func Reboot(cmd int) (err error)
- func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
- func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error)
- func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error)
- func Sendto(fd int, p []byte, flags int, to Sockaddr) (err error)
- func SetErrno(Errno)
- func SetLsfPromisc(name string, m bool) errordeprecated
- func SetNonblock(fd int, nonblocking bool) (err error)
- func Setenv(key, value string) error
- func Setgroups(gids []int) (err error)
- func SetsockoptByte(fd, level, opt int, value byte) (err error)
- func SetsockoptICMPv6Filter(fd, level, opt int, filter *ICMPv6Filter) error
- func SetsockoptIPMreq(fd, level, opt int, mreq *IPMreq) (err error)
- func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error)
- func SetsockoptIPv6Mreq(fd, level, opt int, mreq *IPv6Mreq) (err error)
- func SetsockoptInet4Addr(fd, level, opt int, value [4]byte) (err error)
- func SetsockoptInt(fd, level, opt int, value int) (err error)
- func SetsockoptLinger(fd, level, opt int, l *Linger) (err error)
- func SetsockoptString(fd, level, opt int, s string) (err error)
- func SetsockoptTimeval(fd, level, opt int, tv *Timeval) (err error)
- func Settimeofday(tv *Timeval) (err error)
- func Signame(s Signal) string
- func Sleep(nsec int64) (err error)
- func SlicePtrFromStrings(ss []string) ([]*byte, error)
- func Socket(domain, typ, proto int) (fd int, err error)
- func Socketpair(domain, typ, proto int) (fd [2]int, err error)
- func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
- func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error)
- func StringBytePtr(s string) *bytedeprecated
- func StringByteSlice(s string) []bytedeprecated
- func StringSlicePtr(ss []string) []*bytedeprecated
- func Sysconf(name int) (ret int64, err error)
- func Tgkill(tgid int, tid int, sig Signal) error
- func TimespecToNsec(ts Timespec) int64
- func TimevalToNsec(tv Timeval) int64
- func UnixCredentials(ucred *Ucred) []byte
- func UnixRights(fds ...int) []byte
- func Unlinkat(dirfd int, path string) (err error)
- func Unsetenv(key string) error
- func Utimes(path string, tv []Timeval) (err error)
- func UtimesNano(path string, ts []Timespec) (err error)
- func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error)
- func Write(fd int, p []byte) (n int, err error)
- type Conn
- type Credential
- type Errno
- func GetErrno() Errno
- func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
- func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
- func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
- func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
- type FdSet
- type Linger
- type NetlinkMessage
- type NetlinkRouteAttr
- type NetlinkRouteRequest
- type ProcAttr
- type RawConn
- type RawSockaddr
- type RawSockaddrAny
- type RawSockaddrInet4
- type RawSockaddrInet6
- type RawSockaddrLinklayer
- type RawSockaddrNetlink
- type RawSockaddrUnix
- type Signal
- type Sockaddr
- func Accept(fd int) (nfd int, sa Sockaddr, err error)
- func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error)
- func Getpeername(fd int) (sa Sockaddr, err error)
- func Getsockname(fd int) (sa Sockaddr, err error)
- func Recvfrom(fd int, p []byte, flags int) (n int, from Sockaddr, err error)
- func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error)
- type SockaddrInet4
- type SockaddrInet6
- type SockaddrLinklayer
- type SockaddrNetlink
- type SockaddrUnix
- type SocketControlMessage
- type SysProcAttr
- type SysProcIDMap
- type WaitStatus
- func (w WaitStatus) Continued() bool
- func (w WaitStatus) CoreDump() bool
- func (w WaitStatus) ExitStatus() int
- func (w WaitStatus) Exited() bool
- func (w WaitStatus) Signal() Signal
- func (w WaitStatus) Signaled() bool
- func (w WaitStatus) StopSignal() Signal
- func (w WaitStatus) Stopped() bool
- func (w WaitStatus) TrapCause() int
Constants ¶
const ImplementsGetwd = true
const SizeofSockaddrAny = 0x6c
const SizeofSockaddrInet4 = 16
const SizeofSockaddrInet6 = 28
const SizeofSockaddrLinklayer = 20
const SizeofSockaddrNetlink = 12
const SizeofSockaddrUnix = 110
Variables ¶
var ( Stdin = 0 Stdout = 1 Stderr = 2 )
var ForkLock sync.RWMutex
var SocketDisableIPv6 bool
For testing: clients can set this flag to force creation of IPv6 sockets to return EAFNOSUPPORT.
Functions ¶
func BindToDevice ¶
BindToDevice binds the socket associated with fd to device.
func BytePtrFromString ¶
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 ¶
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 CgocallBack ¶
func CgocallBack()
func CgocallBackDone ¶
func CgocallBackDone()
func CgocallDone ¶
func CgocallDone()
func CloseOnExec ¶
func CloseOnExec(fd int)
func CmsgLen ¶
CmsgLen returns the value to store in the Len field of the Cmsghdr structure, taking into account any necessary alignment.
func CmsgSpace ¶
CmsgSpace returns the number of bytes an ancillary element with payload of the passed data length occupies.
func Entersyscall ¶
func Entersyscall()
func Exitsyscall ¶
func Exitsyscall()
func Futimesat ¶
sys futimesat(dirfd int, path *byte, times *[2]Timeval) (err error) futimesat(dirfd _C_int, path *byte, times *[2]Timeval) _C_int
func Getpagesize ¶
func Getpagesize() int
func GetsockoptByte ¶
func GetsockoptInet4Addr ¶
func GetsockoptInt ¶
func Gettimeofday ¶
func Gettimeofday(tv *Timeval) (err error)
sysnb gettimeofday(tv *Timeval, tz *byte) (err error) gettimeofday(tv *Timeval, tz *byte) _C_int
func NetlinkRIB ¶
NetlinkRIB returns routing information base, as known as RIB, which consists of network facility information, states and parameters.
func ParseDirent ¶
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 Pipe2 ¶
sysnb pipe2(p *[2]_C_int, flags int) (err error) pipe2(p *[2]_C_int, flags _C_int) _C_int
func PtraceAttach ¶
func PtraceCont ¶
func PtraceDetach ¶
func PtraceGetEventMsg ¶
func PtraceGetRegs ¶
func PtracePokeData ¶
func PtracePokeText ¶
func PtraceSetOptions ¶
func PtraceSetRegs ¶
func PtraceSingleStep ¶
func Reboot ¶
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 ¶
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 SetLsfPromisc
deprecated
func SetNonblock ¶
func SetsockoptByte ¶
func SetsockoptICMPv6Filter ¶
func SetsockoptIPMreq ¶
func SetsockoptIPMreqn ¶
func SetsockoptIPv6Mreq ¶
func SetsockoptInet4Addr ¶
func SetsockoptInt ¶
func SetsockoptLinger ¶
func SetsockoptString ¶
func SetsockoptTimeval ¶
func Settimeofday ¶
func Settimeofday(tv *Timeval) (err error)
func SlicePtrFromStrings ¶
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 Socketpair ¶
func Splice ¶
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 ¶
StartProcess wraps ForkExec for package os.
func StringBytePtr
deprecated
func StringByteSlice
deprecated
func StringSlicePtr
deprecated
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 ¶
UnixRights encodes a set of open file descriptors into a socket control message for sending to another process.
func Utimes ¶
sys utimes(path string, times *[2]Timeval) (err error) utimes(path *byte, times *[2]Timeval) _C_int
func UtimesNano ¶
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
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 }
Errno values can be tested against error values from the os package using errors.Is. For example:
_, _, err := syscall.Syscall(...) if errors.Is(err, os.ErrNotExist) ...
func RawSyscall ¶
func RawSyscall6 ¶
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 RawSockaddrAny ¶
type RawSockaddrAny struct { Addr RawSockaddr Pad [96]int8 }
type RawSockaddrInet4 ¶
type RawSockaddrInet6 ¶
type RawSockaddrLinklayer ¶
type RawSockaddrNetlink ¶
type RawSockaddrUnix ¶
type Signal ¶
type Signal int
A Signal is a number describing a process signal. It implements the os.Signal interface.
type Sockaddr ¶
type Sockaddr interface {
// contains filtered or unexported methods
}
func Getpeername ¶
func Getsockname ¶
type SockaddrInet4 ¶
type SockaddrInet6 ¶
type SockaddrLinklayer ¶
type SockaddrNetlink ¶
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) 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
Source Files ¶
- dirent.go
- endian_little.go
- env_unix.go
- errstr_glibc.go
- exec_linux.go
- exec_unix.go
- libcall_glibc.go
- libcall_linux.go
- libcall_linux_alpha.go
- libcall_linux_amd64.go
- libcall_linux_utimesnano.go
- libcall_posix.go
- libcall_posix_largefile.go
- libcall_posix_nonhurd.go
- libcall_support.go
- libcall_uname.go
- libcall_wait4.go
- lsf_linux.go
- msan0.go
- net.go
- netlink_linux.go
- setuidgid_linux.go
- sleep_select.go
- sock_cloexec_linux.go
- sockcmsg_linux.go
- sockcmsg_unix.go
- sockcmsg_unix_other.go
- socket.go
- socket_linux.go
- socket_linux_type.go
- socket_posix.go
- str.go
- syscall.go
- syscall_errno.go
- syscall_funcs.go
- syscall_glibc.go
- syscall_linux_alpha.go
- syscall_linux_amd64.go
- syscall_unix.go
- time_nofake.go
- timestruct.go