Skip to content

Commit

Permalink
Add NetBSD support
Browse files Browse the repository at this point in the history
* Return value of getRSS() is too short for 64-bit environment.
  This will fixed in my next commit.
  • Loading branch information
ryoon committed Aug 30, 2020
1 parent d2187a9 commit b681933
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions phymem_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package phymem

/*
#include <stdio.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <unistd.h>
static int
getRSS(void)
{
int ret;
size_t len;
struct kinfo_proc2 kp;
int mib[] = {CTL_KERN, KERN_PROC2, KERN_PROC_PID, getpid(), sizeof(kp), 1};
size_t miblen = __arraycount(mib);
len = sizeof(kp);
ret = sysctl(mib, miblen, &kp, &len, NULL, 0);
if (ret < 0) {
return -1;
}
long pagesize = sysconf(_SC_PAGESIZE);
return kp.p_vm_rssize * pagesize;
}
*/
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), nil
}

0 comments on commit b681933

Please sign in to comment.