From nobody Tue Feb 10 10:59:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1585596196; cv=none; d=zohomail.com; s=zohoarc; b=c1SVlOFmVkMlEEQMQH1FclOAEJ9wv3/79qy0wrUbzprXkzRWlIc4RzI4WiCsGhp5PIzZwXORwydZpS2DNpigvh+dGqViipM4L+Iq3quI9yvxVEltTSdoLKWMr7M7TFGzuTKpGik3v0omKpk5I3qohwAqpZBIc1QrxSk6hlf/Qm8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585596196; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Ar+pkUkHO0IhgHIuaQM/KErTZxeGYex2N8R3XcCHzrQ=; b=dhSGIWvPUpBdmnZarkicmIKRfED6seTad4J3q+4A1vjv4HAQ7sLS7ERmxqiGJfvrWrU80g3dwBmp3IZIHV5YHta/emAEKi3TIDB9zvTdgsZpxXJm552J47Mda9NoS4OKYrqaJc7tgJ7gw2cJ37e6rOKpEg7HlCYGFjDCSb5T9gg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585596196480338.0264012300795; Mon, 30 Mar 2020 12:23:16 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzY-00067D-54; Mon, 30 Mar 2020 19:22:36 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzX-00066b-6R for xen-devel@lists.xenproject.org; Mon, 30 Mar 2020 19:22:35 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c4a4302e-72bb-11ea-b9f4-12813bfff9fa; Mon, 30 Mar 2020 19:22:17 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jIzzE-0003lx-Io; Mon, 30 Mar 2020 19:22:16 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jIzzE-0007AJ-9t; Mon, 30 Mar 2020 19:22:16 +0000 X-Inumbo-ID: c4a4302e-72bb-11ea-b9f4-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ar+pkUkHO0IhgHIuaQM/KErTZxeGYex2N8R3XcCHzrQ=; b=eAP96CDy+hf5LJjWKoslWCgnDV OBlDEhaQoQj082EWORgY45D5O5I4WegRSYbXD9+2//3vREl11FF+w0VcF2kCnqgSrtTmqanAsNBpK Y2Ha3KBi3ShH+xu21RbgHeoDNkWzNUtdUwUHxtJM762kIWqu+ujOJvTy/l4RWhbHEV/E=; From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 30 Mar 2020 20:21:57 +0100 Message-Id: <20200330192157.1335-9-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200330192157.1335-1-julien@xen.org> References: <20200330192157.1335-1-julien@xen.org> Subject: [Xen-devel] [PATCH 8/8] tools/ocaml: Fix stubs build when OCaml has been compiled with -safe-string X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Julien Grall , Ian Jackson , dfaggioli@suse.com, Christian Lindig , David Scott Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall 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 Signed-off-by: Julien Grall --- I thought about detecting whether caml_alloc_initialized_string() strings exist and implement it if not. This requires a bit more work, so I would like to get feedback first whether this is worth it. --- 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/xenbu= s_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) }; =20 ret =3D 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)); =20 CAMLreturn(ret); } diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index 0fdbeac158..94aba38a42 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -501,7 +501,7 @@ CAMLprim value stub_xc_vcpu_context_get(value xch, valu= e domid, failwith_xc(_H(xch)); =20 context =3D 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)); =20 CAMLreturn(context); } @@ -680,7 +680,7 @@ CAMLprim value stub_xc_readconsolering(value xch) conring_size =3D size; =20 ring =3D caml_alloc_string(count); - memcpy(String_val(ring), str, count); + memcpy((char *) String_val(ring), str, count); free(str); =20 CAMLreturn(ring); --=20 2.17.1