| 1 |
// Copyright 2023 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build wasip1 |
| 6 |
|
| 7 |
package syscall |
| 8 |
|
| 9 |
import "runtime" |
| 10 |
|
| 11 |
// TODO: Auto-generate some day. (Hard-coded in binaries so not likely to change.) |
| 12 |
const ( |
| 13 |
E2BIG Errno = 1 |
| 14 |
EACCES Errno = 2 |
| 15 |
EADDRINUSE Errno = 3 |
| 16 |
EADDRNOTAVAIL Errno = 4 |
| 17 |
EAFNOSUPPORT Errno = 5 |
| 18 |
EAGAIN Errno = 6 |
| 19 |
EALREADY Errno = 7 |
| 20 |
EBADF Errno = 8 |
| 21 |
EBADMSG Errno = 9 |
| 22 |
EBUSY Errno = 10 |
| 23 |
ECANCELED Errno = 11 |
| 24 |
ECHILD Errno = 12 |
| 25 |
ECONNABORTED Errno = 13 |
| 26 |
ECONNREFUSED Errno = 14 |
| 27 |
ECONNRESET Errno = 15 |
| 28 |
EDEADLK Errno = 16 |
| 29 |
EDESTADDRREQ Errno = 17 |
| 30 |
EDOM Errno = 18 |
| 31 |
EDQUOT Errno = 19 |
| 32 |
EEXIST Errno = 20 |
| 33 |
EFAULT Errno = 21 |
| 34 |
EFBIG Errno = 22 |
| 35 |
EHOSTUNREACH Errno = 23 |
| 36 |
EIDRM Errno = 24 |
| 37 |
EILSEQ Errno = 25 |
| 38 |
EINPROGRESS Errno = 26 |
| 39 |
EINTR Errno = 27 |
| 40 |
EINVAL Errno = 28 |
| 41 |
EIO Errno = 29 |
| 42 |
EISCONN Errno = 30 |
| 43 |
EISDIR Errno = 31 |
| 44 |
ELOOP Errno = 32 |
| 45 |
EMFILE Errno = 33 |
| 46 |
EMLINK Errno = 34 |
| 47 |
EMSGSIZE Errno = 35 |
| 48 |
EMULTIHOP Errno = 36 |
| 49 |
ENAMETOOLONG Errno = 37 |
| 50 |
ENETDOWN Errno = 38 |
| 51 |
ENETRESET Errno = 39 |
| 52 |
ENETUNREACH Errno = 40 |
| 53 |
ENFILE Errno = 41 |
| 54 |
ENOBUFS Errno = 42 |
| 55 |
ENODEV Errno = 43 |
| 56 |
ENOENT Errno = 44 |
| 57 |
ENOEXEC Errno = 45 |
| 58 |
ENOLCK Errno = 46 |
| 59 |
ENOLINK Errno = 47 |
| 60 |
ENOMEM Errno = 48 |
| 61 |
ENOMSG Errno = 49 |
| 62 |
ENOPROTOOPT Errno = 50 |
| 63 |
ENOSPC Errno = 51 |
| 64 |
ENOSYS Errno = 52 |
| 65 |
ENOTCONN Errno = 53 |
| 66 |
ENOTDIR Errno = 54 |
| 67 |
ENOTEMPTY Errno = 55 |
| 68 |
ENOTRECOVERABLE Errno = 56 |
| 69 |
ENOTSOCK Errno = 57 |
| 70 |
ENOTSUP Errno = 58 |
| 71 |
ENOTTY Errno = 59 |
| 72 |
ENXIO Errno = 60 |
| 73 |
EOVERFLOW Errno = 61 |
| 74 |
EOWNERDEAD Errno = 62 |
| 75 |
EPERM Errno = 63 |
| 76 |
EPIPE Errno = 64 |
| 77 |
EPROTO Errno = 65 |
| 78 |
EPROTONOSUPPORT Errno = 66 |
| 79 |
EPROTOTYPE Errno = 67 |
| 80 |
ERANGE Errno = 68 |
| 81 |
EROFS Errno = 69 |
| 82 |
ESPIPE Errno = 70 |
| 83 |
ESRCH Errno = 71 |
| 84 |
ESTALE Errno = 72 |
| 85 |
ETIMEDOUT Errno = 73 |
| 86 |
ETXTBSY Errno = 74 |
| 87 |
EXDEV Errno = 75 |
| 88 |
ENOTCAPABLE Errno = 76 |
| 89 |
EBADFD Errno = 77 |
| 90 |
// needed by src/net/error_unix_test.go |
| 91 |
EOPNOTSUPP = ENOTSUP |
| 92 |
) |
| 93 |
|
| 94 |
// TODO: Auto-generate some day. (Hard-coded in binaries so not likely to change.) |
| 95 |
var errorstr = [...]string{ |
| 96 |
E2BIG: "Argument list too long", |
| 97 |
EACCES: "Permission denied", |
| 98 |
EADDRINUSE: "Address already in use", |
| 99 |
EADDRNOTAVAIL: "Address not available", |
| 100 |
EAFNOSUPPORT: "Address family not supported by protocol family", |
| 101 |
EAGAIN: "Try again", |
| 102 |
EALREADY: "Socket already connected", |
| 103 |
EBADF: "Bad file number", |
| 104 |
EBADFD: "file descriptor in bad state", |
| 105 |
EBADMSG: "Trying to read unreadable message", |
| 106 |
EBUSY: "Device or resource busy", |
| 107 |
ECANCELED: "Operation canceled.", |
| 108 |
ECHILD: "No child processes", |
| 109 |
ECONNABORTED: "Connection aborted", |
| 110 |
ECONNREFUSED: "Connection refused", |
| 111 |
ECONNRESET: "Connection reset by peer", |
| 112 |
EDEADLK: "Deadlock condition", |
| 113 |
EDESTADDRREQ: "Destination address required", |
| 114 |
EDOM: "Math arg out of domain of func", |
| 115 |
EDQUOT: "Quota exceeded", |
| 116 |
EEXIST: "File exists", |
| 117 |
EFAULT: "Bad address", |
| 118 |
EFBIG: "File too large", |
| 119 |
EHOSTUNREACH: "Host is unreachable", |
| 120 |
EIDRM: "Identifier removed", |
| 121 |
EILSEQ: "EILSEQ", |
| 122 |
EINPROGRESS: "Connection already in progress", |
| 123 |
EINTR: "Interrupted system call", |
| 124 |
EINVAL: "Invalid argument", |
| 125 |
EIO: "I/O error", |
| 126 |
EISCONN: "Socket is already connected", |
| 127 |
EISDIR: "Is a directory", |
| 128 |
ELOOP: "Too many symbolic links", |
| 129 |
EMFILE: "Too many open files", |
| 130 |
EMLINK: "Too many links", |
| 131 |
EMSGSIZE: "Message too long", |
| 132 |
EMULTIHOP: "Multihop attempted", |
| 133 |
ENAMETOOLONG: "File name too long", |
| 134 |
ENETDOWN: "Network interface is not configured", |
| 135 |
ENETRESET: "Network dropped connection on reset", |
| 136 |
ENETUNREACH: "Network is unreachable", |
| 137 |
ENFILE: "File table overflow", |
| 138 |
ENOBUFS: "No buffer space available", |
| 139 |
ENODEV: "No such device", |
| 140 |
ENOENT: "No such file or directory", |
| 141 |
ENOEXEC: "Exec format error", |
| 142 |
ENOLCK: "No record locks available", |
| 143 |
ENOLINK: "The link has been severed", |
| 144 |
ENOMEM: "Out of memory", |
| 145 |
ENOMSG: "No message of desired type", |
| 146 |
ENOPROTOOPT: "Protocol not available", |
| 147 |
ENOSPC: "No space left on device", |
| 148 |
ENOSYS: "Not implemented on " + runtime.GOOS, |
| 149 |
ENOTCONN: "Socket is not connected", |
| 150 |
ENOTDIR: "Not a directory", |
| 151 |
ENOTEMPTY: "Directory not empty", |
| 152 |
ENOTRECOVERABLE: "State not recoverable", |
| 153 |
ENOTSOCK: "Socket operation on non-socket", |
| 154 |
ENOTSUP: "Not supported", |
| 155 |
ENOTTY: "Not a typewriter", |
| 156 |
ENXIO: "No such device or address", |
| 157 |
EOVERFLOW: "Value too large for defined data type", |
| 158 |
EOWNERDEAD: "Owner died", |
| 159 |
EPERM: "Operation not permitted", |
| 160 |
EPIPE: "Broken pipe", |
| 161 |
EPROTO: "Protocol error", |
| 162 |
EPROTONOSUPPORT: "Unknown protocol", |
| 163 |
EPROTOTYPE: "Protocol wrong type for socket", |
| 164 |
ERANGE: "Math result not representable", |
| 165 |
EROFS: "Read-only file system", |
| 166 |
ESPIPE: "Illegal seek", |
| 167 |
ESRCH: "No such process", |
| 168 |
ESTALE: "Stale file handle", |
| 169 |
ETIMEDOUT: "Connection timed out", |
| 170 |
ETXTBSY: "Text file busy", |
| 171 |
EXDEV: "Cross-device link", |
| 172 |
ENOTCAPABLE: "Capabilities insufficient", |
| 173 |
} |
| 174 |
|
| 175 |
// Do the interface allocations only once for common |
| 176 |
// Errno values. |
| 177 |
var ( |
| 178 |
errEAGAIN error = EAGAIN |
| 179 |
errEINVAL error = EINVAL |
| 180 |
errENOENT error = ENOENT |
| 181 |
) |
| 182 |
|
| 183 |
// errnoErr returns common boxed Errno values, to prevent |
| 184 |
// allocations at runtime. |
| 185 |
// |
| 186 |
// We set both noinline and nosplit to reduce code size, this function has many |
| 187 |
// call sites in the syscall package, inlining it causes a significant increase |
| 188 |
// of the compiled code; the function call ultimately does not make a difference |
| 189 |
// in the performance of syscall functions since the time is dominated by calls |
| 190 |
// to the imports and path resolution. |
| 191 |
// |
| 192 |
//go:noinline |
| 193 |
//go:nosplit |
| 194 |
func errnoErr(e Errno) error { |
| 195 |
switch e { |
| 196 |
case 0: |
| 197 |
return nil |
| 198 |
case EAGAIN: |
| 199 |
return errEAGAIN |
| 200 |
case EINVAL: |
| 201 |
return errEINVAL |
| 202 |
case ENOENT: |
| 203 |
return errENOENT |
| 204 |
} |
| 205 |
return e |
| 206 |
} |