w32mutex-win32.c
w32semaphore-win32.c
w32event-win32.c
- w32process-win32.c
w32socket-win32.c
w32error-win32.c)
w32mutex-unix.c
w32semaphore-unix.c
w32event-unix.c
- w32process-unix.c
- w32process-unix-internals.h
w32process-unix-osx.c
w32process-unix-bsd.c
w32process-unix-haiku.c
property-bag.c
w32socket.h
w32socket-internals.h
- w32process.c
w32process.h
- w32process-internals.h
profiler.c
profiler-private.h
remoting.h
#include <mono/metadata/w32mutex.h>
#include <mono/metadata/w32semaphore.h>
#include <mono/metadata/w32event.h>
-#include <mono/metadata/w32process.h>
#include <mono/metadata/w32file.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/profiler-private.h>
mono_w32mutex_init ();
mono_w32semaphore_init ();
mono_w32event_init ();
- mono_w32process_init ();
mono_w32file_init ();
#ifndef DISABLE_PERFCOUNTERS
mono_coop_mutex_destroy (&appdomains_mutex);
- mono_w32process_cleanup ();
mono_w32file_cleanup ();
}
#include <mono/utils/mono-logger-internals.h>
#include <mono/metadata/marshal.h> /* for mono_delegate_free_ftnptr () */
#include <mono/metadata/attach.h>
-#include <mono/metadata/w32process.h>
#include <mono/utils/mono-os-semaphore.h>
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/mono-counters.h>
reference_queue_proccess_all ();
- mono_w32process_signal_finished ();
-
hazard_free_queue_pump ();
}
#include "w32event.h"
#include "w32file.h"
#include "w32mutex.h"
-#include "w32process.h"
#include "w32semaphore.h"
#include "w32socket.h"
#include "mono/utils/mono-proclib.h"
typedef MonoResolveTokenError *MonoResolveTokenError_ref;
typedef MonoType *MonoType_ref;
typedef MonoTypedRef *MonoTypedRef_ref;
-typedef MonoW32ProcessInfo *MonoW32ProcessInfo_ref;
// Maybe do this in TYPED_HANDLE_DECL.
typedef MonoArray MonoArrayOut;
#include <mono/metadata/appdomain-icalls.h>
#include <mono/metadata/string-icalls.h>
#include <mono/metadata/debug-helpers.h>
-#include <mono/metadata/w32process.h>
#include <mono/metadata/environment.h>
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/security.h>
#include <mono/metadata/image-internals.h>
#include <mono/metadata/loaded-images-internals.h>
#include <mono/metadata/metadata-update.h>
-#include <mono/metadata/w32process-internals.h>
#include <mono/metadata/debug-internals.h>
#include <mono/metadata/mono-private-unstable.h>
#include <sys/types.h>
#include <mono/metadata/verify-internals.h>
#include <mono/metadata/reflection-internals.h>
#include <mono/metadata/w32event.h>
+#include <mono/metadata/w32process.h>
#include <mono/metadata/custom-attrs-internals.h>
#include <mono/metadata/abi-details.h>
#include <mono/utils/strenc.h>
+++ /dev/null
-/**
- * \file
- */
-
-#ifndef _MONO_METADATA_W32PROCESS_INTERNALS_H_
-#define _MONO_METADATA_W32PROCESS_INTERNALS_H_
-
-#include <config.h>
-#include <glib.h>
-#include <mono/utils/w32subset.h>
-
-#ifdef HOST_WIN32
-#include <windows.h>
-#else
-typedef struct {
- guint32 dwSignature; /* Should contain 0xFEEF04BD on le machines */
- guint32 dwStrucVersion;
- guint32 dwFileVersionMS;
- guint32 dwFileVersionLS;
- guint32 dwProductVersionMS;
- guint32 dwProductVersionLS;
- guint32 dwFileFlagsMask;
- guint32 dwFileFlags;
- guint32 dwFileOS;
- guint32 dwFileType;
- guint32 dwFileSubtype;
- guint32 dwFileDateMS;
- guint32 dwFileDateLS;
-} VS_FIXEDFILEINFO;
-
-typedef struct {
- gpointer lpBaseOfDll;
- guint32 SizeOfImage;
- gpointer EntryPoint;
-} MODULEINFO;
-
-#define VS_FF_DEBUG 0x0001
-#define VS_FF_PRERELEASE 0x0002
-#define VS_FF_PATCHED 0x0004
-#define VS_FF_PRIVATEBUILD 0x0008
-#define VS_FF_INFOINFERRED 0x0010
-#define VS_FF_SPECIALBUILD 0x0020
-#endif
-
-guint32
-mono_w32process_get_pid (gpointer handle);
-
-gboolean
-mono_w32process_try_get_modules (gpointer process, gpointer *modules, guint32 size, guint32 *needed);
-
-gboolean
-mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 **str, guint32 *len);
-
-gboolean
-mono_w32process_module_get_filename (gpointer process, gpointer module, gunichar2 **str, guint32 *len);
-
-gboolean
-mono_w32process_module_get_information (gpointer process, gpointer module, gpointer modinfo, guint32 size);
-
-gboolean
-mono_w32process_get_fileversion_info (const gunichar2 *filename, gpointer *data);
-
-gboolean
-mono_w32process_ver_query_value (gconstpointer datablock, const gunichar2 *subblock, gpointer *buffer, guint32 *len);
-
-guint32
-mono_w32process_ver_language_name (guint32 lang, gunichar2 *lang_out, guint32 lang_len);
-
-#endif /* _MONO_METADATA_W32PROCESS_INTERNALS_H_ */
#endif
}
-static gint
-mono_w32process_get_modules_callback (struct dl_phdr_info *info, gsize size, gpointer ptr)
-{
- if (size < offsetof (struct dl_phdr_info, dlpi_phnum) + sizeof (info->dlpi_phnum))
- return (-1);
-
- struct dl_phdr_info *cpy = g_calloc (1, sizeof(struct dl_phdr_info));
- if (!cpy)
- return (-1);
-
- memcpy(cpy, info, sizeof(*info));
-
- g_ptr_array_add ((GPtrArray *)ptr, cpy);
-
- return (0);
-}
-
-GSList*
-mono_w32process_get_modules (pid_t pid)
-{
- GSList *ret = NULL;
- MonoW32ProcessModule *mod;
- GPtrArray *dlarray = g_ptr_array_new();
- gint i;
-
- if (dl_iterate_phdr (mono_w32process_get_modules_callback, dlarray) < 0)
- return NULL;
-
- for (i = 0; i < dlarray->len; i++) {
- struct dl_phdr_info *info = g_ptr_array_index (dlarray, i);
-
- mod = g_new0 (MonoW32ProcessModule, 1);
- mod->address_start = (gpointer)(info->dlpi_addr + info->dlpi_phdr[0].p_vaddr);
- mod->address_end = (gpointer)(info->dlpi_addr + info->dlpi_phdr[info->dlpi_phnum - 1].p_vaddr);
- mod->perms = g_strdup ("r--p");
- mod->address_offset = 0;
- mod->inode = i;
- mod->filename = g_strdup (info->dlpi_name);
-
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: inode=%d, filename=%s, address_start=%p, address_end=%p",
- __func__, mod->inode, mod->filename, mod->address_start, mod->address_end);
-
- g_free (info);
-
- if (g_slist_find_custom (ret, mod, mono_w32process_module_equals) == NULL) {
- ret = g_slist_prepend (ret, mod);
- } else {
- mono_w32process_module_free (mod);
- }
- }
-
- g_ptr_array_free (dlarray, TRUE);
-
- return g_slist_reverse (ret);
-}
-
-void
-mono_w32process_platform_init_once (void)
-{
-}
-
#else
MONO_EMPTY_SOURCE_FILE (w32process_unix_bsd);
return mono_w32process_get_name (pid);
}
-static FILE *
-open_process_map (int pid, const char *mode)
-{
- gint i;
- const gchar *proc_path[] = {
- "/proc/%d/maps", /* GNU/Linux */
- "/proc/%d/map", /* FreeBSD */
- NULL
- };
-
- for (i = 0; proc_path [i]; i++) {
- gchar *filename;
- FILE *fp;
-
- filename = g_strdup_printf (proc_path[i], pid);
- fp = fopen (filename, mode);
- g_free (filename);
-
- if (fp)
- return fp;
- }
-
- return NULL;
-}
-
-
-GSList*
-mono_w32process_get_modules (pid_t pid)
-{
-#if defined(_AIX)
- /* due to procfs, this won't work on i */
- GSList *ret = NULL;
- FILE *fp;
- MonoW32ProcessModule *mod;
- struct prmap module;
- int i;
- fpos64_t curpos;
-
- char pidpath[32]; /* "/proc/<uint64_t max>/map" plus null, rounded */
- char libpath[MAXPATHLEN + 1];
- char membername[MAXPATHLEN + 1];
- char combinedname[(MAXPATHLEN * 2) + 3]; /* lib, member, (), and nul */
-
- sprintf (pidpath, "/proc/%d/map", pid);
- if ((fp = fopen(pidpath, "r"))) {
- while (fread (&module, sizeof (module), 1, fp) == 1
- /* proc(4) declares such a struct to be the array terminator */
- && (module.pr_size != 0 && module.pr_mflags != 0)
- && (module.pr_mflags & MA_READ)) {
-
- fgetpos64 (fp, &curpos); /* save our position */
- fseeko (fp, module.pr_pathoff, SEEK_SET);
- while ((libpath[i++] = fgetc (fp)));
- i = 0;
- while ((membername[i++] = fgetc (fp)));
- i = 0;
- fsetpos64 (fp, &curpos); /* back to normal */
-
- mod = g_new0 (MonoW32ProcessModule, 1);
- mod->address_start = module.pr_vaddr;
- mod->address_end = module.pr_vaddr + module.pr_size;
- mod->address_offset = (void*)module.pr_off;
- mod->perms = g_strdup ("r--p"); /* XXX? */
-
- /* AIX has what appears to be device, channel and inode information,
- * but it's in a string. Try parsing it.
- *
- * XXX: I believe it's fstype.devno.chano.inode, but I'm uncertain
- * as to how that maps out, so I only fill in the inode (like BSD)
- */
- sscanf (module.pr_mapname, "%*[^.].%*lu.%*u.%lu", &(mod->inode));
-
- if (membername[0]) {
- snprintf(combinedname, MAXPATHLEN, "%s(%s)", libpath, membername);
- mod->filename = g_strdup (combinedname);
- } else {
- mod->filename = g_strdup (libpath);
- }
-
- if (g_slist_find_custom (ret, mod, mono_w32process_module_equals) == NULL) {
- ret = g_slist_prepend (ret, mod);
- } else {
- mono_w32process_module_free (mod);
- }
- }
- } else {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: Can't open process map file for pid %d", __func__, pid);
- return NULL;
- }
-
- if (ret)
- ret = g_slist_reverse (ret);
-
- fclose (fp);
-
- return(ret);
-#else
- GSList *ret = NULL;
- FILE *fp;
- MonoW32ProcessModule *mod;
- gchar buf[MAXPATHLEN + 1], *p, *endp;
- gchar *start_start, *end_start, *prot_start, *offset_start;
- gchar *maj_dev_start, *min_dev_start, *inode_start, prot_buf[5];
- gpointer address_start, address_end, address_offset;
- guint32 maj_dev, min_dev;
- guint64 inode;
- guint64 device;
-
- fp = open_process_map (pid, "r");
- if (!fp) {
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER_PROCESS, "%s: Can't open process map file for pid %d", __func__, pid);
- return NULL;
- }
-
- while (fgets (buf, sizeof(buf), fp)) {
- p = buf;
- while (g_ascii_isspace (*p)) ++p;
- start_start = p;
- if (!g_ascii_isxdigit (*start_start)) {
- continue;
- }
- address_start = (gpointer)strtoul (start_start, &endp, 16);
- p = endp;
- if (*p != '-') {
- continue;
- }
-
- ++p;
- end_start = p;
- if (!g_ascii_isxdigit (*end_start)) {
- continue;
- }
- address_end = (gpointer)strtoul (end_start, &endp, 16);
- p = endp;
- if (!g_ascii_isspace (*p)) {
- continue;
- }
-
- while (g_ascii_isspace (*p)) ++p;
- prot_start = p;
- if (*prot_start != 'r' && *prot_start != '-') {
- continue;
- }
- memcpy (prot_buf, prot_start, 4);
- prot_buf[4] = '\0';
- while (!g_ascii_isspace (*p)) ++p;
-
- while (g_ascii_isspace (*p)) ++p;
- offset_start = p;
- if (!g_ascii_isxdigit (*offset_start)) {
- continue;
- }
- address_offset = (gpointer)strtoul (offset_start, &endp, 16);
- p = endp;
- if (!g_ascii_isspace (*p)) {
- continue;
- }
-
- while(g_ascii_isspace (*p)) ++p;
- maj_dev_start = p;
- if (!g_ascii_isxdigit (*maj_dev_start)) {
- continue;
- }
- maj_dev = strtoul (maj_dev_start, &endp, 16);
- p = endp;
- if (*p != ':') {
- continue;
- }
-
- ++p;
- min_dev_start = p;
- if (!g_ascii_isxdigit (*min_dev_start)) {
- continue;
- }
- min_dev = strtoul (min_dev_start, &endp, 16);
- p = endp;
- if (!g_ascii_isspace (*p)) {
- continue;
- }
-
- while (g_ascii_isspace (*p)) ++p;
- inode_start = p;
- if (!g_ascii_isxdigit (*inode_start)) {
- continue;
- }
- inode = (guint64)strtol (inode_start, &endp, 10);
- p = endp;
- if (!g_ascii_isspace (*p)) {
- continue;
- }
-#if defined(MAJOR_IN_MKDEV) || defined(MAJOR_IN_SYSMACROS)
- device = makedev ((int)maj_dev, (int)min_dev);
-#else
- (void)maj_dev;
- (void)min_dev;
- device = 0;
-#endif
- if ((device == 0) && (inode == 0)) {
- continue;
- }
-
- while(g_ascii_isspace (*p)) ++p;
- /* p now points to the filename */
-
- mod = g_new0 (MonoW32ProcessModule, 1);
- mod->address_start = address_start;
- mod->address_end = address_end;
- mod->perms = g_strdup (prot_buf);
- mod->address_offset = address_offset;
- mod->device = device;
- mod->inode = inode;
- mod->filename = g_strdup (g_strstrip (p));
-
- if (g_slist_find_custom (ret, mod, mono_w32process_module_equals) == NULL) {
- ret = g_slist_prepend (ret, mod);
- } else {
- mono_w32process_module_free (mod);
- }
- }
-
- ret = g_slist_reverse (ret);
-
- fclose (fp);
-
- return(ret);
-#endif
-}
-
-void
-mono_w32process_platform_init_once (void)
-{
-}
-
#else
MONO_EMPTY_SOURCE_FILE (w32process_unix_default);
return mono_w32process_get_name (pid);
}
-GSList*
-mono_w32process_get_modules (pid_t pid)
-{
- GSList *ret = NULL;
- MonoW32ProcessModule *mod;
- gint32 cookie = 0;
- image_info imageInfo;
-
- while (get_next_image_info (B_CURRENT_TEAM, &cookie, &imageInfo) == B_OK) {
- mod = g_new0 (MonoW32ProcessModule, 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, mono_w32process_module_equals) == NULL) {
- ret = g_slist_prepend (ret, mod);
- } else {
- mono_w32process_module_free (mod);
- }
- }
-
- return g_slist_reverse (ret);
-}
-
-void
-mono_w32process_platform_init_once (void)
-{
-}
#else
#define USE_DEFAULT_BACKEND
#endif
-typedef struct {
- gpointer address_start;
- gpointer address_end;
- gchar *perms;
- gpointer address_offset;
- guint64 device;
- guint64 inode;
- gchar *filename;
-} MonoW32ProcessModule;
-
gchar*
mono_w32process_get_name (pid_t pid);
-GSList*
-mono_w32process_get_modules (pid_t pid);
-
-void
-mono_w32process_platform_init_once (void);
-
-static void G_GNUC_UNUSED
-mono_w32process_module_free (MonoW32ProcessModule *module)
-{
- g_free (module->perms);
- g_free (module->filename);
- g_free (module);
-}
-
-/*
- * Used to look through the GSList* returned by mono_w32process_get_modules
- */
-static gint G_GNUC_UNUSED
-mono_w32process_module_equals (gconstpointer a, gconstpointer b)
-{
- MonoW32ProcessModule *want = (MonoW32ProcessModule *)a;
- MonoW32ProcessModule *compare = (MonoW32ProcessModule *)b;
- return (want->device == compare->device && want->inode == compare->inode) ? 0 : 1;
-}
-
#endif /* _MONO_METADATA_W32PROCESS_UNIX_INTERNALS_H_ */
#endif
}
-struct mono_dyld_image_info
-{
- const void *header_addr;
- const void *data_section_start;
- const void *data_section_end;
- const char *name;
- guint64 order;
-};
-
-static guint64 dyld_order = 0;
-static GHashTable *images;
-static mono_mutex_t images_mutex;
-
-static int
-sort_modules_by_load_order (gconstpointer a, gconstpointer b)
-{
- MonoW32ProcessModule *ma = (MonoW32ProcessModule *) a;
- MonoW32ProcessModule *mb = (MonoW32ProcessModule *) b;
- return ma->inode == mb->inode ? 0 : ma->inode < mb->inode ? -1 : 1;
-}
-
-GSList *
-mono_w32process_get_modules (pid_t pid)
-{
- GSList *ret = NULL;
- MONO_ENTER_GC_SAFE;
- if (pid != getpid ())
- goto done;
-
- GHashTableIter it;
- g_hash_table_iter_init (&it, images);
-
- gpointer val;
-
- mono_os_mutex_lock (&images_mutex);
- while (g_hash_table_iter_next (&it, NULL, &val)) {
- struct mono_dyld_image_info *info = (struct mono_dyld_image_info *) val;
- MonoW32ProcessModule *mod = g_new0 (MonoW32ProcessModule, 1);
- mod->address_start = GINT_TO_POINTER (info->data_section_start);
- mod->address_end = GINT_TO_POINTER (info->data_section_end);
- mod->perms = g_strdup ("r--p");
- mod->address_offset = 0;
- mod->device = 0;
- mod->inode = info->order;
- mod->filename = g_strdup (info->name);
- ret = g_slist_prepend (ret, mod);
- }
- mono_os_mutex_unlock (&images_mutex);
- ret = g_slist_sort (ret, &sort_modules_by_load_order);
-done:
- MONO_EXIT_GC_SAFE;
- return ret;
-}
-
-static void
-mono_dyld_image_info_free (void *info)
-{
- struct mono_dyld_image_info *dinfo = (struct mono_dyld_image_info *) info;
- g_free ((void *) dinfo->name);
- g_free (dinfo);
-}
-
-static void
-image_added (const struct mach_header *hdr32, intptr_t vmaddr_slide)
-{
- #if SIZEOF_VOID_P == 8
- const struct mach_header_64 *hdr64 = (const struct mach_header_64 *)hdr32;
- const struct section_64 *sec = getsectbynamefromheader_64 (hdr64, SEG_DATA, SECT_DATA);
- #else
- const struct section *sec = getsectbynamefromheader (hdr32, SEG_DATA, SECT_DATA);
- #endif
- Dl_info dlinfo;
- if (!dladdr (hdr32, &dlinfo)) return;
- if (sec == NULL) return;
-
- mono_os_mutex_lock (&images_mutex);
- gpointer found = g_hash_table_lookup (images, (gpointer) hdr32);
- mono_os_mutex_unlock (&images_mutex);
-
- if (found == NULL) {
- struct mono_dyld_image_info *info = g_new0 (struct mono_dyld_image_info, 1);
- info->header_addr = hdr32;
- info->data_section_start = GINT_TO_POINTER (sec->addr);
- info->data_section_end = GINT_TO_POINTER (sec->addr + sec->size);
- info->name = g_strdup (dlinfo.dli_fname);
- info->order = dyld_order;
- ++dyld_order;
-
- mono_os_mutex_lock (&images_mutex);
- g_hash_table_insert (images, (gpointer) hdr32, info);
- mono_os_mutex_unlock (&images_mutex);
- }
-}
-
-static void
-image_removed (const struct mach_header *hdr32, intptr_t vmaddr_slide)
-{
- mono_os_mutex_lock (&images_mutex);
- g_hash_table_remove (images, hdr32);
- mono_os_mutex_unlock (&images_mutex);
-}
-
-void
-mono_w32process_platform_init_once (void)
-{
- mono_os_mutex_init (&images_mutex);
- images = g_hash_table_new_full (NULL, NULL, NULL, &mono_dyld_image_info_free);
-
- /* Ensure that the functions used within the lock-protected region in
- * mono_w32process_get_modules have been loaded, in case these symbols
- * are lazily bound. g_new0 and g_strdup will be called by
- * _dyld_register_func_for_add_image when it calls image_added with the
- * current list of all loaded dynamic libraries
- */
- GSList *dummy = g_slist_prepend (NULL, NULL);
- g_slist_free (dummy);
- GHashTableIter it;
- g_hash_table_iter_init (&it, images);
- g_hash_table_iter_next (&it, NULL, NULL);
-
- _dyld_register_func_for_add_image (&image_added);
- _dyld_register_func_for_remove_image (&image_removed);
-}
-
#else
MONO_EMPTY_SOURCE_FILE (w32process_unix_osx);
+++ /dev/null
-/**
- * \file
- * System.Diagnostics.Process support
- *
- * Author:
- * Dick Porter (dick@ximian.com)
- *
- * Copyright 2002 Ximian, Inc.
- * Copyright 2002-2006 Novell, Inc.
- * Licensed under the MIT license. See LICENSE file in the project root for full license information.
- */
-
-#include <config.h>
-#include <glib.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <pthread.h>
-#include <sched.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <signal.h>
-#include <sys/time.h>
-#include <fcntl.h>
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-#include <ctype.h>
-
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
-#endif
-
-#ifdef HAVE_SYS_MKDEV_H
-#include <sys/mkdev.h>
-#endif
-
-#ifdef HAVE_UTIME_H
-#include <utime.h>
-#endif
-
-#if defined (HAVE_FORK) && defined (HAVE_EXECVE)
-// For close_my_fds
-#if defined (_AIX)
-#include <procinfo.h>
-#elif defined (__FreeBSD__)
-#include <sys/sysctl.h>
-#include <sys/user.h>
-#include <libutil.h>
-#elif defined(__linux__)
-#include <dirent.h>
-#endif
-#endif
-
-#include <mono/metadata/object-internals.h>
-#include <mono/metadata/w32process.h>
-#include <mono/metadata/w32process-internals.h>
-#include <mono/metadata/w32process-unix-internals.h>
-#include <mono/metadata/w32error.h>
-#include <mono/metadata/class.h>
-#include <mono/metadata/class-internals.h>
-#include <mono/metadata/object.h>
-#include <mono/metadata/metadata.h>
-#include <mono/metadata/metadata-internals.h>
-#include <mono/metadata/exception.h>
-#include <mono/metadata/w32handle.h>
-#include <mono/metadata/w32file.h>
-#include <mono/utils/mono-membar.h>
-#include <mono/utils/mono-logger-internals.h>
-#include <mono/utils/strenc-internals.h>
-#include <mono/utils/strenc.h>
-#include <mono/utils/mono-proclib.h>
-#include <mono/utils/mono-path.h>
-#include <mono/utils/mono-lazy-init.h>
-#include <mono/utils/mono-signal-handler.h>
-#include <mono/utils/mono-time.h>
-#include <mono/utils/mono-mmap.h>
-#include <mono/utils/strenc.h>
-#include <mono/utils/mono-io-portability.h>
-#include <mono/utils/w32api.h>
-#include <mono/utils/mono-errno.h>
-#include <mono/utils/mono-once.h>
-#include <mono/utils/mono-error-internals.h>
-#include <mono/utils/mono-threads-coop.h>
-#include "object-internals.h"
-#include "icall-decl.h"
-
-void
-mono_w32process_init (void)
-{
-}
-
-void
-mono_w32process_cleanup (void)
-{
-}
-
-void
-mono_w32process_set_cli_launcher (gchar *path)
-{
-}
-
-void
-mono_w32process_signal_finished (void)
-{
-}
-
-guint32
-mono_w32process_ver_language_name (guint32 lang, gunichar2 *lang_out, guint32 lang_len)
-{
- return 0;
-}
-
-gboolean
-mono_w32process_get_fileversion_info (const gunichar2 *filename, gpointer *data)
-{
- return FALSE;
-}
-
-gboolean
-mono_w32process_module_get_information (gpointer handle, gpointer module, gpointer modinfo, guint32 size)
-{
- return FALSE;
-}
-
-gboolean
-mono_w32process_ver_query_value (gconstpointer datablock, const gunichar2 *subblock, gpointer *buffer, guint32 *len)
-{
- return FALSE;
-}
+++ /dev/null
-/**
- * \file
- * System.Diagnostics.Process support
- *
- * Author:
- * Dick Porter (dick@ximian.com)
- *
- * Copyright 2002 Ximian, Inc.
- * Copyright 2002-2006 Novell, Inc.
- * Licensed under the MIT license. See LICENSE file in the project root for full license information.
- */
-
-#include <config.h>
-
-#include <glib.h>
-#include <string.h>
-
-#include <winsock2.h>
-#include <windows.h>
-
-#include <mono/metadata/w32process.h>
-#include <mono/metadata/assembly.h>
-#include <mono/metadata/appdomain.h>
-#include <mono/metadata/image.h>
-#include <mono/metadata/cil-coff.h>
-#include <mono/metadata/exception.h>
-#include <mono/utils/strenc.h>
-#include <mono/utils/mono-proclib.h>
-#include <mono/metadata/w32handle.h>
-#include <mono/utils/w32api.h>
-#include <mono/utils/mono-threads-coop.h>
-#include <mono/utils/w32subset.h>
-
-void
-mono_w32process_init (void)
-{
-}
-
-void
-mono_w32process_cleanup (void)
-{
-}
-
-void
-mono_w32process_signal_finished (void)
-{
-}
-
-guint32
-mono_w32process_get_pid (gpointer handle)
-{
- return GetProcessId (handle);
-}
-
-#if HAVE_API_SUPPORT_WIN32_ENUM_WINDOWS
-typedef struct {
- DWORD pid;
- HWND hwnd;
-} EnumWindowsArgs;
-
-static BOOL CALLBACK
-mono_enum_windows_callback(HWND hwnd, LPARAM lparam)
-{
- EnumWindowsArgs *args = (EnumWindowsArgs *)lparam;
- DWORD pid = 0;
- GetWindowThreadProcessId(hwnd, &pid);
- if (pid != args->pid || GetWindow(hwnd, GW_OWNER) != NULL || !IsWindowVisible(hwnd)) return TRUE;
- args->hwnd = hwnd;
- return FALSE;
-}
-
-HANDLE
-ves_icall_System_Diagnostics_Process_MainWindowHandle_internal (guint32 pid, MonoError *error)
-{
- EnumWindowsArgs args = {pid, NULL};
- EnumWindows(mono_enum_windows_callback, (LPARAM)&args);
- return args.hwnd;
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_ENUM_WINDOWS
-HANDLE
-ves_icall_System_Diagnostics_Process_MainWindowHandle_internal (guint32 pid, MonoError *error)
-{
- /*TODO: Implement for uwp*/
- return NULL;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_ENUM_WINDOWS */
-
-#if HAVE_API_SUPPORT_WIN32_ENUM_PROCESS_MODULES
-gboolean
-mono_w32process_try_get_modules (gpointer process, gpointer *modules, guint32 size, guint32 *needed)
-{
- return EnumProcessModules (process, (HMODULE *)modules, size, (PDWORD)needed);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_ENUM_PROCESS_MODULES
-gboolean
-mono_w32process_try_get_modules (gpointer process, gpointer *modules, guint32 size, guint32 *needed)
-{
- g_unsupported_api ("EnumProcessModules");
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif
-
-#if HAVE_API_SUPPORT_WIN32_GET_MODULE_BASE_NAME
-gboolean
-mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
-{
- return mono_get_module_basename (process, module, str, len);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_GET_MODULE_BASE_NAME
-gboolean
-mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
-{
- g_unsupported_api ("GetModuleBaseName");
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
- }
-#endif /* HAVE_API_SUPPORT_WIN32_GET_MODULE_BASE_NAME */
-
-#if HAVE_API_SUPPORT_WIN32_GET_MODULE_FILE_NAME_EX
-gboolean
-mono_w32process_module_get_filename (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
-{
- return mono_get_module_filename_ex (process, module, str, len);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_GET_MODULE_FILE_NAME_EX
-gboolean
-mono_w32process_module_get_filename (gpointer process, gpointer module, gunichar2 **str, guint32 *len)
-{
- g_unsupported_api ("GetModuleFileNameEx");
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
- }
-#endif /* HAVE_API_SUPPORT_WIN32_GET_MODULE_FILE_NAME_EX */
-
-#if HAVE_API_SUPPORT_WIN32_GET_MODULE_INFORMATION
-gboolean
-mono_w32process_module_get_information (gpointer process, gpointer module, gpointer modinfo, guint32 size)
-{
- return GetModuleInformation (process, (HMODULE)module, (MODULEINFO *)modinfo, size);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_GET_MODULE_INFORMATION
-gboolean
-mono_w32process_module_get_information (gpointer process, gpointer module, gpointer modinfo, guint32 size)
-{
- g_unsupported_api ("GetModuleInformation");
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_GET_MODULE_INFORMATION */
-
-#if HAVE_API_SUPPORT_WIN32_GET_FILE_VERSION_INFO
-gboolean
-mono_w32process_get_fileversion_info (const gunichar2 *filename, gpointer *data)
-{
- DWORD handle;
-
- g_assert (data);
- *data = NULL;
-
- DWORD datasize = GetFileVersionInfoSizeW (filename, &handle);
- if (datasize <= 0)
- return FALSE;
-
- *data = g_malloc0 (datasize);
- if (!GetFileVersionInfoW (filename, handle, datasize, *data)) {
- g_free (*data);
- return FALSE;
- }
-
- return TRUE;
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_GET_FILE_VERSION_INFO
-gboolean
-mono_w32process_get_fileversion_info (const gunichar2 *filename, gpointer *data)
-{
- g_unsupported_api ("GetFileVersionInfo");
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_GET_FILE_VERSION_INFO */
-
-#if HAVE_API_SUPPORT_WIN32_VER_QUERY_VALUE
-gboolean
-mono_w32process_ver_query_value (gconstpointer datablock, const gunichar2 *subblock, gpointer *buffer, guint32 *len)
-{
- return VerQueryValueW (datablock, subblock, buffer, len);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_VER_QUERY_VALUE
-gboolean
-mono_w32process_ver_query_value (gconstpointer datablock, const gunichar2 *subblock, gpointer *buffer, guint32 *len)
-{
- g_unsupported_api ("VerQueryValue");
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_VER_QUERY_VALUE */
-
-#if HAVE_API_SUPPORT_WIN32_VER_LANGUAGE_NAME
-guint32
-mono_w32process_ver_language_name (guint32 lang, gunichar2 *lang_out, guint32 lang_len)
-{
- return VerLanguageNameW (lang, lang_out, lang_len);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_VER_LANGUAGE_NAME
-guint32
-mono_w32process_ver_language_name (guint32 lang, gunichar2 *lang_out, guint32 lang_len)
-{
- g_unsupported_api ("VerLanguageName");
- SetLastError (ERROR_NOT_SUPPORTED);
- return 0;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_VER_LANGUAGE_NAME */
-
-#if HAVE_API_SUPPORT_WIN32_OPEN_PROCESS
-HANDLE
-ves_icall_System_Diagnostics_Process_GetProcess_internal (guint32 pid, MonoError *error)
-{
- HANDLE handle;
-
- /* GetCurrentProcess returns a pseudo-handle, so use
- * OpenProcess instead
- */
- handle = OpenProcess (PROCESS_ALL_ACCESS, TRUE, pid);
- if (handle == NULL)
- /* FIXME: Throw an exception */
- return NULL;
- return handle;
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_OPEN_PROCESS
-HANDLE
-ves_icall_System_Diagnostics_Process_GetProcess_internal (guint32 pid, MonoError *error)
-{
- g_unsupported_api ("OpenProcess");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "OpenProcess");
- SetLastError (ERROR_NOT_SUPPORTED);
- return NULL;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_OPEN_PROCESS */
-
-#if HAVE_API_SUPPORT_WIN32_SHELL_EXECUTE_EX
-#include <shellapi.h>
-MonoBoolean
-ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoW32ProcessStartInfoHandle proc_start_info, MonoW32ProcessInfo *process_info, MonoError *error)
-{
- MonoCreateProcessCoop coop;
- mono_createprocess_coop_init (&coop, proc_start_info, process_info);
-
- SHELLEXECUTEINFOW shellex = {0};
- gboolean ret;
-
- shellex.cbSize = sizeof(SHELLEXECUTEINFO);
- shellex.fMask = (gulong)(SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_UNICODE);
- shellex.nShow = (gulong)MONO_HANDLE_GETVAL (proc_start_info, window_style);
- shellex.nShow = (gulong)((shellex.nShow == 0) ? 1 : (shellex.nShow == 1 ? 0 : shellex.nShow));
-
- shellex.lpFile = coop.filename;
- shellex.lpParameters = coop.arguments;
-
- if (coop.length.verb)
- shellex.lpVerb = coop.verb;
-
- if (coop.length.working_directory)
- shellex.lpDirectory = coop.working_directory;
-
- if (MONO_HANDLE_GETVAL (proc_start_info, error_dialog))
- shellex.hwnd = (HWND)MONO_HANDLE_GETVAL (proc_start_info, error_dialog_parent_handle);
- else
- shellex.fMask = (gulong)(shellex.fMask | SEE_MASK_FLAG_NO_UI);
-
- MONO_ENTER_GC_SAFE;
- ret = ShellExecuteExW (&shellex);
- MONO_EXIT_GC_SAFE;
-
- if (ret == FALSE) {
- process_info->pid = -GetLastError ();
- } else {
- process_info->process_handle = shellex.hProcess;
-#if !defined(MONO_CROSS_COMPILE)
- process_info->pid = GetProcessId (shellex.hProcess);
-#else
- process_info->pid = 0;
-#endif
- }
-
- mono_createprocess_coop_cleanup (&coop);
-
- return ret;
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_SHELL_EXECUTE_EX
-MonoBoolean
-ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoW32ProcessStartInfoHandle proc_start_info, MonoW32ProcessInfo *process_info, MonoError *error)
-{
- g_unsupported_api ("ShellExecuteEx");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "ShellExecuteEx");
- process_info->pid = (guint32)(-ERROR_NOT_SUPPORTED);
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_SHELL_EXECUTE_EX */
-
-#if HAVE_API_SUPPORT_WIN32_CREATE_PROCESS_WITH_LOGON || HAVE_API_SUPPORT_WIN32_CREATE_PROCESS
-static gboolean
-mono_process_create_process (MonoCreateProcessCoop *coop, MonoW32ProcessInfo *mono_process_info,
- MonoStringHandle cmd, guint32 creation_flags, gunichar2 *env_vars, gunichar2 *dir,
- HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle, PROCESS_INFORMATION *process_info, MonoError *error)
-{
- gboolean result = FALSE;
- MonoGCHandle cmd_gchandle = NULL;
- gunichar2 *cmd_chars = MONO_HANDLE_IS_NULL (cmd) ? NULL : mono_string_handle_pin_chars (cmd, &cmd_gchandle);
-
- STARTUPINFOW start_info={0};
-#if HAVE_API_SUPPORT_WIN32_CONSOLE
- start_info.cb = sizeof(STARTUPINFOW);
- start_info.dwFlags = STARTF_USESTDHANDLES;
- start_info.hStdInput = stdin_handle;
- start_info.hStdOutput = stdout_handle;
- start_info.hStdError = stderr_handle;
-#else
- start_info.dwFlags = 0;
- start_info.hStdInput = INVALID_HANDLE_VALUE;
- start_info.hStdOutput = INVALID_HANDLE_VALUE;
- start_info.hStdError = INVALID_HANDLE_VALUE;
-#endif /* HAVE_API_SUPPORT_WIN32_CONSOLE */
-
- MONO_ENTER_GC_SAFE;
- if (coop->username) {
-#if HAVE_API_SUPPORT_WIN32_CREATE_PROCESS_WITH_LOGON
- guint32 logon_flags = mono_process_info->load_user_profile ? LOGON_WITH_PROFILE : 0;
-
- result = CreateProcessWithLogonW (coop->username,
- coop->domain,
- mono_process_info->password,
- logon_flags,
- NULL,
- cmd_chars,
- creation_flags,
- env_vars, dir, &start_info, process_info);
-#else
- memset (process_info, 0, sizeof (PROCESS_INFORMATION));
- g_unsupported_api ("CreateProcessWithLogon");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "CreateProcessWithLogon");
- SetLastError (ERROR_NOT_SUPPORTED);
-#endif /* HAVE_API_SUPPORT_WIN32_CREATE_PROCESS_WITH_LOGON */
- } else {
-#if HAVE_API_SUPPORT_WIN32_CREATE_PROCESS
- result = CreateProcessW (NULL,
- cmd_chars,
- NULL,
- NULL,
- TRUE,
- creation_flags,
- env_vars,
- dir,
- &start_info,
- process_info);
-#else
- memset (process_info, 0, sizeof (PROCESS_INFORMATION));
- g_unsupported_api ("CreateProcess");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "CreateProcess");
- SetLastError (ERROR_NOT_SUPPORTED);
-#endif
- }
- MONO_EXIT_GC_SAFE;
-
- mono_gchandle_free_internal (cmd_gchandle);
-
- return result;
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_CREATE_PROCESS_WITH_LOGON && !HAVE_EXTERN_DEFINED_WIN32_CREATE_PROCESS
-static gboolean
-mono_process_create_process (MonoCreateProcessCoop *coop, MonoW32ProcessInfo *mono_process_info,
- MonoStringHandle cmd, guint32 creation_flags, gunichar2 *env_vars, gunichar2 *dir,
- HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle, PROCESS_INFORMATION *process_info, MonoError *error)
-{
- memset (process_info, 0, sizeof (PROCESS_INFORMATION));
- g_unsupported_api ("CreateProcessWithLogon, CreateProcess");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "CreateProcessWithLogon, CreateProcess");
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_CREATE_PROCESS_WITH_LOGON || HAVE_API_SUPPORT_WIN32_CREATE_PROCESS */
-
-static gchar*
-process_unquote_application_name (gchar *appname)
-{
- size_t len = strlen (appname);
- if (len) {
- if (appname[len-1] == '\"')
- appname[len-1] = '\0';
- if (appname[0] == '\"')
- appname++;
- }
-
- return appname;
-}
-
-static gchar*
-process_quote_path (const gchar *path)
-{
- gchar *res = g_shell_quote (path);
- gchar *q = res;
- while (*q) {
- if (*q == '\'')
- *q = '\"';
- q++;
- }
- return res;
-}
-
-/* Only used when UseShellExecute is false */
-static gchar*
-process_complete_path (const gunichar2 *appname)
-{
- // FIXME This function should stick to gunichar2.
-
- char *utf8app;
- char *utf8appmemory = NULL;
- char *result;
-
- utf8appmemory = g_utf16_to_utf8 (appname, -1, NULL, NULL, NULL);
- utf8app = process_unquote_application_name (utf8appmemory);
-
- result = process_quote_path (utf8app);
-
- g_free (utf8appmemory);
-
- return result;
-}
-
-static gboolean
-process_get_shell_arguments (MonoCreateProcessCoop *proc_start_info, MonoStringHandle *cmd, MonoError *error)
-{
- char *spath = NULL;
- char *new_cmd = NULL;
- char *cmd_utf8 = NULL;
-
- *cmd = proc_start_info->coophandle.arguments;
-
- // FIXME There are excess utf8 <=> gunichar2 conversions here.
- // We are either returning spath, or spath + " " + cmd.
- // Just use gunichar2. Maybe move logic to C#.
-
- spath = process_complete_path (proc_start_info->filename);
-
- /* Seems like our CreateProcess does not work as the windows one.
- * This hack is needed to deal with paths containing spaces */
- if (!MONO_HANDLE_IS_NULL (*cmd)) {
- cmd_utf8 = mono_string_handle_to_utf8 (*cmd, error);
- goto_if_nok (error, error);
- new_cmd = g_strdup_printf ("%s %s", spath, cmd_utf8);
- *cmd = mono_string_new_utf8_len (mono_domain_get (), new_cmd, strlen (new_cmd), error);
- goto_if_nok (error, error);
- }
- else {
- *cmd = mono_string_new_utf8_len (mono_domain_get (), spath, strlen (spath), error);
- goto_if_nok (error, error);
- }
-
-exit:
- g_free (spath);
- g_free (cmd_utf8);
- g_free (new_cmd);
- return !MONO_HANDLE_IS_NULL (*cmd);
-error:
- *cmd = NULL_HANDLE_STRING;
- goto exit;
-}
-
-MonoBoolean
-ves_icall_System_Diagnostics_Process_CreateProcess_internal (MonoW32ProcessStartInfoHandle proc_start_info,
- HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle, MonoW32ProcessInfo *process_info, MonoError *error)
-{
- MonoCreateProcessCoop coop;
- mono_createprocess_coop_init (&coop, proc_start_info, process_info);
-
- gboolean ret;
- gunichar2 *dir = NULL;
- PROCESS_INFORMATION procinfo;
- gunichar2 *env_vars = NULL;
- MonoStringHandle cmd = NULL_HANDLE_STRING;
- guint32 creation_flags;
-
- creation_flags = CREATE_UNICODE_ENVIRONMENT;
- if (MONO_HANDLE_GETVAL (proc_start_info, create_no_window))
- creation_flags |= CREATE_NO_WINDOW;
-
- if (process_get_shell_arguments (&coop, &cmd, error) == FALSE) {
- // FIXME This should be passed back separately.
- process_info->pid = -ERROR_FILE_NOT_FOUND;
- ret = FALSE;
- goto exit;
- }
-
- if (process_info->env_variables) {
- MonoArrayHandle array = MONO_HANDLE_NEW (MonoArray, process_info->env_variables);
- MonoStringHandle var = MONO_HANDLE_NEW (MonoString, NULL);
- gsize const array_length = mono_array_handle_length (array);
-
- // nul-separated and nul-terminated
- gsize len = array_length + 1 + !array_length;
-
- for (gsize i = 0; i < array_length; i++) {
- MONO_HANDLE_ARRAY_GETREF (var, array, i);
- len += mono_string_handle_length (var);
- }
-
- gunichar2 *ptr = g_new0 (gunichar2, len);
- env_vars = ptr;
-
- for (gsize i = 0; i < array_length; i++) {
- MONO_HANDLE_ARRAY_GETREF (var, array, i);
- MonoGCHandle gchandle = NULL;
- memcpy (ptr, mono_string_handle_pin_chars (var, &gchandle), mono_string_handle_length (var) * sizeof (gunichar2));
- mono_gchandle_free_internal (gchandle);
- ptr += mono_string_handle_length (var);
- ptr += 1; // Skip over the null-separator
- }
- }
-
- /* The default dir name is "". Turn that into NULL to mean
- * "current directory"
- */
- if (coop.length.working_directory)
- dir = coop.working_directory;
-
- ret = mono_process_create_process (&coop, process_info, cmd, creation_flags, env_vars, dir, stdin_handle, stdout_handle, stderr_handle, &procinfo, error);
-
- g_free (env_vars);
-
- if (ret) {
- process_info->process_handle = procinfo.hProcess;
- /*process_info->thread_handle=procinfo.hThread;*/
- if (procinfo.hThread != NULL && procinfo.hThread != INVALID_HANDLE_VALUE)
- CloseHandle (procinfo.hThread);
- process_info->pid = procinfo.dwProcessId;
- } else {
- // FIXME This should be passed back separately.
- process_info->pid = -GetLastError ();
- }
-
-exit:
- mono_createprocess_coop_cleanup (&coop);
- return ret;
-}
-
-#if HAVE_API_SUPPORT_WIN32_ENUM_PROCESSES
-MonoArrayHandle
-ves_icall_System_Diagnostics_Process_GetProcesses_internal (MonoError *error)
-{
- MonoArrayHandle procs = NULL_HANDLE_ARRAY;
- DWORD needed = 0;
- DWORD *pids = NULL;
- int count = 512;
- gboolean success;
-
- do {
- pids = g_new0 (DWORD, count);
-
- MONO_ENTER_GC_SAFE;
- success = EnumProcesses (pids, count * sizeof (DWORD), &needed);
- MONO_EXIT_GC_SAFE;
-
- if (!success)
- goto exit;
- if (needed < (count * sizeof (guint32)))
- break;
- g_free (pids);
- pids = NULL;
- count = (count * 3) / 2;
- } while (TRUE);
-
- count = needed / sizeof (guint32);
- procs = mono_array_new_handle (mono_domain_get (), mono_get_int32_class (), count, error);
- if (!is_ok (error)) {
- procs = NULL_HANDLE_ARRAY;
- goto exit;
- }
-
- MONO_ENTER_NO_SAFEPOINTS;
-
- memcpy (mono_array_addr_internal (MONO_HANDLE_RAW (procs), guint32, 0), pids, needed);
-
- MONO_EXIT_NO_SAFEPOINTS;
-
-exit:
- g_free (pids);
- return procs;
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_ENUM_PROCESSES
-MonoArrayHandle
-ves_icall_System_Diagnostics_Process_GetProcesses_internal (MonoError *error)
-{
- g_unsupported_api ("EnumProcesses");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "EnumProcesses");
- SetLastError (ERROR_NOT_SUPPORTED);
- return NULL_HANDLE_ARRAY;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_ENUM_PROCESSES */
-
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_CloseProcess (gpointer handle)
-{
- return CloseHandle (handle);
-}
-
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_TerminateProcess (gpointer handle, gint32 exitcode)
-{
- return TerminateProcess (handle, exitcode);
-}
-
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_GetExitCodeProcess (gpointer handle, gint32 *exitcode)
-{
- return GetExitCodeProcess (handle, (PDWORD)exitcode);
-}
-
-#if HAVE_API_SUPPORT_WIN32_GET_WORKING_SET_SIZE
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_GetProcessWorkingSetSize (gpointer handle, gsize *min, gsize *max)
-{
- return GetProcessWorkingSetSize (handle, (PSIZE_T)min, (PSIZE_T)max);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_GET_WORKING_SET_SIZE
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_GetProcessWorkingSetSize (gpointer handle, gsize *min, gsize *max)
-{
- ERROR_DECL (error);
- g_unsupported_api ("GetProcessWorkingSetSize");
- mono_error_set_not_supported(error, G_UNSUPPORTED_API, "GetProcessWorkingSetSize");
- mono_error_set_pending_exception (error);
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_GET_WORKING_SET_SIZE */
-
-#if HAVE_API_SUPPORT_WIN32_SET_WORKING_SET_SIZE
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_SetProcessWorkingSetSize (gpointer handle, gsize min, gsize max)
-{
- return SetProcessWorkingSetSize (handle, min, max);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_SET_WORKING_SET_SIZE
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_SetProcessWorkingSetSize (gpointer handle, gsize min, gsize max)
-{
- ERROR_DECL (error);
- g_unsupported_api ("SetProcessWorkingSetSize");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "SetProcessWorkingSetSize");
- mono_error_set_pending_exception (error);
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_SET_WORKING_SET_SIZE */
-
-#if HAVE_API_SUPPORT_WIN32_GET_PRIORITY_CLASS
-gint32
-ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass (gpointer handle)
-{
- return GetPriorityClass (handle);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_GET_PRIORITY_CLASS
-gint32
-ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass (gpointer handle)
-{
- ERROR_DECL (error);
- g_unsupported_api ("GetPriorityClass");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "GetPriorityClass");
- mono_error_set_pending_exception (error);
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_GET_PRIORITY_CLASS */
-
-#if HAVE_API_SUPPORT_WIN32_SET_PRIORITY_CLASS
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass (gpointer handle, gint32 priorityClass)
-{
- return SetPriorityClass (handle, (guint32) priorityClass);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_SET_PRIORITY_CLASS
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass (gpointer handle, gint32 priorityClass)
-{
- ERROR_DECL (error);
- g_unsupported_api ("SetPriorityClass");
- mono_error_set_not_supported(error, G_UNSUPPORTED_API, "SetPriorityClass");
- mono_error_set_pending_exception (error);
- SetLastError (ERROR_NOT_SUPPORTED);
- return FALSE;
-}
-#endif /* HAVE_API_SUPPORT_WIN32_SET_PRIORITY_CLASS */
-
-MonoBoolean
-ves_icall_Microsoft_Win32_NativeMethods_GetProcessTimes (gpointer handle, gint64 *creationtime, gint64 *exittime, gint64 *kerneltime, gint64 *usertime)
-{
- return GetProcessTimes (handle, (LPFILETIME) creationtime, (LPFILETIME) exittime, (LPFILETIME) kerneltime, (LPFILETIME) usertime);
-}
-
-gpointer
-ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcess (void)
-{
- return GetCurrentProcess ();
-}
+++ /dev/null
-/**
- * \file
- */
-
-#include <glib.h>
-
-#include "w32process.h"
-#include "w32process-internals.h"
-#include "w32file.h"
-#include "object.h"
-#include "object-internals.h"
-#include "class.h"
-#include "class-internals.h"
-#include "image.h"
-#include "utils/mono-proclib.h"
-#include "utils/w32api.h"
-#include "icall-decl.h"
-
-#define LOGDEBUG(...)
-/* define LOGDEBUG(...) g_message(__VA_ARGS__) */
-
-static MonoClass*
-get_file_version_info_class (MonoImage *system_image)
-{
- g_assert (system_image);
-
- return mono_class_load_from_name (
- system_image, "System.Diagnostics", "FileVersionInfo");
-}
-
-static MonoClass*
-get_process_module_class (MonoImage *system_image)
-{
- g_assert (system_image);
-
- return mono_class_load_from_name (
- system_image, "System.Diagnostics", "ProcessModule");
-}
-
-static void
-process_set_field_ref (MonoObjectHandle obj, const char *fieldname, MonoObjectHandle data)
-{
- // FIXME Cache offsets. Per-class.
- MonoClass *klass = mono_handle_class (obj);
- g_assert (klass);
-
- MonoClassField *field = mono_class_get_field_from_name_full (klass, fieldname, NULL);
- g_assert (field);
-
- MONO_HANDLE_SET_FIELD_REF (obj, field, data);
-}
-
-static void
-process_set_field_object (MonoObjectHandle obj, const char *fieldname, MonoObjectHandle data)
-{
- LOGDEBUG (g_message ("%s: Setting field %s to object at %p", __func__, fieldname, data));
-
- process_set_field_ref (obj, fieldname, data);
-}
-
-static void
-process_set_field_string (MonoObjectHandle obj, const char *fieldname, MonoStringHandle string)
-{
- process_set_field_ref (obj, fieldname, MONO_HANDLE_CAST (MonoObject, string));
-}
-
-static void
-process_set_field_utf16 (MonoObjectHandle obj, MonoStringHandle str, const char *fieldname, const gunichar2 *val, guint32 len, MonoError *error)
-{
- HANDLE_FUNCTION_ENTER ();
-
- LOGDEBUG (g_message ("%s: Setting field %s to [%s]", __func__, fieldname, g_utf16_to_utf8 (val, len, NULL, NULL, NULL)));
-
- MonoDomain *domain = MONO_HANDLE_DOMAIN (obj);
- g_assert (domain);
-
- MONO_HANDLE_ASSIGN (str, mono_string_new_utf16_handle (domain, val, len, error));
- goto_if_nok (error, exit);
- process_set_field_string (obj, fieldname, str);
-
-exit:
- HANDLE_FUNCTION_RETURN ();
-}
-
-static void
-process_set_field_utf8 (MonoObjectHandle obj, MonoStringHandle str, const char *fieldname, const char *val, MonoError *error)
-{
- HANDLE_FUNCTION_ENTER ();
-
- LOGDEBUG (g_message ("%s: Setting field %s to [%s]", __func__, fieldname, val));
-
- MonoDomain *domain = MONO_HANDLE_DOMAIN (obj);
- g_assert (domain);
-
- MONO_HANDLE_ASSIGN (str, mono_string_new_utf8_len (domain, val, strlen (val), error));
- goto_if_nok (error, exit);
-
- process_set_field_string (obj, fieldname, str);
-
-exit:
- HANDLE_FUNCTION_RETURN ();
-}
-
-static MonoClassField*
-process_resolve_field (MonoObjectHandle obj, const char *fieldname)
-{
- // FIXME Cache offsets. Per-class.
- MonoClass *klass = mono_handle_class (obj);
- g_assert (klass);
-
- MonoClassField *field = mono_class_get_field_from_name_full (klass, fieldname, NULL);
- g_assert (field);
-
- return field;
-}
-
-static void
-process_set_field_int (MonoObjectHandle obj, const char *fieldname, guint32 val)
-{
- LOGDEBUG (g_message ("%s: Setting field %s to %d", __func__, fieldname, val));
-
- MONO_HANDLE_SET_FIELD_VAL (obj, guint32, process_resolve_field (obj, fieldname), val);
-}
-
-static void
-process_set_field_intptr (MonoObjectHandle obj, const char *fieldname, gpointer val)
-{
- LOGDEBUG (g_message ("%s: Setting field %s to %p", __func__, fieldname, val));
-
- MONO_HANDLE_SET_FIELD_VAL (obj, gpointer, process_resolve_field (obj, fieldname), val);
-}
-
-static void
-process_set_field_bool (MonoObjectHandle obj, const char *fieldname, guint8 val)
-{
- LOGDEBUG (g_message ("%s: Setting field %s to %s", __func__, fieldname, val ? "TRUE" : "FALSE"));
-
- MONO_HANDLE_SET_FIELD_VAL (obj, guint8, process_resolve_field (obj, fieldname), val);
-}
-
-#define SFI_COMMENTS "\\StringFileInfo\\%02X%02X%02X%02X\\Comments"
-#define SFI_COMPANYNAME "\\StringFileInfo\\%02X%02X%02X%02X\\CompanyName"
-#define SFI_FILEDESCRIPTION "\\StringFileInfo\\%02X%02X%02X%02X\\FileDescription"
-#define SFI_FILEVERSION "\\StringFileInfo\\%02X%02X%02X%02X\\FileVersion"
-#define SFI_INTERNALNAME "\\StringFileInfo\\%02X%02X%02X%02X\\InternalName"
-#define SFI_LEGALCOPYRIGHT "\\StringFileInfo\\%02X%02X%02X%02X\\LegalCopyright"
-#define SFI_LEGALTRADEMARKS "\\StringFileInfo\\%02X%02X%02X%02X\\LegalTrademarks"
-#define SFI_ORIGINALFILENAME "\\StringFileInfo\\%02X%02X%02X%02X\\OriginalFilename"
-#define SFI_PRIVATEBUILD "\\StringFileInfo\\%02X%02X%02X%02X\\PrivateBuild"
-#define SFI_PRODUCTNAME "\\StringFileInfo\\%02X%02X%02X%02X\\ProductName"
-#define SFI_PRODUCTVERSION "\\StringFileInfo\\%02X%02X%02X%02X\\ProductVersion"
-#define SFI_SPECIALBUILD "\\StringFileInfo\\%02X%02X%02X%02X\\SpecialBuild"
-static const gunichar2 mono_empty_string [ ] = { 0 };
-#define EMPTY_STRING mono_empty_string
-
-typedef struct {
- const char *name;
- const char *id;
-} StringTableEntry;
-
-static const StringTableEntry stringtable_entries [] = {
- { "comments", SFI_COMMENTS },
- { "companyname", SFI_COMPANYNAME },
- { "filedescription", SFI_FILEDESCRIPTION },
- { "fileversion", SFI_FILEVERSION },
- { "internalname", SFI_INTERNALNAME },
- { "legalcopyright", SFI_LEGALCOPYRIGHT },
- { "legaltrademarks", SFI_LEGALTRADEMARKS },
- { "originalfilename", SFI_ORIGINALFILENAME },
- { "privatebuild", SFI_PRIVATEBUILD },
- { "productname", SFI_PRODUCTNAME },
- { "productversion", SFI_PRODUCTVERSION },
- { "specialbuild", SFI_SPECIALBUILD }
-};
-
-static void
-process_module_string_read (MonoObjectHandle filever, MonoStringHandle str, gpointer data, const char *fieldname,
- guchar lang_hi, guchar lang_lo, const gchar *key, MonoError *error)
-{
- char *lang_key_utf8 = NULL;
- gunichar2 *lang_key = NULL;
- const gunichar2 *buffer;
- UINT chars;
-
- lang_key_utf8 = g_strdup_printf (key, lang_lo, lang_hi, 0x04, 0xb0);
- if (!lang_key_utf8)
- goto exit;
-
- LOGDEBUG (g_message ("%s: asking for [%s]", __func__, lang_key_utf8));
-
- lang_key = g_utf8_to_utf16 (lang_key_utf8, -1, NULL, NULL, NULL);
- if (!lang_key)
- goto exit;
-
- if (mono_w32process_ver_query_value (data, lang_key, (gpointer *)&buffer, &chars) && chars > 0) {
- LOGDEBUG (g_message ("%s: found %d chars of [%s]", __func__, chars, g_utf16_to_utf8 (buffer, chars, NULL, NULL, NULL)));
- /* chars includes trailing null */
- chars -= 1;
- } else {
- buffer = EMPTY_STRING;
- chars = 0;
- }
- process_set_field_utf16 (filever, str, fieldname, buffer, chars, error);
-exit:
- g_free (lang_key);
- g_free (lang_key_utf8);
-}
-
-static void
-process_module_stringtable (MonoObjectHandle filever, MonoStringHandle str, gpointer data, guchar lang_hi, guchar lang_lo, MonoError *error)
-{
- for (int i = 0; is_ok (error) && i < G_N_ELEMENTS (stringtable_entries); ++i) {
- process_module_string_read (filever, str, data, stringtable_entries [i].name,
- lang_hi, lang_lo, stringtable_entries [i].id, error);
- }
-}
-
-#if HAVE_API_SUPPORT_WIN32_GET_FILE_VERSION_INFO
-static void
-mono_w32process_get_fileversion (MonoObjectHandle filever, MonoStringHandle str, const gunichar2 *filename, MonoError *error)
-{
- VS_FIXEDFILEINFO *ffi;
- gpointer data = NULL;
- guchar *trans_data;
- gunichar2 *query = NULL;
- UINT ffi_size, trans_size;
- gunichar2 lang_buf [128];
- guint32 lang, lang_count;
-
- if (!mono_w32process_get_fileversion_info (filename, &data))
- goto cleanup;
-
- query = g_utf8_to_utf16 ("\\", -1, NULL, NULL, NULL);
- if (query == NULL)
- goto cleanup;
-
- if (mono_w32process_ver_query_value (data, query, (gpointer *)&ffi, &ffi_size)) {
- #define MONO_LOWORD(i32) ((guint16)((i32) & 0xFFFF))
- #define MONO_HIWORD(i32) ((guint16)(((guint32)(i32) >> 16) & 0xFFFF))
-
- LOGDEBUG (g_message ("%s: recording assembly: FileName [%s] FileVersionInfo [%d.%d.%d.%d]",
- _func__, g_utf16_to_utf8 (filename, -1, NULL, NULL, NULL), MONO_HIWORD (ffi->dwFileVersionMS),
- MONO_LOWORD (ffi->dwFileVersionMS), MONO_HIWORD (ffi->dwFileVersionLS), MONO_LOWORD (ffi->dwFileVersionLS)));
-
- process_set_field_int (filever, "filemajorpart", MONO_HIWORD (ffi->dwFileVersionMS));
- process_set_field_int (filever, "fileminorpart", MONO_LOWORD (ffi->dwFileVersionMS));
- process_set_field_int (filever, "filebuildpart", MONO_HIWORD (ffi->dwFileVersionLS));
- process_set_field_int (filever, "fileprivatepart", MONO_LOWORD (ffi->dwFileVersionLS));
-
- process_set_field_int (filever, "productmajorpart", MONO_HIWORD (ffi->dwProductVersionMS));
- process_set_field_int (filever, "productminorpart", MONO_LOWORD (ffi->dwProductVersionMS));
- process_set_field_int (filever, "productbuildpart", MONO_HIWORD (ffi->dwProductVersionLS));
- process_set_field_int (filever, "productprivatepart", MONO_LOWORD (ffi->dwProductVersionLS));
-
- process_set_field_bool (filever, "isdebug", ((ffi->dwFileFlags & ffi->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
- process_set_field_bool (filever, "isprerelease", ((ffi->dwFileFlags & ffi->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
- process_set_field_bool (filever, "ispatched", ((ffi->dwFileFlags & ffi->dwFileFlagsMask) & VS_FF_PATCHED) != 0);
- process_set_field_bool (filever, "isprivatebuild", ((ffi->dwFileFlags & ffi->dwFileFlagsMask) & VS_FF_PRIVATEBUILD) != 0);
- process_set_field_bool (filever, "isspecialbuild", ((ffi->dwFileFlags & ffi->dwFileFlagsMask) & VS_FF_SPECIALBUILD) != 0);
-
- #undef MONO_LOWORD
- #undef MONO_HIWORD
- }
- g_free (query);
-
- query = g_utf8_to_utf16 ("\\VarFileInfo\\Translation", -1, NULL, NULL, NULL);
- if (query == NULL)
- goto cleanup;
-
- if (mono_w32process_ver_query_value (data, query, (gpointer *)&trans_data, &trans_size)) {
- /* use the first language ID we see */
- if (trans_size >= 4) {
- LOGDEBUG (g_message("%s: %s has 0x%0x 0x%0x 0x%0x 0x%0x", __func__, g_utf16_to_utf8 (filename, -1, NULL, NULL, NULL), trans_data[0], trans_data[1], trans_data[2], trans_data[3]));
- lang = (trans_data[0]) | (trans_data[1] << 8) | (trans_data[2] << 16) | (trans_data[3] << 24);
- /* Only give the lower 16 bits to mono_w32process_ver_language_name, as Windows gets confused otherwise */
- lang_count = mono_w32process_ver_language_name (lang & 0xFFFF, lang_buf, 128);
- if (lang_count) {
- process_set_field_utf16 (filever, str, "language", lang_buf, lang_count, error);
- goto_if_nok (error, cleanup);
- }
- process_module_stringtable (filever, str, data, trans_data [0], trans_data [1], error);
- goto_if_nok (error, cleanup);
- }
- } else {
- int i;
-
- for (i = 0; i < G_N_ELEMENTS (stringtable_entries); ++i) {
- /* No strings, so set every field to the empty string */
- process_set_field_utf16 (filever, str, stringtable_entries [i].name, EMPTY_STRING, 0, error);
- goto_if_nok (error, cleanup);
- }
-
- /* And language seems to be set to en_US according to bug 374600 */
- lang_count = mono_w32process_ver_language_name (0x0409, lang_buf, 128);
- if (lang_count) {
- process_set_field_utf16 (filever, str, "language", lang_buf, lang_count, error);
- goto_if_nok (error, cleanup);
- }
- }
-
-cleanup:
- g_free (query);
- g_free (data);
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_GET_FILE_VERSION_INFO
-static void
-mono_w32process_get_fileversion (MonoObjectHandle filever, MonoStringHandle str, const gunichar2 *filename, MonoError *error)
-{
- g_unsupported_api ("GetFileVersionInfo");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "GetFileVersionInfo");
- SetLastError (ERROR_NOT_SUPPORTED);
-}
-#endif
-
-static GPtrArray*
-get_domain_assemblies (MonoDomain *domain)
-{
- GSList *tmp;
- GPtrArray *assemblies;
-
- /*
- * Make a copy of the list of assemblies because we can't hold the assemblies
- * lock while creating objects etc.
- */
- assemblies = g_ptr_array_new ();
-
- mono_domain_assemblies_lock (domain);
-
- for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next) {
- MonoAssembly *ass = (MonoAssembly *)tmp->data;
- // TODO: the reasoning behind this check being used is unclear to me. Maybe replace with mono_domain_get_assemblies()?
- // Added in https://github.com/mono/mono/commit/46dc6758c67528fa7bc5590d1cfb4c119b69bc2b#diff-7017648b60461e8902a36d22782f4a14R451
- if (m_image_is_fileio_used (ass->image))
- continue;
- g_ptr_array_add (assemblies, ass);
- }
-
- mono_domain_assemblies_unlock (domain);
-
- return assemblies;
-}
-
-#if HAVE_API_SUPPORT_WIN32_GET_MODULE_INFORMATION
-static void
-process_add_module (MonoObjectHandle item, MonoObjectHandle filever, MonoStringHandle str,
- HANDLE process, HMODULE mod, const gunichar2 *filename, const gunichar2 *modulename,
- MonoClass *proc_class, MonoError *error)
-{
- HANDLE_FUNCTION_ENTER ();
-
- MODULEINFO modinfo;
-
- MonoDomain *domain = mono_domain_get ();
- g_assert (domain);
-
- /* Build a System.Diagnostics.ProcessModule with the data. */
- MONO_HANDLE_ASSIGN (item, mono_object_new_handle (domain, proc_class, error));
- goto_if_nok (error, exit);
-
- MONO_HANDLE_ASSIGN (filever, mono_object_new_handle (domain, get_file_version_info_class (m_class_get_image (proc_class)), error));
- goto_if_nok (error, exit);
-
- mono_w32process_get_fileversion (filever, str, filename, error);
- goto_if_nok (error, exit);
-
- process_set_field_utf16 (filever, str, "filename", filename, g_utf16_len (filename), error);
- goto_if_nok (error, exit);
-
- if (mono_w32process_module_get_information (process, mod, &modinfo, sizeof (MODULEINFO))) {
- process_set_field_intptr (item, "baseaddr", modinfo.lpBaseOfDll);
- process_set_field_intptr (item, "entryaddr", modinfo.EntryPoint);
- process_set_field_int (item, "memory_size", modinfo.SizeOfImage);
- }
-
- process_set_field_utf16 (item, str, "filename", filename, g_utf16_len (filename), error);
- goto_if_nok (error, exit);
-
- process_set_field_utf16 (item, str, "modulename", modulename, g_utf16_len (modulename), error);
- goto_if_nok (error, exit);
-
- process_set_field_object (item, "version_info", filever);
-
-exit:
- HANDLE_FUNCTION_RETURN ();
-}
-#elif !HAVE_EXTERN_DEFINED_WIN32_GET_MODULE_INFORMATION
-void
-process_add_module (MonoObjectHandle item, MonoObjectHandle filever, MonoStringHandle str,
- HANDLE process, HMODULE mod, const gunichar2 *filename, const gunichar2 *modulename,
- MonoClass *proc_class, MonoError *error)
-{
- g_unsupported_api ("GetModuleInformation");
- mono_error_set_not_supported (error, G_UNSUPPORTED_API, "GetModuleInformation");
- SetLastError (ERROR_NOT_SUPPORTED);
- return NULL;
-}
-#endif
-
-static void
-process_get_assembly_fileversion (MonoObjectHandle filever, MonoAssembly *assembly)
-{
- process_set_field_int (filever, "filemajorpart", assembly->aname.major);
- process_set_field_int (filever, "fileminorpart", assembly->aname.minor);
- process_set_field_int (filever, "filebuildpart", assembly->aname.build);
-}
-
-static void
-process_get_module (MonoObjectHandle item, MonoObjectHandle filever,
- MonoStringHandle str, MonoAssembly *assembly, MonoClass *proc_class, MonoError *error)
-{
- HANDLE_FUNCTION_ENTER ();
-
- MonoDomain *domain = mono_domain_get ();
- const char *modulename = assembly->aname.name;
- char *filename = g_strdup_printf ("[In Memory] %s", modulename);
-
- /* Build a System.Diagnostics.ProcessModule with the data. */
- MONO_HANDLE_ASSIGN (item, mono_object_new_handle (domain, proc_class, error));
- goto_if_nok (error, exit);
-
- MONO_HANDLE_ASSIGN (filever, mono_object_new_handle (domain, get_file_version_info_class (m_class_get_image (proc_class)), error));
- goto_if_nok (error, exit);
-
- process_get_assembly_fileversion (filever, assembly);
- process_set_field_utf8 (filever, str, "filename", filename, error);
- goto_if_nok (error, exit);
- process_set_field_object (item, "version_info", filever);
-
- process_set_field_intptr (item, "baseaddr", assembly->image->raw_data);
- process_set_field_int (item, "memory_size", assembly->image->raw_data_len);
- process_set_field_utf8 (item, str, "filename", filename, error);
- goto_if_nok (error, exit);
- process_set_field_utf8 (item, str, "modulename", modulename, error);
-exit:
- g_free (filename);
-
- HANDLE_FUNCTION_RETURN ();
-}
-
-gint64
-ves_icall_System_Diagnostics_Process_GetProcessData (int pid, gint32 data_type, MonoProcessError *error)
-{
- g_static_assert (sizeof (MonoProcessError) == sizeof (gint32));
- g_assert (error);
- *error = MONO_PROCESS_ERROR_NONE;
- return mono_process_get_data_with_error (GINT_TO_POINTER (pid), (MonoProcessData)data_type, error);
-}
-
-static void
-mono_pin_string (MonoStringHandle in_coophandle, MonoStringHandle *out_coophandle, gunichar2 **chars, gsize *length, MonoGCHandle *gchandle)
-{
- *out_coophandle = in_coophandle;
- if (!MONO_HANDLE_IS_NULL (in_coophandle)) {
- *chars = mono_string_handle_pin_chars (in_coophandle, gchandle);
- *length = mono_string_handle_length (in_coophandle);
- }
-}
-
-void
-mono_createprocess_coop_init (MonoCreateProcessCoop *coop, MonoW32ProcessStartInfoHandle proc_start_info, MonoW32ProcessInfo *process_info)
-{
- memset (coop, 0, sizeof (*coop));
-
-#define PIN_STRING(h, x) (mono_pin_string (h, &coop->coophandle.x, &coop->x, &coop->length.x, &coop->gchandle.x))
-
-#define PIN(x) PIN_STRING (MONO_HANDLE_NEW_GET (MonoString, proc_start_info, x), x)
- PIN (filename);
- PIN (arguments);
- PIN (working_directory);
- PIN (verb);
-#undef PIN
-#define PIN(x) PIN_STRING (MONO_HANDLE_NEW (MonoString, process_info->x), x)
- PIN (username);
- PIN (domain);
-#undef PIN
-}
-
-static void
-mono_unpin_array (MonoGCHandle *gchandles, gsize count)
-{
- for (gsize i = 0; i < count; ++i) {
- mono_gchandle_free_internal (gchandles [i]);
- gchandles [i] = 0;
- }
-}
-
-void
-mono_createprocess_coop_cleanup (MonoCreateProcessCoop *coop)
-{
- mono_unpin_array ((MonoGCHandle*)&coop->gchandle, sizeof (coop->gchandle) / sizeof (MonoGCHandle));
- memset (coop, 0, sizeof (*coop));
-}
#include <config.h>
#include <glib.h>
+#include <mono/utils/mono-compiler.h>
+
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
-#include <mono/metadata/object.h>
-#include "object-internals.h"
-#include "marshal.h"
-
-typedef enum {
- MONO_W32PROCESS_PRIORITY_CLASS_NORMAL = 0x0020,
- MONO_W32PROCESS_PRIORITY_CLASS_IDLE = 0x0040,
- MONO_W32PROCESS_PRIORITY_CLASS_HIGH = 0x0080,
- MONO_W32PROCESS_PRIORITY_CLASS_REALTIME = 0x0100,
- MONO_W32PROCESS_PRIORITY_CLASS_BELOW_NORMAL = 0x4000,
- MONO_W32PROCESS_PRIORITY_CLASS_ABOVE_NORMAL = 0x8000,
-} MonoW32ProcessPriorityClass;
-
-typedef struct
-{
- gpointer process_handle;
- guint32 pid; /* Contains mono_w32error_get_last () on failure */
- MonoArray *env_variables;
- MonoString *username;
- MonoString *domain;
- mono_bstr password; /* BSTR from SecureString in 2.0 profile */
- MonoBoolean load_user_profile;
-} MonoW32ProcessInfo;
-
-typedef struct
-{
- MonoObject object;
- MonoString *filename;
- MonoString *arguments;
- MonoString *working_directory;
- MonoString *verb;
- guint32 window_style;
- MonoBoolean error_dialog;
- gpointer error_dialog_parent_handle;
- MonoBoolean use_shell_execute;
-
- MonoString *unused_username;
- MonoString *unused_domain;
- MonoObject *unused_password; /* SecureString in 2.0 profile, dummy in 1.x */
- MonoString *unused_password_in_clear_text;
- MonoBoolean unused_load_user_profile;
- MonoBoolean unused_redirect_standard_input;
- MonoBoolean unused_redirect_standard_output;
- MonoBoolean unused_redirect_standard_error;
- MonoObject *unused_encoding_stdout;
- MonoObject *unused_encoding_stderr;
-
- MonoBoolean create_no_window;
-
- MonoObject *unused_weak_parent_process;
- MonoObject *unused_envVars;
-
-} MonoW32ProcessStartInfo;
-
-TYPED_HANDLE_DECL (MonoW32ProcessStartInfo);
-
-typedef struct _MonoCreateProcessCoop {
- gunichar2 *filename;
- gunichar2 *arguments;
- gunichar2 *working_directory;
- gunichar2 *verb;
- gunichar2 *username;
- gunichar2 *domain;
- struct {
- MonoStringHandle filename;
- MonoStringHandle arguments;
- MonoStringHandle working_directory;
- MonoStringHandle verb;
- MonoStringHandle username;
- MonoStringHandle domain;
- } coophandle;
- struct {
- MonoGCHandle filename;
- MonoGCHandle arguments;
- MonoGCHandle working_directory;
- MonoGCHandle verb;
- MonoGCHandle username;
- MonoGCHandle domain;
- } gchandle;
- struct {
- gsize filename;
- gsize arguments;
- gsize working_directory;
- gsize verb;
- gsize username;
- gsize domain;
- } length;
-} MonoCreateProcessCoop;
-
-void
-mono_createprocess_coop_init (MonoCreateProcessCoop *coop, MonoW32ProcessStartInfoHandle proc_start_info, MonoW32ProcessInfo *process_info);
-
-void
-mono_createprocess_coop_cleanup (MonoCreateProcessCoop *coop);
-
-void
-mono_w32process_init (void);
-
-void
-mono_w32process_cleanup (void);
-
-void
-mono_w32process_signal_finished (void);
-
#ifndef HOST_WIN32
-void
-mono_w32process_set_cli_launcher (gchar *path);
-
gchar*
mono_w32process_get_path (pid_t pid);
return 1;
}
-/*
- * XXX: verify if other OSes need it; many platforms seem to have it so that
- * mono_w32process_get_path -> mono_w32process_get_name, and the name is not
- * necessarily a path instead of just the program name
- */
-#if defined (_AIX)
- /*
- * mono_w32process_get_path on these can only return a name, not a path;
- * which may not be good for us if the mono command name isn't on $PATH,
- * like in CI scenarios. chances are argv based is fine if we inherited
- * the environment variables.
- */
- mono_w32process_set_cli_launcher (argv [0]);
-#elif !defined(HOST_WIN32) && defined(HAVE_UNISTD_H)
- /*
- * If we are not embedded, use the mono runtime executable to run managed exe's.
- */
- {
- char *runtime_path;
-
- runtime_path = mono_w32process_get_path (getpid ());
- if (runtime_path) {
- mono_w32process_set_cli_launcher (runtime_path);
- g_free (runtime_path);
- }
- }
-#endif
-
if (g_hasenv ("MONO_XDEBUG"))
enable_debugging = TRUE;