From c1f5bf6d4849a1fe6b5c81e1900f8b0696288571 Mon Sep 17 00:00:00 2001 From: "Michael I. Bushnell" Date: Thu, 13 Jan 1994 20:53:13 +0000 Subject: Initial revision --- libpager/inhibit-term.c | 34 ++++++++++++++++ libpager/mark-error.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ libpager/object-terminate.c | 94 ++++++++++++++++++++++++++++++++++++++++++++ libpager/pagemap.c | 40 +++++++++++++++++++ libpager/seqnos.c | 41 +++++++++++++++++++ libpager/stubs.c | 66 +++++++++++++++++++++++++++++++ 6 files changed, 371 insertions(+) create mode 100644 libpager/inhibit-term.c create mode 100644 libpager/mark-error.c create mode 100644 libpager/object-terminate.c create mode 100644 libpager/pagemap.c create mode 100644 libpager/seqnos.c create mode 100644 libpager/stubs.c (limited to 'libpager') diff --git a/libpager/inhibit-term.c b/libpager/inhibit-term.c new file mode 100644 index 00000000..9eb5f47c --- /dev/null +++ b/libpager/inhibit-term.c @@ -0,0 +1,34 @@ +/* Locks to inhibit termination races for pager library + Copyright (C) 1994 Free Software Foundation + + 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. */ + + +/* Prevent this memory object from being terminated. */ +/* Must be called with interlock held. */ +void +_pager_block_termination (struct pager *p) +{ + p->noterm++; +} + +/* Allow termination again. */ +/* Must be called with interlock held. */ +void +_pagerallow_termination (struct pager *p) +{ + if (!--p->noterm && p->termwaiting) + condition_broadcast (&p->wakeup); +} diff --git a/libpager/mark-error.c b/libpager/mark-error.c new file mode 100644 index 00000000..1463035c --- /dev/null +++ b/libpager/mark-error.c @@ -0,0 +1,96 @@ +/* Recording errors for pager library + Copyright (C) 1994 Free Software Foundation + + 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. */ + + +/* Some error has happened indicating that the page cannot be written. + (Usually this is ENOSPC or EDQOUT.) On the next pagein which + requests write access, return the error to the kernel. (This is + screwy because of the rules associated with m_o_lock_request.) */ +void +mark_next_request_error(struct pager *p, + int offset, + int length, + error_t error) +{ + int page_error; + char *p; + + offset /= __vm_page_size; + length /= __vm_page_size; + + switch (error) + { + case 0: + page_error = PAGE_NOERR; + break; + case ENOSPC: + page_error = PAGE_ENOSPC; + break; + case EIO: + page_error = PAGE_EIO; + break; + case EDQUOT: + page_error = PAGE_EDQUOT; + break; + default: + panic ("mark_object_error"); + break; + } + + for (p = p->pagemap; p < p->pagemap + length; p++) + *p = SET_PM_NEXTERROR (*p, page_error); +} + +/* We are returning a pager error to the kernel. Write down + in the pager what that error was so that the exception handling + routines can find out. (This is only necessary because the + XP interface is not completely implemented in the kernel.) */ +void +mark_object_error(struct pager *p, + int offset, + int length, + error_t error) +{ + int page_error = 0; + char *p; + + offset /= __vm_page_size; + length /= __vm_page_size; + + switch (error) + { + case 0: + page_error = PAGE_NOERR; + break; + case ENOSPC: + page_error = PAGE_ENOSPC; + break; + case EIO: + page_error = PAGE_EIO; + break; + case EDQUOT: + page_error = PAGE_EDQUOT; + break; + default: + panic ("mark_object_error"); + break; + } + + for (p = p->pagemap; p < p->pagemap + length; p++) + *p = SET_PM_ERROR (*p, page_error); +} + diff --git a/libpager/object-terminate.c b/libpager/object-terminate.c new file mode 100644 index 00000000..251fc6db --- /dev/null +++ b/libpager/object-terminate.c @@ -0,0 +1,94 @@ +/* Implementation of memory_object_terminate for pager library + Copyright (C) 1994 Free Software Foundation + + 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. */ + + +/* Called by the kernel when a shutdown has finished. */ +/* This is a dual of seqnos_memory_object_init. */ +kern_return_t +seqnos_memory_object_terminate (mach_port_t object, + mach_port_seqno_t seqno, + mach_port_t control, + mach_port_t name) +{ + struct pager *p; + struct lock_request *lr; + int wakeup; + + if (!(p = check_port_type (object, pager_port_type))) + return EOPNOTSUPP; + + if (control != p->memobjcntl) + { + printf ("incg terminate: wrong control port"); + goto out; + } + if (name != p->memobjname) + { + printf ("incg terminate: wrong name port"); + goto out; + } + + if (p->pager_type != FILE_DATA && p->pager_type != SINDIR) + { + printf ("unexpected m_o_terminate\n"); + goto out; + } + + mutex_lock (&p->interlock); + + _pager_wait_for_seqno (p, seqno); + + while (p->noterm) + { + p->termwaiting = 1; + condition_wait (&p->wakeup, &p->interlock); + } + + wakeup = 0; + for (lr = p->lock_requests; lr; lr = lr->next) + { + lr->locks_pending = 0; + if (!lr->pending_writes) + wakeup = 1; + } + if (wakeup) + condition_broadcast (&p->wakeup); + + mach_port_deallocate (mach_task_self (), control); + mach_port_deallocate (mach_task_self (), name); + + /* Free the pagemap */ + if (p->pagemapsize) + { + vm_deallocate (mach_task_self (), (u_int)p->pagemap, p->pagemapsize); + p->pagemapsize = 0; + p->pagemap = 0; + } + + p->pager_state = NOTINIT; + _pager_release_seqno (p); + + mutex_unlock (&p->interlock); + + if (shutting_down) + /* Drop the user reference rather than waiting for the user to do it. */ + done_with_port (p); + + out: + done_with_port (p); + return 0; +} diff --git a/libpager/pagemap.c b/libpager/pagemap.c new file mode 100644 index 00000000..c09a4d04 --- /dev/null +++ b/libpager/pagemap.c @@ -0,0 +1,40 @@ +/* Pagemap manipulation for pager library + Copyright (C) 1994 Free Software Foundation + + 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. */ + + +/* Grow the pagemap as necessary to deal with address OFF */ +void +pagemap_resize (struct pager *p, + int off) +{ + void *newaddr; + int newsize; + + if (p->pagemapsize && !p->pagemap) + panic ("pagemap failure"); + + off /= __vm_page_size; + if (p->pagemapsize >= off) + return; + + newsize = round_page (off); + vm_allocate (mach_task_self (), (u_int *)&newaddr, newsize, 1); + bcopy (p->pagemap, newaddr, p->pagemapsize); + vm_deallocate (mach_task_self (), (u_int)p->pagemap, p->pagemapsize); + p->pagemap = newaddr; + p->pagemapsize = newsize; +} diff --git a/libpager/seqnos.c b/libpager/seqnos.c new file mode 100644 index 00000000..c1a5ba3d --- /dev/null +++ b/libpager/seqnos.c @@ -0,0 +1,41 @@ +/* Sequence number synchronization routines for pager library + Copyright (C) 1994 Free Software Foundation + + 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. */ + +/* Wait until all preceding messages on this port have + had a chance to be honored. */ +void +_pager_wait_for_seqno (struct pager *p, + int seqno) +{ + while (seqno != p->seqno + 1) + { + p->waitingforseqno = 1; + condition_wait (&p->wakeup, &p->interlock); + } + p->seqno = seqno; +} + +/* Allow the next message in. */ +void +release_seqno (struct pager *p) +{ + if (p->waitingforseqno) + { + p->waitingforseqno = 0; + condition_broadcast (&p->wakeup); + } +} diff --git a/libpager/stubs.c b/libpager/stubs.c new file mode 100644 index 00000000..a8830d70 --- /dev/null +++ b/libpager/stubs.c @@ -0,0 +1,66 @@ +/* Unused memory object interface stubs + Copyright (C) 1994 Free Software Foundation + + 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. */ + + +error_t +seqnos_memory_object_copy (mach_port_t old, + mach_port_seqno_t seq, + memory_object_control_t old_ctl, + vm_offset_t off, + vm_size_t len, + mach_port_t new) +{ + printf ("m_o_copy called\n"); + return EOPNOTSUPP; +} + +error_t +seqnos_memory_object_data_write (mach_port_t old, + mach_port_seqno_t seq, + mach_port_t ctl, + vm_offset_t off, + pointer_t data, + vm_size_t data_cnt) +{ + printf ("m_o_data_write called\n"); + return EOPNOTSUPP; +} + +error_t +seqnos_memory_object_supply_completed (mach_port_t obj, + mach_port_seqno_t seq, + mach_port_t ctl, + vm_offset_t off, + vm_size_t len, + error_t result, + vm_offset_t err_off) +{ + printf ("m_o_supply_completed called\n"); + return EOPNOTSUPP; +} + +error_t +seqnos_memory_object_change_completed (mach_port_t obj, + mach_port_seqno_t seq, + boolean_t maycache, + memory_object_copy_strategy_t strat) +{ + printf ("m_o_change_completed called\n"); + return EOPNOTSUPP; +} + + -- cgit v1.2.3