The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/vm/vm_map.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1991, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * This code is derived from software contributed to Berkeley by
    6  * The Mach Operating System project at Carnegie-Mellon University.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. All advertising materials mentioning features or use of this software
   17  *    must display the following acknowledgement:
   18  *      This product includes software developed by the University of
   19  *      California, Berkeley and its contributors.
   20  * 4. Neither the name of the University nor the names of its contributors
   21  *    may be used to endorse or promote products derived from this software
   22  *    without specific prior written permission.
   23  *
   24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   34  * SUCH DAMAGE.
   35  *
   36  *      @(#)vm_map.h    8.9 (Berkeley) 5/17/95
   37  *
   38  *
   39  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
   40  * All rights reserved.
   41  *
   42  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
   43  *
   44  * Permission to use, copy, modify and distribute this software and
   45  * its documentation is hereby granted, provided that both the copyright
   46  * notice and this permission notice appear in all copies of the
   47  * software, derivative works or modified versions, and any portions
   48  * thereof, and that both notices appear in supporting documentation.
   49  *
   50  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   51  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
   52  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   53  *
   54  * Carnegie Mellon requests users of this software to return to
   55  *
   56  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   57  *  School of Computer Science
   58  *  Carnegie Mellon University
   59  *  Pittsburgh PA 15213-3890
   60  *
   61  * any improvements or extensions that they make and grant Carnegie the
   62  * rights to redistribute these changes.
   63  *
   64  * $FreeBSD$
   65  */
   66 
   67 /*
   68  *      Virtual memory map module definitions.
   69  */
   70 
   71 #ifndef _VM_MAP_
   72 #define _VM_MAP_
   73 
   74 /*
   75  *      Types defined:
   76  *
   77  *      vm_map_t                the high-level address map data structure.
   78  *      vm_map_entry_t          an entry in an address map.
   79  *      vm_map_version_t        a timestamp of a map, for use with vm_map_lookup
   80  */
   81 
   82 /*
   83  *      Objects which live in maps may be either VM objects, or
   84  *      another map (called a "sharing map") which denotes read-write
   85  *      sharing with other maps.
   86  */
   87 
   88 union vm_map_object {
   89         struct vm_object *vm_object;    /* object object */
   90         struct vm_map *share_map;       /* share map */
   91         struct vm_map *sub_map;         /* belongs to another map */
   92 };
   93 
   94 /*
   95  *      Address map entries consist of start and end addresses,
   96  *      a VM object (or sharing map) and offset into that object,
   97  *      and user-exported inheritance and protection information.
   98  *      Also included is control information for virtual copy operations.
   99  */
  100 struct vm_map_entry {
  101         struct vm_map_entry *prev;      /* previous entry */
  102         struct vm_map_entry *next;      /* next entry */
  103         vm_offset_t start;              /* start address */
  104         vm_offset_t end;                /* end address */
  105         vm_offset_t avail_ssize;        /* amt can grow if this is a stack */
  106         union vm_map_object object;     /* object I point to */
  107         vm_ooffset_t offset;            /* offset into object */
  108         u_char eflags;                  /* map entry flags */
  109         /* Only in task maps: */
  110         vm_prot_t protection;           /* protection code */
  111         vm_prot_t max_protection;       /* maximum protection */
  112         vm_inherit_t inheritance;       /* inheritance */
  113         int wired_count;                /* can be paged if = 0 */
  114 };
  115 
  116 #define MAP_ENTRY_IS_A_MAP              0x1
  117 #define MAP_ENTRY_IS_SUB_MAP            0x2
  118 #define MAP_ENTRY_COW                   0x4
  119 #define MAP_ENTRY_NEEDS_COPY            0x8
  120 #define MAP_ENTRY_NOFAULT               0x10
  121 #define MAP_ENTRY_USER_WIRED            0x20
  122 
  123 /*
  124  *      Maps are doubly-linked lists of map entries, kept sorted
  125  *      by address.  A single hint is provided to start
  126  *      searches again from the last successful search,
  127  *      insertion, or removal.
  128  *
  129  *      Note: the lock structure cannot be the first element of vm_map
  130  *      because this can result in a running lockup between two or more
  131  *      system processes trying to kmem_alloc_wait() due to kmem_alloc_wait()
  132  *      and free tsleep/waking up 'map' and the underlying lockmgr also
  133  *      sleeping and waking up on 'map'.  The lockup occurs when the map fills
  134  *      up.  The 'exec' map, for example.
  135  */
  136 struct vm_map {
  137         struct vm_map_entry header;     /* List of entries */
  138         struct lock lock;               /* Lock for map data */
  139         int nentries;                   /* Number of entries */
  140         vm_size_t size;                 /* virtual size */
  141         unsigned char   is_main_map;            /* Am I a main map? */
  142         unsigned char   system_map;                     /* Am I a system map? */
  143         vm_map_entry_t hint;            /* hint for quick lookups */
  144         unsigned int timestamp;         /* Version number */
  145         vm_map_entry_t first_free;      /* First free space hint */
  146         struct pmap *pmap;              /* Physical map */
  147 #define min_offset              header.start
  148 #define max_offset              header.end
  149 };
  150 
  151 /* 
  152  * Shareable process virtual address space.
  153  * May eventually be merged with vm_map.
  154  * Several fields are temporary (text, data stuff).
  155  */
  156 struct vmspace {
  157         struct vm_map vm_map;   /* VM address map */
  158         struct pmap vm_pmap;    /* private physical map */
  159         int vm_refcnt;          /* number of references */
  160         caddr_t vm_shm;         /* SYS5 shared memory private data XXX */
  161 /* we copy from vm_startcopy to the end of the structure on fork */
  162 #define vm_startcopy vm_rssize
  163         segsz_t vm_rssize;      /* current resident set size in pages */
  164         segsz_t vm_swrss;       /* resident set size before last swap */
  165         segsz_t vm_tsize;       /* text size (pages) XXX */
  166         segsz_t vm_dsize;       /* data size (pages) XXX */
  167         segsz_t vm_ssize;       /* stack size (pages) */
  168         caddr_t vm_taddr;       /* user virtual address of text XXX */
  169         caddr_t vm_daddr;       /* user virtual address of data XXX */
  170         caddr_t vm_maxsaddr;    /* user VA at max stack growth */
  171         caddr_t vm_minsaddr;    /* user VA at max stack growth */
  172 };
  173 
  174 
  175 /*
  176  *      Map versions are used to validate a previous lookup attempt.
  177  *
  178  *      Since lookup operations may involve both a main map and
  179  *      a sharing map, it is necessary to have a timestamp from each.
  180  *      [If the main map timestamp has changed, the share_map and
  181  *      associated timestamp are no longer valid; the map version
  182  *      does not include a reference for the embedded share_map.]
  183  */
  184 typedef struct {
  185         int main_timestamp;
  186         vm_map_t share_map;
  187         int share_timestamp;
  188 } vm_map_version_t;
  189 
  190 /*
  191  *      Macros:         vm_map_lock, etc.
  192  *      Function:
  193  *              Perform locking on the data portion of a map.
  194  */
  195 
  196 #define vm_map_lock_drain_interlock(map) { \
  197         lockmgr(&(map)->lock, LK_DRAIN|LK_INTERLOCK, \
  198                 &(map)->ref_lock, curproc); \
  199         (map)->timestamp++; \
  200 }
  201 
  202 #ifdef DIAGNOSTIC
  203 /* #define MAP_LOCK_DIAGNOSTIC 1 */
  204 #ifdef MAP_LOCK_DIAGNOSTIC
  205 #define vm_map_lock(map) { \
  206         printf ("locking map LK_EXCLUSIVE: 0x%x\n", map); \
  207         if (lockmgr(&(map)->lock, LK_EXCLUSIVE, (void *)0, curproc) != 0) { \
  208                 panic("vm_map_lock: failed to get lock"); \
  209         } \
  210         (map)->timestamp++; \
  211 }
  212 #else
  213 #define vm_map_lock(map) { \
  214         if (lockmgr(&(map)->lock, LK_EXCLUSIVE, (void *)0, curproc) != 0) { \
  215                 panic("vm_map_lock: failed to get lock"); \
  216         } \
  217         (map)->timestamp++; \
  218 }
  219 #endif
  220 #else
  221 #define vm_map_lock(map) { \
  222         lockmgr(&(map)->lock, LK_EXCLUSIVE, (void *)0, curproc); \
  223         (map)->timestamp++; \
  224 }
  225 #endif /* DIAGNOSTIC */
  226 
  227 #if defined(MAP_LOCK_DIAGNOSTIC)
  228 #define vm_map_unlock(map) \
  229         do { \
  230                 printf ("locking map LK_RELEASE: 0x%x\n", map); \
  231                 lockmgr(&(map)->lock, LK_RELEASE, (void *)0, curproc); \
  232         } while (0);
  233 #define vm_map_lock_read(map) \
  234         do { \
  235                 printf ("locking map LK_SHARED: 0x%x\n", map); \
  236                 lockmgr(&(map)->lock, LK_SHARED, (void *)0, curproc); \
  237         } while (0);
  238 #define vm_map_unlock_read(map) \
  239         do { \
  240                 printf ("locking map LK_RELEASE: 0x%x\n", map); \
  241                 lockmgr(&(map)->lock, LK_RELEASE, (void *)0, curproc); \
  242         } while (0);
  243 #else
  244 #define vm_map_unlock(map) \
  245         lockmgr(&(map)->lock, LK_RELEASE, (void *)0, curproc);
  246 #define vm_map_lock_read(map) \
  247         lockmgr(&(map)->lock, LK_SHARED, (void *)0, curproc); 
  248 #define vm_map_unlock_read(map) \
  249         lockmgr(&(map)->lock, LK_RELEASE, (void *)0, curproc);
  250 #endif
  251 
  252 static __inline__ int
  253 _vm_map_lock_upgrade(vm_map_t map, struct proc *p) {
  254         int error;
  255 #if defined(MAP_LOCK_DIAGNOSTIC)
  256         printf("locking map LK_EXCLUPGRADE: 0x%x\n", map); 
  257 #endif
  258         error = lockmgr(&map->lock, LK_EXCLUPGRADE, (void *)0, p);
  259         if (error == 0)
  260                 map->timestamp++;
  261         return error;
  262 }
  263 
  264 #define vm_map_lock_upgrade(map) _vm_map_lock_upgrade(map, curproc)
  265 
  266 #if defined(MAP_LOCK_DIAGNOSTIC)
  267 #define vm_map_lock_downgrade(map) \
  268         do { \
  269                 printf ("locking map LK_DOWNGRADE: 0x%x\n", map); \
  270                 lockmgr(&(map)->lock, LK_DOWNGRADE, (void *)0, curproc); \
  271         } while (0);
  272 #else
  273 #define vm_map_lock_downgrade(map) \
  274         lockmgr(&(map)->lock, LK_DOWNGRADE, (void *)0, curproc);
  275 #endif
  276 
  277 #define vm_map_set_recursive(map) { \
  278         simple_lock(&(map)->lock.lk_interlock); \
  279         (map)->lock.lk_flags |= LK_CANRECURSE; \
  280         simple_unlock(&(map)->lock.lk_interlock); \
  281 }
  282 #define vm_map_clear_recursive(map) { \
  283         simple_lock(&(map)->lock.lk_interlock); \
  284         (map)->lock.lk_flags &= ~LK_CANRECURSE; \
  285         simple_unlock(&(map)->lock.lk_interlock); \
  286 }
  287 
  288 /*
  289  *      Functions implemented as macros
  290  */
  291 #define         vm_map_min(map)         ((map)->min_offset)
  292 #define         vm_map_max(map)         ((map)->max_offset)
  293 #define         vm_map_pmap(map)        ((map)->pmap)
  294 
  295 static __inline struct pmap *
  296 vmspace_pmap(struct vmspace *vmspace)
  297 {
  298         return &vmspace->vm_pmap;
  299 }
  300 
  301 /* XXX: number of kernel maps and entries to statically allocate */
  302 #define MAX_KMAP        10
  303 #define MAX_KMAPENT     128
  304 #define MAX_MAPENT      128
  305 
  306 /*
  307  * Copy-on-write flags for vm_map operations
  308  */
  309 #define MAP_COPY_NEEDED 0x1
  310 #define MAP_COPY_ON_WRITE 0x2
  311 #define MAP_NOFAULT 0x4
  312 
  313 /*
  314  * vm_fault option flags
  315  */
  316 #define VM_FAULT_NORMAL 0               /* Nothing special */
  317 #define VM_FAULT_CHANGE_WIRING 1        /* Change the wiring as appropriate */
  318 #define VM_FAULT_USER_WIRE 2            /* Likewise, but for user purposes */
  319 #define VM_FAULT_WIRE_MASK (VM_FAULT_CHANGE_WIRING|VM_FAULT_USER_WIRE)
  320 #define VM_FAULT_HOLD 4                 /* Hold the page */
  321 #define VM_FAULT_DIRTY 8                /* Dirty the page */
  322 
  323 #ifdef KERNEL
  324 extern vm_offset_t kentry_data;
  325 extern vm_size_t kentry_data_size;
  326 
  327 boolean_t vm_map_check_protection __P((vm_map_t, vm_offset_t, vm_offset_t, vm_prot_t));
  328 int vm_map_copy __P((vm_map_t, vm_map_t, vm_offset_t, vm_size_t, vm_offset_t, boolean_t, boolean_t));
  329 struct pmap;
  330 vm_map_t vm_map_create __P((struct pmap *, vm_offset_t, vm_offset_t));
  331 void vm_map_deallocate __P((vm_map_t));
  332 int vm_map_delete __P((vm_map_t, vm_offset_t, vm_offset_t));
  333 int vm_map_find __P((vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, vm_size_t, boolean_t, vm_prot_t, vm_prot_t, int));
  334 int vm_map_findspace __P((vm_map_t, vm_offset_t, vm_size_t, vm_offset_t *));
  335 int vm_map_inherit __P((vm_map_t, vm_offset_t, vm_offset_t, vm_inherit_t));
  336 void vm_map_init __P((struct vm_map *, vm_offset_t, vm_offset_t));
  337 int vm_map_insert __P((vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t, vm_offset_t, vm_prot_t, vm_prot_t, int));
  338 int vm_map_lookup __P((vm_map_t *, vm_offset_t, vm_prot_t, vm_map_entry_t *, vm_object_t *,
  339     vm_pindex_t *, vm_prot_t *, boolean_t *));
  340 void vm_map_lookup_done __P((vm_map_t, vm_map_entry_t));
  341 boolean_t vm_map_lookup_entry __P((vm_map_t, vm_offset_t, vm_map_entry_t *));
  342 int vm_map_pageable __P((vm_map_t, vm_offset_t, vm_offset_t, boolean_t));
  343 int vm_map_user_pageable __P((vm_map_t, vm_offset_t, vm_offset_t, boolean_t));
  344 int vm_map_clean __P((vm_map_t, vm_offset_t, vm_offset_t, boolean_t, boolean_t));
  345 int vm_map_protect __P((vm_map_t, vm_offset_t, vm_offset_t, vm_prot_t, boolean_t));
  346 void vm_map_reference __P((vm_map_t));
  347 int vm_map_remove __P((vm_map_t, vm_offset_t, vm_offset_t));
  348 void vm_map_simplify __P((vm_map_t, vm_offset_t));
  349 void vm_map_startup __P((void));
  350 int vm_map_submap __P((vm_map_t, vm_offset_t, vm_offset_t, vm_map_t));
  351 void vm_map_madvise __P((vm_map_t, pmap_t, vm_offset_t, vm_offset_t, int));
  352 void vm_map_simplify_entry __P((vm_map_t, vm_map_entry_t));
  353 void vm_init2 __P((void));
  354 int vm_uiomove __P((vm_map_t, vm_object_t, off_t, int, vm_offset_t, int *));
  355 void vm_freeze_copyopts __P((vm_object_t, vm_pindex_t, vm_pindex_t));
  356 int vm_map_stack __P((vm_map_t, vm_offset_t, vm_size_t, vm_prot_t, vm_prot_t, int));
  357 int vm_map_growstack __P((struct proc *p, vm_offset_t addr));
  358 
  359 #endif
  360 #endif                          /* _VM_MAP_ */

Cache object: fc428da959c01281fbe4ff3ba7df3f40


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.