Skip to content

Commit f49a930

Browse files
committed
Minor improvements
1 parent e1f1f89 commit f49a930

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-21
lines changed

src/postamble.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function callMain(args) {
167167

168168
#if ABORT_ON_WASM_EXCEPTIONS
169169
// See abortWrapperDepth in preamble.js!
170-
abortWrapperDepth += 2;
170+
abortWrapperDepth += 2;
171171
#endif
172172

173173
#if STANDALONE_WASM
@@ -215,7 +215,7 @@ function callMain(args) {
215215

216216
#if ABORT_ON_WASM_EXCEPTIONS
217217
// See abortWrapperDepth in preamble.js!
218-
abortWrapperDepth -= 2;
218+
abortWrapperDepth -= 2;
219219
#endif
220220
}
221221
}

system/lib/compiler-rt/lib/asan/asan_interceptors.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ void InitializePlatformInterceptors();
3434

3535
} // namespace __asan
3636

37-
// There is no general interception at all on Fuchsia and RTEMS.
37+
// There is no general interception at all on Fuchsia, RTEMS and Emscripten.
3838
// Only the functions in asan_interceptors_memintrinsics.h are
3939
// really defined to replace libc functions.
40-
#if !SANITIZER_FUCHSIA && !SANITIZER_RTEMS
40+
#if !SANITIZER_FUCHSIA && !SANITIZER_RTEMS && !SANITIZER_EMSCRIPTEN
4141

4242
// Use macro to describe if specific function should be
4343
// intercepted on a given platform.
@@ -150,6 +150,6 @@ DECLARE_REAL(char*, strstr, const char *s1, const char *s2)
150150
#define ASAN_INTERCEPT_FUNC(name)
151151
#endif // SANITIZER_MAC
152152

153-
#endif // !SANITIZER_FUCHSIA
153+
#endif // !SANITIZER_FUCHSIA && !SANITIZER_RTEMS && !SANITIZER_EMSCRIPTEN
154154

155155
#endif // ASAN_INTERCEPTORS_H

system/lib/compiler-rt/lib/lsan/lsan_common_emscripten.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ u32 GetCurrentThread();
122122
// Finally, we can only obtain the stack pointer for the current thread,
123123
// so we scan the full stack for other threads.
124124
static void ProcessThreadsCallback(ThreadContextBase *tctx, void *arg) {
125+
tid_t os_id = tctx->os_id;
126+
LOG_THREADS("Processing thread %d\n", os_id);
125127
if (tctx->status != ThreadStatusRunning)
126128
return;
127129

128130
Frontier *frontier = reinterpret_cast<Frontier *>(arg);
129-
tid_t os_id = tctx->os_id;
130131

131132
uptr stack_begin, stack_end, tls_begin, tls_end, cache_begin, cache_end;
132133
DTLS *dtls;
@@ -157,6 +158,7 @@ static void ProcessThreadsCallback(ThreadContextBase *tctx, void *arg) {
157158
}
158159

159160
ScanRangeForPointers(stack_begin, stack_end, frontier, "STACK", kReachable);
161+
//ForEachExtraStackRange(os_id, ForEachExtraStackRangeCb, frontier);
160162
}
161163

