[BACK]Return to kinfo_getvmmap.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libutil

File: [cvs.NetBSD.org] / src / lib / libutil / kinfo_getvmmap.c (download)

Revision 1.4, Wed Jun 14 12:24:51 2017 UTC (2 years, 9 months ago) by kamil
Branch: MAIN
CVS Tags: phil-wifi-base, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, HEAD
Changes since 1.3: +1 -2 lines

Stop including <sys/user.h> in userland libraries

This header in this context is freebsdism.

#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.4 2017/06/14 12:24:51 kamil Exp $");

#include <sys/param.h>
#include <sys/sysctl.h>
#include <stdlib.h>
#include <string.h>
#include <util.h>
#include <uvm/uvm_param.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, (u_int)__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, (u_int)__arraycount(mib), kiv, &len, NULL, 0);
	if (error) {
		free(kiv);
		return NULL;
	}

	*cntp = len / sizeof(*kiv);
	return kiv;	/* Caller must free() return value */
}