diff options
author | Jan Kotas <jkotas@microsoft.com> | 2017-12-16 21:16:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-16 21:16:59 +0300 |
commit | be470f823f6e1de3eaf3cc96a81acb36fd8c93c7 (patch) | |
tree | e547e33133ff94c27e006e8fdc304ee4ea5e321d | |
parent | 4c3a30c4a84ad71cc882a78641beb1a50bcdd589 (diff) | |
parent | efab81562924f93a2e72d41a70391996a6acae5c (diff) |
Merge pull request #5128 from dotnet/master
Merge master to nmirror
36 files changed, 360 insertions, 233 deletions
diff --git a/buildpipeline/DotNet-CoreRT-Publish.json b/buildpipeline/DotNet-CoreRT-Publish.json index ed451610e..3589bf04e 100644 --- a/buildpipeline/DotNet-CoreRT-Publish.json +++ b/buildpipeline/DotNet-CoreRT-Publish.json @@ -94,7 +94,7 @@ "scriptType": "inlineScript", "scriptName": "", "arguments": "", - "inlineScript": "if ($env:Configuration -ne \"Release\") { exit }\n\n& $env:Build_SourcesDirectory\\scripts\\DotNet-Trusted-Publish\\Embed-Index.ps1 `\n $env:Pipeline_SourcesDirectory\\packages\\AzureTransfer\\Windows_NT.x64.$env:Configuration\\$env:AzureContainerSymbolPackageGlob `\n $env:Build_StagingDirectory\\IndexedSymbolPackages", + "inlineScript": "if ($env:Configuration -ne \"Release\") { exit }\n\n& $env:Build_SourcesDirectory\\scripts\\DotNet-Trusted-Publish\\Embed-Index.ps1 `\n $env:Pipeline_SourcesDirectory\\packages\\AzureTransfer\\$env:Configuration\\$env:AzureContainerSymbolPackageGlob `\n $env:Build_StagingDirectory\\IndexedSymbolPackages", "workingFolder": "", "failOnStandardError": "true" } @@ -152,7 +152,7 @@ "scriptType": "inlineScript", "scriptName": "", "arguments": "$(MyGetApiKey)", - "inlineScript": "param($ApiKey)\nif ($env:Configuration -ne \"Release\") { exit }\n& $env:CustomNuGetPath push $env:Pipeline_SourcesDirectory\\packages\\AzureTransfer\\Windows_NT.x64.$env:Configuration\\$env:AzureContainerPackageGlob $ApiKey -Source $env:MyGetFeedUrl -Timeout 3600", + "inlineScript": "param($ApiKey)\nif ($env:Configuration -ne \"Release\") { exit }\n& $env:CustomNuGetPath push $env:Pipeline_SourcesDirectory\\packages\\AzureTransfer\\$env:Configuration\\$env:AzureContainerPackageGlob $ApiKey -Source $env:MyGetFeedUrl -Timeout 3600", "workingFolder": "", "failOnStandardError": "true" } @@ -192,7 +192,7 @@ "scriptType": "inlineScript", "scriptName": "", "arguments": "-gitHubAuthToken $(UpdatePublishedVersions.AuthToken) -root $(Pipeline.SourcesDirectory)", - "inlineScript": "param($gitHubAuthToken, $root)\nif ($env:Configuration -ne \"Release\") { exit }\ncd $root\n. $root\\buildscripts\\UpdatePublishedVersions.ps1 `\n -gitHubUser dotnet-build-bot -gitHubEmail dotnet-build-bot@microsoft.com `\n -gitHubAuthToken $gitHubAuthToken `\n -versionsRepoOwner $env:VersionsRepoOwner -versionsRepo $env:VersionsRepo `\n -versionsRepoPath build-info/dotnet/$env:GitHubRepositoryName/$env:SourceBranch `\n -nupkgPath $root\\packages\\AzureTransfer\\Windows_NT.x64.$env:Configuration\\$env:AzureContainerPackageGlob", + "inlineScript": "param($gitHubAuthToken, $root)\nif ($env:Configuration -ne \"Release\") { exit }\ncd $root\n. $root\\buildscripts\\UpdatePublishedVersions.ps1 `\n -gitHubUser dotnet-build-bot -gitHubEmail dotnet-build-bot@microsoft.com `\n -gitHubAuthToken $gitHubAuthToken `\n -versionsRepoOwner $env:VersionsRepoOwner -versionsRepo $env:VersionsRepo `\n -versionsRepoPath build-info/dotnet/$env:GitHubRepositoryName/$env:SourceBranch `\n -nupkgPath $root\\packages\\AzureTransfer\\$env:Configuration\\$env:AzureContainerPackageGlob", "workingFolder": "", "failOnStandardError": "true" } @@ -135,7 +135,7 @@ <!-- Use the shared tools host and runtime for testing --> <TestHostRootPath Condition="'$(TestHostRootPath)' == ''">$(DotnetCliPath)</TestHostRootPath> - <PackageOutputPath Condition="'$(PackageOutputPath)'==''">$(PackageOutputRoot)$(OSPlatformConfig)/</PackageOutputPath> + <PackageOutputPath Condition="'$(PackageOutputPath)'==''">$(PackageOutputRoot)$(BinDirConfiguration)/</PackageOutputPath> <SymbolPackageOutputPath Condition="'$(SymbolPackageOutputPath)'==''">$(PackageOutputPath)symbols/</SymbolPackageOutputPath> <!-- Folder where we will drop the Nuget package for the toolchain --> diff --git a/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.builds b/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.builds index 841203881..3c6ea9fc8 100644 --- a/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.builds +++ b/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.builds @@ -1,12 +1,15 @@ <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <ItemGroup> <Project Include="Microsoft.DotNet.ILCompiler.pkgproj" > - <OSGroup>Windows_NT</OSGroup> - <OSGroup>Linux</OSGroup> - <OSGroup>Mac</OSGroup> + <OSGroup>AnyOS</OSGroup> </Project> + + <!-- Include this to force a build of platform-specific packages--> + <Project Include="$(MSBuildThisFileDirectory)\TargetSpecific\Microsoft.DotNet.ILCompiler.pkgproj" /> + </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" /> </Project> diff --git a/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index a94ce651b..ac7f6c2b1 100644 --- a/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -5,44 +5,23 @@ <BaseLinePackageDependencies>false</BaseLinePackageDependencies> <PackagePlatforms>x64;</PackagePlatforms> <PreventImplementationReference>true</PreventImplementationReference> + <RestorePackages>true</RestorePackages> <SkipValidatePackage>true</SkipValidatePackage> <IncludeSymbolsInPackage Condition="'$(IncludeSymbolsInPackage)' == ''">true</IncludeSymbolsInPackage> - + <!-- Mark this package as a lineup (meta-) package --> + <IsLineupPackage Condition="'$(IsLineupPackage)' == ''">true</IsLineupPackage> <!-- Override this property so that the package name won't look like runtime.[RID].[TFM].[ID] --> <PackageTargetRuntime></PackageTargetRuntime> </PropertyGroup> + <ItemGroup> - <File Include="$(MSBuildThisFileDirectory)\Microsoft.DotNet.ILCompiler.targets" > - <TargetPath>build</TargetPath> - </File> <File Include="$(PackageSourceDirectory)\BuildIntegration\*"> - <TargetPath>targets</TargetPath> - </File> - <File Include="$(BaseOutputPath)\$(OSPlatformConfig)\tools\*" Exclude="$(BaseOutputPath)\$(OSPlatformConfig)\tools\*.pdb"> - <TargetPath>tools</TargetPath> - </File> - <File Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\*" Exclude="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\*.pdb"> - <TargetPath>sdk</TargetPath> - </File> - <File Include="$(BaseOutputPath)\$(OSPlatformConfig)\framework\*.dll"> - <TargetPath>framework</TargetPath> + <TargetPath>build</TargetPath> </File> - <!-- Workaround to avoid linker warnings on Windows - include all pdb files for static native libraries --> - <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrapper.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrapper.pdb"> - <TargetPath>sdk</TargetPath> - </File> - <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrappercpp.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrappercpp.pdb"> - <TargetPath>sdk</TargetPath> - </File> - <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrapperdll.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrapperdll.pdb"> - <TargetPath>sdk</TargetPath> - </File> - <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\Runtime.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\Runtime.pdb"> - <TargetPath>sdk</TargetPath> - </File> - <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\PortableRuntime.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\PortableRuntime.pdb"> - <TargetPath>sdk</TargetPath> + <!-- This assembly is needed so the build tasks can be resolved and run from the metapackage --> + <File Include="$(BaseOutputPath)\$(OSPlatformConfig)\tools\\ILCompiler.Build.Tasks.dll" Exclude="$(BaseOutputPath)\$(OSPlatformConfig)\tools\*.pdb"> + <TargetPath>tools</TargetPath> </File> </ItemGroup> diff --git a/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.targets b/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.targets deleted file mode 100644 index 28e6f9aa7..000000000 --- a/pkg/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.targets +++ /dev/null @@ -1,7 +0,0 @@ -<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <_ILCompilerRootDir>$(MSBuildThisFileDirectory)../</_ILCompilerRootDir> - <IlCompilerTargetsDir>$(_ILCompilerRootDir)targets/</IlCompilerTargetsDir> - </PropertyGroup> - <Import Project="$(IlCompilerTargetsDir)/Microsoft.NETCore.Native.targets"/> -</Project> diff --git a/pkg/Microsoft.DotNet.ILCompiler/TargetSpecific/Microsoft.DotNet.ILCompiler.pkgproj b/pkg/Microsoft.DotNet.ILCompiler/TargetSpecific/Microsoft.DotNet.ILCompiler.pkgproj new file mode 100644 index 000000000..df63fb391 --- /dev/null +++ b/pkg/Microsoft.DotNet.ILCompiler/TargetSpecific/Microsoft.DotNet.ILCompiler.pkgproj @@ -0,0 +1,53 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + + <PropertyGroup> + <PackageTargetRuntime Condition="'$(OSGroup)' == 'Windows_NT'">win-x64</PackageTargetRuntime> + <PackageTargetRuntime Condition="'$(OSGroup)' == 'Linux'">linux-x64</PackageTargetRuntime> + <PackageTargetRuntime Condition="'$(OSGroup)' == 'OSX'">osx-x64</PackageTargetRuntime> + </PropertyGroup> + + <!-- This target defines files and properties that need to be included in the package regardless of platform --> + <PropertyGroup> + <SkipPackageFileCheck>true</SkipPackageFileCheck> + <BaseLinePackageDependencies>false</BaseLinePackageDependencies> + <PackagePlatforms>x64;</PackagePlatforms> + <PreventImplementationReference>true</PreventImplementationReference> + <SkipValidatePackage>true</SkipValidatePackage> + <IncludeSymbolsInPackage Condition="'$(IncludeSymbolsInPackage)' == ''">true</IncludeSymbolsInPackage> + </PropertyGroup> + + <ItemGroup> + <File Include="$(PackageSourceDirectory)\BuildIntegration\*"> + <TargetPath>targets</TargetPath> + </File> + <File Include="$(BaseOutputPath)\$(OSPlatformConfig)\tools\*" Exclude="$(BaseOutputPath)\$(OSPlatformConfig)\tools\*.pdb"> + <TargetPath>tools</TargetPath> + </File> + <File Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\*" Exclude="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\*.pdb"> + <TargetPath>sdk</TargetPath> + </File> + <File Include="$(BaseOutputPath)\$(OSPlatformConfig)\framework\*"> + <TargetPath>framework</TargetPath> + </File> + <!-- Workaround to avoid linker warnings on Windows - include all pdb files for static native libraries --> + <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrapper.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrapper.pdb"> + <TargetPath>sdk</TargetPath> + </File> + <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrappercpp.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrappercpp.pdb"> + <TargetPath>sdk</TargetPath> + </File> + <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrapperdll.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\bootstrapperdll.pdb"> + <TargetPath>sdk</TargetPath> + </File> + <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\Runtime.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\Runtime.pdb"> + <TargetPath>sdk</TargetPath> + </File> + <File Condition="Exists('$(BaseOutputPath)\$(OSPlatformConfig)\sdk\PortableRuntime.pdb')" Include="$(BaseOutputPath)\$(OSPlatformConfig)\sdk\PortableRuntime.pdb"> + <TargetPath>sdk</TargetPath> + </File> + </ItemGroup> + <Target Name="GetPackageDependencies"/> + + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\src\dir.targets" /> +</Project> diff --git a/src/BuildIntegration/BuildFrameworkNativeObjects.proj b/src/BuildIntegration/BuildFrameworkNativeObjects.proj index 806b087f4..6affd6d3e 100644 --- a/src/BuildIntegration/BuildFrameworkNativeObjects.proj +++ b/src/BuildIntegration/BuildFrameworkNativeObjects.proj @@ -8,7 +8,9 @@ <BuildingFrameworkLibrary>true</BuildingFrameworkLibrary> </PropertyGroup> - <Import Project="Microsoft.NETCore.Native.targets" /> + <!-- Part of workaround for lack of secondary build artifact import - https://github.com/Microsoft/msbuild/issues/2807 --> + <Import Project="$(MSBuildThisFileDirectory)\Microsoft.DotNet.ILCompiler.targets" Condition="'$(IlcCalledViaPackage)' == 'true'"/> + <Import Project="Microsoft.NETCore.Native.targets" Condition="'$(IlcCalledViaPackage)' == ''"/> <Target Name="BuildAllFrameworkLibraries" Inputs="@(DefaultFrameworkAssemblies)" diff --git a/src/BuildIntegration/Microsoft.DotNet.ILCompiler.targets b/src/BuildIntegration/Microsoft.DotNet.ILCompiler.targets new file mode 100644 index 000000000..0009363a3 --- /dev/null +++ b/src/BuildIntegration/Microsoft.DotNet.ILCompiler.targets @@ -0,0 +1,32 @@ +<Project + xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <DeployAppHost>false</DeployAppHost> + + <!-- Part of workaround for lack of secondary build artifact import - https://github.com/Microsoft/msbuild/issues/2807 --> + <!-- Define the name of the runtime specific compiler package to import --> + <RuntimeIlcPackageName Condition="'$(RuntimeIdentifier)' != ''">runtime.$(RuntimeIdentifier).Microsoft.DotNet.ILCompiler</RuntimeIlcPackageName> + <IlcCalledViaPackage>true</IlcCalledViaPackage> + + <!-- If CoreRT is being consumed via its package, runtime-specific properties must be set before compilation can proceed --> + <ImportRuntimeIlcPackageTargetDependsOn>RunResolvePackageDependencies</ImportRuntimeIlcPackageTargetDependsOn> + <IlcSetupPropertiesDependsOn>ImportRuntimeIlcPackageTarget</IlcSetupPropertiesDependsOn> + <IlcDynamicBuildPropertyDependencies>SetupProperties</IlcDynamicBuildPropertyDependencies> + + </PropertyGroup> + + <!-- Part of workaround for lack of secondary build artifact import - https://github.com/Microsoft/msbuild/issues/2807 --> + <!-- Locate the runtime package according to the current target runtime --> + <Target Name="ImportRuntimeIlcPackageTarget" Condition="'$(BuildingFrameworkLibrary)' != 'true' AND $(IlcCalledViaPackage) == 'true'" DependsOnTargets="$(ImportRuntimeIlcPackageTargetDependsOn)" BeforeTargets="Publish"> + <!-- CoreRT SDK and Framework Assemblies need to be defined to avoid CoreCLR implementations being set as compiler inputs --> + <Error Condition="'@(PackageDefinitions)' == ''" Text="The PackageDefinitions ItemGroup is required for target ImportRuntimeIlcPackageTarget" /> + <ItemGroup> + <RuntimePackage Include="@(PackageDefinitions)" Condition="'%(PackageDefinitions.Name)' == '$(RuntimeIlcPackageName)'" /> + </ItemGroup> + <CreateProperty Value="%(RuntimePackage.ResolvedPath)"> + <Output TaskParameter="Value" PropertyName="RuntimePackagePath"/> + </CreateProperty> + </Target> + + <Import Project="$(MSBuildThisFileDirectory)\Microsoft.NETCore.Native.targets" /> +</Project> diff --git a/src/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/BuildIntegration/Microsoft.NETCore.Native.Publish.targets index a7a6d4ac6..12743b911 100644 --- a/src/BuildIntegration/Microsoft.NETCore.Native.Publish.targets +++ b/src/BuildIntegration/Microsoft.NETCore.Native.Publish.targets @@ -1,7 +1,7 @@ <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> - <BuildTasksPath Condition="'$(BuildTasksPath)' == ''">$(MSBuildThisFileDirectory)..\tools\ILCompiler.Build.Tasks.dll</BuildTasksPath> + <IlcBuildTasksPath Condition="'$(IlcBuildTasksPath)' == ''">$(MSBuildThisFileDirectory)..\tools\ILCompiler.Build.Tasks.dll</IlcBuildTasksPath> <!-- Prevent dotnet CLI from deploying the CoreCLR shim executable since we produce @@ -11,7 +11,8 @@ </PropertyGroup> <Target Name="_ComputeIlcCompileInputs" - BeforeTargets="ComputeIlcCompileInputs"> + BeforeTargets="ComputeIlcCompileInputs" + DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)"> <ItemGroup> <IlcReference Include="@(_ManagedResolvedAssembliesToPublish)" /> </ItemGroup> @@ -46,8 +47,8 @@ pipeline we don't want to see in the output (native images, CoreCLR artifacts) until we get a proper AOT NetCore app package. --> - <UsingTask TaskName="ComputeManagedAssemblies" AssemblyFile="$(BuildTasksPath)" /> - <Target Name="_ComputeAssembliesToCompileToNative"> + <UsingTask TaskName="ComputeManagedAssemblies" AssemblyFile="$(IlcBuildTasksPath)" /> + <Target Name="_ComputeAssembliesToCompileToNative" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)"> <!-- CoreRT SDK and Framework Assemblies need to be defined to avoid CoreCLR implementations being set as compiler inputs --> <Error Condition="'@(PrivateSdkAssemblies)' == ''" Text="The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative" /> diff --git a/src/BuildIntegration/Microsoft.NETCore.Native.Unix.props b/src/BuildIntegration/Microsoft.NETCore.Native.Unix.props index 76c280d90..5ed981fed 100644 --- a/src/BuildIntegration/Microsoft.NETCore.Native.Unix.props +++ b/src/BuildIntegration/Microsoft.NETCore.Native.Unix.props @@ -21,44 +21,56 @@ See the LICENSE file in the project root for more information. <CppLinker>$(CppCompilerAndLinker)</CppLinker> <CppLibCreator>ar</CppLibCreator> </PropertyGroup> + + <!-- Part of workaround for lack of secondary build artifact import - https://github.com/Microsoft/msbuild/issues/2807 --> + <!-- Ensure that runtime-specific paths have already been set --> + <PropertyGroup> + <CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == '' and '$(TargetOS)' == 'OSX'">clang</CppCompilerAndLinker> + <CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang-3.9</CppCompilerAndLinker> + <CppCompiler>$(CppCompilerAndLinker)</CppCompiler> + <CppLinker>$(CppCompilerAndLinker)</CppLinker> + <CppLibCreator>ar</CppLibCreator> + </PropertyGroup> + <Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)"> - <ItemGroup> - <CppCompilerAndLinkerArg Include="-I $(IlcPath)/inc" /> - <CppCompilerAndLinkerArg Condition="'$(Configuration)' == 'Debug'" Include="-g -O0" /> - <CppCompilerAndLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="-O2" /> - <CppCompilerAndLinkerArg Include="-c -Wno-invalid-offsetof" /> - <CppCompilerAndLinkerArg Include="$(AdditionalCppCompilerFlags)" /> - </ItemGroup> + <ItemGroup> + <CppCompilerAndLinkerArg Include="-I $(IlcPath)/inc" /> + <CppCompilerAndLinkerArg Condition="'$(Configuration)' == 'Debug'" Include="-g -O0" /> + <CppCompilerAndLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="-O2" /> + <CppCompilerAndLinkerArg Include="-c -Wno-invalid-offsetof" /> + <CppCompilerAndLinkerArg Include="$(AdditionalCppCompilerFlags)" /> + </ItemGroup> - <ItemGroup> - <NativeLibrary Condition="'$(IlcMultiModule)' == 'true' and $(NativeCodeGen) == ''" Include="$(SharedLibrary)" /> - <NativeLibrary Condition="$(NativeCodeGen) == '' and $(NativeLib) == ''" Include="$(IlcPath)/sdk/libbootstrapper.a" /> - <NativeLibrary Condition="$(NativeCodeGen) == '' and $(NativeLib) != ''" Include="$(IlcPath)/sdk/libbootstrapperdll.a" /> - <NativeLibrary Condition="$(NativeCodeGen) == ''" Include="$(IlcPath)/sdk/libRuntime.a" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)/sdk/libbootstrappercpp.a" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)/sdk/libPortableRuntime.a" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libbootstrappercpp.a" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libPortableRuntime.a" /> - </ItemGroup> + <ItemGroup> + <NativeLibrary Condition="'$(IlcMultiModule)' == 'true' and $(NativeCodeGen) == ''" Include="$(SharedLibrary)" /> + <NativeLibrary Condition="$(NativeCodeGen) == '' and $(NativeLib) == ''" Include="$(IlcPath)/sdk/libbootstrapper.a" /> + <NativeLibrary Condition="$(NativeCodeGen) == '' and $(NativeLib) != ''" Include="$(IlcPath)/sdk/libbootstrapperdll.a" /> + <NativeLibrary Condition="$(NativeCodeGen) == ''" Include="$(IlcPath)/sdk/libRuntime.a" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)/sdk/libbootstrappercpp.a" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)/sdk/libPortableRuntime.a" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libbootstrappercpp.a" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libPortableRuntime.a" /> + </ItemGroup> - <ItemGroup> - <AdditionalNativeLibrary Include="$(IlcPath)/sdk/libSystem.Private.CoreLib.Native.a" /> - <AdditionalNativeLibrary Include="$(IlcPath)/framework/System.Native.a" /> - <AdditionalNativeLibrary Include="$(IlcPath)/framework/libSystem.Globalization.Native.a" /> - </ItemGroup> + <ItemGroup> + <AdditionalNativeLibrary Include="$(IlcPath)/sdk/libSystem.Private.CoreLib.Native.a" /> + <AdditionalNativeLibrary Include="$(IlcPath)/framework/System.Native.a" /> + <AdditionalNativeLibrary Include="$(IlcPath)/framework/libSystem.Globalization.Native.a" /> + </ItemGroup> - <ItemGroup> - <LinkerArg Include="@(NativeLibrary)" /> - <LinkerArg Include="@(AdditionalNativeLibrary)" /> - <LinkerArg Include="-g" /> - <LinkerArg Include="-Wl,-rpath,'$ORIGIN'" /> - <LinkerArg Include="-pthread" /> - <LinkerArg Include="-lstdc++" /> - <LinkerArg Include="-ldl" /> - <LinkerArg Include="-lm" /> - <LinkerArg Include="-luuid" Condition="'$(TargetOS)' != 'OSX'" /> - <LinkerArg Include="-lrt" Condition="'$(TargetOS)' != 'OSX'" /> - <LinkerArg Include="-licucore" Condition="'$(TargetOS)' == 'OSX'" /> - <LinkerArg Include="-shared" Condition="'$(NativeLib)' == 'Shared'" /> - </ItemGroup> + <ItemGroup> + <LinkerArg Include="@(NativeLibrary)" /> + <LinkerArg Include="@(AdditionalNativeLibrary)" /> + <LinkerArg Include="-g" /> + <LinkerArg Include="-Wl,-rpath,'$ORIGIN'" /> + <LinkerArg Include="-pthread" /> + <LinkerArg Include="-lstdc++" /> + <LinkerArg Include="-ldl" /> + <LinkerArg Include="-lm" /> + <LinkerArg Include="-luuid" Condition="'$(TargetOS)' != 'OSX'" /> + <LinkerArg Include="-lrt" Condition="'$(TargetOS)' != 'OSX'" /> + <LinkerArg Include="-licucore" Condition="'$(TargetOS)' == 'OSX'" /> + <LinkerArg Include="-shared" Condition="'$(NativeLib)' == 'Shared'" /> + </ItemGroup> + </Target> </Project> diff --git a/src/BuildIntegration/Microsoft.NETCore.Native.Windows.props b/src/BuildIntegration/Microsoft.NETCore.Native.Windows.props index 41b0227a6..2214b3423 100644 --- a/src/BuildIntegration/Microsoft.NETCore.Native.Windows.props +++ b/src/BuildIntegration/Microsoft.NETCore.Native.Windows.props @@ -14,66 +14,68 @@ See the LICENSE file in the project root for more information. *********************************************************************************************** --> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> <CppCompiler>cl</CppCompiler> <CppLinker>link</CppLinker> <CppLibCreator>lib</CppLibCreator> </PropertyGroup> + + <!-- Part of workaround for lack of secondary build artifact import - https://github.com/Microsoft/msbuild/issues/2807 --> + <!-- Ensure that runtime-specific paths have already been set --> + <Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)"> + <ItemGroup> + <CppCompilerAndLinkerArg Include="/I$(IlcPath)\inc" /> + <CppCompilerAndLinkerArg Condition="'$(Configuration)' == 'Debug'" Include="/Od" /> + <CppCompilerAndLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/O2" /> + <CppCompilerAndLinkerArg Include="/c /nologo /W3 /GS /DCPPCODEGEN /EHs /Zi /bigobj" /> + <CppCompilerAndLinkerArg Condition="'$(UseDebugCrt)' == 'true'" Include="/MTd" /> + <CppCompilerAndLinkerArg Condition="'$(UseDebugCrt)' != 'true'" Include="/MT" /> + <CppCompilerAndLinkerArg Include="$(AdditionalCppCompilerFlags)" /> + </ItemGroup> - <ItemGroup> - <CppCompilerAndLinkerArg Include="/I$(IlcPath)\inc" /> - <CppCompilerAndLinkerArg Condition="'$(Configuration)' == 'Debug'" Include="/Od" /> - <CppCompilerAndLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/O2" /> - <CppCompilerAndLinkerArg Include="/c /nologo /W3 /GS /DCPPCODEGEN /EHs /Zi /bigobj" /> - <CppCompilerAndLinkerArg Condition="'$(UseDebugCrt)' == 'true'" Include="/MTd" /> - <CppCompilerAndLinkerArg Condition="'$(UseDebugCrt)' != 'true'" Include="/MT" /> - <CppCompilerAndLinkerArg Include="$(AdditionalCppCompilerFlags)" /> - </ItemGroup> - - <ItemGroup> - <NativeLibrary Condition="$(NativeCodeGen) == '' and $(NativeLib) == ''" Include="$(IlcPath)\sdk\bootstrapper.lib" /> - <NativeLibrary Condition="$(NativeCodeGen) == '' and $(NativeLib) != ''" Include="$(IlcPath)\sdk\bootstrapperdll.lib" /> - <NativeLibrary Condition="$(NativeCodeGen) == ''" Include="$(IlcPath)\sdk\Runtime.lib" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)\sdk\bootstrappercpp.lib" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)\sdk\PortableRuntime.lib" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)\sdk\bootstrappercpp.lib" /> - <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)\sdk\PortableRuntime.lib" /> - <NativeLibrary Condition="'$(IlcMultiModule)' == 'true' and $(NativeCodeGen) == ''" Include="$(SharedLibrary)" /> - </ItemGroup> - - <ItemGroup> - <AdditionalNativeLibrary Include="kernel32.lib" /> - <AdditionalNativeLibrary Include="user32.lib" /> - <AdditionalNativeLibrary Include="gdi32.lib" /> - <AdditionalNativeLibrary Include="winspool.lib" /> - <AdditionalNativeLibrary Include="comdlg32.lib" /> - <AdditionalNativeLibrary Include="advapi32.lib" /> - <AdditionalNativeLibrary Include="shell32.lib" /> - <AdditionalNativeLibrary Include="ole32.lib" /> - <AdditionalNativeLibrary Include="oleaut32.lib" /> - <AdditionalNativeLibrary Include="uuid.lib" /> - <AdditionalNativeLibrary Include="bcrypt.lib" /> - <AdditionalNativeLibrary Include="normaliz.lib" /> - </ItemGroup> - - <ItemGroup> - <LinkerArg Condition="$(NativeLib) == 'Shared'" Include="/DLL" /> - <LinkerArg Condition="$(DefFile) != ''" Include="/DEF:$(DefFile)" /> - <LinkerArg Include="@(NativeLibrary)" /> - <LinkerArg Include="@(AdditionalNativeLibrary)" /> - <LinkerArg Include="/NOLOGO /DEBUG /MANIFEST:NO" /> - <!-- The runtime is not compatible with jump stubs inserted by incremental linking. --> - <LinkerArg Include="/INCREMENTAL:NO" /> - </ItemGroup> - - <ItemGroup> - <!-- TODO <LinkerArg Include="/MACHINE:X64" /> --> - </ItemGroup> - - <ItemGroup Condition="'$(Configuration)' != 'Debug'"> - <LinkerArg Include="/OPT:REF" /> - <LinkerArg Include="/OPT:ICF" /> - </ItemGroup> - + <ItemGroup> + <NativeLibrary Condition="$(NativeCodeGen) == '' and $(NativeLib) == ''" Include="$(IlcPath)\sdk\bootstrapper.lib" /> + <NativeLibrary Condition="$(NativeCodeGen) == '' and $(NativeLib) != ''" Include="$(IlcPath)\sdk\bootstrapperdll.lib" /> + <NativeLibrary Condition="$(NativeCodeGen) == ''" Include="$(IlcPath)\sdk\Runtime.lib" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)\sdk\bootstrappercpp.lib" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)\sdk\PortableRuntime.lib" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)\sdk\bootstrappercpp.lib" /> + <NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)\sdk\PortableRuntime.lib" /> + <NativeLibrary Condition="'$(IlcMultiModule)' == 'true' and $(NativeCodeGen) == ''" Include="$(SharedLibrary)" /> + </ItemGroup> + + <ItemGroup> + <AdditionalNativeLibrary Include="kernel32.lib" /> + <AdditionalNativeLibrary Include="user32.lib" /> + <AdditionalNativeLibrary Include="gdi32.lib" /> + <AdditionalNativeLibrary Include="winspool.lib" /> + <AdditionalNativeLibrary Include="comdlg32.lib" /> + <AdditionalNativeLibrary Include="advapi32.lib" /> + <AdditionalNativeLibrary Include="shell32.lib" /> + <AdditionalNativeLibrary Include="ole32.lib" /> + <AdditionalNativeLibrary Include="oleaut32.lib" /> + <AdditionalNativeLibrary Include="uuid.lib" /> + <AdditionalNativeLibrary Include="bcrypt.lib" /> + <AdditionalNativeLibrary Include="normaliz.lib" /> + </ItemGroup> + + <ItemGroup> + <LinkerArg Condition="$(NativeLib) == 'Shared'" Include="/DLL" /> + <LinkerArg Condition="$(DefFile) != ''" Include="/DEF:$(DefFile)" /> + <LinkerArg Include="@(NativeLibrary)" /> + <LinkerArg Include="@(AdditionalNativeLibrary)" /> + <LinkerArg Include="/NOLOGO /DEBUG /MANIFEST:NO" /> + <!-- The runtime is not compatible with jump stubs inserted by incremental linking. --> + <LinkerArg Include="/INCREMENTAL:NO" /> + </ItemGroup> + + <ItemGroup> + <!-- TODO <LinkerArg Include="/MACHINE:X64" /> --> + </ItemGroup> + + <ItemGroup Condition="'$(Configuration)' != 'Debug'"> + <LinkerArg Include="/OPT:REF" /> + <LinkerArg Include="/OPT:ICF" /> + </ItemGroup> + </Target> </Project> diff --git a/src/BuildIntegration/Microsoft.NETCore.Native.targets b/src/BuildIntegration/Microsoft.NETCore.Native.targets index ce276c899..96bd5d509 100644 --- a/src/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/BuildIntegration/Microsoft.NETCore.Native.targets @@ -25,7 +25,6 @@ See the LICENSE file in the project root for more information. <!-- The correct OS detection code. Uncomment once CI machines are upgraded to the latest version of MSBuild --> <!-- <TargetOS Condition="'$([MSBuild]::IsOSPlatform(OSX))' == 'true'">OSX</TargetOS> --> <TargetOS Condition="'$(TargetOS)' == ''">$(OS)</TargetOS> - <IlcPath Condition="'$(IlcPath)' == ''">$(MSBuildThisFileDirectory)/..</IlcPath> </PropertyGroup> <PropertyGroup> @@ -64,11 +63,13 @@ See the LICENSE file in the project root for more information. <SharedLibrary Condition="'$(OS)' == 'Windows_NT'">$(FrameworkLibPath)\Framework$(LibFileExt)</SharedLibrary> <SharedLibrary Condition="'$(OS)' != 'Windows_NT'">$(FrameworkLibPath)\libframework$(LibFileExt)</SharedLibrary> + <IlcDynamicBuildPropertyDependencies Condition="'$(IlcCalledViaPackage)' == 'true'">SetupProperties</IlcDynamicBuildPropertyDependencies> </PropertyGroup> <PropertyGroup Condition="'$(IlcCompileDependsOn)'=='' and '$(NativeCompilationDuringPublish)' != 'false'"> <IlcCompileDependsOn Condition="'$(BuildingFrameworkLibrary)' != 'true'">Compile;ComputeIlcCompileInputs</IlcCompileDependsOn> <IlcCompileDependsOn Condition="'$(IlcMultiModule)' == 'true' and '$(BuildingFrameworkLibrary)' != 'true'">$(IlcCompileDependsOn);BuildFrameworkLib</IlcCompileDependsOn> + <IlcCompileDependsOn>$(IlcCompileDependsOn);SetupOSSpecificProps</IlcCompileDependsOn> </PropertyGroup> <ItemGroup> @@ -83,7 +84,31 @@ See the LICENSE file in the project root for more information. <DefaultFrameworkAssemblies Include="@(PrivateSdkAssemblies)" /> </ItemGroup> - <Target Name="ComputeIlcCompileInputs"> + <!-- Part of workaround for lack of secondary build artifact import - https://github.com/Microsoft/msbuild/issues/2807 --> + <!-- The properties below need to be defined only after we've found the correct runtime package reference --> + <Target Name="SetupProperties" DependsOnTargets="$(IlcSetupPropertiesDependsOn)" BeforeTargets="Publish"> + <PropertyGroup> + <!-- Define paths used in build targets to point to the runtime-specific ILCompiler implementation --> + <IlcPath Condition="'$(IlcPath)' == ''">$(RuntimePackagePath)</IlcPath> + <IlcBuildTasksPath>$(RuntimePackagePath)\tools\ILCompiler.Build.Tasks.dll</IlcBuildTasksPath> + <!-- Set defaults for unspecified properties --> + </PropertyGroup> + + <!-- If running from a package these values need to be set again with the resolved IlcPath --> + <ItemGroup> + <PrivateSdkAssemblies Include="$(IlcPath)\sdk\*.dll" /> + </ItemGroup> + <ItemGroup> + <FrameworkAssemblies Include="$(IlcPath)\framework\*.dll" /> + </ItemGroup> + + <ItemGroup> + <DefaultFrameworkAssemblies Include="@(FrameworkAssemblies)" /> + <DefaultFrameworkAssemblies Include="@(PrivateSdkAssemblies)" /> + </ItemGroup> + </Target> + + <Target Name="ComputeIlcCompileInputs" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)" BeforeTargets="Publish"> <ItemGroup> <ManagedBinary Condition="$(BuildingFrameworkLibrary) != 'true'" Include="$(IntermediateOutputPath)$(TargetName)$(TargetExt)" /> <IlcCompileInput Include="@(ManagedBinary)" /> @@ -95,13 +120,15 @@ See the LICENSE file in the project root for more information. BuildFrameworkLib is invoked before IlcCompile in multi-module builds to produce the shared framework library on demand --> - <Target Name="BuildFrameworkLib" Condition="'$(DisableFrameworkLibGeneration)' != 'true'"> + <Target Name="BuildFrameworkLib" Condition="'$(DisableFrameworkLibGeneration)' != 'true'" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)"> <ItemGroup> - <ProjectToBuild Include="$(MSBuildThisFileDirectory)\BuildFrameworkNativeObjects.proj"> - <AdditionalProperties> + <!-- This builds the project with the ILC implementation in the identified runtime package to avoid resolving it again --> + <ProjectToBuild Include="$(MSBuildThisFileDirectory)BuildFrameworkNativeObjects.proj"> + <AdditionalProperties> IntermediateOutputPath=$(IntermediateOutputPath); FrameworkLibPath=$(FrameworkLibPath); - FrameworkObjPath=$(FrameworkObjPath) + FrameworkObjPath=$(FrameworkObjPath); + RuntimePackagePath=$(RuntimePackagePath) </AdditionalProperties> </ProjectToBuild> </ItemGroup> @@ -136,8 +163,8 @@ See the LICENSE file in the project root for more information. <Exec Command=""$(IlcPath)\tools\ilc" @"$(NativeIntermediateOutputPath)%(ManagedBinary.Filename).ilc.rsp"" /> </Target> - <Import Project="Microsoft.NETCore.Native.Windows.props" Condition="'$(TargetOS)' == 'Windows_NT'" /> - <Import Project="Microsoft.NETCore.Native.Unix.props" Condition="'$(TargetOS)' != 'Windows_NT'" /> + <Import Project="$(MSBuildThisFileDirectory)Microsoft.NETCore.Native.Windows.props" Condition="'$(TargetOS)' == 'Windows_NT'" /> + <Import Project="$(MSBuildThisFileDirectory)Microsoft.NETCore.Native.Unix.props" Condition="'$(TargetOS)' != 'Windows_NT'" /> <Target Name="CppCompile" Inputs="$(IlcCompileOutput)" @@ -193,23 +220,21 @@ See the LICENSE file in the project root for more information. <Target Name="CreateLib" Inputs="@(LibInputs)" Outputs="$(SharedLibrary)" - DependsOnTargets="$(CreateLibDependsOn)"> + DependsOnTargets="$(CreateLibDependsOn);$(IlcDynamicBuildPropertyDependencies)" + > <ItemGroup> <CustomLibArg Include="/out:$(SharedLibrary)" Condition="'$(OS)' == 'Windows_NT'" /> <CustomLibArg Include="-crs $(SharedLibrary)" Condition="'$(OS)' != 'Windows_NT'" /> <CustomLibArg Include="@(LibInputs->'%(Identity)')" /> </ItemGroup> - <MakeDir Directories="$(NativeIntermediateOutputPath)" /> <WriteLinesToFile File="$(NativeIntermediateOutputPath)lib.rsp" Lines="@(CustomLibArg)" Overwrite="true" Condition="'$(OS)' == 'Windows_NT'" /> - <MakeDir Directories="$([System.IO.Path]::GetDirectoryName($(SharedLibrary)))" /> - <Exec Command="$(CppLibCreator) @"$(NativeIntermediateOutputPath)lib.rsp"" Condition="'$(OS)' == 'Windows_NT'" /> <Exec Command="$(CppLibCreator) @(CustomLibArg, ' ')" Condition="'$(OS)' != 'Windows_NT'" /> </Target> - <Import Project="$(MSBuildThisFileDirectory)\Microsoft.NETCore.Native.Publish.targets" Condition="'$(NativeCompilationDuringPublish)' != 'false'" /> + <Import Project="$(MSBuildThisFileDirectory)Microsoft.NETCore.Native.Publish.targets" Condition="'$(NativeCompilationDuringPublish)' != 'false'" /> </Project> diff --git a/src/ILVerify/README.md b/src/ILVerify/README.md index f9463c1d6..662bf8ca2 100644 --- a/src/ILVerify/README.md +++ b/src/ILVerify/README.md @@ -17,7 +17,7 @@ Historically on Full Framework IL generators used PEVerify to make sure that the - Fast spin up/tear down. ## The codebase -The project targets netcoreapp2.0 and uses the new .csproj based project format. If you want to open and compile it with Visual Studio then you need a version, which supports .NET Core 2.0 tooling. Currently this is supported in Visual Studio 2017 Update 3 Preview (Version 15.3). The other option is to use command (with .NET Core 2.0 tooling - currenly also preview). +The project targets netcoreapp2.0 and uses the new .csproj based project format. If you want to open and compile it with Visual Studio then you need a version, which supports .NET Core 2.0 tooling. This is supported in Visual Studio 2017 Update 3 (Version 15.3) or later. The other option is to use command (with .NET Core 2.0 tooling). ## Tests @@ -100,4 +100,4 @@ Useful sources: - [PEVerify source code](https://github.com/lewischeng-ms/sscli/blob/master/clr/src/jit64/newverify.cpp) - [RyuJIT source code](https://github.com/dotnet/coreclr/blob/master/src/jit), specifically: [exception handling specific part](https://github.com/dotnet/coreclr/blob/master/src/jit/jiteh.cpp), [importer.cpp](https://github.com/dotnet/coreclr/blob/master/src/jit/importer.cpp) (look for `Compiler::ver`, `Verify`, `VerifyOrReturn`, and `VerifyOrReturnSpeculative`), [_typeinfo.h](https://github.com/dotnet/coreclr/blob/master/src/jit/_typeinfo.h), [typeinfo.cpp](https://github.com/dotnet/coreclr/blob/master/src/jit/typeinfo.cpp) - [ECMA-335 standard](https://www.ecma-international.org/publications/standards/Ecma-335.htm) - - [Expert .NET 2.0 IL Assembler book](http://www.apress.com/us/book/9781590596463) by Serge Lidin
\ No newline at end of file + - [Expert .NET 2.0 IL Assembler book](http://www.apress.com/us/book/9781590596463) by Serge Lidin diff --git a/src/System.Private.CoreLib/shared/System/BitConverter.cs b/src/System.Private.CoreLib/shared/System/BitConverter.cs index c7f4d0459..e3cf20eb6 100644 --- a/src/System.Private.CoreLib/shared/System/BitConverter.cs +++ b/src/System.Private.CoreLib/shared/System/BitConverter.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + using Internal.Runtime.CompilerServices; namespace System @@ -37,7 +39,7 @@ namespace System if (destination.Length < sizeof(byte)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value ? (byte)1 : (byte)0); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value ? (byte)1 : (byte)0); return true; } @@ -55,7 +57,7 @@ namespace System if (destination.Length < sizeof(char)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value); return true; } @@ -74,7 +76,7 @@ namespace System if (destination.Length < sizeof(short)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value); return true; } @@ -93,7 +95,7 @@ namespace System if (destination.Length < sizeof(int)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value); return true; } @@ -112,7 +114,7 @@ namespace System if (destination.Length < sizeof(long)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value); return true; } @@ -133,7 +135,7 @@ namespace System if (destination.Length < sizeof(ushort)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value); return true; } @@ -154,7 +156,7 @@ namespace System if (destination.Length < sizeof(uint)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value); return true; } @@ -175,7 +177,7 @@ namespace System if (destination.Length < sizeof(ulong)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value); return true; } @@ -194,7 +196,7 @@ namespace System if (destination.Length < sizeof(float)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value); return true; } @@ -213,7 +215,7 @@ namespace System if (destination.Length < sizeof(double)) return false; - Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value); return true; } @@ -225,7 +227,7 @@ namespace System { if (value.Length < sizeof(char)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<char>(ref value.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned<char>(ref MemoryMarshal.GetReference(value)); } // Converts an array of bytes into a short. @@ -246,7 +248,7 @@ namespace System { if (value.Length < sizeof(short)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<short>(ref value.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned<short>(ref MemoryMarshal.GetReference(value)); } // Converts an array of bytes into an int. @@ -267,7 +269,7 @@ namespace System { if (value.Length < sizeof(int)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<int>(ref value.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned<int>(ref MemoryMarshal.GetReference(value)); } // Converts an array of bytes into a long. @@ -288,7 +290,7 @@ namespace System { if (value.Length < sizeof(long)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<long>(ref value.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned<long>(ref MemoryMarshal.GetReference(value)); } // Converts an array of bytes into an ushort. @@ -302,7 +304,7 @@ namespace System { if (value.Length < sizeof(ushort)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<ushort>(ref value.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned<ushort>(ref MemoryMarshal.GetReference(value)); } // Converts an array of bytes into an uint. @@ -316,7 +318,7 @@ namespace System { if (value.Length < sizeof(uint)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<uint>(ref value.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned<uint>(ref MemoryMarshal.GetReference(value)); } // Converts an array of bytes into an unsigned long. @@ -330,7 +332,7 @@ namespace System { if (value.Length < sizeof(ulong)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<ulong>(ref value.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned<ulong>(ref MemoryMarshal.GetReference(value)); } // Converts an array of bytes into a float. @@ -341,7 +343,7 @@ namespace System { if (value.Length < sizeof(float)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<float>(ref value.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned<float>(ref MemoryMarshal.GetReference(value)); } // Converts an array of bytes into a double. @@ -352,7 +354,7 @@ namespace System { if (value.Length < sizeof(double)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<double>(ref value.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned<double>(ref MemoryMarshal.GetReference(value)); } // Converts an array of bytes into a String. @@ -442,7 +444,7 @@ namespace System { if (value.Length < sizeof(byte)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value); - return Unsafe.ReadUnaligned<byte>(ref value.DangerousGetPinnableReference()) != 0; + return Unsafe.ReadUnaligned<byte>(ref MemoryMarshal.GetReference(value)) != 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/System.Private.CoreLib/shared/System/Convert.cs b/src/System.Private.CoreLib/shared/System/Convert.cs index 6c592a492..488ea7733 100644 --- a/src/System.Private.CoreLib/shared/System/Convert.cs +++ b/src/System.Private.CoreLib/shared/System/Convert.cs @@ -2434,7 +2434,7 @@ namespace System unsafe { - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) fixed (char* charsPtr = result) { int charsWritten = ConvertToBase64Array(charsPtr, bytesPtr, 0, bytes.Length, insertLineBreaks); @@ -2527,8 +2527,8 @@ namespace System return false; } - fixed (char* outChars = &chars.DangerousGetPinnableReference()) - fixed (byte* inData = &bytes.DangerousGetPinnableReference()) + fixed (char* outChars = &MemoryMarshal.GetReference(chars)) + fixed (byte* inData = &MemoryMarshal.GetReference(bytes)) { charsWritten = ConvertToBase64Array(outChars, inData, 0, bytes.Length, insertLineBreaks); return true; @@ -2676,7 +2676,7 @@ namespace System chars = chars.Slice(0, chars.Length - 1); } - fixed (char* charsPtr = &chars.DangerousGetPinnableReference()) + fixed (char* charsPtr = &MemoryMarshal.GetReference(chars)) { int resultLength = FromBase64_ComputeResultLength(charsPtr, chars.Length); Debug.Assert(resultLength >= 0); @@ -2686,7 +2686,7 @@ namespace System return false; } - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) { bytesWritten = FromBase64_Decode(charsPtr, chars.Length, bytesPtr, bytes.Length); return true; diff --git a/src/System.Private.CoreLib/shared/System/EventArgs.cs b/src/System.Private.CoreLib/shared/System/EventArgs.cs index be12af25b..f3561a8d0 100644 --- a/src/System.Private.CoreLib/shared/System/EventArgs.cs +++ b/src/System.Private.CoreLib/shared/System/EventArgs.cs @@ -7,6 +7,8 @@ using System; namespace System { // The base class for all event classes. + [Serializable] + [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class EventArgs { public static readonly EventArgs Empty = new EventArgs(); diff --git a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs index 84fadd376..e088a82de 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs @@ -14,6 +14,7 @@ using System.Reflection; using System.Diagnostics; +using System.Runtime.InteropServices; using System.Runtime.Serialization; namespace System.Globalization @@ -555,8 +556,8 @@ namespace System.Globalization int length = Math.Min(strA.Length, strB.Length); int range = length; - fixed (char* ap = &strA.DangerousGetPinnableReference()) - fixed (char* bp = &strB.DangerousGetPinnableReference()) + fixed (char* ap = &MemoryMarshal.GetReference(strA)) + fixed (char* bp = &MemoryMarshal.GetReference(strB)) { char* a = ap; char* b = bp; diff --git a/src/System.Private.CoreLib/shared/System/Guid.cs b/src/System.Private.CoreLib/shared/System/Guid.cs index db5f93212..423d5bc78 100644 --- a/src/System.Private.CoreLib/shared/System/Guid.cs +++ b/src/System.Private.CoreLib/shared/System/Guid.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using Internal.Runtime.CompilerServices; namespace System @@ -1361,7 +1362,7 @@ namespace System unsafe { - fixed (char* guidChars = &destination.DangerousGetPinnableReference()) + fixed (char* guidChars = &MemoryMarshal.GetReference(destination)) { char * p = guidChars; diff --git a/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs b/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs index 99a337728..34164abc3 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileStream.Unix.cs @@ -4,6 +4,7 @@ using Microsoft.Win32.SafeHandles; using System.Diagnostics; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -459,7 +460,7 @@ namespace System.IO VerifyOSHandlePosition(); int bytesRead; - fixed (byte* bufPtr = &buffer.DangerousGetPinnableReference()) + fixed (byte* bufPtr = &MemoryMarshal.GetReference(buffer)) { bytesRead = CheckFileCall(Interop.Sys.Read(_fileHandle, bufPtr, buffer.Length)); Debug.Assert(bytesRead <= buffer.Length); @@ -612,7 +613,7 @@ namespace System.IO { VerifyOSHandlePosition(); - fixed (byte* bufPtr = &source.DangerousGetPinnableReference()) + fixed (byte* bufPtr = &MemoryMarshal.GetReference(source)) { int offset = 0; int count = source.Length; diff --git a/src/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs b/src/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs index eec11b4b1..477b9430f 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileStream.Windows.cs @@ -1069,7 +1069,7 @@ namespace System.IO Debug.Assert(_useAsyncIO, "WriteInternalCoreAsync doesn't work on synchronous file streams!"); // Create and store async stream class library specific data in the async result - FileStreamCompletionSource completionSource = source.DangerousTryGetArray(out ArraySegment<byte> array) ? + FileStreamCompletionSource completionSource = MemoryMarshal.TryGetArray(source, out ArraySegment<byte> array) ? new FileStreamCompletionSource(this, 0, array.Array) : new MemoryFileStreamCompletionSource(this, 0, source); NativeOverlapped* intOverlapped = completionSource.Overlapped; @@ -1188,7 +1188,7 @@ namespace System.IO int r; int numBytesRead = 0; - fixed (byte* p = &bytes.DangerousGetPinnableReference()) + fixed (byte* p = &MemoryMarshal.GetReference(bytes)) { r = _useAsyncIO ? Interop.Kernel32.ReadFile(handle, p, bytes.Length, IntPtr.Zero, overlapped) : @@ -1215,7 +1215,7 @@ namespace System.IO int numBytesWritten = 0; int r; - fixed (byte* p = &buffer.DangerousGetPinnableReference()) + fixed (byte* p = &MemoryMarshal.GetReference(buffer)) { r = _useAsyncIO ? Interop.Kernel32.WriteFile(handle, p, buffer.Length, IntPtr.Zero, overlapped) : diff --git a/src/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs b/src/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs index e3871bcd6..4e19f465b 100644 --- a/src/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs +++ b/src/System.Private.CoreLib/shared/System/IO/FileStreamCompletionSource.Win32.cs @@ -231,7 +231,7 @@ namespace System.IO internal MemoryFileStreamCompletionSource(FileStream stream, int numBufferedBytes, ReadOnlyMemory<byte> memory) : base(stream, numBufferedBytes, bytes: null) // this type handles the pinning, so null is passed for bytes { - Debug.Assert(!memory.DangerousTryGetArray(out ArraySegment<byte> array), "The base should be used directly if we can get the array."); + Debug.Assert(!MemoryMarshal.TryGetArray(memory, out ArraySegment<byte> array), "The base should be used directly if we can get the array."); _handle = memory.Retain(pin: true); } diff --git a/src/System.Private.CoreLib/shared/System/IO/MemoryStream.cs b/src/System.Private.CoreLib/shared/System/IO/MemoryStream.cs index 727d492ea..c5e5ea918 100644 --- a/src/System.Private.CoreLib/shared/System/IO/MemoryStream.cs +++ b/src/System.Private.CoreLib/shared/System/IO/MemoryStream.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -762,7 +763,7 @@ namespace System.IO { // See corresponding comment in ReadAsync for why we don't just always use Write(ReadOnlySpan<byte>). // Unlike ReadAsync, we could delegate to WriteAsync(byte[], ...) here, but we don't for consistency. - if (source.DangerousTryGetArray(out ArraySegment<byte> sourceArray)) + if (MemoryMarshal.TryGetArray(source, out ArraySegment<byte> sourceArray)) { Write(sourceArray.Array, sourceArray.Offset, sourceArray.Count); } diff --git a/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs b/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs index 9e1cfef49..171113542 100644 --- a/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs +++ b/src/System.Private.CoreLib/shared/System/IO/UnmanagedMemoryStream.cs @@ -418,7 +418,7 @@ namespace System.IO unsafe { - fixed (byte* pBuffer = &destination.DangerousGetPinnableReference()) + fixed (byte* pBuffer = &MemoryMarshal.GetReference(destination)) { if (_buffer != null) { @@ -709,7 +709,7 @@ namespace System.IO } } - fixed (byte* pBuffer = &source.DangerousGetPinnableReference()) + fixed (byte* pBuffer = &MemoryMarshal.GetReference(source)) { if (_buffer != null) { @@ -794,7 +794,7 @@ namespace System.IO { // See corresponding comment in ReadAsync for why we don't just always use Write(ReadOnlySpan<byte>). // Unlike ReadAsync, we could delegate to WriteAsync(byte[], ...) here, but we don't for consistency. - if (source.DangerousTryGetArray(out ArraySegment<byte> sourceArray)) + if (MemoryMarshal.TryGetArray(source, out ArraySegment<byte> sourceArray)) { Write(sourceArray.Array, sourceArray.Offset, sourceArray.Count); } diff --git a/src/System.Private.CoreLib/shared/System/MemoryDebugView.cs b/src/System.Private.CoreLib/shared/System/MemoryDebugView.cs index 215569191..2706d0927 100644 --- a/src/System.Private.CoreLib/shared/System/MemoryDebugView.cs +++ b/src/System.Private.CoreLib/shared/System/MemoryDebugView.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.InteropServices; namespace System { @@ -27,7 +28,7 @@ namespace System // https://devdiv.visualstudio.com/DevDiv/_workitems?id=286592 get { - if (_memory.DangerousTryGetArray(out ArraySegment<T> segment)) + if (MemoryMarshal.TryGetArray(_memory, out ArraySegment<T> segment)) { T[] array = new T[_memory.Length]; Array.Copy(segment.Array, segment.Offset, array, 0, array.Length); diff --git a/src/System.Private.CoreLib/shared/System/Number.Formatting.cs b/src/System.Private.CoreLib/shared/System/Number.Formatting.cs index ddf9ef1b2..70b35a08a 100644 --- a/src/System.Private.CoreLib/shared/System/Number.Formatting.cs +++ b/src/System.Private.CoreLib/shared/System/Number.Formatting.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Globalization; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Text; namespace System @@ -1558,7 +1559,7 @@ namespace System scaleAdjust = 0; src = section; - fixed (char* pFormat = &format.DangerousGetPinnableReference()) + fixed (char* pFormat = &MemoryMarshal.GetReference(format)) { while (src < format.Length && (ch = pFormat[src++]) != 0 && ch != ';') { @@ -1728,7 +1729,7 @@ namespace System bool decimalWritten = false; - fixed (char* pFormat = &format.DangerousGetPinnableReference()) + fixed (char* pFormat = &MemoryMarshal.GetReference(format)) { char* cur = dig; @@ -1948,7 +1949,7 @@ namespace System int digitCount = 0; int digLength = string.wcslen(dig); int digStart = (digPos < digLength) ? digPos : digLength; - fixed (char* spanPtr = &sb.AppendSpan(bufferSize).DangerousGetPinnableReference()) + fixed (char* spanPtr = &MemoryMarshal.GetReference(sb.AppendSpan(bufferSize))) { char* p = spanPtr + bufferSize - 1; for (int i = digPos - 1; i >= 0; i--) @@ -2188,7 +2189,7 @@ namespace System if (section == 0) return 0; - fixed (char* pFormat = &format.DangerousGetPinnableReference()) + fixed (char* pFormat = &MemoryMarshal.GetReference(format)) { src = 0; for (;;) diff --git a/src/System.Private.CoreLib/shared/System/Number.Parsing.cs b/src/System.Private.CoreLib/shared/System/Number.Parsing.cs index 9d40e49af..46951094e 100644 --- a/src/System.Private.CoreLib/shared/System/Number.Parsing.cs +++ b/src/System.Private.CoreLib/shared/System/Number.Parsing.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Globalization; +using System.Runtime.InteropServices; namespace System { @@ -855,7 +856,7 @@ namespace System private static unsafe void StringToNumber(ReadOnlySpan<char> str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo info, bool parseDecimal) { Debug.Assert(info != null); - fixed (char* stringPointer = &str.DangerousGetPinnableReference()) + fixed (char* stringPointer = &MemoryMarshal.GetReference(str)) { char* p = stringPointer; if (!ParseNumber(ref p, options, ref number, info, parseDecimal) @@ -869,7 +870,7 @@ namespace System internal static unsafe bool TryStringToNumber(ReadOnlySpan<char> str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo numfmt, bool parseDecimal) { Debug.Assert(numfmt != null); - fixed (char* stringPointer = &str.DangerousGetPinnableReference()) + fixed (char* stringPointer = &MemoryMarshal.GetReference(str)) { char* p = stringPointer; if (!ParseNumber(ref p, options, ref number, numfmt, parseDecimal) diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs index 090acff55..c6a97eca2 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeFeature.cs @@ -11,17 +11,24 @@ namespace System.Runtime.CompilerServices /// </summary> public const string PortablePdb = nameof(PortablePdb); +#if FEATURE_DEFAULT_INTERFACES + /// <summary> + /// Indicates that this version of runtime supports default interface method implementations. + /// </summary> + public const string DefaultImplementationsOfInterfaces = nameof(DefaultImplementationsOfInterfaces); +#endif + /// <summary> /// Checks whether a certain feature is supported by the Runtime. /// </summary> public static bool IsSupported(string feature) { - // Features should be added as public const string fields in the same class. - // Example: public const string FeatureName = nameof(FeatureName); - switch (feature) { - case nameof(PortablePdb): + case PortablePdb: +#if FEATURE_DEFAULT_INTERFACES + case DefaultImplementationsOfInterfaces: +#endif return true; } diff --git a/src/System.Private.CoreLib/shared/System/Text/Decoder.cs b/src/System.Private.CoreLib/shared/System/Text/Decoder.cs index 8dccaacd9..b827648fc 100644 --- a/src/System.Private.CoreLib/shared/System/Text/Decoder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/Decoder.cs @@ -5,6 +5,7 @@ using System.Text; using System; using System.Diagnostics; +using System.Runtime.InteropServices; namespace System.Text { @@ -133,7 +134,7 @@ namespace System.Text public virtual unsafe int GetCharCount(ReadOnlySpan<byte> bytes, bool flush) { - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) { return GetCharCount(bytesPtr, bytes.Length, flush); } @@ -226,8 +227,8 @@ namespace System.Text public virtual unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars, bool flush) { - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) - fixed (char* charsPtr = &chars.DangerousGetPinnableReference()) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) + fixed (char* charsPtr = &MemoryMarshal.GetReference(chars)) { return GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length, flush); } @@ -340,8 +341,8 @@ namespace System.Text public virtual unsafe void Convert(ReadOnlySpan<byte> bytes, Span<char> chars, bool flush, out int bytesUsed, out int charsUsed, out bool completed) { - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) - fixed (char* charsPtr = &chars.DangerousGetPinnableReference()) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) + fixed (char* charsPtr = &MemoryMarshal.GetReference(chars)) { Convert(bytesPtr, bytes.Length, charsPtr, chars.Length, flush, out bytesUsed, out charsUsed, out completed); } diff --git a/src/System.Private.CoreLib/shared/System/Text/Encoder.cs b/src/System.Private.CoreLib/shared/System/Text/Encoder.cs index 167060859..fb1bdb803 100644 --- a/src/System.Private.CoreLib/shared/System/Text/Encoder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/Encoder.cs @@ -5,6 +5,7 @@ using System.Text; using System; using System.Diagnostics; +using System.Runtime.InteropServices; namespace System.Text { @@ -131,7 +132,7 @@ namespace System.Text public virtual unsafe int GetByteCount(ReadOnlySpan<char> chars, bool flush) { - fixed (char* charsPtr = &chars.DangerousGetPinnableReference()) + fixed (char* charsPtr = &MemoryMarshal.GetReference(chars)) { return GetByteCount(charsPtr, chars.Length, flush); } @@ -220,8 +221,8 @@ namespace System.Text public virtual unsafe int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes, bool flush) { - fixed (char* charsPtr = &chars.DangerousGetPinnableReference()) - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) + fixed (char* charsPtr = &MemoryMarshal.GetReference(chars)) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) { return GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length, flush); } @@ -334,8 +335,8 @@ namespace System.Text public virtual unsafe void Convert(ReadOnlySpan<char> chars, Span<byte> bytes, bool flush, out int charsUsed, out int bytesUsed, out bool completed) { - fixed (char* charsPtr = &chars.DangerousGetPinnableReference()) - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) + fixed (char* charsPtr = &MemoryMarshal.GetReference(chars)) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) { Convert(charsPtr, chars.Length, bytesPtr, bytes.Length, flush, out charsUsed, out bytesUsed, out completed); } diff --git a/src/System.Private.CoreLib/shared/System/Text/Encoding.cs b/src/System.Private.CoreLib/shared/System/Text/Encoding.cs index 8e4d29d24..e469180ce 100644 --- a/src/System.Private.CoreLib/shared/System/Text/Encoding.cs +++ b/src/System.Private.CoreLib/shared/System/Text/Encoding.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Globalization; using System.Threading; +using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Diagnostics.CodeAnalysis; @@ -712,7 +713,7 @@ namespace System.Text public virtual unsafe int GetByteCount(ReadOnlySpan<char> chars) { - fixed (char* charsPtr = &chars.DangerousGetPinnableReference()) + fixed (char* charsPtr = &MemoryMarshal.GetReference(chars)) { return GetByteCount(charsPtr, chars.Length); } @@ -894,8 +895,8 @@ namespace System.Text public virtual unsafe int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes) { - fixed (char* charsPtr = &chars.DangerousGetPinnableReference()) - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) + fixed (char* charsPtr = &MemoryMarshal.GetReference(chars)) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) { return GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length); } @@ -944,7 +945,7 @@ namespace System.Text public virtual unsafe int GetCharCount(ReadOnlySpan<byte> bytes) { - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) { return GetCharCount(bytesPtr, bytes.Length); } @@ -1056,8 +1057,8 @@ namespace System.Text public virtual unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars) { - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) - fixed (char* charsPtr = &chars.DangerousGetPinnableReference()) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) + fixed (char* charsPtr = &MemoryMarshal.GetReference(chars)) { return GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length); } @@ -1086,7 +1087,7 @@ namespace System.Text public unsafe string GetString(ReadOnlySpan<byte> bytes) { - fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference()) + fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes)) { return GetString(bytesPtr, bytes.Length); } diff --git a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs index ced656c5b..d9da9377d 100644 --- a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs @@ -7,6 +7,7 @@ using System.Runtime; using System.Runtime.Serialization; using System; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Threading; @@ -1030,7 +1031,7 @@ namespace System.Text { unsafe { - fixed (char* valueChars = &value.DangerousGetPinnableReference()) + fixed (char* valueChars = &MemoryMarshal.GetReference(value)) { Append(valueChars, value.Length); } @@ -1272,7 +1273,7 @@ namespace System.Text { unsafe { - fixed (char* sourcePtr = &value.DangerousGetPinnableReference()) + fixed (char* sourcePtr = &MemoryMarshal.GetReference(value)) Insert(index, sourcePtr, value.Length); } } @@ -2046,7 +2047,7 @@ namespace System.Text } fixed (char* sourcePtr = &source[sourceIndex]) - fixed (char* destinationPtr = &destination.DangerousGetPinnableReference()) + fixed (char* destinationPtr = &MemoryMarshal.GetReference(destination)) string.wstrcpy(destinationPtr + destinationIndex, sourcePtr, count); } } diff --git a/src/System.Private.CoreLib/src/System/Globalization/CompareInfo.Unix.cs b/src/System.Private.CoreLib/src/System/Globalization/CompareInfo.Unix.cs index f97539360..cbf3fb555 100644 --- a/src/System.Private.CoreLib/src/System/Globalization/CompareInfo.Unix.cs +++ b/src/System.Private.CoreLib/src/System/Globalization/CompareInfo.Unix.cs @@ -152,7 +152,7 @@ namespace System.Globalization Debug.Assert(string2 != null); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); - fixed (char* pString1 = &string1.DangerousGetPinnableReference()) + fixed (char* pString1 = &MemoryMarshal.GetReference(string1)) fixed (char* pString2 = &string2.GetRawStringData()) { return Interop.GlobalizationInterop.CompareString(_sortHandle, pString1, string1.Length, pString2, string2.Length, options); @@ -164,8 +164,8 @@ namespace System.Globalization Debug.Assert(!_invariantMode); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); - fixed (char* pString1 = &string1.DangerousGetPinnableReference()) - fixed (char* pString2 = &string2.DangerousGetPinnableReference()) + fixed (char* pString1 = &MemoryMarshal.GetReference(string1)) + fixed (char* pString2 = &MemoryMarshal.GetReference(string2)) { return Interop.GlobalizationInterop.CompareString(_sortHandle, pString1, string1.Length, pString2, string2.Length, options); } diff --git a/src/System.Private.CoreLib/src/System/Globalization/CompareInfo.Windows.cs b/src/System.Private.CoreLib/src/System/Globalization/CompareInfo.Windows.cs index 765ea3581..958dc727c 100644 --- a/src/System.Private.CoreLib/src/System/Globalization/CompareInfo.Windows.cs +++ b/src/System.Private.CoreLib/src/System/Globalization/CompareInfo.Windows.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.InteropServices; namespace System.Globalization { @@ -120,7 +121,7 @@ namespace System.Globalization string localeName = _sortHandle != IntPtr.Zero ? null : _sortName; fixed (char* pLocaleName = localeName) - fixed (char* pString1 = &string1.DangerousGetPinnableReference()) + fixed (char* pString1 = &MemoryMarshal.GetReference(string1)) fixed (char* pString2 = &string2.GetRawStringData()) { int result = Interop.Kernel32.CompareStringEx( @@ -152,8 +153,8 @@ namespace System.Globalization string localeName = _sortHandle != IntPtr.Zero ? null : _sortName; fixed (char* pLocaleName = localeName) - fixed (char* pString1 = &string1.DangerousGetPinnableReference()) - fixed (char* pString2 = &string2.DangerousGetPinnableReference()) + fixed (char* pString1 = &MemoryMarshal.GetReference(string1)) + fixed (char* pString2 = &MemoryMarshal.GetReference(string2)) { int result = Interop.Kernel32.CompareStringEx( pLocaleName, diff --git a/src/System.Private.CoreLib/src/System/IO/BinaryReader.cs b/src/System.Private.CoreLib/src/System/IO/BinaryReader.cs index 217b473f4..314d01cc7 100644 --- a/src/System.Private.CoreLib/src/System/IO/BinaryReader.cs +++ b/src/System.Private.CoreLib/src/System/IO/BinaryReader.cs @@ -6,6 +6,7 @@ using Internal.Runtime.CompilerServices; using System; using System.Text; using System.Diagnostics; +using System.Runtime.InteropServices; namespace System.IO { @@ -445,7 +446,7 @@ namespace System.IO unsafe { fixed (byte* pBytes = byteBuffer) - fixed (char* pChars = &buffer.DangerousGetPinnableReference()) + fixed (char* pChars = &MemoryMarshal.GetReference(buffer)) { charsRead = _decoder.GetChars(pBytes + position, numBytes, pChars + index, charsRemaining, flush: false); } diff --git a/src/System.Private.CoreLib/src/System/IO/Stream.cs b/src/System.Private.CoreLib/src/System/IO/Stream.cs index ec786672a..b4f8ab30d 100644 --- a/src/System.Private.CoreLib/src/System/IO/Stream.cs +++ b/src/System.Private.CoreLib/src/System/IO/Stream.cs @@ -4,6 +4,7 @@ using System.Buffers; using System.Diagnostics; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -317,7 +318,7 @@ namespace System.IO public virtual Task WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default(CancellationToken)) { - if (source.DangerousTryGetArray(out ArraySegment<byte> array)) + if (MemoryMarshal.TryGetArray(source, out ArraySegment<byte> array)) { return WriteAsync(array.Array, array.Offset, array.Count, cancellationToken); } diff --git a/src/System.Private.CoreLib/src/System/String.cs b/src/System.Private.CoreLib/src/System/String.cs index b17c3bba8..076bd02a8 100644 --- a/src/System.Private.CoreLib/src/System/String.cs +++ b/src/System.Private.CoreLib/src/System/String.cs @@ -408,7 +408,7 @@ namespace System } string result = FastAllocateString(value.Length); - fixed (char* dest = &result._firstChar, src = &value.DangerousGetPinnableReference()) + fixed (char* dest = &result._firstChar, src = &MemoryMarshal.GetReference(value)) { wstrcpy(dest, src, value.Length); } |