/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* The Mach Operating System project at Carnegie-Mellon University.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)vm_map.c 8.9 (Berkeley) 5/17/95
*
*
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
* All rights reserved.
*
* Authors: Avadis Tevanian, Jr., Michael Wayne Young
*
* 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 [email protected]
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
/*
* Virtual memory mapping module.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
/*
* Virtual memory maps provide for the mapping, protection,
* and sharing of virtual memory objects. In addition,
* this module provides for an efficient virtual copy of
* memory from one map to another.
*
* Synchronization is required prior to most operations.
*
* Maps consist of an ordered doubly-linked list of simple
* entries; a single hint is used to speed up lookups.
*
* In order to properly represent the sharing of virtual
* memory regions among maps, the map structure is bi-level.
* Top-level ("address") maps refer to regions of sharable
* virtual memory. These regions are implemented as
* ("sharing") maps, which then refer to the actual virtual
* memory objects. When two address maps "share" memory,
* their top-level maps both have references to the same
* sharing map. When memory is virtual-copied from one
* address map to another, the references in the sharing
* maps are actually copied -- no copying occurs at the
* virtual memory object level.
*
* Since portions of maps are specified by start/end addreses,
* which may not align with existing map entries, all
* routines merely "clip" entries to these start/end values.
* [That is, an entry is split into two, bordering at a
* start or end value.] Note that these clippings may not
* always be necessary (as the two resulting entries are then
* not changed); however, the clipping is done for convenience.
* No attempt is currently made to "glue back together" two
* abutting entries.
*
* As mentioned above, virtual copy operations are performed
* by copying VM object references from one sharing map to
* another, and then marking both regions as copy-on-write.
* It is important to note that only one writeable reference
* to a VM object region exists in any map -- this means that
* shadow object creation can be delayed until a write operation
* occurs.
*/
/*
* vm_map_startup:
*
* Initialize the vm_map module. Must be called before
* any other vm_map routines.
*
* Map and entry structures are allocated from the general
* purpose memory pool with some exceptions:
*
* - The kernel map and kmem submap are allocated statically.
* - Kernel map entries are allocated out of a static pool.
*
* These restrictions are necessary since malloc() uses the
* maps and requires map entries.
*/
vm_offset_t kentry_data;
vm_size_t kentry_data_size;
vm_map_entry_t kentry_free;
vm_map_t kmap_free;
static void _vm_map_clip_end __P((vm_map_t, vm_map_entry_t, vm_offset_t));
static void _vm_map_clip_start __P((vm_map_t, vm_map_entry_t, vm_offset_t));
void
vm_map_startup()
{
register int i;
register vm_map_entry_t mep;
vm_map_t mp;
/*
* Static map structures for allocation before initialization of
* kernel map or kmem map. vm_map_create knows how to deal with them.
*/
kmap_free = mp = (vm_map_t) kentry_data;
i = MAX_KMAP;
while (--i > 0) {
mp->header.next = (vm_map_entry_t) (mp + 1);
mp++;
}
mp++->header.next = NULL;
/*
* Form a free list of statically allocated kernel map entries
* with the rest.
*/
kentry_free = mep = (vm_map_entry_t) mp;
i = (kentry_data_size - MAX_KMAP * sizeof *mp) / sizeof *mep;
while (--i > 0) {
mep->next = mep + 1;
mep++;
}
mep->next = NULL;
}
/*
* Allocate a vmspace structure, including a vm_map and pmap,
* and initialize those structures. The refcnt is set to 1.
* The remaining fields must be initialized by the caller.
*/
struct vmspace *
vmspace_alloc(min, max, pageable)
vm_offset_t min, max;
int pageable;
{
register struct vmspace *vm;
MALLOC(vm, struct vmspace *, sizeof(struct vmspace), M_VMMAP, M_WAITOK);
bzero(vm, (caddr_t) &vm->vm_startcopy - (caddr_t) vm);
vm_map_init(&vm->vm_map, min, max, pageable);
pmap_pinit(&vm->vm_pmap);
vm->vm_map.pmap = &vm->vm_pmap; /* XXX */
vm->vm_refcnt = 1;
return (vm);
}
void
vmspace_free(vm)
register struct vmspace *vm;
{
if (--vm->vm_refcnt == 0) {
/*
* Lock the map, to wait out all other references to it.
* Delete all of the mappings and pages they hold,
* then call the pmap module to reclaim anything left.
*/
vm_map_lock(&vm->vm_map);
(void) vm_map_delete(&vm->vm_map, vm->vm_map.min_offset,
vm->vm_map.max_offset);
pmap_release(&vm->vm_pmap);
FREE(vm, M_VMMAP);
}
}
/*
* vm_map_create:
*
* Creates and returns a new empty VM map with
* the given physical map structure, and having
* the given lower and upper address bounds.
*/
vm_map_t
vm_map_create(pmap, min, max, pageable)
pmap_t pmap;
vm_offset_t min, max;
boolean_t pageable;
{
register vm_map_t result;
extern vm_map_t kmem_map;
if (kmem_map == NULL) {
result = kmap_free;
if (result == NULL)
panic("vm_map_create: out of maps");
kmap_free = (vm_map_t) result->header.next
没有合适的资源?快使用搜索试试~ 我知道了~
vm.zip_open
共34个文件
c:17个
h:15个
txt:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 66 浏览量
2022-09-22
17:05:43
上传
评论
收藏 132KB ZIP 举报
温馨提示
open bsd vm device design
资源推荐
资源详情
资源评论
收起资源包目录
vm.zip (34个子文件)
vm
device_p.h 2KB
swap_pag.c 26KB
vm_map.h 10KB
vm_exter.h 6KB
vm.h 4KB
vm_kern.c 13KB
vm_init.c 4KB
vm_pager.h 5KB
vm_fault.c 25KB
vm_pageo.c 15KB
vm_glue.c 16KB
vm_swap.c 11KB
vm_meter.c 6KB
vm_objec.h 7KB
vnode_pa.h 2KB
TODO 6KB
vm_unix.c 4KB
vm_page.c 17KB
device_p.c 10KB
vm_inher.h 3KB
vm_objec.c 34KB
vm_page.h 8KB
vm_pageo.h 4KB
vm_pager.c 10KB
vm_param.h 5KB
swap_pag.h 4KB
vm_mmap.c 22KB
vm_user.c 8KB
vnode_pa.c 15KB
vm_kern.h 3KB
vm_prot.h 4KB
pmap.h 5KB
vm_map.c 62KB
www.pudn.com.txt 218B
共 34 条
- 1
资源评论
小波思基
- 粉丝: 72
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功