Skip to content

Commit 8b27cc7

Browse files
committed
[compiler-rt][sanitizer-common] adding C23 memset_explicit interception.
1 parent f8a77f3 commit 8b27cc7

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ INTERCEPTOR(void *, bzero, void *block, usize size) {
233233
#define INIT_BZERO
234234
#endif // SANITIZER_INTERCEPT_BZERO
235235

236+
#if SANITIZER_INTERCEPT_MEMSET_EXPLICIT
237+
INTERCEPTOR(void *, memset_explicit, void *block, int c, usize size) {
238+
void *ctx;
239+
COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size);
240+
}
241+
#define INIT_MEMSET_EXPLICIT COMMON_INTERCEPT_FUNCTION(memset_explicit)
242+
#else
243+
#define INIT_MEMSET_EXPLICIT
244+
#endif
245+
236246
namespace __sanitizer {
237247
// This does not need to be called if InitializeCommonInterceptors() is called.
238248
void InitializeMemintrinsicInterceptors() {
@@ -242,5 +252,6 @@ void InitializeMemintrinsicInterceptors() {
242252
INIT_AEABI_MEM;
243253
INIT___BZERO;
244254
INIT_BZERO;
255+
INIT_MEMSET_EXPLICIT;
245256
}
246257
} // namespace __sanitizer

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,15 +663,17 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
663663
#define SANITIZER_INTERCEPT_GETSERVBYNAME_R SI_GLIBC
664664
#define SANITIZER_INTERCEPT_GETSERVBYPORT_R SI_GLIBC
665665

666-
// Until free_sized and free_aligned_sized are more generally available,
666+
// Until free_sized, free_aligned_sized and memset_explicit are more generally available,
667667
// we can only unconditionally intercept on ELF-based platforms where it
668668
// is okay to have undefined weak symbols.
669669
#ifdef __ELF__
670670
# define SANITIZER_INTERCEPT_FREE_SIZED 1
671671
# define SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED 1
672+
# define SANITIZER_INTERCEPT_MEMSET_EXPLICIT 1
672673
#else
673674
# define SANITIZER_INTERCEPT_FREE_SIZED 0
674675
# define SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED 0
676+
# define SANITIZER_INTERCEPT_MEMSET_EXPLICIT 0
675677
#endif
676678

677679
// This macro gives a way for downstream users to override the above
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang -std=c23 -O0 %s -o %t && %run %t
2+
// UNSUPPORTED: asan, lsan, hwasan, ubsan
3+
4+
#include <stddef.h>
5+
#include <stdlib.h>
6+
7+
extern void *memset_explicit(void *p, int value, size_t size);
8+
9+
int main() {
10+
char secbuffer[64];
11+
(void)memset_explicit(secbuffer, 0, sizeof(secbuffer));
12+
return 0;
13+
}

0 commit comments

Comments
 (0)