[compiler-rt] r310116 - Add NetBSD support in sanitizer_procmaps_freebsd.cc

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 4 13:17:25 PDT 2017


Author: kamil
Date: Fri Aug  4 13:17:24 2017
New Revision: 310116

URL: http://llvm.org/viewvc/llvm-project?rev=310116&view=rev
Log:
Add NetBSD support in sanitizer_procmaps_freebsd.cc

Summary:
This adds NetBSD specific:
 - ReadProcMaps()
 - MemoryMappingLayout::Next()

This code is largely shared with FreeBSD.

Part of the code inspired by the original work on libsanitizer in GCC 5.4 by Christos Zoulas.

Sponsored by <The NetBSD Foundation>

Reviewers: kcc, joerg, filcab, vitalybuka, fjricci

Reviewed By: fjricci

Subscribers: emaste, kubamracek, mgorny, llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D35551

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_freebsd.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_freebsd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_freebsd.cc?rev=310116&r1=310115&r2=310116&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_freebsd.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_freebsd.cc Fri Aug  4 13:17:24 2017
@@ -7,18 +7,22 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// Information about the process mappings (FreeBSD-specific parts).
+// Information about the process mappings (FreeBSD and NetBSD-specific parts).
 //===----------------------------------------------------------------------===//
 
 #include "sanitizer_platform.h"
-#if SANITIZER_FREEBSD
+#if SANITIZER_FREEBSD || SANITIZER_NETBSD
 #include "sanitizer_common.h"
+#if SANITIZER_FREEBSD
 #include "sanitizer_freebsd.h"
+#endif
 #include "sanitizer_procmaps.h"
 
 #include <unistd.h>
 #include <sys/sysctl.h>
+#if SANITIZER_FREEBSD
 #include <sys/user.h>
+#endif
 
 // Fix 'kinfo_vmentry' definition on FreeBSD prior v9.2 in 32-bit mode.
 #if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32)
@@ -31,16 +35,30 @@
 namespace __sanitizer {
 
 void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
-  const int Mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid() };
+  const int Mib[] = {
+#if SANITIZER_FREEBSD
+    CTL_KERN,
+    KERN_PROC,
+    KERN_PROC_VMMAP,
+    getpid()
+#else
+    CTL_VM,
+    VM_PROC,
+    VM_PROC_MAP,
+    getpid(),
+    sizeof(struct kinfo_vmentry)
+#endif
+  };
+
   size_t Size = 0;
-  int Err = sysctl(Mib, 4, NULL, &Size, NULL, 0);
+  int Err = sysctl(Mib, ARRAY_SIZE(Mib), NULL, &Size, NULL, 0);
   CHECK_EQ(Err, 0);
   CHECK_GT(Size, 0);
 
   size_t MmapedSize = Size * 4 / 3;
   void *VmMap = MmapOrDie(MmapedSize, "ReadProcMaps()");
   Size = MmapedSize;
-  Err = sysctl(Mib, 4, VmMap, &Size, NULL, 0);
+  Err = sysctl(Mib, ARRAY_SIZE(Mib), VmMap, &Size, NULL, 0);
   CHECK_EQ(Err, 0);
 
   proc_maps->data = (char*)VmMap;
@@ -71,11 +89,15 @@ bool MemoryMappingLayout::Next(MemoryMap
                       VmEntry->kve_path);
   }
 
+#if SANITIZER_FREEBSD
   current_ += VmEntry->kve_structsize;
+#else
+  current_ += sizeof(*VmEntry);
+#endif
 
   return true;
 }
 
 }  // namespace __sanitizer
 
-#endif  // SANITIZER_FREEBSD
+#endif  // SANITIZER_FREEBSD || SANITIZER_NETBSD




More information about the llvm-commits mailing list