// // Copyright (c) Microsoft Corporation. All rights reserved. // /*******************************************************************/ /* WARNING */ /* This file should be identical in the Bartok and Singularity */ /* depots. Master copy resides in Bartok Depot. Changes should be */ /* made to Bartok Depot and propagated to Singularity Depot. */ /*******************************************************************/ namespace System { using System.GCs; using System.Runtime.CompilerServices; /// /// Abstraction for information about the stack height. This is currently /// only used by the logging undo code for determining if a pointer write /// occurred in stack space allocated after the tryall section began. /// /// StackHeight does not record information about the call stack. /// /// The current implementation is hardwired to a stack model where the stack /// is a single contiguous piece of memory that grows by putting smaller /// values into the stack pointer. /// [RequiredByBartok] internal struct StackHeight { /// /// Interpret the pointer as a stack pointer to determine the stack /// height. /// /// Pointer into the stack. /// The stack height of the location pointed to by the /// argument. internal StackHeight(UIntPtr stackPointer) { VTable.Assert(stackPointer == UIntPtr.Zero || (PageTable.Type(PageTable.Page(stackPointer)) == PageType.Stack)); this.stackPointer = stackPointer; } /// /// Interpret the pointer as a stack pointer to determine the stack /// height. /// /// Pointer into the stack. /// The stack height of the location pointed to by the /// argument. public static explicit operator StackHeight(UIntPtr stackPointer) { return new StackHeight(stackPointer); } /// /// Get the current stack height. /// /// The current stack height. [Intrinsic] internal static extern StackHeight GetStackHeight(); /// /// Check if the first stack height represents a deeper location on the /// stack. /// /// The first stack height to compare. /// The second stack height to compare. /// True iff the first height is deeper in the stack than the /// second height. internal static bool Deeper(StackHeight first, StackHeight second) { VTable.Assert(first.stackPointer != UIntPtr.Zero); VTable.Assert(second.stackPointer != UIntPtr.Zero); return first.stackPointer <= second.stackPointer; } public override string ToString() { return stackPointer.ToString(); } /// /// The value of the stack pointer when the stack height was taken. /// private UIntPtr stackPointer; } }