aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/mach/hurd/mlock.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2015-07-09 13:56:30 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2015-07-09 13:56:30 +0200
commited4060f50ea84c7e238110955253647fc091aee9 (patch)
treedc91dd319ec29adf2120b970e3b732b93f371ef3 /sysdeps/mach/hurd/mlock.c
parentb8528e771c0f31ebb8ac2470e2cf7ee9a50693e2 (diff)
downloadglibc-ed4060f50ea84c7e238110955253647fc091aee9.tar
glibc-ed4060f50ea84c7e238110955253647fc091aee9.tar.gz
glibc-ed4060f50ea84c7e238110955253647fc091aee9.tar.bz2
glibc-ed4060f50ea84c7e238110955253647fc091aee9.zip
hurd: permit to use mlock from non-root process
* sysdeps/mach/hurd/mlock.c (mlock): When __get_privileged_ports returns an error, also try to use host port from __mach_host_self for the __vm_wire call. * sysdeps/mach/hurd/munlock.c (munlock): Likewise.
Diffstat (limited to 'sysdeps/mach/hurd/mlock.c')
-rw-r--r--sysdeps/mach/hurd/mlock.c13
1 files changed, 7 insertions, 6 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;
}