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

Re: [Xen-devel] [PATCH 4/5] xen: Enforce casting for guest_handle_cast



On 18 June 2012 12:36, Jan Beulich <JBeulich@xxxxxxxx> wrote:
>>>> On 14.06.12 at 17:39, Jean Guyader <jean.guyader@xxxxxxxxxx> 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);
>
> Something as simple as
>
> #define guest_handle_for_field(hnd, type, fld) \
>    ((XEN_GUEST_HANDLE(type)) { &(hnd).p->fld })
>
> works quite fine for me is an example like
>
> int v4v_test(struct domain *d, XEN_GUEST_HANDLE(v4v_ring_data_t) urp) {
>    v4v_ring_data_t ring_data;
>    XEN_GUEST_HANDLE(v4v_ring_data_ent_t) ring_data_ent_hnd;
>
>    copy_from_guest(&ring_data, urp, 1);
>    ring_data_ent_hnd = guest_handle_for_field(urp, v4v_ring_data_ent_t, 
> ring[0]);
>    return v4v_fill_ring_datas(d, ring_data.nent, ring_data_ent_hnd);
> }
>

Thanks!
That works for me too. I'll replace the code in my patch series.

Jean

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