return DirectorySeparatorStr;
}
}
+
+ internal const int MAX_PATH = 260; // From WinDef.h
}
}
old_state = _state;
if ((old_state & (int) State.Closed) != 0)
- throw new ObjectDisposedException ("handle");
+ throw new ObjectDisposedException (null, "Safe handle has been closed");
new_state = old_state + RefCount_One;
} while (Interlocked.CompareExchange (ref _state, new_state, old_state) != old_state);
* hitting zero though -- that can happen if SetHandleAsInvalid is
* used). */
if ((old_state & RefCount_Mask) == 0)
- throw new ObjectDisposedException ("handle");
+ throw new ObjectDisposedException (null, "Safe handle has been closed");
if ((old_state & RefCount_Mask) != RefCount_One)
perform_release = false;
{
Persist (name, includeSections, null);
}
+
+ internal void Persist (SafeHandle handle)
+ {
+ PersistModifications (handle);
+ }
internal void PersistModifications (SafeHandle handle)
{
+++ /dev/null
-//
-// System.Threading.EventWaitHandle.cs
-//
-// Author:
-// Dick Porter (dick@ximian.com)
-//
-// (C) Ximian, Inc. (http://www.ximian.com)
-// Copyright (C) 2005 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,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.IO;
-using System.Runtime.InteropServices;
-using System.Security.AccessControl;
-
-namespace System.Threading
-{
- [ComVisible (true)]
- public class EventWaitHandle : WaitHandle
- {
- private EventWaitHandle (IntPtr handle)
- {
- Handle = handle;
- }
-
- static bool IsManualReset (EventResetMode mode)
- {
- if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset))
- throw new ArgumentException ("mode");
- return (mode == EventResetMode.ManualReset);
- }
-
- public EventWaitHandle (bool initialState, EventResetMode mode)
- {
- bool created;
- bool manual = IsManualReset (mode);
- Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, null, out created);
- }
-
-#if !MOBILE
-
- public EventWaitHandle (bool initialState, EventResetMode mode,
- string name)
- {
- bool created;
- bool manual = IsManualReset (mode);
- Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out created);
- }
-
- public EventWaitHandle (bool initialState, EventResetMode mode,
- string name, out bool createdNew)
- {
- bool manual = IsManualReset (mode);
- Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew);
- }
-
-
- [MonoTODO ("Use access control in CreateEvent_internal")]
- public EventWaitHandle (bool initialState, EventResetMode mode,
- string name, out bool createdNew,
- EventWaitHandleSecurity eventSecurity)
- {
- bool manual = IsManualReset (mode);
- Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew);
- }
-
- public EventWaitHandleSecurity GetAccessControl ()
- {
- return new EventWaitHandleSecurity (SafeWaitHandle,
- AccessControlSections.Owner |
- AccessControlSections.Group |
- AccessControlSections.Access);
-
- }
-
- public static EventWaitHandle OpenExisting (string name)
- {
- return(OpenExisting (name, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify));
- }
-
- public static EventWaitHandle OpenExisting (string name, EventWaitHandleRights rights)
- {
- if (name == null) {
- throw new ArgumentNullException ("name");
- }
- if ((name.Length == 0) ||
- (name.Length > 260)) {
- throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
- }
-
- MonoIOError error;
- IntPtr handle = NativeEventCalls.OpenEvent_internal (name, rights, out error);
- if (handle == (IntPtr)null) {
- if (error == MonoIOError.ERROR_FILE_NOT_FOUND) {
- throw new WaitHandleCannotBeOpenedException (Locale.GetText ("Named Event handle does not exist: ") + name);
- } else if (error == MonoIOError.ERROR_ACCESS_DENIED) {
- throw new UnauthorizedAccessException ();
- } else {
- throw new IOException (Locale.GetText ("Win32 IO error: ") + error.ToString ());
- }
- }
-
- return(new EventWaitHandle (handle));
- }
-
- public static bool TryOpenExisting (string name, out EventWaitHandle result)
- {
- return TryOpenExisting (
- name, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, out result);
- }
-
- public static bool TryOpenExisting (string name, EventWaitHandleRights rights,
- out EventWaitHandle result)
- {
- if (name == null) {
- throw new ArgumentNullException ("name");
- }
- if ((name.Length == 0) || (name.Length > 260)) {
- throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
- }
-
- MonoIOError error;
- IntPtr handle = NativeEventCalls.OpenEvent_internal (name, rights, out error);
- if (handle == (IntPtr)null) {
- result = null;
- return false;
- }
-
- result = new EventWaitHandle (handle);
- return true;
- }
-#else
- public EventWaitHandle (bool initialState, EventResetMode mode, string name)
- {
- throw new NotSupportedException ();
- }
-
- public EventWaitHandle (bool initialState, EventResetMode mode,
- string name, out bool createdNew)
- {
- throw new NotSupportedException ();
- }
-
-
- public EventWaitHandle (bool initialState, EventResetMode mode,
- string name, out bool createdNew,
- EventWaitHandleSecurity eventSecurity)
- {
- throw new NotSupportedException ();
- }
-
- public static EventWaitHandle OpenExisting (string name)
- {
- throw new NotSupportedException ();
- }
-
- public static EventWaitHandle OpenExisting (string name, EventWaitHandleRights rights)
- {
- throw new NotSupportedException ();
- }
-
- public static bool TryOpenExisting (string name, out EventWaitHandle result)
- {
- throw new NotSupportedException ();
- }
-
- public static bool TryOpenExisting (string name, EventWaitHandleRights rights,
- out EventWaitHandle result)
- {
- throw new NotSupportedException ();
- }
-#endif
-
- public bool Reset ()
- {
- /* This needs locking since another thread could dispose the handle */
- lock (this) {
- CheckDisposed ();
-
- return NativeEventCalls.ResetEvent (SafeWaitHandle);
- }
- }
-
- public bool Set ()
- {
- lock (this) {
- CheckDisposed ();
-
- return NativeEventCalls.SetEvent (SafeWaitHandle);
- }
- }
-
- internal void CheckDisposed ()
- {
- if (disposed)
- throw new ObjectDisposedException (GetType ().FullName);
- }
-
- bool disposed;
- protected override void Dispose(bool explicitDisposing)
- {
- base.Dispose (explicitDisposing);
- disposed = true;
- }
-
-#if !MOBILE
- public void SetAccessControl (EventWaitHandleSecurity eventSecurity)
- {
- if (null == eventSecurity)
- throw new ArgumentNullException ("eventSecurity");
-
- eventSecurity.PersistModifications (SafeWaitHandle);
-
- }
-#endif
- }
-}
internal static class NativeEventCalls
{
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- public static extern IntPtr CreateEvent_internal(bool manual,bool initial,string name, out bool created);
+ public static extern IntPtr CreateEvent_internal (bool manual, bool initial, string name, out int errorCode);
public static bool SetEvent (SafeWaitHandle handle)
{
#if !MOBILE
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public static extern IntPtr OpenEvent_internal (string name, EventWaitHandleRights rights, out MonoIOError error);
+ public static extern IntPtr OpenEvent_internal (string name, EventWaitHandleRights rights, out int errorCode);
#endif
}
}
* of icalls, do not require an increment.
*/
#pragma warning disable 169
- private const int mono_corlib_version = 152;
+ private const int mono_corlib_version = 153;
#pragma warning restore 169
[ComVisible (true)]
{
new EventWaitHandle (true, (EventResetMode) Int32.MinValue);
}
+
+ [Test]
+ public void Disposed_Set ()
+ {
+ var ewh = new EventWaitHandle (false, EventResetMode.ManualReset);
+ ewh.Dispose();
+ try {
+ ewh.Set();
+ Assert.Fail ();
+ } catch (ObjectDisposedException) {
+ }
+ }
}
}
System.Text/NormalizationForm.cs
System.Text/Latin1Encoding.cs
System.Threading/CompressedStack.cs
-System.Threading/EventWaitHandle.cs
System.Threading/HostExecutionContext.cs
System.Threading/HostExecutionContextManager.cs
System.Threading/Interlocked.cs
../referencesource/mscorlib/system/threading/CancellationTokenSource.cs
../referencesource/mscorlib/system/threading/CountdownEvent.cs
../referencesource/mscorlib/system/threading/eventresetmode.cs
+../referencesource/mscorlib/system/threading/eventwaithandle.cs
../referencesource/mscorlib/system/threading/executioncontext.cs
../referencesource/mscorlib/system/threading/LazyInitializer.cs
../referencesource/mscorlib/system/threading/lockrecursionexception.cs
}
#endif
+#if !MONO
#if FEATURE_NETCORE
[SecuritySafeCritical]
#endif
int errorCode = Marshal.GetLastWin32Error();
WinIOError(errorCode, str);
}
+#endif
// After calling GetLastWin32Error(), it clears the last error field,
// so you must save the HResult and pass it to this method. This method
if(null != name && 0 != name.Length && NativeMethods.ERROR_INVALID_HANDLE == errorCode)
throw new WaitHandleCannotBeOpenedException(SR.GetString(SR.WaitHandleCannotBeOpenedException_InvalidHandle,name));
+#if MONO
+ InternalResources.WinIOError(errorCode, "");
+#else
InternalResources.WinIOError();
+#endif
}
this.SafeWaitHandle = myHandle;
}
{
if(null != name && 0 != name.Length && NativeMethods.ERROR_INVALID_HANDLE == errorCode)
throw new WaitHandleCannotBeOpenedException(SR.GetString(SR.WaitHandleCannotBeOpenedException_InvalidHandle,name));
+
+#if MONO
+ InternalResources.WinIOError(errorCode, "");
+#else
InternalResources.WinIOError();
+#endif
}
createdNew = errorCode != NativeMethods.ERROR_ALREADY_EXISTS;
this.SafeWaitHandle = myHandle;
if (null != name && 0 != name.Length && NativeMethods.ERROR_INVALID_HANDLE == errorCode)
return OpenExistingResult.NameInvalid;
//this is for passed through NativeMethods Errors
+#if MONO
+ InternalResources.WinIOError(errorCode, "");
+#else
InternalResources.WinIOError();
+#endif
}
result = new Semaphore(myHandle);
return OpenExistingResult.Success;
=============================================================================*/
+#if !MOBILE
#if !FEATURE_MACL
namespace System.Security.AccessControl
{
}
}
#endif
+#endif
namespace System.Threading
{
Contract.EndContractBlock();
SafeWaitHandle _handle = null;
+#if MONO
+ int errorCode;
+#endif
switch(mode)
{
case EventResetMode.ManualReset:
+#if MONO
+ _handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (true, initialState, name, out errorCode), true);
+#else
_handle = Win32Native.CreateEvent(null, true, initialState, name);
+#endif
break;
case EventResetMode.AutoReset:
+#if MONO
+ _handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (false, initialState, name, out errorCode), true);
+#else
_handle = Win32Native.CreateEvent(null, false, initialState, name);
+#endif
break;
default:
if (_handle.IsInvalid)
{
+#if !MONO
int errorCode = Marshal.GetLastWin32Error();
+#endif
_handle.SetHandleAsInvalid();
if(null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode)
}
Contract.EndContractBlock();
Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
+#if !MONO
#if FEATURE_MACL
// For ACL's, get the security descriptor from the EventWaitHandleSecurity.
if (eventSecurity != null) {
Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length);
secAttrs.pSecurityDescriptor = pSecDescriptor;
}
+#endif
#endif
SafeWaitHandle _handle = null;
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag",name));
};
+#if MONO
+ int errorCode;
+ _handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (isManualReset, initialState, name, out errorCode), true);
+#else
_handle = Win32Native.CreateEvent(secAttrs, isManualReset, initialState, name);
int errorCode = Marshal.GetLastWin32Error();
+#endif
if (_handle.IsInvalid)
{
result = null;
+#if MOBILE
+ throw new NotSupportedException ();
+#else
+
+#if MONO
+ int errorCode;
+ var myHandle = new SafeWaitHandle (NativeEventCalls.OpenEvent_internal (name, rights, out errorCode), true);
+#else
#if FEATURE_MACL
SafeWaitHandle myHandle = Win32Native.OpenEvent((int) rights, false, name);
#else
SafeWaitHandle myHandle = Win32Native.OpenEvent(Win32Native.EVENT_MODIFY_STATE | Win32Native.SYNCHRONIZE, false, name);
+#endif
#endif
if (myHandle.IsInvalid)
{
+#if !MONO
int errorCode = Marshal.GetLastWin32Error();
+#endif
if(Win32Native.ERROR_FILE_NOT_FOUND == errorCode || Win32Native.ERROR_INVALID_NAME == errorCode)
return OpenExistingResult.NameNotFound;
}
result = new EventWaitHandle(myHandle);
return OpenExistingResult.Success;
+#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
public bool Reset()
{
+#if MONO
+ var res = NativeEventCalls.ResetEvent(safeWaitHandle);
+#else
bool res = Win32Native.ResetEvent(safeWaitHandle);
+#endif
if (!res)
+#if MONO
+ throw new IOException ();
+#else
__Error.WinIOError();
+#endif
return res;
}
[System.Security.SecuritySafeCritical] // auto-generated
public bool Set()
{
+#if MONO
+ var res = NativeEventCalls.SetEvent(safeWaitHandle);
+#else
bool res = Win32Native.SetEvent(safeWaitHandle);
+#endif
if (!res)
+#if MONO
+ throw new IOException ();
+#else
__Error.WinIOError();
+#endif
return res;
}
-#if FEATURE_MACL
+#if FEATURE_MACL || MOBILE
[System.Security.SecuritySafeCritical] // auto-generated
public EventWaitHandleSecurity GetAccessControl()
{
return new EventWaitHandleSecurity(safeWaitHandle, AccessControlSections.Access | AccessControlSections.Owner | AccessControlSections.Group);
}
+#endif
+#if FEATURE_MACL
[System.Security.SecuritySafeCritical] // auto-generated
public void SetAccessControl(EventWaitHandleSecurity eventSecurity)
{
* Changes which are already detected at runtime, like the addition
* of icalls, do not require an increment.
*/
-#define MONO_CORLIB_VERSION 152
+#define MONO_CORLIB_VERSION 153
typedef struct
{
ICALL_TYPE(NATIVEC, "System.Threading.NativeEventCalls", NATIVEC_1)
ICALL(NATIVEC_1, "CloseEvent_internal", ves_icall_System_Threading_Events_CloseEvent_internal)
-ICALL(NATIVEC_2, "CreateEvent_internal(bool,bool,string,bool&)", ves_icall_System_Threading_Events_CreateEvent_internal)
-ICALL(NATIVEC_3, "OpenEvent_internal(string,System.Security.AccessControl.EventWaitHandleRights,System.IO.MonoIOError&)", ves_icall_System_Threading_Events_OpenEvent_internal)
+ICALL(NATIVEC_2, "CreateEvent_internal(bool,bool,string,int&)", ves_icall_System_Threading_Events_CreateEvent_internal)
+ICALL(NATIVEC_3, "OpenEvent_internal(string,System.Security.AccessControl.EventWaitHandleRights,int&)", ves_icall_System_Threading_Events_OpenEvent_internal)
ICALL(NATIVEC_4, "ResetEvent_internal", ves_icall_System_Threading_Events_ResetEvent_internal)
ICALL(NATIVEC_5, "SetEvent_internal", ves_icall_System_Threading_Events_SetEvent_internal)
HANDLE ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount, gint32 maximumCount, MonoString *name, gint32 *error);
MonoBoolean ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (HANDLE handle, gint32 releaseCount, gint32 *prevcount);
HANDLE ves_icall_System_Threading_Semaphore_OpenSemaphore_internal (MonoString *name, gint32 rights, gint32 *error);
-HANDLE ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoString *name, MonoBoolean *created);
+HANDLE ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoString *name, gint32 *error);
gboolean ves_icall_System_Threading_Events_SetEvent_internal (HANDLE handle);
gboolean ves_icall_System_Threading_Events_ResetEvent_internal (HANDLE handle);
void ves_icall_System_Threading_Events_CloseEvent_internal (HANDLE handle);
}
*error = GetLastError ();
+
return(sem);
}
HANDLE sem;
sem = OpenSemaphore (rights, FALSE, mono_string_chars (name));
+
*error = GetLastError ();
return(sem);
}
-HANDLE ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoString *name, MonoBoolean *created)
+HANDLE ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoString *name, gint32 *error)
{
HANDLE event;
-
- *created = TRUE;
if (name == NULL) {
event = CreateEvent (NULL, manual, initial, NULL);
} else {
event = CreateEvent (NULL, manual, initial,
mono_string_chars (name));
-
- if (GetLastError () == ERROR_ALREADY_EXISTS) {
- *created = FALSE;
- }
}
-
+
+ *error = GetLastError ();
+
return(event);
}
{
HANDLE ret;
- *error = ERROR_SUCCESS;
-
ret = OpenEvent (rights, FALSE, mono_string_chars (name));
if (ret == NULL) {
*error = GetLastError ();
+ } else {
+ *error = ERROR_SUCCESS;
}
-
+
return(ret);
}