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

Re: [Xen-devel] libxc: Casting of xen virtual address type xen_vaddr_t to signed int64 type: (int64_t)vaddr



(Apologies for the use of outlook - I'm having email problems atm).

A canonical address in x86 is one which is correctly sign extended from bit 47 
to bit 63.

What is undefined about shifting int64_t by 63 bits?  The answer is -1 or 0, 
preserving the sign bit alone (which is the point of the comparison).

~Andrew
________________________________________
From: Viktor Mitin <viktor.mitin.19@xxxxxxxxx>
Sent: 17 May 2019 12:25
To: Juergen Gross; Andrew Cooper; Wei Liu; xen-devel@xxxxxxxxxxxxxxxxxxxx
Cc: Volodymyr Babchuk
Subject: libxc: Casting of xen virtual address type xen_vaddr_t to signed int64 
type: (int64_t)vaddr

Hi All,

While looking at code in tools/libxc/xc_sr_save_x86_pv.c,
we see that there is casting of xen virtual address type xen_vaddr_t
to signed int64 type.
In commit: 7bf74582b343603cb0826d808cd7da43326452a5

+/* Check a 64 bit virtual address for being canonical. */
+static inline bool is_canonical_address(xen_vaddr_t vaddr)
+{
+    return ((int64_t)vaddr >> 47) == ((int64_t)vaddr >> 63);
+}

It seems there is no need to cast vaddr variable. It looks like
shifting vaddr signed 64-bit value by 63 bits introduces undefined
behavior. Could you please describe what is the reason for this
casting?

Thanks

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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