Skip to content

Commit

Permalink
Remove SecurityCriticalDataForSet (#7161)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGoulet73 authored Oct 4, 2024
1 parent 56b7b4f commit 9fe50c7
Show file tree
Hide file tree
Showing 81 changed files with 938 additions and 1,046 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ internal static Uri SiteOfOrigin
{
get
{
Uri siteOfOrigin = SiteOfOriginForClickOnceApp;
if (siteOfOrigin == null)
{
// Calling FixFileUri because BaseDirectory will be a c:\\ style path
siteOfOrigin = BaseUriHelper.FixFileUri(new Uri(System.AppDomain.CurrentDomain.BaseDirectory));
}
// Calling FixFileUri because BaseDirectory will be a c:\\ style path
Uri siteOfOrigin = BaseUriHelper.FixFileUri(new Uri(System.AppDomain.CurrentDomain.BaseDirectory));
#if DEBUG
if (_traceSwitch.Enabled)
System.Diagnostics.Trace.TraceInformation(
Expand All @@ -64,40 +60,16 @@ internal static Uri SiteOfOrigin
return siteOfOrigin;
}
}

// we separated this from the rest of the code because this code is used for media permission
// tests in partial trust but we want to do this without hitting the code path for regular exe's
// as in the code above. This will get hit for click once apps, xbaps, xaml and xps
internal static Uri SiteOfOriginForClickOnceApp
{
get
{
// The ClickOnce API, ApplicationDeployment.IsNetworkDeployed, determines whether the app is network-deployed
// by getting the ApplicationDeployment.CurrentDeployment property and catch the exception it can throw.
// The exception is a first chance exception and caught, but it often confuses developers,
// and can also have a perf impact. So we change to cache the value of SiteofOrigin in Dev10 to avoid the
// exception being thrown too many times.
// An alternative is to cache the value of ApplicationDeployment.IsNetworkDeployed.
if (_siteOfOriginForClickOnceApp == null)
{
_siteOfOriginForClickOnceApp = new SecurityCriticalDataForSet<Uri>(null);
}

Invariant.Assert(_siteOfOriginForClickOnceApp != null);

return _siteOfOriginForClickOnceApp.Value.Value;
}
}

internal static Uri BrowserSource
{
get
{
return _browserSource.Value;
return _browserSource;
}
set
{
_browserSource.Value = value;
_browserSource = value;
}
}

Expand Down Expand Up @@ -244,8 +216,7 @@ protected override PackagePart GetPartCore(Uri uri)

#region Private Members

private static SecurityCriticalDataForSet<Uri> _browserSource;
private static SecurityCriticalDataForSet<Uri>? _siteOfOriginForClickOnceApp;
private static Uri _browserSource;

#endregion Private Members

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,33 +277,33 @@ internal unsafe class UnsafeUshortArray : UshortBuffer
{
private ushort* _array;

private SecurityCriticalDataForSet<int> _arrayLength;
private int _arrayLength;


internal UnsafeUshortArray(CheckedUShortPointer array, int arrayLength)
{
_array = array.Probe(0, arrayLength);
_arrayLength.Value = arrayLength;
_arrayLength = arrayLength;
}


public override ushort this[int index]
{
get
{
Invariant.Assert(index >= 0 && index < _arrayLength.Value);
Invariant.Assert(index >= 0 && index < _arrayLength);
return _array[index];
}
set
{
Invariant.Assert(index >= 0 && index < _arrayLength.Value);
Invariant.Assert(index >= 0 && index < _arrayLength);
_array[index] = value;
}
}

public override int Length
{
get { return _arrayLength.Value; }
get { return _arrayLength; }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace MS.Internal.TextFormatting
internal sealed class FullTextBreakpoint : TextBreakpoint
{
private TextMetrics _metrics; // full text metrics
private SecurityCriticalDataForSet<IntPtr> _ploline; // native object representing this break
private SecurityCriticalDataForSet<IntPtr> _penaltyResource; // unsafe handle to the internal factors used to determines penalty of the break. By default, the lifetime of this resource is managed by _ploline.
private IntPtr _ploline; // native object representing this break
private IntPtr _penaltyResource; // unsafe handle to the internal factors used to determines penalty of the break. By default, the lifetime of this resource is managed by _ploline.
private bool _isDisposed; // flag indicates whether this object is disposed
private bool _isLineTruncated; // flag indicates whether the line produced at this breakpoint is truncated.

Expand Down Expand Up @@ -85,7 +85,7 @@ out int bestFitIndex

IntPtr previousBreakRecord = IntPtr.Zero;
if (settings.PreviousLineBreak != null)
previousBreakRecord = settings.PreviousLineBreak.BreakRecord.Value;
previousBreakRecord = settings.PreviousLineBreak.BreakRecord;

// need not consider marker as tab since marker does not affect line metrics and it wasnt drawn.
fullText.SetTabs(context);
Expand All @@ -95,7 +95,7 @@ out int bestFitIndex
LsErr lserr = context.CreateBreaks(
fullText.GetBreakpointInternalCp(firstCharIndex),
previousBreakRecord,
paragraphCache.Ploparabreak.Value, // para breaking session
paragraphCache.Ploparabreak, // para breaking session
penaltyRestriction,
ref lsbreaks,
out bestFitIndex
Expand Down Expand Up @@ -179,10 +179,10 @@ int breakIndex
&lsbreaks.plslinfoArray[breakIndex]
);

_ploline = new SecurityCriticalDataForSet<IntPtr>(lsbreaks.pplolineArray[breakIndex]);
_ploline = lsbreaks.pplolineArray[breakIndex];

// keep the line penalty handle
_penaltyResource = new SecurityCriticalDataForSet<IntPtr>(lsbreaks.plinepenaltyArray[breakIndex]);
_penaltyResource = lsbreaks.plinepenaltyArray[breakIndex];

if (lsbreaks.plslinfoArray[breakIndex].fForcedBreak != 0)
_isLineTruncated = true;
Expand Down Expand Up @@ -213,11 +213,11 @@ private FullTextBreakpoint()
/// </summary>
protected override void Dispose(bool disposing)
{
if(_ploline.Value != IntPtr.Zero)
if(_ploline != IntPtr.Zero)
{
UnsafeNativeMethods.LoDisposeLine(_ploline.Value, !disposing);
_ploline.Value = IntPtr.Zero;
_penaltyResource.Value = IntPtr.Zero;
UnsafeNativeMethods.LoDisposeLine(_ploline, !disposing);
_ploline = IntPtr.Zero;
_penaltyResource = IntPtr.Zero;
_isDisposed = true;
GC.KeepAlive(this);
}
Expand All @@ -237,7 +237,7 @@ public override TextLineBreak GetTextLineBreak()
{
throw new ObjectDisposedException(SR.TextBreakpointHasBeenDisposed);
}
return _metrics.GetTextLineBreak(_ploline.Value);
return _metrics.GetTextLineBreak(_ploline);
}


Expand All @@ -249,14 +249,14 @@ public override TextLineBreak GetTextLineBreak()
/// We would make a correspondent call to notify our unmanaged wrapper to release them from duty of managing this
/// resource.
/// </remarks>
internal override SecurityCriticalDataForSet<IntPtr> GetTextPenaltyResource()
internal override IntPtr GetTextPenaltyResource()
{
if (_isDisposed)
{
throw new ObjectDisposedException(SR.TextBreakpointHasBeenDisposed);
}

LsErr lserr = UnsafeNativeMethods.LoRelievePenaltyResource(_ploline.Value);
LsErr lserr = UnsafeNativeMethods.LoRelievePenaltyResource(_ploline);
if (lserr != LsErr.None)
{
TextFormatterContext.ThrowExceptionFromLsError(SR.Format(SR.RelievePenaltyResourceFailure, lserr), lserr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ internal class FullTextLine : TextLine
private int _depthQueryMax; // maximum depth of reversals used in querying
private int _paragraphWidth; // paragraph width
private int _textMinWidthAtTrailing; // smallest text width excluding trailing whitespaces
private SecurityCriticalDataForSet<IntPtr> _ploline; // actual LS line
private SecurityCriticalDataForSet<IntPtr> _ploc; // actual LS context
private IntPtr _ploline; // actual LS line
private IntPtr _ploc; // actual LS context
private Overhang _overhang; // overhang metrics
private StatusFlags _statusFlags; // status flags of the line

Expand Down Expand Up @@ -156,11 +156,11 @@ public override void Dispose()
/// </summary>
private void DisposeInternal(bool finalizing)
{
if (_ploline.Value != System.IntPtr.Zero)
if (_ploline != System.IntPtr.Zero)
{
UnsafeNativeMethods.LoDisposeLine(_ploline.Value, finalizing);
UnsafeNativeMethods.LoDisposeLine(_ploline, finalizing);

_ploline.Value = System.IntPtr.Zero;
_ploline = System.IntPtr.Zero;
GC.KeepAlive(this);
}
}
Expand All @@ -178,7 +178,7 @@ private FullTextLine(TextFormattingMode textFormattingMode, bool justify, double
}
_metrics = new TextMetrics();
_metrics._pixelsPerDip = pixelsPerDip;
_ploline = new SecurityCriticalDataForSet<IntPtr>(IntPtr.Zero);
_ploline = IntPtr.Zero;
}


Expand Down Expand Up @@ -300,7 +300,7 @@ out lineWidths
}
}

_ploline.Value = ploline;
_ploline = ploline;

// get the exception in context before it is released
Exception callbackException = context.CallbackException;
Expand Down Expand Up @@ -592,7 +592,7 @@ MatrixTransform antiInversion
{
Rect boundingBox = Rect.Empty;

if (_ploline.Value != System.IntPtr.Zero)
if (_ploline != System.IntPtr.Zero)
{
TextFormatterContext context;
LsErr lserr = LsErr.None;
Expand All @@ -603,7 +603,7 @@ MatrixTransform antiInversion
{
context = _metrics._formatter.AcquireContext(
drawingState,
_ploc.Value
_ploc
);

// set the collector and send the line to LS to draw
Expand All @@ -614,7 +614,7 @@ MatrixTransform antiInversion
LSPOINT lsRefOrigin = new LSPOINT(0, _metrics._baselineOffset);

lserr = UnsafeNativeMethods.LoDisplayLine(
_ploline.Value,
_ploline,
ref lsRefOrigin,
1, // 0 - opaque, 1 - transparent
ref rect
Expand Down Expand Up @@ -864,7 +864,7 @@ private CharacterHit CharacterHitFromDistance(int hitTestDistance)
// assuming the first cp of the line
CharacterHit characterHit = new CharacterHit(_cpFirst, 0);

if(_ploline.Value == IntPtr.Zero)
if(_ploline == IntPtr.Zero)
{
// Returning the first cp for the empty line
return characterHit;
Expand Down Expand Up @@ -999,7 +999,7 @@ private int DistanceFromCharacterHit(CharacterHit characterHit)
{
int hitTestDistance = 0;

if (_ploline.Value == IntPtr.Zero)
if (_ploline == IntPtr.Zero)
{
// Returning start of the line for empty line
return hitTestDistance;
Expand Down Expand Up @@ -1147,7 +1147,7 @@ CharacterHit characterHit

TextFormatterImp.VerifyCaretCharacterHit(characterHit, _cpFirst, _metrics._cchLength);

if (_ploline.Value == System.IntPtr.Zero)
if (_ploline == System.IntPtr.Zero)
{
return characterHit;
}
Expand Down Expand Up @@ -1240,7 +1240,7 @@ CaretDirection direction

TextFormatterImp.VerifyCaretCharacterHit(characterHit, _cpFirst, _metrics._cchLength);

if (_ploline.Value == IntPtr.Zero)
if (_ploline == IntPtr.Zero)
{
return characterHit;
}
Expand Down Expand Up @@ -1517,7 +1517,7 @@ int textLength
textLength = (_cpFirst + _metrics._cchLength - firstTextSourceCharacterIndex);
}

if (_ploline.Value == IntPtr.Zero)
if (_ploline == IntPtr.Zero)
{
return CreateDegenerateBounds();
}
Expand Down Expand Up @@ -2129,11 +2129,11 @@ public override IEnumerable<IndexedGlyphRun> GetIndexedGlyphRuns()

IEnumerable<IndexedGlyphRun> result = null;

if (_ploline.Value != System.IntPtr.Zero)
if (_ploline != System.IntPtr.Zero)
{
TextFormatterContext context = _metrics._formatter.AcquireContext(
new DrawingState(null, new Point(0, 0), null, this),
_ploc.Value
_ploc
);

//
Expand All @@ -2143,7 +2143,7 @@ public override IEnumerable<IndexedGlyphRun> GetIndexedGlyphRuns()

LSPOINT point = new LSPOINT(0, 0);
lserr = UnsafeNativeMethods.LoEnumLine(
_ploline.Value, // line
_ploline, // line
false, // reverse enumeration
false, // geometry needed
ref point // starting point
Expand Down Expand Up @@ -2452,7 +2452,7 @@ private void QueryLinePointPcp(
out LsTextCell lsTextCell
)
{
Debug.Assert(_ploline.Value != IntPtr.Zero);
Debug.Assert(_ploline != IntPtr.Zero);

LsErr lserr = LsErr.None;
lsTextCell = new LsTextCell();
Expand All @@ -2462,7 +2462,7 @@ out LsTextCell lsTextCell
{
LSPOINT pt = new LSPOINT((int)ptQuery.X, (int)ptQuery.Y);
lserr = UnsafeNativeMethods.LoQueryLinePointPcp(
_ploline.Value,
_ploline,
ref pt,
subLineInfo.Length,
(System.IntPtr)plsqsubl,
Expand Down Expand Up @@ -2505,7 +2505,7 @@ private void QueryLineCpPpoint(
out LsTextCell lsTextCell
)
{
Debug.Assert(_ploline.Value != IntPtr.Zero);
Debug.Assert(_ploline != IntPtr.Zero);

LsErr lserr = LsErr.None;

Expand All @@ -2519,7 +2519,7 @@ out LsTextCell lsTextCell
fixed(LsQSubInfo* plsqsubl = subLineInfo)
{
lserr = UnsafeNativeMethods.LoQueryLineCpPpoint(
_ploline.Value,
_ploline,
lscpValidQuery,
subLineInfo.Length,
(System.IntPtr)plsqsubl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ IntPtr ploc
if(context.Owner == null)
break;
}
else if (ploc == context.Ploc.Value)
else if (ploc == context.Ploc)
{
// LS requires that we use the exact same context for line
// destruction or hittesting (part of the reason is that LS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ internal TextLineBreak GetTextLineBreak(IntPtr ploline)
{
return new TextLineBreak(
_lastRun.TextModifierScope,
new SecurityCriticalDataForSet<IntPtr>(pbreakrec)
pbreakrec
);
}
return (pbreakrec != IntPtr.Zero) ? new TextLineBreak(null, new SecurityCriticalDataForSet<IntPtr>(pbreakrec)) : null;
return (pbreakrec != IntPtr.Zero) ? new TextLineBreak(null, pbreakrec) : null;
}


Expand Down
Loading

0 comments on commit 9fe50c7

Please sign in to comment.