public static T SimpleRefWrap <T>(ref T tgt, SimpleRefDel <T> originalCode, String instrMethod) { using (_ProtectingThreadContext.Acquire()) { if (WrapperSentry.Wrap()) { ClrSyncManager manager = ClrSyncManager.SyncManager; manager.SetMethodInfo(instrMethod); if (manager.TrackGC) { return(ref_wrap_gcaddr(manager, ref tgt, originalCode)); } else if (manager.TrackVolatile) { return(ref_wrap_uintptr(manager, ref tgt, originalCode)); } else { return(originalCode(ref tgt)); } } else { return(originalCode(ref tgt)); } } }
private Exception raw_access(UIntPtr address, uint size, bool @volatile, bool write) { using (_ProtectingThreadContext.Acquire()) { try { if (WrapperSentry.Wrap()) { using (new WrapperSentry()) { GCAddress gcAddress; if (TrackGC && GCAddress.FromAddress(address, out gcAddress)) { try { if (@volatile) { SetMethodInfo(write ? "vol.write" : "vol.read"); SyncVarAccess(gcAddress, write ? MSyncVarOp.RWVAR_WRITE : MSyncVarOp.RWVAR_READ); CommitSyncVarAccess(); } else { SetMethodInfo(write ? "write" : "read"); DataVarAccess(gcAddress, write); } } finally { gcAddress.Release(); } } else { // TODO: take size into account if (@volatile) { SetMethodInfo(write ? "vol.write" : "vol.read"); SyncVarAccess(address, write ? MSyncVarOp.RWVAR_WRITE : MSyncVarOp.RWVAR_READ); CommitSyncVarAccess(); } else { SetMethodInfo(write ? "write" : "read"); DataVarAccess(address, write); } } } } } catch (Exception e) { return(e); } } return(null); }
public Exception ObjectAccessThreadMonitor_AllocationAccess(object allocatedObject) { // we are screwed if .Acquire allocates objects - *uck using (_ProtectingThreadContext.Acquire()) { // This flag prevents recursive calls to new (we allocate objects in the wrapper) // This flag is protected by the Lock acquire above if (InAllocationAccess) { return(null); } try { InAllocationAccess = true; if (WrapperSentry.Wrap()) { // Note that we are not entering wrappers here // Because we want the thread forked to be under CHESS' control // However, the check for .Wrap() guarantees that this wrapper is disabled for objects allocated by our wrappers System.GC.SuppressFinalize(allocatedObject); ThreadStart finalizerThreadStart = new ThreadStart(() => { try { typeof(Object).GetMethod("Finalize", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(allocatedObject, null); } catch (TargetInvocationException e) { throw e.InnerException; } }); Thread finalizerThread = Helper.ConstructThread <ThreadStart>( delegate(ThreadStart del) { return(new Thread(del)); }, finalizerThreadStart, Helper.WrapThreadStart ); Helper.StartHelper(finalizerThread, null, false); } } catch (Exception e) { InAllocationAccess = false; return(e); } InAllocationAccess = false; } return(null); }
public static void SimpleWrap <T>(ref T r, SimpleDelManagerRef <T> instrumentedCode, SimpleDelRef <T> originalCode) { using (_ProtectingThreadContext.Acquire()) { if (WrapperSentry.Wrap()) { using (new WrapperSentry()) { ClrSyncManager manager = ClrSyncManager.SyncManager; instrumentedCode(manager, ref r); } } else { originalCode(ref r); } } }
public static T SimpleWrap <T>(SimpleDelManager <T> instrumentedCode, SimpleDel <T> originalCode) { using (_ProtectingThreadContext.Acquire()) { if (WrapperSentry.Wrap()) { using (new WrapperSentry()) { ClrSyncManager manager = ClrSyncManager.SyncManager; return(instrumentedCode(manager)); } } else { return(originalCode()); } } }
public static T SimpleContextExposingWrap <T>(SimpleDelManagerContext <T> instrumentedCode, SimpleDel <T> originalCode) { IDisposable protectingcontext = _ProtectingThreadContext.Acquire(); try { if (WrapperSentry.Wrap()) { using (new WrapperSentry()) { ClrSyncManager manager = ClrSyncManager.SyncManager; return(instrumentedCode(manager, ref protectingcontext)); } } else { return(originalCode()); } } finally { protectingcontext.Dispose(); } }
public override void LeaveChess() { WrapperSentry.LeaveChessImpl(); }
public override void EnterChess() { WrapperSentry.EnterChessImpl(); }