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

Re: [Xen-devel] [PATCH v4 03/11] public: xen.h: add definitions for UUID handling



>>> On 31.08.17 at 14:24, <volodymyr_babchuk@xxxxxxxx> wrote:
> Hi Jan,
> 
> On 31.08.17 10:34, Jan Beulich wrote:
>>>>> On 30.08.17 at 18:20, <volodymyr_babchuk@xxxxxxxx> wrote:
>>> My first intention was to declare union with all possible
>>> representations, so it would be possible to access the same UUID as an
>>> array of bytes or, for example, as Microsoft GUID. Like this:
>>>
>>> typedef union {
>>>       /* UUID represented as a 128-bit object */
>>>       uint8_t obj[16];
>>>
>>>       /* Representation according to RFC 4122 */
>>>       struct {
>>>           __be32  time_low;
>>>           __be16  time_mid;
>>>           __be16  time_hi_and_version;
>>>           __u8    clock_seq_hi_and_reserved;
>>>           __u8    clock_seq_low;
>>>           __u8    node[6];
>>>       } rfc4122;
>>>
>>>       /* Microsoft/Intel style GUID representation */
>>>       struct {
>>>           __le32  Data1;
>>>           __le16  Data2;
>>>           __le16  Data3;
>>>           __u8    Data4[8];
>>>       } guid;
>>>
>>>       /* SMCCC compatible format */
>>>       struct {
>>>           __le32 r0;
>>>           __le32 r1;
>>>           __le32 r2;
>>>           __le32 r3;
>>>       } smccc;
>>> } xen_uuid_t;
>>>
>>>
>>> But looks like we can't use something like __packed or
>>> __attribute__((__packed__)) in the public header. This means that we
>>> can't rely on right overlapping and users of this union should take care
>>> to read and write only to one chosen substructure.
>> 
>> I don't see any use of that attribute in the structure definition
>> above, nor any need to add one - all fields are suitably aligned
>> anyway. You can't use __be* and __le* types in the public
>> headers, though - these will need to be uint*_t.
> This is a public header. As I understand it can be used by different 
> compilers (gcc, icc, msvc, llvm, etc...). C89 have no restrictions to 
> padding or alignment of fields in structures. No one can guarantee that
> 
> sizeof(xen_uuid_t.rfc422) == sizeof(xen_uuid_t.guid) == 
> sizeof(xen_uuid_t.smccc)  == 16
> 
> On all platforms. Using any compiler. With any compiler options.
> 
> This is implementation defined ([1]). Standard says "This should present 
> no problem unless binary data written by one implementation are read by 
> another.". But in case of public headers, this structures can be written 
> by one implementation and read by another.

My reference to C89 was to tell you what language constructs
you're allowed to use. For binary layout, conventions also
matter (like gABI and processor specific ABIs). Without that we
wouldn't be able to write any C header in compatible manner.
What helps us greatly is that we're not needing interfaces for
cross-host communication - the entire public interface assumes
that producer and consumer run on the same physical system
(or, for the parts concerning migration, on similar ones).

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

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