]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Introduce addr_t for linear addresses in hardware registers/datastructrues devel-misc
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 13 May 2019 10:26:22 +0000 (10:26 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 13 Sep 2024 17:55:12 +0000 (18:55 +0100)
Update write_dr[0-3]() to use the new functionality, and drop the casts at the
callsites.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Doxyfile
arch/x86/include/arch/x86-dbg-reg.h
include/xtf/compiler.h
include/xtf/types.h
tests/debug-regs/main.c
tests/xsa-260/main.c
tests/xsa-265/main.c

index f63d04f51355beafc2e9214a99898451e69d2d78..3427804d27573c55443f459984a2b242379c0725 100644 (file)
--- a/Doxyfile
+++ b/Doxyfile
@@ -2262,6 +2262,7 @@ PREDEFINED             = __alias(x)= \
                          __maybe_unused \
                          __noinline \
                          __noreturn \
+                         __transparent \
                          __used \
                          __user_data \
                          __user_page_aligned_bss \
index b70185dd2dc26293ecaa4c642eaee2ab8ecdad54..1353ea8dee7b039cb5f62ff299aab1a442661923 100644 (file)
@@ -108,9 +108,9 @@ static inline unsigned long read_dr0(void)
     return val;
 }
 
-static inline void write_dr0(unsigned long linear)
+static inline void write_dr0(addr_t linear)
 {
-    asm volatile ("mov %0, %%dr0" :: "r" (linear));
+    asm volatile ("mov %0, %%dr0" :: "r" (linear.val));
 }
 
 static inline unsigned long read_dr1(void)
@@ -122,9 +122,9 @@ static inline unsigned long read_dr1(void)
     return val;
 }
 
-static inline void write_dr1(unsigned long linear)
+static inline void write_dr1(addr_t linear)
 {
-    asm volatile ("mov %0, %%dr1" :: "r" (linear));
+    asm volatile ("mov %0, %%dr1" :: "r" (linear.val));
 }
 
 static inline unsigned long read_dr2(void)
@@ -136,9 +136,9 @@ static inline unsigned long read_dr2(void)
     return val;
 }
 
-static inline void write_dr2(unsigned long linear)
+static inline void write_dr2(addr_t linear)
 {
-    asm volatile ("mov %0, %%dr2" :: "r" (linear));
+    asm volatile ("mov %0, %%dr2" :: "r" (linear.val));
 }
 
 static inline unsigned long read_dr3(void)
@@ -150,9 +150,9 @@ static inline unsigned long read_dr3(void)
     return val;
 }
 
-static inline void write_dr3(unsigned long linear)
+static inline void write_dr3(addr_t linear)
 {
-    asm volatile ("mov %0, %%dr3" :: "r" (linear));
+    asm volatile ("mov %0, %%dr3" :: "r" (linear.val));
 }
 
 static inline unsigned long read_dr6(void)
index 19d93492eadfed917392f1cc0a93f35a5ae241fc..1c24d9bce7fb441f20ff43914967497be6bdfaa4 100644 (file)
@@ -11,6 +11,7 @@
 #define __packed              __attribute__((__packed__))
 #define __printf(f, v)        __attribute__((__format__(__printf__, f, v)))
 #define __maybe_unused        __attribute__((__unused__))
+#define __transparent         __attribute__((__transparent_union__))
 #define __used                __attribute__((__used__))
 #define __weak                __attribute__((__weak__))
 
index a2ab15e4ade81ae3273e9ab01e4409cea194002b..a4c46b4022a0c02b34762614d820f2d397e8fd6f 100644 (file)
  */
 extern char zeroptr[];
 
+/**
+ * Type (ab)use for helpers which take a linear address, and would like to
+ * accept it in either pointer or integer form.
+ *
+ * Useful for programming hardware registers and datastructures to point to a
+ * specific C object/function, given the flat memory layout.
+ */
+typedef union {
+    unsigned long val;
+    void *ptr;
+} __attribute__((__transparent_union__)) addr_t;
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* XTF_TYPES_H */
index 5e5cd842648085b4b1b35a9b03778aa8a248aaf4..d4b794a8032035573524341824b4ff4d5ec554ba 100644 (file)
@@ -99,7 +99,7 @@ static void test_pv_dr7_latch(void)
     write_dr7(0);
 
     /* Point %dr0 at dummy, %dr7 set with %dr0 enabled. */
-    write_dr0(_u(&dummy));
+    write_dr0(&dummy);
     dr7 = X86_DR7_GE | DR7_SYM(0, G, RW, 32);
 
     /*
index cdf5274dd5c80b5cf3562c7dbeb4e7e0bd480008..d0d480cb33cea5647035076a6f0640c70cf458ed 100644 (file)
@@ -140,7 +140,7 @@ void test_main(void)
 {
     unsigned int ss = read_ss();
 
-    write_dr0(_u(&ss));
+    write_dr0(&ss);
 
     unsigned long dr7 = DR7_SYM(0, L, G, RW, 32) | X86_DR7_LE | X86_DR7_GE;
 
@@ -162,7 +162,7 @@ void test_main(void)
                          exp, _p(exp), fault, _p(fault));
 
     /* Prime the user code for its exploit attempt. */
-    write_dr0(_u(&user_ss));
+    write_dr0(&user_ss);
 
     printk("Testing native syscall\n");
     exec_user_void(user_syscall);
index 2bb5f5c61de12107ac69703e176340029ec21542..1bb1609980d8983b434a30d43fe64c4bdd18907b 100644 (file)
@@ -31,7 +31,7 @@ void test_main(void)
     write_dr6(X86_DR6_BD);
 
     /* Data breakpoint for `ss`, working around Xen's %dr7 latching bug. */
-    write_dr0(_u(&ss));
+    write_dr0(&ss);
     write_dr7(dr7);
     write_dr7(dr7);