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. Cc: Ingo Weinhold <[email protected]> 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 | 71 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 85 insertions(+), 4 deletions(-) diff --git a/mono/io-layer/ChangeLog b/mono/io-layer/ChangeLog index ede8fed..4bd2d1f 100644 --- a/mono/io-layer/ChangeLog +++ b/mono/io-layer/ChangeLog @@ -1,3 +1,15 @@ +2010-04-03 Andreas Färber <[email protected]> + + * 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-03 Zoltan Varga <[email protected]> * processes.c: Applied some openbsd changes from Robert Nagy <[email protected]>. @@ -120,7 +132,7 @@ Wed Feb 24 16:01:37 CET 2010 Paolo Molaro <[email protected]> 2009-09-01 Zoltan Varga <[email protected]> - * processes.c (EnumProcessModules): Applied patch from Romain Tarti�re + * processes.c (EnumProcessModules): Applied patch from Romain Tartière ([email protected]). Fix this on freebsd/OSX. Fixes #533893. 2009-08-18 Christian Hergert <[email protected]> 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 d830e11..15f0df1 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> @@ -1593,6 +1597,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) { @@ -1677,8 +1699,13 @@ gpointer OpenProcess (guint32 req_access G_GNUC_UNUSED, gboolean inherit G_GNUC_ process_open_compare, GUINT_TO_POINTER (pid), NULL, TRUE); if (handle == 0) { +#ifdef __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)) { +#endif /* Return a pseudo handle for processes we * don't have handles for */ @@ -1891,6 +1918,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) { @@ -2105,7 +2163,7 @@ gboolean EnumProcessModules (gpointer process, gpointer *modules, proc_name = process_handle->proc_name; } -#ifdef PLATFORM_MACOSX +#if defined(PLATFORM_MACOSX) || defined(__HAIKU__) { mods = load_modules (); #else @@ -2177,6 +2235,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); @@ -2282,7 +2347,7 @@ static guint32 get_module_name (gpointer process, gpointer module, } /* Look up the address in /proc/<pid>/maps */ -#ifdef PLATFORM_MACOSX +#if defined(PLATFORM_MACOSX) || defined(__HAIKU__) { mods = load_modules (); #else @@ -2432,7 +2497,7 @@ gboolean GetModuleInformation (gpointer process, gpointer module, proc_name = g_strdup (process_handle->proc_name); } -#ifdef PLATFORM_MACOSX +#if defined(PLATFORM_MACOSX) || defined(__HAIKU__) { mods = load_modules (); #else -- 1.7.0.4
_______________________________________________ Mono-devel-list mailing list [email protected] http://lists.ximian.com/mailman/listinfo/mono-devel-list
