Bug 1450793 - Don't assume 4k page size r=glandium
MozReview-Commit-ID: DWSIUOFfKW5
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'