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 | |
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')
-rw-r--r-- | libpager/Makefile | 2 | ||||
-rw-r--r-- | libpager/object-terminate.c | 5 | ||||
-rw-r--r-- | libpager/pager-create.c | 1 | ||||
-rw-r--r-- | libpager/pager-ro-port.c | 61 | ||||
-rw-r--r-- | libpager/pager.h | 3 | ||||
-rw-r--r-- | libpager/priv.h | 2 |
6 files changed, 73 insertions, 1 deletions
diff --git a/libpager/Makefile b/libpager/Makefile index 72b4bfdc..06fcb96b 100644 --- a/libpager/Makefile +++ b/libpager/Makefile @@ -24,7 +24,7 @@ SRCS = data-request.c data-return.c data-unlock.c pager-port.c \ pager-create.c pager-flush.c pager-shutdown.c pager-sync.c \ stubs.c demuxer.c chg-compl.c pager-attr.c clean.c \ dropweak.c get-upi.c pager-memcpy.c pager-return.c \ - offer-page.c + offer-page.c pager-ro-port.c installhdrs = pager.h HURDLIBS= ports diff --git a/libpager/object-terminate.c b/libpager/object-terminate.c index 3e7df167..8e8205b5 100644 --- a/libpager/object-terminate.c +++ b/libpager/object-terminate.c @@ -115,6 +115,11 @@ _pager_free_structure (struct pager *p) mach_port_deallocate (mach_task_self (), p->memobjname); p->memobjname = MACH_PORT_NULL; } + if (p->ro_proxy != MACH_PORT_NULL) + { + mach_port_deallocate (mach_task_self (), p->ro_proxy); + p->ro_proxy = MACH_PORT_NULL; + } /* Free the pagemap */ if (p->pagemapsize) diff --git a/libpager/pager-create.c b/libpager/pager-create.c index 7f2f7d6e..9c3fba99 100644 --- a/libpager/pager-create.c +++ b/libpager/pager-create.c @@ -42,6 +42,7 @@ _pager_create (size_t size, p->notify_on_evict = notify_on_evict; p->memobjcntl = MACH_PORT_NULL; p->memobjname = MACH_PORT_NULL; + p->ro_proxy = MACH_PORT_NULL; p->noterm = 0; p->termwaiting = 0; p->pagemap = 0; 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; +} diff --git a/libpager/pager.h b/libpager/pager.h index dd8026a7..16b47def 100644 --- a/libpager/pager.h +++ b/libpager/pager.h @@ -155,6 +155,9 @@ pager_change_attributes (struct pager *pager, mach_port_t pager_get_port (struct pager *pager); +mach_port_t +pager_get_ro_port (struct pager *pager); + /* Force termination of a pager. After this returns, no more paging requests on the pager will be honored, and the pager will be deallocated. (The actual deallocation might diff --git a/libpager/priv.h b/libpager/priv.h index 89af52ba..0c38a7c0 100644 --- a/libpager/priv.h +++ b/libpager/priv.h @@ -55,6 +55,8 @@ struct pager memory_object_control_t memobjcntl; memory_object_name_t memobjname; + memory_object_t ro_proxy; + int noterm; /* number of threads blocking termination */ int termwaiting:1; |