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 Errno.
NOTE: Most of the functions, types, and constants defined in this package are also available in the golang.org/x/sys package. That package has more system call support than this one, and most new code should prefer that package where possible. See https://golang.org/s/go1.4-syscall for more information.
Index ¶
- Constants
- Variables
- func Bind(fd int, sa Sockaddr) error
- func BytePtrFromString(s string) (*byte, error)
- func ByteSliceFromString(s string) ([]byte, error)
- func Chdir(path string) (err error)
- func Chmod(path string, mode uint32) error
- func Chown(path string, uid, gid int) error
- func Clearenv()
- func Close(fd int) error
- func CloseOnExec(fd int)
- func Connect(fd int, sa Sockaddr) error
- func Dup(fd int) (int, error)
- func Dup2(fd, newfd int) error
- func Environ() []string
- func Exit(code int)
- func Fchdir(fd int) error
- func Fchmod(fd int, mode uint32) error
- func Fchown(fd int, uid, gid int) error
- func Fstat(fd int, st *Stat_t) error
- func Fsync(fd int) error
- func Ftruncate(fd int, length int64) error
- func Getcwd(buf []byte) (n int, err error)
- func Getegid() int
- func Getenv(key string) (value string, found bool)
- func Geteuid() int
- func Getgid() int
- func Getgroups() (groups []int, err error)
- func Getpagesize() int
- func Getpid() int
- func Getppid() int
- func GetsockoptInt(fd, level, opt int) (value int, err error)
- func Gettimeofday(tv *Timeval) error
- func Getuid() int
- func Getwd() (wd string, err error)
- func Kill(pid int, signum Signal) error
- func Lchown(path string, uid, gid int) error
- func Link(path, link string) error
- func Listen(fd int, backlog int) error
- func Lstat(path string, st *Stat_t) error
- func Mkdir(path string, perm uint32) error
- func Open(path string, openmode int, perm uint32) (int, error)
- func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string)
- func Pipe(fd []int) error
- func Pread(fd int, b []byte, offset int64) (int, error)
- func Pwrite(fd int, b []byte, offset int64) (int, error)
- func Read(fd int, b []byte) (int, error)
- func ReadDirent(fd int, buf []byte) (int, error)
- func Readlink(path string, buf []byte) (n int, err error)
- func Rename(from, to string) error
- func Rmdir(path string) error
- func Seek(fd int, offset int64, whence int) (int64, error)
- func Sendfile(outfd int, infd int, offset *int64, count int) (written 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) error
- func SetNonblock(fd int, nonblocking bool) error
- func SetReadDeadline(fd int, t int64) error
- func SetWriteDeadline(fd int, t int64) error
- func Setenv(key, value string) error
- func SetsockoptInt(fd, level, opt int, value int) error
- func Shutdown(fd int, how int) error
- func Socket(proto, sotype, unused int) (fd int, err error)
- func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error)
- func Stat(path string, st *Stat_t) error
- func StopIO(fd int) error
- func StringBytePtr(s string) *bytedeprecated
- func StringByteSlice(s string) []bytedeprecated
- func Symlink(path, link string) error
- func Sysctl(key string) (string, error)
- func TimespecToNsec(ts Timespec) int64
- func TimevalToNsec(tv Timeval) int64
- func Truncate(path string, length int64) error
- func Umask(mask int) (oldmask int)
- func Unlink(path string) error
- func Unsetenv(key string) error
- func UtimesNano(path string, ts []Timespec) error
- func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error)
- func Write(fd int, b []byte) (int, error)
- type Conn
- type Dirent
- type Errno
- type Iovec
- type ProcAttr
- type RawConn
- type Rusage
- type Signal
- type Sockaddr
- type SockaddrInet4
- type SockaddrInet6
- type SockaddrUnix
- type Stat_t
- type SysProcAttr
- type Timespec
- type Timeval
- 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 ( AF_UNSPEC = iota AF_UNIX AF_INET AF_INET6 )
const ( SOCK_STREAM = 1 + iota SOCK_DGRAM SOCK_RAW SOCK_SEQPACKET )
const ( IPPROTO_IP = 0 IPPROTO_IPV4 = 4 IPPROTO_IPV6 = 0x29 IPPROTO_TCP = 6 IPPROTO_UDP = 0x11 )
const ( IPV6_V6ONLY SO_ERROR )
const ( F_DUPFD_CLOEXEC SYS_FCNTL = 500 // unsupported )
Misc constants expected by package net but not supported.
const ( Stdin = 0 Stdout = 1 Stderr = 2 )
const ( O_RDONLY = 0 O_WRONLY = 1 O_RDWR = 2 O_CREAT = 0100 O_CREATE = O_CREAT O_TRUNC = 01000 O_APPEND = 02000 O_EXCL = 0200 O_SYNC = 010000 O_CLOEXEC = 0 )
const ( F_DUPFD = 0 F_GETFD = 1 F_SETFD = 2 F_GETFL = 3 F_SETFL = 4 F_GETOWN = 5 F_SETOWN = 6 F_GETLK = 7 F_SETLK = 8 F_SETLKW = 9 F_RGETLK = 10 F_RSETLK = 11 F_CNVT = 12 F_RSETLKW = 13 F_RDLCK = 1 F_WRLCK = 2 F_UNLCK = 3 F_UNLKSYS = 4 )
const ( S_IFMT = 0000370000 S_IFSHM_SYSV = 0000300000 S_IFSEMA = 0000270000 S_IFCOND = 0000260000 S_IFMUTEX = 0000250000 S_IFSHM = 0000240000 S_IFBOUNDSOCK = 0000230000 S_IFSOCKADDR = 0000220000 S_IFDSOCK = 0000210000 S_IFSOCK = 0000140000 S_IFLNK = 0000120000 S_IFREG = 0000100000 S_IFBLK = 0000060000 S_IFDIR = 0000040000 S_IFCHR = 0000020000 S_IFIFO = 0000010000 S_UNSUP = 0000370000 S_ISUID = 0004000 S_ISGID = 0002000 S_ISVTX = 0001000 S_IREAD = 0400 S_IWRITE = 0200 S_IEXEC = 0100 S_IRWXU = 0700 S_IRUSR = 0400 S_IWUSR = 0200 S_IXUSR = 0100 S_IRWXG = 070 S_IRGRP = 040 S_IWGRP = 020 S_IXGRP = 010 S_IRWXO = 07 S_IROTH = 04 S_IWOTH = 02 S_IXOTH = 01 )
const ImplementsGetwd = true
const PathMax = 256
const (
SOMAXCONN = 0x80
)
Variables ¶
var ForkLock sync.RWMutex
Functions ¶
func BytePtrFromString ¶ added in go1.1
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 ¶ added in go1.1
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 CloseOnExec ¶ added in go1.11
func CloseOnExec(fd int)
func Getpagesize ¶ added in go1.8
func Getpagesize() int
func GetsockoptInt ¶ added in go1.11
func Gettimeofday ¶ added in go1.11
func ParseDirent ¶ added in go1.11
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 SetNonblock ¶ added in go1.11
func SetReadDeadline ¶ added in go1.11
func SetWriteDeadline ¶ added in go1.11
func SetsockoptInt ¶ added in go1.11
func StartProcess ¶ added in go1.11
func StringBytePtr
deprecated
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 TimespecToNsec ¶ added in go1.11
TimespecToNsec returns the time stored in ts as nanoseconds.
func TimevalToNsec ¶ added in go1.11
TimevalToNsec returns the time stored in tv as nanoseconds.
func UtimesNano ¶ added in go1.11
Types ¶
type Conn ¶ added in go1.9
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 Errno ¶ added in go1.11
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 using errors.Is. For example:
_, _, err := syscall.Syscall(...) if errors.Is(err, fs.ErrNotExist) ...
const ( // native_client/src/trusted/service_runtime/include/sys/errno.h // The errors are mainly copied from Linux. EPERM Errno = 1 /* Operation not permitted */ ENOENT Errno = 2 /* No such file or directory */ ESRCH Errno = 3 /* No such process */ EINTR Errno = 4 /* Interrupted system call */ EIO Errno = 5 /* I/O error */ ENXIO Errno = 6 /* No such device or address */ E2BIG Errno = 7 /* Argument list too long */ ENOEXEC Errno = 8 /* Exec format error */ EBADF Errno = 9 /* Bad file number */ ECHILD Errno = 10 /* No child processes */ EAGAIN Errno = 11 /* Try again */ ENOMEM Errno = 12 /* Out of memory */ EACCES Errno = 13 /* Permission denied */ EFAULT Errno = 14 /* Bad address */ EBUSY Errno = 16 /* Device or resource busy */ EEXIST Errno = 17 /* File exists */ EXDEV Errno = 18 /* Cross-device link */ ENODEV Errno = 19 /* No such device */ ENOTDIR Errno = 20 /* Not a directory */ EISDIR Errno = 21 /* Is a directory */ EINVAL Errno = 22 /* Invalid argument */ ENFILE Errno = 23 /* File table overflow */ EMFILE Errno = 24 /* Too many open files */ ENOTTY Errno = 25 /* Not a typewriter */ EFBIG Errno = 27 /* File too large */ ENOSPC Errno = 28 /* No space left on device */ ESPIPE Errno = 29 /* Illegal seek */ EROFS Errno = 30 /* Read-only file system */ EMLINK Errno = 31 /* Too many links */ EPIPE Errno = 32 /* Broken pipe */ ENAMETOOLONG Errno = 36 /* File name too long */ ENOSYS Errno = 38 /* Function not implemented */ EDQUOT Errno = 122 /* Quota exceeded */ EDOM Errno = 33 /* Math arg out of domain of func */ ERANGE Errno = 34 /* Math result not representable */ EDEADLK Errno = 35 /* Deadlock condition */ ENOLCK Errno = 37 /* No record locks available */ ENOTEMPTY Errno = 39 /* Directory not empty */ ELOOP Errno = 40 /* Too many symbolic links */ ENOMSG Errno = 42 /* No message of desired type */ EIDRM Errno = 43 /* Identifier removed */ ECHRNG Errno = 44 /* Channel number out of range */ EL2NSYNC Errno = 45 /* Level 2 not synchronized */ EL3HLT Errno = 46 /* Level 3 halted */ EL3RST Errno = 47 /* Level 3 reset */ ELNRNG Errno = 48 /* Link number out of range */ EUNATCH Errno = 49 /* Protocol driver not attached */ ENOCSI Errno = 50 /* No CSI structure available */ EL2HLT Errno = 51 /* Level 2 halted */ EBADE Errno = 52 /* Invalid exchange */ EBADR Errno = 53 /* Invalid request descriptor */ EXFULL Errno = 54 /* Exchange full */ ENOANO Errno = 55 /* No anode */ EBADRQC Errno = 56 /* Invalid request code */ EBADSLT Errno = 57 /* Invalid slot */ EDEADLOCK Errno = EDEADLK /* File locking deadlock error */ EBFONT Errno = 59 /* Bad font file fmt */ ENOSTR Errno = 60 /* Device not a stream */ ENODATA Errno = 61 /* No data (for no delay io) */ ETIME Errno = 62 /* Timer expired */ ENOSR Errno = 63 /* Out of streams resources */ ENONET Errno = 64 /* Machine is not on the network */ ENOPKG Errno = 65 /* Package not installed */ EREMOTE Errno = 66 /* The object is remote */ ENOLINK Errno = 67 /* The link has been severed */ EADV Errno = 68 /* Advertise error */ ESRMNT Errno = 69 /* Srmount error */ ECOMM Errno = 70 /* Communication error on send */ EPROTO Errno = 71 /* Protocol error */ EMULTIHOP Errno = 72 /* Multihop attempted */ EDOTDOT Errno = 73 /* Cross mount point (not really error) */ EBADMSG Errno = 74 /* Trying to read unreadable message */ EOVERFLOW Errno = 75 /* Value too large for defined data type */ ENOTUNIQ Errno = 76 /* Given log. name not unique */ EBADFD Errno = 77 /* f.d. invalid for this operation */ EREMCHG Errno = 78 /* Remote address changed */ ELIBACC Errno = 79 /* Can't access a needed shared lib */ ELIBBAD Errno = 80 /* Accessing a corrupted shared lib */ ELIBSCN Errno = 81 /* .lib section in a.out corrupted */ ELIBMAX Errno = 82 /* Attempting to link in too many libs */ ELIBEXEC Errno = 83 /* Attempting to exec a shared library */ EILSEQ Errno = 84 EUSERS Errno = 87 ENOTSOCK Errno = 88 /* Socket operation on non-socket */ EDESTADDRREQ Errno = 89 /* Destination address required */ EMSGSIZE Errno = 90 /* Message too long */ EPROTOTYPE Errno = 91 /* Protocol wrong type for socket */ ENOPROTOOPT Errno = 92 /* Protocol not available */ EPROTONOSUPPORT Errno = 93 /* Unknown protocol */ ESOCKTNOSUPPORT Errno = 94 /* Socket type not supported */ EOPNOTSUPP Errno = 95 /* Operation not supported on transport endpoint */ EPFNOSUPPORT Errno = 96 /* Protocol family not supported */ EAFNOSUPPORT Errno = 97 /* Address family not supported by protocol family */ EADDRINUSE Errno = 98 /* Address already in use */ EADDRNOTAVAIL Errno = 99 /* Address not available */ ENETDOWN Errno = 100 /* Network interface is not configured */ ENETUNREACH Errno = 101 /* Network is unreachable */ ENETRESET Errno = 102 ECONNABORTED Errno = 103 /* Connection aborted */ ECONNRESET Errno = 104 /* Connection reset by peer */ ENOBUFS Errno = 105 /* No buffer space available */ EISCONN Errno = 106 /* Socket is already connected */ ENOTCONN Errno = 107 /* Socket is not connected */ ESHUTDOWN Errno = 108 /* Can't send after socket shutdown */ ETOOMANYREFS Errno = 109 ETIMEDOUT Errno = 110 /* Connection timed out */ ECONNREFUSED Errno = 111 /* Connection refused */ EHOSTDOWN Errno = 112 /* Host is down */ EHOSTUNREACH Errno = 113 /* Host is unreachable */ EALREADY Errno = 114 /* Socket already connected */ EINPROGRESS Errno = 115 /* Connection already in progress */ ESTALE Errno = 116 ENOTSUP Errno = EOPNOTSUPP /* Not supported */ ENOMEDIUM Errno = 123 /* No medium (in tape drive) */ ECANCELED Errno = 125 /* Operation canceled. */ ELBIN Errno = 2048 /* Inode is remote (not really error) */ EFTYPE Errno = 2049 /* Inappropriate file type or format */ ENMFILE Errno = 2050 /* No more files */ EPROCLIM Errno = 2051 ENOSHARE Errno = 2052 /* No such host or network path */ ECASECLASH Errno = 2053 /* Filename exists with different case */ EWOULDBLOCK Errno = EAGAIN /* Operation would block */ )
TODO: Auto-generate some day. (Hard-coded in binaries so not likely to change.)
func RawSyscall ¶ added in go1.11
func RawSyscall6 ¶ added in go1.11
type ProcAttr ¶ added in go1.11
type ProcAttr struct { Dir string Env []string Files []uintptr Sys *SysProcAttr }
XXX made up
type RawConn ¶ added in go1.9
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 Signal ¶ added in go1.11
type Signal int
A Signal is a number describing a process signal. It implements the os.Signal interface.
const ( SIGCHLD Signal SIGINT SIGKILL SIGTRAP SIGQUIT SIGTERM )
type SockaddrInet4 ¶ added in go1.11
type SockaddrInet6 ¶ added in go1.11
type SockaddrUnix ¶ added in go1.11
type SockaddrUnix struct {
Name string
}
type SysProcAttr ¶ added in go1.11
type SysProcAttr struct { }
type Timespec ¶ added in go1.11
func NsecToTimespec ¶ added in go1.11
NsecToTimespec converts a number of nanoseconds into a Timespec.
type Timeval ¶ added in go1.11
func NsecToTimeval ¶ added in go1.11
NsecToTimeval converts a number of nanoseconds into a Timeval.
type WaitStatus ¶ added in go1.11
type WaitStatus uint32
func (WaitStatus) Continued ¶ added in go1.11
func (w WaitStatus) Continued() bool
func (WaitStatus) CoreDump ¶ added in go1.11
func (w WaitStatus) CoreDump() bool
func (WaitStatus) ExitStatus ¶ added in go1.11
func (w WaitStatus) ExitStatus() int
func (WaitStatus) Exited ¶ added in go1.11
func (w WaitStatus) Exited() bool
func (WaitStatus) Signal ¶ added in go1.11
func (w WaitStatus) Signal() Signal
func (WaitStatus) Signaled ¶ added in go1.11
func (w WaitStatus) Signaled() bool
func (WaitStatus) StopSignal ¶ added in go1.11
func (w WaitStatus) StopSignal() Signal
func (WaitStatus) Stopped ¶ added in go1.11
func (w WaitStatus) Stopped() bool
func (WaitStatus) TrapCause ¶ added in go1.11
func (w WaitStatus) TrapCause() int