(* Use the tree to quickly check if an address is mapped (returns false
* if it's a hole).
*)
-let is_mapped { tree = tree } addr =
- let _, mapping = get_mapping addr tree in
- mapping <> None
+let is_mapped { mappings = mappings; tree = tree } addr =
+ (* NB: No [`HasMapping] in the type so we have to check mappings <> []. *)
+ match mappings with
+ | [] -> false
+ | _ ->
+ let _, mapping = get_mapping addr tree in
+ mapping <> None
(* Get a single byte. *)
let get_byte { tree = tree } addr =
in
loop addr
+let is_mapped_range ({ mappings = mappings } as t) addr size =
+ match mappings with
+ (* NB: No [`HasMapping] in the type so we have to check mappings <> []. *)
+ | [] -> false
+ | _ ->
+ (* Quick and dirty. It's possible to make a much faster
+ * implementation of this which doesn't call the closure for every
+ * byte.
+ *)
+ let size = ref size in
+ try dowhile t addr (fun _ _ -> decr size; !size > 0); true
+ with Invalid_argument "dowhile" -> false
+
(* Get a string, ending at ASCII NUL character. *)
let get_string t addr =
let chars = ref [] in