1ce4a8bcbSPeter Wemm.\" 2ce4a8bcbSPeter Wemm.\" Copyright (c) 2008 Peter Wemm 3ce4a8bcbSPeter Wemm.\" All rights reserved. 4ce4a8bcbSPeter Wemm.\" 5ce4a8bcbSPeter Wemm.\" Redistribution and use in source and binary forms, with or without 6ce4a8bcbSPeter Wemm.\" modification, are permitted provided that the following conditions 7ce4a8bcbSPeter Wemm.\" are met: 8ce4a8bcbSPeter Wemm.\" 1. Redistributions of source code must retain the above copyright 9ce4a8bcbSPeter Wemm.\" notice, this list of conditions and the following disclaimer. 10ce4a8bcbSPeter Wemm.\" 2. Redistributions in binary form must reproduce the above copyright 11ce4a8bcbSPeter Wemm.\" notice, this list of conditions and the following disclaimer in the 12ce4a8bcbSPeter Wemm.\" documentation and/or other materials provided with the distribution. 13ce4a8bcbSPeter Wemm.\" 14ce4a8bcbSPeter Wemm.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15ce4a8bcbSPeter Wemm.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16ce4a8bcbSPeter Wemm.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17ce4a8bcbSPeter Wemm.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18ce4a8bcbSPeter Wemm.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19ce4a8bcbSPeter Wemm.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20ce4a8bcbSPeter Wemm.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21ce4a8bcbSPeter Wemm.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22ce4a8bcbSPeter Wemm.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23ce4a8bcbSPeter Wemm.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24ce4a8bcbSPeter Wemm.\" SUCH DAMAGE. 25ce4a8bcbSPeter Wemm.\" 26bc89b58dSGordon Bergling.Dd May 10, 2020 27ce4a8bcbSPeter Wemm.Dt KINFO_GETVMMAP 3 28aa12cea2SUlrich Spörlein.Os 29ce4a8bcbSPeter Wemm.Sh NAME 30ce4a8bcbSPeter Wemm.Nm kinfo_getvmmap 31ce4a8bcbSPeter Wemm.Nd function for getting per-process memory map information 32ce4a8bcbSPeter Wemm.Sh LIBRARY 33ce4a8bcbSPeter Wemm.Lb libutil 34ce4a8bcbSPeter Wemm.Sh SYNOPSIS 35ce4a8bcbSPeter Wemm.In sys/types.h 36965cd3b0SJohn Baldwin.In sys/user.h 37ce4a8bcbSPeter Wemm.In libutil.h 38ce4a8bcbSPeter Wemm.Ft struct kinfo_vmentry * 3963d9261aSRobert Watson.Fn kinfo_getvmmap "pid_t pid" "int *cntp" 40ce4a8bcbSPeter Wemm.Sh DESCRIPTION 4163d9261aSRobert WatsonThis function is used for obtaining virtual memory mapping information 42ce4a8bcbSPeter Wemmof a particular process. 43ce4a8bcbSPeter Wemm.Pp 44ce4a8bcbSPeter WemmThe 45ce4a8bcbSPeter Wemm.Ar pid 46ce4a8bcbSPeter Wemmfield contains the process identifier. 47799162a6SJoel DahlThis should be the a process that you have privilege to access. 48ce4a8bcbSPeter WemmThe 49ce4a8bcbSPeter Wemm.Ar cntp 50ce4a8bcbSPeter Wemmfield is allows the caller to know how many records are returned. 51ce4a8bcbSPeter Wemm.Pp 52ce4a8bcbSPeter WemmThis function is a wrapper around 53ce4a8bcbSPeter Wemm.Xr sysctl 3 54ce4a8bcbSPeter Wemmwith the 55ce4a8bcbSPeter Wemm.Dv KERN_PROC_VMMAP 56ce4a8bcbSPeter Wemmmib. 57ce4a8bcbSPeter WemmWhile the kernel returns a packed structure, this function expands the 58ce4a8bcbSPeter Wemmdata into a fixed record format. 59ce4a8bcbSPeter Wemm.Sh RETURN VALUES 606a3401c5SJohn BaldwinOn success the 61ce4a8bcbSPeter Wemm.Fn kinfo_getvmmap 62ce4a8bcbSPeter Wemmfunction returns a pointer to an array of 63ce4a8bcbSPeter Wemm.Vt struct kinfo_vmentry 647b593c5dSJohn Baldwinstructures as defined by 657b593c5dSJohn Baldwin.In sys/user.h . 66ce4a8bcbSPeter WemmThe array was obtained by an internal call to 67ce4a8bcbSPeter Wemm.Xr malloc 3 68ce4a8bcbSPeter Wemmand must be freed by the caller with a call to 69ce4a8bcbSPeter Wemm.Xr free 3 . 706a3401c5SJohn BaldwinOn failure the 716a3401c5SJohn Baldwin.Fn kinfo_getvmmap 726a3401c5SJohn Baldwinfunction returns 736a3401c5SJohn Baldwin.Dv NULL . 74ce4a8bcbSPeter Wemm.Sh SEE ALSO 75ce4a8bcbSPeter Wemm.Xr free 3 , 76ce4a8bcbSPeter Wemm.Xr kinfo_getfile 3 , 77ce4a8bcbSPeter Wemm.Xr malloc 3 78bc89b58dSGordon Bergling.Sh HISTORY 79bc89b58dSGordon BerglingThe 80bc89b58dSGordon Bergling.Fn kinfo_getvmmap 81bc89b58dSGordon Berglingfunction first appeared in 82bc89b58dSGordon Bergling.Fx 7.0 . 83*816ca3d1SGordon Bergling.Sh CAVEATS 84*816ca3d1SGordon Bergling.Fn kinfo_getvmmap 85*816ca3d1SGordon Berglingcalls can cause significant CPU consumption because calculating the residency 86*816ca3d1SGordon Berglingcounts requires iterating over all memory pages of the process. 87*816ca3d1SGordon BerglingSetting the sysctl variable 88*816ca3d1SGordon Bergling.Va kern.proc_vmmap_skip_resident_count 89*816ca3d1SGordon Berglingto 1 prevents this calculation. 90