17d216f0fSBruce M Simpson.\" 27d216f0fSBruce M Simpson.\" Copyright (c) 2003 Bruce M Simpson <bms@spc.org> 37d216f0fSBruce M Simpson.\" All rights reserved. 47d216f0fSBruce M Simpson.\" 57d216f0fSBruce M Simpson.\" Redistribution and use in source and binary forms, with or without 67d216f0fSBruce M Simpson.\" modification, are permitted provided that the following conditions 77d216f0fSBruce M Simpson.\" are met: 87d216f0fSBruce M Simpson.\" 1. Redistributions of source code must retain the above copyright 97d216f0fSBruce M Simpson.\" notice, this list of conditions and the following disclaimer. 107d216f0fSBruce M Simpson.\" 2. Redistributions in binary form must reproduce the above copyright 117d216f0fSBruce M Simpson.\" notice, this list of conditions and the following disclaimer in the 127d216f0fSBruce M Simpson.\" documentation and/or other materials provided with the distribution. 137d216f0fSBruce M Simpson.\" 147d216f0fSBruce M Simpson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 157d216f0fSBruce M Simpson.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 167d216f0fSBruce M Simpson.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 177d216f0fSBruce M Simpson.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 187d216f0fSBruce M Simpson.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 197d216f0fSBruce M Simpson.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 207d216f0fSBruce M Simpson.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 217d216f0fSBruce M Simpson.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 227d216f0fSBruce M Simpson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 237d216f0fSBruce M Simpson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 247d216f0fSBruce M Simpson.\" SUCH DAMAGE. 257d216f0fSBruce M Simpson.\" 2683506d1aSJohn Baldwin.Dd September 12, 2013 27a970c85cSRuslan Ermilov.Dt VM_MAP_FIND 9 28b4ca3754SRuslan Ermilov.Os 297d216f0fSBruce M Simpson.Sh NAME 307d216f0fSBruce M Simpson.Nm vm_map_find 317d216f0fSBruce M Simpson.Nd find a free region within a map, and optionally map a vm_object 327d216f0fSBruce M Simpson.Sh SYNOPSIS 337d216f0fSBruce M Simpson.In sys/param.h 347d216f0fSBruce M Simpson.In vm/vm.h 357d216f0fSBruce M Simpson.In vm/vm_map.h 367d216f0fSBruce M Simpson.Ft int 37a970c85cSRuslan Ermilov.Fo vm_map_find 38a970c85cSRuslan Ermilov.Fa "vm_map_t map" "vm_object_t object" "vm_ooffset_t offset" 3983506d1aSJohn Baldwin.Fa "vm_offset_t *addr" "vm_size_t length" "vm_offset_t max_addr" 4083506d1aSJohn Baldwin.Fa "int find_space" "vm_prot_t prot" "vm_prot_t max" "int cow" 41a970c85cSRuslan Ermilov.Fc 427d216f0fSBruce M Simpson.Sh DESCRIPTION 437d216f0fSBruce M SimpsonThe 447d216f0fSBruce M Simpson.Fn vm_map_find 457d216f0fSBruce M Simpsonfunction attempts to find a free region in the target 467d216f0fSBruce M Simpson.Fa map , 477d216f0fSBruce M Simpsonwith the given 4883506d1aSJohn Baldwin.Fa length. 4983506d1aSJohn BaldwinIf a free region is found, 5083506d1aSJohn Baldwin.Fn vm_map_find 5183506d1aSJohn Baldwincreates a mapping of 5283506d1aSJohn Baldwin.Fa object 5383506d1aSJohn Baldwinvia a call to 5483506d1aSJohn Baldwin.Xr vm_map_insert 9 . 557d216f0fSBruce M Simpson.Pp 567d216f0fSBruce M SimpsonThe arguments 577d216f0fSBruce M Simpson.Fa offset , 587d216f0fSBruce M Simpson.Fa prot , 597d216f0fSBruce M Simpson.Fa max , 607d216f0fSBruce M Simpsonand 617d216f0fSBruce M Simpson.Fa cow 627d216f0fSBruce M Simpsonare passed unchanged to 637d216f0fSBruce M Simpson.Xr vm_map_insert 9 647d216f0fSBruce M Simpsonwhen creating the mapping, if and only if a free region is found. 657d216f0fSBruce M Simpson.Pp 667d216f0fSBruce M SimpsonIf 677d216f0fSBruce M Simpson.Fa object 68a970c85cSRuslan Ermilovis 69a970c85cSRuslan Ermilov.Pf non- Dv NULL , 70a970c85cSRuslan Ermilovthe reference count on the object must be incremented 717d216f0fSBruce M Simpsonby the caller before calling this function to account for the new entry. 727d216f0fSBruce M Simpson.Pp 737d216f0fSBruce M SimpsonIf 7483506d1aSJohn Baldwin.Fa max_addr 7583506d1aSJohn Baldwinis non-zero, 7683506d1aSJohn Baldwinit specifies an upper bound on the mapping. 7783506d1aSJohn BaldwinThe mapping will only succeed if a free region can be found that resides 7883506d1aSJohn Baldwinentirely below 7983506d1aSJohn Baldwin.Fa max_addr . 8083506d1aSJohn Baldwin.Pp 8183506d1aSJohn BaldwinThe 827d216f0fSBruce M Simpson.Fa find_space 8383506d1aSJohn Baldwinargument specifies the strategy to use when searching for a free region of 8483506d1aSJohn Baldwinthe requested length. 8583506d1aSJohn BaldwinFor all values other than 8626c538ffSAlan Cox.Dv VMFS_NO_SPACE , 8783506d1aSJohn Baldwin.Xr vm_map_findspace 9 8883506d1aSJohn Baldwinis called to locate a free region of the requested length with a starting 8983506d1aSJohn Baldwinaddress at or above 9083506d1aSJohn Baldwin.Fa *addr . 9183506d1aSJohn BaldwinThe following strategies are supported: 920e75d62eSJoel Dahl.Bl -tag -width "Dv VMFS_ALIGNED_SPACE Ns" 9383506d1aSJohn Baldwin.It Dv VMFS_NO_SPACE 9483506d1aSJohn BaldwinThe mapping will only succeed if there is a free region of the requested 9583506d1aSJohn Baldwinlength at the given address 9683506d1aSJohn Baldwin.Fa *addr . 9783506d1aSJohn Baldwin.It Dv VMFS_ANY_SPACE 9883506d1aSJohn BaldwinThe mapping will succeed as long as there is a free region. 9983506d1aSJohn Baldwin.It Dv VMFS_SUPER_SPACE 10083506d1aSJohn BaldwinThe mapping will succeed as long as there is a free region that begins on 10183506d1aSJohn Baldwina superpage boundary. 10283506d1aSJohn BaldwinIf 10383506d1aSJohn Baldwin.Fa object 10483506d1aSJohn Baldwinis 10583506d1aSJohn Baldwin.Pf non- Dv NULL 10683506d1aSJohn Baldwinand is already backed by superpages, 10783506d1aSJohn Baldwinthen the mapping will require a free region that aligns relative to the 10883506d1aSJohn Baldwinexisting superpages rather than one beginning on a superpage boundary. 10983506d1aSJohn Baldwin.It Dv VMFS_OPTIMAL_SPACE 11083506d1aSJohn BaldwinThe mapping will succeed as long as there is a free region. 11183506d1aSJohn BaldwinHowever, if 11283506d1aSJohn Baldwin.Fa object 11383506d1aSJohn Baldwinis 11483506d1aSJohn Baldwin.Pf non- Dv NULL 11583506d1aSJohn Baldwinand is already backed by superpages, 11683506d1aSJohn Baldwinthis strategy will attempt to find a free region aligned relative to 11783506d1aSJohn Baldwinthe existing superpages. 11883506d1aSJohn Baldwin.It Dv VMFS_ALIGNED_SPACE Ns Pq Fa n 11983506d1aSJohn BaldwinThe mapping will succeed as long as there is a free region that aligns on 12083506d1aSJohn Baldwina 12183506d1aSJohn Baldwin.Pf 2^ Fa n 12283506d1aSJohn Baldwinboundary. 12383506d1aSJohn Baldwin.El 1247d216f0fSBruce M Simpson.Sh IMPLEMENTATION NOTES 1257d216f0fSBruce M SimpsonThis function acquires a lock on 1267d216f0fSBruce M Simpson.Fa map 1277d216f0fSBruce M Simpsonby calling 1287d216f0fSBruce M Simpson.Xr vm_map_lock 9 , 1297d216f0fSBruce M Simpsonand holds it until the function returns. 1307d216f0fSBruce M Simpson.Pp 1317d216f0fSBruce M SimpsonThe search for a free region is defined to be first-fit, from the address 1327d216f0fSBruce M Simpson.Fa addr 1337d216f0fSBruce M Simpsononwards. 1347d216f0fSBruce M Simpson.Sh RETURN VALUES 1357d216f0fSBruce M SimpsonThe 136a970c85cSRuslan Ermilov.Fn vm_map_find 1377d216f0fSBruce M Simpsonfunction returns 1387d216f0fSBruce M Simpson.Dv KERN_SUCCESS 13926c538ffSAlan Coxif the mapping was successfully created. 14026c538ffSAlan CoxIf space could not be found or 14126c538ffSAlan Cox.Fa find_space 14226c538ffSAlan Coxwas 14326c538ffSAlan Cox.Dv VMFS_NO_SPACE 14426c538ffSAlan Coxand the given address, 14526c538ffSAlan Cox.Fa addr , 14626c538ffSAlan Coxwas already mapped, 1477d216f0fSBruce M Simpson.Dv KERN_NO_SPACE 1487d216f0fSBruce M Simpsonwill be returned. 1497d216f0fSBruce M SimpsonIf the discovered range turned out to be bogus, 1507d216f0fSBruce M Simpson.Dv KERN_INVALID_ADDRESS 1517d216f0fSBruce M Simpsonwill be returned. 1527d216f0fSBruce M Simpson.Sh SEE ALSO 1537d216f0fSBruce M Simpson.Xr vm_map 9 , 1547d216f0fSBruce M Simpson.Xr vm_map_findspace 9 , 1557d216f0fSBruce M Simpson.Xr vm_map_insert 9 , 1567d216f0fSBruce M Simpson.Xr vm_map_lock 9 1577d216f0fSBruce M Simpson.Sh AUTHORS 158571dba6eSHiten PandyaThis manual page was written by 159*8a7314fcSBaptiste Daroussin.An Bruce M Simpson Aq Mt bms@spc.org . 160