[compiler-rt] r223730 - [asan] move GetRSS from tsan to sanitizer_common
Alexey Samsonov
vonosmas at gmail.com
Mon Dec 8 17:35:09 PST 2014
On Mon, Dec 8, 2014 at 5:23 PM, Kostya Serebryany <kcc at google.com> wrote:
> Author: kcc
> Date: Mon Dec 8 19:22:59 2014
> New Revision: 223730
>
> URL: http://llvm.org/viewvc/llvm-project?rev=223730&view=rev
> Log:
> [asan] move GetRSS from tsan to sanitizer_common
>
> Modified:
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
> compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h
> compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
> compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc
> compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=223730&r1=223729&r2=223730&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Mon Dec 8
> 19:22:59 2014
> @@ -66,6 +66,7 @@ bool MemoryRangeIsAvailable(uptr range_s
> void FlushUnneededShadowMemory(uptr addr, uptr size);
> void IncreaseTotalMmap(uptr size);
> void DecreaseTotalMmap(uptr size);
> +uptr GetRSS();
>
> // InternalScopedBuffer can be used instead of large stack arrays to
> // keep frame size low.
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=223730&r1=223729&r2=223730&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Mon Dec 8
> 19:22:59 2014
> @@ -379,6 +379,34 @@ static void ReadNullSepFileToArray(const
> }
> (*arr)[count] = 0;
> }
> +
> +uptr GetRSS() {
> + uptr fd = OpenFile("/proc/self/statm", false);
> + if ((sptr)fd < 0)
> + return 0;
>
^^
You should use internal_iserror() here
> + char buf[64];
> + uptr len = internal_read(fd, buf, sizeof(buf) - 1);
>
+ internal_close(fd);
> + if ((sptr)len <= 0)
> + return 0;
>
^^ and probably here.
> + buf[len] = 0;
> + // The format of the file is:
> + // 1084 89 69 11 0 79 0
> + // We need the second number which is RSS in 4K units.
> + char *pos = buf;
> + // Skip the first number.
> + while (*pos >= '0' && *pos <= '9')
> + pos++;
> + // Skip whitespaces.
> + while (!(*pos >= '0' && *pos <= '9') && *pos != 0)
> + pos++;
> + // Read the number.
> + uptr rss = 0;
> + while (*pos >= '0' && *pos <= '9')
> + rss = rss * 10 + *pos++ - '0';
>
I think you can greatly simplify this by using internal_simple_strtoll()
function.
> + return rss * 4096;
> +}
> +
> #endif
>
> static void GetArgsAndEnv(char*** argv, char*** envp) {
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=223730&r1=223729&r2=223730&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Mon Dec 8
> 19:22:59 2014
> @@ -317,6 +317,10 @@ MacosVersion GetMacosVersion() {
> return result;
> }
>
> +uptr GetRSS() {
> + return 0;
> +}
> +
> } // namespace __sanitizer
>
> #endif // SANITIZER_MAC
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=223730&r1=223729&r2=223730&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Mon Dec 8
> 19:22:59 2014
> @@ -375,6 +375,10 @@ uptr internal_rename(const char *oldpath
> UNIMPLEMENTED();
> }
>
> +uptr GetRSS() {
> + return 0;
> +}
> +
> // ---------------------- BlockingMutex ---------------- {{{1
> const uptr LOCK_UNINITIALIZED = 0;
> const uptr LOCK_READY = (uptr)-1;
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h?rev=223730&r1=223729&r2=223730&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h Mon Dec 8 19:22:59 2014
> @@ -251,7 +251,6 @@ uptr ALWAYS_INLINE GetThreadTraceHeader(
> void InitializePlatform();
> void FlushShadowMemory();
> void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr
> nlive);
> -uptr GetRSS();
>
> void *internal_start_thread(void(*func)(void*), void *arg);
> void internal_join_thread(void *th);
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc?rev=223730&r1=223729&r2=223730&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc Mon Dec 8
> 19:22:59 2014
> @@ -118,33 +118,6 @@ void WriteMemoryProfile(char *buf, uptr
> nlive, nthread);
> }
>
> -uptr GetRSS() {
> - uptr fd = OpenFile("/proc/self/statm", false);
> - if ((sptr)fd < 0)
> - return 0;
> - char buf[64];
> - uptr len = internal_read(fd, buf, sizeof(buf) - 1);
> - internal_close(fd);
> - if ((sptr)len <= 0)
> - return 0;
> - buf[len] = 0;
> - // The format of the file is:
> - // 1084 89 69 11 0 79 0
> - // We need the second number which is RSS in 4K units.
> - char *pos = buf;
> - // Skip the first number.
> - while (*pos >= '0' && *pos <= '9')
> - pos++;
> - // Skip whitespaces.
> - while (!(*pos >= '0' && *pos <= '9') && *pos != 0)
> - pos++;
> - // Read the number.
> - uptr rss = 0;
> - while (*pos >= '0' && *pos <= '9')
> - rss = rss * 10 + *pos++ - '0';
> - return rss * 4096;
> -}
> -
> #if SANITIZER_LINUX
> void FlushShadowMemoryCallback(
> const SuspendedThreadsList &suspended_threads_list,
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc?rev=223730&r1=223729&r2=223730&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc Mon Dec 8
> 19:22:59 2014
> @@ -50,10 +50,6 @@ void FlushShadowMemory() {
> void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr
> nlive) {
> }
>
> -uptr GetRSS() {
> - return 0;
> -}
> -
> #ifndef TSAN_GO
> void InitializeShadowMemory() {
> uptr shadow = (uptr)MmapFixedNoReserve(kShadowBeg,
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc?rev=223730&r1=223729&r2=223730&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc Mon Dec 8
> 19:22:59 2014
> @@ -31,10 +31,6 @@ void FlushShadowMemory() {
> void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr
> nlive) {
> }
>
> -uptr GetRSS() {
> - return 0;
> -}
> -
> void InitializePlatform() {
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
--
Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141208/2b4d239e/attachment.html>
More information about the llvm-commits
mailing list