stat: Improve last change.
[gnulib.git] / lib / vma-iter.h
blob95374efb65bed59bbcb073f35b19ed4f0e540629
1 /* Iteration over virtual memory areas.
2 Copyright (C) 2011-2017 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2011.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #ifndef _VMA_ITER_H
19 #define _VMA_ITER_H
21 #include <stdint.h>
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
28 /* Bit mask for the FLAGS parameter of a vma_iterate callback function. */
29 #define VMA_PROT_READ (1<<0)
30 #define VMA_PROT_WRITE (1<<1)
31 #define VMA_PROT_EXECUTE (1<<2)
33 typedef int (*vma_iterate_callback_fn) (void *data,
34 uintptr_t start, uintptr_t end,
35 unsigned int flags);
37 /* Iterate over the virtual memory areas of the current process.
38 If such iteration is supported, the callback is called once for every
39 virtual memory area, in ascending order, with the following arguments:
40 - DATA is the same argument as passed to vma_iterate.
41 - START is the address of the first byte in the area, page-aligned.
42 - END is the address of the last byte in the area plus 1, page-aligned.
43 Note that it may be 0 for the last area in the address space.
44 - FLAGS is a combination of the VMA_* bits.
45 If the callback returns 0, the iteration continues. If it returns 1,
46 the iteration terminates prematurely.
47 This function may open file descriptors, but does not call malloc().
48 Return 0 if all went well, or -1 in case of error. */
49 extern int vma_iterate (vma_iterate_callback_fn callback, void *data);
51 /* The macro VMA_ITERATE_SUPPORTED indicates that vma_iterate is supported on
52 this platform.
53 Note that even when this macro is defined, vma_iterate() may still fail to
54 find any virtual memory area, for example if /proc is not mounted. */
55 #if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __sgi || defined __osf__ || (defined __sun && HAVE_SYS_PROCFS_H) || HAVE_PSTAT_GETPROCVM || (defined __APPLE__ && defined __MACH__) || (defined _WIN32 || defined __WIN32__) || defined __CYGWIN__ || defined __BEOS__ || defined __HAIKU__ || HAVE_MQUERY
56 # define VMA_ITERATE_SUPPORTED 1
57 #endif
60 #ifdef __cplusplus
62 #endif
64 #endif /* _VMA_ITER_H */