syscall

package
v0.0.0-...-9caa667 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2014 License: GPL-2.0, BSD-3-Clause Imports: 3 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.

Index

Constants

View Source
const (
	AI_PASSIVE     = 0x00000001
	AI_CANONNAME   = 0x00000002
	AI_NUMERICHOST = 0x00000004
	AI_NUMERICSERV = 0x00000008
	AI_ALL         = 0x00000100
	AI_ADDRCONFIG  = 0x00000400
	AI_V4MAPPED    = 0x00000800
	AI_DEFAULT     = (AI_V4MAPPED | AI_ADDRCONFIG)
)
View Source
const (
	EAI_ADDRFAMILY = 1
	EAI_AGAIN      = 2
	EAI_BADFLAGS   = 3
	EAI_FAIL       = 4
	EAI_FAMILY     = 5
	EAI_MEMORY     = 6
	EAI_NODATA     = 7
	EAI_NONAME     = 8
	EAI_SERVICE    = 9
	EAI_SOCKTYPE   = 10
	EAI_SYSTEM     = 11
	EAI_BADHINTS   = 12
	EAI_OVERFLOW   = 13
	EAI_MAX        = 14
)
View Source
const (
	IPV6_UNICAST_HOPS   = 48
	IPV6_MULTICAST_IF   = IP_MULTICAST_IF
	IPV6_MULTICAST_HOPS = IP_MULTICAST_TTL
	IPV6_MULTICAST_LOOP = IP_MULTICAST_LOOP
)

<netinet/in.h.h> only provides IPV6_* etc. if _NO_XOPEN4 && _NO_XOPEN5, so as above simply provide them here.

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

Variables

View Source
var (
	Stdin  = 0
	Stdout = 1
	Stderr = 2
)
View Source
var (

	// envs is provided by the runtime. elements are expected to be
	// of the form "key=value".
	Envs []string
)
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

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

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

func DetachLsf(fd int) error

func Entersyscall

func Entersyscall()

func Environ

func Environ() []string

func Errstr

func Errstr(errno int) string

func Exec

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

Ordinary exec.

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 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

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

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)

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 RawSyscall

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

func RawSyscall6

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

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 Sendto

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

func SetErrno

func SetErrno(Errno)

func SetLsfPromisc

func SetLsfPromisc(name string, m bool) error

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 slices. 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

func StringBytePtr(s string) *byte

StringBytePtr is deprecated. Use BytePtrFromString instead. If s contains a NUL byte this function panics instead of returning an error.

func StringByteSlice

func StringByteSlice(s string) []byte

StringByteSlice is deprecated. Use ByteSliceFromString instead. If s contains a NUL byte this function panics instead of returning an error.

func StringSlicePtr

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

StringSlicePtr is deprecated. Use SlicePtrFromStrings instead. If any string contains a NUL byte this function panics instead of returning an error.

func Syscall

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

func Syscall6

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

func Tgkill

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

func TimespecToNsec

func TimespecToNsec(ts Timespec) int64

func TimevalToNsec

func TimevalToNsec(tv Timeval) int64

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 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 Addrinfo

type Addrinfo struct {
	Ai_flags     int32
	Ai_family    int32
	Ai_socktype  int32
	Ai_protocol  int32
	Ai_addrlen   int32
	Ai_canonname *uint8
	Ai_addr      *_sockaddr
	Ai_next      *Addrinfo
}

<netdb.h> only provides struct addrinfo, AI_* and EAI_* if _NO_XOPEN4 && _NO_XOPEN5, but -D_XOPEN_SOURCE=500 is required for msg_control etc. in struct msghgr, so simply provide them here.

type Credential

type Credential struct {
	Uid    uint32   // User ID.
	Gid    uint32   // Group ID.
	Groups []uint32 // Supplementary group IDs.
}

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 PtraceRegs

type PtraceRegs struct {
	R0      uint64
	R1      uint64
	R2      uint64
	R3      uint64
	R4      uint64
	R5      uint64
	R6      uint64
	R7      uint64
	R8      uint64
	R19     uint64
	R20     uint64
	R21     uint64
	R22     uint64
	R23     uint64
	R24     uint64
	R25     uint64
	R26     uint64
	R27     uint64
	R28     uint64
	Hae     uint64
	Trap_a0 uint64
	Trap_a1 uint64
	Trap_a2 uint64
	Ps      uint64
	Pc      uint64
	Gp      uint64
	R16     uint64
	R17     uint64
	R18     uint64
}

func (*PtraceRegs) PC

func (r *PtraceRegs) PC() uint64

func (*PtraceRegs) SetPC

func (r *PtraceRegs) SetPC(pc uint64)

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     bool        // Enable tracing.
	Setsid     bool        // Create session.
	Setpgid    bool        // Set process group ID to new pid (SYSV setpgrp)
	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 (Linux only)
	Pdeathsig  Signal      // Signal that the process will get when its parent dies (Linux only)
	Cloneflags uintptr     // Flags for clone calls (Linux only)
}

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

Jump to

Keyboard shortcuts

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