Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -32,7 +32,6 @@
//
using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
@@ -40,6 +39,8 @@ using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
#pragma warning disable 618
namespace System.Diagnostics
{
[DefaultEvent ("EntryWritten")]

View File

@@ -169,7 +169,7 @@ namespace System.Diagnostics
(otherEntry.CategoryNumber == categoryNumber) &&
(otherEntry.Data.Equals (data)) &&
(otherEntry.EntryType == entryType) &&
(otherEntry.EventID == eventID) &&
(otherEntry.InstanceId == instanceId) &&
(otherEntry.Index == index) &&
(otherEntry.MachineName == machineName) &&
(otherEntry.Message == message) &&

View File

@@ -144,7 +144,7 @@ namespace System.Diagnostics {
public string FileName {
get {
#if !MOBILE
#if MONO_FEATURE_CAS
if (SecurityManager.SecurityEnabled) {
new FileIOPermission (FileIOPermissionAccess.PathDiscovery, filename).Demand ();
}
@@ -278,7 +278,7 @@ namespace System.Diagnostics {
public static FileVersionInfo GetVersionInfo (string fileName)
{
#if !MOBILE
#if MONO_FEATURE_CAS
if (SecurityManager.SecurityEnabled) {
new FileIOPermission (FileIOPermissionAccess.Read, fileName).Demand ();
}

View File

@@ -159,7 +159,7 @@ namespace System.Diagnostics {
}
// may throw ArgumentNullException
[DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
[DefaultValue (""), ReadOnly (true), SettingsBindable (true)]
[TypeConverter ("System.Diagnostics.Design.CategoryValueConverter, " + Consts.AssemblySystem_Design)]
[SRDescription ("The category name for this performance counter.")]
public string CategoryName {
@@ -181,7 +181,7 @@ namespace System.Diagnostics {
}
// may throw ArgumentNullException
[DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
[DefaultValue (""), ReadOnly (true), SettingsBindable (true)]
[TypeConverter ("System.Diagnostics.Design.CounterNameConverter, " + Consts.AssemblySystem_Design)]
[SRDescription ("The name of this performance counter.")]
public string CounterName
@@ -212,7 +212,7 @@ namespace System.Diagnostics {
set { lifetime = value; }
}
[DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
[DefaultValue (""), ReadOnly (true), SettingsBindable (true)]
[TypeConverter ("System.Diagnostics.Design.InstanceNameConverter, " + Consts.AssemblySystem_Design)]
[SRDescription ("The instance name for this performance counter.")]
public string InstanceName {
@@ -227,7 +227,7 @@ namespace System.Diagnostics {
// may throw ArgumentException if machine name format is wrong
[MonoTODO("What's the machine name format?")]
[DefaultValue ("."), Browsable (false), RecommendedAsConfigurable (true)]
[DefaultValue ("."), Browsable (false), SettingsBindable (true)]
[SRDescription ("The machine where this performance counter resides.")]
public string MachineName {
get {return machineName;}

View File

@@ -34,6 +34,7 @@
using System.IO;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Runtime.CompilerServices;
@@ -62,8 +63,7 @@ namespace System.Diagnostics
public IntPtr thread_handle;
public int pid; // Contains -GetLastError () on failure.
public int tid;
public string [] envKeys;
public string [] envValues;
public string[] envVariables;
public string UserName;
public string Domain;
public IntPtr Password;
@@ -469,16 +469,6 @@ namespace System.Diagnostics
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static IntPtr GetProcess_internal(int pid);
public static Process GetProcessById(int processId)
{
IntPtr proc = GetProcess_internal(processId);
if (proc == IntPtr.Zero)
throw new ArgumentException ("Can't find process with ID " + processId.ToString ());
return (new Process (new SafeProcessHandle (proc, false), processId));
}
[MonoTODO ("There is no support for retrieving process information from a remote machine")]
public static Process GetProcessById(int processId, string machineName) {
if (machineName == null)
@@ -487,14 +477,53 @@ namespace System.Diagnostics
if (!IsLocalMachine (machineName))
throw new NotImplementedException ();
return GetProcessById (processId);
IntPtr proc = GetProcess_internal(processId);
if (proc == IntPtr.Zero)
throw new ArgumentException ("Can't find process with ID " + processId.ToString ());
return (new Process (new SafeProcessHandle (proc, false), processId));
}
public static Process[] GetProcessesByName(string processName, string machineName)
{
if (machineName == null)
throw new ArgumentNullException ("machineName");
if (!IsLocalMachine (machineName))
throw new NotImplementedException ();
Process[] processes = GetProcesses ();
if (processes.Length == 0)
return processes;
int size = 0;
for (int i = 0; i < processes.Length; i++) {
try {
if (String.Compare (processName, processes[i].ProcessName, true) == 0)
processes [size++] = processes[i];
} catch (SystemException) {
/* The process might exit between GetProcesses_internal and GetProcessById */
}
}
Array.Resize<Process> (ref processes, size);
return processes;
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static int[] GetProcesses_internal();
public static Process[] GetProcesses ()
{
[MonoTODO ("There is no support for retrieving process information from a remote machine")]
public static Process[] GetProcesses(string machineName) {
if (machineName == null)
throw new ArgumentNullException ("machineName");
if (!IsLocalMachine (machineName))
throw new NotImplementedException ();
int [] pids = GetProcesses_internal ();
if (pids == null)
return new Process [0];
@@ -515,46 +544,6 @@ namespace System.Diagnostics
return proclist.ToArray ();
}
[MonoTODO ("There is no support for retrieving process information from a remote machine")]
public static Process[] GetProcesses(string machineName) {
if (machineName == null)
throw new ArgumentNullException ("machineName");
if (!IsLocalMachine (machineName))
throw new NotImplementedException ();
return GetProcesses ();
}
public static Process[] GetProcessesByName(string processName)
{
int [] pids = GetProcesses_internal ();
if (pids == null)
return new Process [0];
var proclist = new List<Process> (pids.Length);
for (int i = 0; i < pids.Length; i++) {
try {
Process p = GetProcessById (pids [i]);
if (String.Compare (processName, p.ProcessName, true) == 0)
proclist.Add (p);
} catch (SystemException) {
/* The process might exit
* between
* GetProcesses_internal and
* GetProcessById
*/
}
}
return proclist.ToArray ();
}
[MonoTODO]
public static Process[] GetProcessesByName(string processName, string machineName) {
throw new NotImplementedException();
}
private static bool IsLocalMachine (string machineName)
{
if (machineName == "." || machineName.Length == 0)
@@ -565,10 +554,10 @@ namespace System.Diagnostics
#if MONO_FEATURE_PROCESS_START
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static bool ShellExecuteEx_internal(ProcessStartInfo startInfo, ref ProcInfo proc_info);
private extern static bool ShellExecuteEx_internal(ProcessStartInfo startInfo, ref ProcInfo procInfo);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static bool CreateProcess_internal(ProcessStartInfo startInfo, IntPtr stdin, IntPtr stdout, IntPtr stderr, ref ProcInfo proc_info);
private extern static bool CreateProcess_internal(ProcessStartInfo startInfo, IntPtr stdin, IntPtr stdout, IntPtr stderr, ref ProcInfo procInfo);
bool StartWithShellExecuteEx (ProcessStartInfo startInfo)
{
@@ -591,23 +580,23 @@ namespace System.Diagnostics
if (startInfo.environmentVariables != null)
throw new InvalidOperationException(SR.GetString(SR.CantUseEnvVars));
ProcInfo proc_info = new ProcInfo();
ProcInfo procInfo = new ProcInfo();
bool ret;
FillUserInfo (startInfo, ref proc_info);
FillUserInfo (startInfo, ref procInfo);
try {
ret = ShellExecuteEx_internal (startInfo, ref proc_info);
ret = ShellExecuteEx_internal (startInfo, ref procInfo);
} finally {
if (proc_info.Password != IntPtr.Zero)
Marshal.ZeroFreeBSTR (proc_info.Password);
proc_info.Password = IntPtr.Zero;
if (procInfo.Password != IntPtr.Zero)
Marshal.ZeroFreeBSTR (procInfo.Password);
procInfo.Password = IntPtr.Zero;
}
if (!ret) {
throw new Win32Exception (-proc_info.pid);
throw new Win32Exception (-procInfo.pid);
}
SetProcessHandle (new SafeProcessHandle (proc_info.process_handle, true));
SetProcessId (proc_info.pid);
SetProcessHandle (new SafeProcessHandle (procInfo.process_handle, true));
SetProcessId (procInfo.pid);
return ret;
}
@@ -687,16 +676,32 @@ namespace System.Diagnostics
if (this.disposed)
throw new ObjectDisposedException (GetType ().Name);
var proc_info = new ProcInfo ();
var procInfo = new ProcInfo ();
if (startInfo.HaveEnvVars) {
string [] strs = new string [startInfo.EnvironmentVariables.Count];
startInfo.EnvironmentVariables.Keys.CopyTo (strs, 0);
proc_info.envKeys = strs;
List<string> envVariables = null;
StringBuilder sb = null;
strs = new string [startInfo.EnvironmentVariables.Count];
startInfo.EnvironmentVariables.Values.CopyTo (strs, 0);
proc_info.envValues = strs;
foreach (DictionaryEntry de in startInfo.EnvironmentVariables) {
if (de.Value == null)
continue;
if (envVariables == null)
envVariables = new List<string> ();
if (sb == null)
sb = new StringBuilder ();
else
sb.Clear ();
sb.Append ((string) de.Key);
sb.Append ('=');
sb.Append ((string) de.Value);
envVariables.Add (sb.ToString ());
}
procInfo.envVariables = envVariables?.ToArray ();
}
MonoIOError error;
@@ -726,16 +731,16 @@ namespace System.Diagnostics
stderr_write = MonoIO.ConsoleError;
}
FillUserInfo (startInfo, ref proc_info);
FillUserInfo (startInfo, ref procInfo);
//
// FIXME: For redirected pipes we need to send descriptors of
// stdin_write, stdout_read, stderr_read to child process and
// close them there (fork makes exact copy of parent's descriptors)
//
if (!CreateProcess_internal (startInfo, stdin_read, stdout_write, stderr_write, ref proc_info)) {
throw new Win32Exception (-proc_info.pid, "ApplicationName='" + startInfo.FileName + "', CommandLine='" + startInfo.Arguments +
"', CurrentDirectory='" + startInfo.WorkingDirectory + "', Native error= " + Win32Exception.W32ErrorMessage (-proc_info.pid));
if (!CreateProcess_internal (startInfo, stdin_read, stdout_write, stderr_write, ref procInfo)) {
throw new Win32Exception (-procInfo.pid, "ApplicationName='" + startInfo.FileName + "', CommandLine='" + startInfo.Arguments +
"', CurrentDirectory='" + startInfo.WorkingDirectory + "', Native error= " + Win32Exception.GetErrorMessage (-procInfo.pid));
}
} catch {
if (startInfo.RedirectStandardInput) {
@@ -761,15 +766,17 @@ namespace System.Diagnostics
throw;
} finally {
if (proc_info.Password != IntPtr.Zero) {
Marshal.ZeroFreeBSTR (proc_info.Password);
proc_info.Password = IntPtr.Zero;
if (procInfo.Password != IntPtr.Zero) {
Marshal.ZeroFreeBSTR (procInfo.Password);
procInfo.Password = IntPtr.Zero;
}
}
SetProcessHandle (new SafeProcessHandle (proc_info.process_handle, true));
SetProcessId (proc_info.pid);
SetProcessHandle (new SafeProcessHandle (procInfo.process_handle, true));
SetProcessId (procInfo.pid);
#pragma warning disable 618
if (startInfo.RedirectStandardInput) {
MonoIO.Close (stdin_read, out error);
@@ -798,21 +805,22 @@ namespace System.Diagnostics
standardError = new StreamReader (new FileStream (stderr_read, FileAccess.Read, true, 8192), stderrEncoding, true);
}
#pragma warning restore
return true;
}
// Note that ProcInfo.Password must be freed.
private static void FillUserInfo (ProcessStartInfo startInfo, ref ProcInfo proc_info)
private static void FillUserInfo (ProcessStartInfo startInfo, ref ProcInfo procInfo)
{
if (startInfo.UserName.Length != 0) {
proc_info.UserName = startInfo.UserName;
proc_info.Domain = startInfo.Domain;
procInfo.UserName = startInfo.UserName;
procInfo.Domain = startInfo.Domain;
if (startInfo.Password != null)
proc_info.Password = Marshal.SecureStringToBSTR (startInfo.Password);
procInfo.Password = Marshal.SecureStringToBSTR (startInfo.Password);
else
proc_info.Password = IntPtr.Zero;
proc_info.LoadUserProfile = startInfo.LoadUserProfile;
procInfo.Password = IntPtr.Zero;
procInfo.LoadUserProfile = startInfo.LoadUserProfile;
}
}
#else

View File

@@ -7,7 +7,6 @@
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
@@ -48,7 +47,7 @@ namespace System.Diagnostics
private IntPtr _readHandle;
private Thread _notifyThread;
private int _lastEntryWritten;
private bool _notifying;
private Object _eventLock = new object();
public Win32EventLog (EventLog coreEventLog)
: base (coreEventLog)
@@ -68,9 +67,11 @@ namespace System.Diagnostics
public override void Close ()
{
if (_readHandle != IntPtr.Zero) {
CloseEventLog (_readHandle);
_readHandle = IntPtr.Zero;
lock (_eventLock) {
if (_readHandle != IntPtr.Zero) {
CloseEventLog (_readHandle);
_readHandle = IntPtr.Zero;
}
}
}
@@ -703,45 +704,56 @@ namespace System.Diagnostics
public override void DisableNotification ()
{
if (_notifyResetEvent != null) {
_notifyResetEvent.Close ();
_notifyResetEvent = null;
}
if (_notifyThread != null) {
if (_notifyThread.ThreadState == System.Threading.ThreadState.Running)
_notifyThread.Abort ();
lock (_eventLock) {
if (_notifyResetEvent != null) {
_notifyResetEvent.Close ();
_notifyResetEvent = null;
}
_notifyThread = null;
}
}
public override void EnableNotification ()
{
_notifyResetEvent = new ManualResetEvent (false);
_lastEntryWritten = OldestEventLogEntry + EntryCount;
if (PInvoke.NotifyChangeEventLog (ReadHandle, _notifyResetEvent.Handle) == 0)
throw new InvalidOperationException (string.Format (
CultureInfo.InvariantCulture, "Unable to receive notifications"
+ " for log '{0}' on computer '{1}'.", CoreEventLog.GetLogName (),
CoreEventLog.MachineName), new Win32Exception ());
_notifyThread = new Thread (new ThreadStart (NotifyEventThread));
_notifyThread.IsBackground = true;
_notifyThread.Start ();
lock (_eventLock) {
if (_notifyResetEvent != null)
return;
_notifyResetEvent = new ManualResetEvent (false);
_lastEntryWritten = OldestEventLogEntry + EntryCount;
if (PInvoke.NotifyChangeEventLog (ReadHandle, _notifyResetEvent.SafeWaitHandle.DangerousGetHandle ()) == 0)
throw new InvalidOperationException (string.Format (
CultureInfo.InvariantCulture, "Unable to receive notifications"
+ " for log '{0}' on computer '{1}'.", CoreEventLog.GetLogName (),
CoreEventLog.MachineName), new Win32Exception ());
_notifyThread = new Thread (() => NotifyEventThread(_notifyResetEvent));
_notifyThread.IsBackground = true;
_notifyThread.Start ();
}
}
private void NotifyEventThread ()
private void NotifyEventThread (ManualResetEvent resetEvent)
{
while (true) {
_notifyResetEvent.WaitOne ();
lock (this) {
// after a clear, we something get notified
// twice for the same entry
if (_notifying)
return;
_notifying = true;
try {
resetEvent.WaitOne ();
} catch (ObjectDisposedException) {
// Notifications have been disabled and event
// has been closed but not yet nulled. End thread.
break;
}
try {
lock (_eventLock) {
if (resetEvent != _notifyResetEvent) {
// A new thread has started with another reset event instance
// or DisableNotifications has been called, setting
// _notifyResetEvent to null. In both cases end this thread.
break;
}
if (_readHandle == IntPtr.Zero)
break;
int oldest_entry = OldestEventLogEntry;
if (_lastEntryWritten < oldest_entry)
_lastEntryWritten = oldest_entry;
@@ -752,9 +764,6 @@ namespace System.Diagnostics
CoreEventLog.OnEntryWritten (entry);
}
_lastEntryWritten = last_entry;
} finally {
lock (this)
_notifying = false;
}
}
}