Skip to content

Commit 4d0ddf2

Browse files
committed
fixed no_std once more
1 parent 64353b2 commit 4d0ddf2

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

libafl/src/bolts/os/pipes.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
//! Unix `pipe` wrapper for `LibAFL`
22
use crate::Error;
3-
use nix::unistd::{close, pipe, read, write};
4-
use std::io::{self, ErrorKind, Read, Write};
5-
use std::os::unix::io::RawFd;
3+
use nix::unistd::{close, pipe};
4+
5+
#[cfg(feature = "std")]
6+
use nix::unistd::{read, write};
7+
#[cfg(feature = "std")]
8+
use std::{
9+
io::{self, ErrorKind, Read, Write},
10+
os::unix::io::RawFd,
11+
};
12+
13+
#[cfg(not(feature = "std"))]
14+
type RawFd = i32;
615

716
#[derive(Debug, Clone)]
817
pub struct Pipe {
@@ -34,6 +43,7 @@ impl Pipe {
3443
}
3544
}
3645

46+
#[cfg(feature = "std")]
3747
impl Read for Pipe {
3848
/// Reads a few bytes
3949
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
@@ -50,6 +60,7 @@ impl Read for Pipe {
5060
}
5161
}
5262

63+
#[cfg(feature = "std")]
5364
impl Write for Pipe {
5465
/// Writes a few bytes
5566
fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {

libafl/src/bolts/shmem.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub type OsShMemProvider = Win32ShMemProvider;
1717
#[cfg(all(windows, feature = "std"))]
1818
pub type OsShMem = Win32ShMem;
1919

20+
use crate::Error;
21+
2022
#[cfg(all(target_os = "android", feature = "std"))]
2123
use crate::bolts::os::ashmem_server::ServedShMemProvider;
2224
#[cfg(all(target_os = "android", feature = "std"))]
@@ -39,7 +41,7 @@ use alloc::{rc::Rc, string::ToString};
3941
use core::{cell::RefCell, fmt::Debug, mem::ManuallyDrop};
4042

4143
#[cfg(all(unix, feature = "std"))]
42-
use crate::{bolts::os::pipes::Pipe, Error};
44+
use crate::bolts::os::pipes::Pipe;
4345
#[cfg(all(unix, feature = "std"))]
4446
use std::io::{Read, Write};
4547

@@ -252,7 +254,7 @@ impl<T: ShMemProvider> Drop for RcShMem<T> {
252254
/// that can use internal mutability.
253255
/// Useful if the `ShMemProvider` needs to keep local state.
254256
#[derive(Debug, Clone)]
255-
#[cfg(unix)]
257+
#[cfg(all(unix, feature = "std"))]
256258
pub struct RcShMemProvider<T: ShMemProvider> {
257259
/// The wrapped [`ShMemProvider`].
258260
internal: Rc<RefCell<T>>,
@@ -266,10 +268,10 @@ pub struct RcShMemProvider<T: ShMemProvider> {
266268
parent_child_pipe: Option<Pipe>,
267269
}
268270

269-
#[cfg(unix)]
271+
#[cfg(all(unix, feature = "std"))]
270272
unsafe impl<T: ShMemProvider> Send for RcShMemProvider<T> {}
271273

272-
#[cfg(unix)]
274+
#[cfg(all(unix, feature = "std"))]
273275
impl<T> ShMemProvider for RcShMemProvider<T>
274276
where
275277
T: ShMemProvider + alloc::fmt::Debug,
@@ -339,7 +341,7 @@ where
339341
}
340342
}
341343

342-
#[cfg(unix)]
344+
#[cfg(all(unix, feature = "std"))]
343345
impl<T> RcShMemProvider<T>
344346
where
345347
T: ShMemProvider,
@@ -402,7 +404,7 @@ where
402404
}
403405
}
404406

405-
#[cfg(unix)]
407+
#[cfg(all(unix, feature = "std"))]
406408
impl<T> Default for RcShMemProvider<T>
407409
where
408410
T: ShMemProvider + alloc::fmt::Debug,

libafl/src/utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//! Utility functions for AFL
22
3+
use crate::Error;
4+
5+
#[cfg(feature = "std")]
36
use crate::{
47
bolts::shmem::ShMemProvider,
58
events::llmp::{LlmpRestartingEventManager, ManagerKind},
69
inputs::Input,
710
state::IfInteresting,
811
stats::Stats,
9-
Error,
1012
};
1113

1214
use alloc::vec::Vec;

0 commit comments

Comments
 (0)