Move libmemunreachable into namespace android
Putting libmemunreachable in the global C++ namespace was an oversight, move it into namespace android. Test: m -j checkbuild Change-Id: I0799906f6463178cb04a719bb4054cad33a50dbe
This commit is contained in:
parent
a83881e33c
commit
a9939e9a23
32 changed files with 140 additions and 8 deletions
|
@ -37,6 +37,8 @@
|
|||
#include "LinkedList.h"
|
||||
#include "anon_vma_naming.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
// runtime interfaces used:
|
||||
// abort
|
||||
// assert - fprintf + mmap
|
||||
|
@ -462,3 +464,5 @@ void Heap::deallocate(HeapImpl* impl, void* ptr) {
|
|||
bool Heap::empty() {
|
||||
return impl_->Empty();
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace android {
|
||||
|
||||
extern std::atomic<int> heap_count;
|
||||
|
||||
class HeapImpl;
|
||||
|
@ -210,4 +213,6 @@ using set = std::set<Key, Compare, Allocator<Key>>;
|
|||
using string = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "ScopedSignalHandler.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
bool HeapWalker::Allocation(uintptr_t begin, uintptr_t end) {
|
||||
if (end == begin) {
|
||||
end = begin + 1;
|
||||
|
@ -173,3 +175,5 @@ void HeapWalker::HandleSegFault(ScopedSignalHandler& handler, int signal, siginf
|
|||
}
|
||||
|
||||
ScopedSignalHandler::SignalFn ScopedSignalHandler::handler_;
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "ScopedSignalHandler.h"
|
||||
#include "Tarjan.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
// A range [begin, end)
|
||||
struct Range {
|
||||
uintptr_t begin;
|
||||
|
@ -125,4 +127,6 @@ inline void HeapWalker::ForEachAllocation(F&& f) {
|
|||
}
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<Leak::Backtrace> {
|
||||
std::size_t operator()(const Leak::Backtrace& key) const {
|
||||
struct hash<android::Leak::Backtrace> {
|
||||
std::size_t operator()(const android::Leak::Backtrace& key) const {
|
||||
std::size_t seed = 0;
|
||||
|
||||
hash_combine(seed, key.num_frames);
|
||||
|
@ -49,9 +49,12 @@ struct hash<Leak::Backtrace> {
|
|||
|
||||
} // namespace std
|
||||
|
||||
namespace android {
|
||||
|
||||
static bool operator==(const Leak::Backtrace& lhs, const Leak::Backtrace& rhs) {
|
||||
return (lhs.num_frames == rhs.num_frames) &&
|
||||
memcmp(lhs.frames, rhs.frames, lhs.num_frames * sizeof(lhs.frames[0])) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "Tarjan.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
// Converts possibly cyclic graph of leaks to a DAG by combining
|
||||
// strongly-connected components into a object, stored in the scc pointer
|
||||
// of each node in the component.
|
||||
|
@ -132,3 +134,5 @@ bool LeakFolding::Leaked(allocator::vector<LeakFolding::Leak>& leaked, size_t* n
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "HeapWalker.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
class LeakFolding {
|
||||
public:
|
||||
LeakFolding(Allocator<void> allocator, HeapWalker& heap_walker)
|
||||
|
@ -93,4 +95,6 @@ class LeakFolding {
|
|||
allocator::vector<Allocator<SCCInfo>::unique_ptr> leak_scc_;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // LIBMEMUNREACHABLE_LEAK_FOLDING_H_
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
bool LeakPipe::SendFd(int sock, int fd) {
|
||||
struct msghdr hdr {};
|
||||
struct iovec iov {};
|
||||
|
@ -87,3 +89,5 @@ int LeakPipe::ReceiveFd(int sock) {
|
|||
|
||||
return *(int*)CMSG_DATA(cmsg);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "ScopedPipe.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
// LeakPipe implements a pipe that can transfer vectors of simple objects
|
||||
// between processes. The pipe is created in the sending process and
|
||||
// transferred over a socketpair that was created before forking. This ensures
|
||||
|
@ -187,4 +189,6 @@ class LeakPipe {
|
|||
int sv_[2];
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // LIBMEMUNREACHABLE_LEAK_PIPE_H_
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include "LineBuffer.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
LineBuffer::LineBuffer(int fd, char* buffer, size_t buffer_len)
|
||||
: fd_(fd), buffer_(buffer), buffer_len_(buffer_len) {}
|
||||
|
||||
|
@ -60,3 +62,5 @@ bool LineBuffer::GetLine(char** line, size_t* line_len) {
|
|||
bytes_ += bytes;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class LineBuffer {
|
||||
public:
|
||||
LineBuffer(int fd, char* buffer, size_t buffer_len);
|
||||
|
@ -33,4 +35,6 @@ class LineBuffer {
|
|||
size_t bytes_ = 0;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // _LIBMEMUNREACHABLE_LINE_BUFFER_H
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#ifndef LIBMEMUNREACHABLE_LINKED_LIST_H_
|
||||
#define LIBMEMUNREACHABLE_LINKED_LIST_H_
|
||||
|
||||
namespace android {
|
||||
|
||||
template <class T>
|
||||
class LinkedList {
|
||||
public:
|
||||
|
@ -56,4 +58,6 @@ class LinkedListHead {
|
|||
LinkedList<T> node_;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <functional>
|
||||
#include <iomanip>
|
||||
|
@ -41,10 +42,12 @@
|
|||
#include "log.h"
|
||||
#include "memunreachable/memunreachable.h"
|
||||
|
||||
const size_t Leak::contents_length;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace android {
|
||||
|
||||
const size_t Leak::contents_length;
|
||||
|
||||
class MemUnreachable {
|
||||
public:
|
||||
MemUnreachable(pid_t pid, Allocator<void> allocator)
|
||||
|
@ -510,9 +513,11 @@ std::string GetUnreachableMemoryString(bool log_contents, size_t limit) {
|
|||
return info.ToString(log_contents);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
bool LogUnreachableMemory(bool log_contents, size_t limit) {
|
||||
UnreachableMemoryInfo info;
|
||||
if (!GetUnreachableMemory(info, limit)) {
|
||||
android::UnreachableMemoryInfo info;
|
||||
if (!android::GetUnreachableMemory(info, limit)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -523,8 +528,8 @@ bool LogUnreachableMemory(bool log_contents, size_t limit) {
|
|||
}
|
||||
|
||||
bool NoLeaks() {
|
||||
UnreachableMemoryInfo info;
|
||||
if (!GetUnreachableMemory(info, 0)) {
|
||||
android::UnreachableMemoryInfo info;
|
||||
if (!android::GetUnreachableMemory(info, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "ProcessMappings.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
// This function is not re-entrant since it uses a static buffer for
|
||||
// the line data.
|
||||
bool ProcessMappings(pid_t pid, allocator::vector<Mapping>& mappings) {
|
||||
|
@ -64,3 +66,5 @@ bool ProcessMappings(pid_t pid, allocator::vector<Mapping>& mappings) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "Allocator.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
struct Mapping {
|
||||
uintptr_t begin;
|
||||
uintptr_t end;
|
||||
|
@ -33,4 +35,6 @@ struct Mapping {
|
|||
// the line data.
|
||||
bool ProcessMappings(pid_t pid, allocator::vector<Mapping>& mappings);
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // LIBMEMUNREACHABLE_PROCESS_MAPPING_H_
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include "anon_vma_naming.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
class Stack {
|
||||
public:
|
||||
explicit Stack(size_t size) : size_(size) {
|
||||
|
@ -148,3 +150,5 @@ void PtracerThread::SetTracer(pid_t tracer_pid) {
|
|||
void PtracerThread::ClearTracer() {
|
||||
prctl(PR_SET_PTRACER, 0);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "Allocator.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
class Stack;
|
||||
|
||||
// PtracerThread is similar to std::thread, except that it creates a "thread"
|
||||
|
@ -48,4 +50,6 @@ class PtracerThread {
|
|||
pid_t child_pid_;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // LIBMEMUNREACHABLE_PTRACER_THREAD_H_
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <chrono>
|
||||
#include <functional>
|
||||
|
||||
namespace android {
|
||||
|
||||
class ScopedAlarm {
|
||||
public:
|
||||
ScopedAlarm(std::chrono::microseconds us, std::function<void()> func) {
|
||||
|
@ -49,4 +51,7 @@ class ScopedAlarm {
|
|||
private:
|
||||
static std::function<void()> func_;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "bionic.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
class DisableMallocGuard {
|
||||
public:
|
||||
DisableMallocGuard() : disabled_(false) {}
|
||||
|
@ -102,4 +104,6 @@ class ScopedDisableMallocTimeout {
|
|||
DisableMallocGuard disable_malloc_;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // LIBMEMUNREACHABLE_SCOPED_DISABLE_MALLOC_H_
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
class ScopedPipe {
|
||||
public:
|
||||
ScopedPipe() : pipefd_{-1, -1} {
|
||||
|
@ -72,4 +74,7 @@ class ScopedPipe {
|
|||
|
||||
int pipefd_[2];
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
class ScopedSignalHandler {
|
||||
public:
|
||||
using Fn = std::function<void(ScopedSignalHandler&, int, siginfo_t*, void*)>;
|
||||
|
@ -74,4 +76,6 @@ class ScopedSignalHandler {
|
|||
static SignalFn handler_;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // LIBMEMUNREACHABLE_SCOPED_SIGNAL_HANDLER_H_
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "android-base/macros.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
class Semaphore {
|
||||
public:
|
||||
explicit Semaphore(int count = 0) : count_(count) {}
|
||||
|
@ -53,4 +55,6 @@ class Semaphore {
|
|||
std::condition_variable cv_;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // LIBMEMUNREACHABLE_SEMAPHORE_H_
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "Allocator.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
template <class T>
|
||||
class Node {
|
||||
public:
|
||||
|
@ -131,4 +133,6 @@ void Tarjan(Graph<T>& graph, SCCList<T>& out) {
|
|||
tarjan.Execute(graph, out);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // LIBMEMUNREACHABLE_TARJAN_H_
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
#include "Allocator.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
// bionic interfaces used:
|
||||
// atoi
|
||||
// strlcat
|
||||
|
@ -361,3 +363,5 @@ bool ThreadCapture::CapturedThreadInfo(ThreadInfoList& threads) {
|
|||
void ThreadCapture::InjectTestFunc(std::function<void(pid_t)>&& f) {
|
||||
impl_->InjectTestFunc(std::forward<std::function<void(pid_t)>>(f));
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "Allocator.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
struct ThreadInfo {
|
||||
pid_t tid;
|
||||
allocator::vector<uintptr_t> regs;
|
||||
|
@ -51,4 +53,6 @@ class ThreadCapture {
|
|||
Allocator<ThreadCaptureImpl>::unique_ptr impl_;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#ifndef LIBMEMUNREACHABLE_MEMUNREACHABLE_H_
|
||||
#define LIBMEMUNREACHABLE_MEMUNREACHABLE_H_
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -24,6 +25,8 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct Leak {
|
||||
uintptr_t begin;
|
||||
size_t size;
|
||||
|
@ -73,6 +76,8 @@ bool GetUnreachableMemory(UnreachableMemoryInfo& info, size_t limit = 100);
|
|||
|
||||
std::string GetUnreachableMemoryString(bool log_contents = false, size_t limit = 100);
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include <ScopedDisableMalloc.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
std::function<void()> ScopedAlarm::func_;
|
||||
|
||||
class AllocatorTest : public testing::Test {
|
||||
|
@ -170,3 +172,5 @@ TEST_F(AllocatorTest, unique) {
|
|||
|
||||
ASSERT_NE(ptr, nullptr);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace android {
|
||||
|
||||
class DisableMallocTest : public ::testing::Test {
|
||||
protected:
|
||||
void alarm(std::chrono::microseconds us) {
|
||||
|
@ -124,3 +126,5 @@ TEST_F(DisableMallocTest, deadlock_fork) {
|
|||
}
|
||||
}, "");
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "Allocator.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
class HeapWalkerTest : public ::testing::Test {
|
||||
public:
|
||||
HeapWalkerTest() : disable_malloc_(), heap_() {}
|
||||
|
@ -199,3 +201,5 @@ TEST_F(HeapWalkerTest, segv) {
|
|||
EXPECT_EQ(0U, leaked_bytes);
|
||||
ASSERT_EQ(0U, leaked.size());
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "Allocator.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
class LeakFoldingTest : public ::testing::Test {
|
||||
public:
|
||||
LeakFoldingTest() : disable_malloc_(), heap_() {}
|
||||
|
@ -425,3 +427,5 @@ TEST_F(LeakFoldingTest, multicycle) {
|
|||
EXPECT_EQ(3U, leaked[3].referenced_count);
|
||||
EXPECT_EQ(6 * sizeof(uintptr_t), leaked[3].referenced_size);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <memunreachable/memunreachable.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class HiddenPointer {
|
||||
public:
|
||||
explicit HiddenPointer(size_t size = 256) { Set(malloc(size)); }
|
||||
|
@ -209,3 +211,5 @@ TEST(MemunreachableTest, leak_lots) {
|
|||
|
||||
ASSERT_TRUE(LogUnreachableMemory(true, 100));
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace android {
|
||||
|
||||
class ThreadListTest : public ::testing::TestWithParam<int> {
|
||||
public:
|
||||
ThreadListTest() : stop_(false) {}
|
||||
|
@ -343,3 +345,5 @@ TEST_F(ThreadCaptureTest, capture_signal) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
Loading…
Reference in a new issue