NetBSD:
a) setrlimit with RLIMIT_AS works.
- b) No VMA iteration API exists.
+ b) The /proc/self/maps file contains a list of the virtual memory areas.
+ Both methods agree,
OpenBSD:
a) setrlimit exists, but RLIMIT_AS is not defined.
if (getrlimit (RLIMIT_AS, &orig_limit) < 0)
{
result = 0;
- goto done;
+ goto done2;
}
if (orig_limit.rlim_max != RLIM_INFINITY
So bail out. */
{
result = 0;
- goto done;
+ goto done2;
}
{
{
/* try_next could not be increased. */
result = low_bound;
- goto done;
+ goto done1;
}
try_limit.rlim_max = orig_limit.rlim_max;
result = low_bound;
}
+ done1:
/* Restore the original rlim_cur value. */
if (setrlimit (RLIMIT_AS, &orig_limit) < 0)
abort ();
- done:
+ done2:
# if !HAVE_MAP_ANONYMOUS
close (fd);
# endif
/* Support for reading text files in the /proc file system. */
-#if defined __linux__ || defined __FreeBSD__ /* || defined __CYGWIN__ */
+#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ /* || defined __CYGWIN__ */
/* Buffered read-only streams.
We cannot use <stdio.h> here, because fopen() calls malloc(), and a malloc()
rof_close (&rof);
return total;
-#elif defined __FreeBSD__
+#elif defined __FreeBSD__ || defined __NetBSD__
struct rofile rof;
int c;
while (VirtualQuery ((void*)address, &info, sizeof(info)) == sizeof(info))
{
if (info.State != MEM_FREE)
- total += info.RegionSize;
+ /* Ignore areas where info.Protect has the undocumented value 0.
+ This is needed, so that on Cygwin, areas used by malloc() are
+ distinguished from areas reserved for future malloc(). */
+ if (info.Protect != 0)
+ total += info.RegionSize;
address = (unsigned long)info.BaseAddress + info.RegionSize;
}
return total;