]> xenbits.xensource.com Git - people/liuw/xtf.git/commitdiff
Introduce zeroptr[] for accessing virtual address 0
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 25 Jul 2016 15:29:03 +0000 (16:29 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 25 Jul 2016 15:29:03 +0000 (16:29 +0100)
There are some times when access to 0 is really needed.  Use the linker to
work around NULL pointer logic in the compiler.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/link.lds.S
include/xtf/types.h

index 4461fe7cec346d6d0521ff4dbfd6968d6ddd8de4..8828e5fbfa5102d83844c0f5ac199cea58de341d 100644 (file)
@@ -54,6 +54,12 @@ SECTIONS
         }
 }
 
+/*
+ * Linker games to use virtual addresses at 0 without triggering NULL pointer
+ * "logic" and associated compiler optimisations.
+ */
+zeroptr = 0;
+
 ASSERT(IS_ALIGNED(hypercall_page, PAGE_SIZE), "hypercall_page misaligned");
 ASSERT(IS_ALIGNED(boot_stack, PAGE_SIZE), "boot_stack misaligned");
 
index e622f6d8f711aa35a702bb9f1ece0643aa887256..4b827c2df8a826956f4e3a0e6e9ddf431fbbfd7f 100644 (file)
@@ -1,3 +1,8 @@
+/**
+ * @file include/xtf/types.h
+ *
+ * Common declarations for all tests.
+ */
 #ifndef XTF_TYPES_H
 #define XTF_TYPES_H
 
@@ -9,6 +14,14 @@
 #include <stddef.h>
 #include <inttypes.h>
 
+/**
+ * An array which the linker resolves to 0.
+ *
+ * For use instead of NULL when access to 0 is really needed, without
+ * triggering NULL pointer logic in the compiler.
+ */
+extern char zeroptr[];
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* XTF_TYPES_H */