33 |
|
#include <regex.h> |
34 |
|
#ifdef ALLBSD |
35 |
|
#include <fcntl.h> |
36 |
+ |
#endif |
37 |
+ |
#if defined(FREEBSD) || defined(DFBSD) |
38 |
|
#include <kvm.h> |
39 |
|
#endif |
40 |
< |
#ifdef NETBSD |
40 |
> |
#if defined(NETBSD) || defined(OPENBSD) |
41 |
|
#include <uvm/uvm_extern.h> |
42 |
+ |
#include <sys/param.h> |
43 |
+ |
#include <sys/sysctl.h> |
44 |
|
#endif |
45 |
|
|
46 |
|
#include "tools.h" |
420 |
|
return num; |
421 |
|
} |
422 |
|
|
423 |
< |
#ifdef ALLBSD |
423 |
> |
#if defined(FREEBSD) || defined(DFBSD) |
424 |
|
kvm_t *get_kvm() { |
425 |
|
static kvm_t *kvmd = NULL; |
426 |
|
|
433 |
|
} |
434 |
|
#endif |
435 |
|
|
436 |
< |
#ifdef NETBSD |
436 |
> |
#if defined(NETBSD) || defined(OPENBSD) |
437 |
|
struct uvmexp *get_uvmexp() { |
438 |
< |
static u_long addr = 0; |
439 |
< |
static struct uvmexp uvm; |
440 |
< |
kvm_t *kvmd = get_kvm(); |
438 |
> |
int mib[2]; |
439 |
> |
size_t size; |
440 |
> |
static struct uvmexp *uvm = NULL; |
441 |
|
|
442 |
< |
if (kvmd == NULL) { |
442 |
> |
mib[0] = CTL_VM; |
443 |
> |
mib[1] = VM_UVMEXP; |
444 |
> |
|
445 |
> |
if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) { |
446 |
|
return NULL; |
447 |
|
} |
448 |
|
|
449 |
< |
if (addr == 0) { |
450 |
< |
struct nlist symbols[] = { |
451 |
< |
{ "_uvmexp" }, |
445 |
< |
{ NULL } |
446 |
< |
}; |
447 |
< |
|
448 |
< |
if (kvm_nlist(kvmd, symbols) != 0) { |
449 |
< |
return NULL; |
450 |
< |
} |
451 |
< |
addr = symbols[0].n_value; |
449 |
> |
uvm = realloc(uvm, size); |
450 |
> |
if (uvm == NULL) { |
451 |
> |
return NULL; |
452 |
|
} |
453 |
|
|
454 |
< |
if (kvm_read(kvmd, addr, &uvm, sizeof uvm) != sizeof uvm) { |
454 |
> |
if (sysctl(mib, 2, uvm, &size, NULL, 0) < 0) { |
455 |
|
return NULL; |
456 |
|
} |
457 |
< |
return &uvm; |
457 |
> |
|
458 |
> |
return uvm; |
459 |
|
} |
460 |
|
#endif |
461 |
|
|
462 |
|
int statgrab_init(){ |
463 |
< |
#ifdef ALLBSD |
463 |
> |
#if defined(FREEBSD) || defined(DFBSD) |
464 |
|
{ |
465 |
|
kvm_t *kvmd = get_kvm(); |
466 |
|
if (kvmd == NULL) return 1; |
466 |
– |
} |
467 |
– |
#endif |
468 |
– |
#ifdef NETBSD |
469 |
– |
{ |
470 |
– |
struct uvmexp *uvm = get_uvmexp(); |
471 |
– |
if (uvm == NULL) return 1; |
467 |
|
} |
468 |
|
#endif |
469 |
|
#ifdef SOLARIS |