package standard library
go1.21.4 Latest Latest

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

Go to latest
Published: Nov 7, 2023 License: BSD-3-Clause Imports: 9 Imported by: 161,902



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 repository instead. That is also where updates required by new systems or versions should be applied. See for more information.



View Source
const (
	AF_UNSPEC = iota
View Source
const (
	SOCK_STREAM = 1 + iota
View Source
const (
	IPPROTO_IPV6 = 0x29
	IPPROTO_UDP  = 0x11
View Source
const (
View Source
const (
	SYS_FCNTL = 500 // unsupported

Misc constants expected by package net but not supported.

View Source
const (
	Stdin  = 0
	Stdout = 1
	Stderr = 2
View Source
const (
	O_RDWR   = 2

	O_CREAT  = 0100
	O_TRUNC  = 01000
	O_APPEND = 02000
	O_EXCL   = 0200
	O_SYNC   = 010000

View Source
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_RDLCK   = 1
	F_WRLCK   = 2
	F_UNLCK   = 3
View Source
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
View Source
const ImplementsGetwd = true
View Source
const PathMax = 256


View Source
var ForkLock sync.RWMutex


func Bind added in go1.11

func Bind(fd int, sa Sockaddr) error

func BytePtrFromString added in go1.1

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 added in go1.1

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 Chdir added in go1.11

func Chdir(path string) (err error)

func Chmod added in go1.11

func Chmod(path string, mode uint32) error

func Chown added in go1.11

func Chown(path string, uid, gid int) error

func Clearenv added in go1.11

func Clearenv()

func Close added in go1.11

func Close(fd int) error

func CloseOnExec added in go1.11

func CloseOnExec(fd int)

func Connect added in go1.11

func Connect(fd int, sa Sockaddr) error

func Dup added in go1.11

func Dup(fd int) (int, error)

func Dup2 added in go1.11

func Dup2(fd, newfd int) error

func Environ added in go1.11

func Environ() []string

func Exit added in go1.10

func Exit(code int)

func Fchdir added in go1.11

func Fchdir(fd int) error

func Fchmod added in go1.11

func Fchmod(fd int, mode uint32) error

func Fchown added in go1.11

func Fchown(fd int, uid, gid int) error

func Fstat added in go1.11

func Fstat(fd int, st *Stat_t) error

func Fsync added in go1.11

func Fsync(fd int) error

func Ftruncate added in go1.11

func Ftruncate(fd int, length int64) error

func Getcwd added in go1.11

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

func Getegid added in go1.11

func Getegid() int

func Getenv added in go1.11

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

func Geteuid added in go1.11

func Geteuid() int

func Getgid added in go1.11

func Getgid() int

func Getgroups added in go1.11

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

func Getpagesize added in go1.8

func Getpagesize() int

func Getpid added in go1.11

func Getpid() int

func Getppid added in go1.11

func Getppid() int

func GetsockoptInt added in go1.11

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

func Gettimeofday added in go1.11

func Gettimeofday(tv *Timeval) error

func Getuid added in go1.11

func Getuid() int

func Getwd added in go1.11

func Getwd() (wd string, err error)

func Kill added in go1.11

func Kill(pid int, signum Signal) error

func Lchown added in go1.11

func Lchown(path string, uid, gid int) error
func Link(path, link string) error

func Listen added in go1.11

func Listen(fd int, backlog int) error

func Lstat added in go1.11

func Lstat(path string, st *Stat_t) error

func Mkdir added in go1.11

func Mkdir(path string, perm uint32) error

func Open added in go1.11

func Open(path string, openmode int, perm uint32) (int, error)

func ParseDirent added in go1.11

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 Pipe added in go1.11

func Pipe(fd []int) error

func Pread added in go1.11

func Pread(fd int, b []byte, offset int64) (int, error)

func Pwrite added in go1.11

func Pwrite(fd int, b []byte, offset int64) (int, error)

func Read added in go1.11

func Read(fd int, b []byte) (int, error)

func ReadDirent added in go1.11

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

func Rename added in go1.11

func Rename(from, to string) error

func Rmdir added in go1.11

func Rmdir(path string) error

func Seek added in go1.11

func Seek(fd int, offset int64, whence int) (int64, error)

func Sendfile added in go1.11

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

func SendmsgN added in go1.11

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

func Sendto added in go1.11

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

func SetNonblock added in go1.11

func SetNonblock(fd int, nonblocking bool) error

func SetReadDeadline added in go1.11

func SetReadDeadline(fd int, t int64) error

func SetWriteDeadline added in go1.11

func SetWriteDeadline(fd int, t int64) error

func Setenv added in go1.11

func Setenv(key, value string) error

func SetsockoptInt added in go1.11

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

func Shutdown added in go1.11

func Shutdown(fd int, how int) error

func Socket added in go1.11

func Socket(proto, sotype, unused int) (fd int, err error)

func StartProcess added in go1.11

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

func Stat added in go1.11

func Stat(path string, st *Stat_t) error

func StopIO added in go1.11

func StopIO(fd int) error

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 Symlink(path, link string) error

func Sysctl added in go1.11

func Sysctl(key string) (string, error)

func TimespecToNsec added in go1.11

func TimespecToNsec(ts Timespec) int64

TimespecToNsec returns the time stored in ts as nanoseconds.

func TimevalToNsec added in go1.11

func TimevalToNsec(tv Timeval) int64

TimevalToNsec returns the time stored in tv as nanoseconds.

func Truncate added in go1.11

func Truncate(path string, length int64) error

func Umask added in go1.13

func Umask(mask int) (oldmask int)
func Unlink(path string) error

func Unsetenv added in go1.11

func Unsetenv(key string) error

func UtimesNano added in go1.11

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

func Wait4 added in go1.11

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

func Write added in go1.11

func Write(fd int, b []byte) (int, error)


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 Dirent added in go1.11

type Dirent struct {
	Reclen uint16
	Name   [256]byte

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 RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)

func RawSyscall6 added in go1.11

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

func Syscall added in go1.11

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

func Syscall6 added in go1.11

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

func (Errno) Error added in go1.11

func (e Errno) Error() string

func (Errno) Is added in go1.13

func (e Errno) Is(target error) bool

func (Errno) Temporary added in go1.11

func (e Errno) Temporary() bool

func (Errno) Timeout added in go1.11

func (e Errno) Timeout() bool

type Iovec added in go1.11

type Iovec struct{} // dummy

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 Rusage added in go1.11

type Rusage struct {
	Utime Timeval
	Stime Timeval

XXX made up

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 (

func (Signal) Signal added in go1.11

func (s Signal) Signal()

func (Signal) String added in go1.11

func (s Signal) String() string

type Sockaddr added in go1.11

type Sockaddr any

func Accept added in go1.11

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

func Recvfrom added in go1.11

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

func Recvmsg added in go1.11

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

type SockaddrInet4 added in go1.11

type SockaddrInet4 struct {
	Port int
	Addr [4]byte

type SockaddrInet6 added in go1.11

type SockaddrInet6 struct {
	Port   int
	ZoneId uint32
	Addr   [16]byte

type SockaddrUnix added in go1.11

type SockaddrUnix struct {
	Name string

type Stat_t added in go1.11

type Stat_t struct {
	Dev       int64
	Ino       uint64
	Mode      uint32
	Nlink     uint32
	Uid       uint32
	Gid       uint32
	Rdev      int64
	Size      int64
	Blksize   int32
	Blocks    int32
	Atime     int64
	AtimeNsec int64
	Mtime     int64
	MtimeNsec int64
	Ctime     int64
	CtimeNsec int64

type SysProcAttr added in go1.11

type SysProcAttr struct {

type Timespec added in go1.11

type Timespec struct {
	Sec  int64
	Nsec int64

func NsecToTimespec added in go1.11

func NsecToTimespec(nsec int64) Timespec

NsecToTimespec converts a number of nanoseconds into a Timespec.

func (*Timespec) Nano added in go1.11

func (ts *Timespec) Nano() int64

Nano returns the time stored in ts as nanoseconds.

func (*Timespec) Unix added in go1.11

func (ts *Timespec) Unix() (sec int64, nsec int64)

Unix returns the time stored in ts as seconds plus nanoseconds.

type Timeval added in go1.11

type Timeval struct {
	Sec  int64
	Usec int64

func NsecToTimeval added in go1.11

func NsecToTimeval(nsec int64) Timeval

NsecToTimeval converts a number of nanoseconds into a Timeval.

func (*Timeval) Nano added in go1.11

func (tv *Timeval) Nano() int64

Nano returns the time stored in tv as nanoseconds.

func (*Timeval) Unix added in go1.11

func (tv *Timeval) Unix() (sec int64, nsec int64)

Unix returns the time stored in tv as seconds plus nanoseconds.

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


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