-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[wasm] improve memory access and marshaling range checks #64845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d119e50
* new memory accessors setI52, setI64Big, getI52, getI64Big
pavelsavara a9a8bcc
doc
pavelsavara e6c06c4
tests
pavelsavara 27cf6b8
feedback from @kg
pavelsavara b6f033c
fix
pavelsavara 4547c85
Merge branch 'main' into wasm_resize_and_int64
pavelsavara 5b5e6b5
- made assert silent on Release config
pavelsavara 7982e54
- fixed marshaling of uint32, uint16 and byte to be unsigned
pavelsavara 3e20335
inlined asserts
pavelsavara 3e3e658
fix test
pavelsavara a11bcf3
fix message
pavelsavara 067e9db
optimize inline
pavelsavara 7b2e211
rename mono_assert and make sure we replace them all
pavelsavara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
128 changes: 128 additions & 0 deletions
128
...InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MemoryTests.cs
This file contains hidden or 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,128 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
| using Xunit; | ||
|
|
||
| namespace System.Runtime.InteropServices.JavaScript.Tests | ||
| { | ||
| public class MemoryTests | ||
| { | ||
| [Theory] | ||
| [InlineData(-1L)] | ||
| [InlineData(-42L)] | ||
| [InlineData(int.MinValue)] | ||
| [InlineData(-9007199254740991L)]//MIN_SAFE_INTEGER | ||
| [InlineData(1L)] | ||
| [InlineData(0L)] | ||
| [InlineData(42L)] | ||
| [InlineData(int.MaxValue)] | ||
| [InlineData(0xF_FFFF_FFFFL)] | ||
| [InlineData(9007199254740991L)]//MAX_SAFE_INTEGER | ||
| public static unsafe void Int52TestOK(long value) | ||
| { | ||
| long expected = value; | ||
| long actual2 = value; | ||
| var bagFn = new Function("ptr", "ptr2", @" | ||
| const value=globalThis.App.MONO.getI52(ptr); | ||
| globalThis.App.MONO.setI52(ptr2, value); | ||
| return value;"); | ||
|
|
||
| uint ptr = (uint)Unsafe.AsPointer(ref expected); | ||
| uint ptr2 = (uint)Unsafe.AsPointer(ref actual2); | ||
|
|
||
| object o = bagFn.Call(null, ptr, ptr2); | ||
| if (value < int.MaxValue && value > int.MinValue) | ||
| { | ||
| Assert.IsType<int>(o); | ||
| long actual = (int)o; | ||
| Assert.Equal(expected, actual); | ||
| } | ||
| Assert.Equal(expected, actual2); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(uint.MinValue)] | ||
| [InlineData(1L)] | ||
| [InlineData(0L)] | ||
| [InlineData(42L)] | ||
| [InlineData(uint.MaxValue)] | ||
| [InlineData(0xF_FFFF_FFFFL)] | ||
| [InlineData(9007199254740991L)]//MAX_SAFE_INTEGER | ||
| public static unsafe void UInt52TestOK(ulong value) | ||
| { | ||
| ulong expected = value; | ||
| ulong actual2 = value; | ||
| var bagFn = new Function("ptr", "ptr2", @" | ||
| const value=globalThis.App.MONO.getI52(ptr); | ||
| globalThis.App.MONO.setU52(ptr2, value); | ||
| return value;"); | ||
|
|
||
| uint ptr = (uint)Unsafe.AsPointer(ref expected); | ||
| uint ptr2 = (uint)Unsafe.AsPointer(ref actual2); | ||
|
|
||
| object o = bagFn.Call(null, ptr, ptr2); | ||
| if (value < int.MaxValue) | ||
| { | ||
| Assert.IsType<int>(o); | ||
| ulong actual = (ulong)(long)(int)o; | ||
| Assert.Equal(expected, actual); | ||
| } | ||
| Assert.Equal(expected, actual2); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(double.NegativeInfinity)] | ||
| [InlineData(double.PositiveInfinity)] | ||
| [InlineData(double.MinValue)] | ||
| [InlineData(double.MaxValue)] | ||
| [InlineData(double.Pi)] | ||
| [InlineData(9007199254740993.0)]//MAX_SAFE_INTEGER +2 | ||
| public static unsafe void Int52TestRange(double value) | ||
| { | ||
| long actual = 0; | ||
| uint ptr = (uint)Unsafe.AsPointer(ref actual); | ||
| var bagFn = new Function("ptr", "value", @" | ||
| globalThis.App.MONO.setI52(ptr, value);"); | ||
| var ex=Assert.Throws<JSException>(() => bagFn.Call(null, ptr, value)); | ||
| Assert.Contains("Overflow: value out of Number.isSafeInteger range", ex.Message); | ||
|
|
||
| double expectedD = value; | ||
| uint ptrD = (uint)Unsafe.AsPointer(ref expectedD); | ||
| var bagFnD = new Function("ptr", "value", @" | ||
| globalThis.App.MONO.getI52(ptr);"); | ||
| var exD = Assert.Throws<JSException>(() => bagFn.Call(null, ptr, value)); | ||
| Assert.Contains("Overflow: value out of Number.isSafeInteger range", ex.Message); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(-1.0)] | ||
| public static unsafe void UInt52TestRange(double value) | ||
| { | ||
| long actual = 0; | ||
| uint ptr = (uint)Unsafe.AsPointer(ref actual); | ||
| var bagFn = new Function("ptr", "value", @" | ||
| globalThis.App.MONO.setU52(ptr, value);"); | ||
| var ex=Assert.Throws<JSException>(() => bagFn.Call(null, ptr, value)); | ||
| Assert.Contains("Can't convert negative Number into UInt64", ex.Message); | ||
|
|
||
| double expectedD = value; | ||
| uint ptrD = (uint)Unsafe.AsPointer(ref expectedD); | ||
| var bagFnD = new Function("ptr", "value", @" | ||
| globalThis.App.MONO.getU52(ptr);"); | ||
| var exD = Assert.Throws<JSException>(() => bagFn.Call(null, ptr, value)); | ||
| Assert.Contains("Can't convert negative Number into UInt64", ex.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static unsafe void Int52TestNaN() | ||
| { | ||
| long actual = 0; | ||
| uint ptr = (uint)Unsafe.AsPointer(ref actual); | ||
| var bagFn = new Function("ptr", "value", @" | ||
| globalThis.App.MONO.setI52(ptr, value);"); | ||
| var ex=Assert.Throws<JSException>(() => bagFn.Call(null, ptr, double.NaN)); | ||
| Assert.Contains("Can't convert Number.Nan into Int64", ex.Message); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.