openbsd-ports/devel/libgtop2/patches/patch-sysdeps_bsd_procmem_c
ajacoutot 40fdf8a7c1 Implements procwd and procopenfiles using a wrapper around lsof(8)
(from FreeBSD sysdeps directory).
Merge proctime.c patch from pkgsrc.
Several other cleanings.
2010-04-18 12:32:09 +00:00

114 lines
3.8 KiB
Plaintext

$OpenBSD: patch-sysdeps_bsd_procmem_c,v 1.3 2010/04/18 12:32:09 ajacoutot Exp $
--- sysdeps/bsd/procmem.c.orig Sun Apr 19 19:51:00 2009
+++ sysdeps/bsd/procmem.c Sun Apr 18 12:10:09 2010
@@ -30,7 +30,7 @@
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/resource.h>
-#if defined(__NetBSD__) && (__NetBSD_Version__ >= 105020000)
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 105020000) || defined(__OpenBSD__)
#include <uvm/uvm_extern.h>
#else
#include <vm/vm_object.h>
@@ -46,14 +46,15 @@
#include <sys/user.h>
#endif
#include <sys/sysctl.h>
-#if defined(__NetBSD__) && (__NetBSD_Version__ >= 105020000)
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 105020000)) || defined(__OpenBSD__)
#include <uvm/uvm.h>
#else
#include <vm/vm.h>
#endif
-#if defined(__NetBSD__) && \
- (__NetBSD_Version__ >= 104000000) && (__NetBSD_Version__ < 105020000)
+#if (defined(__NetBSD__) && \
+ (__NetBSD_Version__ >= 104000000) && (__NetBSD_Version__ < 105020000)) \
+ || defined(__OpenBSD__)
/* Fixme ... */
#undef _KERNEL
#define _UVM_UVM_AMAP_I_H_ 1
@@ -69,10 +70,9 @@ static const unsigned long _glibtop_sysdeps_proc_mem =
(1L << GLIBTOP_PROC_MEM_RSS_RLIM);
static const unsigned long _glibtop_sysdeps_proc_mem_share =
-#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || \
+ defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
(1L << GLIBTOP_PROC_MEM_SHARE);
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-(1L << GLIBTOP_PROC_MEM_SHARE);
#else
0;
#endif
@@ -116,6 +116,9 @@ void
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
pid_t pid)
{
+#if defined(__OpenBSD__)
+ struct kinfo_proc2 *pinfo;
+#else
struct kinfo_proc *pinfo;
struct vm_map_entry entry, *first;
struct vmspace *vms, vmspace;
@@ -127,6 +130,8 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
#if (!defined(__FreeBSD__) || (__FreeBSD_version < 500013)) && !defined(__FreeBSD_kernel__)
struct plimit plimit;
#endif
+#endif /* __OpenBSD__ */
+
int count;
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_MEM), 0);
@@ -140,7 +145,12 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
if (pid == 0) return;
/* Get the process data */
- pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
+#if defined(__OpenBSD__)
+ pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid,
+ sizeof (*pinfo), &count);
+#else
+ pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
+#endif
if ((pinfo == NULL) || (count < 1)) {
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
return;
@@ -157,6 +167,15 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
buf->resident = buf->rss = (guint64) pagetok
(pinfo [0].ki_rssize) << LOG1024;
+#elif defined(__OpenBSD__)
+
+ buf->rss_rlim = pinfo[0].p_uru_maxrss;
+ buf->vsize = buf->size = (guint64)pagetok
+ (pinfo[0].p_vm_tsize + pinfo[0].p_vm_dsize + pinfo[0].p_vm_ssize)
+ << LOG1024;
+ buf->resident = buf->rss = (guint64)pagetok
+ (pinfo[0].p_vm_rssize) << LOG1024;
+
#else
#define PROC_VMSPACE kp_proc.p_vmspace
@@ -182,6 +201,10 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
/* Now we get the shared memory. */
+#if defined(__OpenBSD__)
+ buf->share = pinfo[0].p_uru_ixrss;
+#else
+
if (kvm_read (server->machine.kd,
(unsigned long) pinfo [0].PROC_VMSPACE,
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
@@ -287,6 +310,8 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
buf->share += object.un_pager.vnp.vnp_size;
#endif
}
+
+#endif /* __OpenBSD */
buf->flags = _glibtop_sysdeps_proc_mem |
_glibtop_sysdeps_proc_mem_share;