X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fget-rusage-as.c;h=7cf20006054cbea12f044ba3a3b35008207bc1e5;hb=1276a2c5f24c0c932426aca9c899fa524d2443f2;hp=41363c547fd4f43c11fe925f30cb830019196c4c;hpb=fe810bf8507a92354b4750e6dd1b3bd974ab7fc5;p=gnulib.git diff --git a/lib/get-rusage-as.c b/lib/get-rusage-as.c index 41363c547..7cf200060 100644 --- a/lib/get-rusage-as.c +++ b/lib/get-rusage-as.c @@ -1,5 +1,5 @@ /* Getter for RLIMIT_AS. - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011-2014 Free Software Foundation, Inc. Written by Bruno Haible , 2011. This program is free software: you can redistribute it and/or modify @@ -49,7 +49,7 @@ get_rusage_as_via_iterator() is 4 KB higher than get_rusage_as_via_setrlimit(). - MacOS X: + Mac OS X: a) setrlimit with RLIMIT_AS succeeds but does not really work: The OS ignores RLIMIT_AS. mmap() of a page always succeeds, therefore get_rusage_as_via_setrlimit() is always 0. @@ -66,7 +66,7 @@ OpenBSD: a) setrlimit exists, but RLIMIT_AS is not defined. - b) No VMA iteration API exists. + b) mquery() can be used to find out about the virtual memory areas. AIX: a) setrlimit with RLIMIT_AS succeeds but does not really work: The OS @@ -98,11 +98,11 @@ get_rusage_as_via_setrlimit() therefore produces a wrong value. b) The /proc/$pid/maps file lists only the memory areas belonging to the executable and shared libraries, not the anonymous memory. - But the native Win32 API works. + But the native Windows API works. mingw: a) There is no setrlimit function. - b) The native Win32 API works. + b) The native Windows API works. BeOS, Haiku: a) On BeOS, there is no setrlimit function. @@ -146,7 +146,7 @@ #if HAVE_SETRLIMIT && defined RLIMIT_AS && HAVE_SYS_MMAN_H && HAVE_MPROTECT -static inline uintptr_t +static uintptr_t get_rusage_as_via_setrlimit (void) { uintptr_t result; @@ -308,6 +308,14 @@ get_rusage_as_via_setrlimit (void) return result; } +#else + +static uintptr_t +get_rusage_as_via_setrlimit (void) +{ + return 0; +} + #endif @@ -323,7 +331,7 @@ vma_iterate_callback (void *data, uintptr_t start, uintptr_t end, return 0; } -static inline uintptr_t +static uintptr_t get_rusage_as_via_iterator (void) { uintptr_t total = 0; @@ -335,7 +343,7 @@ get_rusage_as_via_iterator (void) #else -static inline uintptr_t +static uintptr_t get_rusage_as_via_iterator (void) { return 0; @@ -347,7 +355,7 @@ get_rusage_as_via_iterator (void) uintptr_t get_rusage_as (void) { -#if (defined __APPLE__ && defined __MACH__) || defined _AIX || defined __CYGWIN__ /* MacOS X, AIX, Cygwin */ +#if (defined __APPLE__ && defined __MACH__) || defined _AIX || defined __CYGWIN__ /* Mac OS X, AIX, Cygwin */ /* get_rusage_as_via_setrlimit() does not work. Prefer get_rusage_as_via_iterator(). */ return get_rusage_as_via_iterator (); @@ -364,3 +372,31 @@ get_rusage_as (void) return get_rusage_as_via_iterator (); #endif } + + +#ifdef TEST + +#include + +int +main () +{ + printf ("Initially: 0x%08lX 0x%08lX 0x%08lX\n", + get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (), + get_rusage_as ()); + malloc (0x88); + printf ("After small malloc: 0x%08lX 0x%08lX 0x%08lX\n", + get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (), + get_rusage_as ()); + malloc (0x8812); + printf ("After medium malloc: 0x%08lX 0x%08lX 0x%08lX\n", + get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (), + get_rusage_as ()); + malloc (0x281237); + printf ("After large malloc: 0x%08lX 0x%08lX 0x%08lX\n", + get_rusage_as_via_setrlimit (), get_rusage_as_via_iterator (), + get_rusage_as ()); + return 0; +} + +#endif /* TEST */