Skip to content

Commit fcf8e5e

Browse files
committedAug 4, 2017
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 llvm-svn: 310116
1 parent c046208 commit fcf8e5e

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed
 

‎compiler-rt/lib/sanitizer_common/sanitizer_procmaps_freebsd.cc

+28-6
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
//
88
//===----------------------------------------------------------------------===//
99
//
10-
// Information about the process mappings (FreeBSD-specific parts).
10+
// Information about the process mappings (FreeBSD and NetBSD-specific parts).
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "sanitizer_platform.h"
14-
#if SANITIZER_FREEBSD
14+
#if SANITIZER_FREEBSD || SANITIZER_NETBSD
1515
#include "sanitizer_common.h"
16+
#if SANITIZER_FREEBSD
1617
#include "sanitizer_freebsd.h"
18+
#endif
1719
#include "sanitizer_procmaps.h"
1820

1921
#include <unistd.h>
2022
#include <sys/sysctl.h>
23+
#if SANITIZER_FREEBSD
2124
#include <sys/user.h>
25+
#endif
2226

2327
// Fix 'kinfo_vmentry' definition on FreeBSD prior v9.2 in 32-bit mode.
2428
#if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32)
@@ -31,16 +35,30 @@
3135
namespace __sanitizer {
3236

3337
void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
34-
const int Mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid() };
38+
const int Mib[] = {
39+
#if SANITIZER_FREEBSD
40+
CTL_KERN,
41+
KERN_PROC,
42+
KERN_PROC_VMMAP,
43+
getpid()
44+
#else
45+
CTL_VM,
46+
VM_PROC,
47+
VM_PROC_MAP,
48+
getpid(),
49+
sizeof(struct kinfo_vmentry)
50+
#endif
51+
};
52+
3553
size_t Size = 0;
36-
int Err = sysctl(Mib, 4, NULL, &Size, NULL, 0);
54+
int Err = sysctl(Mib, ARRAY_SIZE(Mib), NULL, &Size, NULL, 0);
3755
CHECK_EQ(Err, 0);
3856
CHECK_GT(Size, 0);
3957

4058
size_t MmapedSize = Size * 4 / 3;
4159
void *VmMap = MmapOrDie(MmapedSize, "ReadProcMaps()");
4260
Size = MmapedSize;
43-
Err = sysctl(Mib, 4, VmMap, &Size, NULL, 0);
61+
Err = sysctl(Mib, ARRAY_SIZE(Mib), VmMap, &Size, NULL, 0);
4462
CHECK_EQ(Err, 0);
4563

4664
proc_maps->data = (char*)VmMap;
@@ -71,11 +89,15 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
7189
VmEntry->kve_path);
7290
}
7391

92+
#if SANITIZER_FREEBSD
7493
current_ += VmEntry->kve_structsize;
94+
#else
95+
current_ += sizeof(*VmEntry);
96+
#endif
7597

7698
return true;
7799
}
78100

79101
} // namespace __sanitizer
80102

81-
#endif // SANITIZER_FREEBSD
103+
#endif // SANITIZER_FREEBSD || SANITIZER_NETBSD

0 commit comments

Comments
 (0)