Skip to content

Commit 21772b1

Browse files
fixup! [WIP][ASan] Interceptors for WASI
1 parent 2a6551e commit 21772b1

File tree

3 files changed

+9
-112
lines changed

3 files changed

+9
-112
lines changed

compiler-rt/lib/asan/asan_malloc_linux.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ INTERCEPTOR(void*, realloc, void *ptr, uptr size) {
8383
return asan_realloc(ptr, size, &stack);
8484
}
8585

86-
#if SANITIZER_WASI
87-
extern "C" void *__libc_malloc(uptr) __attribute__((alias("malloc")));
88-
extern "C" void __libc_free(void *) __attribute__((alias("free")));
89-
extern "C" void *__libc_calloc(uptr nmemb, uptr size) __attribute__((alias("calloc")));
90-
#endif
91-
9286
#if SANITIZER_INTERCEPT_REALLOCARRAY
9387
INTERCEPTOR(void*, reallocarray, void *ptr, uptr nmemb, uptr size) {
9488
AsanInitFromRtl();

compiler-rt/lib/asan/wasi/dlmalloc.c

Lines changed: 0 additions & 101 deletions
This file was deleted.

compiler-rt/lib/sanitizer_common/sanitizer_wasi.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# include <unistd.h>
2121
# include <fcntl.h>
2222
# include <time.h>
23+
# include <errno.h>
2324
# include <wasi/api.h>
2425

2526
# include "sanitizer_common.h"
@@ -31,10 +32,11 @@
3132
# include "sanitizer_stacktrace.h"
3233
# include "sanitizer_symbolizer_internal.h"
3334

34-
# include "../asan/wasi/dlmalloc.c"
35-
3635
namespace __sanitizer {
3736

37+
extern "C" void *__libc_malloc(uptr);
38+
extern "C" void __libc_free(void *);
39+
3840
void InitializePlatformEarly() {}
3941
void InitTlsSize() {}
4042

@@ -44,7 +46,7 @@ uptr GetPageSize() { return PAGESIZE; }
4446

4547
void *MmapOrDie(uptr size, const char *mem_type, bool raw_report) {
4648
size = RoundUpTo(size, GetPageSize());
47-
void *ptr = dlmalloc(size);
49+
void *ptr = __libc_malloc(size);
4850
if (!ptr) {
4951
if (raw_report) {
5052
Report("MmapOrDie: failed to allocate %zu bytes\n", size);
@@ -55,7 +57,7 @@ void *MmapOrDie(uptr size, const char *mem_type, bool raw_report) {
5557
}
5658

5759
void UnmapOrDie(void *addr, uptr size, bool raw_report) {
58-
dlfree(addr);
60+
__libc_free(addr);
5961
}
6062

6163
void *MmapNoReserveOrDie(uptr size, const char *mem_type) {
@@ -68,12 +70,14 @@ void DumpProcessMap() {
6870

6971
// Implement mandatory functions for ASan WASI build
7072
void CheckASLR() {}
73+
void PlatformPrepareForSandboxing(void *args) {}
7174
void DisableCoreDumperIfNecessary() {}
7275
void InstallDeadlySignalHandlers(void (*cb)(int, void *, void *)) {}
7376
int Atexit(void (*function)(void)) { return 0; }
7477
uptr GetMaxUserVirtualAddress() { return (1ULL << 30); } // 1GB for WASI
7578
uptr GetMmapGranularity() { return GetPageSize(); }
7679
uptr internal_sched_yield() { return 0; }
80+
void internal_join_thread(void *th) {}
7781
bool MemoryRangeIsAvailable(uptr beg, uptr size) { return true; }
7882
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
7983
uptr *tls_addr, uptr *tls_size) {
@@ -94,7 +98,7 @@ void Symbolizer::LateInitialize() {
9498
// Additional mandatory functions
9599
void *MmapOrDieOnFatalError(uptr size, const char *mem_type) {
96100
size = RoundUpTo(size, GetPageSizeCached()) + GetPageSizeCached();
97-
void *ptr = dlmalloc(size);
101+
void *ptr = __libc_malloc(size);
98102
if (!ptr) {
99103
Report("MmapOrDieOnFatalError: failed to allocate %zu bytes\n", size);
100104
Die();

0 commit comments

Comments
 (0)