@@ -117,6 +117,7 @@ impl litecov::Coverage {
117117 }
118118}
119119
120+ /// The main `TinyInst` struct.
120121pub struct TinyInst {
121122 tinyinst_ptr : UniquePtr < litecov:: TinyInstInstrumentation > ,
122123 program_args_cstr : Vec < CString > ,
@@ -136,7 +137,7 @@ impl Debug for TinyInst {
136137
137138impl TinyInst {
138139 #[ must_use]
139- pub unsafe fn new ( tinyinst_args : & [ String ] , program_args : & [ String ] , timeout : u32 ) -> TinyInst {
140+ pub fn new ( tinyinst_args : & [ String ] , program_args : & [ String ] , timeout : u32 ) -> TinyInst {
140141 // commented out by domenukk:
141142 // a) would require call to a libc, c++ or rust std fn
142143 // b) The program could actually be in the PATH, so, not accessible as file.
@@ -157,11 +158,16 @@ impl TinyInst {
157158 . collect ( ) ;
158159 tinyinst_args_ptr. push ( core:: ptr:: null_mut ( ) ) ;
159160
160- // Init TinyInst with Tinyinst arguments.
161- tinyinst_ptr. pin_mut ( ) . Init (
162- i32:: try_from ( tinyinst_args. len ( ) ) . unwrap ( ) ,
163- tinyinst_args_ptr. as_mut_ptr ( ) ,
164- ) ;
161+ // Init TinyInst with TinyInst arguments.
162+ //
163+ // # Safety
164+ // The arguments and pointers are valid at this point
165+ unsafe {
166+ tinyinst_ptr. pin_mut ( ) . Init (
167+ i32:: try_from ( tinyinst_args. len ( ) ) . unwrap ( ) ,
168+ tinyinst_args_ptr. as_mut_ptr ( ) ,
169+ ) ;
170+ }
165171
166172 let program_args_cstr: Vec < CString > = program_args
167173 . iter ( )
@@ -183,13 +189,21 @@ impl TinyInst {
183189 }
184190 }
185191
192+ /// Runs the target in litecov.
193+ ///
194+ /// # Safety
195+ /// An insecure target can by design be unsafe to run.
186196 pub unsafe fn run ( & mut self ) -> litecov:: RunResult {
187- self . tinyinst_ptr . pin_mut ( ) . Run (
188- i32:: try_from ( self . program_args_cstr . len ( ) ) . unwrap ( ) ,
189- self . program_args_ptr . as_mut_ptr ( ) ,
190- self . timeout ,
191- self . timeout ,
192- )
197+ // # Safety
198+ // Runs the target program in litecov. Anything might happen.
199+ unsafe {
200+ self . tinyinst_ptr . pin_mut ( ) . Run (
201+ i32:: try_from ( self . program_args_cstr . len ( ) ) . unwrap ( ) ,
202+ self . program_args_ptr . as_mut_ptr ( ) ,
203+ self . timeout ,
204+ self . timeout ,
205+ )
206+ }
193207 }
194208
195209 // pub unsafe fn bitmap_coverage(
@@ -204,6 +218,7 @@ impl TinyInst {
204218 // litecov::get_coverage_map(bitmap, map_size, self.coverage_ptr.pin_mut());
205219 // }
206220
221+ /// Gets the covered blocks as vec.
207222 pub fn vec_coverage ( & mut self , afl_coverage : & mut Vec < u64 > , clear_coverage : bool ) {
208223 // Clear coverage if there was previous coverage
209224 afl_coverage. clear ( ) ;
@@ -215,6 +230,8 @@ impl TinyInst {
215230 // This will mark coverage we have seen as already seen coverage and won't report it again.
216231 self . ignore_coverage ( ) ;
217232 }
233+
234+ /// Mark coverage we have seen as already seen coverage to not report it again.
218235 fn ignore_coverage ( & mut self ) {
219236 self . tinyinst_ptr
220237 . pin_mut ( )
@@ -282,6 +299,7 @@ mod tests {
282299 assert_eq ! ( result, super :: litecov:: RunResult :: OK ) ;
283300 }
284301 }
302+
285303 #[ test]
286304 fn tinyinst_crash ( ) {
287305 use alloc:: { string:: ToString , vec:: Vec } ;
0 commit comments