Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add FreeBSD support in the memory.c. #31

Closed
wants to merge 1 commit into from

2 participants

@jlmess77

No description provided.

@BourgerieQuentin

Should be available since v1214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 29, 2012
  1. @jlmess77
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 2 deletions.
  1. +4 −1 build/myocamlbuild_prefix.ml
  2. +30 −1 libbase/memory.c
View
5 build/myocamlbuild_prefix.ml
@@ -541,9 +541,12 @@ let _ = dispatch begin function
let file = dir / "lib" ^ name -.- !Options.ext_lib in
dep ["ocaml"; tag] [file];
flag ["ocaml"; "byte"; "link"; tag] (S[A"-ccopt";A("-L"^dir);A"-cclib";A("-l"^name);A"-custom"]);
- flag ["ocaml"; "native"; "link"; tag] (S[A"-ccopt";A("-L"^dir);A"-cclib";A("-l"^name)])
+ flag ["ocaml"; "native"; "link"; tag] (S[A"-ccopt";A("-L"^dir);A"-cclib";A("-l"^name)]);
in
+ (* In the memory.c in FreeBSD part that uses kvm_getprocs() required link with -lkvm. *)
+ if is_fbsd then
+ flag ["use_stubs"; "link"] (S[A "-cclib";A "-lkvm"]);
(* -- Don't forget that the rest of the "mlstate build stdlib" is in --
-- myocamlbuild_suffix.ml. The rest comes from the build_rules*.ml in each repo -- *)
View
31 libbase/memory.c
@@ -38,7 +38,36 @@ int get_mem (unsigned int *rss)
return 0;
}
-#else /* not MAC */
+#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) /* FreeBSD */
+
+#include <kvm.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+
+int get_mem (unsigned int *rss)
+{
+ kvm_t *kv;
+ int cnt,pagesize,pid;
+
+ pagesize = getpagesize();
+ pid = getpid();
+ kv = kvm_open(NULL, "/dev/null", NULL, O_RDONLY, NULL);
+
+ if (kv != NULL) {
+ struct kinfo_proc *kproc;
+ kproc = kvm_getprocs(kv, KERN_PROC_PID, pid, &cnt);
+ if (kproc && cnt > 0)
+ *rss = kproc->ki_rssize * pagesize;
+ else *rss = 0;
+ kvm_close(kv);
+ return 0;
+ } else return -1;
+}
+
+#else /* not MAC and FreeBSD */
#include <stdio.h>
#include <unistd.h>
Something went wrong with that request. Please try again.