1 //===-- asan_interceptors.cpp ---------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of AddressSanitizer, an address sanity checker.
11 // Intercept various libc functions.
12 //===----------------------------------------------------------------------===//
14 #include "asan_interceptors.h"
15 #include "asan_allocator.h"
16 #include "asan_internal.h"
17 #include "asan_mapping.h"
18 #include "asan_poisoning.h"
19 #include "asan_report.h"
20 #include "asan_stack.h"
21 #include "asan_stats.h"
22 #include "asan_suppressions.h"
23 #include "lsan/lsan_common.h"
24 #include "sanitizer_common/sanitizer_libc.h"
26 // There is no general interception at all on Fuchsia.
27 // Only the functions in asan_interceptors_memintrinsics.cpp are
28 // really defined to replace libc functions.
29 #if !SANITIZER_FUCHSIA
32 # include "sanitizer_common/sanitizer_posix.h"
35 # if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION || \
36 ASAN_INTERCEPT__SJLJ_UNWIND_RAISEEXCEPTION
40 # if defined(__i386) && SANITIZER_LINUX
41 # define ASAN_PTHREAD_CREATE_VERSION "GLIBC_2.1"
42 # elif defined(__mips__) && SANITIZER_LINUX
43 # define ASAN_PTHREAD_CREATE_VERSION "GLIBC_2.2"
48 #define ASAN_READ_STRING_OF_LEN(ctx, s, len, n) \
49 ASAN_READ_RANGE((ctx), (s), \
50 common_flags()->strict_string_checks ? (len) + 1 : (n))
52 # define ASAN_READ_STRING(ctx, s, n) \
53 ASAN_READ_STRING_OF_LEN((ctx), (s), internal_strlen(s), (n))
55 static inline uptr
MaybeRealStrnlen(const char *s
, uptr maxlen
) {
56 #if SANITIZER_INTERCEPT_STRNLEN
58 return REAL(strnlen
)(s
, maxlen
);
61 return internal_strnlen(s
, maxlen
);
64 void SetThreadName(const char *name
) {
65 AsanThread
*t
= GetCurrentThread();
67 asanThreadRegistry().SetThreadName(t
->tid(), name
);
71 if (CAN_SANITIZE_LEAKS
&& common_flags()->detect_leaks
&&
72 __lsan::HasReportedLeaks()) {
73 return common_flags()->exitcode
;
75 // FIXME: ask frontend whether we need to return failure.
81 // ---------------------- Wrappers ---------------- {{{1
82 using namespace __asan
;
84 DECLARE_REAL_AND_INTERCEPTOR(void *, malloc
, uptr
)
85 DECLARE_REAL_AND_INTERCEPTOR(void, free
, void *)
87 #define ASAN_INTERCEPTOR_ENTER(ctx, func) \
88 AsanInterceptorContext _ctx = {#func}; \
89 ctx = (void *)&_ctx; \
92 #define COMMON_INTERCEPT_FUNCTION(name) ASAN_INTERCEPT_FUNC(name)
93 #define COMMON_INTERCEPT_FUNCTION_VER(name, ver) \
94 ASAN_INTERCEPT_FUNC_VER(name, ver)
95 #define COMMON_INTERCEPT_FUNCTION_VER_UNVERSIONED_FALLBACK(name, ver) \
96 ASAN_INTERCEPT_FUNC_VER_UNVERSIONED_FALLBACK(name, ver)
97 #define COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, size) \
98 ASAN_WRITE_RANGE(ctx, ptr, size)
99 #define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) \
100 ASAN_READ_RANGE(ctx, ptr, size)
101 #define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \
102 ASAN_INTERCEPTOR_ENTER(ctx, func); \
104 if (asan_init_is_running) \
105 return REAL(func)(__VA_ARGS__); \
106 if (SANITIZER_MAC && UNLIKELY(!asan_inited)) \
107 return REAL(func)(__VA_ARGS__); \
108 ENSURE_ASAN_INITED(); \
110 #define COMMON_INTERCEPTOR_DIR_ACQUIRE(ctx, path) \
113 #define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \
116 #define COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd) \
119 #define COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, newfd) \
122 #define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name) SetThreadName(name)
123 // Should be asanThreadRegistry().SetThreadNameByUserId(thread, name)
124 // But asan does not remember UserId's for threads (pthread_t);
125 // and remembers all ever existed threads, so the linear search by UserId
127 #define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name) \
130 #define COMMON_INTERCEPTOR_BLOCK_REAL(name) REAL(name)
131 // Strict init-order checking is dlopen-hostile:
132 // https://github.com/google/sanitizers/issues/178
133 # define COMMON_INTERCEPTOR_DLOPEN(filename, flag) \
135 if (flags()->strict_init_order) \
136 StopInitOrderChecking(); \
137 CheckNoDeepBind(filename, flag); \
138 REAL(dlopen)(filename, flag); \
140 # define COMMON_INTERCEPTOR_ON_EXIT(ctx) OnExit()
141 # define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle)
142 # define COMMON_INTERCEPTOR_LIBRARY_UNLOADED()
143 # define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED (!asan_inited)
144 # define COMMON_INTERCEPTOR_GET_TLS_RANGE(begin, end) \
145 if (AsanThread *t = GetCurrentThread()) { \
146 *begin = t->tls_begin(); \
147 *end = t->tls_end(); \
152 #define COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, to, from, size) \
154 ASAN_INTERCEPTOR_ENTER(ctx, memmove); \
155 ASAN_MEMMOVE_IMPL(ctx, to, from, size); \
158 #define COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, to, from, size) \
160 ASAN_INTERCEPTOR_ENTER(ctx, memcpy); \
161 ASAN_MEMCPY_IMPL(ctx, to, from, size); \
164 #define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size) \
166 ASAN_INTERCEPTOR_ENTER(ctx, memset); \
167 ASAN_MEMSET_IMPL(ctx, block, c, size); \
170 #if CAN_SANITIZE_LEAKS
171 #define COMMON_INTERCEPTOR_STRERROR() \
172 __lsan::ScopedInterceptorDisabler disabler
175 #include "sanitizer_common/sanitizer_common_interceptors.inc"
176 #include "sanitizer_common/sanitizer_signal_interceptors.inc"
178 // Syscall interceptors don't have contexts, we don't support suppressions
180 #define COMMON_SYSCALL_PRE_READ_RANGE(p, s) ASAN_READ_RANGE(nullptr, p, s)
181 #define COMMON_SYSCALL_PRE_WRITE_RANGE(p, s) ASAN_WRITE_RANGE(nullptr, p, s)
182 #define COMMON_SYSCALL_POST_READ_RANGE(p, s) \
187 #define COMMON_SYSCALL_POST_WRITE_RANGE(p, s) \
192 #include "sanitizer_common/sanitizer_common_syscalls.inc"
193 #include "sanitizer_common/sanitizer_syscalls_netbsd.inc"
195 #if ASAN_INTERCEPT_PTHREAD_CREATE
196 static thread_return_t THREAD_CALLING_CONV
asan_thread_start(void *arg
) {
197 AsanThread
*t
= (AsanThread
*)arg
;
199 return t
->ThreadStart(GetTid());
202 INTERCEPTOR(int, pthread_create
, void *thread
,
203 void *attr
, void *(*start_routine
)(void*), void *arg
) {
204 EnsureMainThreadIDIsCorrect();
205 // Strict init-order checking is thread-hostile.
206 if (flags()->strict_init_order
)
207 StopInitOrderChecking();
208 GET_STACK_TRACE_THREAD
;
211 REAL(pthread_attr_getdetachstate
)(attr
, &detached
);
213 u32 current_tid
= GetCurrentTidOrInvalid();
215 AsanThread::Create(start_routine
, arg
, current_tid
, &stack
, detached
);
219 // Ignore all allocations made by pthread_create: thread stack/TLS may be
220 // stored by pthread for future reuse even after thread destruction, and
221 // the linked list it's stored in doesn't even hold valid pointers to the
222 // objects, the latter are calculated by obscure pointer arithmetic.
223 #if CAN_SANITIZE_LEAKS
224 __lsan::ScopedInterceptorDisabler disabler
;
226 result
= REAL(pthread_create
)(thread
, attr
, asan_thread_start
, t
);
229 // If the thread didn't start delete the AsanThread to avoid leaking it.
230 // Note AsanThreadContexts never get destroyed so the AsanThreadContext
231 // that was just created for the AsanThread is wasted.
237 INTERCEPTOR(int, pthread_join
, void *t
, void **arg
) {
238 return real_pthread_join(t
, arg
);
241 DEFINE_REAL_PTHREAD_FUNCTIONS
242 #endif // ASAN_INTERCEPT_PTHREAD_CREATE
244 #if ASAN_INTERCEPT_SWAPCONTEXT
245 static void ClearShadowMemoryForContextStack(uptr stack
, uptr ssize
) {
246 // Align to page size.
247 uptr PageSize
= GetPageSizeCached();
248 uptr bottom
= stack
& ~(PageSize
- 1);
249 ssize
+= stack
- bottom
;
250 ssize
= RoundUpTo(ssize
, PageSize
);
251 static const uptr kMaxSaneContextStackSize
= 1 << 22; // 4 Mb
252 if (AddrIsInMem(bottom
) && ssize
&& ssize
<= kMaxSaneContextStackSize
) {
253 PoisonShadow(bottom
, ssize
, 0);
257 INTERCEPTOR(int, swapcontext
, struct ucontext_t
*oucp
,
258 struct ucontext_t
*ucp
) {
259 static bool reported_warning
= false;
260 if (!reported_warning
) {
261 Report("WARNING: ASan doesn't fully support makecontext/swapcontext "
262 "functions and may produce false positives in some cases!\n");
263 reported_warning
= true;
265 // Clear shadow memory for new context (it may share stack
266 // with current context).
268 ReadContextStack(ucp
, &stack
, &ssize
);
269 ClearShadowMemoryForContextStack(stack
, ssize
);
270 #if __has_attribute(__indirect_return__) && \
271 (defined(__x86_64__) || defined(__i386__))
272 int (*real_swapcontext
)(struct ucontext_t
*, struct ucontext_t
*)
273 __attribute__((__indirect_return__
))
275 int res
= real_swapcontext(oucp
, ucp
);
277 int res
= REAL(swapcontext
)(oucp
, ucp
);
279 // swapcontext technically does not return, but program may swap context to
280 // "oucp" later, that would look as if swapcontext() returned 0.
281 // We need to clear shadow for ucp once again, as it may be in arbitrary
283 ClearShadowMemoryForContextStack(stack
, ssize
);
286 #endif // ASAN_INTERCEPT_SWAPCONTEXT
289 #define longjmp __longjmp14
290 #define siglongjmp __siglongjmp14
293 INTERCEPTOR(void, longjmp
, void *env
, int val
) {
294 __asan_handle_no_return();
295 REAL(longjmp
)(env
, val
);
298 #if ASAN_INTERCEPT__LONGJMP
299 INTERCEPTOR(void, _longjmp
, void *env
, int val
) {
300 __asan_handle_no_return();
301 REAL(_longjmp
)(env
, val
);
305 #if ASAN_INTERCEPT___LONGJMP_CHK
306 INTERCEPTOR(void, __longjmp_chk
, void *env
, int val
) {
307 __asan_handle_no_return();
308 REAL(__longjmp_chk
)(env
, val
);
312 #if ASAN_INTERCEPT_SIGLONGJMP
313 INTERCEPTOR(void, siglongjmp
, void *env
, int val
) {
314 __asan_handle_no_return();
315 REAL(siglongjmp
)(env
, val
);
319 #if ASAN_INTERCEPT___CXA_THROW
320 INTERCEPTOR(void, __cxa_throw
, void *a
, void *b
, void *c
) {
321 CHECK(REAL(__cxa_throw
));
322 __asan_handle_no_return();
323 REAL(__cxa_throw
)(a
, b
, c
);
327 #if ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION
328 INTERCEPTOR(void, __cxa_rethrow_primary_exception
, void *a
) {
329 CHECK(REAL(__cxa_rethrow_primary_exception
));
330 __asan_handle_no_return();
331 REAL(__cxa_rethrow_primary_exception
)(a
);
335 #if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION
336 INTERCEPTOR(_Unwind_Reason_Code
, _Unwind_RaiseException
,
337 _Unwind_Exception
*object
) {
338 CHECK(REAL(_Unwind_RaiseException
));
339 __asan_handle_no_return();
340 return REAL(_Unwind_RaiseException
)(object
);
344 #if ASAN_INTERCEPT__SJLJ_UNWIND_RAISEEXCEPTION
345 INTERCEPTOR(_Unwind_Reason_Code
, _Unwind_SjLj_RaiseException
,
346 _Unwind_Exception
*object
) {
347 CHECK(REAL(_Unwind_SjLj_RaiseException
));
348 __asan_handle_no_return();
349 return REAL(_Unwind_SjLj_RaiseException
)(object
);
353 #if ASAN_INTERCEPT_INDEX
354 # if ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
355 INTERCEPTOR(char*, index
, const char *string
, int c
)
356 ALIAS(WRAPPER_NAME(strchr
));
359 DECLARE_REAL(char*, index
, const char *string
, int c
)
360 OVERRIDE_FUNCTION(index
, strchr
);
362 DEFINE_REAL(char*, index
, const char *string
, int c
)
365 #endif // ASAN_INTERCEPT_INDEX
367 // For both strcat() and strncat() we need to check the validity of |to|
368 // argument irrespective of the |from| length.
369 INTERCEPTOR(char *, strcat
, char *to
, const char *from
) {
371 ASAN_INTERCEPTOR_ENTER(ctx
, strcat
);
372 ENSURE_ASAN_INITED();
373 if (flags()->replace_str
) {
374 uptr from_length
= internal_strlen(from
);
375 ASAN_READ_RANGE(ctx
, from
, from_length
+ 1);
376 uptr to_length
= internal_strlen(to
);
377 ASAN_READ_STRING_OF_LEN(ctx
, to
, to_length
, to_length
);
378 ASAN_WRITE_RANGE(ctx
, to
+ to_length
, from_length
+ 1);
379 // If the copying actually happens, the |from| string should not overlap
380 // with the resulting string starting at |to|, which has a length of
381 // to_length + from_length + 1.
382 if (from_length
> 0) {
383 CHECK_RANGES_OVERLAP("strcat", to
, from_length
+ to_length
+ 1, from
,
387 return REAL(strcat
)(to
, from
);
390 INTERCEPTOR(char*, strncat
, char *to
, const char *from
, uptr size
) {
392 ASAN_INTERCEPTOR_ENTER(ctx
, strncat
);
393 ENSURE_ASAN_INITED();
394 if (flags()->replace_str
) {
395 uptr from_length
= MaybeRealStrnlen(from
, size
);
396 uptr copy_length
= Min(size
, from_length
+ 1);
397 ASAN_READ_RANGE(ctx
, from
, copy_length
);
398 uptr to_length
= internal_strlen(to
);
399 ASAN_READ_STRING_OF_LEN(ctx
, to
, to_length
, to_length
);
400 ASAN_WRITE_RANGE(ctx
, to
+ to_length
, from_length
+ 1);
401 if (from_length
> 0) {
402 CHECK_RANGES_OVERLAP("strncat", to
, to_length
+ copy_length
+ 1,
406 return REAL(strncat
)(to
, from
, size
);
409 INTERCEPTOR(char *, strcpy
, char *to
, const char *from
) {
411 ASAN_INTERCEPTOR_ENTER(ctx
, strcpy
);
413 if (UNLIKELY(!asan_inited
))
414 return REAL(strcpy
)(to
, from
);
416 // strcpy is called from malloc_default_purgeable_zone()
417 // in __asan::ReplaceSystemAlloc() on Mac.
418 if (asan_init_is_running
) {
419 return REAL(strcpy
)(to
, from
);
421 ENSURE_ASAN_INITED();
422 if (flags()->replace_str
) {
423 uptr from_size
= internal_strlen(from
) + 1;
424 CHECK_RANGES_OVERLAP("strcpy", to
, from_size
, from
, from_size
);
425 ASAN_READ_RANGE(ctx
, from
, from_size
);
426 ASAN_WRITE_RANGE(ctx
, to
, from_size
);
428 return REAL(strcpy
)(to
, from
);
431 INTERCEPTOR(char*, strdup
, const char *s
) {
433 ASAN_INTERCEPTOR_ENTER(ctx
, strdup
);
434 if (UNLIKELY(!asan_inited
)) return internal_strdup(s
);
435 ENSURE_ASAN_INITED();
436 uptr length
= internal_strlen(s
);
437 if (flags()->replace_str
) {
438 ASAN_READ_RANGE(ctx
, s
, length
+ 1);
440 GET_STACK_TRACE_MALLOC
;
441 void *new_mem
= asan_malloc(length
+ 1, &stack
);
442 REAL(memcpy
)(new_mem
, s
, length
+ 1);
443 return reinterpret_cast<char*>(new_mem
);
446 #if ASAN_INTERCEPT___STRDUP
447 INTERCEPTOR(char*, __strdup
, const char *s
) {
449 ASAN_INTERCEPTOR_ENTER(ctx
, strdup
);
450 if (UNLIKELY(!asan_inited
)) return internal_strdup(s
);
451 ENSURE_ASAN_INITED();
452 uptr length
= internal_strlen(s
);
453 if (flags()->replace_str
) {
454 ASAN_READ_RANGE(ctx
, s
, length
+ 1);
456 GET_STACK_TRACE_MALLOC
;
457 void *new_mem
= asan_malloc(length
+ 1, &stack
);
458 REAL(memcpy
)(new_mem
, s
, length
+ 1);
459 return reinterpret_cast<char*>(new_mem
);
461 #endif // ASAN_INTERCEPT___STRDUP
463 INTERCEPTOR(char*, strncpy
, char *to
, const char *from
, uptr size
) {
465 ASAN_INTERCEPTOR_ENTER(ctx
, strncpy
);
466 ENSURE_ASAN_INITED();
467 if (flags()->replace_str
) {
468 uptr from_size
= Min(size
, MaybeRealStrnlen(from
, size
) + 1);
469 CHECK_RANGES_OVERLAP("strncpy", to
, from_size
, from
, from_size
);
470 ASAN_READ_RANGE(ctx
, from
, from_size
);
471 ASAN_WRITE_RANGE(ctx
, to
, size
);
473 return REAL(strncpy
)(to
, from
, size
);
476 INTERCEPTOR(long, strtol
, const char *nptr
, char **endptr
, int base
) {
478 ASAN_INTERCEPTOR_ENTER(ctx
, strtol
);
479 ENSURE_ASAN_INITED();
480 if (!flags()->replace_str
) {
481 return REAL(strtol
)(nptr
, endptr
, base
);
484 long result
= REAL(strtol
)(nptr
, &real_endptr
, base
);
485 StrtolFixAndCheck(ctx
, nptr
, endptr
, real_endptr
, base
);
489 INTERCEPTOR(int, atoi
, const char *nptr
) {
491 ASAN_INTERCEPTOR_ENTER(ctx
, atoi
);
493 if (UNLIKELY(!asan_inited
)) return REAL(atoi
)(nptr
);
495 ENSURE_ASAN_INITED();
496 if (!flags()->replace_str
) {
497 return REAL(atoi
)(nptr
);
500 // "man atoi" tells that behavior of atoi(nptr) is the same as
501 // strtol(nptr, 0, 10), i.e. it sets errno to ERANGE if the
502 // parsed integer can't be stored in *long* type (even if it's
503 // different from int). So, we just imitate this behavior.
504 int result
= REAL(strtol
)(nptr
, &real_endptr
, 10);
505 FixRealStrtolEndptr(nptr
, &real_endptr
);
506 ASAN_READ_STRING(ctx
, nptr
, (real_endptr
- nptr
) + 1);
510 INTERCEPTOR(long, atol
, const char *nptr
) {
512 ASAN_INTERCEPTOR_ENTER(ctx
, atol
);
514 if (UNLIKELY(!asan_inited
)) return REAL(atol
)(nptr
);
516 ENSURE_ASAN_INITED();
517 if (!flags()->replace_str
) {
518 return REAL(atol
)(nptr
);
521 long result
= REAL(strtol
)(nptr
, &real_endptr
, 10);
522 FixRealStrtolEndptr(nptr
, &real_endptr
);
523 ASAN_READ_STRING(ctx
, nptr
, (real_endptr
- nptr
) + 1);
527 #if ASAN_INTERCEPT_ATOLL_AND_STRTOLL
528 INTERCEPTOR(long long, strtoll
, const char *nptr
, char **endptr
, int base
) {
530 ASAN_INTERCEPTOR_ENTER(ctx
, strtoll
);
531 ENSURE_ASAN_INITED();
532 if (!flags()->replace_str
) {
533 return REAL(strtoll
)(nptr
, endptr
, base
);
536 long long result
= REAL(strtoll
)(nptr
, &real_endptr
, base
);
537 StrtolFixAndCheck(ctx
, nptr
, endptr
, real_endptr
, base
);
541 INTERCEPTOR(long long, atoll
, const char *nptr
) {
543 ASAN_INTERCEPTOR_ENTER(ctx
, atoll
);
544 ENSURE_ASAN_INITED();
545 if (!flags()->replace_str
) {
546 return REAL(atoll
)(nptr
);
549 long long result
= REAL(strtoll
)(nptr
, &real_endptr
, 10);
550 FixRealStrtolEndptr(nptr
, &real_endptr
);
551 ASAN_READ_STRING(ctx
, nptr
, (real_endptr
- nptr
) + 1);
554 #endif // ASAN_INTERCEPT_ATOLL_AND_STRTOLL
556 #if ASAN_INTERCEPT___CXA_ATEXIT || ASAN_INTERCEPT_ATEXIT
557 static void AtCxaAtexit(void *unused
) {
559 StopInitOrderChecking();
563 #if ASAN_INTERCEPT___CXA_ATEXIT
564 INTERCEPTOR(int, __cxa_atexit
, void (*func
)(void *), void *arg
,
567 if (UNLIKELY(!asan_inited
)) return REAL(__cxa_atexit
)(func
, arg
, dso_handle
);
569 ENSURE_ASAN_INITED();
570 #if CAN_SANITIZE_LEAKS
571 __lsan::ScopedInterceptorDisabler disabler
;
573 int res
= REAL(__cxa_atexit
)(func
, arg
, dso_handle
);
574 REAL(__cxa_atexit
)(AtCxaAtexit
, nullptr, nullptr);
577 #endif // ASAN_INTERCEPT___CXA_ATEXIT
579 #if ASAN_INTERCEPT_ATEXIT
580 INTERCEPTOR(int, atexit
, void (*func
)()) {
581 ENSURE_ASAN_INITED();
582 #if CAN_SANITIZE_LEAKS
583 __lsan::ScopedInterceptorDisabler disabler
;
585 // Avoid calling real atexit as it is unreachable on at least on Linux.
586 int res
= REAL(__cxa_atexit
)((void (*)(void *a
))func
, nullptr, nullptr);
587 REAL(__cxa_atexit
)(AtCxaAtexit
, nullptr, nullptr);
592 #if ASAN_INTERCEPT_PTHREAD_ATFORK
594 extern int _pthread_atfork(void (*prepare
)(), void (*parent
)(),
598 INTERCEPTOR(int, pthread_atfork
, void (*prepare
)(), void (*parent
)(),
600 #if CAN_SANITIZE_LEAKS
601 __lsan::ScopedInterceptorDisabler disabler
;
603 // REAL(pthread_atfork) cannot be called due to symbol indirections at least
605 return _pthread_atfork(prepare
, parent
, child
);
609 #if ASAN_INTERCEPT_VFORK
610 DEFINE_REAL(int, vfork
)
611 DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(int, vfork
)
614 // ---------------------- InitializeAsanInterceptors ---------------- {{{1
616 void InitializeAsanInterceptors() {
617 static bool was_called_once
;
618 CHECK(!was_called_once
);
619 was_called_once
= true;
620 InitializeCommonInterceptors();
621 InitializeSignalInterceptors();
623 // Intercept str* functions.
624 ASAN_INTERCEPT_FUNC(strcat
);
625 ASAN_INTERCEPT_FUNC(strcpy
);
626 ASAN_INTERCEPT_FUNC(strncat
);
627 ASAN_INTERCEPT_FUNC(strncpy
);
628 ASAN_INTERCEPT_FUNC(strdup
);
629 #if ASAN_INTERCEPT___STRDUP
630 ASAN_INTERCEPT_FUNC(__strdup
);
632 #if ASAN_INTERCEPT_INDEX && ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
633 ASAN_INTERCEPT_FUNC(index
);
636 ASAN_INTERCEPT_FUNC(atoi
);
637 ASAN_INTERCEPT_FUNC(atol
);
638 ASAN_INTERCEPT_FUNC(strtol
);
639 #if ASAN_INTERCEPT_ATOLL_AND_STRTOLL
640 ASAN_INTERCEPT_FUNC(atoll
);
641 ASAN_INTERCEPT_FUNC(strtoll
);
644 // Intecept jump-related functions.
645 ASAN_INTERCEPT_FUNC(longjmp
);
647 #if ASAN_INTERCEPT_SWAPCONTEXT
648 ASAN_INTERCEPT_FUNC(swapcontext
);
650 #if ASAN_INTERCEPT__LONGJMP
651 ASAN_INTERCEPT_FUNC(_longjmp
);
653 #if ASAN_INTERCEPT___LONGJMP_CHK
654 ASAN_INTERCEPT_FUNC(__longjmp_chk
);
656 #if ASAN_INTERCEPT_SIGLONGJMP
657 ASAN_INTERCEPT_FUNC(siglongjmp
);
660 // Intercept exception handling functions.
661 #if ASAN_INTERCEPT___CXA_THROW
662 ASAN_INTERCEPT_FUNC(__cxa_throw
);
664 #if ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION
665 ASAN_INTERCEPT_FUNC(__cxa_rethrow_primary_exception
);
667 // Indirectly intercept std::rethrow_exception.
668 #if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION
669 INTERCEPT_FUNCTION(_Unwind_RaiseException
);
671 // Indirectly intercept std::rethrow_exception.
672 #if ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION
673 INTERCEPT_FUNCTION(_Unwind_SjLj_RaiseException
);
676 // Intercept threading-related functions
677 #if ASAN_INTERCEPT_PTHREAD_CREATE
678 // TODO: this should probably have an unversioned fallback for newer arches?
679 #if defined(ASAN_PTHREAD_CREATE_VERSION)
680 ASAN_INTERCEPT_FUNC_VER(pthread_create
, ASAN_PTHREAD_CREATE_VERSION
);
682 ASAN_INTERCEPT_FUNC(pthread_create
);
684 ASAN_INTERCEPT_FUNC(pthread_join
);
687 // Intercept atexit function.
688 #if ASAN_INTERCEPT___CXA_ATEXIT
689 ASAN_INTERCEPT_FUNC(__cxa_atexit
);
692 #if ASAN_INTERCEPT_ATEXIT
693 ASAN_INTERCEPT_FUNC(atexit
);
696 #if ASAN_INTERCEPT_PTHREAD_ATFORK
697 ASAN_INTERCEPT_FUNC(pthread_atfork
);
700 #if ASAN_INTERCEPT_VFORK
701 ASAN_INTERCEPT_FUNC(vfork
);
704 InitializePlatformInterceptors();
706 VReport(1, "AddressSanitizer: libc interceptors initialized\n");
709 } // namespace __asan
711 #endif // !SANITIZER_FUCHSIA