diff --git a/phymem.go b/phymem.go index f575935..64ccf5e 100644 --- a/phymem.go +++ b/phymem.go @@ -1,5 +1,6 @@ // +build !windows // +build !linux +// +build !freebsd package phymem diff --git a/phymem_freebsd.go b/phymem_freebsd.go new file mode 100644 index 0000000..d059e41 --- /dev/null +++ b/phymem_freebsd.go @@ -0,0 +1,38 @@ +package phymem + +// #include +// #include +// #include +// #include +// #include +// #include +// +//static segsz_t getRSS(void) { +// int mib[4]; +// size_t len; +// struct kinfo_proc ki; +// +// len = sizeof(mib) / sizeof(mib[0]); +// if (sysctlnametomib("kern.proc.pid", mib, &len) == -1) { +// return -1; +// } +// mib[3] = getpid(); +// len = sizeof(ki); +// if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &ki, &len, NULL, 0) == -1) { +// return -2; +// } +// return ki.ki_rssize; +//} +import "C" +import "fmt" + +// for test. +const providedCurrent = true + +func Current() (uint, error) { + rss := int(C.getRSS()) + if rss < 0 { + return 0, fmt.Errorf("failed to get RSS via sysctl: %d", rss) + } + return uint(rss) * 4096, nil +}