Skip to content

Commit 2265198

Browse files
authored
[compiler-rt] Avoid using musl's syscall layer. NFC (#24655)
Use libc calls instead, similar to the NetBSD and macOS implementations.
1 parent 5b95aa7 commit 2265198

File tree

6 files changed

+127
-117
lines changed

6 files changed

+127
-117
lines changed

system/lib/compiler-rt/lib/sanitizer_common/sanitizer_emscripten.cpp

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
#include "sanitizer_platform.h"
17+
#include "sanitizer_platform_limits_posix.h"
1718
#include "sanitizer_common.h"
1819
#include "sanitizer_stoptheworld.h"
1920

21+
#include <fcntl.h>
2022
#include <signal.h>
2123
#include <time.h>
24+
#include <unistd.h>
25+
#include <math.h>
2226

2327
#if SANITIZER_EMSCRIPTEN
2428

29+
#include <sys/stat.h>
30+
#include <sys/types.h>
31+
2532
#include <emscripten.h>
2633
#include <emscripten/stack.h>
27-
#include <sys/types.h>
2834

2935
#include "emscripten_internal.h"
3036

@@ -128,6 +134,82 @@ u64 MonotonicNanoTime() {
128134

129135
void GetMemoryProfile(fill_profile_f cb, uptr *stats) {}
130136

137+
int internal_madvise(uptr addr, uptr length, int advice) {
138+
return 0; // madvise is currently ignored
139+
}
140+
141+
uptr internal_close(fd_t fd) {
142+
return close(fd);
143+
}
144+
145+
uptr internal_open(const char *filename, int flags) {
146+
return open(filename, flags);
147+
}
148+
149+
uptr internal_open(const char *filename, int flags, u32 mode) {
150+
return open(filename, flags, mode);
151+
}
152+
153+
uptr internal_read(fd_t fd, void *buf, uptr count) {
154+
return read(fd, buf, count);
155+
}
156+
157+
uptr internal_write(fd_t fd, const void *buf, uptr count) {
158+
return write(fd, buf, count);
159+
}
160+
161+
uptr internal_stat(const char *path, void *buf) {
162+
return stat(path, (struct stat *)buf);
163+
}
164+
165+
uptr internal_fstat(fd_t fd, void *buf) {
166+
return fstat(fd, (struct stat *)buf);
167+
}
168+
169+
uptr internal_filesize(fd_t fd) {
170+
struct stat st;
171+
if (internal_fstat(fd, &st))
172+
return -1;
173+
return (uptr)st.st_size;
174+
}
175+
176+
uptr internal_dup(int oldfd) {
177+
return dup(oldfd);
178+
}
179+
180+
uptr internal_getpid() {
181+
return 42;
182+
}
183+
184+
uptr internal_sched_yield() {
185+
return sched_yield();
186+
}
187+
188+
void internal_sigfillset(__sanitizer_sigset_t *set) {
189+
sigfillset(set);
190+
}
191+
192+
uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
193+
__sanitizer_sigset_t *oldset) {
194+
return sigprocmask(how, set, oldset);
195+
}
196+
197+
void internal_usleep(u64 useconds) {
198+
usleep(useconds);
199+
}
200+
201+
void internal__exit(int exitcode) {
202+
_exit(exitcode);
203+
}
204+
205+
tid_t GetTid() {
206+
return gettid();
207+
}
208+
209+
uptr internal_clock_gettime(__sanitizer_clockid_t clk_id, void *tp) {
210+
return clock_gettime(clk_id, (struct timespec *)tp);
211+
}
212+
131213
} // namespace __sanitizer
132214

133215
#endif

0 commit comments

Comments
 (0)