1
1
//! `LibAFL` functionality for filesystem interaction
2
2
3
- #[ cfg( feature = "std" ) ]
4
- use alloc:: { borrow:: ToOwned , vec:: Vec } ;
5
- use alloc:: { rc:: Rc , string:: String } ;
6
- use core:: cell:: RefCell ;
7
- #[ cfg( feature = "std" ) ]
8
- use core:: time:: Duration ;
9
3
#[ cfg( unix) ]
10
4
use std:: os:: unix:: prelude:: { AsRawFd , RawFd } ;
11
- #[ cfg( feature = "std" ) ]
5
+
6
+ use alloc:: string:: String ;
7
+ use alloc:: sync:: Arc ;
8
+ use alloc:: { borrow:: ToOwned , vec:: Vec } ;
9
+ use core:: time:: Duration ;
10
+
11
+ use crate :: Error ;
12
12
use std:: time:: SystemTime ;
13
13
use std:: {
14
14
fs:: { self , File , OpenOptions , remove_file} ,
15
15
io:: { Seek , Write } ,
16
16
path:: { Path , PathBuf } ,
17
17
} ;
18
18
19
- use crate :: Error ;
20
-
21
19
/// The default filename to use to deliver testcases to the target
22
20
pub const INPUTFILE_STD : & str = ".cur_input" ;
23
21
62
60
63
61
/// An [`InputFile`] to write fuzzer input to.
64
62
/// The target/forkserver will read from this file.
65
- #[ cfg( feature = "std" ) ]
66
63
#[ derive( Debug ) ]
67
64
pub struct InputFile {
68
65
/// The filename/path too this [`InputFile`]
@@ -71,7 +68,7 @@ pub struct InputFile {
71
68
pub file : File ,
72
69
/// The ref count for this [`InputFile`].
73
70
/// Once it reaches 0, the underlying [`File`] will be removed.
74
- pub rc : Rc < RefCell < usize > > ,
71
+ pub rc : Arc < ( ) > ,
75
72
}
76
73
77
74
impl Eq for InputFile { }
@@ -84,11 +81,6 @@ impl PartialEq for InputFile {
84
81
85
82
impl Clone for InputFile {
86
83
fn clone ( & self ) -> Self {
87
- {
88
- let mut rc = self . rc . borrow_mut ( ) ;
89
- assert_ne ! ( * rc, usize :: MAX , "InputFile rc overflow" ) ;
90
- * rc += 1 ;
91
- }
92
84
Self {
93
85
path : self . path . clone ( ) ,
94
86
file : self . file . try_clone ( ) . unwrap ( ) ,
@@ -113,7 +105,7 @@ impl InputFile {
113
105
Ok ( Self {
114
106
path : filename. as_ref ( ) . to_owned ( ) ,
115
107
file : f,
116
- rc : Rc :: new ( RefCell :: new ( 1 ) ) ,
108
+ rc : Arc :: new ( ( ) ) ,
117
109
} )
118
110
}
119
111
@@ -147,7 +139,6 @@ impl InputFile {
147
139
/// Finds new files in the given directory, taking the last time we looked at this path as parameter.
148
140
/// This method works recursively.
149
141
/// If `last` is `None`, it'll load all file.
150
- #[ cfg( feature = "std" ) ]
151
142
pub fn find_new_files_rec < P : AsRef < Path > > (
152
143
dir : P ,
153
144
last_check : & Option < Duration > ,
@@ -182,13 +173,9 @@ pub fn find_new_files_rec<P: AsRef<Path>>(
182
173
Ok ( new_files)
183
174
}
184
175
185
- #[ cfg( feature = "std" ) ]
186
176
impl Drop for InputFile {
187
177
fn drop ( & mut self ) {
188
- let mut rc = self . rc . borrow_mut ( ) ;
189
- assert_ne ! ( * rc, 0 , "InputFile rc should never be 0" ) ;
190
- * rc -= 1 ;
191
- if * rc == 0 {
178
+ if Arc :: into_inner ( core:: mem:: take ( & mut self . rc ) ) . is_some ( ) {
192
179
// try to remove the file, but ignore errors
193
180
drop ( remove_file ( & self . path ) ) ;
194
181
}
0 commit comments