File: aflPersistent.ml

package info (click to toggle)
ocaml-afl-persistent 1.4-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 128 kB
  • sloc: ml: 100; sh: 49; makefile: 11
file content (21 lines) | stat: -rw-r--r-- 583 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
external reset_instrumentation : bool -> unit = "caml_reset_afl_instrumentation"
external sys_exit : int -> 'a = "caml_sys_exit"

let run f =
  let _ = try ignore (Sys.getenv "##SIG_AFL_PERSISTENT##") with Not_found -> () in
  let persist = match Sys.getenv "__AFL_PERSISTENT" with
    | _ -> true
    | exception Not_found -> false in
  let pid = Unix.getpid () in
  if persist then begin
    reset_instrumentation true;
    for _ = 1 to 1000 do
      f ();
      Unix.kill pid Sys.sigstop;
      reset_instrumentation false
    done;
    f ();
    sys_exit 0;
  end else
    f ()