-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Poison address-exposed user variables in debug (#54685)
* Poison address exposed user variables in debug code Fix #13072 * Run jit-format * Use named scratch register and kill it in LSRA * Enable it unconditionally for testing purposes * Remove unnecessary modified reg on ARM * Fix OSR and get rid of test code * Remove a declaration * Undo modified comment and use modulo instead of and * Add a test * Rephrase comment Co-authored-by: Kunal Pathak <[email protected]> * Disable poisoning test on mono * Remove outdated line Co-authored-by: Kunal Pathak <[email protected]>
- Loading branch information
1 parent
09785ef
commit b8beed2
Showing
10 changed files
with
162 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
public class Program | ||
{ | ||
[SkipLocalsInit] | ||
public static unsafe int Main() | ||
{ | ||
bool result = true; | ||
|
||
int poisoned; | ||
Unsafe.SkipInit(out poisoned); | ||
result &= VerifyPoison(&poisoned, sizeof(int)); | ||
|
||
GCRef zeroed; | ||
Unsafe.SkipInit(out zeroed); | ||
result &= VerifyZero(Unsafe.AsPointer(ref zeroed), Unsafe.SizeOf<GCRef>()); | ||
|
||
WithoutGCRef poisoned2; | ||
Unsafe.SkipInit(out poisoned2); | ||
result &= VerifyPoison(&poisoned2, sizeof(WithoutGCRef)); | ||
|
||
return result ? 100 : 101; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static unsafe bool VerifyPoison(void* val, int size) | ||
=> AllEq(new Span<byte>(val, size), 0xCD); | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static unsafe bool VerifyZero(void* val, int size) | ||
=> AllEq(new Span<byte>(val, size), 0); | ||
|
||
private static unsafe bool AllEq(Span<byte> span, byte byteVal) | ||
{ | ||
foreach (byte b in span) | ||
{ | ||
if (b != byteVal) | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private struct GCRef | ||
{ | ||
public object ARef; | ||
} | ||
|
||
private struct WithoutGCRef | ||
{ | ||
public double ADouble; | ||
public int ANumber; | ||
public float AFloat; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<DebugType>PdbOnly</DebugType> | ||
<Optimize>False</Optimize> | ||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters