From: Ian Campbell Subject: Re: [PATCH 11/28] libxl: ocaml: propagate the libxl return error code in exceptions Date: Thu, 11 Apr 2013 12:33:14 +0100 Message-ID: <1365679994.8036.88.camel@zakaz.uk.xensource.com> References: <1364222729-6982-1-git-send-email-rob.hoes@citrix.com> <1364222729-6982-12-git-send-email-rob.hoes@citrix.com> <5151879B.2070804@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <5151879B.2070804@eu.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: Dave Scott Cc: Rob Hoes , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On Tue, 2013-03-26 at 11:33 +0000, Dave Scott wrote: > On 25/03/13 14:45, Rob Hoes wrote: > > +static void failwith_xl(int error, char *fname) > > +{ > > + CAMLlocal1(arg); > > value *exc = caml_named_value("Xenlight.Error"); > > + > > if (!exc) > > caml_invalid_argument("Exception Xenlight.Error not initialized, please link xl.cma"); > > - caml_raise_with_string(*exc, fname); > > + > > + arg = caml_alloc_small(2, 0); > > + > > + Field(arg, 0) = Val_error(error); > > + Field(arg, 1) = caml_copy_string(fname); > > I think this violates Rule 5 in the OCaml FFI manual[*]. In the > low-level interface when you allocate a block with "caml_alloc_small" > all the fields contain random values. The assignment: > > Field(arg, 1) = caml_copy_string(fname); > > will first call "caml_copy_string" which performs an allocation before > setting the field to a valid value. Any function which performs an > allocation can trigger a GC which will segfault if it sees the random > data in field 1. I think this answers my earlier query on another patch about the redundant looking store to Field ... Ian.