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
diff --git a/libmemunreachable/Allocator.cpp b/libmemunreachable/Allocator.cpp
index da6db20..213be17 100644
--- a/libmemunreachable/Allocator.cpp
+++ b/libmemunreachable/Allocator.cpp
@@ -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 @@
 bool Heap::empty() {
   return impl_->Empty();
 }
+
+}  // namespace android
diff --git a/libmemunreachable/Allocator.h b/libmemunreachable/Allocator.h
index 67a068f..837a12b 100644
--- a/libmemunreachable/Allocator.h
+++ b/libmemunreachable/Allocator.h
@@ -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 string = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
 }
 
+}  // namespace android
+
 #endif
diff --git a/libmemunreachable/HeapWalker.cpp b/libmemunreachable/HeapWalker.cpp
index df16f40..2403ad0 100644
--- a/libmemunreachable/HeapWalker.cpp
+++ b/libmemunreachable/HeapWalker.cpp
@@ -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 @@
 }
 
 ScopedSignalHandler::SignalFn ScopedSignalHandler::handler_;
+
+}  // namespace android
diff --git a/libmemunreachable/HeapWalker.h b/libmemunreachable/HeapWalker.h
index 865965a..5c7ec13 100644
--- a/libmemunreachable/HeapWalker.h
+++ b/libmemunreachable/HeapWalker.h
@@ -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 @@
   }
 }
 
+}  // namespace android
+
 #endif
diff --git a/libmemunreachable/Leak.h b/libmemunreachable/Leak.h
index db88e29..de64b64 100644
--- a/libmemunreachable/Leak.h
+++ b/libmemunreachable/Leak.h
@@ -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 @@
 
 }  // 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
diff --git a/libmemunreachable/LeakFolding.cpp b/libmemunreachable/LeakFolding.cpp
index 2dff672..69f320c 100644
--- a/libmemunreachable/LeakFolding.cpp
+++ b/libmemunreachable/LeakFolding.cpp
@@ -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 @@
 
   return true;
 }
+
+}  // namespace android
diff --git a/libmemunreachable/LeakFolding.h b/libmemunreachable/LeakFolding.h
index 740b54f..09affac 100644
--- a/libmemunreachable/LeakFolding.h
+++ b/libmemunreachable/LeakFolding.h
@@ -19,6 +19,8 @@
 
 #include "HeapWalker.h"
 
+namespace android {
+
 class LeakFolding {
  public:
   LeakFolding(Allocator<void> allocator, HeapWalker& heap_walker)
@@ -93,4 +95,6 @@
   allocator::vector<Allocator<SCCInfo>::unique_ptr> leak_scc_;
 };
 
+}  // namespace android
+
 #endif  // LIBMEMUNREACHABLE_LEAK_FOLDING_H_
diff --git a/libmemunreachable/LeakPipe.cpp b/libmemunreachable/LeakPipe.cpp
index aac5701..8ea9ad6 100644
--- a/libmemunreachable/LeakPipe.cpp
+++ b/libmemunreachable/LeakPipe.cpp
@@ -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 @@
 
   return *(int*)CMSG_DATA(cmsg);
 }
+
+}  // namespace android
diff --git a/libmemunreachable/LeakPipe.h b/libmemunreachable/LeakPipe.h
index e6aee5f..94d4aa4 100644
--- a/libmemunreachable/LeakPipe.h
+++ b/libmemunreachable/LeakPipe.h
@@ -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 @@
   int sv_[2];
 };
 
+}  // namespace android
+
 #endif  // LIBMEMUNREACHABLE_LEAK_PIPE_H_
diff --git a/libmemunreachable/LineBuffer.cpp b/libmemunreachable/LineBuffer.cpp
index 0709fdd..4ea0542 100644
--- a/libmemunreachable/LineBuffer.cpp
+++ b/libmemunreachable/LineBuffer.cpp
@@ -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 @@
     bytes_ += bytes;
   }
 }
+
+}  // namespace android
diff --git a/libmemunreachable/LineBuffer.h b/libmemunreachable/LineBuffer.h
index 604836b..cc6cd0c 100644
--- a/libmemunreachable/LineBuffer.h
+++ b/libmemunreachable/LineBuffer.h
@@ -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 @@
   size_t bytes_ = 0;
 };
 
+}  // namespace android
+
 #endif  // _LIBMEMUNREACHABLE_LINE_BUFFER_H
diff --git a/libmemunreachable/LinkedList.h b/libmemunreachable/LinkedList.h
index f1b8a17..36fe9fd 100644
--- a/libmemunreachable/LinkedList.h
+++ b/libmemunreachable/LinkedList.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 @@
   LinkedList<T> node_;
 };
 
+}  // namespace android
+
 #endif
