From: Jean Guyader Subject: Re: [PATCH 4/5] xen: Enforce casting for guest_handle_cast Date: Thu, 14 Jun 2012 22:19:44 +0100 Message-ID: <20120614211943.GC27011@boiler.cam.xci-test.com> References: <1338476832-26653-1-git-send-email-jean.guyader@citrix.com> <1338476832-26653-5-git-send-email-jean.guyader@citrix.com> <4FC7AEBD020000780008774C@nat28.tlf.novell.com> <20120614140815.GB22025@spongy> <20120614142614.GE90181@ocelot.phlegethon.org> <20120614142751.GF90181@ocelot.phlegethon.org> <20120614144008.GA24063@spongy> <20120614153913.GC24063@spongy> <4FDA26A8020000780008A100@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <4FDA26A8020000780008A100@nat28.tlf.novell.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: Jan Beulich Cc: "Tim (Xen.org)" , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On 14/06 05:00, Jan Beulich wrote: > >>> On 14.06.12 at 17:39, Jean Guyader wrote: > > Here are the structs: > > > > typedef struct v4v_ring_data_ent > > { > > struct v4v_addr ring; > > uint16_t flags; > > uint16_t pad0; > > uint32_t space_required; > > uint32_t max_message_size; > > } v4v_ring_data_ent_t; > > DEFINE_XEN_GUEST_HANDLE (v4v_ring_data_ent_t); > > > > typedef struct v4v_ring_data > > { > > uint64_t magic; > > uint32_t nent; > > uint32_t padding; > > uint64_t reserved[4]; > > v4v_ring_data_ent_t ring[0]; > > } v4v_ring_data_t; > > DEFINE_XEN_GUEST_HANDLE (v4v_ring_data_t); > > > > I get a XEN_GUEST_HANDLE(v4v_ring_data_t) as argument of my hypercall and I > > would like to access the ring data inside it which is a XEN_GUEST_HANDLE as well. > > > > Here is the code that I use for doing that (with explicte cast in > > guest_handle_cast): > > XEN_GUEST_HANDLE (v4v_ring_data_ent_t) ring_data_ent_hnd; > > XEN_GUEST_HANDLE (uint8_t) slop_hnd = > > guest_handle_cast (ring_data_hnd, uint8_t); > > guest_handle_add_offset (slop_hnd, sizeof (v4v_ring_data_t)); > > ring_data_ent_hnd = > > guest_handle_cast (slop_hnd, v4v_ring_data_ent_t); > > ret = v4v_fill_ring_datas (d, ring_data.nent, ring_data_ent_hnd); > > So you really don't want to add anything (as not being type-safe), > but instead want to get a guest handle representation for accessing > the ring[0] member. That is, I'd introduce a guest_handle_for_field() > for this purpose. Let me see whether I can put something together > for you early next week. > Thanks but I'll follow Tim's advice and get rid of the wrapper structure. I still think having some macro to get a handle from a field can be quite useful in general. Jean