libprocstat.c (f94594b37a145b9b3e9ff31af2cd1dc3de8aa4d4) libprocstat.c (e6b95927f39018d10fcfc39f8236525c72b84d06)
1/*-
2 * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
3 * Copyright (c) 1988, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 1853 unchanged lines hidden (view full) ---

1862 */
1863
1864 /* Pass 1: count items */
1865 cnt = 0;
1866 bp = buf;
1867 eb = buf + len;
1868 while (bp < eb) {
1869 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
1/*-
2 * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
3 * Copyright (c) 1988, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 1853 unchanged lines hidden (view full) ---

1862 */
1863
1864 /* Pass 1: count items */
1865 cnt = 0;
1866 bp = buf;
1867 eb = buf + len;
1868 while (bp < eb) {
1869 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
1870 if (kv->kve_structsize == 0)
1871 break;
1870 bp += kv->kve_structsize;
1871 cnt++;
1872 }
1873
1874 kiv = calloc(cnt, sizeof(*kiv));
1875 if (kiv == NULL) {
1876 free(buf);
1877 return (NULL);
1878 }
1879 bp = buf;
1880 eb = buf + len;
1881 kp = kiv;
1882 /* Pass 2: unpack */
1883 while (bp < eb) {
1884 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
1872 bp += kv->kve_structsize;
1873 cnt++;
1874 }
1875
1876 kiv = calloc(cnt, sizeof(*kiv));
1877 if (kiv == NULL) {
1878 free(buf);
1879 return (NULL);
1880 }
1881 bp = buf;
1882 eb = buf + len;
1883 kp = kiv;
1884 /* Pass 2: unpack */
1885 while (bp < eb) {
1886 kv = (struct kinfo_vmentry *)(uintptr_t)bp;
1887 if (kv->kve_structsize == 0)
1888 break;
1885 /* Copy/expand into pre-zeroed buffer */
1886 memcpy(kp, kv, kv->kve_structsize);
1887 /* Advance to next packed record */
1888 bp += kv->kve_structsize;
1889 /* Set field size to fixed length, advance */
1890 kp->kve_structsize = sizeof(*kp);
1891 kp++;
1892 }

--- 641 unchanged lines hidden ---
1889 /* Copy/expand into pre-zeroed buffer */
1890 memcpy(kp, kv, kv->kve_structsize);
1891 /* Advance to next packed record */
1892 bp += kv->kve_structsize;
1893 /* Set field size to fixed length, advance */
1894 kp->kve_structsize = sizeof(*kp);
1895 kp++;
1896 }

--- 641 unchanged lines hidden ---