tools/ocaml/mmap: Drop the len parameter from Xenmmap.write
PATCH 1/1 tools/ocaml/mmap: Drop the len parameter from Xenmmap.write
Strings in Ocaml carry their own length. Absolutely nothing good can come from having caml_string_length(data) be different to len.
Use the appropriate accessor, String_val(), but retain the workaround for the Ocaml -safe-string constness bug in the same way as we've done elsewhere in Xen.
---
CC: Christian Lindig <[email protected]>
CC: David Scott <[email protected]>
CC: Edwin Török <[email protected]>
CC: Rob Hoes <[email protected]>
--- tools/ocaml/libs/mmap/xenmmap.ml | 4 ++-- tools/ocaml/libs/mmap/xenmmap.mli | 2 +- tools/ocaml/libs/mmap/xenmmap_stubs.c | 11 +++++------ 3 files changed, 8 insertions(+), 9 deletions(-)
tools/ocaml/libs/mmap/xenmmap.ml +2 -2
@@ -25,7 +25,7 @@ external mmap: Unix.file_descr -> mmap_prot_flag -> mmap_map_flag external unmap: mmap_interface -> unit = "stub_mmap_final" (* read: interface -> start -> length -> data *) external read: mmap_interface -> int -> int -> string = "stub_mmap_read" -(* write: interface -> data -> start -> length -> unit *) -external write: mmap_interface -> string -> int -> int -> unit = "stub_mmap_write" +(* write: interface -> data -> start -> unit *) +external write: mmap_interface -> string -> int -> unit = "stub_mmap_write" (* getpagesize: unit -> size of page *) external getpagesize: unit -> int = "stub_mmap_getpagesize"
tools/ocaml/libs/mmap/xenmmap.mli +1 -1
@@ -22,7 +22,7 @@ external mmap : Unix.file_descr -> mmap_prot_flag -> mmap_map_flag -> int -> int -> mmap_interface = "stub_mmap_init" external unmap : mmap_interface -> unit = "stub_mmap_final" external read : mmap_interface -> int -> int -> string = "stub_mmap_read" -external write : mmap_interface -> string -> int -> int -> unit +external write : mmap_interface -> string -> int -> unit = "stub_mmap_write" external getpagesize : unit -> int = "stub_mmap_getpagesize"
tools/ocaml/libs/mmap/xenmmap_stubs.c +5 -6
@@ -99,27 +99,26 @@ CAMLprim value stub_mmap_read(value intf, value start, value len)caml_invalid_argument ("len invalid" ); data =caml_alloc_string (c_len); -memcpy ((char *) data,Intf_val (intf)->addr + c_start, c_len); +memcpy ((char *)String_val (data),Intf_val (intf)->addr + c_start, c_len);CAMLreturn (data); } -CAMLprim value stub_mmap_write(value intf, value data, -value start,value len) +CAMLprim value stub_mmap_write(value intf, value data, value start) { -CAMLparam4 (intf, data, start, len); +CAMLparam3 (intf, data, start);int c_start;int c_len; c_start =Int_val (start); - c_len =Int_val (len); + c_len =caml_string_length (data);if (c_start >Intf_val (intf)->len)caml_invalid_argument ("start invalid" );if (c_start + c_len >Intf_val (intf)->len)caml_invalid_argument ("len invalid" ); -memcpy (Intf_val (intf)->addr + c_start, (char *) data, c_len); +memcpy (Intf_val (intf)->addr + c_start,String_val (data), c_len);CAMLreturn (Val_unit); }
Signature · 1 line
2.30.2
Quoted 18 lines · Andrew Cooper
Strings in Ocaml carry their own length. Absolutely nothing good can come from having
caml_string_length(data)be different to len.Use the appropriate accessor,
String_val(), but retain the workaround for the Ocaml -safe-string constness bug in the same way as we've done elsewhere in Xen.Signed-off-by Andrew Cooper <[email protected]>---
CC: Christian Lindig <[email protected]>
CC: David Scott <[email protected]>
CC: Edwin Török <[email protected]>
CC: Rob Hoes <[email protected]>
---
Quoted 4 lines
tools/ocaml/libs/mmap/xenmmap.ml | 4 ++-- tools/ocaml/libs/mmap/xenmmap.mli | 2 +- tools/ocaml/libs/mmap/xenmmap_stubs.c | 11 +++++------ 3 files changed, 8 insertions(+), 9 deletions(-)