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
62int32_t __imported_wasi_snapshot_preview1_environ_get(int32_t environ_ptr, int32_t environ_buf_ptr)
63{
64 // No environment variables, so nothing to write. The pointers point to
65 // arrays that would hold the environ entries and the concatenated
66 // key=value strings respectively, but with count == 0 they are empty.
67 (void)environ_ptr;
68 (void)environ_buf_ptr;
69 return 0;
70}
71
72int32_t __imported_wasi_snapshot_preview1_environ_sizes_get(int32_t count_ptr, int32_t buf_size_ptr)
73{
74 // WASI requires writing the number of environment variables and the total
75 // buffer size needed to hold them. We have none of either.
76 *(int32_t*)(uintptr_t)count_ptr = 0;
77 *(int32_t*)(uintptr_t)buf_size_ptr = 0;
78 return 0;
79}
80
81// int32_t __imported_wasi_snapshot_preview1_clock_time_get(int32_t, int64_t, int32_t)
82// {
83// info("clock_time_get not implemented.");
84// abort();
85// return 0;
86// }
87
89{
90 // info("fd_fdstat_get not implemented.");
91 // abort();
92 if (fd != 1 && fd != 2) {
93 info("fd_fdstat_get with unsupported file descriptor: ", fd);
94 abort();
95 }
96 memset(buf, 0, 20);
97 *(uint8_t*)buf = (uint8_t)fd;
98 return 0;
99}
100
102{
103 info("fd_fdstat_set_flags not implemented.");
104 abort();
105 return 0;
106}
107
109{
110 info("fd_filestat_get not implemented.");
111 abort();
112 return 0;
113}
114
116{
117 info("fd_filestat_set_size not implemented.");
118 abort();
119 return 0;
120}
121
123{
124 info("path_create_directory not implemented.");
125 abort();
126 return 0;
127}
128
129int32_t __imported_wasi_snapshot_preview1_fd_readdir(int32_t, int32_t, int32_t, int64_t, int32_t)
130{
131 info("fd_readdir not implemented.");
132 abort();
133 return 0;
134}
135
136int32_t __imported_wasi_snapshot_preview1_fd_advise(int32_t, int64_t, int64_t, int32_t)
137{
138 info("fd_advise not implemented.");
139 abort();
140 return 0;
141}
142
143int32_t __imported_wasi_snapshot_preview1_fd_allocate(int32_t, int64_t, int64_t)
144{
145 info("fd_allocate not implemented.");
146 abort();
147 return 0;
148}
149
151{
152 info("fd_datasync not implemented.");
153 abort();
154 return 0;
155}
156
158{
159 info("fd_sync not implemented.");
160 abort();
161 return 0;
162}
163
165{
166 info("fd_renumber not implemented.");
167 abort();
168 return 0;
169}
170
172{
173 info("fd_tell stubbed.");
174 return 0;
175}
176
177int32_t __imported_wasi_snapshot_preview1_fd_read(int32_t, int32_t, int32_t, int32_t)
178{
179 info("fd_read not implemented.");
180 abort();
181 return 0;
182}
183
185 int32_t, int32_t, int32_t, int32_t, int32_t, int64_t, int64_t, int32_t, int32_t)
186{
187 info("path_open not implemented.");
188 abort();
189 return 0;
190}
191
193{
194 // info("fd_prestat_get not implemented.");
195 // abort();
196 return 8;
197}
198
200{
201 info("fd_prestat_dir_name not implemented.");
202 abort();
203 return 28;
204}
205
206int32_t __imported_wasi_snapshot_preview1_path_filestat_get(int32_t, int32_t, int32_t, int32_t, int32_t)
207{
208 return 0;
209}
210
212 int32_t, int32_t, int32_t, int32_t, int64_t, int64_t, int32_t)
213{
214 info("path_filestat_set_times not implemented.");
215 abort();
216 return 0;
217}
218
219int32_t __imported_wasi_snapshot_preview1_path_link(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)
220{
221 info("path_link not implemented.");
222 abort();
223 return 0;
224}
225
226int32_t __imported_wasi_snapshot_preview1_path_readlink(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)
227{
228 info("path_readlink not implemented.");
229 abort();
230 return 0;
231}
232
234{
235 info("path_remove_directory not implemented.");
236 abort();
237 return 0;
238}
239
240int32_t __imported_wasi_snapshot_preview1_path_rename(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t)
241{
242 info("path_rename not implemented.");
243 abort();
244 return 0;
245}
246
247int32_t __imported_wasi_snapshot_preview1_path_symlink(int32_t, int32_t, int32_t, int32_t, int32_t)
248{
249 info("path_symlink not implemented.");
250 abort();
251 return 0;
252}
253
255{
256 info("path_unlink_file not implemented.");
257 abort();
258 return 0;
259}
260}
#define info(...)
Definition log.hpp:93
uint8_t const * buf
Definition data_store.hpp:9
void logstr(char const *msg)
Definition logstr.cpp:66
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_environ_sizes_get(int32_t count_ptr, int32_t buf_size_ptr)
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_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_environ_get(int32_t environ_ptr, int32_t environ_buf_ptr)
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_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()