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

[PATCH v2 10/17] tools/ocaml/libs/mmap: allocate correct number of bytes


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Edwin Török <edvin.torok@xxxxxxxxxx>
  • Date: Tue, 11 May 2021 19:05:23 +0100
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Edwin Török <edvin.torok@xxxxxxxxxx>, "Christian Lindig" <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, "Ian Jackson" <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 11 May 2021 18:20:02 +0000
  • Ironport-hdrordr: A9a23:cDkGHakVqebc6LuaNIr1rdhr2xrpDfLo3DAbv31ZSRFFG/Fw9/ rCoB17726QtN91YhsdcL+7V5VoLUmzyXcX2/hyAV7BZmnbUQKTRekP0WKL+Vbd8kbFh41gPM lbEpSXCLfLfCJHZcSR2njELz73quP3jJxBho3lvghQpRkBUdAF0+/gYDzranGfQmN9dP0EPa vZ3OVrjRy6d08aa8yqb0N1JNQq97Xw5fTbiQdtPW9f1DWz
  • Ironport-sdr: 5dqYvYo9PE6bRcChvJHKFrOgutPz93AFiuEpLzhFm+/o8GJC64ivIpxv1XHEhD6rJzTgW92JBD YUgSM6VQ1YfKywzksLHNpmIoaJMQZRaRM95+yvQLvMWVN/oPwS7l+0HICLYKKOdw05jra/1oDC Y4R0miiMfKxRECU4tfIcMCu82t/6bUVbHmidc5XljLdtiBewFmG2gVH2uuLimICTTpcPrAgehU 1FSk4Xl+JCPWgTeVjgsrGOblx4+ld7XKXWT7RxBZRoTZjScQbSdrBvFZPijKNqhdFZZHkZ+YoC prU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 = sizeof(value)

The Wsize_bsize macro converts bytes to words.

Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>
---
 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 <caml/fail.h>
 #include <caml/callback.h>
 
+#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, value 
mflag,
        default: caml_invalid_argument("maptype");
        }
 
-       result = caml_alloc(sizeof(struct mmap_interface), Abstract_tag);
+       result = caml_alloc(Wsize_bsize_round(sizeof(struct mmap_interface)), 
Abstract_tag);
 
        if (mmap_interface_init(Intf_val(result), Int_val(fd),
                                c_pflag, c_mflag,
-- 
2.25.1




 


Rackspace

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