[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] tools/ocaml/mmap: Drop the len parameter from Xenmmap.write



commit 12c5eea3ca6fa2674726d62cc9f369f81861d23f
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Mon Feb 6 20:06:45 2023 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Thu Mar 30 16:26:24 2023 +0100

    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.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Christian Lindig <christian.lindig@xxxxxxxxx>
---
 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(-)

diff --git a/tools/ocaml/libs/mmap/xenmmap.ml b/tools/ocaml/libs/mmap/xenmmap.ml
index fd6735649f..746ca6e21c 100644
--- a/tools/ocaml/libs/mmap/xenmmap.ml
+++ b/tools/ocaml/libs/mmap/xenmmap.ml
@@ -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"
diff --git a/tools/ocaml/libs/mmap/xenmmap.mli 
b/tools/ocaml/libs/mmap/xenmmap.mli
index d097b68a8f..5d6aa19ca6 100644
--- a/tools/ocaml/libs/mmap/xenmmap.mli
+++ b/tools/ocaml/libs/mmap/xenmmap.mli
@@ -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"
diff --git a/tools/ocaml/libs/mmap/xenmmap_stubs.c 
b/tools/ocaml/libs/mmap/xenmmap_stubs.c
index c85b1fcce7..c15a565aaa 100644
--- a/tools/ocaml/libs/mmap/xenmmap_stubs.c
+++ b/tools/ocaml/libs/mmap/xenmmap_stubs.c
@@ -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);
 }
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.