Skip to content

Commit

Permalink
Merge pull request #3 from koron-go/support-freebsd
Browse files Browse the repository at this point in the history
impl. for FreeBSD
  • Loading branch information
koron authored Aug 14, 2020
2 parents ae7c630 + 5a24e15 commit 585270a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions phymem.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// +build !windows
// +build !linux
// +build !freebsd

package phymem

Expand Down
38 changes: 38 additions & 0 deletions phymem_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package phymem

// #include <stdio.h>
// #include <unistd.h>
// #include <sys/types.h>
// #include <sys/sysctl.h>
// #include <sys/param.h>
// #include <sys/user.h>
//
//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
}

0 comments on commit 585270a

Please sign in to comment.