kinfo_getvmmap.c (7d4b968b0fa6afc6bca132c27e2041c979ee6101) | kinfo_getvmmap.c (e6b95927f39018d10fcfc39f8236525c72b84d06) |
---|---|
1#include <sys/cdefs.h> 2__FBSDID("$FreeBSD$"); 3 4#include <sys/param.h> 5#include <sys/user.h> 6#include <sys/sysctl.h> 7#include <stdlib.h> 8#include <string.h> --- 30 unchanged lines hidden (view full) --- 39 return (NULL); 40 } 41 /* Pass 1: count items */ 42 cnt = 0; 43 bp = buf; 44 eb = buf + len; 45 while (bp < eb) { 46 kv = (struct kinfo_vmentry *)(uintptr_t)bp; | 1#include <sys/cdefs.h> 2__FBSDID("$FreeBSD$"); 3 4#include <sys/param.h> 5#include <sys/user.h> 6#include <sys/sysctl.h> 7#include <stdlib.h> 8#include <string.h> --- 30 unchanged lines hidden (view full) --- 39 return (NULL); 40 } 41 /* Pass 1: count items */ 42 cnt = 0; 43 bp = buf; 44 eb = buf + len; 45 while (bp < eb) { 46 kv = (struct kinfo_vmentry *)(uintptr_t)bp; |
47 if (kv->kve_structsize == 0) 48 break; |
|
47 bp += kv->kve_structsize; 48 cnt++; 49 } 50 51 kiv = calloc(cnt, sizeof(*kiv)); 52 if (kiv == NULL) { 53 free(buf); 54 return (NULL); 55 } 56 bp = buf; 57 eb = buf + len; 58 kp = kiv; 59 /* Pass 2: unpack */ 60 while (bp < eb) { 61 kv = (struct kinfo_vmentry *)(uintptr_t)bp; | 49 bp += kv->kve_structsize; 50 cnt++; 51 } 52 53 kiv = calloc(cnt, sizeof(*kiv)); 54 if (kiv == NULL) { 55 free(buf); 56 return (NULL); 57 } 58 bp = buf; 59 eb = buf + len; 60 kp = kiv; 61 /* Pass 2: unpack */ 62 while (bp < eb) { 63 kv = (struct kinfo_vmentry *)(uintptr_t)bp; |
64 if (kv->kve_structsize == 0) 65 break; |
|
62 /* Copy/expand into pre-zeroed buffer */ 63 memcpy(kp, kv, kv->kve_structsize); 64 /* Advance to next packed record */ 65 bp += kv->kve_structsize; 66 /* Set field size to fixed length, advance */ 67 kp->kve_structsize = sizeof(*kp); 68 kp++; 69 } 70 free(buf); 71 *cntp = cnt; 72 return (kiv); /* Caller must free() return value */ 73} | 66 /* Copy/expand into pre-zeroed buffer */ 67 memcpy(kp, kv, kv->kve_structsize); 68 /* Advance to next packed record */ 69 bp += kv->kve_structsize; 70 /* Set field size to fixed length, advance */ 71 kp->kve_structsize = sizeof(*kp); 72 kp++; 73 } 74 free(buf); 75 *cntp = cnt; 76 return (kiv); /* Caller must free() return value */ 77} |