annotate lib/vma-iter.h @ 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 b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14220
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Iteration over virtual memory areas.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19595
diff changeset
2 Copyright (C) 2011-2019 Free Software Foundation, Inc.
14220
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2011.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18784
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
14220
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #ifndef _VMA_ITER_H
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #define _VMA_ITER_H
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdint.h>
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #ifdef __cplusplus
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 extern "C" {
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #endif
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 /* Bit mask for the FLAGS parameter of a vma_iterate callback function. */
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #define VMA_PROT_READ (1<<0)
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #define VMA_PROT_WRITE (1<<1)
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #define VMA_PROT_EXECUTE (1<<2)
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 typedef int (*vma_iterate_callback_fn) (void *data,
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 uintptr_t start, uintptr_t end,
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 unsigned int flags);
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 /* Iterate over the virtual memory areas of the current process.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 If such iteration is supported, the callback is called once for every
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 virtual memory area, in ascending order, with the following arguments:
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 - DATA is the same argument as passed to vma_iterate.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 - START is the address of the first byte in the area, page-aligned.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 - END is the address of the last byte in the area plus 1, page-aligned.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 Note that it may be 0 for the last area in the address space.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 - FLAGS is a combination of the VMA_* bits.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 If the callback returns 0, the iteration continues. If it returns 1,
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 the iteration terminates prematurely.
18727
6e02cce8c632 vma-iter: Let callers know about error.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
47 This function may open file descriptors, but does not call malloc().
6e02cce8c632 vma-iter: Let callers know about error.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
48 Return 0 if all went well, or -1 in case of error. */
6e02cce8c632 vma-iter: Let callers know about error.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
49 extern int vma_iterate (vma_iterate_callback_fn callback, void *data);
14220
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 /* The macro VMA_ITERATE_SUPPORTED indicates that vma_iterate is supported on
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 this platform.
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 Note that even when this macro is defined, vma_iterate() may still fail to
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 find any virtual memory area, for example if /proc is not mounted. */
40149
e1f68c6256cf vma-iter: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
55 #if defined __linux__ || defined __ANDROID__ || defined __GNU__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __sgi || defined __osf__ || defined __sun || HAVE_PSTAT_GETPROCVM || (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __CYGWIN__ || defined __BEOS__ || defined __HAIKU__ || defined __minix || HAVE_MQUERY
14220
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 # define VMA_ITERATE_SUPPORTED 1
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 #endif
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 #ifdef __cplusplus
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 #endif
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
996391c07734 New module 'vma-iter'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 #endif /* _VMA_ITER_H */