From c75886b8f8afabef83da96821d8a34111b4b5e83 Mon Sep 17 00:00:00 2001 From: ligd Date: Mon, 8 Jan 2024 15:46:50 +0800 Subject: [PATCH] kasan: add new API kasan_init_early() Signed-off-by: ligd --- mm/kasan/kasan.c | 5 +++++ mm/kasan/kasan.h | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c index 277323bad6..5f26277db6 100644 --- a/mm/kasan/kasan.c +++ b/mm/kasan/kasan.c @@ -324,6 +324,11 @@ void kasan_register(FAR void *addr, FAR size_t *size) *size -= KASAN_REGION_SIZE(*size); } +void kasan_init_early(void) +{ + g_region_init = 0; +} + /* Exported functions called from the compiler generated code */ void __sanitizer_annotate_contiguous_container(FAR const void *beg, diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index c6fd07ccc6..28eb544f8a 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -35,6 +35,7 @@ # define kasan_poison(addr, size) # define kasan_unpoison(addr, size) # define kasan_register(addr, size) +# define kasan_init_early() #endif /**************************************************************************** @@ -105,6 +106,24 @@ void kasan_unpoison(FAR const void *addr, size_t size); void kasan_register(FAR void *addr, FAR size_t *size); +/**************************************************************************** + * Name: kasan_init_early + * + * Description: + * Initialize the kasan early, setup g_region_init variable. + * This used for some platfroms clear bss late, and error use kasan before + * called kasan_register(). + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void kasan_init_early(void); + #endif /* CONFIG_MM_KASAN */ #undef EXTERN