]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/mach/hurd/munlock.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / mach / hurd / munlock.c
index c03af90cb8f21b5601b1065dc94620f00f388e09..abd36e072edb0a9b5ac98786d0e90f4353d2f9b9 100644 (file)
@@ -1,5 +1,5 @@
 /* munlock -- undo the effects of prior mlock calls.  Mach/Hurd version.
-   Copyright (C) 2001-2014 Free Software Foundation, Inc.
+   Copyright (C) 2001-2020 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -14,7 +14,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 #include <sys/types.h>
 #include <sys/mman.h>
 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;
 }