1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include <sys/mman.h> // mprotect
8 #include <unistd.h> // sysconf
10 #include "mozilla/ipc/SharedMemory.h"
12 #if defined(XP_MACOSX) && defined(__x86_64__)
19 #if defined(XP_MACOSX) && defined(__x86_64__)
20 std::atomic
<size_t> sPageSizeOverride
= 0;
23 void SharedMemory::SystemProtect(char* aAddr
, size_t aSize
, int aRights
) {
24 if (!SystemProtectFallible(aAddr
, aSize
, aRights
)) {
25 MOZ_CRASH("can't mprotect()");
29 bool SharedMemory::SystemProtectFallible(char* aAddr
, size_t aSize
,
32 if (aRights
& RightsRead
) flags
|= PROT_READ
;
33 if (aRights
& RightsWrite
) flags
|= PROT_WRITE
;
34 if (RightsNone
== aRights
) flags
= PROT_NONE
;
36 return 0 == mprotect(aAddr
, aSize
, flags
);
39 size_t SharedMemory::SystemPageSize() {
40 #if defined(XP_MACOSX) && defined(__x86_64__)
41 if (sPageSizeOverride
== 0) {
42 if (PR_GetEnv("MOZ_SHMEM_PAGESIZE_16K")) {
43 sPageSizeOverride
= 16 * 1024;
45 sPageSizeOverride
= sysconf(_SC_PAGESIZE
);
48 return sPageSizeOverride
;
50 return sysconf(_SC_PAGESIZE
);
55 } // namespace mozilla