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

[Xen-changelog] [xen master] x86/mm: avoid undefined behavior in IS_NIL()



commit 50ae2d0cb625a5c122f27ee69fc2f81479eee33e
Author:     Xi Wang <xi@xxxxxxx>
AuthorDate: Fri Mar 15 10:26:17 2013 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Fri Mar 15 10:26:17 2013 +0100

    x86/mm: avoid undefined behavior in IS_NIL()
    
    Since pointer overflow is undefined behavior in C, some compilers such
    as clang optimize away the check !((ptr) + 1) in the macro IS_NIL().
    
    This patch fixes the issue by casting the pointer type to uintptr_t,
    the operations of which are well-defined.
    
    Signed-off-by: Xi Wang <xi@xxxxxxx>
    
    With that, we also need to avoid the overflow in NIL().
    
    Note that either part of the change results in the respective macros to
    become unsuitable for use with "void".
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/include/asm-x86/mm.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index fd9d654..41d3209 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -573,8 +573,8 @@ int donate_page(
 
 int map_ldt_shadow_page(unsigned int);
 
-#define NIL(type) ((type *)NULL - 1)
-#define IS_NIL(ptr) (!((ptr) + 1))
+#define NIL(type) ((type *)-sizeof(type))
+#define IS_NIL(ptr) (!((uintptr_t)(ptr) + sizeof(*(ptr))))
 
 int create_perdomain_mapping(struct domain *, unsigned long va,
                              unsigned int nr, l1_pgentry_t **,
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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