summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2017-03-19 14:19:07 +0100
committerBruno Haible <bruno@clisp.org>2017-03-19 14:19:07 +0100
commitbfd9640a37b36b6b4dd3712c6cf6dc76560126da (patch)
tree25888f185d87d86d605d69a3f81fb202d32d4ee5
parent751d63a4aaac787d43357534feac4db3732e68c7 (diff)
downloadgnulib-bfd9640a37b36b6b4dd3712c6cf6dc76560126da.tar.gz
vma-iter: Prefer HP-UX specific API on HP-UX.
* lib/vma-iter.c (vma_iterate): Move HP-UX specific implementation up. * lib/vma-iter.h: Update. Just in case HP-UX ever implements mquery().
-rw-r--r--ChangeLog7
-rw-r--r--lib/vma-iter.c66
-rw-r--r--lib/vma-iter.h2
3 files changed, 41 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index 396b0b8538..311d45c93e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-03-19 Bruno Haible <bruno@clisp.org>
+
+ vma-iter: Prefer HP-UX specific API on HP-UX.
+ * lib/vma-iter.c (vma_iterate): Move HP-UX specific implementation up.
+ * lib/vma-iter.h: Update.
+ Just in case HP-UX ever implements mquery().
+
2017-03-18 Paul Eggert <eggert@cs.ucla.edu>
stdalign: restore previous behavior for HP-UX IA64
diff --git a/lib/vma-iter.c b/lib/vma-iter.c
index b9036ae4e6..2a12449a78 100644
--- a/lib/vma-iter.c
+++ b/lib/vma-iter.c
@@ -32,6 +32,10 @@
# include <sys/procfs.h> /* PIOC*, prmap_t */
#endif
+#if HAVE_PSTAT_GETPROCVM /* HP-UX */
+# include <sys/pstat.h> /* pstat_getprocvm */
+#endif
+
#if defined __APPLE__ && defined __MACH__ /* Mac OS X */
# include <mach/mach.h>
#endif
@@ -49,10 +53,6 @@
# include <sys/mman.h> /* mquery */
#endif
-#if HAVE_PSTAT_GETPROCVM /* HP-UX */
-# include <sys/pstat.h> /* pstat_getprocvm */
-#endif
-
/* Note: On AIX, there is a /proc/$pic/map file, that contains records of type
prmap_t, defined in <sys/procfs.h>. But it lists only the virtual memory
areas that are connected to a file, not the anonymous ones. */
@@ -369,6 +369,35 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
close (fd);
return -1;
+#elif HAVE_PSTAT_GETPROCVM /* HP-UX */
+
+ unsigned long pagesize = getpagesize ();
+ int i;
+
+ for (i = 0; ; i++)
+ {
+ struct pst_vm_status info;
+ int ret = pstat_getprocvm (&info, sizeof (info), 0, i);
+ if (ret < 0)
+ return -1;
+ if (ret == 0)
+ break;
+ {
+ unsigned long start = info.pst_vaddr;
+ unsigned long end = start + info.pst_length * pagesize;
+ unsigned int flags = 0;
+ if (info.pst_permission & PS_PROT_READ)
+ flags |= VMA_PROT_READ;
+ if (info.pst_permission & PS_PROT_WRITE)
+ flags |= VMA_PROT_WRITE;
+ if (info.pst_permission & PS_PROT_EXECUTE)
+ flags |= VMA_PROT_EXECUTE;
+
+ if (callback (data, start, end, flags))
+ break;
+ }
+ }
+
#elif defined __APPLE__ && defined __MACH__ /* Mac OS X */
task_t task = mach_task_self ();
@@ -602,35 +631,6 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
}
return 0;
-#elif HAVE_PSTAT_GETPROCVM /* HP-UX */
-
- unsigned long pagesize = getpagesize ();
- int i;
-
- for (i = 0; ; i++)
- {
- struct pst_vm_status info;
- int ret = pstat_getprocvm (&info, sizeof (info), 0, i);
- if (ret < 0)
- return -1;
- if (ret == 0)
- break;
- {
- unsigned long start = info.pst_vaddr;
- unsigned long end = start + info.pst_length * pagesize;
- unsigned int flags = 0;
- if (info.pst_permission & PS_PROT_READ)
- flags |= VMA_PROT_READ;
- if (info.pst_permission & PS_PROT_WRITE)
- flags |= VMA_PROT_WRITE;
- if (info.pst_permission & PS_PROT_EXECUTE)
- flags |= VMA_PROT_EXECUTE;
-
- if (callback (data, start, end, flags))
- break;
- }
- }
-
#else
/* Not implemented. */
diff --git a/lib/vma-iter.h b/lib/vma-iter.h
index c989e7f1ba..b1acaa2b54 100644
--- a/lib/vma-iter.h
+++ b/lib/vma-iter.h
@@ -52,7 +52,7 @@ extern int vma_iterate (vma_iterate_callback_fn callback, void *data);
this platform.
Note that even when this macro is defined, vma_iterate() may still fail to
find any virtual memory area, for example if /proc is not mounted. */
-#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 || HAVE_PSTAT_GETPROCVM
+#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __sgi || defined __osf__ || HAVE_PSTAT_GETPROCVM || (defined __APPLE__ && defined __MACH__) || (defined _WIN32 || defined __WIN32__) || defined __CYGWIN__ || defined __BEOS__ || defined __HAIKU__ || HAVE_MQUERY
# define VMA_ITERATE_SUPPORTED 1
#endif