syscall

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: BSD-3-Clause Imports: 9 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 (
	AF_UNSPEC = iota
	AF_UNIX
	AF_INET
	AF_INET6
)
View Source
const (
	SOCK_STREAM = 1 + iota
	SOCK_DGRAM
	SOCK_RAW
	SOCK_SEQPACKET
)
View Source
const (
	IPPROTO_IP   = 0
	IPPROTO_IPV4 = 4
	IPPROTO_IPV6 = 0x29
	IPPROTO_TCP  = 6
	IPPROTO_UDP  = 0x11
)
View Source
const (
	IPV6_V6ONLY
	SOMAXCONN
	SO_ERROR
)
View Source
const (
	F_DUPFD_CLOEXEC
	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_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
)
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_RSETLKW = 13

	F_RDLCK   = 1
	F_WRLCK   = 2
	F_UNLCK   = 3
	F_UNLKSYS = 4
)
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

Variables

View Source
var ForkLock sync.RWMutex

Functions

func Bind

func Bind(fd int, sa Sockaddr) error

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 Chdir

func Chdir(path string) (err error)

func Chmod

func Chmod(path string, mode uint32) error

func Chown

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

func Clearenv

func Clearenv()

func Close

func Close(fd int) error

func CloseOnExec

func CloseOnExec(fd int)

func Connect

func Connect(fd int, sa Sockaddr) error

func Dup

func Dup(fd int) (int, error)

func Dup2

func Dup2(fd, newfd int) error

func Environ

func Environ() []string

func Exit

func Exit(code int)

func Fchdir

func Fchdir(fd int) error

func Fchmod

func Fchmod(fd int, mode uint32) error

func Fchown

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

func Fstat

func Fstat(fd int, st *Stat_t) error

func Fsync

func Fsync(fd int) error

func Ftruncate

func Ftruncate(fd int, length int64) error

func Getcwd

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

func Getegid

func Getegid() int

func Getenv

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

func Geteuid

func Geteuid() int

func Getgid

func Getgid() int

func Getgroups

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

func Getpagesize

func Getpagesize() int

func Getpid

func Getpid() int

func Getppid

func Getppid() int

func GetsockoptInt

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

func Gettimeofday

func Gettimeofday(tv *Timeval) error

func Getuid

func Getuid() int

func Getwd

func Getwd() (wd string, err error)

func Kill

func Kill(pid int, signum Signal) error

func Lchown

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

func Listen

func Listen(fd int, backlog int) error

func Lstat

func Lstat(path string, st *Stat_t) error

func Mkdir

func Mkdir(path string, perm uint32) error

func Open

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

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 Pipe

func Pipe(fd []int) error

func Pread

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

func ProcExit

func ProcExit(code int32)

func Pwrite

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

func Read

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

func ReadDirent

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

func Rename

func Rename(from, to string) error

func Rmdir

func Rmdir(path string) error

func Seek

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

func Sendfile

func Sendfile(outfd int, infd int, offset *int64, count int) (written 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) error

func SetNonblock

func SetNonblock(fd int, nonblocking bool) error

func SetReadDeadline

func SetReadDeadline(fd int, t int64) error

func SetWriteDeadline

func SetWriteDeadline(fd int, t int64) error

func Setenv

func Setenv(key, value string) error

func SetsockoptInt

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

func Shutdown

func Shutdown(fd int, how int) error

func Socket

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

func StartProcess

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

func Stat

func Stat(path string, st *Stat_t) error

func StopIO

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

func Sysctl(key string) (string, error)

func TimespecToNsec

func TimespecToNsec(ts Timespec) int64

TimespecToNsec returns the time stored in ts as nanoseconds.

func TimevalToNsec

func TimevalToNsec(tv Timeval) int64

TimevalToNsec returns the time stored in tv as nanoseconds.

func Truncate

func Truncate(path string, length int64) error

func Umask

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

func Unsetenv

func Unsetenv(key string) error

func UtimesNano

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

func Wait4

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

func Write

func Write(fd int, b []byte) (int, 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 Dirent

type Dirent struct {
	Reclen uint16
	Name   [256]byte
}

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

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)

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

func (e Errno) Is(target error) bool

func (Errno) Temporary

func (e Errno) Temporary() bool

func (Errno) Timeout

func (e Errno) Timeout() bool

type Iovec

type Iovec struct{} // dummy

type ProcAttr

type ProcAttr struct {
	Dir   string
	Env   []string
	Files []uintptr
	Sys   *SysProcAttr
}

XXX made up

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 Rusage

type Rusage struct {
	Utime Timeval
	Stime Timeval
}

XXX made up

type Signal

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
)

func (Signal) Signal

func (s Signal) Signal()

func (Signal) String

func (s Signal) String() string

type Sockaddr

type Sockaddr any

func Accept

func Accept(fd int) (newfd 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, recvflags int, from Sockaddr, err error)

type SockaddrInet4

type SockaddrInet4 struct {
	Port int
	Addr [4]byte
}

type SockaddrInet6

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

type SockaddrUnix

type SockaddrUnix struct {
	Name string
}

type Stat_t

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

type SysProcAttr struct {
}

type Timespec

type Timespec struct {
	Sec  int64
	Nsec int64
}

func NsecToTimespec

func NsecToTimespec(nsec int64) Timespec

NsecToTimespec converts a number of nanoseconds into a Timespec.

func (*Timespec) Nano

func (ts *Timespec) Nano() int64

Nano returns the time stored in ts as nanoseconds.

func (*Timespec) Unix

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

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

type Timeval

type Timeval struct {
	Sec  int64
	Usec int64
}

func NsecToTimeval

func NsecToTimeval(nsec int64) Timeval

NsecToTimeval converts a number of nanoseconds into a Timeval.

func (*Timeval) Nano

func (tv *Timeval) Nano() int64

Nano returns the time stored in tv as nanoseconds.

func (*Timeval) Unix

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

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

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