[System] Import System.Diagnostics.Process

This commit is contained in:
Ludovic Henry committed 2016-02-16 20:11:58 +00:00
1 parent 1a69330766
commit 00b5517dd3
15 files changed
+630 -1377

No files matched your search

@@ -0,0 +1,11 @@
namespace System
{
internal static class EnvironmentHelpers
{
internal static bool IsWindowsVistaOrAbove()
{
return true;
}
}
}
@@ -1,7 +1,208 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace Microsoft.Win32
{
static class NativeMethods
{
public const int E_ABORT = unchecked ((int)0x80004004);
}
static class NativeMethods
{
public const int E_ABORT = unchecked ((int)0x80004004);
public const int PROCESS_TERMINATE = 0x0001;
public const int PROCESS_CREATE_THREAD = 0x0002;
public const int PROCESS_SET_SESSIONID = 0x0004;
public const int PROCESS_VM_OPERATION = 0x0008;
public const int PROCESS_VM_READ = 0x0010;
public const int PROCESS_VM_WRITE = 0x0020;
public const int PROCESS_DUP_HANDLE = 0x0040;
public const int PROCESS_CREATE_PROCESS = 0x0080;
public const int PROCESS_SET_QUOTA = 0x0100;
public const int PROCESS_SET_INFORMATION = 0x0200;
public const int PROCESS_QUERY_INFORMATION = 0x0400;
public const int PROCESS_QUERY_LIMITED_INFORMATION = 0x1000;
public const int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
public const int SYNCHRONIZE = 0x00100000;
public const int PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF;
public const int DUPLICATE_CLOSE_SOURCE = 1;
public const int DUPLICATE_SAME_ACCESS = 2;
public const int STILL_ACTIVE = 0x00000103;
public const int WAIT_OBJECT_0 = 0x00000000;
public const int WAIT_FAILED = unchecked((int)0xFFFFFFFF);
public const int WAIT_TIMEOUT = 0x00000102;
public const int WAIT_ABANDONED = 0x00000080;
public const int WAIT_ABANDONED_0 = WAIT_ABANDONED;
public static bool DuplicateHandle(HandleRef hSourceProcessHandle, SafeHandle hSourceHandle, HandleRef hTargetProcess,
out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
{
bool release = false;
try {
hSourceHandle.DangerousAddRef (ref release);
MonoIOError error;
IntPtr nakedTargetHandle;
bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.DangerousGetHandle (), hTargetProcess.Handle,
out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);
if (error != MonoIOError.ERROR_SUCCESS)
throw MonoIO.GetException (error);
targetHandle = new SafeWaitHandle (nakedTargetHandle, true);
return ret;
} finally {
if (release)
hSourceHandle.DangerousRelease ();
}
}
public static bool DuplicateHandle(HandleRef hSourceProcessHandle, HandleRef hSourceHandle, HandleRef hTargetProcess,
out SafeProcessHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
{
MonoIOError error;
IntPtr nakedTargetHandle;
bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.Handle, hTargetProcess.Handle,
out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);
if (error != MonoIOError.ERROR_SUCCESS)
throw MonoIO.GetException (error);
targetHandle = new SafeProcessHandle (nakedTargetHandle, true);
return ret;
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern IntPtr GetCurrentProcess();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool GetExitCodeProcess (IntPtr processHandle, out int exitCode);
public static bool GetExitCodeProcess (SafeProcessHandle processHandle, out int exitCode)
{
bool release = false;
try {
processHandle.DangerousAddRef (ref release);
return GetExitCodeProcess (processHandle.DangerousGetHandle (), out exitCode);
} finally {
if (release)
processHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool TerminateProcess (IntPtr processHandle, int exitCode);
public static bool TerminateProcess (SafeProcessHandle processHandle, int exitCode)
{
bool release = false;
try {
processHandle.DangerousAddRef (ref release);
return TerminateProcess (processHandle.DangerousGetHandle (), exitCode);
} finally {
if (release)
processHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern int WaitForInputIdle (IntPtr handle, int milliseconds);
public static int WaitForInputIdle (SafeProcessHandle handle, int milliseconds)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return WaitForInputIdle (handle.DangerousGetHandle (), milliseconds);
} finally {
if (release)
handle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool GetProcessWorkingSetSize (IntPtr handle, out IntPtr min, out IntPtr max);
public static bool GetProcessWorkingSetSize (SafeProcessHandle handle, out IntPtr min, out IntPtr max)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return GetProcessWorkingSetSize (handle.DangerousGetHandle (), out min, out max);
} finally {
if (release)
handle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool SetProcessWorkingSetSize (IntPtr handle, IntPtr min, IntPtr max);
public static bool SetProcessWorkingSetSize (SafeProcessHandle handle, IntPtr min, IntPtr max)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return SetProcessWorkingSetSize (handle.DangerousGetHandle (), min, max);
} finally {
if (release)
handle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool GetProcessTimes (IntPtr handle, out long creation, out long exit, out long kernel, out long user);
public static bool GetProcessTimes (SafeProcessHandle handle, out long creation, out long exit, out long kernel, out long user)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return GetProcessTimes (handle.DangerousGetHandle (), out creation, out exit, out kernel, out user);
} finally {
if (release)
handle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern int GetCurrentProcessId ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern int GetPriorityClass (IntPtr handle);
public static int GetPriorityClass(SafeProcessHandle handle)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return GetPriorityClass (handle.DangerousGetHandle ());
} finally {
if (release)
handle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern bool SetPriorityClass (IntPtr handle, int priorityClass);
public static bool SetPriorityClass(SafeProcessHandle handle, int priorityClass)
{
bool release = false;
try {
handle.DangerousAddRef (ref release);
return SetPriorityClass (handle.DangerousGetHandle (), priorityClass);
} finally {
if (release)
handle.DangerousRelease ();
}
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern static bool CloseProcess (IntPtr handle);
}
}
+87
View File
@@ -926,4 +926,91 @@ public const string InvalidPathCharsInChecksum = @"The CodeChecksumPragma file n
public const string InvalidLanguageIdentifier = @"The identifier:""{0}"" on the property:""{1}"" of type:""{2}"" is not a valid language-independent identifier name. Check to see if CodeGenerator.IsValidLanguageIndependentIdentifier allows the identifier name.";
public const string InvalidTypeName = @"The type name:""{0}"" on the property:""{1}"" of type:""{2}"" is not a valid language-independent type name.";
public const string InvalidRegion = "The region directive '{0}' contains invalid characters. RegionText cannot contain any new line characters.";
public const string BadMaxWorkset = "Maximum working set size is invalid. It must be greater than or equal to the minimum working set size.";
public const string BadMinWorkset = "Minimum working set size is invalid. It must be less than or equal to the maximum working set size.";
public const string CantGetStandardError = "StandardError has not been redirected.";
public const string CantGetStandardIn = "StandardIn has not been redirected.";
public const string CantGetStandardOut = "StandardOut has not been redirected or the process hasn't started yet.";
public const string CantMixSyncAsyncOperation = "Cannot mix synchronous and asynchronous operation on process stream.";
public const string CantRedirectStreams = "The Process object must have the UseShellExecute property set to false in order to redirect IO streams.";
public const string CantStartAsUser = "The Process object must have the UseShellExecute property set to false in order to start a process as a user.";
public const string CantUseEnvVars = "The Process object must have the UseShellExecute property set to false in order to use environment variables.";
public const string EnvironmentBlockTooLong = "The environment block used to start a process cannot be longer than 65535 bytes. Your environment block is {0} bytes long. Remove some environment variables and try again.";
public const string FileNameMissing = "Cannot start process because a file name has not been provided.";
public const string InputIdleUnkownError = "WaitForInputIdle failed. This could be because the process does not have a graphical interface.";
public const string NoAssociatedProcess = "No process is associated with this object.";
public const string NoAsyncOperation = "No async read operation is in progress on the stream.";
public const string NoProcessHandle = "Process was not started by this object, so requested information cannot be determined.";
public const string NoProcessInfo = "Process has exited, so the requested information is not available.";
public const string NotSupportedRemote = "Feature is not supported for remote machines.";
public const string PendingAsyncOperation = "An async read operation has already been started on the stream.";
public const string PriorityClassNotSupported = "The AboveNormal and BelowNormal priority classes are not available on this platform.";
public const string ProcessArguments = "Command line arguments that will be passed to the application specified by the FileName property.";
public const string ProcessAssociated = "Indicates if the process component is associated with a real process.";
public const string ProcessBasePriority = "The base priority computed based on the priority class that all threads run relative to.";
public const string ProcessCreateNoWindow = "Whether to start the process without creating a new window to contain it.";
public const string ProcessDesc = "Provides access to local and remote processes, enabling starting and stopping of local processes.";
public const string ProcessEnableRaisingEvents = "Whether the process component should watch for the associated process to exit, and raise the Exited event.";
public const string ProcessEnvironmentVariables = "Set of environment variables that apply to this process and child processes.";
public const string ProcessErrorDialog = "Whether to show an error dialog to the user if there is an error.";
public const string ProcessExitCode = "The value returned from the associated process when it terminated.";
public const string ProcessExited = "If the WatchForExit property is set to true, then this event is raised when the associated process exits.";
public const string ProcessExitTime = "The time that the associated process exited.";
public const string ProcessFileName = "The name of the application, document or URL to start.";
public const string ProcessHandle = "Returns the native handle for this process. The handle is only available if the process was started using this component.";
public const string ProcessHandleCount = "The number of native handles associated with this process.";
public const string ProcessHasExited = "Cannot process request because the process ({0}) has exited.";
public const string ProcessHasExitedNoId = "Cannot process request because the process has exited.";
public const string ProcessId = "The unique identifier for the process.";
public const string ProcessIdRequired = "Feature requires a process identifier.";
public const string ProcessMachineName = "The name of the machine the running the process.";
public const string ProcessMainModule = "The main module for the associated process.";
public const string ProcessMainWindowHandle = "The handle of the main window for the process.";
public const string ProcessMainWindowTitle = "The caption of the main window for the process.";
public const string ProcessMaxWorkingSet = "The maximum amount of physical memory the process has required since it was started.";
public const string ProcessMinWorkingSet = "The minimum amount of physical memory the process has required since it was started.";
public const string ProcessModules = "The modules that have been loaded by the associated process.";
public const string ProcessNonpagedSystemMemorySize = "The number of bytes of non pageable system memory the process is using.";
public const string ProcessPagedMemorySize = "The current amount of memory that can be paged to disk that the process is using.";
public const string ProcessPagedSystemMemorySize = "The number of bytes of pageable system memory the process is using.";
public const string ProcessPeakPagedMemorySize = "The maximum amount of memory that can be paged to disk that the process has used since it was started.";
public const string ProcessPeakVirtualMemorySize = "The maximum amount of virtual memory the process has allocated since it was started.";
public const string ProcessPeakWorkingSet = "The maximum amount of physical memory the process has used since it was started.";
public const string ProcessPriorityBoostEnabled = "Whether this process would like a priority boost when the user interacts with it.";
public const string ProcessPriorityClass = "The priority that the threads in the process run relative to.";
public const string ProcessPrivateMemorySize = "The current amount of memory that the process has allocated that cannot be shared with other processes.";
public const string ProcessPrivilegedProcessorTime = "The amount of CPU time the process spent inside the operating system core.";
public const string ProcessProcessName = "The name of the process.";
public const string ProcessProcessorAffinity = "A bit mask which represents the processors that the threads within the process are allowed to run on.";
public const string ProcessRedirectStandardError = "Whether the process's error output is written to the Process instance's StandardError member.";
public const string ProcessRedirectStandardInput = "Whether the process command input is read from the Process instance's StandardInput member.";
public const string ProcessRedirectStandardOutput = "Whether the process output is written to the Process instance's StandardOutput member.";
public const string ProcessResponding = "Whether this process is currently responding.";
public const string ProcessSessionId = "The identifier for the session of the process.";
public const string ProcessStandardError = "Standard error stream of the process.";
public const string ProcessStandardInput = "Standard input stream of the process.";
public const string ProcessStandardOutput = "Standard output stream of the process.";
public const string ProcessStartInfo = "Specifies information used to start a process.";
public const string ProcessStartTime = "The time at which the process was started.";
public const string ProcessSynchronizingObject = "The object used to marshal the event handler calls issued as a result of a Process exit.";
public const string ProcessTerminated = "Indicates if the associated process has been terminated.";
public const string ProcessThreads = "The threads running in the associated process.";
public const string ProcessTotalProcessorTime = "The amount of CPU time the process has used.";
public const string ProcessUserProcessorTime = "The amount of CPU time the process spent outside the operating system core.";
public const string ProcessUseShellExecute = "Whether to use the operating system shell to start the process.";
public const string ProcessVerb = "The verb to apply to the document specified by the FileName property.";
public const string ProcessVirtualMemorySize = "The amount of virtual memory the process has currently allocated.";
public const string ProcessWindowStyle = "How the main window should be created when the process starts.";
public const string ProcessWorkingDirectory = "The initial working directory for the process.";
public const string ProcessWorkingSet = "The current amount of physical memory the process is using.";
public const string ProcModBaseAddress = "The memory address that the module loaded at.";
public const string ProcModEntryPointAddress = "The memory address of the function that runs when the module is loaded.";
public const string ProcModFileName = "The file name of the module.";
public const string ProcModModuleMemorySize = "The amount of virtual memory required by the code and data in the module file.";
public const string ProcModModuleName = "The name of the module.";
public const string StandardErrorEncodingNotAllowed = "StandardErrorEncoding is only supported when standard error is redirected.";
public const string StandardOutputEncodingNotAllowed = "StandardOutputEncoding is only supported when standard output is redirected.";
public const string WaitTillExit = "Process must exit before requested information can be determined.";
public const string Win2kRequired = "Feature requires Windows 2000.";
}
File diff suppressed because it is too large. Load diff
@@ -41,204 +41,11 @@ using System.Runtime.InteropServices;
namespace System.Diagnostics
{
[TypeConverter (typeof (ExpandableObjectConverter))]
[PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
[StructLayout (LayoutKind.Sequential)]
public sealed class ProcessStartInfo
public sealed partial class ProcessStartInfo
{
/* keep these fields in this order and in sync with metadata/process.h */
private string arguments;
private IntPtr error_dialog_parent_handle = (IntPtr)0;
private string filename;
private string verb;
private string working_directory;
private StringDictionary envVars;
private bool create_no_window = false;
private bool error_dialog = false;
private bool redirect_standard_error = false;
private bool redirect_standard_input = false;
private bool redirect_standard_output = false;
private bool use_shell_execute = true;
private ProcessWindowStyle window_style = ProcessWindowStyle.Normal;
private Encoding encoding_stderr, encoding_stdout;
private string username, domain;
private SecureString password;
private bool load_user_profile;
public ProcessStartInfo()
{
}
public ProcessStartInfo(string filename)
{
this.filename = filename;
}
public ProcessStartInfo(string filename, string arguments)
{
this.filename = filename;
this.arguments = arguments;
}
[RecommendedAsConfigurable (true), DefaultValue ("")]
[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
[MonitoringDescription ("Command line agruments for this process.")]
[NotifyParentPropertyAttribute (true)]
public string Arguments {
get {
return arguments ?? string.Empty;
}
set {
arguments = value;
}
}
[DefaultValue (false)]
[MonitoringDescription ("Start this process with a new window.")]
[NotifyParentPropertyAttribute (true)]
public bool CreateNoWindow {
get {
return(create_no_window);
}
set {
create_no_window = value;
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content), DefaultValue (null)]
[Editor ("System.Diagnostics.Design.StringDictionaryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
[MonitoringDescription ("Environment variables used for this process.")]
[NotifyParentPropertyAttribute (true)]
public StringDictionary EnvironmentVariables {
get {
if (envVars == null) {
// check for non-Unix platforms - see FAQ for more details
// http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
int platform = (int) Environment.OSVersion.Platform;
if ((platform != 4) && (platform != 128)) {
envVars = new StringDictionary ();
} else {
envVars = new CaseSensitiveStringDictionary ();
}
foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables ())
envVars.Add ((string) entry.Key, (string) entry.Value);
}
return envVars;
}
}
internal bool HaveEnvVars {
get { return (envVars != null); }
}
[DefaultValue (false)]
[MonitoringDescription ("Thread shows dialogboxes for errors.")]
[NotifyParentPropertyAttribute (true)]
public bool ErrorDialog {
get {
return(error_dialog);
}
set {
error_dialog = value;
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
public IntPtr ErrorDialogParentHandle {
get {
return(error_dialog_parent_handle);
}
set {
error_dialog_parent_handle = value;
}
}
[RecommendedAsConfigurable (true), DefaultValue ("")]
[Editor ("System.Diagnostics.Design.StartFileNameEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
[MonitoringDescription ("The name of the resource to start this process.")]
[NotifyParentPropertyAttribute (true)]
public string FileName {
get {
return filename ?? string.Empty;
}
set {
filename = value;
}
}
[DefaultValue (false)]
[MonitoringDescription ("Errors of this process are redirected.")]
[NotifyParentPropertyAttribute (true)]
public bool RedirectStandardError {
get {
return(redirect_standard_error);
}
set {
redirect_standard_error = value;
}
}
[DefaultValue (false)]
[MonitoringDescription ("Standard input of this process is redirected.")]
[NotifyParentPropertyAttribute (true)]
public bool RedirectStandardInput {
get {
return(redirect_standard_input);
}
set {
redirect_standard_input = value;
}
}
[DefaultValue (false)]
[MonitoringDescription ("Standard output of this process is redirected.")]
[NotifyParentPropertyAttribute (true)]
public bool RedirectStandardOutput {
get {
return(redirect_standard_output);
}
set {
redirect_standard_output = value;
}
}
public Encoding StandardErrorEncoding {
get { return encoding_stderr; }
set { encoding_stderr = value; }
}
public Encoding StandardOutputEncoding {
get { return encoding_stdout; }
set { encoding_stdout = value; }
}
[DefaultValue (true)]
[MonitoringDescription ("Use the shell to start this process.")]
[NotifyParentPropertyAttribute (true)]
public bool UseShellExecute {
get {
return(use_shell_execute);
}
set {
use_shell_execute = value;
}
}
[DefaultValue ("")]
[TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
[MonitoringDescription ("The verb to apply to a used document.")]
[NotifyParentPropertyAttribute (true)]
public string Verb {
get {
return verb ?? string.Empty;
}
set {
verb = value;
}
get { return (environmentVariables != null); }
}
static readonly string [] empty = new string [0];
@@ -249,14 +56,13 @@ namespace System.Diagnostics
#if MOBILE
return empty;
#else
switch (Environment.OSVersion.Platform) {
switch (System.Environment.OSVersion.Platform) {
case (PlatformID)4:
case (PlatformID)6:
case (PlatformID)128:
return empty; // no verb on non-Windows
default:
string ext = filename == null | filename.Length == 0 ?
null : Path.GetExtension (filename);
string ext = String.IsNullOrEmpty (fileName) ? null : Path.GetExtension (fileName);
if (ext == null)
return empty;
@@ -279,54 +85,5 @@ namespace System.Diagnostics
#endif
}
}
[DefaultValue (typeof (ProcessWindowStyle), "Normal")]
[MonitoringDescription ("The window style used to start this process.")]
[NotifyParentPropertyAttribute (true)]
public ProcessWindowStyle WindowStyle {
get {
return(window_style);
}
set {
window_style = value;
}
}
[RecommendedAsConfigurable (true), DefaultValue ("")]
[Editor ("System.Diagnostics.Design.WorkingDirectoryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
[MonitoringDescription ("The initial directory for this process.")]
[NotifyParentPropertyAttribute (true)]
public string WorkingDirectory {
get {
return working_directory ?? string.Empty;
}
set {
working_directory = value;
}
}
[NotifyParentPropertyAttribute (true)]
public bool LoadUserProfile {
get { return load_user_profile; }
set { load_user_profile = value; }
}
[NotifyParentPropertyAttribute (true)]
public string UserName {
get { return username ?? string.Empty; }
set { username = value; }
}
[NotifyParentPropertyAttribute (true)]
public string Domain {
get { return domain ?? string.Empty; }
set { domain = value; }
}
public SecureString Password {
get { return password; }
set { password = value; }
}
}
}
+6
View File
@@ -640,6 +640,7 @@ Mono.Net.Security/SystemCertificateValidator.cs
ReferenceSources/AssertWrapper.cs
ReferenceSources/BinaryCompatibility.cs
ReferenceSources/ConfigurationManagerInternalFactory.cs
ReferenceSources/EnvironmentHelpers.cs
ReferenceSources/Internal.cs
ReferenceSources/HttpSysSettings.cs
ReferenceSources/Logging.cs
@@ -1178,3 +1179,8 @@ ReferenceSources/_SslStream.cs
../../../external/referencesource/System/compmod/system/codedom/compiler/LanguageOptions.cs
../../../external/referencesource/System/services/monitoring/system/diagnosticts/AsyncStreamReader.cs
../../../external/referencesource/System/services/monitoring/system/diagnosticts/Process.cs
../../../external/referencesource/System/services/monitoring/system/diagnosticts/ProcessStartInfo.cs
../../../external/referencesource/System/services/monitoring/system/diagnosticts/processwaithandle.cs
../../../external/referencesource/System/compmod/microsoft/win32/safehandles/SafeProcessHandle.cs
@@ -855,9 +855,9 @@ namespace MonoTests.System.Diagnostics
p.EnableRaisingEvents = false;
var exitedCalledCounter = 0;
ManualResetEvent mre = new ManualResetEvent (false);
p.Exited += (object sender, EventArgs e) => {
exitedCalledCounter++;
mre.Set ();
};
p.Start ();
@@ -865,7 +865,7 @@ namespace MonoTests.System.Diagnostics
p.BeginOutputReadLine ();
p.WaitForExit ();
Assert.AreEqual (0, exitedCalledCounter);
Assert.IsFalse (mre.WaitOne (1000));
}
ProcessStartInfo GetCrossPlatformStartInfo ()
@@ -0,0 +1,15 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace Microsoft.Win32
{
static class NativeMethods
{
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern int GetCurrentProcessId ();
}
}
+1
View File
@@ -907,6 +907,7 @@ ReferenceSources/TypeNameParser.cs
ReferenceSources/RuntimeType.cs
ReferenceSources/RemotingFieldCachedData.cs
ReferenceSources/MethodBase.cs
ReferenceSources/NativeMethods.cs
ReferenceSources/RuntimeHandles.cs
ReferenceSources/CompareInfo.cs
ReferenceSources/TypeBuilderInstantiation.cs
+23 -1
View File
@@ -2754,7 +2754,29 @@ process_wait (gpointer handle, guint32 timeout, gboolean alertable)
/* We don't need to lock mono_processes here, the entry
* has a handle_count > 0 which means it will not be freed. */
mp = process_handle->mono_process;
g_assert (mp);
if (!mp) {
pid_t res;
/* This path is used when calling Process.HasExited, so
* it is only used to poll the state of the process, not
* to actually wait on it to exit */
g_assert (timeout == 0);
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s (%p, %u): waiting on non-child process", __func__, handle, timeout);
res = waitpid (pid, &status, WNOHANG);
if (res == 0) {
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s (%p, %u): non-child process WAIT_TIMEOUT", __func__, handle, timeout);
return WAIT_TIMEOUT;
}
if (res > 0) {
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s (%p, %u): non-child process waited successfully", __func__, handle, timeout);
return WAIT_OBJECT_0;
}
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s (%p, %u): non-child process WAIT_FAILED, error : %s (%d))", __func__, handle, timeout, g_strerror (errno), errno);
return WAIT_FAILED;
}
start = mono_msec_ticks ();
now = start;
+16 -19
View File
@@ -37,6 +37,21 @@
* declaration if you add a new icall at the beginning of a type's icall list.
*/
#ifndef DISABLE_PROCESS_HANDLING
ICALL_TYPE(NATIVEMETHODS, "Microsoft.Win32.NativeMethods", NATIVEMETHODS_1)
ICALL(NATIVEMETHODS_1, "CloseProcess", ves_icall_Microsoft_Win32_NativeMethods_CloseProcess)
ICALL(NATIVEMETHODS_2, "GetCurrentProcess", ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcess)
ICALL(NATIVEMETHODS_3, "GetCurrentProcessId", ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcessId)
ICALL(NATIVEMETHODS_4, "GetExitCodeProcess", ves_icall_Microsoft_Win32_NativeMethods_GetExitCodeProcess)
ICALL(NATIVEMETHODS_5, "GetPriorityClass", ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass)
ICALL(NATIVEMETHODS_6, "GetProcessTimes", ves_icall_Microsoft_Win32_NativeMethods_GetProcessTimes)
ICALL(NATIVEMETHODS_7, "GetProcessWorkingSetSize", ves_icall_Microsoft_Win32_NativeMethods_GetProcessWorkingSetSize)
ICALL(NATIVEMETHODS_8, "SetPriorityClass", ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass)
ICALL(NATIVEMETHODS_9, "SetProcessWorkingSetSize", ves_icall_Microsoft_Win32_NativeMethods_SetProcessWorkingSetSize)
ICALL(NATIVEMETHODS_10, "TerminateProcess", ves_icall_Microsoft_Win32_NativeMethods_TerminateProcess)
ICALL(NATIVEMETHODS_11, "WaitForInputIdle", ves_icall_Microsoft_Win32_NativeMethods_WaitForInputIdle)
#endif /* !DISABLE_PROCESS_HANDLING */
#ifndef DISABLE_COM
ICALL_TYPE(COMPROX, "Mono.Interop.ComInteropProxy", COMPROX_1)
ICALL(COMPROX_1, "AddProxy", ves_icall_Mono_Interop_ComInteropProxy_AddProxy)
@@ -187,29 +202,12 @@ ICALL(PERFCTRCAT_8, "InstanceExistsInternal", mono_perfcounter_instance_exists)
ICALL_TYPE(PROCESS, "System.Diagnostics.Process", PROCESS_1)
ICALL(PROCESS_1, "CreateProcess_internal(System.Diagnostics.ProcessStartInfo,intptr,intptr,intptr,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_CreateProcess_internal)
ICALL(PROCESS_2, "ExitCode_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitCode_internal)
ICALL(PROCESS_3, "ExitTime_internal(intptr)", ves_icall_System_Diagnostics_Process_ExitTime_internal)
ICALL(PROCESS_4, "GetModules_internal(intptr)", ves_icall_System_Diagnostics_Process_GetModules_internal)
ICALL(PROCESS_5, "GetPid_internal()", ves_icall_System_Diagnostics_Process_GetPid_internal)
ICALL(PROCESS_5B, "GetPriorityClass(intptr,int&)", ves_icall_System_Diagnostics_Process_GetPriorityClass)
ICALL(PROCESS_5H, "GetProcessData", ves_icall_System_Diagnostics_Process_GetProcessData)
ICALL(PROCESS_6, "GetProcess_internal(int)", ves_icall_System_Diagnostics_Process_GetProcess_internal)
ICALL(PROCESS_7, "GetProcesses_internal()", ves_icall_System_Diagnostics_Process_GetProcesses_internal)
ICALL(PROCESS_8, "GetWorkingSet_internal(intptr,int&,int&)", ves_icall_System_Diagnostics_Process_GetWorkingSet_internal)
ICALL(PROCESS_9, "Kill_internal", ves_icall_System_Diagnostics_Process_Kill_internal)
ICALL(PROCESS_10, "ProcessName_internal(intptr)", ves_icall_System_Diagnostics_Process_ProcessName_internal)
ICALL(PROCESS_11, "Process_free_internal(intptr)", ves_icall_System_Diagnostics_Process_Process_free_internal)
ICALL(PROCESS_11B, "SetPriorityClass(intptr,int,int&)", ves_icall_System_Diagnostics_Process_SetPriorityClass)
ICALL(PROCESS_12, "SetWorkingSet_internal(intptr,int,int,bool)", ves_icall_System_Diagnostics_Process_SetWorkingSet_internal)
ICALL(PROCESS_13, "ShellExecuteEx_internal(System.Diagnostics.ProcessStartInfo,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal)
ICALL(PROCESS_14, "StartTime_internal(intptr)", ves_icall_System_Diagnostics_Process_StartTime_internal)
ICALL(PROCESS_14M, "Times", ves_icall_System_Diagnostics_Process_Times)
ICALL(PROCESS_15, "WaitForExit_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForExit_internal)
ICALL(PROCESS_16, "WaitForInputIdle_internal(intptr,int)", ves_icall_System_Diagnostics_Process_WaitForInputIdle_internal)
ICALL_TYPE (PROCESSHANDLE, "System.Diagnostics.Process/ProcessWaitHandle", PROCESSHANDLE_1)
ICALL (PROCESSHANDLE_1, "ProcessHandle_close(intptr)", ves_icall_System_Diagnostics_Process_ProcessHandle_close)
ICALL (PROCESSHANDLE_2, "ProcessHandle_duplicate(intptr)", ves_icall_System_Diagnostics_Process_ProcessHandle_duplicate)
#endif /* !DISABLE_PROCESS_HANDLING */
ICALL_TYPE(SFRAME, "System.Diagnostics.StackFrame", SFRAME_1)
@@ -728,8 +726,7 @@ ICALL(REMSER_2, "IsTransparentProxy", ves_icall_IsTransparentProxy)
#endif
ICALL_TYPE(RVH, "System.Runtime.Versioning.VersioningHelper", RVH_1)
ICALL(RVH_1, "GetCurrentProcessId", ves_icall_System_Diagnostics_Process_GetPid_internal)
ICALL(RVH_2, "GetRuntimeId", ves_icall_System_Runtime_Versioning_VersioningHelper_GetRuntimeId)
ICALL(RVH_1, "GetRuntimeId", ves_icall_System_Runtime_Versioning_VersioningHelper_GetRuntimeId)
ICALL_TYPE(RFH, "System.RuntimeFieldHandle", RFH_1)
ICALL(RFH_1, "SetValueDirect", ves_icall_System_RuntimeFieldHandle_SetValueDirect)
+70
View File
@@ -7806,6 +7806,76 @@ ves_icall_System_StackFrame_GetILOffsetFromFile (MonoString *path, guint32 metho
return il_offset;
}
ICALL_EXPORT gpointer
ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcess (void)
{
return GetCurrentProcess ();
}
ICALL_EXPORT MonoBoolean
ves_icall_Microsoft_Win32_NativeMethods_GetExitCodeProcess (gpointer handle, gint32 *exitcode)
{
return GetExitCodeProcess (handle, (guint32*) exitcode);
}
ICALL_EXPORT MonoBoolean
ves_icall_Microsoft_Win32_NativeMethods_CloseProcess (gpointer handle)
{
#if defined(TARGET_WIN32) || defined(HOST_WIN32)
return CloseHandle (handle);
#else
return CloseProcess (handle);
#endif
}
ICALL_EXPORT MonoBoolean
ves_icall_Microsoft_Win32_NativeMethods_TerminateProcess (gpointer handle, gint32 exitcode)
{
return TerminateProcess (handle, exitcode);
}
ICALL_EXPORT gint32
ves_icall_Microsoft_Win32_NativeMethods_WaitForInputIdle (gpointer handle, gint32 milliseconds)
{
return WaitForInputIdle (handle, milliseconds);
}
ICALL_EXPORT MonoBoolean
ves_icall_Microsoft_Win32_NativeMethods_GetProcessWorkingSetSize (gpointer handle, gsize *min, gsize *max)
{
return GetProcessWorkingSetSize (handle, min, max);
}
ICALL_EXPORT MonoBoolean
ves_icall_Microsoft_Win32_NativeMethods_SetProcessWorkingSetSize (gpointer handle, gsize min, gsize max)
{
return SetProcessWorkingSetSize (handle, min, max);
}
ICALL_EXPORT 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);
}
ICALL_EXPORT gint32
ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcessId (void)
{
return mono_process_current_pid ();
}
ICALL_EXPORT gint32
ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass (gpointer handle)
{
return GetPriorityClass (handle);
}
ICALL_EXPORT MonoBoolean
ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass (gpointer handle, gint32 priorityClass)
{
return SetPriorityClass (handle, priorityClass);
}
#ifndef DISABLE_ICALL_TABLES
#define ICALL_TYPE(id,name,first)
-195
View File
@@ -51,26 +51,6 @@ HANDLE ves_icall_System_Diagnostics_Process_GetProcess_internal (guint32 pid)
return(handle);
}
guint32
ves_icall_System_Diagnostics_Process_GetPid_internal (void)
{
return mono_process_current_pid ();
}
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_obj, process);
#endif
#if defined(TARGET_WIN32) || defined(HOST_WIN32)
CloseHandle (process);
#else
CloseProcess (process);
#endif
}
#define STASH_SYS_ASS(this_obj) \
if(system_assembly == NULL) { \
system_assembly=this_obj->vtable->klass->image; \
@@ -810,83 +790,6 @@ MonoBoolean ves_icall_System_Diagnostics_Process_CreateProcess_internal (MonoPro
return(ret);
}
MonoBoolean ves_icall_System_Diagnostics_Process_WaitForExit_internal (MonoObject *this_obj, HANDLE process, gint32 ms)
{
guint32 ret;
MONO_PREPARE_BLOCKING;
if(ms<0) {
/* Wait forever */
ret=WaitForSingleObjectEx (process, INFINITE, TRUE);
} else {
ret=WaitForSingleObjectEx (process, ms, TRUE);
}
MONO_FINISH_BLOCKING;
if(ret==WAIT_OBJECT_0) {
return(TRUE);
} else {
return(FALSE);
}
}
MonoBoolean ves_icall_System_Diagnostics_Process_WaitForInputIdle_internal (MonoObject *this_obj, HANDLE process, gint32 ms)
{
guint32 ret;
if(ms<0) {
/* Wait forever */
ret=WaitForInputIdle (process, INFINITE);
} else {
ret=WaitForInputIdle (process, ms);
}
return (ret) ? FALSE : TRUE;
}
static guint64
file_time_to_guint64 (FILETIME *time)
{
return ((guint64)time->dwHighDateTime << 32) | ((guint64)time->dwLowDateTime);
}
gint64 ves_icall_System_Diagnostics_Process_ExitTime_internal (HANDLE process)
{
gboolean ret;
FILETIME create_time, exit_time, kernel_time, user_time;
ret = GetProcessTimes (process, &create_time, &exit_time, &kernel_time,
&user_time);
if (ret)
return file_time_to_guint64 (&exit_time);
else
return 0;
}
gint64 ves_icall_System_Diagnostics_Process_StartTime_internal (HANDLE process)
{
gboolean ret;
FILETIME create_time, exit_time, kernel_time, user_time;
ret = GetProcessTimes (process, &create_time, &exit_time, &kernel_time,
&user_time);
if (ret)
return file_time_to_guint64 (&create_time);
else
return 0;
}
gint32 ves_icall_System_Diagnostics_Process_ExitCode_internal (HANDLE process)
{
DWORD code;
GetExitCodeProcess (process, &code);
LOGDEBUG (g_message ("%s: process exit code is %d", __func__, code));
return(code);
}
MonoString *ves_icall_System_Diagnostics_Process_ProcessName_internal (HANDLE process)
{
MonoError error;
@@ -977,104 +880,6 @@ ves_icall_System_Diagnostics_Process_GetProcesses_internal (void)
#endif
}
MonoBoolean ves_icall_System_Diagnostics_Process_GetWorkingSet_internal (HANDLE process, guint32 *min, guint32 *max)
{
gboolean ret;
SIZE_T ws_min, ws_max;
ret=GetProcessWorkingSetSize (process, &ws_min, &ws_max);
*min=(guint32)ws_min;
*max=(guint32)ws_max;
return(ret);
}
MonoBoolean ves_icall_System_Diagnostics_Process_SetWorkingSet_internal (HANDLE process, guint32 min, guint32 max, MonoBoolean use_min)
{
gboolean ret;
SIZE_T ws_min;
SIZE_T ws_max;
ret=GetProcessWorkingSetSize (process, &ws_min, &ws_max);
if(ret==FALSE) {
return(FALSE);
}
if(use_min==TRUE) {
ws_min=(SIZE_T)min;
} else {
ws_max=(SIZE_T)max;
}
ret=SetProcessWorkingSetSize (process, ws_min, ws_max);
return(ret);
}
MonoBoolean
ves_icall_System_Diagnostics_Process_Kill_internal (HANDLE process, gint32 sig)
{
/* sig == 1 -> Kill, sig == 2 -> CloseMainWindow */
return TerminateProcess (process, -sig);
}
gint64
ves_icall_System_Diagnostics_Process_Times (HANDLE process, gint32 type)
{
FILETIME create_time, exit_time, kernel_time, user_time;
if (GetProcessTimes (process, &create_time, &exit_time, &kernel_time, &user_time)) {
guint64 ktime = file_time_to_guint64 (&kernel_time);
guint64 utime = file_time_to_guint64 (&user_time);
if (type == 0)
return utime;
else if (type == 1)
return ktime;
else
return ktime + utime;
}
return 0;
}
gint32
ves_icall_System_Diagnostics_Process_GetPriorityClass (HANDLE process, gint32 *error)
{
gint32 ret = GetPriorityClass (process);
*error = ret == 0 ? GetLastError () : 0;
return ret;
}
MonoBoolean
ves_icall_System_Diagnostics_Process_SetPriorityClass (HANDLE process, gint32 priority_class, gint32 *error)
{
gboolean ret = SetPriorityClass (process, priority_class);
*error = ret == 0 ? GetLastError () : 0;
return ret;
}
HANDLE
ves_icall_System_Diagnostics_Process_ProcessHandle_duplicate (HANDLE process)
{
HANDLE ret;
LOGDEBUG (g_message ("%s: Duplicating process handle %p", __func__, process));
DuplicateHandle (GetCurrentProcess (), process, GetCurrentProcess (),
&ret, THREAD_ALL_ACCESS, TRUE, 0);
return ret;
}
void
ves_icall_System_Diagnostics_Process_ProcessHandle_close (HANDLE process)
{
LOGDEBUG (g_message ("%s: Closing process handle %p", __func__, process));
CloseHandle (process);
}
gint64
ves_icall_System_Diagnostics_Process_GetProcessData (int pid, gint32 data_type, gint32 *error)
{
+14 -28
View File
@@ -34,54 +34,40 @@ typedef struct
typedef struct
{
MonoObject object;
MonoString *arguments;
gpointer error_dialog_parent_handle;
MonoString *filename;
MonoString *verb;
MonoString *arguments;
MonoString *working_directory;
MonoObject *envVars;
MonoBoolean create_no_window;
MonoBoolean error_dialog;
MonoBoolean redirect_standard_error;
MonoBoolean redirect_standard_input;
MonoBoolean redirect_standard_output;
MonoBoolean use_shell_execute;
MonoString *verb;
guint32 window_style;
MonoObject *encoding_stderr;
MonoObject *encoding_stdout;
MonoBoolean error_dialog;
gpointer error_dialog_parent_handle;
MonoBoolean use_shell_execute;
MonoString *username;
MonoString *domain;
MonoObject *password; /* SecureString in 2.0 profile, dummy in 1.x */
MonoString *password_in_clear_text;
MonoBoolean load_user_profile;
MonoBoolean redirect_standard_input;
MonoBoolean redirect_standard_output;
MonoBoolean redirect_standard_error;
MonoObject *encoding_stdout;
MonoObject *encoding_stderr;
MonoBoolean create_no_window;
MonoObject *weak_parent_process;
MonoObject *envVars;
} MonoProcessStartInfo;
G_BEGIN_DECLS
HANDLE ves_icall_System_Diagnostics_Process_GetProcess_internal (guint32 pid);
MonoArray *ves_icall_System_Diagnostics_Process_GetProcesses_internal (void);
guint32 ves_icall_System_Diagnostics_Process_GetPid_internal (void);
void ves_icall_System_Diagnostics_Process_Process_free_internal (MonoObject *this_obj, HANDLE process);
MonoArray *ves_icall_System_Diagnostics_Process_GetModules_internal (MonoObject *this_obj, HANDLE process);
void ves_icall_System_Diagnostics_FileVersionInfo_GetVersionInfo_internal (MonoObject *this_obj, MonoString *filename);
MonoBoolean ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoProcessStartInfo *proc_start_info, MonoProcInfo *process_handle);
MonoBoolean ves_icall_System_Diagnostics_Process_CreateProcess_internal (MonoProcessStartInfo *proc_start_info, HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle, MonoProcInfo *process_handle);
MonoBoolean ves_icall_System_Diagnostics_Process_WaitForExit_internal (MonoObject *this_obj, HANDLE process, gint32 ms);
MonoBoolean ves_icall_System_Diagnostics_Process_WaitForInputIdle_internal (MonoObject *this_obj, HANDLE process, gint32 ms);
gint64 ves_icall_System_Diagnostics_Process_ExitTime_internal (HANDLE process);
gint64 ves_icall_System_Diagnostics_Process_StartTime_internal (HANDLE process);
gint32 ves_icall_System_Diagnostics_Process_ExitCode_internal (HANDLE process);
MonoString *ves_icall_System_Diagnostics_Process_ProcessName_internal (HANDLE process);
MonoBoolean ves_icall_System_Diagnostics_Process_GetWorkingSet_internal (HANDLE process, guint32 *min, guint32 *max);
MonoBoolean ves_icall_System_Diagnostics_Process_SetWorkingSet_internal (HANDLE process, guint32 min, guint32 max, MonoBoolean use_min);
MonoBoolean ves_icall_System_Diagnostics_Process_Kill_internal (HANDLE process, gint32 sig);
gint64 ves_icall_System_Diagnostics_Process_Times (HANDLE process, gint32 type);
gint32 ves_icall_System_Diagnostics_Process_GetPriorityClass (HANDLE process, gint32 *error);
MonoBoolean ves_icall_System_Diagnostics_Process_SetPriorityClass (HANDLE process, gint32 priority_class, gint32 *error);
gint64 ves_icall_System_Diagnostics_Process_GetProcessData (int pid, gint32 data_type, gint32 *error);
HANDLE ves_icall_System_Diagnostics_Process_ProcessHandle_duplicate (HANDLE process);
void ves_icall_System_Diagnostics_Process_ProcessHandle_close (HANDLE process);
G_END_DECLS
#endif /* _MONO_METADATA_PROCESS_H_ */