1 /* $OpenBSD: uvm_extern.h,v 1.23 2001/08/12 22:41:15 mickey Exp $ */ 2 /* $NetBSD: uvm_extern.h,v 1.42 2000/06/08 05:52:34 thorpej Exp $ */ 3 4 /* 5 * 6 * Copyright (c) 1997 Charles D. Cranor and Washington University. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by Charles D. Cranor and 20 * Washington University. 21 * 4. The name of the author may not be used to endorse or promote products 22 * derived from this software without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * from: Id: uvm_extern.h,v 1.1.2.21 1998/02/07 01:16:53 chs Exp 36 */ 37 38 #ifndef _UVM_UVM_EXTERN_H_ 39 #define _UVM_UVM_EXTERN_H_ 40 41 /* 42 * uvm_extern.h: this file defines the external interface to the VM system. 43 * 44 * this should be the only file included by non-VM parts of the kernel 45 * which need access to VM services. if you want to know the interface 46 * to the MI VM layer without knowing the details, this is the file to 47 * learn. 48 * 49 * NOTE: vm system calls are prototyped in syscallargs.h 50 */ 51 52 /* 53 * defines 54 */ 55 56 /* 57 * the following defines are for uvm_map and functions which call it. 58 */ 59 60 /* protections bits */ 61 #define UVM_PROT_MASK 0x07 /* protection mask */ 62 #define UVM_PROT_NONE 0x00 /* protection none */ 63 #define UVM_PROT_ALL 0x07 /* everything */ 64 #define UVM_PROT_READ 0x01 /* read */ 65 #define UVM_PROT_WRITE 0x02 /* write */ 66 #define UVM_PROT_EXEC 0x04 /* exec */ 67 68 /* protection short codes */ 69 #define UVM_PROT_R 0x01 /* read */ 70 #define UVM_PROT_W 0x02 /* write */ 71 #define UVM_PROT_RW 0x03 /* read-write */ 72 #define UVM_PROT_X 0x04 /* exec */ 73 #define UVM_PROT_RX 0x05 /* read-exec */ 74 #define UVM_PROT_WX 0x06 /* write-exec */ 75 #define UVM_PROT_RWX 0x07 /* read-write-exec */ 76 77 /* 0x08: not used */ 78 79 /* inherit codes */ 80 #define UVM_INH_MASK 0x30 /* inherit mask */ 81 #define UVM_INH_SHARE 0x00 /* "share" */ 82 #define UVM_INH_COPY 0x10 /* "copy" */ 83 #define UVM_INH_NONE 0x20 /* "none" */ 84 #define UVM_INH_DONATE 0x30 /* "donate" << not used */ 85 86 /* 0x40, 0x80: not used */ 87 88 /* bits 0x700: max protection, 0x800: not used */ 89 90 /* bits 0x7000: advice, 0x8000: not used */ 91 92 typedef int vm_prot_t; 93 94 /* 95 * Protection values, defined as bits within the vm_prot_t type 96 * 97 * These are funky definitions from old CMU VM and are kept 98 * for compatibility reasons, one day they are going to die, 99 * just like everybody else. 100 */ 101 102 #define VM_PROT_NONE ((vm_prot_t) 0x00) 103 104 #define VM_PROT_READ ((vm_prot_t) 0x01) /* read permission */ 105 #define VM_PROT_WRITE ((vm_prot_t) 0x02) /* write permission */ 106 #define VM_PROT_EXECUTE ((vm_prot_t) 0x04) /* execute permission */ 107 108 /* 109 * The default protection for newly-created virtual memory 110 */ 111 112 #define VM_PROT_DEFAULT (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE) 113 114 /* 115 * The maximum privileges possible, for parameter checking. 116 */ 117 118 #define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE) 119 120 /* 121 * Enumeration of valid values for vm_inherit_t. 122 */ 123 124 #define VM_INHERIT_SHARE ((vm_inherit_t)0) /* share with child */ 125 #define VM_INHERIT_COPY ((vm_inherit_t)1) /* copy into child */ 126 #define VM_INHERIT_NONE ((vm_inherit_t)2) /* absent from child */ 127 #define VM_INHERIT_DONATE_COPY ((vm_inherit_t)3) /* copy and delete */ 128 129 #define VM_INHERIT_DEFAULT VM_INHERIT_COPY 130 131 /* advice: matches MADV_* from sys/mman.h */ 132 #define UVM_ADV_NORMAL 0x0 /* 'normal' */ 133 #define UVM_ADV_RANDOM 0x1 /* 'random' */ 134 #define UVM_ADV_SEQUENTIAL 0x2 /* 'sequential' */ 135 /* 0x3: will need, 0x4: dontneed */ 136 #define UVM_ADV_MASK 0x7 /* mask */ 137 138 /* mapping flags */ 139 #define UVM_FLAG_FIXED 0x010000 /* find space */ 140 #define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */ 141 #define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */ 142 #define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */ 143 #define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */ 144 #define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */ 145 146 /* macros to extract info */ 147 #define UVM_PROTECTION(X) ((X) & UVM_PROT_MASK) 148 #define UVM_INHERIT(X) (((X) & UVM_INH_MASK) >> 4) 149 #define UVM_MAXPROTECTION(X) (((X) >> 8) & UVM_PROT_MASK) 150 #define UVM_ADVICE(X) (((X) >> 12) & UVM_ADV_MASK) 151 152 #define UVM_MAPFLAG(PROT,MAXPROT,INH,ADVICE,FLAGS) \ 153 ((MAXPROT << 8)|(PROT)|(INH)|((ADVICE) << 12)|(FLAGS)) 154 155 /* magic offset value */ 156 #define UVM_UNKNOWN_OFFSET ((voff_t) -1) 157 /* offset not known(obj) or don't care(!obj) */ 158 159 /* 160 * the following defines are for uvm_km_kmemalloc's flags 161 */ 162 #define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */ 163 #define UVM_KMF_VALLOC 0x2 /* allocate VA only */ 164 #define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */ 165 166 /* 167 * the following defines the strategies for uvm_pagealloc_strat() 168 */ 169 #define UVM_PGA_STRAT_NORMAL 0 /* high -> low free list walk */ 170 #define UVM_PGA_STRAT_ONLY 1 /* only specified free list */ 171 #define UVM_PGA_STRAT_FALLBACK 2 /* ONLY falls back on NORMAL */ 172 173 /* 174 * flags for uvm_pagealloc_strat() 175 */ 176 #define UVM_PGA_USERESERVE 0x0001 /* ok to use reserve pages */ 177 #define UVM_PGA_ZERO 0x0002 /* returned page must be zero'd */ 178 179 /* 180 * lockflags that control the locking behavior of various functions. 181 */ 182 #define UVM_LK_ENTER 0x00000001 /* map locked on entry */ 183 #define UVM_LK_EXIT 0x00000002 /* leave map locked on exit */ 184 185 /* 186 * structures 187 */ 188 189 struct buf; 190 struct core; 191 struct mount; 192 struct pglist; 193 struct proc; 194 struct ucred; 195 struct uio; 196 struct uvm_object; 197 struct vm_anon; 198 struct vm_aref; 199 struct vmspace; 200 struct pmap; 201 struct vnode; 202 struct simplelock; 203 204 /* 205 * uvmexp: global data structures that are exported to parts of the kernel 206 * other than the vm system. 207 */ 208 209 struct uvmexp { 210 /* vm_page constants */ 211 int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */ 212 int pagemask; /* page mask */ 213 int pageshift; /* page shift */ 214 215 /* vm_page counters */ 216 int npages; /* number of pages we manage */ 217 int free; /* number of free pages */ 218 int active; /* number of active pages */ 219 int inactive; /* number of pages that we free'd but may want back */ 220 int paging; /* number of pages in the process of being paged out */ 221 int wired; /* number of wired pages */ 222 int zeropages; /* number of zero'd pages */ 223 int reserve_pagedaemon; /* number of pages reserved for pagedaemon */ 224 int reserve_kernel; /* number of pages reserved for kernel */ 225 226 /* pageout params */ 227 int freemin; /* min number of free pages */ 228 int freetarg; /* target number of free pages */ 229 int inactarg; /* target number of inactive pages */ 230 int wiredmax; /* max number of wired pages */ 231 232 /* swap */ 233 int nswapdev; /* number of configured swap devices in system */ 234 int swpages; /* number of PAGE_SIZE'ed swap pages */ 235 int swpguniq; /* number of swap pages in use, not also in RAM */ 236 int swpginuse; /* number of swap pages in use */ 237 int swpgonly; /* number of swap pages in use, not also in RAM */ 238 int nswget; /* number of times fault calls uvm_swap_get() */ 239 int nanon; /* number total of anon's in system */ 240 int nanonneeded;/* number of anons currently needed */ 241 int nfreeanon; /* number of free anon's */ 242 243 /* stat counters */ 244 int faults; /* page fault count */ 245 int traps; /* trap count */ 246 int intrs; /* interrupt count */ 247 int swtch; /* context switch count */ 248 int softs; /* software interrupt count */ 249 int syscalls; /* system calls */ 250 int pageins; /* pagein operation count */ 251 /* pageouts are in pdpageouts below */ 252 int swapins; /* swapins */ 253 int swapouts; /* swapouts */ 254 int pgswapin; /* pages swapped in */ 255 int pgswapout; /* pages swapped out */ 256 int forks; /* forks */ 257 int forks_ppwait; /* forks where parent waits */ 258 int forks_sharevm; /* forks where vmspace is shared */ 259 int pga_zerohit; /* pagealloc where zero wanted and zero 260 was available */ 261 int pga_zeromiss; /* pagealloc where zero wanted and zero 262 not available */ 263 264 /* fault subcounters */ 265 int fltnoram; /* number of times fault was out of ram */ 266 int fltnoanon; /* number of times fault was out of anons */ 267 int fltpgwait; /* number of times fault had to wait on a page */ 268 int fltpgrele; /* number of times fault found a released page */ 269 int fltrelck; /* number of times fault relock called */ 270 int fltrelckok; /* number of times fault relock is a success */ 271 int fltanget; /* number of times fault gets anon page */ 272 int fltanretry; /* number of times fault retrys an anon get */ 273 int fltamcopy; /* number of times fault clears "needs copy" */ 274 int fltnamap; /* number of times fault maps a neighbor anon page */ 275 int fltnomap; /* number of times fault maps a neighbor obj page */ 276 int fltlget; /* number of times fault does a locked pgo_get */ 277 int fltget; /* number of times fault does an unlocked get */ 278 int flt_anon; /* number of times fault anon (case 1a) */ 279 int flt_acow; /* number of times fault anon cow (case 1b) */ 280 int flt_obj; /* number of times fault is on object page (2a) */ 281 int flt_prcopy; /* number of times fault promotes with copy (2b) */ 282 int flt_przero; /* number of times fault promotes with zerofill (2b) */ 283 284 /* daemon counters */ 285 int pdwoke; /* number of times daemon woke up */ 286 int pdrevs; /* number of times daemon rev'd clock hand */ 287 int pdswout; /* number of times daemon called for swapout */ 288 int pdfreed; /* number of pages daemon freed since boot */ 289 int pdscans; /* number of pages daemon scaned since boot */ 290 int pdanscan; /* number of anonymous pages scanned by daemon */ 291 int pdobscan; /* number of object pages scanned by daemon */ 292 int pdreact; /* number of pages daemon reactivated since boot */ 293 int pdbusy; /* number of times daemon found a busy page */ 294 int pdpageouts; /* number of times daemon started a pageout */ 295 int pdpending; /* number of times daemon got a pending pagout */ 296 int pddeact; /* number of pages daemon deactivates */ 297 298 /* kernel memory objects: managed by uvm_km_kmemalloc() only! */ 299 struct uvm_object *kmem_object; 300 struct uvm_object *mb_object; 301 }; 302 303 #ifdef _KERNEL 304 305 extern struct uvmexp uvmexp; 306 307 /* 308 * macros 309 */ 310 311 /* zalloc zeros memory, alloc does not */ 312 #define uvm_km_zalloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,TRUE) 313 #define uvm_km_alloc(MAP,SIZE) uvm_km_alloc1(MAP,SIZE,FALSE) 314 315 #endif /* _KERNEL */ 316 317 /* 318 * typedefs 319 */ 320 321 typedef unsigned int uvm_flag_t; 322 typedef int vm_fault_t; 323 324 #ifdef _KERNEL 325 326 /* uvm_aobj.c */ 327 struct uvm_object *uao_create __P((vsize_t, int)); 328 void uao_detach __P((struct uvm_object *)); 329 void uao_detach_locked __P((struct uvm_object *)); 330 void uao_reference __P((struct uvm_object *)); 331 void uao_reference_locked __P((struct uvm_object *)); 332 333 /* uvm_fault.c */ 334 int uvm_fault __P((vm_map_t, vaddr_t, 335 vm_fault_t, vm_prot_t)); 336 /* handle a page fault */ 337 338 /* uvm_glue.c */ 339 #if defined(KGDB) 340 void uvm_chgkprot __P((caddr_t, size_t, int)); 341 #endif 342 void uvm_fork __P((struct proc *, struct proc *, boolean_t, 343 void *, size_t)); 344 void uvm_exit __P((struct proc *)); 345 void uvm_init_limits __P((struct proc *)); 346 boolean_t uvm_kernacc __P((caddr_t, size_t, int)); 347 __dead void uvm_scheduler __P((void)); 348 void uvm_swapin __P((struct proc *)); 349 boolean_t uvm_useracc __P((caddr_t, size_t, int)); 350 int uvm_vslock __P((struct proc *, caddr_t, size_t, 351 vm_prot_t)); 352 void uvm_vsunlock __P((struct proc *, caddr_t, size_t)); 353 354 355 /* uvm_init.c */ 356 void uvm_init __P((void)); 357 /* init the uvm system */ 358 359 /* uvm_io.c */ 360 int uvm_io __P((vm_map_t, struct uio *)); 361 362 /* uvm_km.c */ 363 vaddr_t uvm_km_alloc1 __P((vm_map_t, vsize_t, boolean_t)); 364 void uvm_km_free __P((vm_map_t, vaddr_t, vsize_t)); 365 void uvm_km_free_wakeup __P((vm_map_t, vaddr_t, 366 vsize_t)); 367 vaddr_t uvm_km_kmemalloc __P((vm_map_t, struct uvm_object *, 368 vsize_t, int)); 369 struct vm_map *uvm_km_suballoc __P((vm_map_t, vaddr_t *, 370 vaddr_t *, vsize_t, int, 371 boolean_t, vm_map_t)); 372 vaddr_t uvm_km_valloc __P((vm_map_t, vsize_t)); 373 vaddr_t uvm_km_valloc_wait __P((vm_map_t, vsize_t)); 374 vaddr_t uvm_km_alloc_poolpage1 __P((vm_map_t, 375 struct uvm_object *, boolean_t)); 376 void uvm_km_free_poolpage1 __P((vm_map_t, vaddr_t)); 377 378 #define uvm_km_alloc_poolpage(waitok) uvm_km_alloc_poolpage1(kmem_map, \ 379 uvmexp.kmem_object, (waitok)) 380 #define uvm_km_free_poolpage(addr) uvm_km_free_poolpage1(kmem_map, (addr)) 381 382 /* uvm_map.c */ 383 int uvm_map __P((vm_map_t, vaddr_t *, vsize_t, 384 struct uvm_object *, voff_t, uvm_flag_t)); 385 int uvm_map_pageable __P((vm_map_t, vaddr_t, 386 vaddr_t, boolean_t, int)); 387 int uvm_map_pageable_all __P((vm_map_t, int, vsize_t)); 388 boolean_t uvm_map_checkprot __P((vm_map_t, vaddr_t, 389 vaddr_t, vm_prot_t)); 390 int uvm_map_protect __P((vm_map_t, vaddr_t, 391 vaddr_t, vm_prot_t, boolean_t)); 392 struct vmspace *uvmspace_alloc __P((vaddr_t, vaddr_t, 393 boolean_t)); 394 void uvmspace_init __P((struct vmspace *, struct pmap *, 395 vaddr_t, vaddr_t, boolean_t)); 396 void uvmspace_exec __P((struct proc *)); 397 struct vmspace *uvmspace_fork __P((struct vmspace *)); 398 void uvmspace_free __P((struct vmspace *)); 399 void uvmspace_share __P((struct proc *, struct proc *)); 400 void uvmspace_unshare __P((struct proc *)); 401 402 403 /* uvm_meter.c */ 404 void uvm_meter __P((void)); 405 int uvm_sysctl __P((int *, u_int, void *, size_t *, 406 void *, size_t, struct proc *)); 407 void uvm_total __P((struct vmtotal *)); 408 409 /* uvm_mmap.c */ 410 int uvm_mmap __P((vm_map_t, vaddr_t *, vsize_t, 411 vm_prot_t, vm_prot_t, int, 412 caddr_t, voff_t, vsize_t)); 413 414 /* uvm_page.c */ 415 struct vm_page *uvm_pagealloc_strat __P((struct uvm_object *, 416 voff_t, struct vm_anon *, int, int, int)); 417 #define uvm_pagealloc(obj, off, anon, flags) \ 418 uvm_pagealloc_strat((obj), (off), (anon), (flags), \ 419 UVM_PGA_STRAT_NORMAL, 0) 420 vaddr_t uvm_pagealloc_contig __P((vaddr_t, vaddr_t, 421 vaddr_t, vaddr_t)); 422 void uvm_pagerealloc __P((struct vm_page *, 423 struct uvm_object *, voff_t)); 424 /* Actually, uvm_page_physload takes PF#s which need their own type */ 425 void uvm_page_physload __P((paddr_t, paddr_t, 426 paddr_t, paddr_t, int)); 427 void uvm_setpagesize __P((void)); 428 429 /* uvm_pdaemon.c */ 430 void uvm_pageout __P((void)); 431 432 /* uvm_pglist.c */ 433 int uvm_pglistalloc __P((psize_t, paddr_t, 434 paddr_t, paddr_t, paddr_t, 435 struct pglist *, int, int)); 436 void uvm_pglistfree __P((struct pglist *)); 437 438 /* uvm_swap.c */ 439 void uvm_swap_init __P((void)); 440 441 /* uvm_unix.c */ 442 int uvm_coredump __P((struct proc *, struct vnode *, 443 struct ucred *, struct core *)); 444 int uvm_grow __P((struct proc *, vaddr_t)); 445 446 /* uvm_user.c */ 447 int uvm_deallocate __P((vm_map_t, vaddr_t, vsize_t)); 448 449 /* uvm_vnode.c */ 450 void uvm_vnp_setsize __P((struct vnode *, voff_t)); 451 void uvm_vnp_sync __P((struct mount *)); 452 void uvm_vnp_terminate __P((struct vnode *)); 453 /* terminate a uvm/uvn object */ 454 boolean_t uvm_vnp_uncache __P((struct vnode *)); 455 struct uvm_object *uvn_attach __P((void *, vm_prot_t)); 456 457 /* kern_malloc.c */ 458 void kmeminit_nkmempages __P((void)); 459 void kmeminit __P((void)); 460 extern int nkmempages; 461 462 void swstrategy __P((struct buf *)); 463 464 /* Machine dependent portion */ 465 void vmapbuf __P((struct buf *, vsize_t)); 466 void vunmapbuf __P((struct buf *, vsize_t)); 467 void pagemove __P((caddr_t, caddr_t, size_t)); 468 void cpu_fork __P((struct proc *, struct proc *, void *, size_t)); 469 #ifndef cpu_swapin 470 void cpu_swapin __P((struct proc *)); 471 #endif 472 #ifndef cpu_swapout 473 void cpu_swapout __P((struct proc *)); 474 #endif 475 476 #endif /* _KERNEL */ 477 #endif /* _UVM_UVM_EXTERN_H_ */ 478