caml_alloc() takes units of Wsize (word size), not bytes. As a consequence,
we're allocating 4 or 8 times too much memory.
Ocaml has a helper, Wsize_bsize(), but it truncates cases which aren't an
exact multiple. Use a BUILD_BUG_ON() to cover the potential for truncation,
as there's no rounding-up form of the helper.
Fixes: 8b7ce06a2d34 ("ocaml: Add XC bindings.")
Fixes: d3e649277a13 ("ocaml: add mmap bindings implementation.")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
XEN_ROOT=$(OCAML_TOPLEVEL)/../..
include $(OCAML_TOPLEVEL)/common.make
+CFLAGS += $(CFLAGS_xeninclude)
+
OBJS = xenmmap
INTF = $(foreach obj, $(OBJS),$(obj).cmi)
LIBS = xenmmap.cma xenmmap.cmxa
#include <errno.h>
#include "mmap_stubs.h"
+#include <xen-tools/libs.h>
+
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
default: caml_invalid_argument("maptype");
}
- result = caml_alloc(sizeof(struct mmap_interface), Abstract_tag);
+ BUILD_BUG_ON((sizeof(struct mmap_interface) % sizeof(value)) != 0);
+ result = caml_alloc(Wsize_bsize(sizeof(struct mmap_interface)),
+ Abstract_tag);
if (mmap_interface_init(Intf_val(result), Int_val(fd),
c_pflag, c_mflag,
uint32_t c_dom;
unsigned long c_mfn;
- result = caml_alloc(sizeof(struct mmap_interface), Abstract_tag);
+ BUILD_BUG_ON((sizeof(struct mmap_interface) % sizeof(value)) != 0);
+ result = caml_alloc(Wsize_bsize(sizeof(struct mmap_interface)),
+ Abstract_tag);
+
intf = (struct mmap_interface *) result;
intf->len = Int_val(size);