From: Rob Hoes Subject: [PATCH 2/3] libxl: ocaml: use int64 for timeval fields in the timeout_register callback Date: Thu, 12 Dec 2013 16:36:50 +0000 Message-ID: <1386866211-12639-3-git-send-email-rob.hoes@citrix.com> References: <1386866211-12639-1-git-send-email-rob.hoes@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1386866211-12639-1-git-send-email-rob.hoes@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Rob Hoes , ian.jackson@eu.citrix.com, ian.campbell@citrix.com, dave.scott@eu.citrix.com List-Id: xen-devel@lists.xenproject.org The original code works fine on 64-bit, but on 32-bit, the OCaml int (which is 1 bit smaller than the C int) is likely to overflow. Signed-off-by: Rob Hoes --- tools/ocaml/libs/xl/xenlight.mli.in | 2 +- tools/ocaml/libs/xl/xenlight_stubs.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/ocaml/libs/xl/xenlight.mli.in b/tools/ocaml/libs/xl/xenlight.mli.in index 794dbf1..b9819e1 100644 --- a/tools/ocaml/libs/xl/xenlight.mli.in +++ b/tools/ocaml/libs/xl/xenlight.mli.in @@ -71,7 +71,7 @@ module Async : sig fd_register:('a -> Unix.file_descr -> event list -> for_libxl -> unit) -> fd_modify:('a -> Unix.file_descr -> event list -> unit) -> fd_deregister:('a -> Unix.file_descr -> unit) -> - timeout_register:('a -> int -> int -> for_libxl -> unit) -> + timeout_register:('a -> int64 -> int64 -> for_libxl -> unit) -> timeout_modify:('a -> unit) -> osevent_hooks diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c index a61c222..2e2606a 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -1286,6 +1286,7 @@ int timeout_register(void *user, void **for_app_registration_out, { caml_leave_blocking_section(); CAMLparam0(); + CAMLlocal2(sec, usec); CAMLlocalN(args, 4); static value *func = NULL; value *p = (value *) user; @@ -1295,9 +1296,12 @@ int timeout_register(void *user, void **for_app_registration_out, func = caml_named_value("libxl_timeout_register"); } + sec = caml_copy_int64(abs.tv_sec); + usec = caml_copy_int64(abs.tv_usec); + args[0] = *p; - args[1] = Val_int(abs.tv_sec); - args[2] = Val_int(abs.tv_usec); + args[1] = sec; + args[2] = usec; args[3] = (value) for_libxl; caml_callbackN(*func, 4, args); -- 1.7.10.4