memory/replace/dmd/DMD.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=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 #ifndef DMD_h___
     8 #define DMD_h___
    10 #include <stdarg.h>
    11 #include <string.h>
    13 #include "mozilla/Types.h"
    15 namespace mozilla {
    16 namespace dmd {
    18 // Mark a heap block as reported by a memory reporter.
    19 MOZ_EXPORT void
    20 Report(const void* aPtr);
    22 // Mark a heap block as reported immediately on allocation.
    23 MOZ_EXPORT void
    24 ReportOnAlloc(const void* aPtr);
    26 class Writer
    27 {
    28 public:
    29   typedef void (*WriterFun)(void* aWriteState, const char* aFmt, va_list aAp);
    31   Writer(WriterFun aWriterFun, void* aWriteState)
    32     : mWriterFun(aWriterFun), mWriteState(aWriteState)
    33   {}
    35   void Write(const char* aFmt, ...) const;
    37 private:
    38   WriterFun mWriterFun;
    39   void*     mWriteState;
    40 };
    42 // Clears existing reportedness data from any prior runs of the memory
    43 // reporters.  The following sequence should be used.
    44 // - ClearReports()
    45 // - run the memory reporters
    46 // - Dump()
    47 // This sequence avoids spurious twice-reported warnings.
    48 MOZ_EXPORT void
    49 ClearReports();
    51 // Checks which heap blocks have been reported, and dumps a human-readable
    52 // summary (via |aWrite|).  If |aWrite| is nullptr it will dump to stderr.
    53 // Beware:  this output may have very long lines.
    54 MOZ_EXPORT void
    55 Dump(Writer aWriter);
    57 // A useful |WriterFun|.  If |fp| is a FILE* you want |Dump|'s output to be
    58 // written to, call:
    59 //
    60 //   dmd::Writer writer(FpWrite, fp);
    61 //   dmd::Dump(writer);
    62 MOZ_EXPORT void
    63 FpWrite(void* aFp, const char* aFmt, va_list aAp);
    65 struct Sizes
    66 {
    67   size_t mStackTracesUsed;
    68   size_t mStackTracesUnused;
    69   size_t mStackTraceTable;
    70   size_t mBlockTable;
    72   Sizes() { Clear(); }
    73   void Clear() { memset(this, 0, sizeof(Sizes)); }
    74 };
    76 // Gets the size of various data structures.  Used to implement a memory
    77 // reporter for DMD.
    78 MOZ_EXPORT void
    79 SizeOf(Sizes* aSizes);
    81 // Indicates whether or not DMD is enabled.
    82 MOZ_EXPORT bool
    83 IsEnabled();
    85 } // namespace mozilla
    86 } // namespace dmd
    88 #endif /* DMD_h___ */

mercurial