[PATCH] D35551: Add NetBSD support in sanitizer_procmaps_freebsd.cc

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 4 06:22:15 PDT 2017


krytarowski updated this revision to Diff 109723.
krytarowski retitled this revision from "Introduce sanitizer_procmaps_netbsd.cc" to "Add NetBSD support in sanitizer_procmaps_freebsd.cc".
krytarowski edited the summary of this revision.
Herald added a subscriber: emaste.

Repository:
  rL LLVM

https://reviews.llvm.org/D35551

Files:
  lib/sanitizer_common/sanitizer_procmaps_freebsd.cc


Index: lib/sanitizer_common/sanitizer_procmaps_freebsd.cc
===================================================================
--- lib/sanitizer_common/sanitizer_procmaps_freebsd.cc
+++ lib/sanitizer_common/sanitizer_procmaps_freebsd.cc
@@ -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)
@@ -28,19 +32,37 @@
 # endif
 #endif
 
+#ifndef __arraycount
+#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
+#endif
+
 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, __arraycount(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, __arraycount(Mib), VmMap, &Size, NULL, 0);
   CHECK_EQ(Err, 0);
 
   proc_maps->data = (char*)VmMap;
@@ -71,11 +93,15 @@
                       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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35551.109723.patch
Type: text/x-patch
Size: 2328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170804/410ac598/attachment.bin>


More information about the llvm-commits mailing list