Bug 1450793 - Don't assume 4k page size r=glandium
authorJames Willcox <snorp@snorp.net>
Wed, 11 Apr 2018 21:34:16 -0500
changeset 413233 e73f2e16ec4195375a293f7361a6ff972ff89f21
parent 413232 e5336e51b77f8d95a51eae13ff5f8676d3886083
child 413234 c06258f53c2c476ba35b51b7ab06b105f8d4102b
push id33840
push userapavel@mozilla.com
push dateFri, 13 Apr 2018 21:56:54 +0000
treeherdermozilla-central@6547c27303bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1450793
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1450793 - Don't assume 4k page size r=glandium MozReview-Commit-ID: DWSIUOFfKW5
mozglue/linker/ElfLoader.cpp
mozglue/linker/Utils.h
--- a/mozglue/linker/ElfLoader.cpp
+++ b/mozglue/linker/ElfLoader.cpp
@@ -11,18 +11,24 @@
 #include <errno.h>
 #include <algorithm>
 #include <fcntl.h>
 #include "ElfLoader.h"
 #include "BaseElf.h"
 #include "CustomElf.h"
 #include "Mappable.h"
 #include "Logging.h"
+#include "Utils.h"
 #include <inttypes.h>
 
+using namespace mozilla;
+
+// From Utils.h
+Atomic<size_t, ReleaseAcquire> gPageSize;
+
 #if defined(ANDROID)
 #include <sys/syscall.h>
 #include <math.h>
 
 #include <android/api-level.h>
 #if __ANDROID_API__ < 8
 /* Android API < 8 doesn't provide sigaltstack */
 
@@ -46,17 +52,16 @@ extern "C" MOZ_EXPORT const void *
  * reference. */
 extern "C" MOZ_EXPORT int
 dl_iterate_phdr(dl_phdr_cb callback, void *data) __attribute__((weak));
 
 /* Pointer to the PT_DYNAMIC section of the executable or library
  * containing this code. */
 extern "C" Elf::Dyn _DYNAMIC[];
 
-using namespace mozilla;
 
 /**
  * dlfcn.h replacements functions
  */
 
 void *
 __wrap_dlopen(const char *path, int flags)
 {
--- 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, mozilla::ReleaseAcquire> 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>