1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
package wasip1
import (
"fmt"
"github.com/tetratelabs/wazero/experimental/sys"
)
// Errno is neither uint16 nor an alias for parity with wasm.ValueType.
type Errno = uint32
// ErrnoName returns the POSIX error code name, except ErrnoSuccess, which is
// not an error. e.g. Errno2big -> "E2BIG"
func ErrnoName(errno uint32) string {
if int(errno) < len(errnoToString) {
return errnoToString[errno]
}
return fmt.Sprintf("errno(%d)", errno)
}
// Note: Below prefers POSIX symbol names over WASI ones, even if the docs are from WASI.
// See https://linux.die.net/man/3/errno
// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#variants-1
const (
// ErrnoSuccess No error occurred. System call completed successfully.
ErrnoSuccess Errno = iota
// Errno2big Argument list too long.
Errno2big
// ErrnoAcces Permission denied.
ErrnoAcces
// ErrnoAddrinuse Address in use.
ErrnoAddrinuse
// ErrnoAddrnotavail Address not available.
ErrnoAddrnotavail
// ErrnoAfnosupport Address family not supported.
ErrnoAfnosupport
// ErrnoAgain Resource unavailable, or operation would block.
ErrnoAgain
// ErrnoAlready Connection already in progress.
ErrnoAlready
// ErrnoBadf Bad file descriptor.
ErrnoBadf
// ErrnoBadmsg Bad message.
ErrnoBadmsg
// ErrnoBusy Device or resource busy.
ErrnoBusy
// ErrnoCanceled Operation canceled.
ErrnoCanceled
// ErrnoChild No child processes.
ErrnoChild
// ErrnoConnaborted Connection aborted.
ErrnoConnaborted
// ErrnoConnrefused Connection refused.
ErrnoConnrefused
// ErrnoConnreset Connection reset.
ErrnoConnreset
// ErrnoDeadlk Resource deadlock would occur.
ErrnoDeadlk
// ErrnoDestaddrreq Destination address required.
ErrnoDestaddrreq
// ErrnoDom Mathematics argument out of domain of function.
ErrnoDom
// ErrnoDquot Reserved.
ErrnoDquot
// ErrnoExist File exists.
ErrnoExist
// ErrnoFault Bad address.
ErrnoFault
// ErrnoFbig File too large.
ErrnoFbig
// ErrnoHostunreach Host is unreachable.
ErrnoHostunreach
// ErrnoIdrm Identifier removed.
ErrnoIdrm
// ErrnoIlseq Illegal byte sequence.
ErrnoIlseq
// ErrnoInprogress Operation in progress.
ErrnoInprogress
// ErrnoIntr Interrupted function.
ErrnoIntr
// ErrnoInval Invalid argument.
ErrnoInval
// ErrnoIo I/O error.
ErrnoIo
// ErrnoIsconn Socket is connected.
ErrnoIsconn
// ErrnoIsdir Is a directory.
ErrnoIsdir
// ErrnoLoop Too many levels of symbolic links.
ErrnoLoop
// ErrnoMfile File descriptor value too large.
ErrnoMfile
// ErrnoMlink Too many links.
ErrnoMlink
// ErrnoMsgsize Message too large.
ErrnoMsgsize
// ErrnoMultihop Reserved.
ErrnoMultihop
// ErrnoNametoolong Filename too long.
ErrnoNametoolong
// ErrnoNetdown Network is down.
ErrnoNetdown
// ErrnoNetreset Connection aborted by network.
ErrnoNetreset
// ErrnoNetunreach Network unreachable.
ErrnoNetunreach
// ErrnoNfile Too many files open in system.
ErrnoNfile
// ErrnoNobufs No buffer space available.
ErrnoNobufs
// ErrnoNodev No such device.
ErrnoNodev
// ErrnoNoent No such file or directory.
ErrnoNoent
// ErrnoNoexec Executable file format error.
ErrnoNoexec
// ErrnoNolck No locks available.
ErrnoNolck
// ErrnoNolink Reserved.
ErrnoNolink
// ErrnoNomem Not enough space.
ErrnoNomem
// ErrnoNomsg No message of the desired type.
ErrnoNomsg
// ErrnoNoprotoopt No message of the desired type.
ErrnoNoprotoopt
// ErrnoNospc No space left on device.
ErrnoNospc
// ErrnoNosys function not supported.
ErrnoNosys
// ErrnoNotconn The socket is not connected.
ErrnoNotconn
// ErrnoNotdir Not a directory or a symbolic link to a directory.
ErrnoNotdir
// ErrnoNotempty Directory not empty.
ErrnoNotempty
// ErrnoNotrecoverable State not recoverable.
ErrnoNotrecoverable
// ErrnoNotsock Not a socket.
ErrnoNotsock
// ErrnoNotsup Not supported, or operation not supported on socket.
ErrnoNotsup
// ErrnoNotty Inappropriate I/O control operation.
ErrnoNotty
// ErrnoNxio No such device or address.
ErrnoNxio
// ErrnoOverflow Value too large to be stored in data type.
ErrnoOverflow
// ErrnoOwnerdead Previous owner died.
ErrnoOwnerdead
// ErrnoPerm Operation not permitted.
ErrnoPerm
// ErrnoPipe Broken pipe.
ErrnoPipe
// ErrnoProto Protocol error.
ErrnoProto
// ErrnoProtonosupport Protocol error.
ErrnoProtonosupport
// ErrnoPrototype Protocol wrong type for socket.
ErrnoPrototype
// ErrnoRange Result too large.
ErrnoRange
// ErrnoRofs Read-only file system.
ErrnoRofs
// ErrnoSpipe Invalid seek.
ErrnoSpipe
// ErrnoSrch No such process.
ErrnoSrch
// ErrnoStale Reserved.
ErrnoStale
// ErrnoTimedout Connection timed out.
ErrnoTimedout
// ErrnoTxtbsy Text file busy.
ErrnoTxtbsy
// ErrnoXdev Cross-device link.
ErrnoXdev
// Note: ErrnoNotcapable was removed by WASI maintainers.
// See https://github.com/WebAssembly/wasi-libc/pull/294
)
var errnoToString = [...]string{
"ESUCCESS",
"E2BIG",
"EACCES",
"EADDRINUSE",
"EADDRNOTAVAIL",
"EAFNOSUPPORT",
"EAGAIN",
"EALREADY",
"EBADF",
"EBADMSG",
"EBUSY",
"ECANCELED",
"ECHILD",
"ECONNABORTED",
"ECONNREFUSED",
"ECONNRESET",
"EDEADLK",
"EDESTADDRREQ",
"EDOM",
"EDQUOT",
"EEXIST",
"EFAULT",
"EFBIG",
"EHOSTUNREACH",
"EIDRM",
"EILSEQ",
"EINPROGRESS",
"EINTR",
"EINVAL",
"EIO",
"EISCONN",
"EISDIR",
"ELOOP",
"EMFILE",
"EMLINK",
"EMSGSIZE",
"EMULTIHOP",
"ENAMETOOLONG",
"ENETDOWN",
"ENETRESET",
"ENETUNREACH",
"ENFILE",
"ENOBUFS",
"ENODEV",
"ENOENT",
"ENOEXEC",
"ENOLCK",
"ENOLINK",
"ENOMEM",
"ENOMSG",
"ENOPROTOOPT",
"ENOSPC",
"ENOSYS",
"ENOTCONN",
"ENOTDIR",
"ENOTEMPTY",
"ENOTRECOVERABLE",
"ENOTSOCK",
"ENOTSUP",
"ENOTTY",
"ENXIO",
"EOVERFLOW",
"EOWNERDEAD",
"EPERM",
"EPIPE",
"EPROTO",
"EPROTONOSUPPORT",
"EPROTOTYPE",
"ERANGE",
"EROFS",
"ESPIPE",
"ESRCH",
"ESTALE",
"ETIMEDOUT",
"ETXTBSY",
"EXDEV",
"ENOTCAPABLE",
}
// ToErrno coerces the error to a WASI Errno.
//
// Note: Coercion isn't centralized in sys.FSContext because ABI use different
// error codes. For example, wasi-filesystem doesn't map to these
// Errno.
func ToErrno(errno sys.Errno) Errno {
switch errno {
case 0:
return ErrnoSuccess
case sys.EACCES:
return ErrnoAcces
case sys.EAGAIN:
return ErrnoAgain
case sys.EBADF:
return ErrnoBadf
case sys.EEXIST:
return ErrnoExist
case sys.EFAULT:
return ErrnoFault
case sys.EINTR:
return ErrnoIntr
case sys.EINVAL:
return ErrnoInval
case sys.EIO:
return ErrnoIo
case sys.EISDIR:
return ErrnoIsdir
case sys.ELOOP:
return ErrnoLoop
case sys.ENAMETOOLONG:
return ErrnoNametoolong
case sys.ENOENT:
return ErrnoNoent
case sys.ENOSYS:
return ErrnoNosys
case sys.ENOTDIR:
return ErrnoNotdir
case sys.ERANGE:
return ErrnoRange
case sys.ENOTEMPTY:
return ErrnoNotempty
case sys.ENOTSOCK:
return ErrnoNotsock
case sys.ENOTSUP:
return ErrnoNotsup
case sys.EPERM:
return ErrnoPerm
case sys.EROFS:
return ErrnoRofs
default:
return ErrnoIo
}
}
|