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

Re: [Xen-devel] [PATCH v6 08/12] libxl: ocaml: drop the ocaml heap lock before calling into libxl



On Mon, 2013-12-02 at 12:11 +0000, Rob Hoes wrote:
> > On Mon, 2013-12-02 at 11:58 +0000, Rob Hoes wrote:
> > > > > > Can't you just use caml_register_global_root on the address of
> > > > > > your value for_callback? I presume you can call this
> > > > > > register/unregister pair many times (for different events etc)?
> > > > >
> > > > > I think you need to register a value, not a pointer to a value.
> > > >
> > > > CAMLextern void caml_register_global_root (value *);
> > > >
> > > > It takes a pointer to the value to register. Is there any reason why
> > > > you can't pass &for_callback given "value for_callback" in the local
> > context?
> > >
> > > I think we'd then have to rely on libxl to never copy to pointer
> > > internally, and throw away the original one. I am worried that this
> > > may happen, because the ao_how value is temporary.
> > 
> > libxl will for certain take a copy of the pointer passed into the ao_how,
> > because it stashes it for later use.
> > 
> > Either I'm very confused about what you are suggesting or pointers in C
> > don't work like you seem to think.
> > 
> > AFAICT caml_register_global_root takes a pointer to the value and locks
> > down the value itself, preventing it from moving. There is no way for it
> > to do anything else given a pointer and not a pointer to a pointer.
> 
> That's the point, I don't think that is how it works.
> 
> I think the value on the heap can still move around, but registering a 
> pointer to it as a root means that:
> 1. the value does not get dropped by the GC;
> 2. the root/pointer will be updated by the GC when the value itself moves,

There is no way this #2 can happen, the C interface takes a "value *"
and therefore is only able to update the value and not the pointer to
it.

Do you mean:
        foo(value for_callback)
        {
                value *p = malloc(SOME)
                *p = for_callback
                value pval = Val_ptr(p);
                register_global(p)
                return (something containing p)
        }
?

This would make p safe to pass to libxl, where it can copy it around to
its hearts content.

In this case the ocaml runtime can never change "p" from the point of
view of the C code in order to move it around (since p is passed by
value not reference to the registration fn). It could change *p but that
doesn't equate to moving the value around.

Maybe we've just been talking at cross purposes?

BTW I see now why
        foo(value for_callback)
        {
                register_global(&for_callback)
        }
won't work -- &for_callback is a stack address.

Ian.


_______________________________________________
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®.