mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] fuzz: add context pointer to call_for_each_fuzz_test
@ 2025-10-27  7:42 Ahmad Fatoum
  2025-10-27  7:42 ` [PATCH 2/3] sandbox: export list_fuzz_tests to sandbox_main Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-10-27  7:42 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

In preparation for removing call_for_each_fuzz_test from the sandbox
PBL, give it a context pointer to simplify its use.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 arch/sandbox/os/common.c | 9 +++++----
 include/fuzz.h           | 2 +-
 lib/fuzz.c               | 5 +++--
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 86aaeb24ee3d..e872a6381988 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -56,11 +56,11 @@ extern int barebox_loglevel;
 #endif
 
 #ifdef CONFIG_FUZZ_EXTERNAL
-int call_for_each_fuzz_test(int (*fn)(const char **test));
+int call_for_each_fuzz_test(int (*fn)(const char **test, void *), void *ctx);
 int setup_external_fuzz(const char *name,
 			int *argc, char ***argv);
 #else
-static inline int call_for_each_fuzz_test(int (*fn)(const char **test))
+static inline int call_for_each_fuzz_test(int (*fn)(const char **test, void *), void *ctx)
 {
 	return 0;
 }
@@ -558,7 +558,8 @@ static struct option long_options[] = {
 
 static const char optstring[] = "hm:i:c:e:d:O:I:B:x:y:";
 
-static __attribute__((unused)) int print_fuzz_test_name(const char **test_name)
+static __attribute__((unused)) int print_fuzz_test_name(const char **test_name,
+							void *ctx)
 {
 	printf("%s\n", *test_name);
 	return 0;
@@ -667,7 +668,7 @@ static int normal_main(int argc, char *argv[])
 			sdl_yres = strtoul(optarg, NULL, 0);
 			break;
 		case OPT_LIST_FUZZERS:
-			call_for_each_fuzz_test(print_fuzz_test_name);
+			call_for_each_fuzz_test(print_fuzz_test_name, NULL);
 			exit(0);
 			break;
 		case OPT_FUZZ:
diff --git a/include/fuzz.h b/include/fuzz.h
index caebc284d5db..f516d86ab769 100644
--- a/include/fuzz.h
+++ b/include/fuzz.h
@@ -84,7 +84,7 @@ static inline int fuzz_test_once(const struct fuzz_test *test, const u8 *data, s
 	return test->func(data, len);
 }
 
-int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test));
+int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test, void *), void *ctx);
 
 int setup_external_fuzz(const char *fuzz_name,
 			int *argc, char ***argv);
diff --git a/lib/fuzz.c b/lib/fuzz.c
index 084455e365cd..7be7ecedd922 100644
--- a/lib/fuzz.c
+++ b/lib/fuzz.c
@@ -4,13 +4,14 @@
 #include <string.h>
 #include <common.h>
 
-int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test))
+int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test, void *ctx),
+			    void *ctx)
 {
 	const struct fuzz_test *test;
 	int ret;
 
 	for_each_fuzz_test(test) {
-		ret = fn(test);
+		ret = fn(test, ctx);
 		if (ret)
 			return ret;
 	}
-- 
2.47.3




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-10-28  7:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-27  7:42 [PATCH 1/3] fuzz: add context pointer to call_for_each_fuzz_test Ahmad Fatoum
2025-10-27  7:42 ` [PATCH 2/3] sandbox: export list_fuzz_tests to sandbox_main Ahmad Fatoum
2025-10-27  7:42 ` [PATCH 3/3] fuzz: do not export for_each_fuzz_test Ahmad Fatoum
2025-10-28  7:26 ` [PATCH 1/3] fuzz: add context pointer to call_for_each_fuzz_test Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox