Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/lib/host/wasi/wasimodule.cpp
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 "host/wasi/wasimodule.h"
5
#include "host/wasi/wasifunc.h"
6
7
#include <memory>
8
9
namespace WasmEdge {
10
namespace Host {
11
12
0
WasiModule::WasiModule() : ModuleInstance("wasi_snapshot_preview1") {
13
0
  addHostFunc("args_get", std::make_unique<WasiArgsGet>(Env));
14
0
  addHostFunc("args_sizes_get", std::make_unique<WasiArgsSizesGet>(Env));
15
0
  addHostFunc("environ_get", std::make_unique<WasiEnvironGet>(Env));
16
0
  addHostFunc("environ_sizes_get", std::make_unique<WasiEnvironSizesGet>(Env));
17
0
  addHostFunc("clock_res_get", std::make_unique<WasiClockResGet>(Env));
18
0
  addHostFunc("clock_time_get", std::make_unique<WasiClockTimeGet>(Env));
19
0
  addHostFunc("fd_advise", std::make_unique<WasiFdAdvise>(Env));
20
0
  addHostFunc("fd_allocate", std::make_unique<WasiFdAllocate>(Env));
21
0
  addHostFunc("fd_close", std::make_unique<WasiFdClose>(Env));
22
0
  addHostFunc("fd_datasync", std::make_unique<WasiFdDatasync>(Env));
23
0
  addHostFunc("fd_fdstat_get", std::make_unique<WasiFdFdstatGet>(Env));
24
0
  addHostFunc("fd_fdstat_set_flags",
25
0
              std::make_unique<WasiFdFdstatSetFlags>(Env));
26
0
  addHostFunc("fd_fdstat_set_rights",
27
0
              std::make_unique<WasiFdFdstatSetRights>(Env));
28
0
  addHostFunc("fd_filestat_get", std::make_unique<WasiFdFilestatGet>(Env));
29
0
  addHostFunc("fd_filestat_set_size",
30
0
              std::make_unique<WasiFdFilestatSetSize>(Env));
31
0
  addHostFunc("fd_filestat_set_times",
32
0
              std::make_unique<WasiFdFilestatSetTimes>(Env));
33
0
  addHostFunc("fd_pread", std::make_unique<WasiFdPread>(Env));
34
0
  addHostFunc("fd_prestat_get", std::make_unique<WasiFdPrestatGet>(Env));
35
0
  addHostFunc("fd_prestat_dir_name",
36
0
              std::make_unique<WasiFdPrestatDirName>(Env));
37
0
  addHostFunc("fd_pwrite", std::make_unique<WasiFdPwrite>(Env));
38
0
  addHostFunc("fd_read", std::make_unique<WasiFdRead>(Env));
39
0
  addHostFunc("fd_readdir", std::make_unique<WasiFdReadDir>(Env));
40
0
  addHostFunc("fd_renumber", std::make_unique<WasiFdRenumber>(Env));
41
0
  addHostFunc("fd_seek", std::make_unique<WasiFdSeek>(Env));
42
0
  addHostFunc("fd_sync", std::make_unique<WasiFdSync>(Env));
43
0
  addHostFunc("fd_tell", std::make_unique<WasiFdTell>(Env));
44
0
  addHostFunc("fd_write", std::make_unique<WasiFdWrite>(Env));
45
0
  addHostFunc("path_create_directory",
46
0
              std::make_unique<WasiPathCreateDirectory>(Env));
47
0
  addHostFunc("path_filestat_get", std::make_unique<WasiPathFilestatGet>(Env));
48
0
  addHostFunc("path_filestat_set_times",
49
0
              std::make_unique<WasiPathFilestatSetTimes>(Env));
50
0
  addHostFunc("path_link", std::make_unique<WasiPathLink>(Env));
51
0
  addHostFunc("path_open", std::make_unique<WasiPathOpen>(Env));
52
0
  addHostFunc("path_readlink", std::make_unique<WasiPathReadLink>(Env));
53
0
  addHostFunc("path_remove_directory",
54
0
              std::make_unique<WasiPathRemoveDirectory>(Env));
55
0
  addHostFunc("path_rename", std::make_unique<WasiPathRename>(Env));
56
0
  addHostFunc("path_symlink", std::make_unique<WasiPathSymlink>(Env));
57
0
  addHostFunc("path_unlink_file", std::make_unique<WasiPathUnlinkFile>(Env));
58
0
  addHostFunc("poll_oneoff",
59
0
              std::make_unique<WasiPollOneoff<WASI::TriggerType::Level>>(Env));
60
0
  addHostFunc("epoll_oneoff",
61
0
              std::make_unique<WasiPollOneoff<WASI::TriggerType::Edge>>(Env));
62
0
  addHostFunc("proc_exit", std::make_unique<WasiProcExit>(Env));
63
0
  addHostFunc("proc_raise", std::make_unique<WasiProcRaise>(Env));
64
0
  addHostFunc("sched_yield", std::make_unique<WasiSchedYield>(Env));
65
0
  addHostFunc("random_get", std::make_unique<WasiRandomGet>(Env));
66
  // To make the socket API compatible with the old one,
67
  // we will duplicate all the API to V1 and V2.
68
  // The V1 presents the original behavior before 0.12 release.
69
  // On the other hand, the V2 presents the new behavior including
70
  // the sock_accept is following the WASI spec, some of the API
71
  // use a larger size for handling complex address type, e.g.
72
  // AF_UNIX.
73
  // By default, we will register V1 first, if the signatures are
74
  // not the same as the wasm application imported, then V2 will
75
  // replace instead.
76
0
  addHostFunc("sock_open", std::make_unique<WasiSockOpenV1>(Env));
77
0
  addHostFunc("sock_bind", std::make_unique<WasiSockBindV1>(Env));
78
0
  addHostFunc("sock_connect", std::make_unique<WasiSockConnectV1>(Env));
79
0
  addHostFunc("sock_listen", std::make_unique<WasiSockListenV1>(Env));
80
0
  addHostFunc("sock_accept", std::make_unique<WasiSockAcceptV1>(Env));
81
0
  addHostFunc("sock_recv", std::make_unique<WasiSockRecvV1>(Env));
82
0
  addHostFunc("sock_recv_from", std::make_unique<WasiSockRecvFromV1>(Env));
83
0
  addHostFunc("sock_send", std::make_unique<WasiSockSendV1>(Env));
84
0
  addHostFunc("sock_send_to", std::make_unique<WasiSockSendToV1>(Env));
85
0
  addHostFunc("sock_accept_v2", std::make_unique<WasiSockAcceptV2>(Env));
86
0
  addHostFunc("sock_open_v2", std::make_unique<WasiSockOpenV2>(Env));
87
0
  addHostFunc("sock_bind_v2", std::make_unique<WasiSockBindV2>(Env));
88
0
  addHostFunc("sock_connect_v2", std::make_unique<WasiSockConnectV2>(Env));
89
0
  addHostFunc("sock_listen_v2", std::make_unique<WasiSockListenV2>(Env));
90
0
  addHostFunc("sock_recv_v2", std::make_unique<WasiSockRecvV2>(Env));
91
0
  addHostFunc("sock_recv_from_v2", std::make_unique<WasiSockRecvFromV2>(Env));
92
0
  addHostFunc("sock_send_v2", std::make_unique<WasiSockSendV2>(Env));
93
0
  addHostFunc("sock_send_to_v2", std::make_unique<WasiSockSendToV2>(Env));
94
0
  addHostFunc("sock_shutdown", std::make_unique<WasiSockShutdown>(Env));
95
0
  addHostFunc("sock_getsockopt", std::make_unique<WasiSockGetOpt>(Env));
96
0
  addHostFunc("sock_setsockopt", std::make_unique<WasiSockSetOpt>(Env));
97
0
  addHostFunc("sock_getlocaladdr",
98
0
              std::make_unique<WasiSockGetLocalAddrV1>(Env));
99
0
  addHostFunc("sock_getpeeraddr", std::make_unique<WasiSockGetPeerAddrV1>(Env));
100
0
  addHostFunc("sock_getlocaladdr_v2",
101
0
              std::make_unique<WasiSockGetLocalAddrV2>(Env));
102
0
  addHostFunc("sock_getpeeraddr_v2",
103
0
              std::make_unique<WasiSockGetPeerAddrV2>(Env));
104
0
  addHostFunc("sock_getaddrinfo", std::make_unique<WasiSockGetAddrinfo>(Env));
105
0
}
106
107
} // namespace Host
108
} // namespace WasmEdge