Bug 1664774 [wpt PR 25514] - Python 3: make the new introduced image.py file python...
[gecko.git] / mfbt / TaggedAnonymousMemory.h
blob3884045a798f8427c82bc85e0f03c5626303db79
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 // Some Linux kernels -- specifically, newer versions of Android and
8 // some B2G devices -- have a feature for assigning names to ranges of
9 // anonymous memory (i.e., memory that doesn't have a "name" in the
10 // form of an underlying mapped file). These names are reported in
11 // /proc/<pid>/smaps alongside system-level memory usage information
12 // such as Proportional Set Size (memory usage adjusted for sharing
13 // between processes), which allows reporting this information at a
14 // finer granularity than would otherwise be possible (e.g.,
15 // separating malloc() heap from JS heap).
17 // Existing memory can be tagged with MozTagAnonymousMemory(); it will
18 // tag the range of complete pages containing the given interval, so
19 // the results may be inexact if the range isn't page-aligned.
20 // MozTaggedAnonymousMmap() can be used like mmap() with an extra
21 // parameter, and will tag the returned memory if the mapping was
22 // successful (and if it was in fact anonymous).
24 // NOTE: The pointer given as the "tag" argument MUST remain valid as
25 // long as the mapping exists. The referenced string is read when
26 // /proc/<pid>/smaps or /proc/<pid>/maps is read, not when the tag is
27 // established, so freeing it or changing its contents will have
28 // unexpected results. Using a static string is probably best.
30 // Also note that this header can be used by both C and C++ code.
32 #ifndef mozilla_TaggedAnonymousMemory_h
33 #define mozilla_TaggedAnonymousMemory_h
35 #ifndef XP_WIN
37 # include <sys/types.h>
38 # include <sys/mman.h>
40 # include "mozilla/Types.h"
42 # ifdef ANDROID
44 # ifdef __cplusplus
45 extern "C" {
46 # endif
48 MFBT_API void MozTagAnonymousMemory(const void* aPtr, size_t aLength,
49 const char* aTag);
51 MFBT_API void* MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt,
52 int aFlags, int aFd, off_t aOffset,
53 const char* aTag);
55 MFBT_API int MozTaggedMemoryIsSupported(void);
57 # ifdef __cplusplus
58 } // extern "C"
59 # endif
61 # else // ANDROID
63 static inline void MozTagAnonymousMemory(const void* aPtr, size_t aLength,
64 const char* aTag) {}
66 static inline void* MozTaggedAnonymousMmap(void* aAddr, size_t aLength,
67 int aProt, int aFlags, int aFd,
68 off_t aOffset, const char* aTag) {
69 return mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset);
72 static inline int MozTaggedMemoryIsSupported(void) { return 0; }
74 # endif // ANDROID
76 #endif // !XP_WIN
78 #endif // mozilla_TaggedAnonymousMemory_h