diff --git a/libmemunreachable/MemUnreachable.cpp b/libmemunreachable/MemUnreachable.cpp
index 870cd1d..a1f74c3 100644
--- a/libmemunreachable/MemUnreachable.cpp
+++ b/libmemunreachable/MemUnreachable.cpp
@@ -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 @@
   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 NoLeaks() {
-  UnreachableMemoryInfo info;
-  if (!GetUnreachableMemory(info, 0)) {
+  android::UnreachableMemoryInfo info;
+  if (!android::GetUnreachableMemory(info, 0)) {
     return false;
   }
 
diff --git a/libmemunreachable/ProcessMappings.cpp b/libmemunreachable/ProcessMappings.cpp
index 42e5326..9a06870 100644
--- a/libmemunreachable/ProcessMappings.cpp
+++ b/libmemunreachable/ProcessMappings.cpp
@@ -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 @@
   }
   return true;
 }
+
+}  // namespace android
diff --git a/libmemunreachable/ProcessMappings.h b/libmemunreachable/ProcessMappings.h
index 81b33dc..a0e97e9 100644
--- a/libmemunreachable/ProcessMappings.h
+++ b/libmemunreachable/ProcessMappings.h
@@ -19,6 +19,8 @@
 
 #include "Allocator.h"
 
+namespace android {
+
 struct Mapping {
   uintptr_t begin;
   uintptr_t end;
@@ -33,4 +35,6 @@
 // the line data.
 bool ProcessMappings(pid_t pid, allocator::vector<Mapping>& mappings);
 
+}  // namespace android
+
 #endif  // LIBMEMUNREACHABLE_PROCESS_MAPPING_H_
diff --git a/libmemunreachable/PtracerThread.cpp b/libmemunreachable/PtracerThread.cpp
index 41efa9c..aca2a82 100644
--- a/libmemunreachable/PtracerThread.cpp
+++ b/libmemunreachable/PtracerThread.cpp
@@ -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::ClearTracer() {
   prctl(PR_SET_PTRACER, 0);
 }
+
+}  // namespace android
diff --git a/libmemunreachable/PtracerThread.h b/libmemunreachable/PtracerThread.h
index ddf9026..4f9c420 100644
--- a/libmemunreachable/PtracerThread.h
+++ b/libmemunreachable/PtracerThread.h
@@ -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 @@
   pid_t child_pid_;
 };
 
+}  // namespace android
+
 #endif  // LIBMEMUNREACHABLE_PTRACER_THREAD_H_
diff --git a/libmemunreachable/ScopedAlarm.h b/libmemunreachable/ScopedAlarm.h
index 53ea112..bb50b9e 100644
--- a/libmemunreachable/ScopedAlarm.h
+++ b/libmemunreachable/ScopedAlarm.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 @@
  private:
   static std::function<void()> func_;
 };
+
+}  // namespace android
+
 #endif
diff --git a/libmemunreachable/ScopedDisableMalloc.h b/libmemunreachable/ScopedDisableMalloc.h
index 7d2f630..655e826 100644
--- a/libmemunreachable/ScopedDisableMalloc.h
+++ b/libmemunreachable/ScopedDisableMalloc.h
@@ -25,6 +25,8 @@
 #include "bionic.h"
 #include "log.h"
 
+namespace android {
+
 class DisableMallocGuard {
  public:
   DisableMallocGuard() : disabled_(false) {}
@@ -102,4 +104,6 @@
   DisableMallocGuard disable_malloc_;
 };
 
+}  // namespace android
+
 #endif  // LIBMEMUNREACHABLE_SCOPED_DISABLE_MALLOC_H_
diff --git a/libmemunreachable/ScopedPipe.h b/libmemunreachable/ScopedPipe.h
index 76bd974..adabfd8 100644
--- a/libmemunreachable/ScopedPipe.h
+++ b/libmemunreachable/ScopedPipe.h
@@ -21,6 +21,8 @@
 
 #include "log.h"
 
+namespace android {
+
 class ScopedPipe {
  public:
   ScopedPipe() : pipefd_{-1, -1} {
@@ -72,4 +74,7 @@
 
   int pipefd_[2];
 };
+
+}  // namespace android
+
 #endif
diff --git a/libmemunreachable/ScopedSignalHandler.h b/libmemunreachable/ScopedSignalHandler.h
index 58ac2aa..f62f368 100644
--- a/libmemunreachable/ScopedSignalHandler.h
+++ b/libmemunreachable/ScopedSignalHandler.h
@@ -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 @@
   static SignalFn handler_;
 };
 
+}  // namespace android
+
 #endif  // LIBMEMUNREACHABLE_SCOPED_SIGNAL_HANDLER_H_
diff --git a/libmemunreachable/Semaphore.h b/libmemunreachable/Semaphore.h
index 6d39a93..cd73972 100644
--- a/libmemunreachable/Semaphore.h
+++ b/libmemunreachable/Semaphore.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 @@
   std::condition_variable cv_;
 };
 
+}  // namespace android
+
 #endif  // LIBMEMUNREACHABLE_SEMAPHORE_H_
diff --git a/libmemunreachable/Tarjan.h b/libmemunreachable/Tarjan.h
index 86c7360..355679f 100644
--- a/libmemunreachable/Tarjan.h
+++ b/libmemunreachable/Tarjan.h
@@ -24,6 +24,8 @@
 
 #include "Allocator.h"
 
