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

[Xen-devel] [PATCH RFC 2/4] xen/x86: add helper for stack guard



Instead of open coding the calculation of the stack guard page multiple
times add a helper to do the calculation.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 xen/arch/x86/mm.c        | 8 ++------
 xen/include/asm-x86/mm.h | 6 ++++++
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index a56f875d45..b60e79e82e 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -5517,16 +5517,12 @@ void memguard_unguard_range(void *p, unsigned long l)
 void memguard_guard_stack(void *p)
 {
     BUILD_BUG_ON((PRIMARY_STACK_SIZE + PAGE_SIZE) > STACK_SIZE);
-    p = (void *)((unsigned long)p + STACK_SIZE -
-                 PRIMARY_STACK_SIZE - PAGE_SIZE);
-    memguard_guard_range(p, PAGE_SIZE);
+    memguard_guard_range(memguard_get_guard_page(p), PAGE_SIZE);
 }
 
 void memguard_unguard_stack(void *p)
 {
-    p = (void *)((unsigned long)p + STACK_SIZE -
-                 PRIMARY_STACK_SIZE - PAGE_SIZE);
-    memguard_unguard_range(p, PAGE_SIZE);
+    memguard_unguard_range(memguard_get_guard_page(p), PAGE_SIZE);
 }
 
 void arch_dump_shared_mem_info(void)
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 4af6b2341a..84e112b830 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -517,6 +517,12 @@ void memguard_unguard_range(void *p, unsigned long l);
 #define memguard_unguard_range(_p,_l)  ((void)0)
 #endif
 
+static inline void *memguard_get_guard_page(void *p)
+{
+    return (void *)((unsigned long)p + STACK_SIZE -
+                    PRIMARY_STACK_SIZE - PAGE_SIZE);
+}
+
 void memguard_guard_stack(void *p);
 void memguard_unguard_stack(void *p);
 
-- 
2.13.6


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