]> xenbits.xensource.com Git - xen.git/commitdiff
tools/ocaml: Fix stubs build when OCaml has been compiled with -safe-string
authorJulien Grall <jgrall@amazon.com>
Mon, 30 Mar 2020 14:14:23 +0000 (15:14 +0100)
committerIan Jackson <iwj@xenproject.org>
Fri, 19 Mar 2021 13:46:43 +0000 (13:46 +0000)
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@suse.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
(cherry picked from commit 59b087e3954402c487e0abb4ad9bd05f43669436)

tools/ocaml/libs/xb/xenbus_stubs.c
tools/ocaml/libs/xc/xenctrl_stubs.c

index 001bb033710943dab6022e71e34ad3311fa7c239..3065181a55e666898943054f271bdd8c0d11e97d 100644 (file)
@@ -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);
 }
index c4fdc58b2d66d65160adc1fbc3e85367a3140758..cae33a8cb25fe223d55208fc2426e2289ac31a88 100644 (file)
@@ -436,7 +436,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);
 }
@@ -615,7 +615,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);