vm_fault.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1994,1990,1989,1988,1987 Carnegie Mellon University.
  4. * Copyright (c) 1993,1994 The University of Utah and
  5. * the Computer Systems Laboratory (CSL).
  6. * All rights reserved.
  7. *
  8. * Permission to use, copy, modify and distribute this software and its
  9. * documentation is hereby granted, provided that both the copyright
  10. * notice and this permission notice appear in all copies of the
  11. * software, derivative works or modified versions, and any portions
  12. * thereof, and that both notices appear in supporting documentation.
  13. *
  14. * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF
  15. * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY
  16. * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
  17. * THIS SOFTWARE.
  18. *
  19. * Carnegie Mellon requests users of this software to return to
  20. *
  21. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  22. * School of Computer Science
  23. * Carnegie Mellon University
  24. * Pittsburgh PA 15213-3890
  25. *
  26. * any improvements or extensions that they make and grant Carnegie Mellon
  27. * the rights to redistribute these changes.
  28. */
  29. /*
  30. * File: vm_fault.c
  31. * Author: Avadis Tevanian, Jr., Michael Wayne Young
  32. *
  33. * Page fault handling module.
  34. */
  35. #include <kern/printf.h>
  36. #include <vm/vm_fault.h>
  37. #include <mach/kern_return.h>
  38. #include <mach/message.h> /* for error codes */
  39. #include <kern/counters.h>
  40. #include <kern/debug.h>
  41. #include <kern/thread.h>
  42. #include <kern/sched_prim.h>
  43. #include <vm/vm_map.h>
  44. #include <vm/vm_object.h>
  45. #include <vm/vm_page.h>
  46. #include <vm/pmap.h>
  47. #include <mach/vm_statistics.h>
  48. #include <vm/vm_pageout.h>
  49. #include <mach/vm_param.h>
  50. #include <mach/memory_object.h>
  51. #include <vm/memory_object_user.user.h>
  52. /* For memory_object_data_{request,unlock} */
  53. #include <kern/macros.h>
  54. #include <kern/slab.h>
  55. #if MACH_PCSAMPLE
  56. #include <kern/pc_sample.h>
  57. #endif
  58. /*
  59. * State needed by vm_fault_continue.
  60. * This is a little hefty to drop directly
  61. * into the thread structure.
  62. */
  63. typedef struct vm_fault_state {
  64. struct vm_map *vmf_map;
  65. vm_offset_t vmf_vaddr;
  66. vm_prot_t vmf_fault_type;
  67. boolean_t vmf_change_wiring;
  68. void (*vmf_continuation)();
  69. vm_map_version_t vmf_version;
  70. boolean_t vmf_wired;
  71. struct vm_object *vmf_object;
  72. vm_offset_t vmf_offset;
  73. vm_prot_t vmf_prot;
  74. boolean_t vmfp_backoff;
  75. struct vm_object *vmfp_object;
  76. vm_offset_t vmfp_offset;
  77. struct vm_page *vmfp_first_m;
  78. vm_prot_t vmfp_access;
  79. } vm_fault_state_t;
  80. struct kmem_cache vm_fault_state_cache;
  81. int vm_object_absent_max = 50;
  82. boolean_t vm_fault_dirty_handling = FALSE;
  83. boolean_t vm_fault_interruptible = TRUE;
  84. boolean_t software_reference_bits = TRUE;
  85. #if MACH_KDB
  86. extern struct db_watchpoint *db_watchpoint_list;
  87. #endif /* MACH_KDB */
  88. /*
  89. * Routine: vm_fault_init
  90. * Purpose:
  91. * Initialize our private data structures.
  92. */
  93. void vm_fault_init(void)
  94. {
  95. kmem_cache_init(&vm_fault_state_cache, "vm_fault_state",
  96. sizeof(vm_fault_state_t), 0, NULL, 0);
  97. }
  98. /*
  99. * Routine: vm_fault_cleanup
  100. * Purpose:
  101. * Clean up the result of vm_fault_page.
  102. * Results:
  103. * The paging reference for "object" is released.
  104. * "object" is unlocked.
  105. * If "top_page" is not null, "top_page" is
  106. * freed and the paging reference for the object
  107. * containing it is released.
  108. *
  109. * In/out conditions:
  110. * "object" must be locked.
  111. */
  112. void
  113. vm_fault_cleanup(
  114. vm_object_t object,
  115. vm_page_t top_page)
  116. {
  117. vm_object_paging_end(object);
  118. vm_object_unlock(object);
  119. if (top_page != VM_PAGE_NULL) {
  120. object = top_page->object;
  121. vm_object_lock(object);
  122. VM_PAGE_FREE(top_page);
  123. vm_object_paging_end(object);
  124. vm_object_unlock(object);
  125. }
  126. }
  127. #if MACH_PCSAMPLE
  128. /*
  129. * Do PC sampling on current thread, assuming
  130. * that it is the thread taking this page fault.
  131. *
  132. * Must check for THREAD_NULL, since faults
  133. * can occur before threads are running.
  134. */
  135. #define vm_stat_sample(flavor) \
  136. MACRO_BEGIN \
  137. thread_t _thread_ = current_thread(); \
  138. \
  139. if (_thread_ != THREAD_NULL) \
  140. take_pc_sample_macro(_thread_, (flavor), 1, 0); \
  141. MACRO_END
  142. #else
  143. #define vm_stat_sample(x)
  144. #endif /* MACH_PCSAMPLE */
  145. /*
  146. * Routine: vm_fault_page
  147. * Purpose:
  148. * Find the resident page for the virtual memory
  149. * specified by the given virtual memory object
  150. * and offset.
  151. * Additional arguments:
  152. * The required permissions for the page is given
  153. * in "fault_type". Desired permissions are included
  154. * in "protection".
  155. *
  156. * If the desired page is known to be resident (for
  157. * example, because it was previously wired down), asserting
  158. * the "unwiring" parameter will speed the search.
  159. *
  160. * If the operation can be interrupted (by thread_abort
  161. * or thread_terminate), then the "interruptible"
  162. * parameter should be asserted.
  163. *
  164. * Results:
  165. * The page containing the proper data is returned
  166. * in "result_page".
  167. *
  168. * In/out conditions:
  169. * The source object must be locked and referenced,
  170. * and must donate one paging reference. The reference
  171. * is not affected. The paging reference and lock are
  172. * consumed.
  173. *
  174. * If the call succeeds, the object in which "result_page"
  175. * resides is left locked and holding a paging reference.
  176. * If this is not the original object, a busy page in the
  177. * original object is returned in "top_page", to prevent other
  178. * callers from pursuing this same data, along with a paging
  179. * reference for the original object. The "top_page" should
  180. * be destroyed when this guarantee is no longer required.
  181. * The "result_page" is also left busy. It is not removed
  182. * from the pageout queues.
  183. */
  184. vm_fault_return_t vm_fault_page(
  185. /* Arguments: */
  186. vm_object_t first_object, /* Object to begin search */
  187. vm_offset_t first_offset, /* Offset into object */
  188. vm_prot_t fault_type, /* What access is requested */
  189. boolean_t must_be_resident,/* Must page be resident? */
  190. boolean_t interruptible, /* May fault be interrupted? */
  191. /* Modifies in place: */
  192. vm_prot_t *protection, /* Protection for mapping */
  193. /* Returns: */
  194. vm_page_t *result_page, /* Page found, if successful */
  195. vm_page_t *top_page, /* Page in top object, if
  196. * not result_page.
  197. */
  198. /* More arguments: */
  199. boolean_t resume, /* We are restarting. */
  200. void (*continuation)()) /* Continuation for blocking. */
  201. {
  202. vm_page_t m;
  203. vm_object_t object;
  204. vm_offset_t offset;
  205. vm_page_t first_m;
  206. vm_object_t next_object;
  207. vm_object_t copy_object;
  208. boolean_t look_for_page;
  209. vm_prot_t access_required;
  210. if (resume) {
  211. vm_fault_state_t *state =
  212. (vm_fault_state_t *) current_thread()->ith_other;
  213. if (state->vmfp_backoff)
  214. goto after_block_and_backoff;
  215. object = state->vmfp_object;
  216. offset = state->vmfp_offset;
  217. first_m = state->vmfp_first_m;
  218. access_required = state->vmfp_access;
  219. goto after_thread_block;
  220. }
  221. vm_stat_sample(SAMPLED_PC_VM_FAULTS_ANY);
  222. vm_stat.faults++; /* needs lock XXX */
  223. current_task()->faults++;
  224. /*
  225. * Recovery actions
  226. */
  227. #define RELEASE_PAGE(m) \
  228. MACRO_BEGIN \
  229. PAGE_WAKEUP_DONE(m); \
  230. vm_page_lock_queues(); \
  231. if (!m->active && !m->inactive) \
  232. vm_page_activate(m); \
  233. vm_page_unlock_queues(); \
  234. MACRO_END
  235. if (vm_fault_dirty_handling
  236. #if MACH_KDB
  237. /*
  238. * If there are watchpoints set, then
  239. * we don't want to give away write permission
  240. * on a read fault. Make the task write fault,
  241. * so that the watchpoint code notices the access.
  242. */
  243. || db_watchpoint_list
  244. #endif /* MACH_KDB */
  245. ) {
  246. /*
  247. * If we aren't asking for write permission,
  248. * then don't give it away. We're using write
  249. * faults to set the dirty bit.
  250. */
  251. if (!(fault_type & VM_PROT_WRITE))
  252. *protection &= ~VM_PROT_WRITE;
  253. }
  254. if (!vm_fault_interruptible)
  255. interruptible = FALSE;
  256. /*
  257. * INVARIANTS (through entire routine):
  258. *
  259. * 1) At all times, we must either have the object
  260. * lock or a busy page in some object to prevent
  261. * some other thread from trying to bring in
  262. * the same page.
  263. *
  264. * Note that we cannot hold any locks during the
  265. * pager access or when waiting for memory, so
  266. * we use a busy page then.
  267. *
  268. * Note also that we aren't as concerned about more than
  269. * one thread attempting to memory_object_data_unlock
  270. * the same page at once, so we don't hold the page
  271. * as busy then, but do record the highest unlock
  272. * value so far. [Unlock requests may also be delivered
  273. * out of order.]
  274. *
  275. * 2) To prevent another thread from racing us down the
  276. * shadow chain and entering a new page in the top
  277. * object before we do, we must keep a busy page in
  278. * the top object while following the shadow chain.
  279. *
  280. * 3) We must increment paging_in_progress on any object
  281. * for which we have a busy page, to prevent
  282. * vm_object_collapse from removing the busy page
  283. * without our noticing.
  284. *
  285. * 4) We leave busy pages on the pageout queues.
  286. * If the pageout daemon comes across a busy page,
  287. * it will remove the page from the pageout queues.
  288. */
  289. /*
  290. * Search for the page at object/offset.
  291. */
  292. object = first_object;
  293. offset = first_offset;
  294. first_m = VM_PAGE_NULL;
  295. access_required = fault_type;
  296. /*
  297. * See whether this page is resident
  298. */
  299. while (TRUE) {
  300. m = vm_page_lookup(object, offset);
  301. if (m != VM_PAGE_NULL) {
  302. /*
  303. * If the page is being brought in,
  304. * wait for it and then retry.
  305. *
  306. * A possible optimization: if the page
  307. * is known to be resident, we can ignore
  308. * pages that are absent (regardless of
  309. * whether they're busy).
  310. */
  311. if (m->busy) {
  312. kern_return_t wait_result;
  313. PAGE_ASSERT_WAIT(m, interruptible);
  314. vm_object_unlock(object);
  315. if (continuation != (void (*)()) 0) {
  316. vm_fault_state_t *state =
  317. (vm_fault_state_t *) current_thread()->ith_other;
  318. /*
  319. * Save variables in case
  320. * thread_block discards
  321. * our kernel stack.
  322. */
  323. state->vmfp_backoff = FALSE;
  324. state->vmfp_object = object;
  325. state->vmfp_offset = offset;
  326. state->vmfp_first_m = first_m;
  327. state->vmfp_access =
  328. access_required;
  329. state->vmf_prot = *protection;
  330. counter(c_vm_fault_page_block_busy_user++);
  331. thread_block(continuation);
  332. } else
  333. {
  334. counter(c_vm_fault_page_block_busy_kernel++);
  335. thread_block((void (*)()) 0);
  336. }
  337. after_thread_block:
  338. wait_result = current_thread()->wait_result;
  339. vm_object_lock(object);
  340. if (wait_result != THREAD_AWAKENED) {
  341. vm_fault_cleanup(object, first_m);
  342. if (wait_result == THREAD_RESTART)
  343. return(VM_FAULT_RETRY);
  344. else
  345. return(VM_FAULT_INTERRUPTED);
  346. }
  347. continue;
  348. }
  349. /*
  350. * If the page is in error, give up now.
  351. */
  352. if (m->error) {
  353. VM_PAGE_FREE(m);
  354. vm_fault_cleanup(object, first_m);
  355. return(VM_FAULT_MEMORY_ERROR);
  356. }
  357. /*
  358. * If the page isn't busy, but is absent,
  359. * then it was deemed "unavailable".
  360. */
  361. if (m->absent) {
  362. /*
  363. * Remove the non-existent page (unless it's
  364. * in the top object) and move on down to the
  365. * next object (if there is one).
  366. */
  367. offset += object->shadow_offset;
  368. access_required = VM_PROT_READ;
  369. next_object = object->shadow;
  370. if (next_object == VM_OBJECT_NULL) {
  371. vm_page_t real_m;
  372. assert(!must_be_resident);
  373. /*
  374. * Absent page at bottom of shadow
  375. * chain; zero fill the page we left
  376. * busy in the first object, and flush
  377. * the absent page. But first we
  378. * need to allocate a real page.
  379. */
  380. real_m = vm_page_grab();
  381. if (real_m == VM_PAGE_NULL) {
  382. vm_fault_cleanup(object, first_m);
  383. return(VM_FAULT_MEMORY_SHORTAGE);
  384. }
  385. if (object != first_object) {
  386. VM_PAGE_FREE(m);
  387. vm_object_paging_end(object);
  388. vm_object_unlock(object);
  389. object = first_object;
  390. offset = first_offset;
  391. m = first_m;
  392. first_m = VM_PAGE_NULL;
  393. vm_object_lock(object);
  394. }
  395. VM_PAGE_FREE(m);
  396. assert(real_m->busy);
  397. vm_page_lock_queues();
  398. vm_page_insert(real_m, object, offset);
  399. vm_page_unlock_queues();
  400. m = real_m;
  401. /*
  402. * Drop the lock while zero filling
  403. * page. Then break because this
  404. * is the page we wanted. Checking
  405. * the page lock is a waste of time;
  406. * this page was either absent or
  407. * newly allocated -- in both cases
  408. * it can't be page locked by a pager.
  409. */
  410. vm_object_unlock(object);
  411. vm_page_zero_fill(m);
  412. vm_stat_sample(SAMPLED_PC_VM_ZFILL_FAULTS);
  413. vm_stat.zero_fill_count++;
  414. current_task()->zero_fills++;
  415. vm_object_lock(object);
  416. pmap_clear_modify(m->phys_addr);
  417. break;
  418. } else {
  419. if (must_be_resident) {
  420. vm_object_paging_end(object);
  421. } else if (object != first_object) {
  422. vm_object_paging_end(object);
  423. VM_PAGE_FREE(m);
  424. } else {
  425. first_m = m;
  426. m->absent = FALSE;
  427. vm_object_absent_release(object);
  428. m->busy = TRUE;
  429. vm_page_lock_queues();
  430. VM_PAGE_QUEUES_REMOVE(m);
  431. vm_page_unlock_queues();
  432. }
  433. vm_object_lock(next_object);
  434. vm_object_unlock(object);
  435. object = next_object;
  436. vm_object_paging_begin(object);
  437. continue;
  438. }
  439. }
  440. /*
  441. * If the desired access to this page has
  442. * been locked out, request that it be unlocked.
  443. */
  444. if (access_required & m->page_lock) {
  445. if ((access_required & m->unlock_request) != access_required) {
  446. vm_prot_t new_unlock_request;
  447. kern_return_t rc;
  448. if (!object->pager_ready) {
  449. vm_object_assert_wait(object,
  450. VM_OBJECT_EVENT_PAGER_READY,
  451. interruptible);
  452. goto block_and_backoff;
  453. }
  454. new_unlock_request = m->unlock_request =
  455. (access_required | m->unlock_request);
  456. vm_object_unlock(object);
  457. if ((rc = memory_object_data_unlock(
  458. object->pager,
  459. object->pager_request,
  460. offset + object->paging_offset,
  461. PAGE_SIZE,
  462. new_unlock_request))
  463. != KERN_SUCCESS) {
  464. printf("vm_fault: memory_object_data_unlock failed\n");
  465. vm_object_lock(object);
  466. vm_fault_cleanup(object, first_m);
  467. return((rc == MACH_SEND_INTERRUPTED) ?
  468. VM_FAULT_INTERRUPTED :
  469. VM_FAULT_MEMORY_ERROR);
  470. }
  471. vm_object_lock(object);
  472. continue;
  473. }
  474. PAGE_ASSERT_WAIT(m, interruptible);
  475. goto block_and_backoff;
  476. }
  477. /*
  478. * We mark the page busy and leave it on
  479. * the pageout queues. If the pageout
  480. * deamon comes across it, then it will
  481. * remove the page.
  482. */
  483. if (!software_reference_bits) {
  484. vm_page_lock_queues();
  485. if (m->inactive) {
  486. vm_stat_sample(SAMPLED_PC_VM_REACTIVATION_FAULTS);
  487. vm_stat.reactivations++;
  488. current_task()->reactivations++;
  489. }
  490. VM_PAGE_QUEUES_REMOVE(m);
  491. vm_page_unlock_queues();
  492. }
  493. assert(!m->busy);
  494. m->busy = TRUE;
  495. assert(!m->absent);
  496. break;
  497. }
  498. look_for_page =
  499. (object->pager_created)
  500. #if MACH_PAGEMAP
  501. && (vm_external_state_get(object->existence_info, offset + object->paging_offset) !=
  502. VM_EXTERNAL_STATE_ABSENT)
  503. #endif /* MACH_PAGEMAP */
  504. ;
  505. if ((look_for_page || (object == first_object))
  506. && !must_be_resident) {
  507. /*
  508. * Allocate a new page for this object/offset
  509. * pair.
  510. */
  511. m = vm_page_grab_fictitious();
  512. if (m == VM_PAGE_NULL) {
  513. vm_fault_cleanup(object, first_m);
  514. return(VM_FAULT_FICTITIOUS_SHORTAGE);
  515. }
  516. vm_page_lock_queues();
  517. vm_page_insert(m, object, offset);
  518. vm_page_unlock_queues();
  519. }
  520. if (look_for_page && !must_be_resident) {
  521. kern_return_t rc;
  522. /*
  523. * If the memory manager is not ready, we
  524. * cannot make requests.
  525. */
  526. if (!object->pager_ready) {
  527. vm_object_assert_wait(object,
  528. VM_OBJECT_EVENT_PAGER_READY,
  529. interruptible);
  530. VM_PAGE_FREE(m);
  531. goto block_and_backoff;
  532. }
  533. if (object->internal) {
  534. /*
  535. * Requests to the default pager
  536. * must reserve a real page in advance,
  537. * because the pager's data-provided
  538. * won't block for pages.
  539. */
  540. if (m->fictitious && !vm_page_convert(&m)) {
  541. VM_PAGE_FREE(m);
  542. vm_fault_cleanup(object, first_m);
  543. return(VM_FAULT_MEMORY_SHORTAGE);
  544. }
  545. } else if (object->absent_count >
  546. vm_object_absent_max) {
  547. /*
  548. * If there are too many outstanding page
  549. * requests pending on this object, we
  550. * wait for them to be resolved now.
  551. */
  552. vm_object_absent_assert_wait(object, interruptible);
  553. VM_PAGE_FREE(m);
  554. goto block_and_backoff;
  555. }
  556. /*
  557. * Indicate that the page is waiting for data
  558. * from the memory manager.
  559. */
  560. m->absent = TRUE;
  561. object->absent_count++;
  562. /*
  563. * We have a busy page, so we can
  564. * release the object lock.
  565. */
  566. vm_object_unlock(object);
  567. /*
  568. * Call the memory manager to retrieve the data.
  569. */
  570. vm_stat.pageins++;
  571. vm_stat_sample(SAMPLED_PC_VM_PAGEIN_FAULTS);
  572. current_task()->pageins++;
  573. if ((rc = memory_object_data_request(object->pager,
  574. object->pager_request,
  575. m->offset + object->paging_offset,
  576. PAGE_SIZE, access_required)) != KERN_SUCCESS) {
  577. if (object->pager && rc != MACH_SEND_INTERRUPTED)
  578. printf("%s(0x%p, 0x%p, 0x%lx, 0x%x, 0x%x) failed, %x\n",
  579. "memory_object_data_request",
  580. object->pager,
  581. object->pager_request,
  582. m->offset + object->paging_offset,
  583. PAGE_SIZE, access_required, rc);
  584. /*
  585. * Don't want to leave a busy page around,
  586. * but the data request may have blocked,
  587. * so check if it's still there and busy.
  588. */
  589. vm_object_lock(object);
  590. if (m == vm_page_lookup(object,offset) &&
  591. m->absent && m->busy)
  592. VM_PAGE_FREE(m);
  593. vm_fault_cleanup(object, first_m);
  594. return((rc == MACH_SEND_INTERRUPTED) ?
  595. VM_FAULT_INTERRUPTED :
  596. VM_FAULT_MEMORY_ERROR);
  597. }
  598. /*
  599. * Retry with same object/offset, since new data may
  600. * be in a different page (i.e., m is meaningless at
  601. * this point).
  602. */
  603. vm_object_lock(object);
  604. continue;
  605. }
  606. /*
  607. * For the XP system, the only case in which we get here is if
  608. * object has no pager (or unwiring). If the pager doesn't
  609. * have the page this is handled in the m->absent case above
  610. * (and if you change things here you should look above).
  611. */
  612. if (object == first_object)
  613. first_m = m;
  614. else
  615. {
  616. assert(m == VM_PAGE_NULL);
  617. }
  618. /*
  619. * Move on to the next object. Lock the next
  620. * object before unlocking the current one.
  621. */
  622. access_required = VM_PROT_READ;
  623. offset += object->shadow_offset;
  624. next_object = object->shadow;
  625. if (next_object == VM_OBJECT_NULL) {
  626. assert(!must_be_resident);
  627. /*
  628. * If there's no object left, fill the page
  629. * in the top object with zeros. But first we
  630. * need to allocate a real page.
  631. */
  632. if (object != first_object) {
  633. vm_object_paging_end(object);
  634. vm_object_unlock(object);
  635. object = first_object;
  636. offset = first_offset;
  637. vm_object_lock(object);
  638. }
  639. m = first_m;
  640. assert(m->object == object);
  641. first_m = VM_PAGE_NULL;
  642. if (m->fictitious && !vm_page_convert(&m)) {
  643. VM_PAGE_FREE(m);
  644. vm_fault_cleanup(object, VM_PAGE_NULL);
  645. return(VM_FAULT_MEMORY_SHORTAGE);
  646. }
  647. vm_object_unlock(object);
  648. vm_page_zero_fill(m);
  649. vm_stat_sample(SAMPLED_PC_VM_ZFILL_FAULTS);
  650. vm_stat.zero_fill_count++;
  651. current_task()->zero_fills++;
  652. vm_object_lock(object);
  653. pmap_clear_modify(m->phys_addr);
  654. break;
  655. }
  656. else {
  657. vm_object_lock(next_object);
  658. if ((object != first_object) || must_be_resident)
  659. vm_object_paging_end(object);
  660. vm_object_unlock(object);
  661. object = next_object;
  662. vm_object_paging_begin(object);
  663. }
  664. }
  665. /*
  666. * PAGE HAS BEEN FOUND.
  667. *
  668. * This page (m) is:
  669. * busy, so that we can play with it;
  670. * not absent, so that nobody else will fill it;
  671. * possibly eligible for pageout;
  672. *
  673. * The top-level page (first_m) is:
  674. * VM_PAGE_NULL if the page was found in the
  675. * top-level object;
  676. * busy, not absent, and ineligible for pageout.
  677. *
  678. * The current object (object) is locked. A paging
  679. * reference is held for the current and top-level
  680. * objects.
  681. */
  682. assert(m->busy && !m->absent);
  683. assert((first_m == VM_PAGE_NULL) ||
  684. (first_m->busy && !first_m->absent &&
  685. !first_m->active && !first_m->inactive));
  686. /*
  687. * If the page is being written, but isn't
  688. * already owned by the top-level object,
  689. * we have to copy it into a new page owned
  690. * by the top-level object.
  691. */
  692. if (object != first_object) {
  693. /*
  694. * We only really need to copy if we
  695. * want to write it.
  696. */
  697. if (fault_type & VM_PROT_WRITE) {
  698. vm_page_t copy_m;
  699. assert(!must_be_resident);
  700. /*
  701. * If we try to collapse first_object at this
  702. * point, we may deadlock when we try to get
  703. * the lock on an intermediate object (since we
  704. * have the bottom object locked). We can't
  705. * unlock the bottom object, because the page
  706. * we found may move (by collapse) if we do.
  707. *
  708. * Instead, we first copy the page. Then, when
  709. * we have no more use for the bottom object,
  710. * we unlock it and try to collapse.
  711. *
  712. * Note that we copy the page even if we didn't
  713. * need to... that's the breaks.
  714. */
  715. /*
  716. * Allocate a page for the copy
  717. */
  718. copy_m = vm_page_grab();
  719. if (copy_m == VM_PAGE_NULL) {
  720. RELEASE_PAGE(m);
  721. vm_fault_cleanup(object, first_m);
  722. return(VM_FAULT_MEMORY_SHORTAGE);
  723. }
  724. vm_object_unlock(object);
  725. vm_page_copy(m, copy_m);
  726. vm_object_lock(object);
  727. /*
  728. * If another map is truly sharing this
  729. * page with us, we have to flush all
  730. * uses of the original page, since we
  731. * can't distinguish those which want the
  732. * original from those which need the
  733. * new copy.
  734. *
  735. * XXXO If we know that only one map has
  736. * access to this page, then we could
  737. * avoid the pmap_page_protect() call.
  738. */
  739. vm_page_lock_queues();
  740. vm_page_deactivate(m);
  741. pmap_page_protect(m->phys_addr, VM_PROT_NONE);
  742. vm_page_unlock_queues();
  743. /*
  744. * We no longer need the old page or object.
  745. */
  746. PAGE_WAKEUP_DONE(m);
  747. vm_object_paging_end(object);
  748. vm_object_unlock(object);
  749. vm_stat.cow_faults++;
  750. vm_stat_sample(SAMPLED_PC_VM_COW_FAULTS);
  751. current_task()->cow_faults++;
  752. object = first_object;
  753. offset = first_offset;
  754. vm_object_lock(object);
  755. VM_PAGE_FREE(first_m);
  756. first_m = VM_PAGE_NULL;
  757. assert(copy_m->busy);
  758. vm_page_lock_queues();
  759. vm_page_insert(copy_m, object, offset);
  760. vm_page_unlock_queues();
  761. m = copy_m;
  762. /*
  763. * Now that we've gotten the copy out of the
  764. * way, let's try to collapse the top object.
  765. * But we have to play ugly games with
  766. * paging_in_progress to do that...
  767. */
  768. vm_object_paging_end(object);
  769. vm_object_collapse(object);
  770. vm_object_paging_begin(object);
  771. }
  772. else {
  773. *protection &= (~VM_PROT_WRITE);
  774. }
  775. }
  776. /*
  777. * Now check whether the page needs to be pushed into the
  778. * copy object. The use of asymmetric copy on write for
  779. * shared temporary objects means that we may do two copies to
  780. * satisfy the fault; one above to get the page from a
  781. * shadowed object, and one here to push it into the copy.
  782. */
  783. while ((copy_object = first_object->copy) != VM_OBJECT_NULL) {
  784. vm_offset_t copy_offset;
  785. vm_page_t copy_m;
  786. /*
  787. * If the page is being written, but hasn't been
  788. * copied to the copy-object, we have to copy it there.
  789. */
  790. if ((fault_type & VM_PROT_WRITE) == 0) {
  791. *protection &= ~VM_PROT_WRITE;
  792. break;
  793. }
  794. /*
  795. * If the page was guaranteed to be resident,
  796. * we must have already performed the copy.
  797. */
  798. if (must_be_resident)
  799. break;
  800. /*
  801. * Try to get the lock on the copy_object.
  802. */
  803. if (!vm_object_lock_try(copy_object)) {
  804. vm_object_unlock(object);
  805. simple_lock_pause(); /* wait a bit */
  806. vm_object_lock(object);
  807. continue;
  808. }
  809. /*
  810. * Make another reference to the copy-object,
  811. * to keep it from disappearing during the
  812. * copy.
  813. */
  814. assert(copy_object->ref_count > 0);
  815. copy_object->ref_count++;
  816. /*
  817. * Does the page exist in the copy?
  818. */
  819. copy_offset = first_offset - copy_object->shadow_offset;
  820. copy_m = vm_page_lookup(copy_object, copy_offset);
  821. if (copy_m != VM_PAGE_NULL) {
  822. if (copy_m->busy) {
  823. /*
  824. * If the page is being brought
  825. * in, wait for it and then retry.
  826. */
  827. PAGE_ASSERT_WAIT(copy_m, interruptible);
  828. RELEASE_PAGE(m);
  829. copy_object->ref_count--;
  830. assert(copy_object->ref_count > 0);
  831. vm_object_unlock(copy_object);
  832. goto block_and_backoff;
  833. }
  834. }
  835. else {
  836. /*
  837. * Allocate a page for the copy
  838. */
  839. copy_m = vm_page_alloc(copy_object, copy_offset);
  840. if (copy_m == VM_PAGE_NULL) {
  841. RELEASE_PAGE(m);
  842. copy_object->ref_count--;
  843. assert(copy_object->ref_count > 0);
  844. vm_object_unlock(copy_object);
  845. vm_fault_cleanup(object, first_m);
  846. return(VM_FAULT_MEMORY_SHORTAGE);
  847. }
  848. /*
  849. * Must copy page into copy-object.
  850. */
  851. vm_page_copy(m, copy_m);
  852. /*
  853. * If the old page was in use by any users
  854. * of the copy-object, it must be removed
  855. * from all pmaps. (We can't know which
  856. * pmaps use it.)
  857. */
  858. vm_page_lock_queues();
  859. pmap_page_protect(m->phys_addr, VM_PROT_NONE);
  860. copy_m->dirty = TRUE;
  861. vm_page_unlock_queues();
  862. /*
  863. * If there's a pager, then immediately
  864. * page out this page, using the "initialize"
  865. * option. Else, we use the copy.
  866. */
  867. if (!copy_object->pager_created) {
  868. vm_page_lock_queues();
  869. vm_page_activate(copy_m);
  870. vm_page_unlock_queues();
  871. PAGE_WAKEUP_DONE(copy_m);
  872. } else {
  873. /*
  874. * The page is already ready for pageout:
  875. * not on pageout queues and busy.
  876. * Unlock everything except the
  877. * copy_object itself.
  878. */
  879. vm_object_unlock(object);
  880. /*
  881. * Write the page to the copy-object,
  882. * flushing it from the kernel.
  883. */
  884. vm_pageout_page(copy_m, TRUE, TRUE);
  885. /*
  886. * Since the pageout may have
  887. * temporarily dropped the
  888. * copy_object's lock, we
  889. * check whether we'll have
  890. * to deallocate the hard way.
  891. */
  892. if ((copy_object->shadow != object) ||
  893. (copy_object->ref_count == 1)) {
  894. vm_object_unlock(copy_object);
  895. vm_object_deallocate(copy_object);
  896. vm_object_lock(object);
  897. continue;
  898. }
  899. /*
  900. * Pick back up the old object's
  901. * lock. [It is safe to do so,
  902. * since it must be deeper in the
  903. * object tree.]
  904. */
  905. vm_object_lock(object);
  906. }
  907. /*
  908. * Because we're pushing a page upward
  909. * in the object tree, we must restart
  910. * any faults that are waiting here.
  911. * [Note that this is an expansion of
  912. * PAGE_WAKEUP that uses the THREAD_RESTART
  913. * wait result]. Can't turn off the page's
  914. * busy bit because we're not done with it.
  915. */
  916. if (m->wanted) {
  917. m->wanted = FALSE;
  918. thread_wakeup_with_result((event_t) m,
  919. THREAD_RESTART);
  920. }
  921. }
  922. /*
  923. * The reference count on copy_object must be
  924. * at least 2: one for our extra reference,
  925. * and at least one from the outside world
  926. * (we checked that when we last locked
  927. * copy_object).
  928. */
  929. copy_object->ref_count--;
  930. assert(copy_object->ref_count > 0);
  931. vm_object_unlock(copy_object);
  932. break;
  933. }
  934. *result_page = m;
  935. *top_page = first_m;
  936. /*
  937. * If the page can be written, assume that it will be.
  938. * [Earlier, we restrict the permission to allow write
  939. * access only if the fault so required, so we don't
  940. * mark read-only data as dirty.]
  941. */
  942. if (vm_fault_dirty_handling && (*protection & VM_PROT_WRITE))
  943. m->dirty = TRUE;
  944. return(VM_FAULT_SUCCESS);
  945. block_and_backoff:
  946. vm_fault_cleanup(object, first_m);
  947. if (continuation != (void (*)()) 0) {
  948. vm_fault_state_t *state =
  949. (vm_fault_state_t *) current_thread()->ith_other;
  950. /*
  951. * Save variables in case we must restart.
  952. */
  953. state->vmfp_backoff = TRUE;
  954. state->vmf_prot = *protection;
  955. counter(c_vm_fault_page_block_backoff_user++);
  956. thread_block(continuation);
  957. } else
  958. {
  959. counter(c_vm_fault_page_block_backoff_kernel++);
  960. thread_block((void (*)()) 0);
  961. }
  962. after_block_and_backoff:
  963. if (current_thread()->wait_result == THREAD_AWAKENED)
  964. return VM_FAULT_RETRY;
  965. else
  966. return VM_FAULT_INTERRUPTED;
  967. #undef RELEASE_PAGE
  968. }
  969. /*
  970. * Routine: vm_fault
  971. * Purpose:
  972. * Handle page faults, including pseudo-faults
  973. * used to change the wiring status of pages.
  974. * Returns:
  975. * If an explicit (expression) continuation is supplied,
  976. * then we call the continuation instead of returning.
  977. * Implementation:
  978. * Explicit continuations make this a little icky,
  979. * because it hasn't been rewritten to embrace CPS.
  980. * Instead, we have resume arguments for vm_fault and
  981. * vm_fault_page, to let continue the fault computation.
  982. *
  983. * vm_fault and vm_fault_page save mucho state
  984. * in the moral equivalent of a closure. The state
  985. * structure is allocated when first entering vm_fault
  986. * and deallocated when leaving vm_fault.
  987. */
  988. void
  989. vm_fault_continue(void)
  990. {
  991. vm_fault_state_t *state =
  992. (vm_fault_state_t *) current_thread()->ith_other;
  993. (void) vm_fault(state->vmf_map,
  994. state->vmf_vaddr,
  995. state->vmf_fault_type,
  996. state->vmf_change_wiring,
  997. TRUE, state->vmf_continuation);
  998. /*NOTREACHED*/
  999. }
  1000. kern_return_t vm_fault(
  1001. vm_map_t map,
  1002. vm_offset_t vaddr,
  1003. vm_prot_t fault_type,
  1004. boolean_t change_wiring,
  1005. boolean_t resume,
  1006. void (*continuation)())
  1007. {
  1008. vm_map_version_t version; /* Map version for verificiation */
  1009. boolean_t wired; /* Should mapping be wired down? */
  1010. vm_object_t object; /* Top-level object */
  1011. vm_offset_t offset; /* Top-level offset */
  1012. vm_prot_t prot; /* Protection for mapping */
  1013. vm_object_t old_copy_object; /* Saved copy object */
  1014. vm_page_t result_page; /* Result of vm_fault_page */
  1015. vm_page_t top_page; /* Placeholder page */
  1016. kern_return_t kr;
  1017. vm_page_t m; /* Fast access to result_page */
  1018. if (resume) {
  1019. vm_fault_state_t *state =
  1020. (vm_fault_state_t *) current_thread()->ith_other;
  1021. /*
  1022. * Retrieve cached variables and
  1023. * continue vm_fault_page.
  1024. */
  1025. object = state->vmf_object;
  1026. if (object == VM_OBJECT_NULL)
  1027. goto RetryFault;
  1028. version = state->vmf_version;
  1029. wired = state->vmf_wired;
  1030. offset = state->vmf_offset;
  1031. prot = state->vmf_prot;
  1032. kr = vm_fault_page(object, offset, fault_type,
  1033. (change_wiring && !wired), !change_wiring,
  1034. &prot, &result_page, &top_page,
  1035. TRUE, vm_fault_continue);
  1036. goto after_vm_fault_page;
  1037. }
  1038. if (continuation != (void (*)()) 0) {
  1039. /*
  1040. * We will probably need to save state.
  1041. */
  1042. char * state;
  1043. /*
  1044. * if this assignment stmt is written as
  1045. * 'active_threads[cpu_number()] = kmem_cache_alloc()',
  1046. * cpu_number may be evaluated before kmem_cache_alloc;
  1047. * if kmem_cache_alloc blocks, cpu_number will be wrong
  1048. */
  1049. state = (char *) kmem_cache_alloc(&vm_fault_state_cache);
  1050. current_thread()->ith_other = state;
  1051. }
  1052. RetryFault: ;
  1053. /*
  1054. * Find the backing store object and offset into
  1055. * it to begin the search.
  1056. */
  1057. if ((kr = vm_map_lookup(&map, vaddr, fault_type, &version,
  1058. &object, &offset,
  1059. &prot, &wired)) != KERN_SUCCESS) {
  1060. goto done;
  1061. }
  1062. /*
  1063. * If the page is wired, we must fault for the current protection
  1064. * value, to avoid further faults.
  1065. */
  1066. if (wired)
  1067. fault_type = prot;
  1068. /*
  1069. * Make a reference to this object to
  1070. * prevent its disposal while we are messing with
  1071. * it. Once we have the reference, the map is free
  1072. * to be diddled. Since objects reference their
  1073. * shadows (and copies), they will stay around as well.
  1074. */
  1075. assert(object->ref_count > 0);
  1076. object->ref_count++;
  1077. vm_object_paging_begin(object);
  1078. if (continuation != (void (*)()) 0) {
  1079. vm_fault_state_t *state =
  1080. (vm_fault_state_t *) current_thread()->ith_other;
  1081. /*
  1082. * Save variables, in case vm_fault_page discards
  1083. * our kernel stack and we have to restart.
  1084. */
  1085. state->vmf_map = map;
  1086. state->vmf_vaddr = vaddr;
  1087. state->vmf_fault_type = fault_type;
  1088. state->vmf_change_wiring = change_wiring;
  1089. state->vmf_continuation = continuation;
  1090. state->vmf_version = version;
  1091. state->vmf_wired = wired;
  1092. state->vmf_object = object;
  1093. state->vmf_offset = offset;
  1094. state->vmf_prot = prot;
  1095. kr = vm_fault_page(object, offset, fault_type,
  1096. (change_wiring && !wired), !change_wiring,
  1097. &prot, &result_page, &top_page,
  1098. FALSE, vm_fault_continue);
  1099. } else
  1100. {
  1101. kr = vm_fault_page(object, offset, fault_type,
  1102. (change_wiring && !wired), !change_wiring,
  1103. &prot, &result_page, &top_page,
  1104. FALSE, (void (*)()) 0);
  1105. }
  1106. after_vm_fault_page:
  1107. /*
  1108. * If we didn't succeed, lose the object reference immediately.
  1109. */
  1110. if (kr != VM_FAULT_SUCCESS)
  1111. vm_object_deallocate(object);
  1112. /*
  1113. * See why we failed, and take corrective action.
  1114. */
  1115. switch (kr) {
  1116. case VM_FAULT_SUCCESS:
  1117. break;
  1118. case VM_FAULT_RETRY:
  1119. goto RetryFault;
  1120. case VM_FAULT_INTERRUPTED:
  1121. kr = KERN_SUCCESS;
  1122. goto done;
  1123. case VM_FAULT_MEMORY_SHORTAGE:
  1124. if (continuation != (void (*)()) 0) {
  1125. vm_fault_state_t *state =
  1126. (vm_fault_state_t *) current_thread()->ith_other;
  1127. /*
  1128. * Save variables in case VM_PAGE_WAIT
  1129. * discards our kernel stack.
  1130. */
  1131. state->vmf_map = map;
  1132. state->vmf_vaddr = vaddr;
  1133. state->vmf_fault_type = fault_type;
  1134. state->vmf_change_wiring = change_wiring;
  1135. state->vmf_continuation = continuation;
  1136. state->vmf_object = VM_OBJECT_NULL;
  1137. VM_PAGE_WAIT(vm_fault_continue);
  1138. } else
  1139. VM_PAGE_WAIT((void (*)()) 0);
  1140. goto RetryFault;
  1141. case VM_FAULT_FICTITIOUS_SHORTAGE:
  1142. vm_page_more_fictitious();
  1143. goto RetryFault;
  1144. case VM_FAULT_MEMORY_ERROR:
  1145. kr = KERN_MEMORY_ERROR;
  1146. goto done;
  1147. }
  1148. m = result_page;
  1149. assert((change_wiring && !wired) ?
  1150. (top_page == VM_PAGE_NULL) :
  1151. ((top_page == VM_PAGE_NULL) == (m->object == object)));
  1152. /*
  1153. * How to clean up the result of vm_fault_page. This
  1154. * happens whether the mapping is entered or not.
  1155. */
  1156. #define UNLOCK_AND_DEALLOCATE \
  1157. MACRO_BEGIN \
  1158. vm_fault_cleanup(m->object, top_page); \
  1159. vm_object_deallocate(object); \
  1160. MACRO_END
  1161. /*
  1162. * What to do with the resulting page from vm_fault_page
  1163. * if it doesn't get entered into the physical map:
  1164. */
  1165. #define RELEASE_PAGE(m) \
  1166. MACRO_BEGIN \
  1167. PAGE_WAKEUP_DONE(m); \
  1168. vm_page_lock_queues(); \
  1169. if (!m->active && !m->inactive) \
  1170. vm_page_activate(m); \
  1171. vm_page_unlock_queues(); \
  1172. MACRO_END
  1173. /*
  1174. * We must verify that the maps have not changed
  1175. * since our last lookup.
  1176. */
  1177. old_copy_object = m->object->copy;
  1178. vm_object_unlock(m->object);
  1179. while (!vm_map_verify(map, &version)) {
  1180. vm_object_t retry_object;
  1181. vm_offset_t retry_offset;
  1182. vm_prot_t retry_prot;
  1183. /*
  1184. * To avoid trying to write_lock the map while another
  1185. * thread has it read_locked (in vm_map_pageable), we
  1186. * do not try for write permission. If the page is
  1187. * still writable, we will get write permission. If it
  1188. * is not, or has been marked needs_copy, we enter the
  1189. * mapping without write permission, and will merely
  1190. * take another fault.
  1191. */
  1192. kr = vm_map_lookup(&map, vaddr,
  1193. fault_type & ~VM_PROT_WRITE, &version,
  1194. &retry_object, &retry_offset, &retry_prot,
  1195. &wired);
  1196. if (kr != KERN_SUCCESS) {
  1197. vm_object_lock(m->object);
  1198. RELEASE_PAGE(m);
  1199. UNLOCK_AND_DEALLOCATE;
  1200. goto done;
  1201. }
  1202. vm_object_unlock(retry_object);
  1203. vm_object_lock(m->object);
  1204. if ((retry_object != object) ||
  1205. (retry_offset != offset)) {
  1206. RELEASE_PAGE(m);
  1207. UNLOCK_AND_DEALLOCATE;
  1208. goto RetryFault;
  1209. }
  1210. /*
  1211. * Check whether the protection has changed or the object
  1212. * has been copied while we left the map unlocked.
  1213. */
  1214. prot &= retry_prot;
  1215. vm_object_unlock(m->object);
  1216. }
  1217. vm_object_lock(m->object);
  1218. /*
  1219. * If the copy object changed while the top-level object
  1220. * was unlocked, then we must take away write permission.
  1221. */
  1222. if (m->object->copy != old_copy_object)
  1223. prot &= ~VM_PROT_WRITE;
  1224. /*
  1225. * If we want to wire down this page, but no longer have
  1226. * adequate permissions, we must start all over.
  1227. */
  1228. if (wired && (prot != fault_type)) {
  1229. vm_map_verify_done(map, &version);
  1230. RELEASE_PAGE(m);
  1231. UNLOCK_AND_DEALLOCATE;
  1232. goto RetryFault;
  1233. }
  1234. /*
  1235. * It's critically important that a wired-down page be faulted
  1236. * only once in each map for which it is wired.
  1237. */
  1238. vm_object_unlock(m->object);
  1239. /*
  1240. * Put this page into the physical map.
  1241. * We had to do the unlock above because pmap_enter
  1242. * may cause other faults. The page may be on
  1243. * the pageout queues. If the pageout daemon comes
  1244. * across the page, it will remove it from the queues.
  1245. */
  1246. PMAP_ENTER(map->pmap, vaddr, m, prot, wired);
  1247. /*
  1248. * If the page is not wired down and isn't already
  1249. * on a pageout queue, then put it where the
  1250. * pageout daemon can find it.
  1251. */
  1252. vm_object_lock(m->object);
  1253. vm_page_lock_queues();
  1254. if (change_wiring) {
  1255. if (wired)
  1256. vm_page_wire(m);
  1257. else
  1258. vm_page_unwire(m);
  1259. } else if (software_reference_bits) {
  1260. if (!m->active && !m->inactive)
  1261. vm_page_activate(m);
  1262. m->reference = TRUE;
  1263. } else {
  1264. vm_page_activate(m);
  1265. }
  1266. vm_page_unlock_queues();
  1267. /*
  1268. * Unlock everything, and return
  1269. */
  1270. vm_map_verify_done(map, &version);
  1271. PAGE_WAKEUP_DONE(m);
  1272. kr = KERN_SUCCESS;
  1273. UNLOCK_AND_DEALLOCATE;
  1274. #undef UNLOCK_AND_DEALLOCATE
  1275. #undef RELEASE_PAGE
  1276. done:
  1277. if (continuation != (void (*)()) 0) {
  1278. vm_fault_state_t *state =
  1279. (vm_fault_state_t *) current_thread()->ith_other;
  1280. kmem_cache_free(&vm_fault_state_cache, (vm_offset_t) state);
  1281. (*continuation)(kr);
  1282. /*NOTREACHED*/
  1283. }
  1284. return(kr);
  1285. }
  1286. /*
  1287. * vm_fault_wire:
  1288. *
  1289. * Wire down a range of virtual addresses in a map.
  1290. */
  1291. void vm_fault_wire(
  1292. vm_map_t map,
  1293. vm_map_entry_t entry)
  1294. {
  1295. vm_offset_t va;
  1296. pmap_t pmap;
  1297. vm_offset_t end_addr = entry->vme_end;
  1298. pmap = vm_map_pmap(map);
  1299. /*
  1300. * Inform the physical mapping system that the
  1301. * range of addresses may not fault, so that
  1302. * page tables and such can be locked down as well.
  1303. */
  1304. pmap_pageable(pmap, entry->vme_start, end_addr, FALSE);
  1305. /*
  1306. * We simulate a fault to get the page and enter it
  1307. * in the physical map.
  1308. */
  1309. for (va = entry->vme_start; va < end_addr; va += PAGE_SIZE) {
  1310. if (vm_fault_wire_fast(map, va, entry) != KERN_SUCCESS)
  1311. (void) vm_fault(map, va, VM_PROT_NONE, TRUE,
  1312. FALSE, (void (*)()) 0);
  1313. }
  1314. }
  1315. /*
  1316. * vm_fault_unwire:
  1317. *
  1318. * Unwire a range of virtual addresses in a map.
  1319. */
  1320. void vm_fault_unwire(
  1321. vm_map_t map,
  1322. vm_map_entry_t entry)
  1323. {
  1324. vm_offset_t va;
  1325. pmap_t pmap;
  1326. vm_offset_t end_addr = entry->vme_end;
  1327. vm_object_t object;
  1328. pmap = vm_map_pmap(map);
  1329. object = (entry->is_sub_map)
  1330. ? VM_OBJECT_NULL : entry->object.vm_object;
  1331. /*
  1332. * Since the pages are wired down, we must be able to
  1333. * get their mappings from the physical map system.
  1334. */
  1335. for (va = entry->vme_start; va < end_addr; va += PAGE_SIZE) {
  1336. pmap_change_wiring(pmap, va, FALSE);
  1337. if (object == VM_OBJECT_NULL) {
  1338. vm_map_lock_set_recursive(map);
  1339. (void) vm_fault(map, va, VM_PROT_NONE, TRUE,
  1340. FALSE, (void (*)()) 0);
  1341. vm_map_lock_clear_recursive(map);
  1342. } else {
  1343. vm_prot_t prot;
  1344. vm_page_t result_page;
  1345. vm_page_t top_page;
  1346. vm_fault_return_t result;
  1347. do {
  1348. prot = VM_PROT_NONE;
  1349. vm_object_lock(object);
  1350. vm_object_paging_begin(object);
  1351. result = vm_fault_page(object,
  1352. entry->offset +
  1353. (va - entry->vme_start),
  1354. VM_PROT_NONE, TRUE,
  1355. FALSE, &prot,
  1356. &result_page,
  1357. &top_page,
  1358. FALSE, (void (*)()) 0);
  1359. } while (result == VM_FAULT_RETRY);
  1360. if (result != VM_FAULT_SUCCESS)
  1361. panic("vm_fault_unwire: failure");
  1362. vm_page_lock_queues();
  1363. vm_page_unwire(result_page);
  1364. vm_page_unlock_queues();
  1365. PAGE_WAKEUP_DONE(result_page);
  1366. vm_fault_cleanup(result_page->object, top_page);
  1367. }
  1368. }
  1369. /*
  1370. * Inform the physical mapping system that the range
  1371. * of addresses may fault, so that page tables and
  1372. * such may be unwired themselves.
  1373. */
  1374. pmap_pageable(pmap, entry->vme_start, end_addr, TRUE);
  1375. }
  1376. /*
  1377. * vm_fault_wire_fast:
  1378. *
  1379. * Handle common case of a wire down page fault at the given address.
  1380. * If successful, the page is inserted into the associated physical map.
  1381. * The map entry is passed in to avoid the overhead of a map lookup.
  1382. *
  1383. * NOTE: the given address should be truncated to the
  1384. * proper page address.
  1385. *
  1386. * KERN_SUCCESS is returned if the page fault is handled; otherwise,
  1387. * a standard error specifying why the fault is fatal is returned.
  1388. *
  1389. * The map in question must be referenced, and remains so.
  1390. * Caller has a read lock on the map.
  1391. *
  1392. * This is a stripped version of vm_fault() for wiring pages. Anything
  1393. * other than the common case will return KERN_FAILURE, and the caller
  1394. * is expected to call vm_fault().
  1395. */
  1396. kern_return_t vm_fault_wire_fast(
  1397. vm_map_t map,
  1398. vm_offset_t va,
  1399. vm_map_entry_t entry)
  1400. {
  1401. vm_object_t object;
  1402. vm_offset_t offset;
  1403. vm_page_t m;
  1404. vm_prot_t prot;
  1405. vm_stat.faults++; /* needs lock XXX */
  1406. current_task()->faults++;
  1407. /*
  1408. * Recovery actions
  1409. */
  1410. #undef RELEASE_PAGE
  1411. #define RELEASE_PAGE(m) { \
  1412. PAGE_WAKEUP_DONE(m); \
  1413. vm_page_lock_queues(); \
  1414. vm_page_unwire(m); \
  1415. vm_page_unlock_queues(); \
  1416. }
  1417. #undef UNLOCK_THINGS
  1418. #define UNLOCK_THINGS { \
  1419. object->paging_in_progress--; \
  1420. vm_object_unlock(object); \
  1421. }
  1422. #undef UNLOCK_AND_DEALLOCATE
  1423. #define UNLOCK_AND_DEALLOCATE { \
  1424. UNLOCK_THINGS; \
  1425. vm_object_deallocate(object); \
  1426. }
  1427. /*
  1428. * Give up and have caller do things the hard way.
  1429. */
  1430. #define GIVE_UP { \
  1431. UNLOCK_AND_DEALLOCATE; \
  1432. return(KERN_FAILURE); \
  1433. }
  1434. /*
  1435. * If this entry is not directly to a vm_object, bail out.
  1436. */
  1437. if (entry->is_sub_map)
  1438. return(KERN_FAILURE);
  1439. /*
  1440. * Find the backing store object and offset into it.
  1441. */
  1442. object = entry->object.vm_object;
  1443. offset = (va - entry->vme_start) + entry->offset;
  1444. prot = entry->protection;
  1445. /*
  1446. * Make a reference to this object to prevent its
  1447. * disposal while we are messing with it.
  1448. */
  1449. vm_object_lock(object);
  1450. assert(object->ref_count > 0);
  1451. object->ref_count++;
  1452. object->paging_in_progress++;
  1453. /*
  1454. * INVARIANTS (through entire routine):
  1455. *
  1456. * 1) At all times, we must either have the object
  1457. * lock or a busy page in some object to prevent
  1458. * some other thread from trying to bring in
  1459. * the same page.
  1460. *
  1461. * 2) Once we have a busy page, we must remove it from
  1462. * the pageout queues, so that the pageout daemon
  1463. * will not grab it away.
  1464. *
  1465. */
  1466. /*
  1467. * Look for page in top-level object. If it's not there or
  1468. * there's something going on, give up.
  1469. */
  1470. m = vm_page_lookup(object, offset);
  1471. if ((m == VM_PAGE_NULL) || (m->error) ||
  1472. (m->busy) || (m->absent) || (prot & m->page_lock)) {
  1473. GIVE_UP;
  1474. }
  1475. /*
  1476. * Wire the page down now. All bail outs beyond this
  1477. * point must unwire the page.
  1478. */
  1479. vm_page_lock_queues();
  1480. vm_page_wire(m);
  1481. vm_page_unlock_queues();
  1482. /*
  1483. * Mark page busy for other threads.
  1484. */
  1485. assert(!m->busy);
  1486. m->busy = TRUE;
  1487. assert(!m->absent);
  1488. /*
  1489. * Give up if the page is being written and there's a copy object
  1490. */
  1491. if ((object->copy != VM_OBJECT_NULL) && (prot & VM_PROT_WRITE)) {
  1492. RELEASE_PAGE(m);
  1493. GIVE_UP;
  1494. }
  1495. /*
  1496. * Put this page into the physical map.
  1497. * We have to unlock the object because pmap_enter
  1498. * may cause other faults.
  1499. */
  1500. vm_object_unlock(object);
  1501. PMAP_ENTER(map->pmap, va, m, prot, TRUE);
  1502. /*
  1503. * Must relock object so that paging_in_progress can be cleared.
  1504. */
  1505. vm_object_lock(object);
  1506. /*
  1507. * Unlock everything, and return
  1508. */
  1509. PAGE_WAKEUP_DONE(m);
  1510. UNLOCK_AND_DEALLOCATE;
  1511. return(KERN_SUCCESS);
  1512. }
  1513. /*
  1514. * Routine: vm_fault_copy_cleanup
  1515. * Purpose:
  1516. * Release a page used by vm_fault_copy.
  1517. */
  1518. void vm_fault_copy_cleanup(
  1519. vm_page_t page,
  1520. vm_page_t top_page)
  1521. {
  1522. vm_object_t object = page->object;
  1523. vm_object_lock(object);
  1524. PAGE_WAKEUP_DONE(page);
  1525. vm_page_lock_queues();
  1526. if (!page->active && !page->inactive)
  1527. vm_page_activate(page);
  1528. vm_page_unlock_queues();
  1529. vm_fault_cleanup(object, top_page);
  1530. }
  1531. /*
  1532. * Routine: vm_fault_copy
  1533. *
  1534. * Purpose:
  1535. * Copy pages from one virtual memory object to another --
  1536. * neither the source nor destination pages need be resident.
  1537. *
  1538. * Before actually copying a page, the version associated with
  1539. * the destination address map wil be verified.
  1540. *
  1541. * In/out conditions:
  1542. * The caller must hold a reference, but not a lock, to
  1543. * each of the source and destination objects and to the
  1544. * destination map.
  1545. *
  1546. * Results:
  1547. * Returns KERN_SUCCESS if no errors were encountered in
  1548. * reading or writing the data. Returns KERN_INTERRUPTED if
  1549. * the operation was interrupted (only possible if the
  1550. * "interruptible" argument is asserted). Other return values
  1551. * indicate a permanent error in copying the data.
  1552. *
  1553. * The actual amount of data copied will be returned in the
  1554. * "copy_size" argument. In the event that the destination map
  1555. * verification failed, this amount may be less than the amount
  1556. * requested.
  1557. */
  1558. kern_return_t vm_fault_copy(
  1559. vm_object_t src_object,
  1560. vm_offset_t src_offset,
  1561. vm_size_t *src_size, /* INOUT */
  1562. vm_object_t dst_object,
  1563. vm_offset_t dst_offset,
  1564. vm_map_t dst_map,
  1565. vm_map_version_t *dst_version,
  1566. boolean_t interruptible)
  1567. {
  1568. vm_page_t result_page;
  1569. vm_prot_t prot;
  1570. vm_page_t src_page;
  1571. vm_page_t src_top_page;
  1572. vm_page_t dst_page;
  1573. vm_page_t dst_top_page;
  1574. vm_size_t amount_done;
  1575. vm_object_t old_copy_object;
  1576. #define RETURN(x) \
  1577. MACRO_BEGIN \
  1578. *src_size = amount_done; \
  1579. MACRO_RETURN(x); \
  1580. MACRO_END
  1581. amount_done = 0;
  1582. do { /* while (amount_done != *src_size) */
  1583. RetrySourceFault: ;
  1584. if (src_object == VM_OBJECT_NULL) {
  1585. /*
  1586. * No source object. We will just
  1587. * zero-fill the page in dst_object.
  1588. */
  1589. src_page = VM_PAGE_NULL;
  1590. } else {
  1591. prot = VM_PROT_READ;
  1592. vm_object_lock(src_object);
  1593. vm_object_paging_begin(src_object);
  1594. switch (vm_fault_page(src_object, src_offset,
  1595. VM_PROT_READ, FALSE, interruptible,
  1596. &prot, &result_page, &src_top_page,
  1597. FALSE, (void (*)()) 0)) {
  1598. case VM_FAULT_SUCCESS:
  1599. break;
  1600. case VM_FAULT_RETRY:
  1601. goto RetrySourceFault;
  1602. case VM_FAULT_INTERRUPTED:
  1603. RETURN(MACH_SEND_INTERRUPTED);
  1604. case VM_FAULT_MEMORY_SHORTAGE:
  1605. VM_PAGE_WAIT((void (*)()) 0);
  1606. goto RetrySourceFault;
  1607. case VM_FAULT_FICTITIOUS_SHORTAGE:
  1608. vm_page_more_fictitious();
  1609. goto RetrySourceFault;
  1610. case VM_FAULT_MEMORY_ERROR:
  1611. return(KERN_MEMORY_ERROR);
  1612. }
  1613. src_page = result_page;
  1614. assert((src_top_page == VM_PAGE_NULL) ==
  1615. (src_page->object == src_object));
  1616. assert ((prot & VM_PROT_READ) != VM_PROT_NONE);
  1617. vm_object_unlock(src_page->object);
  1618. }
  1619. RetryDestinationFault: ;
  1620. prot = VM_PROT_WRITE;
  1621. vm_object_lock(dst_object);
  1622. vm_object_paging_begin(dst_object);
  1623. switch (vm_fault_page(dst_object, dst_offset, VM_PROT_WRITE,
  1624. FALSE, FALSE /* interruptible */,
  1625. &prot, &result_page, &dst_top_page,
  1626. FALSE, (void (*)()) 0)) {
  1627. case VM_FAULT_SUCCESS:
  1628. break;
  1629. case VM_FAULT_RETRY:
  1630. goto RetryDestinationFault;
  1631. case VM_FAULT_INTERRUPTED:
  1632. if (src_page != VM_PAGE_NULL)
  1633. vm_fault_copy_cleanup(src_page,
  1634. src_top_page);
  1635. RETURN(MACH_SEND_INTERRUPTED);
  1636. case VM_FAULT_MEMORY_SHORTAGE:
  1637. VM_PAGE_WAIT((void (*)()) 0);
  1638. goto RetryDestinationFault;
  1639. case VM_FAULT_FICTITIOUS_SHORTAGE:
  1640. vm_page_more_fictitious();
  1641. goto RetryDestinationFault;
  1642. case VM_FAULT_MEMORY_ERROR:
  1643. if (src_page != VM_PAGE_NULL)
  1644. vm_fault_copy_cleanup(src_page,
  1645. src_top_page);
  1646. return(KERN_MEMORY_ERROR);
  1647. }
  1648. assert ((prot & VM_PROT_WRITE) != VM_PROT_NONE);
  1649. dst_page = result_page;
  1650. old_copy_object = dst_page->object->copy;
  1651. vm_object_unlock(dst_page->object);
  1652. if (!vm_map_verify(dst_map, dst_version)) {
  1653. BailOut: ;
  1654. if (src_page != VM_PAGE_NULL)
  1655. vm_fault_copy_cleanup(src_page, src_top_page);
  1656. vm_fault_copy_cleanup(dst_page, dst_top_page);
  1657. break;
  1658. }
  1659. vm_object_lock(dst_page->object);
  1660. if (dst_page->object->copy != old_copy_object) {
  1661. vm_object_unlock(dst_page->object);
  1662. vm_map_verify_done(dst_map, dst_version);
  1663. goto BailOut;
  1664. }
  1665. vm_object_unlock(dst_page->object);
  1666. /*
  1667. * Copy the page, and note that it is dirty
  1668. * immediately.
  1669. */
  1670. if (src_page == VM_PAGE_NULL)
  1671. vm_page_zero_fill(dst_page);
  1672. else
  1673. vm_page_copy(src_page, dst_page);
  1674. dst_page->dirty = TRUE;
  1675. /*
  1676. * Unlock everything, and return
  1677. */
  1678. vm_map_verify_done(dst_map, dst_version);
  1679. if (src_page != VM_PAGE_NULL)
  1680. vm_fault_copy_cleanup(src_page, src_top_page);
  1681. vm_fault_copy_cleanup(dst_page, dst_top_page);
  1682. amount_done += PAGE_SIZE;
  1683. src_offset += PAGE_SIZE;
  1684. dst_offset += PAGE_SIZE;
  1685. } while (amount_done != *src_size);
  1686. RETURN(KERN_SUCCESS);
  1687. #undef RETURN
  1688. /*NOTREACHED*/
  1689. }
  1690. #ifdef notdef
  1691. /*
  1692. * Routine: vm_fault_page_overwrite
  1693. *
  1694. * Description:
  1695. * A form of vm_fault_page that assumes that the
  1696. * resulting page will be overwritten in its entirety,
  1697. * making it unnecessary to obtain the correct *contents*
  1698. * of the page.
  1699. *
  1700. * Implementation:
  1701. * XXX Untested. Also unused. Eventually, this technology
  1702. * could be used in vm_fault_copy() to advantage.
  1703. */
  1704. vm_fault_return_t vm_fault_page_overwrite(
  1705. vm_object_t dst_object,
  1706. vm_offset_t dst_offset,
  1707. vm_page_t *result_page) /* OUT */
  1708. {
  1709. vm_page_t dst_page;
  1710. #define interruptible FALSE /* XXX */
  1711. while (TRUE) {
  1712. /*
  1713. * Look for a page at this offset
  1714. */
  1715. while ((dst_page = vm_page_lookup(dst_object, dst_offset))
  1716. == VM_PAGE_NULL) {
  1717. /*
  1718. * No page, no problem... just allocate one.
  1719. */
  1720. dst_page = vm_page_alloc(dst_object, dst_offset);
  1721. if (dst_page == VM_PAGE_NULL) {
  1722. vm_object_unlock(dst_object);
  1723. VM_PAGE_WAIT((void (*)()) 0);
  1724. vm_object_lock(dst_object);
  1725. continue;
  1726. }
  1727. /*
  1728. * Pretend that the memory manager
  1729. * write-protected the page.
  1730. *
  1731. * Note that we will be asking for write
  1732. * permission without asking for the data
  1733. * first.
  1734. */
  1735. dst_page->overwriting = TRUE;
  1736. dst_page->page_lock = VM_PROT_WRITE;
  1737. dst_page->absent = TRUE;
  1738. dst_object->absent_count++;
  1739. break;
  1740. /*
  1741. * When we bail out, we might have to throw
  1742. * away the page created here.
  1743. */
  1744. #define DISCARD_PAGE \
  1745. MACRO_BEGIN \
  1746. vm_object_lock(dst_object); \
  1747. dst_page = vm_page_lookup(dst_object, dst_offset); \
  1748. if ((dst_page != VM_PAGE_NULL) && dst_page->overwriting) \
  1749. VM_PAGE_FREE(dst_page); \
  1750. vm_object_unlock(dst_object); \
  1751. MACRO_END
  1752. }
  1753. /*
  1754. * If the page is write-protected...
  1755. */
  1756. if (dst_page->page_lock & VM_PROT_WRITE) {
  1757. /*
  1758. * ... and an unlock request hasn't been sent
  1759. */
  1760. if ( ! (dst_page->unlock_request & VM_PROT_WRITE)) {
  1761. vm_prot_t u;
  1762. kern_return_t rc;
  1763. /*
  1764. * ... then send one now.
  1765. */
  1766. if (!dst_object->pager_ready) {
  1767. vm_object_assert_wait(dst_object,
  1768. VM_OBJECT_EVENT_PAGER_READY,
  1769. interruptible);
  1770. vm_object_unlock(dst_object);
  1771. thread_block((void (*)()) 0);
  1772. if (current_thread()->wait_result !=
  1773. THREAD_AWAKENED) {
  1774. DISCARD_PAGE;
  1775. return(VM_FAULT_INTERRUPTED);
  1776. }
  1777. continue;
  1778. }
  1779. u = dst_page->unlock_request |= VM_PROT_WRITE;
  1780. vm_object_unlock(dst_object);
  1781. if ((rc = memory_object_data_unlock(
  1782. dst_object->pager,
  1783. dst_object->pager_request,
  1784. dst_offset + dst_object->paging_offset,
  1785. PAGE_SIZE,
  1786. u)) != KERN_SUCCESS) {
  1787. printf("vm_object_overwrite: memory_object_data_unlock failed\n");
  1788. DISCARD_PAGE;
  1789. return((rc == MACH_SEND_INTERRUPTED) ?
  1790. VM_FAULT_INTERRUPTED :
  1791. VM_FAULT_MEMORY_ERROR);
  1792. }
  1793. vm_object_lock(dst_object);
  1794. continue;
  1795. }
  1796. /* ... fall through to wait below */
  1797. } else {
  1798. /*
  1799. * If the page isn't being used for other
  1800. * purposes, then we're done.
  1801. */
  1802. if ( ! (dst_page->busy || dst_page->absent || dst_page->error) )
  1803. break;
  1804. }
  1805. PAGE_ASSERT_WAIT(dst_page, interruptible);
  1806. vm_object_unlock(dst_object);
  1807. thread_block((void (*)()) 0);
  1808. if (current_thread()->wait_result != THREAD_AWAKENED) {
  1809. DISCARD_PAGE;
  1810. return(VM_FAULT_INTERRUPTED);
  1811. }
  1812. }
  1813. *result_page = dst_page;
  1814. return(VM_FAULT_SUCCESS);
  1815. #undef interruptible
  1816. #undef DISCARD_PAGE
  1817. }
  1818. #endif /* notdef */