Coverage Report

Created: 2025-08-29 06:29

/src/WasmEdge/lib/host/wasi/linux.h
Line
Count
Source (jump to first uncovered line)
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2024 Second State INC
3
4
#include "common/defines.h"
5
#include "common/types.h"
6
#if !WASMEDGE_OS_LINUX
7
#error
8
#endif
9
10
// Uncomment these flag to test CentOS 6
11
// #undef __GLIBC_MINOR__
12
// #define __GLIBC_MINOR__ 5
13
14
#include "common/errcode.h"
15
#include "wasi/api.hpp"
16
#include <cerrno>
17
#include <chrono>
18
#include <csignal>
19
#include <cstdio>
20
#include <ctime>
21
#include <dirent.h>
22
#include <fcntl.h>
23
#include <sched.h>
24
#include <sys/epoll.h>
25
#include <sys/ioctl.h>
26
#include <sys/time.h>
27
#include <sys/types.h>
28
#include <sys/uio.h>
29
#include <sys/un.h>
30
#include <sys/wait.h>
31
#include <unistd.h>
32
33
// socket include
34
#include <arpa/inet.h>
35
#include <netdb.h>
36
#include <netinet/in.h>
37
#include <sys/socket.h>
38
39
#include <sys/stat.h>
40
41
#if defined(__GLIBC_PREREQ)
42
#if defined(_LIBCPP_GLIBC_PREREQ)
43
#undef _LIBCPP_GLIBC_PREREQ
44
#endif
45
#define _LIBCPP_GLIBC_PREREQ(a, b) 0
46
#else
47
#if defined(_LIBCPP_GLIBC_PREREQ)
48
#define __GLIBC_PREREQ(a, b) _LIBCPP_GLIBC_PREREQ(a, b)
49
#else
50
#define __GLIBC_PREREQ(a, b) 1
51
#endif
52
#endif
53
54
#if __GLIBC_PREREQ(2, 8)
55
#include <sys/timerfd.h>
56
#endif
57
58
namespace WasmEdge {
59
namespace Host {
60
namespace WASI {
61
inline namespace detail {
62
63
0
inline constexpr __wasi_errno_t fromErrNo(int ErrNo) noexcept {
64
0
  switch (ErrNo) {
65
0
  case 0:
66
0
    return __WASI_ERRNO_SUCCESS;
67
0
  case E2BIG:
68
0
    return __WASI_ERRNO_2BIG;
69
0
  case EACCES:
70
0
    return __WASI_ERRNO_ACCES;
71
0
  case EADDRINUSE:
72
0
    return __WASI_ERRNO_ADDRINUSE;
73
0
  case EADDRNOTAVAIL:
74
0
    return __WASI_ERRNO_ADDRNOTAVAIL;
75
0
  case EAFNOSUPPORT:
76
0
    return __WASI_ERRNO_AFNOSUPPORT;
77
0
  case EAGAIN:
78
0
    return __WASI_ERRNO_AGAIN;
79
0
  case EALREADY:
80
0
    return __WASI_ERRNO_ALREADY;
81
0
  case EBADF:
82
0
    return __WASI_ERRNO_BADF;
83
0
  case EBADMSG:
84
0
    return __WASI_ERRNO_BADMSG;
85
0
  case EBUSY:
86
0
    return __WASI_ERRNO_BUSY;
87
0
  case ECANCELED:
88
0
    return __WASI_ERRNO_CANCELED;
89
0
  case ECHILD:
90
0
    return __WASI_ERRNO_CHILD;
91
0
  case ECONNABORTED:
92
0
    return __WASI_ERRNO_CONNABORTED;
93
0
  case ECONNREFUSED:
94
0
    return __WASI_ERRNO_CONNREFUSED;
95
0
  case ECONNRESET:
96
0
    return __WASI_ERRNO_CONNRESET;
97
0
  case EDEADLK:
98
0
    return __WASI_ERRNO_DEADLK;
99
0
  case EDESTADDRREQ:
100
0
    return __WASI_ERRNO_DESTADDRREQ;
101
0
  case EDOM:
102
0
    return __WASI_ERRNO_DOM;
103
0
  case EDQUOT:
104
0
    return __WASI_ERRNO_DQUOT;
105
0
  case EEXIST:
106
0
    return __WASI_ERRNO_EXIST;
107
0
  case EFAULT:
108
0
    return __WASI_ERRNO_FAULT;
109
0
  case EFBIG:
110
0
    return __WASI_ERRNO_FBIG;
111
0
  case EHOSTUNREACH:
112
0
    return __WASI_ERRNO_HOSTUNREACH;
113
0
  case EIDRM:
114
0
    return __WASI_ERRNO_IDRM;
115
0
  case EILSEQ:
116
0
    return __WASI_ERRNO_ILSEQ;
117
0
  case EINPROGRESS:
118
0
    return __WASI_ERRNO_INPROGRESS;
119
0
  case EINTR:
120
0
    return __WASI_ERRNO_INTR;
121
0
  case EINVAL:
122
0
    return __WASI_ERRNO_INVAL;
123
0
  case EIO:
124
0
    return __WASI_ERRNO_IO;
125
0
  case EISCONN:
126
0
    return __WASI_ERRNO_ISCONN;
127
0
  case EISDIR:
128
0
    return __WASI_ERRNO_ISDIR;
129
0
  case ELOOP:
130
0
    return __WASI_ERRNO_LOOP;
131
0
  case EMFILE:
132
0
    return __WASI_ERRNO_MFILE;
133
0
  case EMLINK:
134
0
    return __WASI_ERRNO_MLINK;
135
0
  case EMSGSIZE:
136
0
    return __WASI_ERRNO_MSGSIZE;
137
0
  case EMULTIHOP:
138
0
    return __WASI_ERRNO_MULTIHOP;
139
0
  case ENAMETOOLONG:
140
0
    return __WASI_ERRNO_NAMETOOLONG;
141
0
  case ENETDOWN:
142
0
    return __WASI_ERRNO_NETDOWN;
143
0
  case ENETRESET:
144
0
    return __WASI_ERRNO_NETRESET;
145
0
  case ENETUNREACH:
146
0
    return __WASI_ERRNO_NETUNREACH;
147
0
  case ENFILE:
148
0
    return __WASI_ERRNO_NFILE;
149
0
  case ENOBUFS:
150
0
    return __WASI_ERRNO_NOBUFS;
151
0
  case ENODEV:
152
0
    return __WASI_ERRNO_NODEV;
153
0
  case ENOENT:
154
0
    return __WASI_ERRNO_NOENT;
155
0
  case ENOEXEC:
156
0
    return __WASI_ERRNO_NOEXEC;
157
0
  case ENOLCK:
158
0
    return __WASI_ERRNO_NOLCK;
159
0
  case ENOLINK:
160
0
    return __WASI_ERRNO_NOLINK;
161
0
  case ENOMEM:
162
0
    return __WASI_ERRNO_NOMEM;
163
0
  case ENOMSG:
164
0
    return __WASI_ERRNO_NOMSG;
165
0
  case ENOPROTOOPT:
166
0
    return __WASI_ERRNO_NOPROTOOPT;
167
0
  case ENOSPC:
168
0
    return __WASI_ERRNO_NOSPC;
169
0
  case ENOSYS:
170
0
    return __WASI_ERRNO_NOSYS;
171
0
  case ENOTCONN:
172
0
    return __WASI_ERRNO_NOTCONN;
173
0
  case ENOTDIR:
174
0
    return __WASI_ERRNO_NOTDIR;
175
0
  case ENOTEMPTY:
176
0
    return __WASI_ERRNO_NOTEMPTY;
177
0
  case ENOTRECOVERABLE:
178
0
    return __WASI_ERRNO_NOTRECOVERABLE;
179
0
  case ENOTSOCK:
180
0
    return __WASI_ERRNO_NOTSOCK;
181
0
  case ENOTSUP:
182
0
    return __WASI_ERRNO_NOTSUP;
183
0
  case ENOTTY:
184
0
    return __WASI_ERRNO_NOTTY;
185
0
  case ENXIO:
186
0
    return __WASI_ERRNO_NXIO;
187
0
  case EOVERFLOW:
188
0
    return __WASI_ERRNO_OVERFLOW;
189
0
  case EOWNERDEAD:
190
0
    return __WASI_ERRNO_OWNERDEAD;
191
0
  case EPERM:
192
0
    return __WASI_ERRNO_PERM;
193
0
  case EPIPE:
194
0
    return __WASI_ERRNO_PIPE;
195
0
  case EPROTO:
196
0
    return __WASI_ERRNO_PROTO;
197
0
  case EPROTONOSUPPORT:
198
0
    return __WASI_ERRNO_PROTONOSUPPORT;
199
0
  case EPROTOTYPE:
200
0
    return __WASI_ERRNO_PROTOTYPE;
201
0
  case ERANGE:
202
0
    return __WASI_ERRNO_RANGE;
203
0
  case EROFS:
204
0
    return __WASI_ERRNO_ROFS;
205
0
  case ESPIPE:
206
0
    return __WASI_ERRNO_SPIPE;
207
0
  case ESRCH:
208
0
    return __WASI_ERRNO_SRCH;
209
0
  case ESTALE:
210
0
    return __WASI_ERRNO_STALE;
211
0
  case ETIMEDOUT:
212
0
    return __WASI_ERRNO_TIMEDOUT;
213
0
  case ETXTBSY:
214
0
    return __WASI_ERRNO_TXTBSY;
215
0
  case EXDEV:
216
0
    return __WASI_ERRNO_XDEV;
217
0
  default:
218
0
    assumingUnreachable();
219
0
  }
220
0
}
221
222
0
inline constexpr __wasi_errno_t fromEAIErrNo(int ErrNo) noexcept {
223
0
  switch (ErrNo) {
224
0
  case EAI_ADDRFAMILY:
225
0
    return __WASI_ERRNO_AIADDRFAMILY;
226
0
  case EAI_AGAIN:
227
0
    return __WASI_ERRNO_AIAGAIN;
228
0
  case EAI_BADFLAGS:
229
0
    return __WASI_ERRNO_AIBADFLAG;
230
0
  case EAI_FAIL:
231
0
    return __WASI_ERRNO_AIFAIL;
232
0
  case EAI_FAMILY:
233
0
    return __WASI_ERRNO_AIFAMILY;
234
0
  case EAI_MEMORY:
235
0
    return __WASI_ERRNO_AIMEMORY;
236
0
  case EAI_NODATA:
237
0
    return __WASI_ERRNO_AINODATA;
238
0
  case EAI_NONAME:
239
0
    return __WASI_ERRNO_AINONAME;
240
0
  case EAI_SERVICE:
241
0
    return __WASI_ERRNO_AISERVICE;
242
0
  case EAI_SOCKTYPE:
243
0
    return __WASI_ERRNO_AISOCKTYPE;
244
0
  case EAI_SYSTEM:
245
0
    return __WASI_ERRNO_AISYSTEM;
246
0
  default:
247
0
    assumingUnreachable();
248
0
  }
249
0
}
250
251
0
inline constexpr clockid_t toClockId(__wasi_clockid_t Clock) noexcept {
252
0
  switch (Clock) {
253
0
  case __WASI_CLOCKID_REALTIME:
254
0
    return CLOCK_REALTIME;
255
0
  case __WASI_CLOCKID_MONOTONIC:
256
0
    return CLOCK_MONOTONIC;
257
0
  case __WASI_CLOCKID_PROCESS_CPUTIME_ID:
258
0
    return CLOCK_PROCESS_CPUTIME_ID;
259
0
  case __WASI_CLOCKID_THREAD_CPUTIME_ID:
260
0
    return CLOCK_THREAD_CPUTIME_ID;
261
0
  default:
262
0
    assumingUnreachable();
263
0
  }
264
0
}
265
266
0
inline constexpr timespec toTimespec(__wasi_timestamp_t Timestamp) noexcept {
267
0
  using namespace std::chrono;
268
0
  const auto Total = duration<uint64_t, std::nano>(Timestamp);
269
0
  const auto Second = duration_cast<seconds>(Total);
270
0
  const auto Nano = Total - Second;
271
0
  timespec Result{};
272
0
  Result.tv_sec = Second.count();
273
0
  Result.tv_nsec = Nano.count();
274
0
  return Result;
275
0
}
276
277
inline constexpr EndianValue<__wasi_timestamp_t>
278
0
fromTimespec(const timespec &Time) noexcept {
279
0
  using namespace std::chrono;
280
0
  const auto Result = seconds(Time.tv_sec) + nanoseconds(Time.tv_nsec);
281
0
  return Result.count();
282
0
}
283
284
#if !__GLIBC_PREREQ(2, 6)
285
inline constexpr timeval toTimeval(__wasi_timestamp_t Timestamp) noexcept {
286
  using namespace std::chrono;
287
  const auto Total = duration_cast<microseconds>(nanoseconds(Timestamp));
288
  const auto Second = duration_cast<seconds>(Total);
289
  const auto Micro = Total - Second;
290
  timeval Result{};
291
  Result.tv_sec = Second.count();
292
  Result.tv_usec = Micro.count();
293
  return Result;
294
}
295
inline constexpr timeval toTimeval(timespec Timespec) noexcept {
296
  using namespace std::chrono;
297
  timeval Result{};
298
  Result.tv_sec = Timespec.tv_sec;
299
  Result.tv_usec =
300
      duration_cast<microseconds>(nanoseconds(Timespec.tv_nsec)).count();
301
  return Result;
302
}
303
#endif
304
305
0
inline constexpr int toAdvice(__wasi_advice_t Advice) noexcept {
306
0
  switch (Advice) {
307
0
  case __WASI_ADVICE_NORMAL:
308
0
    return POSIX_FADV_NORMAL;
309
0
  case __WASI_ADVICE_SEQUENTIAL:
310
0
    return POSIX_FADV_SEQUENTIAL;
311
0
  case __WASI_ADVICE_RANDOM:
312
0
    return POSIX_FADV_RANDOM;
313
0
  case __WASI_ADVICE_WILLNEED:
314
0
    return POSIX_FADV_WILLNEED;
315
0
  case __WASI_ADVICE_DONTNEED:
316
0
    return POSIX_FADV_DONTNEED;
317
0
  case __WASI_ADVICE_NOREUSE:
318
0
    return POSIX_FADV_NOREUSE;
319
0
  default:
320
0
    assumingUnreachable();
321
0
  }
322
0
}
323
324
0
inline constexpr __wasi_filetype_t fromFileType(mode_t Mode) noexcept {
325
0
  switch (Mode & S_IFMT) {
326
0
  case S_IFBLK:
327
0
    return __WASI_FILETYPE_BLOCK_DEVICE;
328
0
  case S_IFCHR:
329
0
    return __WASI_FILETYPE_CHARACTER_DEVICE;
330
0
  case S_IFDIR:
331
0
    return __WASI_FILETYPE_DIRECTORY;
332
0
  case S_IFREG:
333
0
    return __WASI_FILETYPE_REGULAR_FILE;
334
0
  case S_IFSOCK:
335
0
    return __WASI_FILETYPE_SOCKET_STREAM;
336
0
  case S_IFLNK:
337
0
    return __WASI_FILETYPE_SYMBOLIC_LINK;
338
0
  case S_IFIFO:
339
0
  default:
340
0
    return __WASI_FILETYPE_UNKNOWN;
341
0
  }
342
0
}
343
344
0
inline constexpr __wasi_filetype_t fromFileType(uint8_t Type) noexcept {
345
0
  switch (Type) {
346
0
  case DT_BLK:
347
0
    return __WASI_FILETYPE_BLOCK_DEVICE;
348
0
  case DT_CHR:
349
0
    return __WASI_FILETYPE_CHARACTER_DEVICE;
350
0
  case DT_DIR:
351
0
    return __WASI_FILETYPE_DIRECTORY;
352
0
  case DT_LNK:
353
0
    return __WASI_FILETYPE_SYMBOLIC_LINK;
354
0
  case DT_REG:
355
0
    return __WASI_FILETYPE_REGULAR_FILE;
356
0
  case DT_SOCK:
357
0
    return __WASI_FILETYPE_SOCKET_STREAM;
358
0
  case DT_FIFO:
359
0
  case DT_UNKNOWN:
360
0
  default:
361
0
    return __WASI_FILETYPE_UNKNOWN;
362
0
  }
363
0
}
364
365
0
inline constexpr int toWhence(__wasi_whence_t Whence) noexcept {
366
0
  switch (Whence) {
367
0
  case __WASI_WHENCE_CUR:
368
0
    return SEEK_CUR;
369
0
  case __WASI_WHENCE_END:
370
0
    return SEEK_END;
371
0
  case __WASI_WHENCE_SET:
372
0
    return SEEK_SET;
373
0
  default:
374
0
    assumingUnreachable();
375
0
  }
376
0
}
377
378
0
inline constexpr int toSockOptLevel(__wasi_sock_opt_level_t Level) noexcept {
379
0
  switch (Level) {
380
0
  case __WASI_SOCK_OPT_LEVEL_SOL_SOCKET:
381
0
    return SOL_SOCKET;
382
0
  default:
383
0
    assumingUnreachable();
384
0
  }
385
0
}
386
387
0
inline constexpr int toSockOptSoName(__wasi_sock_opt_so_t SoName) noexcept {
388
0
  switch (SoName) {
389
0
  case __WASI_SOCK_OPT_SO_REUSEADDR:
390
0
    return SO_REUSEADDR;
391
0
  case __WASI_SOCK_OPT_SO_TYPE:
392
0
    return SO_TYPE;
393
0
  case __WASI_SOCK_OPT_SO_ERROR:
394
0
    return SO_ERROR;
395
0
  case __WASI_SOCK_OPT_SO_DONTROUTE:
396
0
    return SO_DONTROUTE;
397
0
  case __WASI_SOCK_OPT_SO_BROADCAST:
398
0
    return SO_BROADCAST;
399
0
  case __WASI_SOCK_OPT_SO_SNDBUF:
400
0
    return SO_SNDBUF;
401
0
  case __WASI_SOCK_OPT_SO_RCVBUF:
402
0
    return SO_RCVBUF;
403
0
  case __WASI_SOCK_OPT_SO_KEEPALIVE:
404
0
    return SO_KEEPALIVE;
405
0
  case __WASI_SOCK_OPT_SO_OOBINLINE:
406
0
    return SO_OOBINLINE;
407
0
  case __WASI_SOCK_OPT_SO_LINGER:
408
0
    return SO_LINGER;
409
0
  case __WASI_SOCK_OPT_SO_RCVLOWAT:
410
0
    return SO_RCVLOWAT;
411
0
  case __WASI_SOCK_OPT_SO_RCVTIMEO:
412
0
    return SO_RCVTIMEO;
413
0
  case __WASI_SOCK_OPT_SO_SNDTIMEO:
414
0
    return SO_SNDTIMEO;
415
0
  case __WASI_SOCK_OPT_SO_ACCEPTCONN:
416
0
    return SO_ACCEPTCONN;
417
0
  case __WASI_SOCK_OPT_SO_BINDTODEVICE:
418
0
    return SO_BINDTODEVICE;
419
420
0
  default:
421
0
    assumingUnreachable();
422
0
  }
423
0
}
424
425
0
inline constexpr __wasi_aiflags_t fromAIFlags(int AIFlags) noexcept {
426
0
  __wasi_aiflags_t Result = static_cast<__wasi_aiflags_t>(0);
427
428
0
  if (AIFlags & AI_PASSIVE) {
429
0
    Result |= __WASI_AIFLAGS_AI_PASSIVE;
430
0
  }
431
0
  if (AIFlags & AI_CANONNAME) {
432
0
    Result |= __WASI_AIFLAGS_AI_CANONNAME;
433
0
  }
434
0
  if (AIFlags & AI_NUMERICHOST) {
435
0
    Result |= __WASI_AIFLAGS_AI_NUMERICHOST;
436
0
  }
437
0
  if (AIFlags & AI_NUMERICSERV) {
438
0
    Result |= __WASI_AIFLAGS_AI_NUMERICSERV;
439
0
  }
440
0
  if (AIFlags & AI_V4MAPPED) {
441
0
    Result |= __WASI_AIFLAGS_AI_V4MAPPED;
442
0
  }
443
0
  if (AIFlags & AI_ALL) {
444
0
    Result |= __WASI_AIFLAGS_AI_ALL;
445
0
  }
446
0
  if (AIFlags & AI_ADDRCONFIG) {
447
0
    Result |= __WASI_AIFLAGS_AI_ADDRCONFIG;
448
0
  }
449
450
0
  return Result;
451
0
}
452
453
0
inline constexpr int toAIFlags(__wasi_aiflags_t AIFlags) noexcept {
454
0
  int Result = 0;
455
456
0
  if (AIFlags & __WASI_AIFLAGS_AI_PASSIVE) {
457
0
    Result |= AI_PASSIVE;
458
0
  }
459
0
  if (AIFlags & __WASI_AIFLAGS_AI_CANONNAME) {
460
0
    Result |= AI_CANONNAME;
461
0
  }
462
0
  if (AIFlags & __WASI_AIFLAGS_AI_NUMERICHOST) {
463
0
    Result |= AI_NUMERICHOST;
464
0
  }
465
0
  if (AIFlags & __WASI_AIFLAGS_AI_NUMERICSERV) {
466
0
    Result |= AI_NUMERICSERV;
467
0
  }
468
0
  if (AIFlags & __WASI_AIFLAGS_AI_V4MAPPED) {
469
0
    Result |= AI_V4MAPPED;
470
0
  }
471
0
  if (AIFlags & __WASI_AIFLAGS_AI_ALL) {
472
0
    Result |= AI_ALL;
473
0
  }
474
0
  if (AIFlags & __WASI_AIFLAGS_AI_ADDRCONFIG) {
475
0
    Result |= AI_ADDRCONFIG;
476
0
  }
477
478
0
  return Result;
479
0
}
480
481
0
inline constexpr __wasi_sock_type_t fromSockType(int SockType) noexcept {
482
0
  switch (SockType) {
483
0
  case 0:
484
0
    return __WASI_SOCK_TYPE_SOCK_ANY;
485
0
  case SOCK_DGRAM:
486
0
    return __WASI_SOCK_TYPE_SOCK_DGRAM;
487
0
  case SOCK_STREAM:
488
0
    return __WASI_SOCK_TYPE_SOCK_STREAM;
489
0
  default:
490
0
    assumingUnreachable();
491
0
  }
492
0
}
493
494
0
inline constexpr int toSockType(__wasi_sock_type_t SockType) noexcept {
495
0
  switch (SockType) {
496
0
  case __WASI_SOCK_TYPE_SOCK_ANY:
497
0
    return 0;
498
0
  case __WASI_SOCK_TYPE_SOCK_DGRAM:
499
0
    return SOCK_DGRAM;
500
0
  case __WASI_SOCK_TYPE_SOCK_STREAM:
501
0
    return SOCK_STREAM;
502
0
  default:
503
0
    assumingUnreachable();
504
0
  }
505
0
}
506
507
0
inline constexpr __wasi_protocol_t fromProtocol(int Protocol) noexcept {
508
0
  switch (Protocol) {
509
0
  case IPPROTO_IP:
510
0
    return __WASI_PROTOCOL_IPPROTO_IP;
511
0
  case IPPROTO_TCP:
512
0
    return __WASI_PROTOCOL_IPPROTO_TCP;
513
0
  case IPPROTO_UDP:
514
0
    return __WASI_PROTOCOL_IPPROTO_UDP;
515
0
  default:
516
0
    assumingUnreachable();
517
0
  }
518
0
}
519
520
0
inline constexpr int toProtocol(__wasi_protocol_t Protocol) noexcept {
521
0
  switch (Protocol) {
522
0
  case __WASI_PROTOCOL_IPPROTO_IP:
523
0
    return IPPROTO_IP;
524
0
  case __WASI_PROTOCOL_IPPROTO_TCP:
525
0
    return IPPROTO_TCP;
526
0
  case __WASI_PROTOCOL_IPPROTO_UDP:
527
0
    return IPPROTO_UDP;
528
0
  default:
529
0
    assumingUnreachable();
530
0
  }
531
0
}
532
533
inline constexpr __wasi_address_family_t
534
0
fromAddressFamily(int AddressFamily) noexcept {
535
0
  switch (AddressFamily) {
536
0
  case PF_UNSPEC:
537
0
    return __WASI_ADDRESS_FAMILY_UNSPEC;
538
0
  case PF_INET:
539
0
    return __WASI_ADDRESS_FAMILY_INET4;
540
0
  case PF_INET6:
541
0
    return __WASI_ADDRESS_FAMILY_INET6;
542
0
  case PF_UNIX:
543
0
    return __WASI_ADDRESS_FAMILY_AF_UNIX;
544
0
  default:
545
0
    assumingUnreachable();
546
0
  }
547
0
}
548
549
inline constexpr int
550
0
toAddressFamily(__wasi_address_family_t AddressFamily) noexcept {
551
0
  switch (AddressFamily) {
552
0
  case __WASI_ADDRESS_FAMILY_UNSPEC:
553
0
    return PF_UNSPEC;
554
0
  case __WASI_ADDRESS_FAMILY_INET4:
555
0
    return PF_INET;
556
0
  case __WASI_ADDRESS_FAMILY_INET6:
557
0
    return PF_INET6;
558
0
  case __WASI_ADDRESS_FAMILY_AF_UNIX:
559
0
    return PF_UNIX;
560
0
  default:
561
0
    assumingUnreachable();
562
0
  }
563
0
}
564
565
} // namespace detail
566
} // namespace WASI
567
} // namespace Host
568
} // namespace WasmEdge