[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: vma-iter: support Solaris
From: |
Bruno Haible |
Subject: |
Re: vma-iter: support Solaris |
Date: |
Wed, 19 Apr 2017 01:28:44 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-72-generic; KDE/5.18.0; x86_64; ; ) |
Tom G. Christensen wrote:
> On Solaris 2.6 and 7 there is the additional issue of missing MAP_ANONYMOUS:
>
> In file included from vma-iter.c:41:0:
> /usr/include/sys/procfs.h:44:2: error: #error "Cannot use procfs in the
> large file compilation environment"
> vma-iter.c: In function 'vma_iterate':
> vma-iter.c:545:27: error: 'MAP_ANONYMOUS' undeclared (first use in this
> function)
> vma-iter.c:545:27: note: each undeclared identifier is reported only
> once for each function it appears in
> make[4]: *** [vma-iter.o] Error 1
Fixed as follows. Thanks for the report!
2017-04-18 Bruno Haible <address@hidden>
vma-iter: Fix compilation error on Solaris 7.
* lib/vma-iter.c (vma_iterate): Treat missing MAP_ANONYMOUS on Solaris
like on IRIX, OSF/1.
Reported by Tom G. Christensen <address@hidden>.
diff --git a/lib/vma-iter.c b/lib/vma-iter.c
index d4bae13..e81b8ea 100644
--- a/lib/vma-iter.c
+++ b/lib/vma-iter.c
@@ -399,6 +399,13 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
int fd;
int nmaps;
size_t memneed;
+# if HAVE_MAP_ANONYMOUS
+# define zero_fd -1
+# define map_flags MAP_ANONYMOUS
+# else /* Solaris <= 7 */
+ int zero_fd;
+# define map_flags 0
+# endif
void *auxmap;
unsigned long auxmap_start;
unsigned long auxmap_end;
@@ -433,8 +440,16 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
and thus pre-allocate available memory.
So use mmap(), and ignore the resulting VMA. */
memneed = ((memneed - 1) / pagesize + 1) * pagesize;
+# if !HAVE_MAP_ANONYMOUS
+ zero_fd = open ("/dev/zero", O_RDONLY, 0644);
+ if (zero_fd < 0)
+ goto fail2;
+# endif
auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ map_flags | MAP_PRIVATE, zero_fd, 0);
+# if !HAVE_MAP_ANONYMOUS
+ close (zero_fd);
+# endif
if (auxmap == (void *) -1)
goto fail2;
auxmap_start = (unsigned long) auxmap;
@@ -502,6 +517,13 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
int fd;
int nmaps;
size_t memneed;
+# if HAVE_MAP_ANONYMOUS
+# define zero_fd -1
+# define map_flags MAP_ANONYMOUS
+# else /* Solaris <= 7 */
+ int zero_fd;
+# define map_flags 0
+# endif
void *auxmap;
unsigned long auxmap_start;
unsigned long auxmap_end;
@@ -541,8 +563,16 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
and thus pre-allocate available memory.
So use mmap(), and ignore the resulting VMA. */
memneed = ((memneed - 1) / pagesize + 1) * pagesize;
+# if !HAVE_MAP_ANONYMOUS
+ zero_fd = open ("/dev/zero", O_RDONLY, 0644);
+ if (zero_fd < 0)
+ goto fail2;
+# endif
auxmap = (void *) mmap ((void *) 0, memneed, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ map_flags | MAP_PRIVATE, zero_fd, 0);
+# if !HAVE_MAP_ANONYMOUS
+ close (zero_fd);
+# endif
if (auxmap == (void *) -1)
goto fail2;
auxmap_start = (unsigned long) auxmap;