[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



>>> On 17.05.19 at 13:25, <viktor.mitin.19@xxxxxxxxx> wrote:
> 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.

I don't think so - as per my reading of the standard text, UB
results only when the shift count is greater or equal than the
width of the (promoted) shifted value's type. The results of
both shifts above are implementation defined afaict.

> Could you please describe what is the reason for this casting?

Well, we want to check that the top 17 bits are either all 1s
or all 0s, preferably with just a single comparison.

Jan



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