-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NativeAOT] Add null checks into memcpy/memset helpers (#98547)
- Loading branch information
1 parent
9a391bc
commit 6d4fc1a
Showing
3 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...lr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/MemoryHelpers.cs
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,33 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime; | ||
|
||
namespace Internal.Runtime.CompilerHelpers | ||
{ | ||
/// <summary> | ||
/// These methods are used to implement memcpy and memset intrinsics with null checks. | ||
/// </summary> | ||
internal static class MemoryHelpers | ||
{ | ||
private static unsafe void MemSet(ref byte dest, byte value, nuint size) | ||
{ | ||
if (size > 0) | ||
{ | ||
_ = dest; | ||
SpanHelpers.Fill(ref dest, size, value); | ||
} | ||
} | ||
|
||
private static unsafe void MemCopy(ref byte dest, ref byte src, nuint size) | ||
{ | ||
if (size > 0) | ||
{ | ||
_ = dest; | ||
_ = src; | ||
Buffer.Memmove(ref dest, ref src, size); | ||
} | ||
} | ||
} | ||
} |
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