Skip to content

Commit 4fde02d

Browse files
committed
[sanitizer] Add type __sanitizer::ssize
Add distinct type __sanitizer::ssize and typedef it initially to sptr except for s390 -m31 where it is set to long. Replace uptr by usize wherever appropriate.
1 parent 0a1795f commit 4fde02d

8 files changed

+70
-64
lines changed

compiler-rt/lib/asan/asan_interceptors.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +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-
static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
59+
static inline usize MaybeRealStrnlen(const char *s, usize maxlen) {
6060
#if SANITIZER_INTERCEPT_STRNLEN
6161
if (REAL(strnlen)) {
6262
return REAL(strnlen)(s, maxlen);
@@ -85,7 +85,7 @@ int OnExit() {
8585
// ---------------------- Wrappers ---------------- {{{1
8686
using namespace __asan;
8787

88-
DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, uptr)
88+
DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, usize)
8989
DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
9090

9191
#define COMMON_INTERCEPT_FUNCTION_VER(name, ver) \
@@ -513,9 +513,9 @@ DEFINE_REAL(char*, index, const char *string, int c)
513513
ASAN_INTERCEPTOR_ENTER(ctx, strcat);
514514
AsanInitFromRtl();
515515
if (flags()->replace_str) {
516-
uptr from_length = internal_strlen(from);
516+
usize from_length = internal_strlen(from);
517517
ASAN_READ_RANGE(ctx, from, from_length + 1);
518-
uptr to_length = internal_strlen(to);
518+
usize to_length = internal_strlen(to);
519519
ASAN_READ_STRING_OF_LEN(ctx, to, to_length, to_length);
520520
ASAN_WRITE_RANGE(ctx, to + to_length, from_length + 1);
521521
// If the copying actually happens, the |from| string should not overlap
@@ -529,15 +529,15 @@ DEFINE_REAL(char*, index, const char *string, int c)
529529
return REAL(strcat)(to, from);
530530
}
531531

532-
INTERCEPTOR(char*, strncat, char *to, const char *from, uptr size) {
532+
INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
533533
void *ctx;
534534
ASAN_INTERCEPTOR_ENTER(ctx, strncat);
535535
AsanInitFromRtl();
536536
if (flags()->replace_str) {
537-
uptr from_length = MaybeRealStrnlen(from, size);
538-
uptr copy_length = Min(size, from_length + 1);
537+
usize from_length = MaybeRealStrnlen(from, size);
538+
usize copy_length = Min(size, from_length + 1);
539539
ASAN_READ_RANGE(ctx, from, copy_length);
540-
uptr to_length = internal_strlen(to);
540+
usize to_length = internal_strlen(to);
541541
ASAN_READ_STRING_OF_LEN(ctx, to, to_length, to_length);
542542
ASAN_WRITE_RANGE(ctx, to + to_length, from_length + 1);
543543
if (from_length > 0) {
@@ -562,7 +562,7 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) {
562562
}
563563

564564
if (flags()->replace_str) {
565-
uptr from_size = internal_strlen(from) + 1;
565+
usize from_size = internal_strlen(from) + 1;
566566
CHECK_RANGES_OVERLAP("strcpy", to, from_size, from, from_size);
567567
ASAN_READ_RANGE(ctx, from, from_size);
568568
ASAN_WRITE_RANGE(ctx, to, from_size);
@@ -586,7 +586,7 @@ INTERCEPTOR(char*, strdup, const char *s) {
586586
ASAN_INTERCEPTOR_ENTER(ctx, strdup);
587587
if (UNLIKELY(!TryAsanInitFromRtl()))
588588
return internal_strdup(s);
589-
uptr length = internal_strlen(s);
589+
usize length = internal_strlen(s);
590590
if (flags()->replace_str) {
591591
ASAN_READ_RANGE(ctx, s, length + 1);
592592
}
@@ -604,7 +604,7 @@ INTERCEPTOR(char*, __strdup, const char *s) {
604604
ASAN_INTERCEPTOR_ENTER(ctx, strdup);
605605
if (UNLIKELY(!TryAsanInitFromRtl()))
606606
return internal_strdup(s);
607-
uptr length = internal_strlen(s);
607+
usize length = internal_strlen(s);
608608
if (flags()->replace_str) {
609609
ASAN_READ_RANGE(ctx, s, length + 1);
610610
}
@@ -617,12 +617,12 @@ INTERCEPTOR(char*, __strdup, const char *s) {
617617
}
618618
#endif // ASAN_INTERCEPT___STRDUP
619619

620-
INTERCEPTOR(char*, strncpy, char *to, const char *from, uptr size) {
620+
INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) {
621621
void *ctx;
622622
ASAN_INTERCEPTOR_ENTER(ctx, strncpy);
623623
AsanInitFromRtl();
624624
if (flags()->replace_str) {
625-
uptr from_size = Min(size, MaybeRealStrnlen(from, size) + 1);
625+
usize from_size = Min(size, MaybeRealStrnlen(from, size) + 1);
626626
CHECK_RANGES_OVERLAP("strncpy", to, from_size, from, from_size);
627627
ASAN_READ_RANGE(ctx, from, from_size);
628628
ASAN_WRITE_RANGE(ctx, to, size);

compiler-rt/lib/asan/asan_interceptors.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ void InitializePlatformInterceptors();
124124
# define ASAN_INTERCEPT_PTHREAD_ATFORK 0
125125
#endif
126126

127-
DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
127+
DECLARE_REAL(int, memcmp, const void *a1, const void *a2, SIZE_T size)
128128
DECLARE_REAL(char*, strchr, const char *str, int c)
129129
DECLARE_REAL(SIZE_T, strlen, const char *s)
130-
DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size)
131-
DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
130+
DECLARE_REAL(char*, strncpy, char *to, const char *from, SIZE_T size)
131+
DECLARE_REAL(SIZE_T, strnlen, const char *s, SIZE_T maxlen)
132132
DECLARE_REAL(char*, strstr, const char *s1, const char *s2)
133133

134134
# if !SANITIZER_APPLE

compiler-rt/lib/asan/asan_interceptors_memintrinsics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include "asan_mapping.h"
1919
#include "interception/interception.h"
2020

21-
DECLARE_REAL(void *, memcpy, void *to, const void *from, uptr size)
22-
DECLARE_REAL(void *, memset, void *block, int c, uptr size)
21+
DECLARE_REAL(void *, memcpy, void *to, const void *from, SIZE_T size)
22+
DECLARE_REAL(void *, memset, void *block, int c, SIZE_T size)
2323

2424
namespace __asan {
2525

compiler-rt/lib/interception/interception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#endif
3838

3939
#define SIZE_T __sanitizer::usize
40-
#define SSIZE_T __sanitizer::sptr
40+
#define SSIZE_T __sanitizer::ssize
4141
typedef __sanitizer::sptr PTRDIFF_T;
4242
typedef __sanitizer::s64 INTMAX_T;
4343
typedef __sanitizer::u64 UINTMAX_T;

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ extern const short *_tolower_tab_;
344344
#ifndef COMMON_INTERCEPTOR_STRNDUP_IMPL
345345
#define COMMON_INTERCEPTOR_STRNDUP_IMPL(ctx, s, size) \
346346
COMMON_INTERCEPTOR_ENTER(ctx, strndup, s, size); \
347-
uptr copy_length = internal_strnlen(s, size); \
347+
usize copy_length = internal_strnlen(s, size); \
348348
char *new_mem = (char *)WRAP(malloc)(copy_length + 1); \
349349
if (common_flags()->intercept_strndup) { \
350350
COMMON_INTERCEPTOR_READ_STRING(ctx, s, Min(size, copy_length + 1)); \
@@ -445,7 +445,7 @@ INTERCEPTOR(SIZE_T, strnlen, const char *s, SIZE_T maxlen) {
445445
#endif
446446

447447
#if SANITIZER_INTERCEPT_STRNDUP
448-
INTERCEPTOR(char*, strndup, const char *s, uptr size) {
448+
INTERCEPTOR(char*, strndup, const char *s, usize size) {
449449
void *ctx;
450450
COMMON_INTERCEPTOR_STRNDUP_IMPL(ctx, s, size);
451451
}
@@ -455,7 +455,7 @@ INTERCEPTOR(char*, strndup, const char *s, uptr size) {
455455
#endif // SANITIZER_INTERCEPT_STRNDUP
456456

457457
#if SANITIZER_INTERCEPT___STRNDUP
458-
INTERCEPTOR(char*, __strndup, const char *s, uptr size) {
458+
INTERCEPTOR(char*, __strndup, const char *s, usize size) {
459459
void *ctx;
460460
COMMON_INTERCEPTOR_STRNDUP_IMPL(ctx, s, size);
461461
}
@@ -494,7 +494,7 @@ INTERCEPTOR(int, strcmp, const char *s1, const char *s2) {
494494
void *ctx;
495495
COMMON_INTERCEPTOR_ENTER(ctx, strcmp, s1, s2);
496496
unsigned char c1, c2;
497-
uptr i;
497+
usize i;
498498
for (i = 0;; i++) {
499499
c1 = (unsigned char)s1[i];
500500
c2 = (unsigned char)s2[i];
@@ -511,23 +511,23 @@ INTERCEPTOR(int, strcmp, const char *s1, const char *s2) {
511511
}
512512

513513
DECLARE_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_strncmp, uptr called_pc,
514-
const char *s1, const char *s2, uptr n,
514+
const char *s1, const char *s2, usize n,
515515
int result)
516516

517-
INTERCEPTOR(int, strncmp, const char *s1, const char *s2, uptr size) {
517+
INTERCEPTOR(int, strncmp, const char *s1, const char *s2, usize size) {
518518
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
519519
return internal_strncmp(s1, s2, size);
520520
void *ctx;
521521
COMMON_INTERCEPTOR_ENTER(ctx, strncmp, s1, s2, size);
522522
unsigned char c1 = 0, c2 = 0;
523-
uptr i;
523+
usize i;
524524
for (i = 0; i < size; i++) {
525525
c1 = (unsigned char)s1[i];
526526
c2 = (unsigned char)s2[i];
527527
if (c1 != c2 || c1 == '\0') break;
528528
}
529-
uptr i1 = i;
530-
uptr i2 = i;
529+
usize i1 = i;
530+
usize i2 = i;
531531
if (common_flags()->strict_string_checks) {
532532
for (; i1 < size && s1[i1]; i1++) {}
533533
for (; i2 < size && s2[i2]; i2++) {}
@@ -561,7 +561,7 @@ INTERCEPTOR(int, strcasecmp, const char *s1, const char *s2) {
561561
void *ctx;
562562
COMMON_INTERCEPTOR_ENTER(ctx, strcasecmp, s1, s2);
563563
unsigned char c1 = 0, c2 = 0;
564-
uptr i;
564+
usize i;
565565
for (i = 0;; i++) {
566566
c1 = (unsigned char)s1[i];
567567
c2 = (unsigned char)s2[i];
@@ -576,21 +576,21 @@ INTERCEPTOR(int, strcasecmp, const char *s1, const char *s2) {
576576
}
577577

578578
DECLARE_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_strncasecmp, uptr called_pc,
579-
const char *s1, const char *s2, uptr size,
579+
const char *s1, const char *s2, usize size,
580580
int result)
581581

582582
INTERCEPTOR(int, strncasecmp, const char *s1, const char *s2, SIZE_T size) {
583583
void *ctx;
584584
COMMON_INTERCEPTOR_ENTER(ctx, strncasecmp, s1, s2, size);
585585
unsigned char c1 = 0, c2 = 0;
586-
uptr i;
586+
usize i;
587587
for (i = 0; i < size; i++) {
588588
c1 = (unsigned char)s1[i];
589589
c2 = (unsigned char)s2[i];
590590
if (CharCaseCmp(c1, c2) != 0 || c1 == '\0') break;
591591
}
592-
uptr i1 = i;
593-
uptr i2 = i;
592+
usize i1 = i;
593+
usize i2 = i;
594594
if (common_flags()->strict_string_checks) {
595595
for (; i1 < size && s1[i1]; i1++) {}
596596
for (; i2 < size && s2[i2]; i2++) {}
@@ -613,8 +613,8 @@ INTERCEPTOR(int, strncasecmp, const char *s1, const char *s2, SIZE_T size) {
613613
#if SANITIZER_INTERCEPT_STRSTR || SANITIZER_INTERCEPT_STRCASESTR
614614
static inline void StrstrCheck(void *ctx, char *r, const char *s1,
615615
const char *s2) {
616-
uptr len1 = internal_strlen(s1);
617-
uptr len2 = internal_strlen(s2);
616+
usize len1 = internal_strlen(s1);
617+
usize len2 = internal_strlen(s2);
618618
COMMON_INTERCEPTOR_READ_STRING(ctx, s1, r ? r - s1 + len2 : len1 + 1);
619619
COMMON_INTERCEPTOR_READ_RANGE(ctx, s2, len2 + 1);
620620
}
@@ -758,7 +758,7 @@ INTERCEPTOR(char*, strchrnul, const char *s, int c) {
758758
void *ctx;
759759
COMMON_INTERCEPTOR_ENTER(ctx, strchrnul, s, c);
760760
char *result = REAL(strchrnul)(s, c);
761-
uptr len = result - s + 1;
761+
usize len = result - s + 1;
762762
if (common_flags()->intercept_strchr)
763763
COMMON_INTERCEPTOR_READ_STRING(ctx, s, len);
764764
return result;
@@ -833,13 +833,13 @@ INTERCEPTOR(char *, strpbrk, const char *s1, const char *s2) {
833833

834834
#if SANITIZER_INTERCEPT_MEMCMP
835835
DECLARE_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_memcmp, uptr called_pc,
836-
const void *s1, const void *s2, uptr n,
836+
const void *s1, const void *s2, usize n,
837837
int result)
838838

839839
// Common code for `memcmp` and `bcmp`.
840840
int MemcmpInterceptorCommon(void *ctx,
841-
int (*real_fn)(const void *, const void *, uptr),
842-
const void *a1, const void *a2, uptr size) {
841+
int (*real_fn)(const void *, const void *, usize),
842+
const void *a1, const void *a2, usize size) {
843843
if (common_flags()->intercept_memcmp) {
844844
if (common_flags()->strict_memcmp) {
845845
// Check the entire regions even if the first bytes of the buffers are
@@ -851,7 +851,7 @@ int MemcmpInterceptorCommon(void *ctx,
851851
unsigned char c1 = 0, c2 = 0;
852852
const unsigned char *s1 = (const unsigned char*)a1;
853853
const unsigned char *s2 = (const unsigned char*)a2;
854-
uptr i;
854+
usize i;
855855
for (i = 0; i < size; i++) {
856856
c1 = s1[i];
857857
c2 = s2[i];
@@ -871,7 +871,7 @@ int MemcmpInterceptorCommon(void *ctx,
871871
return result;
872872
}
873873

874-
INTERCEPTOR(int, memcmp, const void *a1, const void *a2, uptr size) {
874+
INTERCEPTOR(int, memcmp, const void *a1, const void *a2, usize size) {
875875
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
876876
return internal_memcmp(a1, a2, size);
877877
void *ctx;
@@ -885,7 +885,7 @@ INTERCEPTOR(int, memcmp, const void *a1, const void *a2, uptr size) {
885885
#endif
886886

887887
#if SANITIZER_INTERCEPT_BCMP
888-
INTERCEPTOR(int, bcmp, const void *a1, const void *a2, uptr size) {
888+
INTERCEPTOR(int, bcmp, const void *a1, const void *a2, usize size) {
889889
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
890890
return internal_memcmp(a1, a2, size);
891891
void *ctx;
@@ -914,7 +914,7 @@ INTERCEPTOR(void*, memchr, const void *s, int c, SIZE_T n) {
914914
#else
915915
void *res = REAL(memchr)(s, c, n);
916916
#endif
917-
uptr len = res ? (char *)res - (const char *)s + 1 : n;
917+
usize len = res ? (char *)res - (const char *)s + 1 : n;
918918
COMMON_INTERCEPTOR_READ_RANGE(ctx, s, len);
919919
return res;
920920
}
@@ -1138,7 +1138,7 @@ INTERCEPTOR(SSIZE_T, write, int fd, void *ptr, SIZE_T count) {
11381138
#endif
11391139

11401140
#if SANITIZER_INTERCEPT_FWRITE
1141-
INTERCEPTOR(SIZE_T, fwrite, const void *p, uptr size, uptr nmemb, void *file) {
1141+
INTERCEPTOR(SIZE_T, fwrite, const void *p, usize size, usize nmemb, void *file) {
11421142
// libc file streams can call user-supplied functions, see fopencookie.
11431143
void *ctx;
11441144
COMMON_INTERCEPTOR_ENTER(ctx, fwrite, p, size, nmemb, file);
@@ -6534,12 +6534,12 @@ static void MlockIsUnsupported() {
65346534
SanitizerToolName);
65356535
}
65366536

6537-
INTERCEPTOR(int, mlock, const void *addr, uptr len) {
6537+
INTERCEPTOR(int, mlock, const void *addr, usize len) {
65386538
MlockIsUnsupported();
65396539
return 0;
65406540
}
65416541

6542-
INTERCEPTOR(int, munlock, const void *addr, uptr len) {
6542+
INTERCEPTOR(int, munlock, const void *addr, usize len) {
65436543
MlockIsUnsupported();
65446544
return 0;
65456545
}

0 commit comments

Comments
 (0)