From: Damjan Jovanovic Subject: [PATCH 4/7] server: implement vm counters on FreeBSD Message-Id: Date: Sun, 31 Oct 2021 17:48:46 +0200 Does not regenerate ./configure or include/config.h. Signed-off-by: Damjan Jovanovic --- configure.ac | 2 ++ include/config.h.in | 6 ++++++ server/Makefile.in | 2 +- server/process.c | 47 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index ab55c72a238..6e6e0d6340d 100644 --- a/configure.ac +++ b/configure.ac @@ -457,6 +457,7 @@ AC_CHECK_HEADERS(\ mach-o/loader.h \ mach/mach.h \ machine/cpu.h \ + machine/proc.h \ machine/sysarch.h \ mntent.h \ netdb.h \ @@ -490,6 +491,7 @@ AC_CHECK_HEADERS(\ sys/param.h \ sys/poll.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 a589411e4ae..7f3512c85c1 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -281,6 +281,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MACHINE_CPU_H +/* Define to 1 if you have the header file. */ +#undef HAVE_MACHINE_PROC_H + /* Define to 1 if you have the header file. */ #undef HAVE_MACHINE_SYSARCH_H @@ -664,6 +667,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_PRCTL_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_PRIORITY_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_PROTOSW_H diff --git a/server/Makefile.in b/server/Makefile.in index b6197cffec3..eaeccdb0bb5 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 6eda0bb0191..eab3da409fd 100644 --- a/server/process.c +++ b/server/process.c @@ -38,6 +38,30 @@ #ifdef HAVE_POLL_H #include #endif +#ifdef HAVE_SYS_PARAM_H +# include +#endif +#ifdef HAVE_SYS_QUEUE_H +# include +#endif +#ifdef HAVE_SYS_SYSCTL_H +# include +#endif + +/* Prevent sys/user.h from including sys/proc.h, which redefines 'struct thread': */ +#define _SYS_PROC_H_ +#ifdef HAVE_MACHINE_PROC_H +# include +#endif +#ifdef HAVE_SYS_PRIORITY_H +# include +#endif +#ifdef HAVE_SYS_USER_H +# include +#endif +#ifdef HAVE_LIBPROCSTAT +# include +#endif #include "ntstatus.h" #define WIN32_NO_STATUS @@ -1541,9 +1565,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; @@ -1570,9 +1594,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 ); }