Files
palemoon27/toolkit/devtools/server/AutoMemMap.h
T
roytam1 6885f7ffc2 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1185749 - Implement a DynamicTraceable HashMap subclass that can be used with Rooted; r=jonco (3f84bdb30)
- Bug 1186609 - Implement a DynamicTraceable Vector subclass for use with Rooted; r=sfink (fa5b47e5b)
- Bug 1155985 - Set FieldInto::mType just before storing to reserved slot. r=jonco, a=abillings (34dbc3ca0)
- Bug 1156295 - Refactor GC rooting in StructType::DefineInternal() r=terrence (ec40a1701)
- Bug 1185755 - Use Rooted to simplify FieldInfoHash rooting; r=jonco (8dc66d7cd)
- Bug 1189072 - Make DefaultTracer for struct types call T::trace; r=fitzgen (96f79bc6f)
- Bug 1149294 - Part 1: Don't trace permanent atoms and well known symbols that are owned by a parent JSRuntime inside SimpeEdgeVectorTracer; r=terrence (7ce049a33)
- Bug 1149294 - Part 2: expose ChromeUtils and HeapSnapshot to workers; r=bholley (5737cd923)
- Bug 1147679 - Use PR_GetFileInfo64 when deserializing heap snapshots; r=jimb (1ce8cd241)
- Bug 1147680 - Use PR_MemMap when deserializing heap snapshots; r=jimb (04e5a370d)
- Bug 1149294 - Part 3: Split thread-safe methods on ChromeUtils out in to a new (4967637e2)
- Bug 1173829. Fix some compile issues in code generated by bindings codegen for non-concrete interfaces. r=peterv (3e0f93640)
- Bug 1170274 - A better string parser for nsGenericHTMLElement::GetURIListAttr, r=ehsan (8c1595d29)
- Bug 1170274 - patch 2 - A better string parser for nsGenericHTMLElement::GetURIListAttr, r=ehsan CLOSED TREE (5626d631f)
- Bug 1096550 - Update content scale when swapping remote tabs between windows. r=roc. (ed974edf4)
- Bug 1180017: Give GCCellPtr is<T> and as<T> methods, replacing isFoo and toFoo methods. Fix callers. r=terrence (b95645bbb)
- pointer style (a46b905fe)
- pointer style (cb548fd44)
- Bug 1151182 - Fix type for JSOP_THROWMSG documentation comment. r=efaust (f9bce9df7)
- Bug 1077318 - Part 2: Fix the order of include in AsmJSModule.cpp. r=evilpie (a61716e33)
- Bug 1155006: Fix unified build sensitivities in js/src. r=shu (b0f166ec9)
- Bug 988463 - Add in support for tracelogging on ARM. r=h4writer (10345729b)
- Bug 1190077 - Move RDTSC and prmjtime.* to vm/Time.*. r=nbp (b72c1f366)
2021-04-27 09:19:42 +08:00

71 lines
2.0 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 <prio.h>
#include "mozilla/GuardObjects.h"
namespace mozilla {
namespace devtools {
// # AutoMemMap
//
// AutoMemMap is an RAII class to manage mapping a file to memory. It is a
// wrapper aorund managing opening and closing a file and calling PR_MemMap and
// PR_MemUnmap.
//
// Example usage:
//
// {
// AutoMemMap mm;
// if (NS_FAILED(mm.init("/path/to/desired/file"))) {
// // Handle the error however you see fit.
// return false;
// }
//
// doStuffWithMappedMemory(mm.address());
// }
// // The memory is automatically unmapped when the AutoMemMap leaves scope.
class MOZ_STACK_CLASS AutoMemMap
{
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER;
PRFileInfo64 fileInfo;
PRFileDesc* fd;
PRFileMap* fileMap;
void* addr;
AutoMemMap(const AutoMemMap& aOther) = delete;
void operator=(const AutoMemMap& aOther) = delete;
public:
explicit AutoMemMap(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM)
: fd(nullptr)
, fileMap(nullptr)
, addr(nullptr)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
};
~AutoMemMap();
// Initialize this AutoMemMap.
nsresult init(const char* filePath, PRIntn flags = PR_RDONLY, PRIntn mode = 0,
PRFileMapProtect prot = PR_PROT_READONLY);
// Get the size of the memory mapped file.
uint32_t size() const {
MOZ_ASSERT(fileInfo.size <= UINT32_MAX,
"Should only call size() if init() succeeded.");
return uint32_t(fileInfo.size);
}
// Get the mapped memory.
void* address() { MOZ_ASSERT(addr); return addr; }
const void* address() const { MOZ_ASSERT(addr); return addr; }
};
} // namespace devtools
} // namespace mozilla