forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
platform/posix: Unbreak fuzzer support
Upstream Zephyr moved the LLVM fuzzer entry point out of the arch layer and made it an app responsibility, so we broke. Add back the support here that got removed. Signed-off-by: Andy Ross <[email protected]>
- Loading branch information
Showing
4 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// Copyright(c) 2024 Google LLC. All rights reserved. | ||
// Author: Andy Ross <[email protected]> | ||
|
||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
|
||
#include <irq_ctrl.h> | ||
#include <zephyr/sys/time_units.h> | ||
|
||
/* Zephyr arch APIs, not in a header (native_sim has them though) */ | ||
void posix_init(int argc, char *argv[]); | ||
void posix_exec_for(uint64_t us); | ||
|
||
const uint8_t *posix_fuzz_buf; | ||
size_t posix_fuzz_sz; | ||
|
||
/** | ||
* Entry point for fuzzing. Works by placing the data | ||
* into two known symbols, triggering an app-visible interrupt, and | ||
* then letting the simulator run for a fixed amount of time (intended to be | ||
* "long enough" to handle the event and reach a quiescent state | ||
* again) | ||
*/ | ||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t sz) | ||
{ | ||
static bool runner_initialized; | ||
|
||
if (!runner_initialized) { | ||
posix_init(0, NULL); | ||
runner_initialized = true; | ||
} | ||
|
||
/* Provide the fuzz data to the embedded OS as an interrupt, with | ||
* "DMA-like" data placed into native_fuzz_buf/sz | ||
*/ | ||
posix_fuzz_buf = (void *)data; | ||
posix_fuzz_sz = sz; | ||
hw_irq_ctrl_set_irq(CONFIG_ZEPHYR_POSIX_FUZZ_IRQ); | ||
|
||
/* Give the OS time to process whatever happened in that | ||
* interrupt and reach an idle state. | ||
*/ | ||
posix_exec_for(k_ticks_to_us_ceil64(CONFIG_ZEPHYR_POSIX_FUZZ_TICKS)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters