[compiler-rt] ad1eb25 - [scudo] Fix return type of GetRSS()
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 22 19:42:00 PST 2022
Author: Vitaly Buka
Date: 2022-12-22T19:41:28-08:00
New Revision: ad1eb251d6821e097662799eaf26e8851cb41c83
URL: https://github.com/llvm/llvm-project/commit/ad1eb251d6821e097662799eaf26e8851cb41c83
DIFF: https://github.com/llvm/llvm-project/commit/ad1eb251d6821e097662799eaf26e8851cb41c83.diff
LOG: [scudo] Fix return type of GetRSS()
Added:
Modified:
compiler-rt/lib/scudo/standalone/common.cpp
compiler-rt/lib/scudo/standalone/common.h
compiler-rt/lib/scudo/standalone/linux.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/common.cpp b/compiler-rt/lib/scudo/standalone/common.cpp
index 67fd2381e701d..9f14faeef283c 100644
--- a/compiler-rt/lib/scudo/standalone/common.cpp
+++ b/compiler-rt/lib/scudo/standalone/common.cpp
@@ -36,7 +36,7 @@ void NORETURN dieOnMapUnmapError(uptr SizeIfOOM) {
}
#if !SCUDO_LINUX
-u64 GetRSS() { return 0; }
+uptr GetRSS() { return 0; }
#endif
} // namespace scudo
diff --git a/compiler-rt/lib/scudo/standalone/common.h b/compiler-rt/lib/scudo/standalone/common.h
index 601481671d71d..2ec9a630359af 100644
--- a/compiler-rt/lib/scudo/standalone/common.h
+++ b/compiler-rt/lib/scudo/standalone/common.h
@@ -132,7 +132,7 @@ u32 getNumberOfCPUs();
const char *getEnv(const char *Name);
-u64 GetRSS();
+uptr GetRSS();
u64 getMonotonicTime();
diff --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp
index 4966b49b1de25..9c5755af5750a 100644
--- a/compiler-rt/lib/scudo/standalone/linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/linux.cpp
@@ -181,7 +181,7 @@ bool getRandom(void *Buffer, uptr Length, UNUSED bool Blocking) {
extern "C" WEAK int async_safe_write_log(int pri, const char *tag,
const char *msg);
-static u64 GetRSSFromBuffer(const char *Buf) {
+static uptr GetRSSFromBuffer(const char *Buf) {
// The format of the file is:
// 1084 89 69 11 0 79 0
// We need the second number which is RSS in pages.
@@ -196,10 +196,13 @@ static u64 GetRSSFromBuffer(const char *Buf) {
u64 Rss = 0;
for (; *Pos >= '0' && *Pos <= '9'; Pos++)
Rss = Rss * 10 + static_cast<u64>(*Pos) - '0';
- return Rss * getPageSizeCached();
+ return static_cast<uptr>(Rss * getPageSizeCached());
}
-u64 GetRSS() {
+uptr GetRSS() {
+ // TODO: We currently use sanitizer_common's GetRSS which reads the
+ // RSS from /proc/self/statm by default. We might want to
+ // call getrusage directly, even if it's less accurate.
auto Fd = open("/proc/self/statm", O_RDONLY);
char Buf[64];
s64 Len = read(Fd, Buf, sizeof(Buf) - 1);
More information about the llvm-commits
mailing list