forked from OSchip/llvm-project
Add dfsan_weak_hook_memcmp
Summary: Add a weak hook to be called from dfsan's custom memcmp. The primary user will be lib/Fuzzer. If this works well we'll add more hooks (strcmp, etc). Test Plan: Will be covered by lib/Fuzzer tests. Reviewers: pcc Reviewed By: pcc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9541 llvm-svn: 236679
This commit is contained in:
parent
567d0e5a90
commit
13c03581ac
compiler-rt
|
@ -91,6 +91,16 @@ void dfsan_set_write_callback(dfsan_write_callback_t labeled_write_callback);
|
||||||
/// <label> <parent label 1> <parent label 2> <label description if any>
|
/// <label> <parent label 1> <parent label 2> <label description if any>
|
||||||
void dfsan_dump_labels(int fd);
|
void dfsan_dump_labels(int fd);
|
||||||
|
|
||||||
|
/// Whenever a dfsan's custom function is called the corresponding
|
||||||
|
/// hook is called it non-zero. The hooks should be defined by the user.
|
||||||
|
/// The primary use case is taint-guided fuzzing, where the fuzzer
|
||||||
|
/// needs to see the parameters of the function and the labels.
|
||||||
|
/// FIXME: implement more hooks.
|
||||||
|
|
||||||
|
/// memcmp hook.
|
||||||
|
void dfsan_weak_hook_memcmp(void *caller_pc, const void *s1, const void *s2,
|
||||||
|
size_t n, dfsan_label s1_label,
|
||||||
|
dfsan_label s2_label, dfsan_label n_label);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
|
|
|
@ -82,11 +82,20 @@ SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strchr(const char *s, int c,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
||||||
|
void
|
||||||
|
dfsan_weak_hook_memcmp(uptr caller_pc, const void *s1, const void *s2, size_t n,
|
||||||
|
dfsan_label s1_label, dfsan_label s2_label,
|
||||||
|
dfsan_label n_label);
|
||||||
|
|
||||||
SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_memcmp(const void *s1, const void *s2,
|
SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_memcmp(const void *s1, const void *s2,
|
||||||
size_t n, dfsan_label s1_label,
|
size_t n, dfsan_label s1_label,
|
||||||
dfsan_label s2_label,
|
dfsan_label s2_label,
|
||||||
dfsan_label n_label,
|
dfsan_label n_label,
|
||||||
dfsan_label *ret_label) {
|
dfsan_label *ret_label) {
|
||||||
|
if (dfsan_weak_hook_memcmp)
|
||||||
|
dfsan_weak_hook_memcmp(GET_CALLER_PC(), s1, s2, n, s1_label, s2_label,
|
||||||
|
n_label);
|
||||||
const char *cs1 = (const char *) s1, *cs2 = (const char *) s2;
|
const char *cs1 = (const char *) s1, *cs2 = (const char *) s2;
|
||||||
for (size_t i = 0; i != n; ++i) {
|
for (size_t i = 0; i != n; ++i) {
|
||||||
if (cs1[i] != cs2[i]) {
|
if (cs1[i] != cs2[i]) {
|
||||||
|
|
Loading…
Reference in New Issue