From 23981cdf3d0c380f1d09407562972033087c2524 Mon Sep 17 00:00:00 2001 From: wangmingrong1 Date: Tue, 3 Sep 2024 12:41:03 +0800 Subject: [PATCH] mm/kasan: Add branch prediction and constant prediction Signed-off-by: wangmingrong1 --- mm/kasan/hook.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/kasan/hook.c b/mm/kasan/hook.c index da111ab2ac..694767af21 100644 --- a/mm/kasan/hook.c +++ b/mm/kasan/hook.c @@ -23,6 +23,7 @@ ****************************************************************************/ #include +#include #include #include @@ -204,7 +205,7 @@ static void kasan_check_watchpoint(FAR const void *addr, size_t size, { FAR struct kasan_watchpoint_s *watchpoint = &g_watchpoint[i]; - if (watchpoint->type == DEBUGPOINT_NONE) + if (predict_false(watchpoint->type == DEBUGPOINT_NONE)) { break; } @@ -228,20 +229,20 @@ static inline void kasan_check_report(FAR const void *addr, size_t size, bool is_write, FAR void *return_address) { - if (size == 0 || g_region_init != KASAN_INIT_VALUE) + if (predict_false(size == 0 || g_region_init != KASAN_INIT_VALUE)) { return; } #ifndef CONFIG_MM_KASAN_DISABLE_NULL_POINTER_CHECK - if (addr == NULL) + if (predict_false(addr == NULL)) { kasan_report(addr, size, is_write, return_address); } #endif #ifndef CONFIG_MM_KASAN_NONE - if (kasan_is_poisoned(addr, size)) + if (predict_false(kasan_is_poisoned(addr, size))) { kasan_report(addr, size, is_write, return_address); }