[Mono-dev] [PATCH v4 4/7] io-layer: Fix process helper functions for Haiku
Zoltan Varga
vargaz at gmail.com
Fri Apr 9 22:32:41 EDT 2010
Looks ok.
Zoltan
On Mon, Apr 5, 2010 at 1:52 AM, Andreas Färber <andreas.faerber at web.de>wrote:
> Haiku has neither makedev nor /proc. Enumerate processes, process modules
> and retrieve the process name via Kernel Kit. Fixes build on Haiku.
>
> Adjust _WAPI_PROCESS_UNHANDLED_PID_MASK to cope with Haiku's 32-bit pid_t.
> Fixes exception trying to obtain the ProcessName of pids >= 2^15.
>
> v3 -> v4:
> * Rebase against OpenBSD changes.
>
> v2 -> v3:
> * Fix get_process_name_from_proc implementation to use get_next_image_info.
> * Add new implementation of EnumProcesses.
> * Fix OpenProcess' check whether pid is available.
> * Fix _WAPI_PROCESS_UNHANDLED_PID_MASK to handle Haiku's 32-bit pid_t.
> * Fix module addresses in load_modules by considering the text segment,
> too.
> Suggested by Ingo Weinhold.
> * Add ChangeLog entry, fix file encoding.
>
> v1 -> v2:
> * Instead of providing a dummy makedev macro, avoid its use.
> * Don't try to parse /proc.
> * Add new implementations of load_modules and get_process_name_from_proc
> based on libroot's Kernel Kit, suggested by François Revol.
> ---
> mono/io-layer/ChangeLog | 14 +++++++-
> mono/io-layer/process-private.h | 4 ++
> mono/io-layer/processes.c | 69
> +++++++++++++++++++++++++++++++++++++--
> 3 files changed, 83 insertions(+), 4 deletions(-)
>
> diff --git a/mono/io-layer/ChangeLog b/mono/io-layer/ChangeLog
> index bb199ba..3fed2e9 100644
> --- a/mono/io-layer/ChangeLog
> +++ b/mono/io-layer/ChangeLog
> @@ -1,3 +1,15 @@
> +2010-04-04 Andreas Färber <andreas.faerber at web.de>
> +
> + * processes.c (EnumProcesses, load_modules): Add implementations
> + for Haiku. Fixes build on Haiku.
> + (OpenProcess, EnumProcessModules, get_process_name_from_proc):
> + Tweak implementations for Haiku.
> + * process-private.h: Fix _WAPI_PROCESS_UNHANDLED_PID_MASK for
> + 32-bit pids (Haiku).
> + * ChangeLog: Fix UTF-8 encoding
> +
> + Code is contributed under MIT/X11 license.
> +
> 2010-04-04 Zoltan Varga <vargaz at gmail.com>
>
> * processes.c: Applied more openbsd changes from Robert Nagy <
> robert at openbsd.org>.
> @@ -128,7 +140,7 @@ Wed Feb 24 16:01:37 CET 2010 Paolo Molaro <
> lupus at ximian.com>
>
> 2009-09-01 Zoltan Varga <vargaz at gmail.com>
>
> - * processes.c (EnumProcessModules): Applied patch from Romain
> Tartière
> + * processes.c (EnumProcessModules): Applied patch from Romain
> Tartière
> (romain at blogreen.org). Fix this on freebsd/OSX. Fixes #533893.
>
> 2009-08-18 Christian Hergert <chris at dronelabs.com>
> diff --git a/mono/io-layer/process-private.h
> b/mono/io-layer/process-private.h
> index a8b9f54..dc95283 100644
> --- a/mono/io-layer/process-private.h
> +++ b/mono/io-layer/process-private.h
> @@ -18,7 +18,11 @@
>
> /* This marks a system process that we don't have a handle on */
> /* FIXME: cope with pids > 16bit */
> +#if defined(__HAIKU__)
> +#define _WAPI_PROCESS_UNHANDLED_PID_MASK 0x7FFFFFFF
> +#else
> #define _WAPI_PROCESS_UNHANDLED_PID_MASK 0x7FFF
> +#endif
> #define _WAPI_PROCESS_UNHANDLED (-1 & ~_WAPI_PROCESS_UNHANDLED_PID_MASK)
>
> extern gpointer _wapi_process_duplicate (void);
> diff --git a/mono/io-layer/processes.c b/mono/io-layer/processes.c
> index 55d9600..98507d5 100644
> --- a/mono/io-layer/processes.c
> +++ b/mono/io-layer/processes.c
> @@ -54,6 +54,10 @@
> #endif
> #endif
>
> +#ifdef __HAIKU__
> +#include <KernelKit.h>
> +#endif
> +
> #include <mono/io-layer/wapi.h>
> #include <mono/io-layer/wapi-private.h>
> #include <mono/io-layer/handles-private.h>
> @@ -1595,6 +1599,24 @@ gboolean EnumProcesses (guint32 *pids, guint32 len,
> guint32 *needed)
>
> return(TRUE);
> }
> +#elif defined(__HAIKU__)
> +
> +gboolean EnumProcesses (guint32 *pids, guint32 len, guint32 *needed)
> +{
> + guint32 fit, i = 0;
> + int32 cookie = 0;
> + team_info teamInfo;
> +
> + mono_once (&process_current_once, process_set_current);
> +
> + fit = len / sizeof (guint32);
> + while (get_next_team_info (&cookie, &teamInfo) == B_OK && i < fit)
> {
> + pids [i++] = teamInfo.team;
> + }
> + *needed = i * sizeof (guint32);
> +
> + return TRUE;
> +}
> #else
> gboolean EnumProcesses (guint32 *pids, guint32 len, guint32 *needed)
> {
> @@ -1681,6 +1703,9 @@ gpointer OpenProcess (guint32 req_access
> G_GNUC_UNUSED, gboolean inherit G_GNUC_
> if (handle == 0) {
> #if defined(__OpenBSD__)
> if ((kill(pid, 0) == 0) || (errno == EPERM)) {
> +#elif defined(__HAIKU__)
> + team_info teamInfo;
> + if (get_team_info ((team_id)pid, &teamInfo) == B_OK) {
> #else
> gchar *dir = g_strdup_printf ("/proc/%d", pid);
> if (!access (dir, F_OK)) {
> @@ -1958,6 +1983,37 @@ static GSList *load_modules (void)
>
> return(ret);
> }
> +#elif defined(__HAIKU__)
> +
> +static GSList *load_modules (void)
> +{
> + GSList *ret = NULL;
> + WapiProcModule *mod;
> + int32 cookie = 0;
> + image_info imageInfo;
> +
> + while (get_next_image_info (B_CURRENT_TEAM, &cookie, &imageInfo) ==
> B_OK) {
> + mod = g_new0 (WapiProcModule, 1);
> + mod->device = imageInfo.device;
> + mod->inode = imageInfo.node;
> + mod->filename = g_strdup (imageInfo.name);
> + mod->address_start = MIN (imageInfo.text, imageInfo.data);
> + mod->address_end = MAX ((uint8_t*)imageInfo.text +
> imageInfo.text_size,
> + (uint8_t*)imageInfo.data + imageInfo.data_size);
> + mod->perms = g_strdup ("r--p");
> + mod->address_offset = 0;
> +
> + if (g_slist_find_custom (ret, mod, find_procmodule) ==
> NULL) {
> + ret = g_slist_prepend (ret, mod);
> + } else {
> + free_procmodule (mod);
> + }
> + }
> +
> + ret = g_slist_reverse (ret);
> +
> + return ret;
> +}
> #else
> static GSList *load_modules (FILE *fp)
> {
> @@ -2176,7 +2232,7 @@ gboolean EnumProcessModules (gpointer process,
> gpointer *modules,
> proc_name = process_handle->proc_name;
> }
>
> -#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__)
> +#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__HAIKU__)
> {
> mods = load_modules ();
> #else
> @@ -2248,6 +2304,13 @@ static gchar *get_process_name_from_proc (pid_t pid)
> proc_name (pid, buf, sizeof(buf));
> if (strlen (buf) > 0)
> ret = g_strdup (buf);
> +#elif defined(__HAIKU__)
> + image_info imageInfo;
> + int32 cookie = 0;
> +
> + if (get_next_image_info ((team_id)pid, &cookie, &imageInfo) ==
> B_OK) {
> + ret = g_strdup (imageInfo.name);
> + }
> #else
> memset (buf, '\0', sizeof(buf));
> filename = g_strdup_printf ("/proc/%d/exe", pid);
> @@ -2355,7 +2418,7 @@ static guint32 get_module_name (gpointer process,
> gpointer module,
> }
>
> /* Look up the address in /proc/<pid>/maps */
> -#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__)
> +#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__HAIKU__)
> {
> mods = load_modules ();
> #else
> @@ -2507,7 +2570,7 @@ gboolean GetModuleInformation (gpointer process,
> gpointer module,
> proc_name = g_strdup (process_handle->proc_name);
> }
>
> -#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__)
> +#if defined(PLATFORM_MACOSX) || defined(__OpenBSD__) || defined(__HAIKU__)
> {
> mods = load_modules ();
> #else
> --
> 1.7.0.4.297.g6555b1
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100410/83b37f04/attachment-0001.html
More information about the Mono-devel-list
mailing list