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

Re: [Xen-devel] [PATCH 11/28] libxl: ocaml: propagate the libxl return error code in exceptions



[...]
> > +       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 strongly recommend using the "simple interface" i.e.
> 
>    caml_alloc()
>    caml_alloc_tuple()
>    Store_field()
[...]

Damn, this stuff is trickier than it seems! :)

I'll make sure that only the "simple interface" is used in all bindings, just 
to be sure.

Cheers,
Rob

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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