Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libutil Add kinfo_getvmmap from FreeBSD



details:   https://anonhg.NetBSD.org/src/rev/f9503b78b35a
branches:  trunk
changeset: 340679:f9503b78b35a
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Sep 24 14:39:20 2015 +0000

description:
Add kinfo_getvmmap from FreeBSD

diffstat:

 lib/libutil/Makefile         |   6 +-
 lib/libutil/kinfo_getvmmap.3 |  80 ++++++++++++++++++++++++++++++++++++++++++++
 lib/libutil/kinfo_getvmmap.c |  48 ++++++++++++++++++++++++++
 lib/libutil/shlib_version    |   4 +-
 4 files changed, 133 insertions(+), 5 deletions(-)

diffs (174 lines):

diff -r 59732112933f -r f9503b78b35a lib/libutil/Makefile
--- a/lib/libutil/Makefile      Thu Sep 24 14:37:56 2015 +0000
+++ b/lib/libutil/Makefile      Thu Sep 24 14:39:20 2015 +0000
@@ -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 @@
        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 @@
        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 \
diff -r 59732112933f -r f9503b78b35a lib/libutil/kinfo_getvmmap.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libutil/kinfo_getvmmap.3      Thu Sep 24 14:39:20 2015 +0000
@@ -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
diff -r 59732112933f -r f9503b78b35a lib/libutil/kinfo_getvmmap.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libutil/kinfo_getvmmap.c      Thu Sep 24 14:39:20 2015 +0000
@@ -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 */
+}
diff -r 59732112933f -r f9503b78b35a lib/libutil/shlib_version
--- a/lib/libutil/shlib_version Thu Sep 24 14:37:56 2015 +0000
+++ b/lib/libutil/shlib_version Thu Sep 24 14:39:20 2015 +0000
@@ -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



Home | Main Index | Thread Index | Old Index