@@ -56,6 +56,7 @@ namespace __asan {
5656# define ASAN_READ_STRING (ctx, s, n ) \
5757 ASAN_READ_STRING_OF_LEN ((ctx), (s), internal_strlen(s), (n))
5858
59+ #if SANITIZER_INTERCEPT_STRCAT || SANITIZER_INTERCEPT_STRCPY
5960static inline uptr MaybeRealStrnlen (const char *s, uptr maxlen) {
6061#if SANITIZER_INTERCEPT_STRNLEN
6162 if (REAL (strnlen)) {
@@ -64,6 +65,7 @@ static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
6465#endif
6566 return internal_strnlen (s, maxlen);
6667}
68+ #endif
6769
6870void SetThreadName (const char *name) {
6971 AsanThread *t = GetCurrentThread ();
@@ -275,7 +277,12 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
275277# endif
276278 asanThreadArgRetval ().Create (detached, {start_routine, arg}, [&]() -> uptr {
277279 result = REAL (pthread_create)(thread, attr, asan_thread_start, t);
280+ // AIX pthread_t is unsigned int.
281+ #if SANITIZER_AIX
282+ return result ? 0 : *(unsigned int *)(thread);
283+ #else
278284 return result ? 0 : *(uptr *)(thread);
285+ #endif
279286 });
280287 }
281288 if (result != 0 ) {
@@ -432,10 +439,12 @@ INTERCEPTOR(int, swapcontext, struct ucontext_t *oucp,
432439#define siglongjmp __siglongjmp14
433440#endif
434441
442+ #if ASAN_INTERCEPT_LONGJMP
435443INTERCEPTOR (void , longjmp, void *env, int val) {
436444 __asan_handle_no_return ();
437445 REAL (longjmp)(env, val);
438446}
447+ #endif
439448
440449#if ASAN_INTERCEPT__LONGJMP
441450INTERCEPTOR (void , _longjmp, void *env, int val) {
@@ -508,6 +517,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
508517
509518// For both strcat() and strncat() we need to check the validity of |to|
510519// argument irrespective of the |from| length.
520+ #if SANITIZER_INTERCEPT_STRCAT
511521 INTERCEPTOR (char *, strcat, char *to, const char *from) {
512522 void *ctx;
513523 ASAN_INTERCEPTOR_ENTER (ctx, strcat);
@@ -528,6 +538,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
528538 }
529539 return REAL (strcat)(to, from);
530540 }
541+ #endif
531542
532543INTERCEPTOR (char *, strncat, char *to, const char *from, usize size) {
533544 void *ctx;
@@ -548,6 +559,7 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
548559 return REAL (strncat)(to, from, size);
549560}
550561
562+ #if SANITIZER_INTERCEPT_STRCPY
551563INTERCEPTOR (char *, strcpy, char *to, const char *from) {
552564 void *ctx;
553565 ASAN_INTERCEPTOR_ENTER (ctx, strcpy);
@@ -569,6 +581,7 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) {
569581 }
570582 return REAL (strcpy)(to, from);
571583}
584+ #endif
572585
573586// Windows doesn't always define the strdup identifier,
574587// and when it does it's a macro defined to either _strdup
@@ -596,9 +609,16 @@ INTERCEPTOR(char*, strdup, const char *s) {
596609 GET_STACK_TRACE_MALLOC;
597610 void *new_mem = asan_malloc (length + 1 , &stack);
598611 if (new_mem) {
612+ # if SANITIZER_AIX
613+ // memcpy is a static function defined in libc.a on AIX. It can not be
614+ // intercepted, so REAL(memcpy) is null on AIX. Use internal_memcpy instead.
615+ internal_memcpy (new_mem, s, length + 1 );
616+ # else
599617 REAL (memcpy)(new_mem, s, length + 1 );
618+ # endif
600619 }
601620 return reinterpret_cast <char *>(new_mem);
621+
602622}
603623
604624# if ASAN_INTERCEPT___STRDUP
@@ -614,12 +634,17 @@ INTERCEPTOR(char*, __strdup, const char *s) {
614634 GET_STACK_TRACE_MALLOC;
615635 void *new_mem = asan_malloc (length + 1 , &stack);
616636 if (new_mem) {
637+ #if SANITIZER_AIX
638+ internal_memcpy (new_mem, s, length + 1 );
639+ #else
617640 REAL (memcpy)(new_mem, s, length + 1 );
641+ #endif
618642 }
619643 return reinterpret_cast <char *>(new_mem);
620644}
621645#endif // ASAN_INTERCEPT___STRDUP
622646
647+ #if SANITIZER_INTERCEPT_STRCPY
623648INTERCEPTOR (char *, strncpy, char *to, const char *from, usize size) {
624649 void *ctx;
625650 ASAN_INTERCEPTOR_ENTER (ctx, strncpy);
@@ -632,6 +657,7 @@ INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) {
632657 }
633658 return REAL (strncpy)(to, from, size);
634659}
660+ #endif
635661
636662template <typename Fn>
637663static ALWAYS_INLINE auto StrtolImpl (void *ctx, Fn real, const char *nptr,
@@ -743,6 +769,14 @@ static void AtCxaAtexit(void *unused) {
743769}
744770#endif
745771
772+ #if ASAN_INTERCEPT_EXIT
773+ INTERCEPTOR (void , exit, int status) {
774+ AsanInitFromRtl ();
775+ StopInitOrderChecking ();
776+ REAL (exit)(status);
777+ }
778+ #endif
779+
746780#if ASAN_INTERCEPT___CXA_ATEXIT
747781INTERCEPTOR (int , __cxa_atexit, void (*func)(void *), void *arg,
748782 void *dso_handle) {
@@ -804,10 +838,14 @@ void InitializeAsanInterceptors() {
804838 InitializeSignalInterceptors ();
805839
806840 // Intercept str* functions.
841+ #if SANITIZER_INTERCEPT_STRCAT
807842 ASAN_INTERCEPT_FUNC (strcat);
808- ASAN_INTERCEPT_FUNC (strcpy);
809843 ASAN_INTERCEPT_FUNC (strncat);
844+ #endif
845+ #if SANITIZER_INTERCEPT_STRCPY
846+ ASAN_INTERCEPT_FUNC (strcpy);
810847 ASAN_INTERCEPT_FUNC (strncpy);
848+ #endif
811849 ASAN_INTERCEPT_FUNC (strdup);
812850# if ASAN_INTERCEPT___STRDUP
813851 ASAN_INTERCEPT_FUNC (__strdup);
@@ -826,8 +864,10 @@ void InitializeAsanInterceptors() {
826864 ASAN_INTERCEPT_FUNC (__isoc23_strtoll);
827865# endif
828866
829- // Intecept jump-related functions.
867+ // Intercept jump-related functions.
868+ #if ASAN_INTERCEPT_LONGJMP
830869 ASAN_INTERCEPT_FUNC (longjmp);
870+ #endif
831871
832872# if ASAN_INTERCEPT_SWAPCONTEXT
833873 ASAN_INTERCEPT_FUNC (swapcontext);
@@ -894,6 +934,10 @@ void InitializeAsanInterceptors() {
894934 ASAN_INTERCEPT_FUNC (atexit);
895935#endif
896936
937+ #if ASAN_INTERCEPT_EXIT
938+ ASAN_INTERCEPT_FUNC (exit);
939+ #endif
940+
897941#if ASAN_INTERCEPT_PTHREAD_ATFORK
898942 ASAN_INTERCEPT_FUNC (pthread_atfork);
899943#endif
0 commit comments