Skip to content

Commit 9a156f6

Browse files
stefan-sf-ibmvitalybuka
authored andcommitted
[sanitizer] Replace uptr by usize/SIZE_T in interfaces
For some targets uptr is mapped to unsigned int and size_t to unsigned long and sizeof(int)==sizeof(long) holds. Still, these are distinct types and type checking may fail. Therefore, replace uptr by usize/SIZE_T wherever a size_t is expected. Part of #116957
1 parent 16c2a10 commit 9a156f6

14 files changed

+65
-66
lines changed

compiler-rt/lib/asan/asan_interceptors.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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) \
@@ -529,7 +529,7 @@ 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();
@@ -617,7 +617,7 @@ 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();

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/memprof/memprof_interceptors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int OnExit() {
4949
// ---------------------- Wrappers ---------------- {{{1
5050
using namespace __memprof;
5151

52-
DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, uptr)
52+
DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, usize)
5353
DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
5454

5555
#define COMMON_INTERCEPT_FUNCTION_VER(name, ver) \

compiler-rt/lib/memprof/memprof_interceptors.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ void InitializePlatformInterceptors();
3333

3434
} // namespace __memprof
3535

36-
DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
36+
DECLARE_REAL(int, memcmp, const void *a1, const void *a2, SIZE_T size)
3737
DECLARE_REAL(char *, strchr, const char *str, int c)
3838
DECLARE_REAL(SIZE_T, strlen, const char *s)
39-
DECLARE_REAL(char *, strncpy, char *to, const char *from, uptr size)
40-
DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
39+
DECLARE_REAL(char *, strncpy, char *to, const char *from, SIZE_T size)
40+
DECLARE_REAL(SIZE_T, strnlen, const char *s, SIZE_T maxlen)
4141
DECLARE_REAL(char *, strstr, const char *s1, const char *s2)
4242

4343
#define MEMPROF_INTERCEPT_FUNC(name) \

compiler-rt/lib/memprof/memprof_interceptors_memintrinsics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include "memprof_internal.h"
1919
#include "memprof_mapping.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 __memprof {
2525

compiler-rt/lib/msan/msan_interceptors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ using __sanitizer::atomic_uintptr_t;
5959

6060
DECLARE_REAL(SIZE_T, strlen, const char *s)
6161
DECLARE_REAL(SIZE_T, strnlen, const char *s, SIZE_T maxlen)
62-
DECLARE_REAL(void *, memcpy, void *dest, const void *src, uptr n)
63-
DECLARE_REAL(void *, memset, void *dest, int c, uptr n)
62+
DECLARE_REAL(void *, memcpy, void *dest, const void *src, SIZE_T n)
63+
DECLARE_REAL(void *, memset, void *dest, int c, SIZE_T n)
6464

6565
// True if this is a nested interceptor.
6666
static THREADLOCAL int in_interceptor_scope;

compiler-rt/lib/msan/msan_poisoning.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include "msan_thread.h"
1818
#include "sanitizer_common/sanitizer_common.h"
1919

20-
DECLARE_REAL(void *, memset, void *dest, int c, uptr n)
21-
DECLARE_REAL(void *, memcpy, void *dest, const void *src, uptr n)
22-
DECLARE_REAL(void *, memmove, void *dest, const void *src, uptr n)
20+
DECLARE_REAL(void *, memset, void *dest, int c, SIZE_T n)
21+
DECLARE_REAL(void *, memcpy, void *dest, const void *src, SIZE_T n)
22+
DECLARE_REAL(void *, memmove, void *dest, const void *src, SIZE_T n)
2323

