about summary refs log tree commit diff
path: root/sysdeps/mach
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/mach')
-rw-r--r--sysdeps/mach/hurd/mlock.c13
-rw-r--r--sysdeps/mach/hurd/munlock.c12
2 files changed, 14 insertions, 11 deletions
diff --git a/sysdeps/mach/hurd/mlock.c b/sysdeps/mach/hurd/mlock.c
index 10078e7f80..8ef568ea4c 100644
--- a/sysdeps/mach/hurd/mlock.c
+++ b/sysdeps/mach/hurd/mlock.c
@@ -28,19 +28,20 @@
 int
 mlock (const void *addr, size_t len)
 {
-  mach_port_t hostpriv;
+  mach_port_t host;
   vm_address_t page;
   error_t err;
 
-  err = __get_privileged_ports (&hostpriv, NULL);
+  err = __get_privileged_ports (&host, NULL);
   if (err)
-    return __hurd_fail (EPERM);
+    host = __mach_host_self();
 
   page = trunc_page ((vm_address_t) addr);
   len = round_page ((vm_address_t) addr + len) - page;
-  err = __vm_wire (hostpriv, __mach_task_self (), page, len,
-		   VM_PROT_READ);
-  __mach_port_deallocate (__mach_task_self (), hostpriv);
+
+  err = __vm_wire (host, __mach_task_self (), page, len, VM_PROT_READ);
+  if (host != __mach_host_self())
+    __mach_port_deallocate (__mach_task_self (), host);
 
   return err ? __hurd_fail (err) : 0;
 }
diff --git a/sysdeps/mach/hurd/munlock.c b/sysdeps/mach/hurd/munlock.c
index 411115df46..d063afc9c9 100644
--- a/sysdeps/mach/hurd/munlock.c
+++ b/sysdeps/mach/hurd/munlock.c
@@ -27,18 +27,20 @@
 int
 munlock (const void *addr, size_t len)
 {
-  mach_port_t hostpriv;
+  mach_port_t host;
   vm_address_t page;
   error_t err;
 
-  err = __get_privileged_ports (&hostpriv, NULL);
+  err = __get_privileged_ports (&host, NULL);
   if (err)
-    return __hurd_fail (EPERM);
+    host = __mach_host_self();
 
   page = trunc_page ((vm_address_t) addr);
   len = round_page ((vm_address_t) addr + len) - page;
-  err = __vm_wire (hostpriv, __mach_task_self (), page, len, VM_PROT_NONE);
-  __mach_port_deallocate (__mach_task_self (), hostpriv);
+
+  err = __vm_wire (host, __mach_task_self (), page, len, VM_PROT_NONE);
+  if (host != __mach_host_self())
+    __mach_port_deallocate (__mach_task_self (), host);
 
   return err ? __hurd_fail (err) : 0;
 }