xref: /csrg-svn/sys/vm/vm_map.h (revision 68930)
145748Smckusick /*
263379Sbostic  * Copyright (c) 1991, 1993
363379Sbostic  *	The Regents of the University of California.  All rights reserved.
445748Smckusick  *
545748Smckusick  * This code is derived from software contributed to Berkeley by
645748Smckusick  * The Mach Operating System project at Carnegie-Mellon University.
745748Smckusick  *
848493Smckusick  * %sccs.include.redist.c%
945748Smckusick  *
10*68930Smckusick  *	@(#)vm_map.h	8.6 (Berkeley) 04/27/95
1148493Smckusick  *
1248493Smckusick  *
1348493Smckusick  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
1448493Smckusick  * All rights reserved.
1548493Smckusick  *
1648493Smckusick  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
1748493Smckusick  *
1848493Smckusick  * Permission to use, copy, modify and distribute this software and
1948493Smckusick  * its documentation is hereby granted, provided that both the copyright
2048493Smckusick  * notice and this permission notice appear in all copies of the
2148493Smckusick  * software, derivative works or modified versions, and any portions
2248493Smckusick  * thereof, and that both notices appear in supporting documentation.
2348493Smckusick  *
2448493Smckusick  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
2548493Smckusick  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
2648493Smckusick  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
2748493Smckusick  *
2848493Smckusick  * Carnegie Mellon requests users of this software to return to
2948493Smckusick  *
3048493Smckusick  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
3148493Smckusick  *  School of Computer Science
3248493Smckusick  *  Carnegie Mellon University
3348493Smckusick  *  Pittsburgh PA 15213-3890
3448493Smckusick  *
3548493Smckusick  * any improvements or extensions that they make and grant Carnegie the
3648493Smckusick  * rights to redistribute these changes.
3745748Smckusick  */
3845748Smckusick 
3945748Smckusick /*
4045748Smckusick  *	Virtual memory map module definitions.
4145748Smckusick  */
4245748Smckusick 
4345748Smckusick #ifndef	_VM_MAP_
4445748Smckusick #define	_VM_MAP_
4545748Smckusick 
4645748Smckusick /*
4745748Smckusick  *	Types defined:
4845748Smckusick  *
4945748Smckusick  *	vm_map_t		the high-level address map data structure.
5045748Smckusick  *	vm_map_entry_t		an entry in an address map.
5145748Smckusick  *	vm_map_version_t	a timestamp of a map, for use with vm_map_lookup
5245748Smckusick  */
5345748Smckusick 
5445748Smckusick /*
5545748Smckusick  *	Objects which live in maps may be either VM objects, or
5645748Smckusick  *	another map (called a "sharing map") which denotes read-write
5745748Smckusick  *	sharing with other maps.
5845748Smckusick  */
5945748Smckusick 
6045748Smckusick union vm_map_object {
6145748Smckusick 	struct vm_object	*vm_object;	/* object object */
6245748Smckusick 	struct vm_map		*share_map;	/* share map */
6345748Smckusick 	struct vm_map		*sub_map;	/* belongs to another map */
6445748Smckusick };
6545748Smckusick 
6645748Smckusick /*
6745748Smckusick  *	Address map entries consist of start and end addresses,
6845748Smckusick  *	a VM object (or sharing map) and offset into that object,
6945748Smckusick  *	and user-exported inheritance and protection information.
7045748Smckusick  *	Also included is control information for virtual copy operations.
7145748Smckusick  */
7245748Smckusick struct vm_map_entry {
7345748Smckusick 	struct vm_map_entry	*prev;		/* previous entry */
7445748Smckusick 	struct vm_map_entry	*next;		/* next entry */
7545748Smckusick 	vm_offset_t		start;		/* start address */
7645748Smckusick 	vm_offset_t		end;		/* end address */
7745748Smckusick 	union vm_map_object	object;		/* object I point to */
7845748Smckusick 	vm_offset_t		offset;		/* offset into object */
7945748Smckusick 	boolean_t		is_a_map;	/* Is "object" a map? */
8045748Smckusick 	boolean_t		is_sub_map;	/* Is "object" a submap? */
8145748Smckusick 		/* Only in sharing maps: */
8245748Smckusick 	boolean_t		copy_on_write;	/* is data copy-on-write */
8345748Smckusick 	boolean_t		needs_copy;	/* does object need to be copied */
8445748Smckusick 		/* Only in task maps: */
8545748Smckusick 	vm_prot_t		protection;	/* protection code */
8645748Smckusick 	vm_prot_t		max_protection;	/* maximum protection */
8745748Smckusick 	vm_inherit_t		inheritance;	/* inheritance */
8845748Smckusick 	int			wired_count;	/* can be paged if = 0 */
8945748Smckusick };
9045748Smckusick 
9145748Smckusick /*
9245748Smckusick  *	Maps are doubly-linked lists of map entries, kept sorted
9345748Smckusick  *	by address.  A single hint is provided to start
9445748Smckusick  *	searches again from the last successful search,
9545748Smckusick  *	insertion, or removal.
9645748Smckusick  */
9745748Smckusick struct vm_map {
9848386Skarels 	struct pmap *		pmap;		/* Physical map */
9945748Smckusick 	lock_data_t		lock;		/* Lock for map data */
10045748Smckusick 	struct vm_map_entry	header;		/* List of entries */
10145748Smckusick 	int			nentries;	/* Number of entries */
10245748Smckusick 	vm_size_t		size;		/* virtual size */
10345748Smckusick 	boolean_t		is_main_map;	/* Am I a main map? */
10445748Smckusick 	int			ref_count;	/* Reference count */
10545748Smckusick 	simple_lock_data_t	ref_lock;	/* Lock for ref_count field */
10645748Smckusick 	vm_map_entry_t		hint;		/* hint for quick lookups */
10745748Smckusick 	simple_lock_data_t	hint_lock;	/* lock for hint storage */
10845748Smckusick 	vm_map_entry_t		first_free;	/* First free space hint */
10945748Smckusick 	boolean_t		entries_pageable; /* map entries pageable?? */
11045748Smckusick 	unsigned int		timestamp;	/* Version number */
11145748Smckusick #define	min_offset		header.start
11245748Smckusick #define max_offset		header.end
11345748Smckusick };
11445748Smckusick 
11545748Smckusick /*
11645748Smckusick  *	Map versions are used to validate a previous lookup attempt.
11745748Smckusick  *
11845748Smckusick  *	Since lookup operations may involve both a main map and
11945748Smckusick  *	a sharing map, it is necessary to have a timestamp from each.
12045748Smckusick  *	[If the main map timestamp has changed, the share_map and
12145748Smckusick  *	associated timestamp are no longer valid; the map version
12245748Smckusick  *	does not include a reference for the imbedded share_map.]
12345748Smckusick  */
12445748Smckusick typedef struct {
12545748Smckusick 	int		main_timestamp;
12645748Smckusick 	vm_map_t	share_map;
12745748Smckusick 	int		share_timestamp;
12845748Smckusick } vm_map_version_t;
12945748Smckusick 
13045748Smckusick /*
13145748Smckusick  *	Macros:		vm_map_lock, etc.
13245748Smckusick  *	Function:
13345748Smckusick  *		Perform locking on the data portion of a map.
13445748Smckusick  */
13545748Smckusick 
13668793Smckusick extern struct proc *curproc;	/* XXX */
137*68930Smckusick #define LOCKPID (curproc ? curproc->p_pid : LK_KERNPROC)
13868793Smckusick 
13953330Sbostic #define	vm_map_lock(map) { \
140*68930Smckusick 	lockmgr(&(map)->lock, LK_EXCLUSIVE, (void *)0, LOCKPID); \
14153330Sbostic 	(map)->timestamp++; \
14253330Sbostic }
143*68930Smckusick #define	vm_map_unlock(map) \
144*68930Smckusick 		lockmgr(&(map)->lock, LK_RELEASE, (void *)0, LOCKPID)
145*68930Smckusick #define	vm_map_lock_read(map) \
146*68930Smckusick 		lockmgr(&(map)->lock, LK_SHARED, (void *)0, LOCKPID)
147*68930Smckusick #define	vm_map_unlock_read(map) \
148*68930Smckusick 		lockmgr(&(map)->lock, LK_RELEASE, (void *)0, LOCKPID)
14968796Smckusick #define vm_map_set_recursive(map) { \
15068796Smckusick 	simple_lock(&(map)->lk_interlock); \
15168796Smckusick 	(map)->lk_flags |= LK_CANRECURSE; \
15268796Smckusick 	simple_unlock(&(map)->lk_interlock); \
15368796Smckusick }
15468796Smckusick #define vm_map_clear_recursive(map) { \
15568796Smckusick 	simple_lock(&(map)->lk_interlock); \
15668796Smckusick 	(map)->lk_flags &= ~LK_CANRECURSE; \
15768796Smckusick 	simple_unlock(&(map)->lk_interlock); \
15868796Smckusick }
15945748Smckusick /*
16045748Smckusick  *	Functions implemented as macros
16145748Smckusick  */
16245748Smckusick #define		vm_map_min(map)		((map)->min_offset)
16345748Smckusick #define		vm_map_max(map)		((map)->max_offset)
16445748Smckusick #define		vm_map_pmap(map)	((map)->pmap)
16545748Smckusick 
16645748Smckusick /* XXX: number of kernel maps and entries to statically allocate */
16745748Smckusick #define MAX_KMAP	10
16866359Sbostic #define	MAX_KMAPENT	500
16945748Smckusick 
17053330Sbostic #ifdef KERNEL
17153330Sbostic boolean_t	 vm_map_check_protection __P((vm_map_t,
17253330Sbostic 		    vm_offset_t, vm_offset_t, vm_prot_t));
17353330Sbostic int		 vm_map_copy __P((vm_map_t, vm_map_t, vm_offset_t,
17453330Sbostic 		    vm_size_t, vm_offset_t, boolean_t, boolean_t));
17553330Sbostic void		 vm_map_copy_entry __P((vm_map_t,
17653330Sbostic 		    vm_map_t, vm_map_entry_t, vm_map_entry_t));
17753330Sbostic struct pmap;
17853330Sbostic vm_map_t	 vm_map_create __P((struct pmap *,
17953330Sbostic 		    vm_offset_t, vm_offset_t, boolean_t));
18053330Sbostic void		 vm_map_deallocate __P((vm_map_t));
18153330Sbostic int		 vm_map_delete __P((vm_map_t, vm_offset_t, vm_offset_t));
18253330Sbostic vm_map_entry_t	 vm_map_entry_create __P((vm_map_t));
18353330Sbostic void		 vm_map_entry_delete __P((vm_map_t, vm_map_entry_t));
18453330Sbostic void		 vm_map_entry_dispose __P((vm_map_t, vm_map_entry_t));
18553330Sbostic void		 vm_map_entry_unwire __P((vm_map_t, vm_map_entry_t));
18653330Sbostic int		 vm_map_find __P((vm_map_t, vm_object_t,
18753330Sbostic 		    vm_offset_t, vm_offset_t *, vm_size_t, boolean_t));
18853330Sbostic int		 vm_map_findspace __P((vm_map_t,
18953330Sbostic 		    vm_offset_t, vm_size_t, vm_offset_t *));
19053330Sbostic int		 vm_map_inherit __P((vm_map_t,
19153330Sbostic 		    vm_offset_t, vm_offset_t, vm_inherit_t));
19253330Sbostic void		 vm_map_init __P((struct vm_map *,
19353330Sbostic 		    vm_offset_t, vm_offset_t, boolean_t));
19453330Sbostic int		 vm_map_insert __P((vm_map_t,
19553330Sbostic 		    vm_object_t, vm_offset_t, vm_offset_t, vm_offset_t));
19653330Sbostic int		 vm_map_lookup __P((vm_map_t *, vm_offset_t, vm_prot_t,
19753330Sbostic 		    vm_map_entry_t *, vm_object_t *, vm_offset_t *, vm_prot_t *,
19853330Sbostic 		    boolean_t *, boolean_t *));
19953330Sbostic void		 vm_map_lookup_done __P((vm_map_t, vm_map_entry_t));
20053330Sbostic boolean_t	 vm_map_lookup_entry __P((vm_map_t,
20153330Sbostic 		    vm_offset_t, vm_map_entry_t *));
20253330Sbostic int		 vm_map_pageable __P((vm_map_t,
20353330Sbostic 		    vm_offset_t, vm_offset_t, boolean_t));
20465685Shibler int		 vm_map_clean __P((vm_map_t,
20565685Shibler 		    vm_offset_t, vm_offset_t, boolean_t, boolean_t));
20653330Sbostic void		 vm_map_print __P((vm_map_t, boolean_t));
20753330Sbostic int		 vm_map_protect __P((vm_map_t,
20853330Sbostic 		    vm_offset_t, vm_offset_t, vm_prot_t, boolean_t));
20953330Sbostic void		 vm_map_reference __P((vm_map_t));
21053330Sbostic int		 vm_map_remove __P((vm_map_t, vm_offset_t, vm_offset_t));
21153330Sbostic void		 vm_map_simplify __P((vm_map_t, vm_offset_t));
21253330Sbostic void		 vm_map_simplify_entry __P((vm_map_t, vm_map_entry_t));
21353330Sbostic void		 vm_map_startup __P((void));
21453330Sbostic int		 vm_map_submap __P((vm_map_t,
21553330Sbostic 		    vm_offset_t, vm_offset_t, vm_map_t));
21653330Sbostic #endif
21760337Storek #endif /* _VM_MAP_ */
218