Samuel Thibault, le Wed 08 Jul 2015 18:22:56 +0200, a écrit : > Justus Winter, le Wed 08 Jul 2015 16:22:28 +0200, a écrit : > > Alternatively, you could re-purpose the existing RPC `vm_wire', > > changing the type of its first argument from `host_priv_t' to `host_t' > > (this is backwards compatible as the privileged host control port is > > also a host port), and changing the behavior slightly depending on > > whether the user passed the priv port or a normal host port. > > Ok, so it'd look like this? (I can't reuse the intran, since the > obtained host_t is the same in non-priv and priv cases).
I forgot the glibc part, which becomes different. Samuel
diff --git a/sysdeps/mach/hurd/mlock.c b/sysdeps/mach/hurd/mlock.c index 14c311c..ed54166 100644 --- a/sysdeps/mach/hurd/mlock.c +++ b/sysdeps/mach/hurd/mlock.c @@ -28,19 +28,21 @@ 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); - if (err) - return __hurd_fail (EPERM); - 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, + + err = __get_privileged_ports (&host, NULL); + if (err) + host = __mach_host_self(); + + err = __vm_wire (host, __mach_task_self (), page, len, VM_PROT_READ); - __mach_port_deallocate (__mach_task_self (), hostpriv); + 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 c03af90..e2fe21c 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); - if (err) - return __hurd_fail (EPERM); - 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 = __get_privileged_ports (&host, NULL); + if (err) + host = __mach_host_self(); + + 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; }