diff options
author | Sergey Bugaev <bugaevc@gmail.com> | 2021-05-19 18:14:37 +0300 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2022-08-10 22:04:10 +0200 |
commit | ff0487ddf0ba1f98daef8265eb3a50b1570b8f41 (patch) | |
tree | b21d88054ee81b2b65b33c6eab79b5f926019cfb /libpager/pager-ro-port.c | |
parent | 033397a36ab5bf40d7184791e036fae781355a21 (diff) | |
download | hurd-ff0487ddf0ba1f98daef8265eb3a50b1570b8f41.tar.gz hurd-ff0487ddf0ba1f98daef8265eb3a50b1570b8f41.tar.bz2 hurd-ff0487ddf0ba1f98daef8265eb3a50b1570b8f41.zip |
libpager: Add pager_get_ro_port ()
A pager will now maintain a port to a read-only memory object proxy
for itself, and let the users access it with pager_get_ro_port ().
Diffstat (limited to 'libpager/pager-ro-port.c')
-rw-r--r-- | libpager/pager-ro-port.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/libpager/pager-ro-port.c b/libpager/pager-ro-port.c new file mode 100644 index 00000000..713b0423 --- /dev/null +++ b/libpager/pager-ro-port.c @@ -0,0 +1,61 @@ +/* Copyright (C) 2021 Free Software Foundation, Inc. + + Written by Sergey Bugaev <bugaevc@gmail.com>. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "priv.h" +#include <mach/mach4.h> + +mach_port_t +pager_get_ro_port (struct pager *p) +{ + error_t err = 0;; + mach_port_t port = MACH_PORT_NULL; + mach_port_t rw_port; + vm_offset_t offset = 0; + vm_offset_t start = 0; + vm_size_t len = ~0; + + pthread_mutex_lock (&p->interlock); + + if (!MACH_PORT_VALID (p->ro_proxy)) + { + rw_port = ports_get_send_right (p); + if (!MACH_PORT_VALID (rw_port)) + { + err = errno; + goto out; + } + + err = memory_object_create_proxy (mach_task_self (), + VM_PROT_READ | VM_PROT_EXECUTE, + &rw_port, 1, + &offset, 1, &start, 1, &len, 1, + &p->ro_proxy); + + mach_port_deallocate (mach_task_self (), rw_port); + + if (err) + goto out; + } + + port = p->ro_proxy; + + out: + pthread_mutex_unlock (&p->interlock); + errno = err; + return port; +} |