Bug 1450793 - Don't assume 4k page size r=glandium draft
authorJames Willcox <snorp@snorp.net>
Wed, 11 Apr 2018 21:34:16 -0500
changeset 781061 cefa2f0064089c6d464bfe55d5d64ca6cbca1a09
parent 780837 0bb3a0f0d20b0858134569ed4af78fd4ef3aacf6
push id106196
push userbmo:snorp@snorp.net
push dateThu, 12 Apr 2018 13:31:38 +0000
reviewersglandium
bugs1450793
milestone61.0a1
Bug 1450793 - Don't assume 4k page size r=glandium MozReview-Commit-ID: DWSIUOFfKW5
mozglue/linker/Utils.cpp
mozglue/linker/Utils.h
mozglue/linker/moz.build
new file mode 100644
--- /dev/null
+++ b/mozglue/linker/Utils.cpp
@@ -0,0 +1,7 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "Utils.h"
+
+mozilla::Atomic<size_t> gPageSize;
\ No newline at end of file
--- a/mozglue/linker/Utils.h
+++ b/mozglue/linker/Utils.h
@@ -6,16 +6,17 @@
 #define Utils_h
 
 #include <pthread.h>
 #include <stdint.h>
 #include <stddef.h>
 #include <sys/mman.h>
 #include <unistd.h>
 #include "mozilla/Assertions.h"
+#include "mozilla/Atomics.h"
 #include "mozilla/Scoped.h"
 
 /**
  * On architectures that are little endian and that support unaligned reads,
  * we can use direct type, but on others, we want to have a special class
  * to handle conversion and alignment issues.
  */
 #if !defined(DEBUG) && (defined(__i386__) || defined(__x86_64__))
@@ -97,22 +98,28 @@ typedef mozilla::Scoped<AutoCloseFDTrait
 struct AutoCloseFILETraits
 {
   typedef FILE *type;
   static FILE *empty() { return nullptr; }
   static void release(FILE *f) { if (f) fclose(f); }
 };
 typedef mozilla::Scoped<AutoCloseFILETraits> AutoCloseFILE;
 
+extern mozilla::Atomic<size_t> gPageSize;
+
 /**
  * Page alignment helpers
  */
-static inline size_t PageSize()
+static size_t PageSize()
 {
-  return 4096;
+  if (!gPageSize) {
+    gPageSize = sysconf(_SC_PAGESIZE);
+  }
+
+  return gPageSize;
 }
 
 static inline uintptr_t AlignedPtr(uintptr_t ptr, size_t alignment)
 {
   return ptr & ~(alignment - 1);
 }
 
 template <typename T>
--- a/mozglue/linker/moz.build
+++ b/mozglue/linker/moz.build
@@ -4,16 +4,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 SOURCES += [
     'BaseElf.cpp',
     'CustomElf.cpp',
     'ElfLoader.cpp',
     'Mappable.cpp',
+    'Utils.cpp',
     'XZStream.cpp',
     'Zip.cpp',
 ]
 
 Library('linker')
 
 FINAL_LIBRARY = 'mozglue'