示例#1
0
 // 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);
     }
 }
示例#2
0
 public void SetThreadContext(int threadId, INativeContext context)
 {
     using (IContextDirectAccessor w = context.OpenForDirectAccess())
     {
         // context buffer is now locked
         SetThreadContext(threadId, w.RawBuffer, w.Size);
     }
 }
示例#3
0
 public void ClearContext()
 {
     // make sure that we have access to the buffer
     using (IContextDirectAccessor w = this.OpenForDirectAccess())
     {
         for (int i = 0; i < w.Size; i++)
         {
             Marshal.WriteByte(w.RawBuffer, i, (byte)0);
         }
     }
 }
示例#4
0
        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);
        }
示例#5
0
        // 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));
            }
        }
示例#6
0
        // compare a chuck of the context record contained between the two offsets
        private bool CheckContextChunk(IA64Context a1, IA64Context a2, int startOffset, int endOffset)
        {
            using (IContextDirectAccessor c1 = a1.OpenForDirectAccess())
            {
                using (IContextDirectAccessor c2 = a2.OpenForDirectAccess())
                {
                    for (int i = startOffset; i < endOffset; i++)
                    {
                        if (Marshal.ReadByte(c1.RawBuffer, i) != Marshal.ReadByte(c2.RawBuffer, i))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
示例#7
0
 /// <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);
         }
     }
 }
示例#8
0
        // This is a private contstructor for cloning Context objects.  It should not be used outside of this class.
        private IA64Context(INativeContext ctx)
        {
            this.m_size             = ctx.Size;
            this.m_platform         = ctx.Platform;
            this.m_imageFileMachine = ctx.ImageFileMachine;
            this.m_rawPtr           = Marshal.AllocHGlobal(this.Size);

            using (IContextDirectAccessor w = ctx.OpenForDirectAccess())
            {
                // The fact that Marshal.Copy cannot copy between to native memory locations is stupid.
                for (int i = 0; i < this.m_size; i++)
                {
                    // In theory, we could make this faster by copying larger units (i.e. Int64).  We get our sizes in bytes
                    // so for now we'll just copy bytes to keep our units straight.
                    byte chunk = Marshal.ReadByte(w.RawBuffer, i);
                    Marshal.WriteByte(this.RawPtr, i, chunk);
                }
            }
        }