comparison lib/vma-iter.c @ 40149:e1f68c6256cf

vma-iter: Add support for Android. * lib/vma-iter.h (VMA_ITERATE_SUPPORTED): Define on Android as well. * lib/vma-iter.c: Treat Android like Linux. * lib/get-rusage-data.c (get_rusage_data): Likewise.
author Bruno Haible <bruno@clisp.org>
date Sun, 27 Jan 2019 04:57:29 +0100
parents f63c4e7dfb31
children
comparison
equal deleted inserted replaced
40148:5be6b690b930 40149:e1f68c6256cf
38 #include <errno.h> /* errno */ 38 #include <errno.h> /* errno */
39 #include <stdlib.h> /* size_t */ 39 #include <stdlib.h> /* size_t */
40 #include <fcntl.h> /* open, O_RDONLY */ 40 #include <fcntl.h> /* open, O_RDONLY */
41 #include <unistd.h> /* getpagesize, lseek, read, close, getpid */ 41 #include <unistd.h> /* getpagesize, lseek, read, close, getpid */
42 42
43 #if defined __linux__ 43 #if defined __linux__ || defined __ANDROID__
44 # include <limits.h> /* PATH_MAX */ 44 # include <limits.h> /* PATH_MAX */
45 #endif 45 #endif
46 46
47 #if defined __linux__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */ 47 #if defined __linux__ || defined __ANDROID__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */
48 # include <sys/types.h> 48 # include <sys/types.h>
49 # include <sys/mman.h> /* mmap, munmap */ 49 # include <sys/mman.h> /* mmap, munmap */
50 #endif 50 #endif
51 #if defined __minix 51 #if defined __minix
52 # include <string.h> /* memcpy */ 52 # include <string.h> /* memcpy */
110 areas that are connected to a file, not the anonymous ones. */ 110 areas that are connected to a file, not the anonymous ones. */
111 111
112 112
113 /* Support for reading text files in the /proc file system. */ 113 /* Support for reading text files in the /proc file system. */
114 114
115 #if defined __linux__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */ 115 #if defined __linux__ || defined __ANDROID__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */
116 116
117 /* Buffered read-only streams. 117 /* Buffered read-only streams.
118 We cannot use <stdio.h> here, because fopen() calls malloc(), and a malloc() 118 We cannot use <stdio.h> here, because fopen() calls malloc(), and a malloc()
119 call may call mmap() and thus pre-allocate available memory. 119 call may call mmap() and thus pre-allocate available memory.
120 Also, we cannot use multiple read() calls, because if the buffer size is 120 Also, we cannot use multiple read() calls, because if the buffer size is
127 result of these two read() calls don't fit together, and as a 127 result of these two read() calls don't fit together, and as a
128 consequence we will parse garbage and either omit some VMAs or return 128 consequence we will parse garbage and either omit some VMAs or return
129 VMAs with nonsensical addresses. 129 VMAs with nonsensical addresses.
130 So use mmap(), and ignore the resulting VMA. */ 130 So use mmap(), and ignore the resulting VMA. */
131 131
132 # ifdef __linux__ 132 # if defined __linux__ || defined __ANDROID__
133 /* On Linux, if the file does not entirely fit into the buffer, the read() 133 /* On Linux, if the file does not entirely fit into the buffer, the read()
134 function stops before the line that would come out truncated. The 134 function stops before the line that would come out truncated. The
135 maximum size of such a line is 73 + PATH_MAX bytes. To be sure that we 135 maximum size of such a line is 73 + PATH_MAX bytes. To be sure that we
136 have read everything, we must verify that at least that many bytes are 136 have read everything, we must verify that at least that many bytes are
137 left when read() returned. */ 137 left when read() returned. */
203 goto fail1; 203 goto fail1;
204 if (n + MIN_LEFTOVER <= size) 204 if (n + MIN_LEFTOVER <= size)
205 { 205 {
206 /* The buffer was sufficiently large. */ 206 /* The buffer was sufficiently large. */
207 rof->filled = n; 207 rof->filled = n;
208 # ifdef __linux__ 208 # if defined __linux__ || defined __ANDROID__
209 /* On Linux, the read() call may stop even if the buffer was 209 /* On Linux, the read() call may stop even if the buffer was
210 large enough. We need the equivalent of full_read(). */ 210 large enough. We need the equivalent of full_read(). */
211 for (;;) 211 for (;;)
212 { 212 {
213 n = read (fd, rof->buffer + rof->filled, size - rof->filled); 213 n = read (fd, rof->buffer + rof->filled, size - rof->filled);
340 #endif 340 #endif
341 341
342 342
343 /* Support for reading the info from a text file in the /proc file system. */ 343 /* Support for reading the info from a text file in the /proc file system. */
344 344
345 #if defined __linux__ || (defined __FreeBSD_kernel__ && !defined __FreeBSD__) /* || defined __CYGWIN__ */ 345 #if defined __linux__ || defined __ANDROID__ || (defined __FreeBSD_kernel__ && !defined __FreeBSD__) /* || defined __CYGWIN__ */
346 /* GNU/kFreeBSD mounts /proc as linprocfs, which looks like a Linux /proc 346 /* GNU/kFreeBSD mounts /proc as linprocfs, which looks like a Linux /proc
347 file system. */ 347 file system. */
348 348
349 static int 349 static int
350 vma_iterate_proc (vma_iterate_callback_fn callback, void *data) 350 vma_iterate_proc (vma_iterate_callback_fn callback, void *data)
864 864
865 865
866 int 866 int
867 vma_iterate (vma_iterate_callback_fn callback, void *data) 867 vma_iterate (vma_iterate_callback_fn callback, void *data)
868 { 868 {
869 #if defined __linux__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */ 869 #if defined __linux__ || defined __ANDROID__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */
870 870
871 # if defined __FreeBSD__ 871 # if defined __FreeBSD__
872 /* On FreeBSD with procfs (but not GNU/kFreeBSD, which uses linprocfs), the 872 /* On FreeBSD with procfs (but not GNU/kFreeBSD, which uses linprocfs), the
873 function vma_iterate_proc does not return the virtual memory areas that 873 function vma_iterate_proc does not return the virtual memory areas that
874 were created by anonymous mmap. See 874 were created by anonymous mmap. See