2424
namespace __msan {
2525

compiler-rt/lib/nsan/nsan_allocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
using namespace __nsan;
2727

28-
DECLARE_REAL(void *, memcpy, void *dest, const void *src, uptr n)
29-
DECLARE_REAL(void *, memset, void *dest, int c, uptr n)
28+
DECLARE_REAL(void *, memcpy, void *dest, const void *src, SIZE_T n)
29+
DECLARE_REAL(void *, memset, void *dest, int c, SIZE_T n)
3030

3131
namespace {
3232
struct Metadata {

compiler-rt/lib/nsan/nsan_interceptors.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace __sanitizer;
2828

2929
template <typename T> T min(T a, T b) { return a < b ? a : b; }
3030

31-
INTERCEPTOR(void *, memset, void *dst, int v, uptr size) {
31+
INTERCEPTOR(void *, memset, void *dst, int v, usize size) {
3232
// NOTE: This guard is needed because nsan's initialization code might call
3333
// memset.
3434
if (!nsan_initialized && REAL(memset) == nullptr)
@@ -39,13 +39,13 @@ INTERCEPTOR(void *, memset, void *dst, int v, uptr size) {
3939
return res;
4040
}
4141

42-
INTERCEPTOR(wchar_t *, wmemset, wchar_t *dst, wchar_t v, uptr size) {
42+
INTERCEPTOR(wchar_t *, wmemset, wchar_t *dst, wchar_t v, usize size) {
4343
wchar_t *res = REAL(wmemset)(dst, v, size);
4444
__nsan_set_value_unknown((u8 *)dst, sizeof(wchar_t) * size);
4545
return res;
4646
}
4747

48-
INTERCEPTOR(void *, memmove, void *dst, const void *src, uptr size) {
48+
INTERCEPTOR(void *, memmove, void *dst, const void *src, usize size) {
4949
// NOTE: This guard is needed because nsan's initialization code might call
5050
// memmove.
5151
if (!nsan_initialized && REAL(memmove) == nullptr)
@@ -57,13 +57,13 @@ INTERCEPTOR(void *, memmove, void *dst, const void *src, uptr size) {
5757
return res;
5858
}
5959

60-
INTERCEPTOR(wchar_t *, wmemmove, wchar_t *dst, const wchar_t *src, uptr size) {
60+
INTERCEPTOR(wchar_t *, wmemmove, wchar_t *dst, const wchar_t *src, usize size) {
6161
wchar_t *res = REAL(wmemmove)(dst, src, size);
6262
__nsan_copy_values((u8 *)dst, (const u8 *)src, sizeof(wchar_t) * size);
6363
return res;
6464
}
6565

66-
INTERCEPTOR(void *, memcpy, void *dst, const void *src, uptr size) {
66+
INTERCEPTOR(void *, memcpy, void *dst, const void *src, usize size) {
6767
// NOTE: This guard is needed because nsan's initialization code might call
6868
// memcpy.
6969
if (!nsan_initialized && REAL(memcpy) == nullptr) {
@@ -78,7 +78,7 @@ INTERCEPTOR(void *, memcpy, void *dst, const void *src, uptr size) {
7878
return res;
7979
}
8080

81-
INTERCEPTOR(wchar_t *, wmemcpy, wchar_t *dst, const wchar_t *src, uptr size) {
81+
INTERCEPTOR(wchar_t *, wmemcpy, wchar_t *dst, const wchar_t *src, usize size) {
8282
wchar_t *res = REAL(wmemcpy)(dst, src, size);
8383
__nsan_copy_values((u8 *)dst, (const u8 *)src, sizeof(wchar_t) * size);
8484
return res;
@@ -136,7 +136,7 @@ INTERCEPTOR(wchar_t *, wcsdup, const wchar_t *S) {
136136
return res;
137137
}
138138

139-
INTERCEPTOR(char *, strndup, const char *S, uptr size) {
139+
INTERCEPTOR(char *, strndup, const char *S, usize size) {
140140
char *res = REAL(strndup)(S, size);
141141
if (res) {
142142
nsanCopyZeroTerminated(res, S, min(internal_strlen(S), size));
@@ -156,7 +156,7 @@ INTERCEPTOR(wchar_t *, wcscpy, wchar_t *dst, const wchar_t *src) {
156156
return res;
157157
}
158158

159-
INTERCEPTOR(char *, strncpy, char *dst, const char *src, uptr size) {
159+
INTERCEPTOR(char *, strncpy, char *dst, const char *src, usize size) {
160160
char *res = REAL(strncpy)(dst, src, size);
161161
nsanCopyZeroTerminated(dst, src, min(size, internal_strlen(src)));
162162
return res;
@@ -176,7 +176,7 @@ INTERCEPTOR(wchar_t *, wcscat, wchar_t *dst, const wchar_t *src) {
176176
return res;
177177
}
178178

179-
INTERCEPTOR(char *, strncat, char *dst, const char *src, uptr size) {
179+
INTERCEPTOR(char *, strncat, char *dst, const char *src, usize size) {
180180
const auto DstLen = internal_strlen(dst);
181181
char *res = REAL(strncat)(dst, src, size);
182182
nsanCopyZeroTerminated(dst + DstLen, src, min(size, internal_strlen(src)));
@@ -195,11 +195,10 @@ INTERCEPTOR(wchar_t *, wcpcpy, wchar_t *dst, const wchar_t *src) {
195195
return res;
196196
}
197197

198-
INTERCEPTOR(uptr, strxfrm, char *dst, const char *src, uptr size) {
198+
INTERCEPTOR(usize, strxfrm, char *dst, const char *src, usize size) {
199199
// This is overly conservative, but this function should very rarely be used.
200200
__nsan_set_value_unknown(reinterpret_cast<u8 *>(dst), internal_strlen(dst));
201-
const uptr res = REAL(strxfrm)(dst, src, size);
202-
return res;
201+
return REAL(strxfrm)(dst, src, size);
203202
}
204203

205204
extern "C" int pthread_attr_init(void *attr);

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -511,10 +511,10 @@ 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;
@@ -576,7 +576,7 @@ 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) {
@@ -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
@@ -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;
@@ -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);
@@ -6553,12 +6553,12 @@ static void MlockIsUnsupported() {
65536553
SanitizerToolName);
65546554
}
65556555

6556-
INTERCEPTOR(int, mlock, const void *addr, uptr len) {
6556+
INTERCEPTOR(int, mlock, const void *addr, usize len) {
65576557
MlockIsUnsupported();
65586558
return 0;
65596559
}
65606560

6561-
INTERCEPTOR(int, munlock, const void *addr, uptr len) {
6561+
INTERCEPTOR(int, munlock, const void *addr, usize len) {
65626562
MlockIsUnsupported();
65636563
return 0;
65646564
}

0 commit comments

Comments
 (0)