|
14 | 14 | //===----------------------------------------------------------------------===//
|
15 | 15 |
|
16 | 16 | #include "sanitizer_platform.h"
|
| 17 | +#include "sanitizer_platform_limits_posix.h" |
17 | 18 | #include "sanitizer_common.h"
|
18 | 19 | #include "sanitizer_stoptheworld.h"
|
19 | 20 |
|
| 21 | +#include <fcntl.h> |
20 | 22 | #include <signal.h>
|
21 | 23 | #include <time.h>
|
| 24 | +#include <unistd.h> |
| 25 | +#include <math.h> |
22 | 26 |
|
23 | 27 | #if SANITIZER_EMSCRIPTEN
|
24 | 28 |
|
| 29 | +#include <sys/stat.h> |
| 30 | +#include <sys/types.h> |
| 31 | + |
25 | 32 | #include <emscripten.h>
|
26 | 33 | #include <emscripten/stack.h>
|
27 |
| -#include <sys/types.h> |
| 34 | +#include <wasi/api.h> |
| 35 | +#include <wasi/wasi-helpers.h> |
28 | 36 |
|
29 | 37 | #include "emscripten_internal.h"
|
30 | 38 |
|
@@ -128,6 +136,92 @@ u64 MonotonicNanoTime() {
|
128 | 136 |
|
129 | 137 | void GetMemoryProfile(fill_profile_f cb, uptr *stats) {}
|
130 | 138 |
|
| 139 | +int internal_madvise(uptr addr, uptr length, int advice) { |
| 140 | + return 0; // madvise is currently ignored |
| 141 | +} |
| 142 | + |
| 143 | +uptr internal_close(fd_t fd) { |
| 144 | + return __wasi_fd_close(fd); |
| 145 | +} |
| 146 | + |
| 147 | +uptr internal_open(const char *filename, int flags) { |
| 148 | + return open(filename, flags); |
| 149 | +} |
| 150 | + |
| 151 | +uptr internal_open(const char *filename, int flags, u32 mode) { |
| 152 | + return open(filename, flags, mode); |
| 153 | +} |
| 154 | + |
| 155 | +uptr internal_read(fd_t fd, void *buf, uptr count) { |
| 156 | + __wasi_iovec_t iov = { (uint8_t*)buf, count }; |
| 157 | + size_t num; |
| 158 | + if (__wasi_syscall_ret(__wasi_fd_read(fd, &iov, 1, &num))) { |
| 159 | + return -1; |
| 160 | + } |
| 161 | + return num; |
| 162 | +} |
| 163 | + |
| 164 | +uptr internal_write(fd_t fd, const void *buf, uptr count) { |
| 165 | + __wasi_ciovec_t iov = { (const uint8_t*)buf, count }; |
| 166 | + size_t num; |
| 167 | + if (__wasi_syscall_ret(__wasi_fd_write(fd, &iov, 1, &num))) { |
| 168 | + return -1; |
| 169 | + } |
| 170 | + return num; |
| 171 | +} |
| 172 | + |
| 173 | +uptr internal_stat(const char *path, void *buf) { |
| 174 | + return stat(path, (struct stat *)buf); |
| 175 | +} |
| 176 | + |
| 177 | +uptr internal_fstat(fd_t fd, void *buf) { |
| 178 | + return fstat(fd, (struct stat *)buf); |
| 179 | +} |
| 180 | + |
| 181 | +uptr internal_filesize(fd_t fd) { |
| 182 | + struct stat st; |
| 183 | + if (internal_fstat(fd, &st)) |
| 184 | + return -1; |
| 185 | + return (uptr)st.st_size; |
| 186 | +} |
| 187 | + |
| 188 | +uptr internal_dup(int oldfd) { |
| 189 | + return dup(oldfd); |
| 190 | +} |
| 191 | + |
| 192 | +uptr internal_getpid() { |
| 193 | + return 42; |
| 194 | +} |
| 195 | + |
| 196 | +uptr internal_sched_yield() { |
| 197 | + return sched_yield(); |
| 198 | +} |
| 199 | + |
| 200 | +void internal_sigfillset(__sanitizer_sigset_t *set) { |
| 201 | + sigfillset(set); |
| 202 | +} |
| 203 | + |
| 204 | +uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set, |
| 205 | + __sanitizer_sigset_t *oldset) { |
| 206 | + return sigprocmask(how, set, oldset); |
| 207 | +} |
| 208 | + |
| 209 | +void internal_usleep(u64 useconds) { |
| 210 | + usleep(useconds); |
| 211 | +} |
| 212 | + |
| 213 | +void internal__exit(int exitcode) { |
| 214 | + __wasi_proc_exit(exitcode); |
| 215 | +} |
| 216 | + |
| 217 | +tid_t GetTid() { |
| 218 | + return gettid(); |
| 219 | +} |
| 220 | + |
| 221 | +uptr internal_clock_gettime(__sanitizer_clockid_t clk_id, void *tp) { |
| 222 | + return clock_gettime(clk_id, (struct timespec *)tp); |
| 223 | +} |
| 224 | + |
131 | 225 | } // namespace __sanitizer
|
132 | 226 |
|
133 | 227 | #endif
|
0 commit comments