From: Ian Campbell Subject: Re: [PATCH v6 08/12] libxl: ocaml: drop the ocaml heap lock before calling into libxl Date: Mon, 2 Dec 2013 12:05:32 +0000 Message-ID: <1385985932.7108.60.camel@kazak.uk.xensource.com> References: <1385507713-347-1-git-send-email-rob.hoes@citrix.com> <21143.29030.825290.256212@mariner.uk.xensource.com> <360717C0B01E6345BCBE64B758E22C2D1997FE@AMSPEX01CL03.citrite.net> <21143.34627.123297.562064@mariner.uk.xensource.com> <1385714393.23632.26.camel@dagon.hellion.org.uk> <1385722101.25763.10.camel@kazak.uk.xensource.com> <7D79EEB1-417B-447C-B5B5-DC90949D2978@citrix.com> <1385978138.7108.16.camel@kazak.uk.xensource.com> <360717C0B01E6345BCBE64B758E22C2D19EF94@AMSPEX01CL03.citrite.net> <1385985178.7108.54.camel@kazak.uk.xensource.com> <360717C0B01E6345BCBE64B758E22C2D19F018@AMSPEX01CL03.citrite.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <360717C0B01E6345BCBE64B758E22C2D19F018@AMSPEX01CL03.citrite.net> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Rob Hoes Cc: Ian Jackson , Dave Scott , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org 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. Ian. > > > > > > > > Otherwise you need to build some sort of C-side data structure to > > > > hold all the various values, which is doable but a bit tedious I > > imagine. > > > > > > I think we can malloc a new "value" (pointer to ocaml heap), make it > > > equal to the for_callback value, register this with the GC (so it can > > > update this heap pointer when the actual value moves), and give a > > > pointer to it to libxl. And then of course deregister and free before > > > we give it back to ocaml. > > > > I think this (moving the heap pointer from the GC) would require the > > prototype to be "value **" not "value *". > > > > Ian. >