Bug 1660755 [wpt PR 25207] - [scroll-animations] Allow null source in ScrollTimeline...
[gecko.git] / ipc / glue / SharedMemory_posix.cpp
blobb540d987f3045b5c3c9d8b285f580405b904ac03
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 namespace mozilla {
13 namespace ipc {
15 void SharedMemory::SystemProtect(char* aAddr, size_t aSize, int aRights) {
16 if (!SystemProtectFallible(aAddr, aSize, aRights)) {
17 MOZ_CRASH("can't mprotect()");
21 bool SharedMemory::SystemProtectFallible(char* aAddr, size_t aSize,
22 int aRights) {
23 int flags = 0;
24 if (aRights & RightsRead) flags |= PROT_READ;
25 if (aRights & RightsWrite) flags |= PROT_WRITE;
26 if (RightsNone == aRights) flags = PROT_NONE;
28 return 0 == mprotect(aAddr, aSize, flags);
31 size_t SharedMemory::SystemPageSize() { return sysconf(_SC_PAGESIZE); }
33 } // namespace ipc
34 } // namespace mozilla