162164
if (flags()->use_tls && tls_begin) {

system/lib/compiler-rt/lib/lsan/lsan_interceptors.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333

3434
#include <stddef.h>
3535

36+
#if SANITIZER_EMSCRIPTEN
37+
#define __ATTRP_C11_THREAD ((void*)(uptr)-1)
38+
#endif
39+
3640
using namespace __lsan;
3741

3842
extern "C" {
@@ -63,9 +67,9 @@ INTERCEPTOR(void, free, void *p) {
6367
}
6468

6569
INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {
66-
// This hack is not required for Fuchsia because there are no dlsym calls
70+
// This hack is not required for Fuchsia and Emscripten because there are no dlsym calls
6771
// involved in setting up interceptors.
68-
#if !SANITIZER_FUCHSIA
72+
#if !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN
6973
if (lsan_init_is_running) {
7074
// Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
7175
const uptr kCallocPoolSize = 1024;
@@ -77,7 +81,7 @@ INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {
7781
CHECK(allocated < kCallocPoolSize);
7882
return mem;
7983
}
80-
#endif // !SANITIZER_FUCHSIA
84+
#endif // !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN
8185
ENSURE_LSAN_INITED;
8286
GET_STACK_TRACE_MALLOC;
8387
return lsan_calloc(nmemb, size, stack);
@@ -316,7 +320,7 @@ INTERCEPTOR(void, _ZdaPvRKSt9nothrow_t, void *ptr, std::nothrow_t const&)
316320

317321
///// Thread initialization and finalization. /////
318322

319-
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD && !SANITIZER_FUCHSIA
323+
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD && !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN
320324
static unsigned g_thread_finalize_key;
321325

322326
static void thread_finalize(void *v) {
@@ -428,7 +432,7 @@ extern "C" void *__lsan_thread_start_func(void *arg) {
428432
void *param = p->param;
429433
// Wait until the last iteration to maximize the chance that we are the last
430434
// destructor to run.
431-
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
435+
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD && !SANITIZER_EMSCRIPTEN
432436
if (pthread_setspecific(g_thread_finalize_key,
433437
(void*)GetPthreadDestructorIterations())) {
434438
Report("LeakSanitizer: failed to set thread key.\n");
@@ -452,7 +456,11 @@ INTERCEPTOR(int, pthread_create, void *th, void *attr,
452456
ENSURE_LSAN_INITED;
453457
EnsureMainThreadIDIsCorrect();
454458
__sanitizer_pthread_attr_t myattr;
459+
#if SANITIZER_EMSCRIPTEN
460+
if (!attr || attr == __ATTRP_C11_THREAD) {
461+
#else
455462
if (!attr) {
463+
#endif
456464
pthread_attr_init(&myattr);
457465
attr = &myattr;
458466
}
@@ -531,7 +539,7 @@ INTERCEPTOR(void, _exit, int status) {
531539
namespace __lsan {
532540

533541
void InitializeInterceptors() {
534-
// Fuchsia doesn't use interceptors that require any setup.
542+
// Fuchsia and Emscripten doesn't use interceptors that require any setup.
535543
#if !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN
536544
InitializeSignalInterceptors();
537545

@@ -562,16 +570,15 @@ void InitializeInterceptors() {
562570
LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK;
563571

564572
LSAN_MAYBE_INTERCEPT_STRERROR;
573+
#endif // !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN
565574

566-
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
575+
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD && !SANITIZER_FUCHSIA && !SANITIZER_EMSCRIPTEN
567576
if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) {
568577
Report("LeakSanitizer: failed to create thread key.\n");
569578
Die();
570579
}
571580
#endif
572-
573-
#endif // !SANITIZER_FUCHSIA
574581
}
575582

576583
} // namespace __lsan
577-
#endif // SANITIZER_EMSCRIPTEN
584+
#endif // SANITIZER_POSIX

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "sanitizer_stoptheworld.h"
1919

2020
#include <signal.h>
21+
#include <unistd.h>
2122

2223
#if SANITIZER_EMSCRIPTEN
2324

@@ -124,6 +125,10 @@ void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
124125
#endif
125126
}
126127

128+
tid_t GetTid() {
129+
return gettid();
130+
}
131+
127132
class SuspendedThreadsListEmscripten final : public SuspendedThreadsList {};
128133

129134
void StopTheWorld(StopTheWorldCallback callback, void *argument) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,14 @@ bool FileExists(const char *filename) {
514514
return S_ISREG(st.st_mode);
515515
}
516516

517-
#if !SANITIZER_NETBSD
517+
#if !SANITIZER_NETBSD && !SANITIZER_EMSCRIPTEN
518518
tid_t GetTid() {
519519
#if SANITIZER_FREEBSD
520520
long Tid;
521521
thr_self(&Tid);
522522
return Tid;
523523
#elif SANITIZER_SOLARIS
524524
return thr_self();
525-
#elif SANITIZER_EMSCRIPTEN
526-
return (tid_t) pthread_self();
527525
#else
528526
return internal_syscall(SYSCALL(gettid));
529527
#endif

system/lib/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
#define SANITIZER_INTERCEPT_SENDMMSG SI_LINUX
279279
#define SANITIZER_INTERCEPT_SYSMSG SI_LINUX_NOT_ANDROID
280280
#define SANITIZER_INTERCEPT_GETPEERNAME SI_POSIX
281-
#define SANITIZER_INTERCEPT_IOCTL SI_POSIX && !SI_EMSCRIPTEN
281+
#define SANITIZER_INTERCEPT_IOCTL SI_POSIX_NOT_EMSCRIPTEN
282282
#define SANITIZER_INTERCEPT_INET_ATON SI_POSIX
283283
#define SANITIZER_INTERCEPT_SYSINFO SI_LINUX
284284
#define SANITIZER_INTERCEPT_READDIR SI_POSIX

tools/system_libs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def get_files(self):
821821

822822
libc_files += files_in_path(
823823
path_components=['system', 'lib', 'libc', 'musl', 'src', 'linux'],
824-
filenames=['getdents.c'])
824+
filenames=['getdents.c', 'gettid.c'])
825825

826826
libc_files += files_in_path(
827827
path_components=['system', 'lib', 'libc', 'musl', 'src', 'env'],

0 commit comments

Comments
 (0)