mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-10-24 21:23:13 +00:00
ec058d6c46
Move GuestAddress and GuestMemory to a new crate for VM memory. This will make separating sys_util and crosvm independent making it easier to use sys_util functions outside of crosvm. Change-Id: I12e14948ea85754dfa6267b3a3fb32b77ef6796e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311251 Auto-Submit: Dylan Reid <dgreid@chromium.org> Commit-Queue: Dylan Reid <dgreid@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
30 lines
905 B
Rust
30 lines
905 B
Rust
// Copyright 2019 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#![no_main]
|
|
|
|
use cros_fuzz::fuzz_target;
|
|
use sys_util::SharedMemory;
|
|
use vm_memory::{GuestAddress, GuestMemory};
|
|
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
|
|
const MEM_SIZE: u64 = 256 * 1024 * 1024;
|
|
|
|
fn make_elf_bin(elf_bytes: &[u8]) -> File {
|
|
let mut shm = SharedMemory::anon().expect("failed to create shared memory");
|
|
shm.set_size(elf_bytes.len() as u64)
|
|
.expect("failed to set shared memory size");
|
|
shm.write_all(elf_bytes)
|
|
.expect("failed to write elf to shared memoy");
|
|
shm.into()
|
|
}
|
|
|
|
fuzz_target!(|bytes| {
|
|
let mut kimage = make_elf_bin(bytes);
|
|
let mem = GuestMemory::new(&[(GuestAddress(0), MEM_SIZE)]).unwrap();
|
|
let _ = kernel_loader::load_kernel(&mem, GuestAddress(0), &mut kimage);
|
|
});
|