Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 49779f4

Browse files
author
Marcos Pividori
committed
[sanitizer] Add weak hooks for Windows.
Add support for weak hooks on Windows, as we do on Linux and Darwin. As we use the macro: `SANITIZER_INTERFACE_WEAK_DEF()` it was not necessary to modify the header file: `sanitizer_common_interceptors.h`. After this diff, many tests were fixed for libFuzzer. Differential Revision: https://reviews.llvm.org/D29562 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@294409 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9a050b3 commit 49779f4

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

lib/sanitizer_common/sanitizer_common_interface.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ INTERFACE_FUNCTION(__sanitizer_set_report_fd)
1616
INTERFACE_FUNCTION(__sanitizer_verify_contiguous_container)
1717
INTERFACE_WEAK_FUNCTION(__sanitizer_report_error_summary)
1818
INTERFACE_WEAK_FUNCTION(__sanitizer_sandbox_on_notify)
19+
// Sanitizer weak hooks
20+
INTERFACE_WEAK_FUNCTION(__sanitizer_weak_hook_memcmp)
21+
INTERFACE_WEAK_FUNCTION(__sanitizer_weak_hook_strcmp)
22+
INTERFACE_WEAK_FUNCTION(__sanitizer_weak_hook_strncmp)
23+
INTERFACE_WEAK_FUNCTION(__sanitizer_weak_hook_strstr)
1924
// Stacktrace interface.
2025
INTERFACE_FUNCTION(__sanitizer_get_module_and_offset_for_pc)
2126
INTERFACE_FUNCTION(__sanitizer_symbolize_global)

lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
#include "sanitizer_internal_defs.h"
1818

1919
#if !SANITIZER_WINDOWS
20+
# define SI_WINDOWS 0
2021
# define SI_NOT_WINDOWS 1
2122
# include "sanitizer_platform_limits_posix.h"
2223
#else
24+
# define SI_WINDOWS 1
2325
# define SI_NOT_WINDOWS 0
2426
#endif
2527

@@ -310,7 +312,7 @@
310312
#define SANITIZER_INTERCEPT_CTERMID SI_LINUX || SI_MAC || SI_FREEBSD
311313
#define SANITIZER_INTERCEPT_CTERMID_R SI_MAC || SI_FREEBSD
312314

313-
#define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX || SI_MAC
315+
#define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX || SI_MAC || SI_WINDOWS
314316
#define SANITIZER_INTERCEPT_RECV_RECVFROM SI_NOT_WINDOWS
315317
#define SANITIZER_INTERCEPT_SEND_SENDTO SI_NOT_WINDOWS
316318
#define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE SI_LINUX

lib/sanitizer_common/sanitizer_win_weak_interception.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ int interceptWhenPossible(uptr dll_function, const char *real_function) {
3737
}
3838
} // namespace __sanitizer
3939

40+
// Declare weak hooks.
41+
extern "C" {
42+
void __sanitizer_weak_hook_memcmp(uptr called_pc, const void *s1,
43+
const void *s2, uptr n, int result);
44+
void __sanitizer_weak_hook_strcmp(uptr called_pc, const char *s1,
45+
const char *s2, int result);
46+
void __sanitizer_weak_hook_strncmp(uptr called_pc, const char *s1,
47+
const char *s2, uptr n, int result);
48+
void __sanitizer_weak_hook_strstr(uptr called_pc, const char *s1,
49+
const char *s2, char *result);
50+
}
51+
4052
// Include Sanitizer Common interface.
4153
#define INTERFACE_FUNCTION(Name)
4254
#define INTERFACE_WEAK_FUNCTION(Name) INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)

test/asan/TestCases/Darwin/interface_symbols_darwin.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// RUN: %p/../../../../lib/sanitizer_common/sanitizer_common_interface.inc \
2222
// RUN: %p/../../../../lib/sanitizer_common/sanitizer_common_interface_posix.inc \
2323
// RUN: %p/../../../../lib/sanitizer_common/sanitizer_coverage_interface.inc \
24+
// RUN: | grep -v "__sanitizer_weak_hook" \
2425
// RUN: | sed -e "s/.*(//" -e "s/).*//" > %t.imports
2526
//
2627
// RUN: cat %t.imports | sort | uniq > %t.imports-sorted

test/asan/TestCases/Linux/interface_symbols_linux.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// RUN: %p/../../../../lib/sanitizer_common/sanitizer_common_interface.inc \
1616
// RUN: %p/../../../../lib/sanitizer_common/sanitizer_common_interface_posix.inc \
1717
// RUN: %p/../../../../lib/sanitizer_common/sanitizer_coverage_interface.inc \
18+
// RUN: | grep -v "__sanitizer_weak_hook" \
1819
// RUN: | sed -e "s/.*(//" -e "s/).*//" > %t.imports
1920
//
2021
// RUN: cat %t.imports | sort | uniq > %t.imports-sorted

0 commit comments

Comments
 (0)