[runtime] Clean up configure.ac a bit.
[mono.git] / mono / metadata / process.c
index 3d78ab49d49efa08448cd89fc7ef51ae8d82aa33..02b36b631c612ab69e00fc7ab69a382fe6d5d468 100644 (file)
@@ -20,6 +20,7 @@
 #include <mono/metadata/image.h>
 #include <mono/metadata/cil-coff.h>
 #include <mono/metadata/exception.h>
+#include <mono/metadata/threadpool-ms-io.h>
 #include <mono/utils/strenc.h>
 #include <mono/utils/mono-proclib.h>
 #include <mono/io-layer/io-layer.h>
@@ -53,11 +54,11 @@ ves_icall_System_Diagnostics_Process_GetPid_internal (void)
        return mono_process_current_pid ();
 }
 
-void ves_icall_System_Diagnostics_Process_Process_free_internal (MonoObject *this,
+void ves_icall_System_Diagnostics_Process_Process_free_internal (MonoObject *this_obj,
                                                                 HANDLE process)
 {
 #ifdef THREAD_DEBUG
-       g_message ("%s: Closing process %p, handle %p", __func__, this, process);
+       g_message ("%s: Closing process %p, handle %p", __func__, this_obj, process);
 #endif
 
 #if defined(TARGET_WIN32) || defined(HOST_WIN32)
@@ -67,9 +68,9 @@ void ves_icall_System_Diagnostics_Process_Process_free_internal (MonoObject *thi
 #endif
 }
 
-#define STASH_SYS_ASS(this) \
+#define STASH_SYS_ASS(this_obj) \
        if(system_assembly == NULL) { \
-               system_assembly=this->vtable->klass->image; \
+               system_assembly=this_obj->vtable->klass->image; \
        }
 
 static MonoImage *system_assembly=NULL;
@@ -373,20 +374,23 @@ static void process_get_assembly_fileversion (MonoObject *filever, MonoAssembly
 
 static MonoObject* get_process_module (MonoAssembly *assembly, MonoClass *proc_class)
 {
-       MonoClass *filever_class;
+       static MonoClass *filever_class = NULL;
        MonoObject *item, *filever;
        MonoDomain *domain = mono_domain_get ();
        char filename [80] = "[In Memory] ";
+       const char *modulename = assembly->aname.name;
 
-       strncat (filename, assembly->image->module_name, 80);
+       strncat (filename, modulename, 80);
 
        /* Build a System.Diagnostics.ProcessModule with the data.
         */
        item = mono_object_new (domain, proc_class);
 
-       filever_class = mono_class_from_name (system_assembly,
+       if (!filever_class)
+               filever_class = mono_class_from_name (system_assembly,
                                            "System.Diagnostics",
                                            "FileVersionInfo");
+
        filever = mono_object_new (domain, filever_class);
 
        process_get_assembly_fileversion (filever, assembly);
@@ -396,14 +400,14 @@ static MonoObject* get_process_module (MonoAssembly *assembly, MonoClass *proc_c
        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_string_char (item, "filename", filename);
-       process_set_field_string_char (item, "modulename", assembly->image->module_name);
+       process_set_field_string_char (item, "modulename", modulename);
 
        return item;
 }
 
 static MonoObject* process_add_module (HANDLE process, HMODULE mod, gunichar2 *filename, gunichar2 *modulename, MonoClass *proc_class)
 {
-       MonoClass *filever_class;
+       static MonoClass *filever_class = NULL;
        MonoObject *item, *filever;
        MonoDomain *domain=mono_domain_get ();
        MODULEINFO modinfo;
@@ -413,9 +417,11 @@ static MonoObject* process_add_module (HANDLE process, HMODULE mod, gunichar2 *f
         */
        item=mono_object_new (domain, proc_class);
 
-       filever_class=mono_class_from_name (system_assembly,
+       if (!filever_class)
+               filever_class=mono_class_from_name (system_assembly,
                                            "System.Diagnostics",
                                            "FileVersionInfo");
+
        filever=mono_object_new (domain, filever_class);
 
        process_get_fileversion (filever, filename);
@@ -464,7 +470,7 @@ static GPtrArray* get_domain_assemblies (MonoDomain *domain)
 }
 
 /* Returns an array of System.Diagnostics.ProcessModule */
-MonoArray *ves_icall_System_Diagnostics_Process_GetModules_internal (MonoObject *this, HANDLE process)
+MonoArray *ves_icall_System_Diagnostics_Process_GetModules_internal (MonoObject *this_obj, HANDLE process)
 {
        MonoArray *temp_arr = NULL;
        MonoArray *arr;
@@ -474,7 +480,7 @@ MonoArray *ves_icall_System_Diagnostics_Process_GetModules_internal (MonoObject
        DWORD needed;
        guint32 count = 0, module_count = 0, assembly_count = 0;
        guint32 i, num_added = 0;
-       MonoClass *proc_class;
+       static MonoClass *proc_class = NULL;
        GPtrArray *assemblies = NULL;
        static HANDLE current_process = 0;
        
@@ -483,7 +489,7 @@ MonoArray *ves_icall_System_Diagnostics_Process_GetModules_internal (MonoObject
                current_process = ves_icall_System_Diagnostics_Process_GetProcess_internal (pid);
        }
 
-       STASH_SYS_ASS (this);
+       STASH_SYS_ASS (this_obj);
 
        if (process == current_process) {
                assemblies = get_domain_assemblies (mono_domain_get ());
@@ -495,7 +501,9 @@ MonoArray *ves_icall_System_Diagnostics_Process_GetModules_internal (MonoObject
        }
 
        count = module_count + assembly_count; 
-       proc_class = mono_class_from_name (system_assembly, "System.Diagnostics", "ProcessModule");
+       if (!proc_class)
+               proc_class = mono_class_from_name (system_assembly, "System.Diagnostics", "ProcessModule");
+
        temp_arr = mono_array_new (mono_domain_get (), proc_class, count);
 
        for (i = 0; i < module_count; i++) {
@@ -539,12 +547,12 @@ MonoArray *ves_icall_System_Diagnostics_Process_GetModules_internal (MonoObject
        return arr;
 }
 
-void ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal (MonoObject *this, MonoString *filename)
+void ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal (MonoObject *this_obj, MonoString *filename)
 {
-       STASH_SYS_ASS (this);
+       STASH_SYS_ASS (this_obj);
        
-       process_get_fileversion (this, mono_string_chars (filename));
-       process_set_field_string (this, "filename",
+       process_get_fileversion (this_obj, mono_string_chars (filename));
+       process_set_field_string (this_obj, "filename",
                                  mono_string_chars (filename),
                                  mono_string_length (filename));
 }
@@ -655,10 +663,7 @@ MonoBoolean ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoPr
        } else {
                process_info->process_handle = shellex.hProcess;
                process_info->thread_handle = NULL;
-               /* It appears that there's no way to get the pid from a
-                * process handle before windows xp.  Really.
-                */
-#if defined(HAVE_GETPROCESSID) && !defined(MONO_CROSS_COMPILE)
+#if !defined(MONO_CROSS_COMPILE)
                process_info->pid = GetProcessId (shellex.hProcess);
 #else
                process_info->pid = 0;
@@ -795,7 +800,7 @@ MonoBoolean ves_icall_System_Diagnostics_Process_CreateProcess_internal (MonoPro
        return(ret);
 }
 
-MonoBoolean ves_icall_System_Diagnostics_Process_WaitForExit_internal (MonoObject *this, HANDLE process, gint32 ms)
+MonoBoolean ves_icall_System_Diagnostics_Process_WaitForExit_internal (MonoObject *this_obj, HANDLE process, gint32 ms)
 {
        guint32 ret;
        
@@ -815,7 +820,7 @@ MonoBoolean ves_icall_System_Diagnostics_Process_WaitForExit_internal (MonoObjec
        }
 }
 
-MonoBoolean ves_icall_System_Diagnostics_Process_WaitForInputIdle_internal (MonoObject *this, HANDLE process, gint32 ms)
+MonoBoolean ves_icall_System_Diagnostics_Process_WaitForInputIdle_internal (MonoObject *this_obj, HANDLE process, gint32 ms)
 {
        guint32 ret;
        
@@ -1069,3 +1074,9 @@ ves_icall_System_Diagnostics_Process_GetProcessData (int pid, gint32 data_type,
        return res;
 }
 
+void
+ves_icall_System_Diagnostics_Process_ProcessAsyncReader_RemoveFromIOThreadPool (HANDLE handle)
+{
+       mono_threadpool_ms_io_remove_socket (GPOINTER_TO_INT (handle));
+}
+