#include <sys/time.h>
#include <errno.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <sys/param.h>
+#include <ctype.h>
#ifdef HAVE_SYS_MKDEV_H
#include <sys/mkdev.h>
#include <mono/io-layer/timefuncs-private.h>
/* The process' environment strings */
+#ifdef __APPLE__
+/* Apple defines this in crt_externs.h but doesn't provide that header for
+ * arm-apple-darwin9. We'll manually define the symbol on Apple as it does
+ * in fact exist on all implementations (so far)
+ */
+gchar ***_NSGetEnviron();
+#define environ (*_NSGetEnviron())
+#else
extern char **environ;
+#endif
#undef DEBUG
gboolean ok;
int thr_ret;
+ g_assert ((GPOINTER_TO_UINT (handle) & _WAPI_PROCESS_UNHANDLED) != _WAPI_PROCESS_UNHANDLED);
+
ok = _wapi_lookup_handle (handle, WAPI_HANDLE_PROCESS,
(gpointer *)&process_handle);
if (ok == FALSE) {
*/
#ifdef DEBUG
- g_message ("%s: Setting handle %p signalled", __func__, handle);
+ g_message ("%s: Setting handle %p pid %d signalled, exit status %d",
+ __func__, handle, process_handle->id,
+ process_handle->exitstatus);
#endif
_wapi_shared_handle_set_signal_state (handle, TRUE);
int status;
pid_t ret;
+ g_assert ((GPOINTER_TO_UINT (test) & _WAPI_PROCESS_UNHANDLED) != _WAPI_PROCESS_UNHANDLED);
+
ok = _wapi_lookup_handle (test, WAPI_HANDLE_PROCESS,
(gpointer *)&process);
if (ok == FALSE) {
pid_t pid, ret;
int status;
+ g_assert ((GPOINTER_TO_UINT (handle) & _WAPI_PROCESS_UNHANDLED) != _WAPI_PROCESS_UNHANDLED);
+
#ifdef DEBUG
g_message ("%s: Waiting for process %p", __func__, handle);
#endif
static const gunichar2 utf16_space_bytes [2] = { 0x20, 0 };
static const gunichar2 *utf16_space = utf16_space_bytes;
+static const gunichar2 utf16_quote_bytes [2] = { 0x22, 0 };
+static const gunichar2 *utf16_quote = utf16_quote_bytes;
/* Implemented as just a wrapper around CreateProcess () */
gboolean ShellExecuteEx (WapiShellExecuteInfo *sei)
#endif
handler_utf16 = g_utf8_to_utf16 (handler, -1, NULL, NULL, NULL);
g_free (handler);
- args = utf16_concat (handler_utf16, utf16_space, sei->lpFile,
+
+ /* Put quotes around the filename, in case it's a url
+ * that contains #'s (CreateProcess() calls
+ * g_shell_parse_argv(), which deliberately throws
+ * away anything after an unquoted #). Fixes bug
+ * 371567.
+ */
+ args = utf16_concat (handler_utf16, utf16_space, utf16_quote,
+ sei->lpFile, utf16_quote,
sei->lpParameters == NULL ? NULL : utf16_space,
sei->lpParameters, NULL);
if (args == NULL){
const gunichar2 *appname,
const gunichar2 *cmdline,
guint32 create_flags,
- gpointer environ,
+ gpointer env,
const gunichar2 *cwd,
WapiStartupInfo *startup,
WapiProcessInformation *process_info)
{
/* FIXME: use user information */
- return CreateProcess (appname, cmdline, NULL, NULL, FALSE, create_flags, environ, cwd, startup, process_info);
+ return CreateProcess (appname, cmdline, NULL, NULL, FALSE, create_flags, env, cwd, startup, process_info);
+}
+
+static gboolean
+is_executable (const char *prog)
+{
+ struct stat buf;
+ if (access (prog, X_OK) != 0)
+ return FALSE;
+ if (stat (prog, &buf))
+ return FALSE;
+ if (S_ISREG (buf.st_mode))
+ return TRUE;
+ return FALSE;
}
gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
#endif
SetLastError (ERROR_PATH_NOT_FOUND);
- goto cleanup;
+ goto free_strings;
}
/* Turn all the slashes round the right way */
#endif
SetLastError (ERROR_PATH_NOT_FOUND);
- goto cleanup;
+ goto free_strings;
}
}
#endif
SetLastError (ERROR_PATH_NOT_FOUND);
- goto cleanup;
+ goto free_strings;
}
/* Turn all the slashes round the right way */
prog = g_strdup (unquoted);
/* Executable existing ? */
- if (access (prog, X_OK) != 0) {
+ if (!is_executable (prog)) {
#ifdef DEBUG
g_message ("%s: Couldn't find executable %s",
__func__, prog);
#endif
g_free (unquoted);
SetLastError (ERROR_FILE_NOT_FOUND);
- goto cleanup;
+ goto free_strings;
}
} else {
/* Search for file named by cmd in the current
g_free (curdir);
/* And make sure it's executable */
- if (access (prog, X_OK) != 0) {
+ if (!is_executable (prog)) {
#ifdef DEBUG
g_message ("%s: Couldn't find executable %s",
__func__, prog);
#endif
g_free (unquoted);
SetLastError (ERROR_FILE_NOT_FOUND);
- goto cleanup;
+ goto free_strings;
}
}
g_free (unquoted);
#endif
SetLastError (ERROR_PATH_NOT_FOUND);
- goto cleanup;
+ goto free_strings;
}
/* Turn all the slashes round the right way. Only for
prog = g_strdup (token);
/* Executable existing ? */
- if (access (prog, X_OK) != 0) {
+ if (!is_executable (prog)) {
#ifdef DEBUG
g_message ("%s: Couldn't find executable %s",
__func__, token);
#endif
g_free (token);
SetLastError (ERROR_FILE_NOT_FOUND);
- goto cleanup;
+ goto free_strings;
}
} else {
/* I assume X_OK is the criterion to use,
* rather than F_OK
*/
- if (access (prog, X_OK) != 0) {
+ if (!is_executable (prog)) {
g_free (prog);
prog = g_find_program_in_path (token);
if (prog == NULL) {
g_free (token);
SetLastError (ERROR_FILE_NOT_FOUND);
- goto cleanup;
+ goto free_strings;
}
}
}
/* Check for CLR binaries; if found, we will try to invoke
* them using the same mono binary that started us.
*/
- if (is_managed_binary (prog) && (appname == NULL)) {
+ if (is_managed_binary (prog)) {
+ gunichar2 *newapp, *newcmd;
gsize bytes_ignored;
- appname = mono_unicode_from_external ("mono", &bytes_ignored);
+ newapp = mono_unicode_from_external ("mono", &bytes_ignored);
- if (appname != NULL) {
- cmdline = utf16_concat (appname, utf16_space, cmdline, NULL);
+ if (newapp != NULL) {
+ if (appname != NULL) {
+ newcmd = utf16_concat (newapp, utf16_space,
+ appname, utf16_space,
+ cmdline, NULL);
+ } else {
+ newcmd = utf16_concat (newapp, utf16_space,
+ cmdline, NULL);
+ }
- g_free ((gunichar2 *)appname);
+ g_free ((gunichar2 *)newapp);
- if (cmdline != NULL) {
- gboolean return_value = CreateProcess (
- NULL, cmdline, process_attrs,
- thread_attrs, inherit_handles, create_flags, new_environ,
- cwd, startup, process_info);
+ if (newcmd != NULL) {
+ ret = CreateProcess (NULL, newcmd,
+ process_attrs,
+ thread_attrs,
+ inherit_handles,
+ create_flags, new_environ,
+ cwd, startup,
+ process_info);
- g_free ((gunichar2 *)cmdline);
+ g_free ((gunichar2 *)newcmd);
- return return_value;
+ goto free_strings;
}
}
}
g_warning ("%s: error creating process handle", __func__);
SetLastError (ERROR_PATH_NOT_FOUND);
- goto cleanup;
+ goto free_strings;
}
/* Hold another reference so the process has somewhere to
cleanup:
_wapi_handle_unlock_shared_handles ();
+free_strings:
if (cmd != NULL) {
g_free (cmd);
}
{
struct _WapiHandle_process *process_handle;
gboolean ok;
+
+ if ((GPOINTER_TO_UINT (handle) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle */
+ return(GPOINTER_TO_UINT (handle) & _WAPI_PROCESS_UNHANDLED_PID_MASK);
+ }
ok = _wapi_lookup_handle (handle, WAPI_HANDLE_PROCESS,
(gpointer *)&process_handle);
struct _WapiHandle_process *process_handle;
gboolean ok;
+ g_assert ((GPOINTER_TO_UINT (handle) & _WAPI_PROCESS_UNHANDLED) != _WAPI_PROCESS_UNHANDLED);
+
/* Make sure the process is signalled if it has exited - if
* the parent process didn't wait for it then it won't be
*/
return (process_handle->id);
}
+#ifdef UNUSED_CODE
static gboolean process_enum (gpointer handle, gpointer user_data)
{
GArray *processes=user_data;
/* Return false to keep searching */
return(FALSE);
}
+#endif /* UNUSED_CODE */
gboolean EnumProcesses (guint32 *pids, guint32 len, guint32 *needed)
{
GArray *processes = g_array_new (FALSE, FALSE, sizeof(pid_t));
guint32 fit, i, j;
+ DIR *dir;
+ struct dirent *entry;
mono_once (&process_current_once, process_set_current);
-
- _wapi_search_handle (WAPI_HANDLE_PROCESS, process_enum, processes,
- NULL, TRUE);
-
+
+ dir = opendir ("/proc");
+ if (dir == NULL) {
+ return(FALSE);
+ }
+ while((entry = readdir (dir)) != NULL) {
+ if (isdigit (entry->d_name[0])) {
+ char *endptr;
+ pid_t pid = (pid_t)strtol (entry->d_name, &endptr, 10);
+
+ if (*endptr == '\0') {
+ /* Name was entirely numeric, so was a
+ * process ID
+ */
+ g_array_append_val (processes, pid);
+ }
+ }
+ }
+ closedir (dir);
+
fit=len/sizeof(guint32);
for (i = 0, j = 0; j < fit && i < processes->len; i++) {
pids[j++] = g_array_index (processes, pid_t, i);
}
}
-gpointer OpenProcess (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UNUSED, guint32 pid)
+gpointer OpenProcess (guint32 req_access G_GNUC_UNUSED, gboolean inherit G_GNUC_UNUSED, guint32 pid)
{
/* Find the process handle that corresponds to pid */
gpointer handle;
process_open_compare,
GUINT_TO_POINTER (pid), NULL, TRUE);
if (handle == 0) {
+ gchar *dir = g_strdup_printf ("/proc/%d", pid);
+ if (!access (dir, F_OK)) {
+ /* Return a pseudo handle for processes we
+ * don't have handles for
+ */
+ return((gpointer)(_WAPI_PROCESS_UNHANDLED + pid));
+ } else {
#ifdef DEBUG
- g_message ("%s: Can't find pid %d", __func__, pid);
+ g_message ("%s: Can't find pid %d", __func__, pid);
#endif
- SetLastError (ERROR_PROC_NOT_FOUND);
+ SetLastError (ERROR_PROC_NOT_FOUND);
- return(NULL);
+ return(NULL);
+ }
}
_wapi_handle_ref (handle);
return(FALSE);
}
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle, so we don't know what the
+ * exit code was
+ */
+ return(FALSE);
+ }
+
ok=_wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
(gpointer *)&process_handle);
if(ok==FALSE) {
/* A process handle is only signalled if the process has exited
* and has been waited for */
- if (_wapi_handle_issignalled (process) == TRUE ||
- process_wait (process, 0) == WAIT_OBJECT_0) {
+
+ /* Make sure any process exit has been noticed, before
+ * checking if the process is signalled. Fixes bug 325463.
+ */
+ process_wait (process, 0);
+
+ if (_wapi_handle_issignalled (process) == TRUE) {
*code = process_handle->exitstatus;
} else {
*code = STILL_ACTIVE;
return(FALSE);
}
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle, so just fail for now
+ */
+ return(FALSE);
+ }
+
ok=_wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
(gpointer *)&process_handle);
if(ok==FALSE) {
return(ret);
}
+static gboolean match_procname_to_modulename (gchar *procname, gchar *modulename)
+{
+ char* lastsep = NULL;
+
+ if (procname == NULL || modulename == NULL)
+ return (FALSE);
+
+ if (!strcmp (procname, modulename))
+ return (TRUE);
+
+ lastsep = strrchr (modulename, '/');
+ if (lastsep) {
+ if (!strcmp (lastsep+1, procname))
+ return (TRUE);
+ return (FALSE);
+ }
+
+ return (FALSE);
+}
+
gboolean EnumProcessModules (gpointer process, gpointer *modules,
guint32 size, guint32 *needed)
{
WapiProcModule *module;
guint32 count, avail = size / sizeof(gpointer);
int i;
+ pid_t pid;
+ gchar *proc_name = NULL;
/* Store modules in an array of pointers (main module as
* modules[0]), using the load address for each module as a
return(FALSE);
}
- ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
- (gpointer *)&process_handle);
- if (ok == FALSE) {
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle */
+ pid = (pid_t)(GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED_PID_MASK);
+ } else {
+ ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
+ (gpointer *)&process_handle);
+ if (ok == FALSE) {
#ifdef DEBUG
- g_message ("%s: Can't find process %p", __func__, process);
+ g_message ("%s: Can't find process %p", __func__, process);
#endif
- return(FALSE);
+ return(FALSE);
+ }
+ pid = process_handle->id;
+ proc_name = process_handle->proc_name;
}
- filename = g_strdup_printf ("/proc/%d/maps", process_handle->id);
+ filename = g_strdup_printf ("/proc/%d/maps", pid);
if ((fp = fopen (filename, "r")) == NULL) {
/* No /proc/<pid>/maps so just return the main module
* shortcut for now
*needed = sizeof(gpointer);
} else {
mods = load_modules (fp);
+ fclose (fp);
count = g_slist_length (mods);
/* count + 1 to leave slot 0 for the main module */
/* Use the NULL shortcut, as the first line in
* /proc/<pid>/maps isn't the executable, and we need
- * that first in the returned list. We'll probably
- * have a duplicate reference to the main module later
- * in the list too. FIXME if this turns out to be a
- * problem.
+ * that first in the returned list. Check the module name
+ * to see if it ends with the proc name and substitute
+ * the first entry with it. FIXME if this turns out to
+ * be a problem.
*/
modules[0] = NULL;
for (i = 0; i < (avail - 1) && i < count; i++) {
module = (WapiProcModule *)g_slist_nth_data (mods, i);
- modules[i + 1] = module->address_start;
+ if (modules[0] != NULL)
+ modules[i] = module->address_start;
+ else if (match_procname_to_modulename (proc_name, module->filename))
+ modules[0] = module->address_start;
+ else
+ modules[i + 1] = module->address_start;
}
for (i = 0; i < count; i++) {
g_slist_free (mods);
}
- fclose (fp);
g_free (filename);
return(TRUE);
}
+static gchar *get_process_name_from_proc (pid_t pid)
+{
+ gchar *filename;
+ gchar *ret = NULL;
+ gchar buf[256];
+ FILE *fp;
+
+ memset (buf, '\0', sizeof(buf));
+
+ filename = g_strdup_printf ("/proc/%d/exe", pid);
+ if (readlink (filename, buf, 255) > 0) {
+ ret = g_strdup (buf);
+ }
+ g_free (filename);
+
+ if (ret != NULL) {
+ return(ret);
+ }
+
+ filename = g_strdup_printf ("/proc/%d/cmdline", pid);
+ if ((fp = fopen (filename, "r")) != NULL) {
+ if (fgets (buf, 256, fp) != NULL) {
+ ret = g_strdup (buf);
+ }
+
+ fclose (fp);
+ }
+ g_free (filename);
+
+ if (ret != NULL) {
+ return(ret);
+ }
+
+ filename = g_strdup_printf ("/proc/%d/stat", pid);
+ if ((fp = fopen (filename, "r")) != NULL) {
+ if (fgets (buf, 256, fp) != NULL) {
+ gchar *start, *end;
+
+ start = strchr (buf, '(');
+ if (start != NULL) {
+ end = strchr (start + 1, ')');
+
+ if (end != NULL) {
+ ret = g_strndup (start + 1,
+ end - start - 1);
+ }
+ }
+ }
+
+ fclose (fp);
+ }
+ g_free (filename);
+
+ if (ret != NULL) {
+ return(ret);
+ }
+
+ return(NULL);
+}
+
static guint32 get_module_name (gpointer process, gpointer module,
gunichar2 *basename, guint32 size,
gboolean base)
WapiProcModule *found_module;
guint32 count;
int i;
+ gchar *proc_name = NULL;
mono_once (&process_current_once, process_set_current);
return(0);
}
- ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
- (gpointer *)&process_handle);
- if (ok == FALSE) {
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle */
+ pid = (pid_t)(GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED_PID_MASK);
+ proc_name = get_process_name_from_proc (pid);
+ } else {
+ ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
+ (gpointer *)&process_handle);
+ if (ok == FALSE) {
#ifdef DEBUG
- g_message ("%s: Can't find process %p", __func__, process);
+ g_message ("%s: Can't find process %p", __func__,
+ process);
#endif
-
- return(0);
+
+ return(0);
+ }
+ pid = process_handle->id;
+ proc_name = g_strdup (process_handle->proc_name);
}
- pid = process_handle->id;
- if (module == NULL) {
- /* Shorthand for the main module, which has the
- * process name recorded in the handle data
- */
-
-#ifdef DEBUG
- g_message ("%s: Returning main module name", __func__);
-#endif
-
- if (base) {
- procname_ext = g_path_get_basename (process_handle->proc_name);
+ /* Look up the address in /proc/<pid>/maps */
+ filename = g_strdup_printf ("/proc/%d/maps", pid);
+ if ((fp = fopen (filename, "r")) == NULL) {
+ if (errno == EACCES && module == NULL && base == TRUE) {
+ procname_ext = get_process_name_from_proc (pid);
} else {
- procname_ext = g_strdup (process_handle->proc_name);
- }
- } else {
- /* Look up the address in /proc/<pid>/maps */
- filename = g_strdup_printf ("/proc/%d/maps", pid);
- if ((fp = fopen (filename, "r")) == NULL) {
/* No /proc/<pid>/maps, so just return failure
* for now
*/
+ g_free (proc_name);
g_free (filename);
return(0);
- } else {
- mods = load_modules (fp);
- fclose (fp);
- count = g_slist_length (mods);
-
- for (i = 0; i < count; i++) {
- found_module = (WapiProcModule *)g_slist_nth_data (mods, i);
- if (procname_ext == NULL &&
- found_module->address_start == module) {
- if (base) {
- procname_ext = g_path_get_basename (found_module->filename);
- } else {
- procname_ext = g_strdup (found_module->filename);
- }
- }
+ }
+ } else {
+ mods = load_modules (fp);
+ fclose (fp);
+ count = g_slist_length (mods);
- free_procmodule (found_module);
+ /* If module != NULL compare the address.
+ * If module == NULL we are looking for the main module.
+ * The best we can do for now check it the module name end with the process name.
+ */
+ for (i = 0; i < count; i++) {
+ found_module = (WapiProcModule *)g_slist_nth_data (mods, i);
+ if (procname_ext == NULL &&
+ ((module == NULL && match_procname_to_modulename (proc_name, found_module->filename)) ||
+ (module != NULL && found_module->address_start == module))) {
+ if (base) {
+ procname_ext = g_path_get_basename (found_module->filename);
+ } else {
+ procname_ext = g_strdup (found_module->filename);
+ }
}
- g_slist_free (mods);
- g_free (filename);
+ free_procmodule (found_module);
}
+
+ if (procname_ext == NULL)
+ {
+ /* If it's *still* null, we might have hit the
+ * case where reading /proc/$pid/maps gives an
+ * empty file for this user.
+ */
+ procname_ext = get_process_name_from_proc (pid);
+ }
+
+ g_slist_free (mods);
+ g_free (filename);
+ g_free (proc_name);
}
if (procname_ext != NULL) {
guint32 count;
int i;
gboolean ret = FALSE;
+ gchar *proc_name = NULL;
mono_once (&process_current_once, process_set_current);
return(FALSE);
}
- ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
- (gpointer *)&process_handle);
- if (ok == FALSE) {
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle */
+ pid = (pid_t)(GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED_PID_MASK);
+ proc_name = get_process_name_from_proc (pid);
+ } else {
+ ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
+ (gpointer *)&process_handle);
+ if (ok == FALSE) {
#ifdef DEBUG
- g_message ("%s: Can't find process %p", __func__, process);
+ g_message ("%s: Can't find process %p", __func__,
+ process);
#endif
-
- return(FALSE);
+
+ return(FALSE);
+ }
+ pid = process_handle->id;
+ proc_name = g_strdup (process_handle->proc_name);
}
- pid = process_handle->id;
-
- if (module == NULL) {
- /* Shorthand for the main module, which has the
- * process name recorded in the handle data
- *
- * FIXME: try and dig through the /proc/<pid>/maps
- * list matching filename?
+
+ /* Look up the address in /proc/<pid>/maps */
+ filename = g_strdup_printf ("/proc/%d/maps", pid);
+ if ((fp = fopen (filename, "r")) == NULL) {
+ /* No /proc/<pid>/maps, so just return failure
+ * for now
*/
+ g_free (proc_name);
+ g_free (filename);
return(FALSE);
} else {
- /* Look up the address in /proc/<pid>/maps */
- filename = g_strdup_printf ("/proc/%d/maps", pid);
- if ((fp = fopen (filename, "r")) == NULL) {
- /* No /proc/<pid>/maps, so just return failure
- * for now
- */
- g_free (filename);
- return(FALSE);
- } else {
- mods = load_modules (fp);
- fclose (fp);
- count = g_slist_length (mods);
-
- for (i = 0; i < count; i++) {
- found_module = (WapiProcModule *)g_slist_nth_data (mods, i);
- if (found_module->address_start == module) {
- modinfo->lpBaseOfDll = found_module->address_start;
- modinfo->SizeOfImage = GPOINTER_TO_UINT(found_module->address_end) - GPOINTER_TO_UINT (found_module->address_start);
- modinfo->EntryPoint = found_module->address_offset;
- ret = TRUE;
- }
-
- free_procmodule (found_module);
+ mods = load_modules (fp);
+ fclose (fp);
+ count = g_slist_length (mods);
+
+ /* If module != NULL compare the address.
+ * If module == NULL we are looking for the main module.
+ * The best we can do for now check it the module name end with the process name.
+ */
+ for (i = 0; i < count; i++) {
+ found_module = (WapiProcModule *)g_slist_nth_data (mods, i);
+ if ( ret == FALSE &&
+ ((module == NULL && match_procname_to_modulename (proc_name, found_module->filename)) ||
+ (module != NULL && found_module->address_start == module))) {
+ modinfo->lpBaseOfDll = found_module->address_start;
+ modinfo->SizeOfImage = (gsize)(found_module->address_end) - (gsize)(found_module->address_start);
+ modinfo->EntryPoint = found_module->address_offset;
+ ret = TRUE;
}
-
- g_slist_free (mods);
- g_free (filename);
+
+ free_procmodule (found_module);
}
+
+ g_slist_free (mods);
+ g_free (filename);
+ g_free (proc_name);
}
-
+
return(ret);
}
return(FALSE);
}
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle, so just fail for now
+ */
+ return(FALSE);
+ }
+
ok=_wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
(gpointer *)&process_handle);
if(ok==FALSE) {
gboolean ok;
mono_once (&process_current_once, process_set_current);
+
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle, so just fail for now
+ */
+ return(FALSE);
+ }
ok=_wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
(gpointer *)&process_handle);
gboolean ok;
int signo;
int ret;
+ pid_t pid;
+
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle */
+ pid = (pid_t)(GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED_PID_MASK);
+ } else {
+ ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
+ (gpointer *) &process_handle);
- ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
- (gpointer *) &process_handle);
-
- if (ok == FALSE) {
+ if (ok == FALSE) {
#ifdef DEBUG
- g_message ("%s: Can't find process %p", __func__, process);
+ g_message ("%s: Can't find process %p", __func__,
+ process);
#endif
- SetLastError (ERROR_INVALID_HANDLE);
- return FALSE;
+ SetLastError (ERROR_INVALID_HANDLE);
+ return FALSE;
+ }
+ pid = process_handle->id;
}
signo = (exitCode == -1) ? SIGKILL : SIGTERM;
- ret = kill (process_handle->id, signo);
+ ret = kill (pid, signo);
if (ret == -1) {
switch (errno) {
case EINVAL:
struct _WapiHandle_process *process_handle;
gboolean ok;
int ret;
+ pid_t pid;
+
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle */
+ pid = (pid_t)(GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED_PID_MASK);
+ } else {
+ ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
+ (gpointer *) &process_handle);
- ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
- (gpointer *) &process_handle);
-
- if (!ok) {
- SetLastError (ERROR_INVALID_HANDLE);
- return FALSE;
+ if (!ok) {
+ SetLastError (ERROR_INVALID_HANDLE);
+ return FALSE;
+ }
+ pid = process_handle->id;
}
errno = 0;
- ret = getpriority (PRIO_PROCESS, process_handle->id);
+ ret = getpriority (PRIO_PROCESS, pid);
if (ret == -1 && errno != 0) {
switch (errno) {
case EPERM:
gboolean ok;
int ret;
int prio;
+ pid_t pid;
+
+ if ((GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
+ /* This is a pseudo handle */
+ pid = (pid_t)(GPOINTER_TO_UINT (process) & _WAPI_PROCESS_UNHANDLED_PID_MASK);
+ } else {
+ ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
+ (gpointer *) &process_handle);
- ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
- (gpointer *) &process_handle);
-
- if (!ok) {
- SetLastError (ERROR_INVALID_HANDLE);
- return FALSE;
+ if (!ok) {
+ SetLastError (ERROR_INVALID_HANDLE);
+ return FALSE;
+ }
+ pid = process_handle->id;
}
switch (priority_class) {
return FALSE;
}
- ret = setpriority (PRIO_PROCESS, process_handle->id, prio);
+ ret = setpriority (PRIO_PROCESS, pid, prio);
if (ret == -1) {
switch (errno) {
case EPERM: