kinfo_getvmmap.c (302408) | kinfo_getvmmap.c (312031) |
---|---|
1#include <sys/cdefs.h> | 1#include <sys/cdefs.h> |
2__FBSDID("$FreeBSD: stable/11/lib/libutil/kinfo_getvmmap.c 288944 2015-10-06 18:07:00Z cem $"); | 2__FBSDID("$FreeBSD: stable/11/lib/libutil/kinfo_getvmmap.c 312031 2017-01-13 08:39:23Z ngie $"); |
3 4#include <sys/param.h> | 3 4#include <sys/param.h> |
5#include <sys/user.h> | |
6#include <sys/sysctl.h> | 5#include <sys/sysctl.h> |
6#include <sys/user.h> |
|
7#include <stdlib.h> 8#include <string.h> 9 10#include "libutil.h" 11 12struct kinfo_vmentry * 13kinfo_getvmmap(pid_t pid, int *cntp) 14{ --- 6 unchanged lines hidden (view full) --- 21 22 *cntp = 0; 23 len = 0; 24 mib[0] = CTL_KERN; 25 mib[1] = KERN_PROC; 26 mib[2] = KERN_PROC_VMMAP; 27 mib[3] = pid; 28 | 7#include <stdlib.h> 8#include <string.h> 9 10#include "libutil.h" 11 12struct kinfo_vmentry * 13kinfo_getvmmap(pid_t pid, int *cntp) 14{ --- 6 unchanged lines hidden (view full) --- 21 22 *cntp = 0; 23 len = 0; 24 mib[0] = CTL_KERN; 25 mib[1] = KERN_PROC; 26 mib[2] = KERN_PROC_VMMAP; 27 mib[3] = pid; 28 |
29 error = sysctl(mib, 4, NULL, &len, NULL, 0); | 29 error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0); |
30 if (error) 31 return (NULL); 32 len = len * 4 / 3; 33 buf = malloc(len); 34 if (buf == NULL) 35 return (NULL); | 30 if (error) 31 return (NULL); 32 len = len * 4 / 3; 33 buf = malloc(len); 34 if (buf == NULL) 35 return (NULL); |
36 error = sysctl(mib, 4, buf, &len, NULL, 0); | 36 error = sysctl(mib, nitems(mib), buf, &len, NULL, 0); |
37 if (error) { 38 free(buf); 39 return (NULL); 40 } 41 /* Pass 1: count items */ 42 cnt = 0; 43 bp = buf; 44 eb = buf + len; --- 33 unchanged lines hidden --- | 37 if (error) { 38 free(buf); 39 return (NULL); 40 } 41 /* Pass 1: count items */ 42 cnt = 0; 43 bp = buf; 44 eb = buf + len; --- 33 unchanged lines hidden --- |