1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2026, Linutronix GmbH 4 */ 5 #ifndef __ASAN_TEST_H 6 #define __ASAN_TEST_H 7 8 #include <compiler.h> 9 #include <stddef.h> 10 11 /* 12 * Context used by ASan runtime tests. 13 */ 14 struct asan_test_ctx { 15 char *pmalloc1; 16 char *pmalloc2[3]; 17 char write_value; 18 void (*write_func)(char *buf, size_t pos, char value); 19 char (*read_func)(char *buf, size_t pos); 20 void *(*memcpy_func)(void *__restrict dst, 21 const void *__restrict src, size_t size); 22 void *(*memset_func)(void *buf, int val, size_t size); 23 void (*free_func)(void *ptr); 24 }; 25 26 27 /* 28 * Initialize ASan test context. 29 * Allocations and function pointers are set up for subsequent tests. 30 */ 31 void asan_test_init(struct asan_test_ctx *ctx); 32 33 /* 34 * Release any resources owned by the context. 35 */ 36 void asan_test_deinit(struct asan_test_ctx *ctx); 37 38 /* 39 * Helper to run a single ASan test. 40 * 41 * Returns 0 on success, or a negative error code on internal failure. 42 */ 43 int asan_call_test(struct asan_test_ctx *ctx, 44 void (*test)(struct asan_test_ctx *ctx), 45 const char __unused *desc); 46 47 /* Individual ASan test cases */ 48 void asan_test_stack(struct asan_test_ctx *ctx); 49 void asan_test_global_stat(struct asan_test_ctx *ctx); 50 void asan_test_global_ro(struct asan_test_ctx *ctx); 51 void asan_test_global(struct asan_test_ctx *ctx); 52 void asan_test_malloc(struct asan_test_ctx *ctx); 53 void asan_test_malloc2(struct asan_test_ctx *ctx); 54 void asan_test_use_after_free(struct asan_test_ctx *ctx); 55 void asan_test_memcpy_dst(struct asan_test_ctx *ctx); 56 void asan_test_memcpy_src(struct asan_test_ctx *ctx); 57 void asan_test_memset(struct asan_test_ctx *ctx); 58 59 #endif /* __ASAN_TEST_H */ 60