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

[Xen-devel] memop struct packing, 32/64 bits

  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: "Andres Lagar-Cavilla" <andres@xxxxxxxxxxxxxxxx>
  • Date: Thu, 19 Jan 2012 12:30:21 -0800
  • Cc: ian.jackson@xxxxxxxxxx, ian.campbell@xxxxxxxxxx
  • Delivery-date: Thu, 19 Jan 2012 20:30:55 +0000
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=lagarcavilla.org; h=message-id :date:subject:from:to:cc:reply-to:mime-version:content-type: content-transfer-encoding; q=dns; s=lagarcavilla.org; b=jnAmzDwj 7821WNwI0jopfu1ovYq/LFZT7k8/sqpC09yqtohH+HVz5waus7S3zS035RffYObB hnn6ueOehV69iPeQ1DsnkoIU91OO9cps4mPPr4WNRdyjCiMrZJzdXSLIepr1cqlr PW4ETOuiQLQ64j0HUa40RvYumRJv+RTNjcw=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

I had the following painful experience. I declared

struct xen_mem_event_op {
    uint8_t       op;           /* XENMEM_*_op_* */
    domid_t       domain;
    uint64_t buffer;
    uint64_t gfn;          /* IN:  gfn of page being operated on */
typedef struct xen_mem_event_op xen_mem_event_op_t;

to be passed as the argument of a memory op called form the toolstack. The
hypervisor is 64 bits and the toolstack is 32 bits. My toolstack code

    xen_mem_event_op_t meo;
... set fields ...
    return do_memory_op(xch, mode, &meo, sizeof(meo));

No joy because 32 bits was packing the struct differently than 64 bits.
Namely, both were adding a 1 byte pad between 'op' and 'domain', but when
compiled in 64 bits mode for the hypervisor, an additional 4 byte pad was
thrown between 'domain' and 'buffer'.

The first question is, what is the preferred way around this. Declare pads
inside the struct?

Exploring the include/public/memory.h declarations and toolstack code, I
see that no current declare includes __attribute__((aligned)) or
__attribute__((packed)), or explicit pads.

So how come things don't break more often for 32 bit toolstacks? pure
luck? Am I missing something?


Xen-devel mailing list



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