Bug 1891340 - Part 1: Add parameters to customize the before and after icon tints...
[gecko.git] / ipc / glue / SharedMemory_posix.cpp
blobb634058945a7023df4424461680aae9361ab5582
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__)
13 # include "prenv.h"
14 #endif
16 namespace mozilla {
17 namespace ipc {
19 #if defined(XP_MACOSX) && defined(__x86_64__)
20 std::atomic<size_t> sPageSizeOverride = 0;
21 #endif
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,
30 int aRights) {
31 int flags = 0;
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;
44 } else {
45 sPageSizeOverride = sysconf(_SC_PAGESIZE);
48 return sPageSizeOverride;
49 #else
50 return sysconf(_SC_PAGESIZE);
51 #endif
54 } // namespace ipc
55 } // namespace mozilla