maint: update copyright
[gnulib.git] / lib / vma-iter.h
1 /* Iteration over virtual memory areas.
2    Copyright (C) 2011-2014 Free Software Foundation, Inc.
3    Written by Bruno Haible <bruno@clisp.org>, 2011.
4
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.
9
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.
14
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/>.  */
17
18 #ifndef _VMA_ITER_H
19 #define _VMA_ITER_H
20
21 #include <stdint.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27
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)
32
33 typedef int (*vma_iterate_callback_fn) (void *data,
34                                         uintptr_t start, uintptr_t end,
35                                         unsigned int flags);
36
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 extern void vma_iterate (vma_iterate_callback_fn callback, void *data);
49
50 /* The macro VMA_ITERATE_SUPPORTED indicates that vma_iterate is supported on
51    this platform.
52    Note that even when this macro is defined, vma_iterate() may still fail to
53    find any virtual memory area, for example if /proc is not mounted.  */
54 #if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __sgi || defined __osf__ || (defined __APPLE__ && defined __MACH__) || (defined _WIN32 || defined __WIN32__) || defined __CYGWIN__ || defined __BEOS__ || defined __HAIKU__ || HAVE_MQUERY
55 # define VMA_ITERATE_SUPPORTED 1
56 #endif
57
58
59 #ifdef __cplusplus
60 }
61 #endif
62
63 #endif /* _VMA_ITER_H */