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

[xen staging-4.13] tools/ocaml: Fix stubs build when OCaml has been compiled with -safe-string



commit 1cd059ae93261374527cc678551510bfb4a8858e
Author:     Julien Grall <jgrall@xxxxxxxxxx>
AuthorDate: Mon Mar 30 15:14:23 2020 +0100
Commit:     Ian Jackson <iwj@xxxxxxxxxxxxxx>
CommitDate: Fri Mar 19 13:41:05 2021 +0000

    tools/ocaml: Fix stubs build when OCaml has been compiled with -safe-string
    
    The OCaml code has been fixed to handle properly -safe-string in Xen
    4.11, however the stubs part were missed.
    
    On OCaml newer than 4.06.1, String_Val() will return a const char *
    when using -safe-string leading to build failure when this is used
    in place where char * is expected.
    
    The main use in Xen code base is when a new string is allocated. The
    suggested approach by the OCaml community [1] is to use the helper
    caml_alloc_initialized_string() but it was introduced by OCaml 4.06.1.
    
    The next best approach is to cast String_val() to (char *) as the helper
    would have done. So use it when we need to update the new string using
    memcpy().
    
    Take the opportunity to remove the unnecessary cast of the source as
    mempcy() is expecting a void *.
    
    [1] https://github.com/ocaml/ocaml/pull/1274
    
    Reported-by: Dario Faggioli <dfaggioli@xxxxxxxx>
    Signed-off-by: Julien Grall <jgrall@xxxxxxxxxx>
    Acked-by: Christian Lindig <christian.lindig@xxxxxxxxxx>
    (cherry picked from commit 59b087e3954402c487e0abb4ad9bd05f43669436)
---
 tools/ocaml/libs/xb/xenbus_stubs.c  | 2 +-
 tools/ocaml/libs/xc/xenctrl_stubs.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/ocaml/libs/xb/xenbus_stubs.c 
b/tools/ocaml/libs/xb/xenbus_stubs.c
index 001bb03371..3065181a55 100644
--- a/tools/ocaml/libs/xb/xenbus_stubs.c
+++ b/tools/ocaml/libs/xb/xenbus_stubs.c
@@ -65,7 +65,7 @@ CAMLprim value stub_string_of_header(value tid, value rid, 
value ty, value len)
        };
 
        ret = caml_alloc_string(sizeof(struct xsd_sockmsg));
-       memcpy(String_val(ret), &xsd, sizeof(struct xsd_sockmsg));
+       memcpy((char *) String_val(ret), &xsd, sizeof(struct xsd_sockmsg));
 
        CAMLreturn(ret);
 }
diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c 
b/tools/ocaml/libs/xc/xenctrl_stubs.c
index 48f39f81d5..e16ed15b86 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -505,7 +505,7 @@ CAMLprim value stub_xc_vcpu_context_get(value xch, value 
domid,
        ret = xc_vcpu_getcontext(_H(xch), _D(domid), Int_val(cpu), &ctxt);
 
        context = caml_alloc_string(sizeof(ctxt));
-       memcpy(String_val(context), (char *) &ctxt.c, sizeof(ctxt.c));
+       memcpy((char *) String_val(context), &ctxt.c, sizeof(ctxt.c));
 
        CAMLreturn(context);
 }
@@ -684,7 +684,7 @@ CAMLprim value stub_xc_readconsolering(value xch)
                conring_size = size;
 
        ring = caml_alloc_string(count);
-       memcpy(String_val(ring), str, count);
+       memcpy((char *) String_val(ring), str, count);
        free(str);
 
        CAMLreturn(ring);
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.13



 


Rackspace

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