Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
.\"	$NetBSD: uvm_map.9,v 1.12 2020/08/27 14:14:00 fcambus Exp $
.\"
.\" Copyright (c) 1998 Matthew R. Green
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd May 20, 2017
.Dt UVM_MAP 9
.Os
.Sh NAME
.Nm uvm_map
.Nd
virtual address space management interface
.Sh SYNOPSIS
.In sys/param.h
.In uvm/uvm.h
.Ft int
.Fn uvm_map "struct vm_map *map" "vaddr_t *startp" "vsize_t size" \
"struct uvm_object *uobj" "voff_t uoffset" "vsize_t align" "uvm_flag_t flags"
.Ft void
.Fn uvm_unmap "struct vm_map *map" "vaddr_t start" "vaddr_t end"
.Ft int
.Fn uvm_map_pageable "struct vm_map *map" "vaddr_t start" "vaddr_t end" \
"bool new_pageable" "int lockflags"
.Ft bool
.Fn uvm_map_checkprot "struct vm_map *map" "vaddr_t start" "vaddr_t end" \
"vm_prot_t protection"
.Ft int
.Fn uvm_map_protect "struct vm_map *map" "vaddr_t start" "vaddr_t end" \
"vm_prot_t new_prot" "bool set_max"
.Ft int
.Fn uvm_map_protect_user "struct lwp *l" "vaddr_t start" "vaddr_t end" \
"vm_prot_t new_prot"
.Ft int
.Fn uvm_deallocate "struct vm_map *map" "vaddr_t start" "vsize_t size"
.Ft struct vmspace *
.Fn uvmspace_alloc "vaddr_t min" "vaddr_t max"
.Ft void
.Fn uvmspace_exec "struct lwp *l" "vaddr_t start" "vaddr_t end"
.Ft struct vmspace *
.Fn uvmspace_fork "struct vmspace *vm"
.Ft void
.Fn uvmspace_free "struct vmspace *vm"
.Ft void
.Fn uvmspace_share "struct proc *p1" "struct proc *p2"
.\" .Ft void
.\" .Fn uvmspace_unshare "struct lwp *l"
.Ft vaddr_t
.Fn uvm_uarea_alloc "void"
.Ft void
.Fn uvm_uarea_free "vaddr_t uaddr"
.Ft vaddr_t
.Fn uvm_uarea_system_alloc "void"
.Ft void
.Fn uvm_uarea_system_free "vaddr_t uaddr"
.Sh DESCRIPTION
The UVM facility for virtual address space management.
.Sh FUNCTIONS
.Fn uvm_map
establishes a valid mapping in map
.Fa map ,
which must be unlocked.
The new mapping has size
.Fa size ,
which must be a multiple of
.Dv PAGE_SIZE .
.Pp
The
.Fa uobj
and
.Fa uoffset
arguments can have four meanings:
.Bl -bullet -offset abcd -compact
.It
When
.Fa uobj
is
.Dv NULL
and
.Fa uoffset
is
.Dv UVM_UNKNOWN_OFFSET ,
.Fn uvm_map
does not use the machine-dependent
.Dv PMAP_PREFER
function.
.It
When
.Fa uobj
is
.Dv NULL
and
.Fa uoffset
is any other value, it is used as the hint to
.Dv PMAP_PREFER .
.It
When
.Fa uobj
is not
.Dv NULL
and
.Fa uoffset
is
.Dv UVM_UNKNOWN_OFFSET ,
.Fn uvm_map
finds the offset based upon the virtual address, passed as
.Fa startp .
.It
When
.Fa uobj
is not
.Dv NULL
and
.Fa uoffset
is any other value, then a regular mapping is performed at this offset.
The start address of the map will be returned in
.Fa startp .
.El
If
.Fa uobj
is supplied, then
.Fn uvm_map
.Em consumes
the caller's reference to
.Fa uobj
on success;
.Fn uvm_unmap
will release it when removing this mapping.
On failure,
.Fn uvm_map
leaves the reference count of
.Fa uobj
unmodified.
.Pp
.Fa align
specifies alignment of mapping unless
.Dv UVM_FLAG_FIXED
is specified in
.Fa flags .
.Fa align
must be a power of 2.
.Pp
.Fa flags
passed to
.Fn uvm_map
are typically created using the
.Fn UVM_MAPFLAG "vm_prot_t prot" "vm_prot_t maxprot" "vm_inherit_t inh" \
"int advice" "int flags"
macro, which uses the following values.
.Pp
The values that
.Fa prot
and
.Fa maxprot
can take are:
.Bl -tag -offset abcd -compact -width UVM_ADV_SEQUENTIAL
.It UVM_PROT_NONE
No protection bits.
.It UVM_PROT_R
Read.
.It UVM_PROT_W
Write.
.It UVM_PROT_X
Exec.
.It UVM_PROT_MASK
Mask to extraction the protection bits.
.El
Additionally, the following constants for ORed values are available:
.Dv UVM_PROT_RW ,
.Dv UVM_PROT_RX ,
.Dv UVM_PROT_WX
and
.Dv UVM_PROT_RWX .
.Pp
The values that
.Fa inh
can take are:
.Bl -tag -offset abcd -compact -width UVM_ADV_SEQUENTIAL
.It UVM_INH_SHARE
Share the map.
.It UVM_INH_COPY
Copy the map.
.It UVM_INH_NONE
No inheritance.
.It UVM_INH_MASK
Mask to extract inherit flags.
.El
.Pp
The values that
.Fa advice
can take are:
.Bl -tag -offset abcd -compact -width UVM_ADV_SEQUENTIAL
.It UVM_ADV_NORMAL
"Normal" use.
.It UVM_ADV_RANDOM
"Random" access likelihood.
.It UVM_ADV_SEQUENTIAL
"Sequential" access likelihood.
.It UVM_ADV_MASK
Mask to extract the advice flags.
.El
.Pp
The values that
.Fa flags
can take are:
.Bl -tag -offset abcd -compact -width UVM_ADV_SEQUENTIAL
.It UVM_FLAG_FIXED
Attempt to map on the address specified by
.Fa startp .
Otherwise, it is used just as a hint.
.It UVM_FLAG_OVERLAY
Establish overlay.
.It UVM_FLAG_NOMERGE
Do not merge map entries, if such merge is possible.
.It UVM_FLAG_COPYONW
Use copy-on-write i.e. do not fault in the pages immediately.
.It UVM_FLAG_AMAPPAD
Used for BSS: allocate larger amap, if extending is likely.
.It UVM_FLAG_TRYLOCK
Fail if cannot acquire the lock immediately.
.It UVM_FLAG_NOWAIT
Not allowed to sleep.
Fail, in such case.
.It UVM_FLAG_QUANTUM
Indicates that map entry cannot be split once mapped.
.It UVM_FLAG_WAITVA
Sleep until VA space is available, if it is not.
.It UVM_FLAG_VAONLY
Unmap only VA space.
Used by
.Fn uvm_unmap .
.It UVM_FLAG_UNMAP
Any existing entries in the range for this mapping should be
unmapped as part of creating the new mapping.
Use of this flag without also specifying
.Dv UVM_FLAG_FIXED
is a bug.
.El
.Pp
The
.Dv UVM_MAPFLAG
macro arguments can be combined with an or operator.
There are several special purpose macros for checking protection
combinations, e.g., the
.Dv UVM_PROT_WX .
There are also some additional macros to extract bits from the flags.
The
.Dv UVM_PROTECTION ,
.Dv UVM_INHERIT ,
.Dv UVM_MAXPROTECTION
and
.Dv UVM_ADVICE
macros return the protection, inheritance, maximum protection, and
advice, respectively.
.Fn uvm_map
returns zero on success or error number otherwise.
.Pp
.Fn uvm_unmap
removes a valid mapping,
from
.Fa start
to
.Fa end ,
in map
.Fa map ,
which must be unlocked.
.Pp
.Fn uvm_map_pageable
changes the pageability of the pages in the range from
.Fa start
to
.Fa end
in map
.Fa map
to
.Fa new_pageable .
.Fn uvm_map_pageable
returns zero on success or error number otherwise.
.Pp
.Fn uvm_map_checkprot
checks the protection of the range from
.Fa start
to
.Fa end
in map
.Fa map
against
.Fa protection .
This returns either
.Dv true
or
.Dv false .
.Pp
.Fn uvm_map_protect
changes the protection
.Fa start
to
.Fa end
in map
.Fa map
to
.Fa new_prot ,
also setting the maximum protection to the region to
.Fa new_prot
if
.Fa set_max
is true.
This function returns a standard UVM return value.
.Pp
.Fn uvm_map_protect_user
verifies that the new permissions honor PAX restrictions if applicable
and forwards to
.Fn uvm_map_protect
on passing.
.Pp
.Fn uvm_deallocate
deallocates kernel memory in map
.Fa map
from address
.Fa start
to
.Fa start + size .
.Pp
.Fn uvmspace_alloc
allocates and returns a new address space, with ranges from
.Fa min
to
.Fa max .
.Pp
.Fn uvmspace_exec
either reuses the address space of thread
.Fa l
(its process) if there are no other references to it, or creates
a new one with
.Fn uvmspace_alloc .
The range of valid addresses in the address space is reset to
.Fa start
through
.Fa end .
.Pp
.Fn uvmspace_fork
creates and returns a new address space based upon the
.Fa vm
address space, typically used when allocating an address space for a
child process.
.Pp
.Fn uvmspace_free
lowers the reference count on the address space
.Fa vm ,
freeing the data structures if there are no other references.
.Pp
.Fn uvmspace_share
causes process
.Pa p2
to share the address space of
.Fa p1 .
.\" .Pp
.\" .Fn uvmspace_unshare
.\" ensures that thread
.\" .Fa l
.\" has its own, unshared address space, by creating a new one if
.\" necessary by calling
.\" .Fn uvmspace_fork .
.Pp
.Fn uvm_uarea_alloc
allocates memory for a u-area (i.e. kernel stack, PCB, etc) and returns
the address.
.Pp
.Fn uvm_uarea_free
frees a u-area allocated with
.Fn uvm_uarea_alloc .
.Pp
.Fn uvm_uarea_system_alloc
and
.Fn uvm_uarea_system_free
are optimized routines, which are used for kernel threads.
.Sh SEE ALSO
.Xr pmap 9 ,
.Xr uvm 9 ,
.Xr uvm_km 9 ,
.Xr vmem 9
.Sh HISTORY
UVM and
.Nm
first appeared in
.Nx 1.4 .