From nobody Sat Nov 30 00:37:33 2024 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=pass; 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1620757213; cv=none; d=zohomail.com; s=zohoarc; b=WgSN7zmO34NYf1iMiMTkOazPV/DXXqlreqA0mPHLkEvkCh+c+7DJYNhrG08wiB1bKXleKI7gOy/HVTLS+wPhynJIyKCJitpbRNveByoIz2Snm5BAz/dmrX0Bcme4cNDsgGauGOCEeXJWviIDBSqCrGaXEHvaIrkvmAJswk/HQcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620757213; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OPCKjBUDyrIo19Tla6TwFLg+5oIxqO9gOJ2a8sRRpLE=; b=cm4XGvSF2+BHT+d3w20V5lYCYI4Ao7I+Q+cfVy7PuPhBZCxm/9yV1FGXmFcN48eSWNkNYl64k93b5ib36hD/R70fg4qfW4LGYkGO1XCy+c7p0yVpuO1FsfpvuOn6mo1FTLINagrlisz2Eennp/Rd6ktVxwbQMSHbu9iVaV+j78U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620757213398108.03195581194166; Tue, 11 May 2021 11:20:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125965.237144 (Exim 4.92) (envelope-from ) id 1lgWzC-00012t-4D; Tue, 11 May 2021 18:20:02 +0000 Received: by outflank-mailman (output) from mailman id 125965.237144; Tue, 11 May 2021 18:20:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lgWzC-00012K-0V; Tue, 11 May 2021 18:20:02 +0000 Received: by outflank-mailman (input) for mailman id 125965; Tue, 11 May 2021 18:20:01 +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.92) (envelope-from ) id 1lgWzB-0007fz-5W for xen-devel@lists.xenproject.org; Tue, 11 May 2021 18:20:01 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 44ad55f2-40e0-4b29-b73e-727bf73df6b9; Tue, 11 May 2021 18:19:53 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 44ad55f2-40e0-4b29-b73e-727bf73df6b9 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620757193; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wH4ZTnWLfQtQSCRp1fYnZ6Grjr9l6Pd0afiHDgqCHrM=; b=GI+dBNyrMhpKjrIqNEqrrLHSe3SoWGBQpwX7ANSAKpVGcn8VwTlcmEq+ jsvTdMY5gXj3aOWIek1WTxt0oZ5DeczAyXC4e/AjZOqD8itfFk9RBqlV1 C3ii+Nt3HCCLVJxS+LGjsJ5o0Q9OxJOhSXz9MiArhzj0WmfXUz4fvG5yR U=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: 5dqYvYo9PE6bRcChvJHKFrOgutPz93AFiuEpLzhFm+/o8GJC64ivIpxv1XHEhD6rJzTgW92JBD YUgSM6VQ1YfKywzksLHNpmIoaJMQZRaRM95+yvQLvMWVN/oPwS7l+0HICLYKKOdw05jra/1oDC Y4R0miiMfKxRECU4tfIcMCu82t/6bUVbHmidc5XljLdtiBewFmG2gVH2uuLimICTTpcPrAgehU 1FSk4Xl+JCPWgTeVjgsrGOblx4+ld7XKXWT7RxBZRoTZjScQbSdrBvFZPijKNqhdFZZHkZ+YoC prU= X-SBRS: 5.1 X-MesageID: 43562377 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:cDkGHakVqebc6LuaNIr1rdhr2xrpDfLo3DAbv31ZSRFFG/Fw9/ rCoB17726QtN91YhsdcL+7V5VoLUmzyXcX2/hyAV7BZmnbUQKTRekP0WKL+Vbd8kbFh41gPM lbEpSXCLfLfCJHZcSR2njELz73quP3jJxBho3lvghQpRkBUdAF0+/gYDzranGfQmN9dP0EPa vZ3OVrjRy6d08aa8yqb0N1JNQq97Xw5fTbiQdtPW9f1DWz X-IronPort-AV: E=Sophos;i="5.82,291,1613451600"; d="scan'208";a="43562377" From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= To: CC: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , "Christian Lindig" , David Scott , "Ian Jackson" , Wei Liu Subject: [PATCH v2 10/17] tools/ocaml/libs/mmap: allocate correct number of bytes Date: Tue, 11 May 2021 19:05:23 +0100 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) OCaml memory allocation functions use words as units, unless explicitly documented otherwise. Thus we were allocating more memory than necessary, caml_alloc should've been called with the parameter '2', but was called with a lot more. To account for future changes in the struct keep using sizeof, but round up and convert to number of words. For OCaml 1 word =3D sizeof(value) The Wsize_bsize macro converts bytes to words. Signed-off-by: Edwin T=C3=B6r=C3=B6k --- tools/ocaml/libs/mmap/xenmmap_stubs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/ocaml/libs/mmap/xenmmap_stubs.c b/tools/ocaml/libs/mmap/= xenmmap_stubs.c index b811990a89..4d09c5a6e6 100644 --- a/tools/ocaml/libs/mmap/xenmmap_stubs.c +++ b/tools/ocaml/libs/mmap/xenmmap_stubs.c @@ -28,6 +28,8 @@ #include #include =20 +#define Wsize_bsize_round(n) (Wsize_bsize( (n) + sizeof(value) - 1 )) + static int mmap_interface_init(struct mmap_interface *intf, int fd, int pflag, int mflag, int len, int offset) @@ -57,7 +59,7 @@ CAMLprim value stub_mmap_init(value fd, value pflag, valu= e mflag, default: caml_invalid_argument("maptype"); } =20 - result =3D caml_alloc(sizeof(struct mmap_interface), Abstract_tag); + result =3D caml_alloc(Wsize_bsize_round(sizeof(struct mmap_interface)), A= bstract_tag); =20 if (mmap_interface_init(Intf_val(result), Int_val(fd), c_pflag, c_mflag, --=20 2.25.1