>From 1e79c6c34369192a103bf71eff17b5d6da555388 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 7 Oct 2017 12:59:23 +0200 Subject: [PATCH] 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. --- ChangeLog | 6 ++++++ lib/vma-iter.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8d18287..894c3c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2017-10-07 Bruno Haible + 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 + test-framework-sh: Don't require bash on Windows and OS/2. Reported by KO Myung-Hun. * tests/test-init.sh: Use 'shopt' only when running in bash. diff --git a/lib/vma-iter.c b/lib/vma-iter.c index 5549eca..0fb8834 100644 --- a/lib/vma-iter.c +++ b/lib/vma-iter.c @@ -34,7 +34,7 @@ #include /* open, O_RDONLY */ #include /* 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 # include /* mmap, munmap */ #endif @@ -75,6 +75,10 @@ # include #endif +#if defined __GNU__ /* GNU/Hurd */ +# include +#endif + #if (defined _WIN32 || defined __WIN32__) || defined __CYGWIN__ /* Windows */ # include #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 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. */ -- 2.7.4