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"
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
,
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
); }
34 } // namespace mozilla