+namespace android {
+
 template <class T>
 class Node {
  public:
@@ -131,4 +133,6 @@
   tarjan.Execute(graph, out);
 }
 
+}  // namespace android
+
 #endif  // LIBMEMUNREACHABLE_TARJAN_H_
diff --git a/libmemunreachable/ThreadCapture.cpp b/libmemunreachable/ThreadCapture.cpp
index a7bd91c..45eb55d 100644
--- a/libmemunreachable/ThreadCapture.cpp
+++ b/libmemunreachable/ThreadCapture.cpp
@@ -39,6 +39,8 @@
 #include "Allocator.h"
 #include "log.h"
 
+namespace android {
+
 // bionic interfaces used:
 // atoi
 // strlcat
@@ -361,3 +363,5 @@
 void ThreadCapture::InjectTestFunc(std::function<void(pid_t)>&& f) {
   impl_->InjectTestFunc(std::forward<std::function<void(pid_t)>>(f));
 }
+
+}  // namespace android
diff --git a/libmemunreachable/ThreadCapture.h b/libmemunreachable/ThreadCapture.h
index d209660..961cb60 100644
--- a/libmemunreachable/ThreadCapture.h
+++ b/libmemunreachable/ThreadCapture.h
@@ -21,6 +21,8 @@
 
 #include "Allocator.h"
 
+namespace android {
+
 struct ThreadInfo {
   pid_t tid;
   allocator::vector<uintptr_t> regs;
@@ -51,4 +53,6 @@
   Allocator<ThreadCaptureImpl>::unique_ptr impl_;
 };
 
+}  // namespace android
+
 #endif
diff --git a/libmemunreachable/include/memunreachable/memunreachable.h b/libmemunreachable/include/memunreachable/memunreachable.h
index f6249e3..438fcaf 100644
--- a/libmemunreachable/include/memunreachable/memunreachable.h
+++ b/libmemunreachable/include/memunreachable/memunreachable.h
@@ -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 @@
 
 std::string GetUnreachableMemoryString(bool log_contents = false, size_t limit = 100);
 
+}  // namespace android
+
 #endif
 
 __BEGIN_DECLS
diff --git a/libmemunreachable/tests/Allocator_test.cpp b/libmemunreachable/tests/Allocator_test.cpp
index 0bb4f31..8991a7b 100644
--- a/libmemunreachable/tests/Allocator_test.cpp
+++ b/libmemunreachable/tests/Allocator_test.cpp
@@ -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 @@
 
   ASSERT_NE(ptr, nullptr);
 }
+
+}  // namespace android
diff --git a/libmemunreachable/tests/DisableMalloc_test.cpp b/libmemunreachable/tests/DisableMalloc_test.cpp
index 2db5848..c630049 100644
--- a/libmemunreachable/tests/DisableMalloc_test.cpp
+++ b/libmemunreachable/tests/DisableMalloc_test.cpp
@@ -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 @@
 }
 }, "");
 }
+
+}  // namespace android
diff --git a/libmemunreachable/tests/HeapWalker_test.cpp b/libmemunreachable/tests/HeapWalker_test.cpp
index 1b258ee..84a0ec6 100644
--- a/libmemunreachable/tests/HeapWalker_test.cpp
+++ b/libmemunreachable/tests/HeapWalker_test.cpp
@@ -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 @@
   EXPECT_EQ(0U, leaked_bytes);
   ASSERT_EQ(0U, leaked.size());
 }
+
+}  // namespace android
diff --git a/libmemunreachable/tests/LeakFolding_test.cpp b/libmemunreachable/tests/LeakFolding_test.cpp
index 7ae7f76..f5b3631 100644
--- a/libmemunreachable/tests/LeakFolding_test.cpp
+++ b/libmemunreachable/tests/LeakFolding_test.cpp
@@ -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 @@
   EXPECT_EQ(3U, leaked[3].referenced_count);
   EXPECT_EQ(6 * sizeof(uintptr_t), leaked[3].referenced_size);
 }
+
+}  // namespace android
diff --git a/libmemunreachable/tests/MemUnreachable_test.cpp b/libmemunreachable/tests/MemUnreachable_test.cpp
index a231f4f..bb6bcbc 100644
--- a/libmemunreachable/tests/MemUnreachable_test.cpp
+++ b/libmemunreachable/tests/MemUnreachable_test.cpp
@@ -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 @@
 
   ASSERT_TRUE(LogUnreachableMemory(true, 100));
 }
+
+}  // namespace android
diff --git a/libmemunreachable/tests/ThreadCapture_test.cpp b/libmemunreachable/tests/ThreadCapture_test.cpp
index 5bcb79e..4fbf729 100644
--- a/libmemunreachable/tests/ThreadCapture_test.cpp
+++ b/libmemunreachable/tests/ThreadCapture_test.cpp
@@ -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 @@
         }
       });
 }
+
+}  // namespace android