40 |
|
#include <sys/sysctl.h> |
41 |
|
#include <unistd.h> |
42 |
|
#endif |
43 |
< |
#ifdef OPENBSD |
44 |
< |
#include <stdlib.h> |
43 |
> |
#if defined(NETBSD) || defined(OPENBSD) |
44 |
|
#include <sys/param.h> |
46 |
– |
#include <sys/sysctl.h> |
45 |
|
#include <uvm/uvm.h> |
46 |
|
#endif |
47 |
|
|
73 |
|
#if defined(NETBSD) || defined(OPENBSD) |
74 |
|
struct uvmexp *uvm; |
75 |
|
#endif |
78 |
– |
#ifdef OPENBSD |
79 |
– |
int mib[2]; |
80 |
– |
size_t size; |
81 |
– |
#endif |
76 |
|
|
77 |
|
#ifdef SOLARIS |
78 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
169 |
|
mem_stat.used=physmem-mem_stat.free; |
170 |
|
#endif |
171 |
|
|
172 |
< |
#ifdef NETBSD |
172 |
> |
#if defined(NETBSD) || defined(OPENBSD) |
173 |
|
if ((uvm = get_uvmexp()) == NULL) { |
174 |
|
return NULL; |
175 |
|
} |
182 |
– |
#endif |
183 |
– |
#ifdef OPENBSD |
184 |
– |
mib[0] = CTL_VM; |
185 |
– |
mib[1] = VM_UVMEXP; |
176 |
|
|
187 |
– |
if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) { |
188 |
– |
return NULL; |
189 |
– |
} |
190 |
– |
|
191 |
– |
uvm = malloc(size); |
192 |
– |
if (uvm == NULL) { |
193 |
– |
return NULL; |
194 |
– |
} |
195 |
– |
|
196 |
– |
if (sysctl(mib, 2, uvm, &size, NULL, 0) < 0) { |
197 |
– |
return NULL; |
198 |
– |
} |
199 |
– |
#endif |
200 |
– |
#if defined(NETBSD) || defined(OPENBSD) |
177 |
|
mem_stat.total = uvm->pagesize * uvm->npages; |
178 |
|
#ifdef NETBSD |
179 |
|
mem_stat.cache = uvm->pagesize * (uvm->filepages + uvm->execpages); |
180 |
|
#else |
181 |
+ |
/* Can't find cache memory on OpenBSD */ |
182 |
|
mem_stat.cache = 0; |
183 |
|
#endif |
184 |
|
mem_stat.free = uvm->pagesize * (uvm->free + uvm->inactive); |
185 |
|
mem_stat.used = mem_stat.total - mem_stat.free; |
209 |
– |
#endif |
210 |
– |
|
211 |
– |
#ifdef OPENBSD |
212 |
– |
free(uvm); |
186 |
|
#endif |
187 |
|
|
188 |
|
return &mem_stat; |