[PATCH 1/3] fuzz: add context pointer to call_for_each_fuzz_test
Ahmad Fatoum
a.fatoum at barebox.org
Mon Oct 27 00:42:30 PDT 2025
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 at 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
More information about the barebox
mailing list