]> Savannah Git Hosting - gnulib.git/commitdiff
vma-iter: Improve support for GNU/Hurd.
authorBruno Haible <bruno@clisp.org>
Sat, 7 Oct 2017 10:59:23 +0000 (12:59 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 7 Oct 2017 11:00:52 +0000 (13:00 +0200)
* lib/vma-iter.c (vma_iterate): On GNU/Hurd, use the Mach vm_region()
API, not the /proc file system.

ChangeLog
lib/vma-iter.c

index 8d18287c7a44d3dba882ab236537c9e433a9dda5..894c3c6c27fc0edb57d5aa316e743ea2a7438f38 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-10-07  Bruno Haible  <bruno@clisp.org>
+
+       vma-iter: Improve support for GNU/Hurd.
+       * lib/vma-iter.c (vma_iterate): On GNU/Hurd, use the Mach vm_region()
+       API, not the /proc file system.
+
 2017-10-07  Bruno Haible  <bruno@clisp.org>
 
        test-framework-sh: Don't require bash on Windows and OS/2.
index 5549ecab324620279c2dc5fe7b561fe011606ba9..0fb88343336e4ef3ac7a9c2cc69ac34cf88bc679 100644 (file)
@@ -34,7 +34,7 @@
 #include <fcntl.h> /* open, O_RDONLY */
 #include <unistd.h> /* getpagesize, lseek, read, close, getpid */
 
-#if defined __linux__ || defined __GNU__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ /* || defined __CYGWIN__ */
+#if defined __linux__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ /* || defined __CYGWIN__ */
 # include <sys/types.h>
 # include <sys/mman.h> /* mmap, munmap */
 #endif
 # include <mach/mach.h>
 #endif
 
+#if defined __GNU__ /* GNU/Hurd */
+# include <mach/mach.h>
+#endif
+
 #if (defined _WIN32 || defined __WIN32__) || defined __CYGWIN__ /* Windows */
 # include <windows.h>
 #endif
@@ -95,7 +99,7 @@
 
 /* Support for reading text files in the /proc file system.  */
 
-#if defined __linux__ || defined __GNU__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ /* || defined __CYGWIN__ */
+#if defined __linux__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ /* || defined __CYGWIN__ */
 
 /* Buffered read-only streams.
    We cannot use <stdio.h> here, because fopen() calls malloc(), and a malloc()
@@ -557,7 +561,7 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data)
 int
 vma_iterate (vma_iterate_callback_fn callback, void *data)
 {
-#if defined __linux__ || defined __GNU__ || (defined __FreeBSD_kernel__ && !defined __FreeBSD__) /* || defined __CYGWIN__ */
+#if defined __linux__ || (defined __FreeBSD_kernel__ && !defined __FreeBSD__) /* || defined __CYGWIN__ */
   /* GNU/kFreeBSD mounts /proc as linprocfs, which looks like a Linux /proc
      file system.  */
 
@@ -1186,6 +1190,45 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
     }
   return 0;
 
+#elif defined __GNU__ /* GNU/Hurd */
+
+  /* The Hurd has a /proc/self/maps that looks like the Linux one, but it
+     lacks the VMAs created through anonymous mmap.  Therefore use the Mach
+     API.
+     Documentation:
+     https://www.gnu.org/software/hurd/gnumach-doc/Memory-Attributes.html */
+
+  task_t task = mach_task_self ();
+  vm_address_t address;
+  vm_size_t size;
+
+  for (address = 0;; address += size)
+    {
+      vm_prot_t protection;
+      vm_prot_t max_protection;
+      vm_inherit_t inheritance;
+      boolean_t shared;
+      memory_object_name_t object_name;
+      vm_offset_t offset;
+      unsigned int flags;
+
+      if (!(vm_region (task, &address, &size, &protection, &max_protection,
+                         &inheritance, &shared, &object_name, &offset)
+            == KERN_SUCCESS))
+        break;
+      mach_port_deallocate (task, object_name);
+      flags = 0;
+      if (protection & VM_PROT_READ)
+        flags |= VMA_PROT_READ;
+      if (protection & VM_PROT_WRITE)
+        flags |= VMA_PROT_WRITE;
+      if (protection & VM_PROT_EXECUTE)
+        flags |= VMA_PROT_EXECUTE;
+      if (callback (data, address, address + size, flags))
+        break;
+    }
+  return 0;
+
 #elif (defined _WIN32 || defined __WIN32__) || defined __CYGWIN__
   /* Windows platform.  Use the native Windows API.  */