From 5717a89bc7af7ccbd2f104551876291338f7888c Mon Sep 17 00:00:00 2001 From: Thomas Bushnell Date: Sat, 26 Oct 1996 01:08:00 +0000 Subject: Still under construction. --- defpager/defpager.c | 145 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 118 insertions(+), 27 deletions(-) (limited to 'defpager/defpager.c') diff --git a/defpager/defpager.c b/defpager/defpager.c index 60ca6c19..9b0bce3a 100644 --- a/defpager/defpager.c +++ b/defpager/defpager.c @@ -1,6 +1,6 @@ /* Default pager for GNU Hurd. - Copyright (C) 1994 Free Software Foundation, Inc. - Written by Michael I. Bushnell. + Copyright (C) 1996 Free Software Foundation, Inc. + Written by Thomas Bushnell, n/BSG. This file is part of the GNU Hurd. @@ -18,30 +18,121 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* - * Mach Operating System - * Copyright (c) 1993-1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ +#include +#include +struct user_pager_info +{ + /* Size of the object */ + vm_size_t size; + + /* One entry for each page of the object. */ + off_t *map; +}; + + +/* Expand the P->map as necessary to handle an incoming request of the + page at ADDR. */ +static inline void +expand_map (struct user_pager_info *p, vm_offset_t addr) +{ + /* See if this is beyond the current extent */ + if (page >= pager->size) + { + off_t *newmap; + vm_size_t newsize; + + newsize = page + vm_page_size; + newmap = realloc (pager->map, size / vm_page_size * sizeof (off_t)); + + bzero (pager->map + pager->size / vm_page_size * sizeof (off_t), + (newsize - pager->size) / vm_page_size * sizeof (off_t)); + pager->size = newsize; + pager->map = newmap; + } +} + + +error_t +pager_read_page (struct user_pager_info *pager, + vm_offset_t page, + vm_address_t *buf, + int *write_lock) +{ + int pfn = page / vm_page_size; + size_t nread; + + /* We never request write locks. */ + *write_lock = 0; + + expand_map (pager, page); + + if (!pager->map[pfn]) + vm_allocate (mach_task_self (), buf, vm_page_size, 1); + else + { + store_read (backing_store, pager->map[pfn], vm_page_size, + (void **)buf, &nread); + if (nread != vm_page_size) + { + vm_deallocate (mach_task_self (), *buf, nread); + return EIO; + } + } + return 0; +} + + +error_t +pager_write_page (struct user_pager_info *pager, + vm_offset_t page, + vm_address_t buf) +{ + int pfn = page / vm_page_size; + size_t nwritten; + + expand_map (pager, page); + + if (!pager->map[pfn]) + pager->map[pfn] = allocate_backing_page (); + + /* No more backing store. Oh dear. */ + if (!pager->map[pfn]) + return EIO; + + err = store_write (backing_store, pager->map[pfn], (void *) buf, + vm_page_size, &nwritten); + if (!err && nwritten != vm_page_size) + err = EIO; + return err; +} + +error_t +pager_unlock_page (struct user_pager_info *pager, + vm_offset_t address) +{ + return 0; +} + +error_t +pager_report_extent (struct user_pager_info *pager, + vm_address_t *offset, + vm_size_t *size) +{ + *offset = 0; + *size = pager->size; + return 0; +} + +void +pager_clear_user_data (struct user_pager_info *pager) +{ + return_backing_pages (pager->map, pager->size / vm_page_size); + free (pager->map); +} + +void +pager_dropweak (struct user_pager_info *pager) +{ +} -- cgit v1.2.3