Module Name: src
Committed By: christos
Date: Thu Sep 24 14:39:20 UTC 2015
Modified Files:
src/lib/libutil: Makefile shlib_version
Added Files:
src/lib/libutil: kinfo_getvmmap.3 kinfo_getvmmap.c
Log Message:
Add kinfo_getvmmap from FreeBSD
To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/lib/libutil/Makefile
cvs rdiff -u -r0 -r1.1 src/lib/libutil/kinfo_getvmmap.3 \
src/lib/libutil/kinfo_getvmmap.c
cvs rdiff -u -r1.52 -r1.53 src/lib/libutil/shlib_version
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libutil/Makefile
diff -u src/lib/libutil/Makefile:1.77 src/lib/libutil/Makefile:1.78
--- src/lib/libutil/Makefile:1.77 Sat Jul 25 22:20:30 2015
+++ src/lib/libutil/Makefile Thu Sep 24 10:39:20 2015
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.77 2015/07/26 02:20:30 kamil Exp $
+# $NetBSD: Makefile,v 1.78 2015/09/24 14:39:20 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
@@ -15,7 +15,7 @@ SRCS+= efun.c \
getbootfile.c getbyteorder.c getlabelsector.c getmaxpartitions.c \
getfsspecname.c getmntopts.c getrawpartition.c getdiskrawname.c \
disklabel_dkcksum.c disklabel_scan.c \
- if_media.c \
+ if_media.c kinfo_getvmmap.c \
login.c loginx.c login_cap.c login_tty.c logout.c logoutx.c \
logwtmp.c logwtmpx.c opendisk.c parsedate.y \
passwd.c pw_scan.c pidfile.c pidlock.c pty.c \
@@ -27,7 +27,7 @@ MAN= efun.3 \
getbootfile.3 getbyteorder.3 getfstypename.3 getlabelsector.3 \
getmaxpartitions.3 getmntopts.3 getrawpartition.3 \
getdiskrawname.3 getfsspecname.3 \
- login.3 login_cap.3 loginx.3 \
+ login.3 login_cap.3 loginx.3 kinfo_getvmmap.3 \
disklabel_dkcksum.3 disklabel_scan.3 \
opendisk.3 openpty.3 parsedate.3 pidfile.3 pidlock.3 \
proc_compare.3 pw_getconf.3 pw_init.3 pw_lock.3 secure_path.3 \
Index: src/lib/libutil/shlib_version
diff -u src/lib/libutil/shlib_version:1.52 src/lib/libutil/shlib_version:1.53
--- src/lib/libutil/shlib_version:1.52 Sun Jul 26 11:15:31 2015
+++ src/lib/libutil/shlib_version Thu Sep 24 10:39:20 2015
@@ -1,5 +1,5 @@
-# $NetBSD: shlib_version,v 1.52 2015/07/26 15:15:31 kamil Exp $
+# $NetBSD: shlib_version,v 1.53 2015/09/24 14:39:20 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=7
-minor=22
+minor=23
Added files:
Index: src/lib/libutil/kinfo_getvmmap.3
diff -u /dev/null src/lib/libutil/kinfo_getvmmap.3:1.1
--- /dev/null Thu Sep 24 10:39:20 2015
+++ src/lib/libutil/kinfo_getvmmap.3 Thu Sep 24 10:39:20 2015
@@ -0,0 +1,80 @@
+.\" $NetBSD: kinfo_getvmmap.3,v 1.1 2015/09/24 14:39:20 christos Exp $
+.\"
+.\" Copyright (c) 2008 Peter Wemm
+.\" 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+.\"
+.\" $FreeBSD: head/lib/libutil/kinfo_getvmmap.3 283622 2015-05-27 17:51:06Z jhb $
+.\"
+.Dd September 16, 2015
+.Dt KINFO_GETVMMAP 3
+.Os
+.Sh NAME
+.Nm kinfo_getvmmap
+.Nd function for getting per-process memory map information
+.Sh LIBRARY
+.Lb libutil
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/sysctl.h
+.In util.h
+.Ft struct kinfo_vmentry *
+.Fn kinfo_getvmmap "pid_t pid" "size_t *cntp"
+.Sh DESCRIPTION
+This function is used for obtaining virtual memory mapping information
+of a particular process.
+.Pp
+The
+.Ar pid
+field contains the process identifier.
+This should be the a process that you have privilege to access.
+The
+.Ar cntp
+field is allows the caller to know how many records are returned.
+.Pp
+This function is a wrapper around
+.Xr sysctl 3
+with the
+.Dv KERN_PROC_VMMAP
+mib.
+While the kernel returns a packed structure, this function expands the
+data into a fixed record format.
+.Sh RETURN VALUES
+On success the
+.Fn kinfo_getvmmap
+function returns a pointer to an array of
+.Vt struct kinfo_vmentry
+structures as defined by
+.In sys/sysctl.h .
+The array was obtained by an internal call to
+.Xr malloc 3
+and must be freed by the caller with a call to
+.Xr free 3 .
+On failure the
+.Fn kinfo_getvmmap
+function returns
+.Dv NULL .
+.Sh SEE ALSO
+.Xr free 3 ,
+.\" .Xr kinfo_getfile 3 ,
+.Xr malloc 3
Index: src/lib/libutil/kinfo_getvmmap.c
diff -u /dev/null src/lib/libutil/kinfo_getvmmap.c:1.1
--- /dev/null Thu Sep 24 10:39:20 2015
+++ src/lib/libutil/kinfo_getvmmap.c Thu Sep 24 10:39:20 2015
@@ -0,0 +1,48 @@
+#include <sys/cdefs.h>
+#ifdef __FBSDID
+__FBSDID("$FreeBSD: head/lib/libutil/kinfo_getvmmap.c 186512 2008-12-27 11:12:23Z rwatson $");
+#endif
+__RCSID("$NetBSD: kinfo_getvmmap.c,v 1.1 2015/09/24 14:39:20 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/user.h>
+#include <sys/sysctl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <util.h>
+
+struct kinfo_vmentry *
+kinfo_getvmmap(pid_t pid, size_t *cntp)
+{
+ int mib[5];
+ int error;
+ size_t len;
+ struct kinfo_vmentry *kiv;
+
+ *cntp = 0;
+ len = 0;
+ mib[0] = CTL_VM;
+ mib[1] = VM_PROC;
+ mib[2] = VM_PROC_MAP;
+ mib[3] = pid;
+ mib[4] = sizeof(*kiv);
+
+ error = sysctl(mib, __arraycount(mib), NULL, &len, NULL, 0);
+ if (error)
+ return NULL;
+
+ len = len * 4 / 3;
+
+ kiv = malloc(len);
+ if (kiv == NULL)
+ return NULL;
+
+ error = sysctl(mib, __arraycount(mib), kiv, &len, NULL, 0);
+ if (error) {
+ free(kiv);
+ return NULL;
+ }
+
+ *cntp = len / sizeof(*kiv);
+ return kiv; /* Caller must free() return value */
+}