From 2b7f8933bb473832c664d44c9e865e9da6331be1 Mon Sep 17 00:00:00 2001
From: Will Hawkins <whh8b@virginia.edu>
Date: Mon, 18 Jun 2018 03:47:50 +0000
Subject: [PATCH] Make a global PAGE_SIZE definition.

---
 include/zipr_all.h  | 2 ++
 include/zipr_impl.h | 1 -
 src/elfwrite.cpp    | 7 +------
 src/zipr.cpp        | 8 ++++++--
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/zipr_all.h b/include/zipr_all.h
index 8fdbe56..a47f996 100644
--- a/include/zipr_all.h
+++ b/include/zipr_all.h
@@ -49,6 +49,8 @@ namespace zipr
 
 using namespace Zipr_SDK;
 
+#define PAGE_SIZE 4096
+
 #include <sled.h>
 #include <unresolved.h>
 #include <zipr_mem_space.h>
diff --git a/include/zipr_impl.h b/include/zipr_impl.h
index 4ad2e11..a636221 100644
--- a/include/zipr_impl.h
+++ b/include/zipr_impl.h
@@ -511,7 +511,6 @@ class ZiprImpl_t : public Zipr_t
 
                 template <class T> static T page_align(const T& in)
 		{
-			const T PAGE_SIZE=4096;
 			return align_by(in,PAGE_SIZE);
 		}
                 template <class T> static T align_up_to(const T& in, const T &by)
diff --git a/src/elfwrite.cpp b/src/elfwrite.cpp
index d705eec..ac32b08 100644
--- a/src/elfwrite.cpp
+++ b/src/elfwrite.cpp
@@ -26,14 +26,9 @@ using namespace zipr;
 using namespace ELFIO;
 
 
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 4096
-#endif
-
 static inline uintptr_t page_round_up(uintptr_t x)
 {
-        const int page_size=PAGE_SIZE;
-        return  ( (((uintptr_t)(x)) + page_size-1)  & (~(page_size-1)) );
+        return  ( (((uintptr_t)(x)) + PAGE_SIZE-1)  & (~(PAGE_SIZE-1)) );
 }
 
 
diff --git a/src/zipr.cpp b/src/zipr.cpp
index 63a6308..9979b13 100644
--- a/src/zipr.cpp
+++ b/src/zipr.cpp
@@ -58,8 +58,12 @@ using namespace IRDBUtility;
 
 inline uintptr_t page_round_up(uintptr_t x)
 {
-	const int page_size=4096;
-	return  ( (((uintptr_t)(x)) + page_size-1)  & (~(page_size-1)) );
+	return  ( (((uintptr_t)(x)) + PAGE_SIZE-1)  & (~(PAGE_SIZE-1)) );
+}
+
+inline uintptr_t page_round_down(uintptr_t x)
+{
+	return  ( (((uintptr_t)(x)) - (PAGE_SIZE-1))  & (~(PAGE_SIZE-1)) );
 }
 
 int find_magic_segment_index(ELFIO::elfio *elfiop);
-- 
GitLab