• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIBMEMUNREACHABLE_MEMUNREACHABLE_H_
18 #define LIBMEMUNREACHABLE_MEMUNREACHABLE_H_
19 
20 #include <string.h>
21 #include <sys/cdefs.h>
22 
23 #ifdef __cplusplus
24 
25 #include <string>
26 #include <vector>
27 
28 namespace android {
29 
30 struct Leak {
31   uintptr_t begin = 0;
32   size_t size = 0;
33 
34   size_t referenced_count = 0;
35   size_t referenced_size = 0;
36 
37   size_t similar_count = 0;
38   size_t similar_size = 0;
39   size_t similar_referenced_count = 0;
40   size_t similar_referenced_size = 0;
41 
42   size_t total_size = 0;
43 
44   static const size_t contents_length = 32;
45   char contents[contents_length] = {};
46 
47   struct Backtrace {
48     size_t num_frames = 0;
49 
50     static const size_t max_frames = 16;
51     uintptr_t frames[max_frames] = {};
52 
53     size_t reserved[8] = {};
54   } backtrace;
55 
56   size_t reserved[8] = {};
57 
58   std::string ToString(bool log_contents) const;
59 };
60 
61 struct UnreachableMemoryInfo {
62   std::vector<Leak> leaks;
63   size_t num_leaks = 0;
64   size_t leak_bytes = 0;
65   size_t num_allocations = 0;
66   size_t allocation_bytes = 0;
67 
68   size_t version = 0;  // Must be 0
69   size_t reserved[8] = {};
70 
UnreachableMemoryInfoUnreachableMemoryInfo71   UnreachableMemoryInfo() {}
72   ~UnreachableMemoryInfo();
73 
74   std::string ToString(bool log_contents) const;
75 };
76 
77 bool GetUnreachableMemory(UnreachableMemoryInfo& info, size_t limit = 100);
78 
79 std::string GetUnreachableMemoryString(bool log_contents = false, size_t limit = 100);
80 
81 }  // namespace android
82 
83 #endif
84 
85 __BEGIN_DECLS
86 
87 bool LogUnreachableMemory(bool log_contents, size_t limit);
88 
89 bool NoLeaks();
90 
91 __END_DECLS
92 
93 #endif  // LIBMEMUNREACHABLE_MEMUNREACHABLE_H_
94