From af05e818fb0519f027120e160ca036a3ab678584 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 19 Jan 2023 18:01:03 +0000 Subject: [PATCH] [Sanitizers] GetMemoryProfile implementation for FreeBSD. Reviewers: dvyukov Reviewed-By: dvyukov Differental Revision: https://reviews.llvm.org/D140688 --- .../lib/sanitizer_common/sanitizer_procmaps_bsd.cpp | 16 ++++++++++++++++ .../lib/sanitizer_common/sanitizer_procmaps_common.cpp | 2 ++ 2 files changed, 18 insertions(+) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_bsd.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_bsd.cpp index 1f489b71..36a82c4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_bsd.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_bsd.cpp @@ -39,6 +39,22 @@ namespace __sanitizer { +#if SANITIZER_FREEBSD +void GetMemoryProfile(fill_profile_f cb, uptr *stats) { + const int Mib[] = { + CTL_KERN, + KERN_PROC, + KERN_PROC_PID, + getpid() + }; + + struct kinfo_proc InfoProc; + uptr Len = sizeof(InfoProc); + CHECK_EQ(internal_sysctl(Mib, ARRAY_SIZE(Mib), nullptr, (uptr *)&InfoProc, &Len, 0), 0); + cb(0, InfoProc.ki_rssize * GetPageSizeCached(), false, stats); +} +#endif + void ReadProcMaps(ProcSelfMapsBuff *proc_maps) { const int Mib[] = { #if SANITIZER_FREEBSD diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp index eb351b0..a7805ad 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp @@ -145,6 +145,7 @@ void MemoryMappingLayout::DumpListOfModules( } } +#if SANITIZER_LINUX || SANITIZER_ANDROID || SANITIZER_SOLARIS || SANITIZER_NETBSD void GetMemoryProfile(fill_profile_f cb, uptr *stats) { char *smaps = nullptr; uptr smaps_cap = 0; @@ -184,6 +185,7 @@ void ParseUnixMemoryProfile(fill_profile_f cb, uptr *stats, char *smaps, while (*pos++ != '\n') {} } } +#endif } // namespace __sanitizer -- 2.7.4