// ClsComplaint version of SetThreadContext. // Caller must ensure that the context is valid, and for the right architecture. public void SetContext(CorDebugSetContextFlag flag, INativeContext context) { using (IContextDirectAccessor w = context.OpenForDirectAccess()) { // context buffer is now locked SetThreadContext(flag, w.Size, w.RawBuffer); } }
public void SetThreadContext(int threadId, INativeContext context) { using (IContextDirectAccessor w = context.OpenForDirectAccess()) { // context buffer is now locked SetThreadContext(threadId, w.RawBuffer, w.Size); } }
public INativeContext GetThreadContext(int threadId) { INativeContext context = ContextAllocator.GenerateContext(); using (IContextDirectAccessor w = context.OpenForDirectAccess()) { // context buffer is now locked // We initialize to a HUGE number so that we make sure GetThreadContext is updating the size variable. If it doesn't, // then we will hit the assert statement below. this.GetThreadContext(threadId, w.RawBuffer, w.Size); } return(context); }
// ClsComplaint version of GetThreadContext. // Caller must ensure that the context is valid, and for the right architecture. public void GetContext(INativeContext context) { using (IContextDirectAccessor w = context.OpenForDirectAccess()) { // context buffer is now locked // We initialize to a HUGE number so that we make sure GetThreadContext is updating the size variable. If it doesn't, // then we will hit the assert statement below. int size = Int32.MaxValue; this.GetThreadContext((ContextFlags)context.Flags, w.Size, out size, w.RawBuffer); // We should only assert when the buffer is insufficient. Since the runtime only keeps track of CONTEXT_CONTROL and CONTEXT_INTEGER // we will expect to create a larger buffer than absolutely necessary. The context buffer will be the size of a FULL machine // context. Debug.Assert(size <= w.Size, String.Format("Insufficient Buffer: Expected {0} bytes, but received {1}", w.Size, size)); } }
/// <summary> /// Writes back the Thread Context of the thread that the CreateThreadNativeEvent was generated on /// </summary> /// <remarks>Setting a thread's context is very dangerous operation and must be used properly.</remarks> public void WriteContext(INativeContext context) { IntPtr hThread = IntPtr.Zero; try { hThread = NativeMethods.OpenThread(ThreadAccess.THREAD_ALL_ACCESS, true, (uint)this.ThreadId); using (IContextDirectAccessor w = context.OpenForDirectAccess()) { // context buffer is now locked NativeMethods.SetThreadContext(hThread, w.RawBuffer); } // w is disposed, this unlocks the context buffer. } finally { if (hThread != IntPtr.Zero) { NativeMethods.CloseHandle(hThread); } } }
/* Set the INativeContext object for the given thread */ public void SetThreadContext(int threadId, INativeContext context) { using (IContextDirectAccessor w = context.OpenForDirectAccess()) { // context buffer is now locked SetThreadContext(threadId, w.RawBuffer, w.Size); } }
// ClsComplaint version of SetThreadContext. // Caller must ensure that the context is valid, and for the right architecture. public void SetContext(CorDebugSetContextFlag flag, INativeContext context) { using (IContextDirectAccessor w = context.OpenForDirectAccess()) { // context buffer is now locked SetThreadContext(flag, w.Size, w.RawBuffer); } }
// ClsComplaint version of GetThreadContext. // Caller must ensure that the context is valid, and for the right architecture. public void GetContext(INativeContext context) { using (IContextDirectAccessor w = context.OpenForDirectAccess()) { // context buffer is now locked // We initialize to a HUGE number so that we make sure GetThreadContext is updating the size variable. If it doesn't, // then we will hit the assert statement below. int size = Int32.MaxValue; this.GetThreadContext((ContextFlags)context.Flags,w.Size, out size, w.RawBuffer); // We should only assert when the buffer is insufficient. Since the runtime only keeps track of CONTEXT_CONTROL and CONTEXT_INTEGER // we will expect to create a larger buffer than absolutely necessary. The context buffer will be the size of a FULL machine // context. Debug.Assert(size <= w.Size, String.Format("Insufficient Buffer: Expected {0} bytes, but received {1}",w.Size, size)); } }
/// <summary> /// Writes back the Thread Context of the thread that the CreateThreadNativeEvent was generated on /// </summary> /// <remarks>Setting a thread's context is very dangerous operation and must be used properly.</remarks> public void WriteContext(INativeContext context) { IntPtr hThread = IntPtr.Zero; try { hThread = NativeMethods.OpenThread(ThreadAccess.THREAD_ALL_ACCESS, true, (uint) ThreadId); using (IContextDirectAccessor w = context.OpenForDirectAccess()) { // context buffer is now locked NativeMethods.SetThreadContext(hThread, w.RawBuffer); } // w is disposed, this unlocks the context buffer. } finally { if (hThread != IntPtr.Zero) { NativeMethods.CloseHandle(hThread); } } }