[PATCH v2] server: implement vm counters on FreeBSD
Damjan Jovanovic
damjan.jov at gmail.com
Thu Nov 11 21:58:17 CST 2021
Does not regenerate ./configure or include/config.h.
Try 2 gets the patch to apply.
Signed-off-by: Damjan Jovanovic <damjan.jov at gmail.com>
---
configure.ac | 2 ++
include/config.h.in | 6 ++++++
server/Makefile.in | 2 +-
server/process.c | 47 +++++++++++++++++++++++++++++++++++++++++++--
4 files changed, 54 insertions(+), 3 deletions(-)
-------------- next part --------------
diff --git a/configure.ac b/configure.ac
index f86a5decb07..c6a8d8dd82f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -467,6 +467,7 @@ AC_CHECK_HEADERS(\
mach-o/loader.h \
mach/mach.h \
machine/cpu.h \
+ machine/proc.h \
machine/sysarch.h \
mntent.h \
netdb.h \
@@ -498,6 +499,7 @@ AC_CHECK_HEADERS(\
sys/mtio.h \
sys/param.h \
sys/prctl.h \
+ sys/priority.h \
sys/protosw.h \
sys/ptrace.h \
sys/queue.h \
diff --git a/include/config.h.in b/include/config.h.in
index 09cf7c923e3..045636a4b7d 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -281,6 +281,9 @@
/* Define to 1 if you have the <machine/cpu.h> header file. */
#undef HAVE_MACHINE_CPU_H
+/* Define to 1 if you have the <machine/proc.h> header file. */
+#undef HAVE_MACHINE_PROC_H
+
/* Define to 1 if you have the <machine/sysarch.h> header file. */
#undef HAVE_MACHINE_SYSARCH_H
@@ -658,6 +661,9 @@
/* Define to 1 if you have the <sys/prctl.h> header file. */
#undef HAVE_SYS_PRCTL_H
+/* Define to 1 if you have the <sys/priority.h> header file. */
+#undef HAVE_SYS_PRIORITY_H
+
/* Define to 1 if you have the <sys/protosw.h> header file. */
#undef HAVE_SYS_PROTOSW_H
diff --git a/server/Makefile.in b/server/Makefile.in
index 84e78d0aa56..739d0517339 100644
--- a/server/Makefile.in
+++ b/server/Makefile.in
@@ -49,6 +49,6 @@ MANPAGES = \
wineserver.fr.UTF-8.man.in \
wineserver.man.in
-EXTRALIBS = $(LDEXECFLAGS) $(RT_LIBS) $(INOTIFY_LIBS)
+EXTRALIBS = $(LDEXECFLAGS) $(RT_LIBS) $(INOTIFY_LIBS) $(PROCSTAT_LIBS)
unicode_EXTRADEFS = -DNLSDIR="\"${nlsdir}\"" -DBIN_TO_NLSDIR=\"`${MAKEDEP} -R ${bindir} ${nlsdir}`\"
diff --git a/server/process.c b/server/process.c
index 48b5d6d6dd4..cd7a055b2e7 100644
--- a/server/process.c
+++ b/server/process.c
@@ -36,6 +36,30 @@
#endif
#include <unistd.h>
#include <poll.h>
+#ifdef HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_QUEUE_H
+# include <sys/queue.h>
+#endif
+#ifdef HAVE_SYS_SYSCTL_H
+# include <sys/sysctl.h>
+#endif
+
+/* Prevent sys/user.h from including sys/proc.h, which redefines 'struct thread': */
+#define _SYS_PROC_H_
+#ifdef HAVE_MACHINE_PROC_H
+# include <machine/proc.h>
+#endif
+#ifdef HAVE_SYS_PRIORITY_H
+# include <sys/priority.h>
+#endif
+#ifdef HAVE_SYS_USER_H
+# include <sys/user.h>
+#endif
+#ifdef HAVE_LIBPROCSTAT
+# include <libprocstat.h>
+#endif
#include "ntstatus.h"
#define WIN32_NO_STATUS
@@ -1539,9 +1563,9 @@ DECL_HANDLER(get_process_vm_counters)
struct process *process = get_process_from_handle( req->handle, PROCESS_QUERY_LIMITED_INFORMATION );
if (!process) return;
-#ifdef linux
if (process->unix_pid != -1)
{
+#ifdef linux
FILE *f;
char proc_path[32], line[256];
unsigned long value;
@@ -1568,9 +1592,28 @@ DECL_HANDLER(get_process_vm_counters)
fclose( f );
}
else set_error( STATUS_ACCESS_DENIED );
+#elif defined(HAVE_LIBPROCSTAT)
+ struct procstat *procstat;
+ unsigned int count;
+
+ if ((procstat = procstat_open_sysctl()))
+ {
+ struct kinfo_proc *kp = procstat_getprocs( procstat, KERN_PROC_PID, process->unix_pid, &count );
+ if (kp)
+ {
+ reply->virtual_size = kp->ki_size;
+ reply->peak_virtual_size = reply->virtual_size;
+ reply->working_set_size = kp->ki_rssize << PAGE_SHIFT;
+ reply->peak_working_set_size = kp->ki_rusage.ru_maxrss * 1024;
+ procstat_freeprocs( procstat, kp );
+ }
+ else set_error( STATUS_ACCESS_DENIED );
+ procstat_close( procstat );
+ }
+ else set_error( STATUS_ACCESS_DENIED );
+#endif
}
else set_error( STATUS_ACCESS_DENIED );
-#endif
release_object( process );
}
More information about the wine-devel
mailing list