Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
wasi_stubs.cpp
Go to the documentation of this file.
1// If building WASM, we can stub out functions we know we don't need, to save the host
2// environment from having to stub them itself.
4#include <cstdint>
5#include <cstdlib>
6#include <string.h>
7
8extern "C" {
9
11{
12 return 0;
13}
14
15int32_t __imported_wasi_snapshot_preview1_poll_oneoff(int32_t, int32_t, int32_t, int32_t)
16{
17 info("poll_oneoff not implemented.");
18 abort();
19}
20
21// void __imported_wasi_snapshot_preview1_proc_exit(int32_t)
22// {
23// info("proc_exit not implemented.");
24// abort();
25// }
26
28 char* data;
29 size_t len;
30};
31
32int32_t __imported_wasi_snapshot_preview1_fd_write(int32_t fd, iovs_struct* iovs_ptr, size_t iovs_len, size_t* ret_ptr)
33{
34 if (fd != 1 && fd != 2) {
35 info("fd_write to unsupported file descriptor: ", fd);
36 abort();
37 }
38 std::string str;
39 for (size_t i = 0; i < iovs_len; ++i) {
40 auto iovs = iovs_ptr[i];
41 str += std::string(iovs.data, iovs.len);
42 }
43 logstr(str.c_str());
44 *ret_ptr = str.length();
45 return 0;
46}
47
48int32_t __imported_wasi_snapshot_preview1_fd_seek(int32_t, int64_t, int32_t, int32_t)
49{
50 info("fd_seek not implemented.");
51 abort();
52 return 0;
53}
54
56{
57 info("fd_close not implemented.");
58 abort();
59 return 0;
60}
61
63{
64 // info("environ_get not implemented.");
65 // abort();
66 return 0;
67}
68
70{
71 // info("environ_sizes_get not implemented.");
72 // abort();
73 return 0;
74}
75
76// int32_t __imported_wasi_snapshot_preview1_clock_time_get(int32_t, int64_t, int32_t)
77// {
78// info("clock_time_get not implemented.");
79// abort();
80// return 0;
81// }
82
84{
85 // info("fd_fdstat_get not implemented.");
86 // abort();
87 if (fd != 1 && fd != 2) {
88 info("fd_fdstat_get with unsupported file descriptor: ", fd);
89 abort();
90 }
91 memset(buf, 0, 20);
92 *(uint8_t*)buf = (uint8_t)fd;
93 return 0;
94}
95
97{
98 info("fd_fdstat_set_flags not implemented.");
99 abort();
100 return 0;
101}
102
104{
105 info("fd_filestat_get not implemented.");
106 abort();
107 return 0;
108}
109
111{
112 info("fd_filestat_set_size not implemented.");
113 abort();
114 return 0;
115}
116
118{
119 info("path_create_directory not implemented.");
120 abort();
121 return 0;
122}
123
124int32_t __imported_wasi_snapshot_preview1_fd_readdir(int32_t, int32_t, int32_t, int64_t, int32_t)
125{
126 info("fd_readdir not implemented.");
127 abort();
128 return 0;
129}
130
131int32_t __imported_wasi_snapshot_preview1_fd_advise(int32_t, int64_t, int64_t, int32_t)
132{
133 info("fd_advise not implemented.");
134 abort();
135 return 0;
136}
137
138int32_t __imported_wasi_snapshot_preview1_fd_allocate(int32_t, int64_t, int64_t)
139{
140 info("fd_allocate not implemented.");
141 abort();
142 return 0;
143}
144
146{
147 info("fd_datasync not implemented.");
148 abort();
149 return 0;
150}
151
153{
154 info("fd_sync not implemented.");
155 abort();
156 return 0;
157}
158
160{
161 info("fd_renumber not implemented.");
162 abort();
163 return 0;
164}
165
167{
168 info("fd_tell stubbed.");
169 return 0;
170}
171
172int32_t __imported_wasi_snapshot_preview1_fd_read(int32_t, int32_t, int32_t, int32_t)
173{
174 info("fd_read not implemented.");
175 abort();
176 return 0;
177}
178
180 int32_t, int32_t, int32_t, int32_t, int32_t, int64_t, int64_t, int32_t, int32_t)
181{
182 info("path_open not implemented.");
183 abort();
184 return 0;
185}
186
188{
189 // info("fd_prestat_get not implemented.");
190 // abort();
191 return 8;
192}
193
195{
196 info("fd_prestat_dir_name not implemented.");
197 abort();
198 return 28;
199}
200
201int32_t __imported_wasi_snapshot_preview1_path_filestat_get(int32_t, int32_t, int32_t, int32_t, int32_t)
202{
203 return 0;
204}
205
207 int32_t, int32_t, int32_t, int32_t, int64_t, int64_t, int32_t)
208{
209 info("path_filestat_set_times not implemented.");
210 abort();
211 return 0;
212}
213
214int32_t __imported_wasi_snapshot_preview1_path_link(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)
215{
216 info("path_link not implemented.");
217 abort();
218 return 0;
219}
220
221int32_t __imported_wasi_snapshot_preview1_path_readlink(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)
222{
223 info("path_readlink not implemented.");
224 abort();
225 return 0;
226}
227
229{
230 info("path_remove_directory not implemented.");
231 abort();
232 return 0;
233}
234
235int32_t __imported_wasi_snapshot_preview1_path_rename(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)
236{
237 info("path_rename not implemented.");
238 abort();
239 return 0;
240}
241
242int32_t __imported_wasi_snapshot_preview1_path_symlink(int32_t, int32_t, int32_t, int32_t, int32_t)
243{
244 info("path_symlink not implemented.");
245 abort();
246 return 0;
247}
248
250{
251 info("path_unlink_file not implemented.");
252 abort();
253 return 0;
254}
255}
void info(Args... args)
Definition log.hpp:70
uint8_t const * buf
Definition data_store.hpp:9
void logstr(char const *msg)
Definition logstr.cpp:63
int32_t __imported_wasi_snapshot_preview1_path_symlink(int32_t, int32_t, int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_close(int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_filestat_set_size(int32_t, int64_t)
int32_t __imported_wasi_snapshot_preview1_fd_prestat_dir_name(int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_write(int32_t fd, iovs_struct *iovs_ptr, size_t iovs_len, size_t *ret_ptr)
int32_t __imported_wasi_snapshot_preview1_path_create_directory(int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_fdstat_get(int32_t fd, void *buf)
int32_t __imported_wasi_snapshot_preview1_fd_advise(int32_t, int64_t, int64_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_path_unlink_file(int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_readdir(int32_t, int32_t, int32_t, int64_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_environ_sizes_get(int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_allocate(int32_t, int64_t, int64_t)
int32_t __imported_wasi_snapshot_preview1_fd_seek(int32_t, int64_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_path_rename(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_path_link(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_datasync(int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_filestat_get(int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_prestat_get(int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_path_remove_directory(int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_read(int32_t, int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_path_filestat_get(int32_t, int32_t, int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_path_filestat_set_times(int32_t, int32_t, int32_t, int32_t, int64_t, int64_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_poll_oneoff(int32_t, int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_path_readlink(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_environ_get(int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_tell(int32_t, uint64_t *)
int32_t __imported_wasi_snapshot_preview1_fd_renumber(int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_fdstat_set_flags(int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_path_open(int32_t, int32_t, int32_t, int32_t, int32_t, int64_t, int64_t, int32_t, int32_t)
int32_t __imported_wasi_snapshot_preview1_fd_sync(int32_t)
int32_t __imported_wasi_snapshot_preview1_sched_yield()