1 /* $NetBSD: uvm_fault_i.h,v 1.28 2012/02/19 00:05:56 rmind Exp $ */
4 * Copyright (c) 1997 Charles D. Cranor and Washington University.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * from: Id: uvm_fault_i.h,v 1.1.6.1 1997/12/08 16:07:12 chuck Exp
30 #ifndef _UVM_UVM_FAULT_I_H_
31 #define _UVM_UVM_FAULT_I_H_
34 * uvm_fault_i.h: fault inline functions
38 * uvmfault_unlockmaps: unlock the maps
42 uvmfault_unlockmaps(struct uvm_faultinfo
*ufi
, bool write_locked
)
45 * ufi can be NULL when this isn't really a fault,
46 * but merely paging in anon data.
54 vm_map_unlock(ufi
->map
);
56 vm_map_unlock_read(ufi
->map
);
61 * uvmfault_unlockall: unlock everything passed in.
63 * => maps must be read-locked (not write-locked).
67 uvmfault_unlockall(struct uvm_faultinfo
*ufi
, struct vm_amap
*amap
,
68 struct uvm_object
*uobj
)
72 mutex_exit(uobj
->vmobjlock
);
75 uvmfault_unlockmaps(ufi
, false);
79 * uvmfault_lookup: lookup a virtual address in a map
81 * => caller must provide a uvm_faultinfo structure with the IN
82 * params properly filled in
83 * => we will lookup the map entry (handling submaps) as we go
84 * => if the lookup is a success we will return with the maps locked
85 * => if "write_lock" is true, we write_lock the map, otherwise we only
87 * => note that submaps can only appear in the kernel and they are
88 * required to use the same virtual addresses as the map they
89 * are referenced by (thus address translation between the main
90 * map and the submap is unnecessary).
94 uvmfault_lookup(struct uvm_faultinfo
*ufi
, bool write_lock
)
96 struct vm_map
*tmpmap
;
99 * init ufi values for lookup.
102 ufi
->map
= ufi
->orig_map
;
103 ufi
->size
= ufi
->orig_size
;
106 * keep going down levels until we are done. note that there can
107 * only be two levels so we won't loop very long.
115 vm_map_lock(ufi
->map
);
117 vm_map_lock_read(ufi
->map
);
123 if (!uvm_map_lookup_entry(ufi
->map
, ufi
->orig_rvaddr
,
125 uvmfault_unlockmaps(ufi
, write_lock
);
130 * reduce size if necessary
132 if (ufi
->entry
->end
- ufi
->orig_rvaddr
< ufi
->size
)
133 ufi
->size
= ufi
->entry
->end
- ufi
->orig_rvaddr
;
136 * submap? replace map with the submap and lookup again.
137 * note: VAs in submaps must match VAs in main map.
139 if (UVM_ET_ISSUBMAP(ufi
->entry
)) {
140 tmpmap
= ufi
->entry
->object
.sub_map
;
142 vm_map_unlock(ufi
->map
);
144 vm_map_unlock_read(ufi
->map
);
154 ufi
->mapv
= ufi
->map
->timestamp
;
163 * uvmfault_relock: attempt to relock the same version of the map
165 * => fault data structures should be unlocked before calling.
166 * => if a success (true) maps will be locked after call.
170 uvmfault_relock(struct uvm_faultinfo
*ufi
)
173 * ufi can be NULL when this isn't really a fault,
174 * but merely paging in anon data.
184 * relock map. fail if version mismatch (in which case nothing
188 vm_map_lock_read(ufi
->map
);
189 if (ufi
->mapv
!= ufi
->map
->timestamp
) {
190 vm_map_unlock_read(ufi
->map
);
198 #endif /* _UVM_UVM_FAULT_I_H_ */