Skip to content

Commit e371ada

Browse files
authored
[compiler-rt] reimplements GetMemoryProfile for netbsd. (#84841)
The actual solution relies on the premise /proc/self/smaps existence. instead relying on native api like freebsd. fixing fuzzer build too.
1 parent 2d62ce4 commit e371ada

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void SetThreadName(std::thread &thread, const std::string &name) {
4444
#if LIBFUZZER_LINUX || LIBFUZZER_FREEBSD
4545
(void)pthread_setname_np(thread.native_handle(), name.c_str());
4646
#elif LIBFUZZER_NETBSD
47-
(void)pthread_set_name_np(thread.native_handle(), "%s", name.c_str());
47+
(void)pthread_setname_np(thread.native_handle(), "%s", const_cast<char *>(name.c_str()));
4848
#endif
4949
}
5050

compiler-rt/lib/sanitizer_common/sanitizer_procmaps_bsd.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ void GetMemoryProfile(fill_profile_f cb, uptr *stats) {
4242
cb(0, InfoProc->ki_rssize * GetPageSizeCached(), false, stats);
4343
UnmapOrDie(InfoProc, Size, true);
4444
}
45+
#elif SANITIZER_NETBSD
46+
void GetMemoryProfile(fill_profile_f cb, uptr *stats) {
47+
struct kinfo_proc2 *InfoProc;
48+
uptr Len = sizeof(*InfoProc);
49+
uptr Size = Len;
50+
const int Mib[] = {CTL_KERN, KERN_PROC2, KERN_PROC_PID, getpid(), Size, 1};
51+
InfoProc = (struct kinfo_proc2 *)MmapOrDie(Size, "GetMemoryProfile()");
52+
CHECK_EQ(
53+
internal_sysctl(Mib, ARRAY_SIZE(Mib), nullptr, (uptr *)InfoProc, &Len, 0),
54+
0);
55+
cb(0, InfoProc->p_vm_rssize * GetPageSizeCached(), false, stats);
56+
UnmapOrDie(InfoProc, Size, true);
57+
}
4558
#endif
4659

4760
void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {

compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void MemoryMappingLayout::DumpListOfModules(
145145
}
146146
}
147147

148-
#if SANITIZER_LINUX || SANITIZER_ANDROID || SANITIZER_SOLARIS || SANITIZER_NETBSD
148+
#if SANITIZER_LINUX || SANITIZER_ANDROID || SANITIZER_SOLARIS
149149
void GetMemoryProfile(fill_profile_f cb, uptr *stats) {
150150
char *smaps = nullptr;
151151
uptr smaps_cap = 0;

0 commit comments

Comments
 (0)