From 7b144f3a018ab427e0e6d2125cfbce2140e527f2 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 6 Dec 2024 13:55:45 +0100 Subject: [PATCH 01/63] Beginnings of native Android build --- Directory.Build.props | 2 +- eng/native/build-commons.sh | 1 + src/native/external/libunwind_extras/CMakeLists.txt | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index bff6874d7bbe4d..5c68a138042415 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -69,7 +69,7 @@ - src/tasks/MobileBuildTasks/Apple/AppleProject.cs - https://github.com/dotnet/sdk repo > src/Installer/redist-installer/targets/GeneratePKG.targets --> - 21 + 28 12.2 12.2 12.0 diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index b27eae7765a0d3..94d2bc9efb613e 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -81,6 +81,7 @@ build_native() if [[ "$targetOS" == android || "$targetOS" == linux-bionic ]]; then # Keep in sync with $(AndroidApiLevelMin) in Directory.Build.props in the repository rooot local ANDROID_API_LEVEL=21 + if [[ -z "$ANDROID_NDK_ROOT" ]]; then echo "Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root." exit 1 diff --git a/src/native/external/libunwind_extras/CMakeLists.txt b/src/native/external/libunwind_extras/CMakeLists.txt index 8b7b708b702649..1b9751b66ac6b0 100644 --- a/src/native/external/libunwind_extras/CMakeLists.txt +++ b/src/native/external/libunwind_extras/CMakeLists.txt @@ -11,6 +11,8 @@ add_definitions(-DPACKAGE_STRING="") add_definitions(-DPACKAGE_BUGREPORT="") add_definitions(-DHAVE_DL_ITERATE_PHDR=1) + + if(CLR_CMAKE_HOST_UNIX) if (CLR_CMAKE_HOST_ARCH_AMD64) set(arch x86_64) From 06c1c83f3119af9493e34bb34ca273750fb0cae7 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 6 Dec 2024 13:55:45 +0100 Subject: [PATCH 02/63] Beginnings of native Android build --- eng/native/build-commons.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 94d2bc9efb613e..b27eae7765a0d3 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -81,7 +81,6 @@ build_native() if [[ "$targetOS" == android || "$targetOS" == linux-bionic ]]; then # Keep in sync with $(AndroidApiLevelMin) in Directory.Build.props in the repository rooot local ANDROID_API_LEVEL=21 - if [[ -z "$ANDROID_NDK_ROOT" ]]; then echo "Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root." exit 1 From 62189fcdea085e5b395c0f5b18157a8456a1f571 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 11 Dec 2024 16:53:54 -0500 Subject: [PATCH 03/63] Bump min API level to 29 (proper TLS support) and link the right system.native library for the singlefilehost --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 5c68a138042415..09e95cb181ca32 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -69,7 +69,7 @@ - src/tasks/MobileBuildTasks/Apple/AppleProject.cs - https://github.com/dotnet/sdk repo > src/Installer/redist-installer/targets/GeneratePKG.targets --> - 28 + 29 12.2 12.2 12.0 From f9f7b90b0b0639c2065143bf3e59d74b83463e0a Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 12 Dec 2024 22:19:56 -0500 Subject: [PATCH 04/63] Fix host/target confusion in R2R tool publish / Add Android target to R2R that acts like linux --- eng/native/naming.props | 1 + src/coreclr/tools/Common/CommandLineHelpers.cs | 3 ++- .../tools/Common/TypeSystem/Common/TargetDetails.cs | 3 ++- .../ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs | 1 + src/coreclr/tools/aot/crossgen2/crossgen2.props | 7 +++++++ src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj | 4 +++- 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/eng/native/naming.props b/eng/native/naming.props index aa59f00c79030e..d1e1b3c552009b 100644 --- a/eng/native/naming.props +++ b/eng/native/naming.props @@ -2,6 +2,7 @@ lib .exe + $(HostOS) diff --git a/src/coreclr/tools/Common/CommandLineHelpers.cs b/src/coreclr/tools/Common/CommandLineHelpers.cs index 7f93e48a8949f6..c2741931c79962 100644 --- a/src/coreclr/tools/Common/CommandLineHelpers.cs +++ b/src/coreclr/tools/Common/CommandLineHelpers.cs @@ -60,7 +60,7 @@ public static TargetOS GetTargetOS(string token) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return TargetOS.Windows; - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"))) return TargetOS.Linux; else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return TargetOS.OSX; @@ -81,6 +81,7 @@ public static TargetOS GetTargetOS(string token) "ios" => TargetOS.iOS, "tvossimulator" => TargetOS.tvOSSimulator, "tvos" => TargetOS.tvOS, + "android" => TargetOS.Android, _ => throw new CommandLineException($"Target OS '{token}' is not supported") }; } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs index bb7929b88affe2..a0bee20e6b0ff6 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs @@ -23,7 +23,8 @@ public enum TargetOS FreeBSD, NetBSD, SunOS, - WebAssembly + WebAssembly, + Android } public enum TargetAbi diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs index ef76a9abcce5bb..1a18bfe9fca950 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs @@ -109,6 +109,7 @@ public static MachineOSOverride MachineOSOverrideFromTarget(this TargetDetails t return MachineOSOverride.Windows; case TargetOS.Linux: + case TargetOS.Android: return MachineOSOverride.Linux; case TargetOS.OSX: diff --git a/src/coreclr/tools/aot/crossgen2/crossgen2.props b/src/coreclr/tools/aot/crossgen2/crossgen2.props index 2ec464eaa54bd5..0242e4b45222f7 100644 --- a/src/coreclr/tools/aot/crossgen2/crossgen2.props +++ b/src/coreclr/tools/aot/crossgen2/crossgen2.props @@ -43,6 +43,13 @@ + + <_LibPrefix Condition="'$(_IsCrossHostPublish)' == 'true'">$(LibPrefix) + <_LibPrefix Condition="'$(_IsCrossHostPublish)' != 'true'">$(HostLibPrefix) + <_LibSuffix Condition="'$(_IsCrossHostPublish)' == 'true'">$(LibSuffix) + <_LibSuffix Condition="'$(_IsCrossHostPublish)' != 'true'">$(HostLibSuffix) + + $(TargetArchitecture) $(CrossHostArch) diff --git a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj index c7041857e08577..259535813bdbf5 100644 --- a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj +++ b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj @@ -2,12 +2,14 @@ <_IsPublishing>true - $(PackageRID) + $(NETCoreSdkPortableRuntimeIdentifier) + $(PackageRID) $(RuntimeBinDir)crossgen2-published/ true true false true + <_IsCrossHostPublish>true From 2a1535e40eceeeb543b65754997478d006832acb Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 6 Dec 2024 13:55:45 +0100 Subject: [PATCH 05/63] Beginnings of native Android build --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 09e95cb181ca32..bff6874d7bbe4d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -69,7 +69,7 @@ - src/tasks/MobileBuildTasks/Apple/AppleProject.cs - https://github.com/dotnet/sdk repo > src/Installer/redist-installer/targets/GeneratePKG.targets --> - 29 + 21 12.2 12.2 12.0 From 10e88b0ce568fc593e0fc596a1c7a98e8aaaafdc Mon Sep 17 00:00:00 2001 From: Ivan Povazan Date: Fri, 10 Jan 2025 10:05:10 +0100 Subject: [PATCH 06/63] Cleanup --- eng/native/naming.props | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/native/naming.props b/eng/native/naming.props index d1e1b3c552009b..aa59f00c79030e 100644 --- a/eng/native/naming.props +++ b/eng/native/naming.props @@ -2,7 +2,6 @@ lib .exe - $(HostOS) From c2b4eac7c81d9ac36702280499d72b5633cce827 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Fri, 10 Jan 2025 13:52:16 -0500 Subject: [PATCH 07/63] Revert changes to R2R that alias Android to linux and put it in a few msbuild places instead. --- src/coreclr/tools/Common/CommandLineHelpers.cs | 3 +-- src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs | 3 +-- .../aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/coreclr/tools/Common/CommandLineHelpers.cs b/src/coreclr/tools/Common/CommandLineHelpers.cs index c2741931c79962..7f93e48a8949f6 100644 --- a/src/coreclr/tools/Common/CommandLineHelpers.cs +++ b/src/coreclr/tools/Common/CommandLineHelpers.cs @@ -60,7 +60,7 @@ public static TargetOS GetTargetOS(string token) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return TargetOS.Windows; - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"))) + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return TargetOS.Linux; else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return TargetOS.OSX; @@ -81,7 +81,6 @@ public static TargetOS GetTargetOS(string token) "ios" => TargetOS.iOS, "tvossimulator" => TargetOS.tvOSSimulator, "tvos" => TargetOS.tvOS, - "android" => TargetOS.Android, _ => throw new CommandLineException($"Target OS '{token}' is not supported") }; } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs index a0bee20e6b0ff6..bb7929b88affe2 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs @@ -23,8 +23,7 @@ public enum TargetOS FreeBSD, NetBSD, SunOS, - WebAssembly, - Android + WebAssembly } public enum TargetAbi diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs index 1a18bfe9fca950..ef76a9abcce5bb 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs @@ -109,7 +109,6 @@ public static MachineOSOverride MachineOSOverrideFromTarget(this TargetDetails t return MachineOSOverride.Windows; case TargetOS.Linux: - case TargetOS.Android: return MachineOSOverride.Linux; case TargetOS.OSX: From aebb13f7ec11cd50fcd0874a0bf17ef81f98eee3 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Tue, 14 Jan 2025 09:48:02 -0500 Subject: [PATCH 08/63] Undo host awareness in crossgen_publish as building it is about the target --- src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj index 259535813bdbf5..c7041857e08577 100644 --- a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj +++ b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj @@ -2,14 +2,12 @@ <_IsPublishing>true - $(NETCoreSdkPortableRuntimeIdentifier) - $(PackageRID) + $(PackageRID) $(RuntimeBinDir)crossgen2-published/ true true false true - <_IsCrossHostPublish>true From 766af9b3a5a1192e6dbbece2a5da801080d433b3 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 15 Jan 2025 09:55:55 -0500 Subject: [PATCH 09/63] Make sure android runtime pack is generated and crossgen_inbuild uses host lib prefix/suffix on cross builds --- src/coreclr/tools/aot/crossgen2/crossgen2.props | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/tools/aot/crossgen2/crossgen2.props b/src/coreclr/tools/aot/crossgen2/crossgen2.props index 0242e4b45222f7..a2de4becafa015 100644 --- a/src/coreclr/tools/aot/crossgen2/crossgen2.props +++ b/src/coreclr/tools/aot/crossgen2/crossgen2.props @@ -44,10 +44,10 @@ - <_LibPrefix Condition="'$(_IsCrossHostPublish)' == 'true'">$(LibPrefix) - <_LibPrefix Condition="'$(_IsCrossHostPublish)' != 'true'">$(HostLibPrefix) - <_LibSuffix Condition="'$(_IsCrossHostPublish)' == 'true'">$(LibSuffix) - <_LibSuffix Condition="'$(_IsCrossHostPublish)' != 'true'">$(HostLibSuffix) + <_LibPrefix Condition="'$(CrossHostArch)' == 'true'">$(LibPrefix) + <_LibPrefix Condition="'$(CrossHostArch)' != 'true'">$(HostLibPrefix) + <_LibSuffix Condition="'$(CrossHostArch)' == 'true'">$(LibSuffix) + <_LibSuffix Condition="'$(CrossHostArch)' != 'true'">$(HostLibSuffix) From 4f9e6802e4d184087fae39b1e679f9d677abe5a1 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 15 Jan 2025 14:38:04 -0500 Subject: [PATCH 10/63] Condition min api level for coreclr and not. --- src/native/external/libunwind_extras/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/native/external/libunwind_extras/CMakeLists.txt b/src/native/external/libunwind_extras/CMakeLists.txt index 1b9751b66ac6b0..8b7b708b702649 100644 --- a/src/native/external/libunwind_extras/CMakeLists.txt +++ b/src/native/external/libunwind_extras/CMakeLists.txt @@ -11,8 +11,6 @@ add_definitions(-DPACKAGE_STRING="") add_definitions(-DPACKAGE_BUGREPORT="") add_definitions(-DHAVE_DL_ITERATE_PHDR=1) - - if(CLR_CMAKE_HOST_UNIX) if (CLR_CMAKE_HOST_ARCH_AMD64) set(arch x86_64) From 2509f3fa938c8ee8ba869e8d64c301ddc24e32e6 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 15 Jan 2025 23:30:17 -0500 Subject: [PATCH 11/63] Add FEATURE_NATIVEAOT_ONLY --- src/coreclr/CMakeLists.txt | 2 +- src/coreclr/clrfeatures.cmake | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 405cf527687c1a..1cb6181963fc7f 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -116,7 +116,7 @@ endif() #---------------------------------------------------- # Build the test watchdog alongside the CLR #---------------------------------------------------- -if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) +if(NOT FEATURE_NATIVEAOT_ONLY) add_subdirectory("${CLR_SRC_NATIVE_DIR}/watchdog" test-watchdog) endif() diff --git a/src/coreclr/clrfeatures.cmake b/src/coreclr/clrfeatures.cmake index 83cf4818add318..1b1eec6c3aefc5 100644 --- a/src/coreclr/clrfeatures.cmake +++ b/src/coreclr/clrfeatures.cmake @@ -47,4 +47,5 @@ endif() if (CLR_CMAKE_TARGET_WIN32) set(FEATURE_TYPEEQUIVALENCE 1) -endif(CLR_CMAKE_TARGET_WIN32) \ No newline at end of file +endif(CLR_CMAKE_TARGET_WIN32) + From 37d326f72a5a07694cfd424646fef43b5b3349ab Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 16 Jan 2025 07:53:37 -0500 Subject: [PATCH 12/63] Revert FEATURE_NATIVEAOT_ONLY --- src/coreclr/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 1cb6181963fc7f..405cf527687c1a 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -116,7 +116,7 @@ endif() #---------------------------------------------------- # Build the test watchdog alongside the CLR #---------------------------------------------------- -if(NOT FEATURE_NATIVEAOT_ONLY) +if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) add_subdirectory("${CLR_SRC_NATIVE_DIR}/watchdog" test-watchdog) endif() From ee65f011c59e7cb2b371965f0f557dcc4e828f9b Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 16 Jan 2025 11:59:35 -0500 Subject: [PATCH 13/63] Set PrimaryRuntimeFlavor on mobile official build and don't try to generate android coreclr runtime packs during a mono android build --- eng/Subsets.props | 5 +++++ eng/pipelines/runtime-official.yml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/eng/Subsets.props b/eng/Subsets.props index c43840784acef3..cb522ee3f7c71f 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -57,6 +57,11 @@ $(DefaultPrimaryRuntimeFlavor) + + + false + + clr+mono+libs+tools+host+packs mono+libs+packs diff --git a/eng/pipelines/runtime-official.yml b/eng/pipelines/runtime-official.yml index 03c4308e13aebf..75953e0a1ab557 100644 --- a/eng/pipelines/runtime-official.yml +++ b/eng/pipelines/runtime-official.yml @@ -256,7 +256,7 @@ extends: - linux_bionic_arm64 jobParameters: templatePath: 'templates-official' - buildArgs: -c $(_BuildConfig) /p:BuildMonoAOTCrossCompiler=false /p:DotNetBuildAllRuntimePacks=true + buildArgs: -c $(_BuildConfig) /p:BuildMonoAOTCrossCompiler=false /p:DotNetBuildAllRuntimePacks=true /p:PrimaryRuntimeFlavor=Mono nameSuffix: AllRuntimes isOfficialBuild: ${{ variables.isOfficialBuild }} postBuildSteps: From c17e21e7974104903add27d874566ae1503bbbbb Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 16 Jan 2025 17:39:49 -0500 Subject: [PATCH 14/63] Override API level in coreclr runtime.proj and flow runtimeFlavor into build-commons.sh --- eng/native/build-commons.sh | 11 ++++++----- src/coreclr/build-runtime.sh | 7 ++++++- src/coreclr/runtime.proj | 5 +++++ src/native/libs/build-native.proj | 3 ++- src/native/libs/build-native.sh | 7 ++++++- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index b27eae7765a0d3..327459ae9efd2c 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -54,11 +54,12 @@ build_native() targetOS="$1" hostArch="$2" - cmakeDir="$3" - intermediatesDir="$4" - target="$5" - cmakeArgs="$6" - message="$7" + runtimeFlavor="$3" + cmakeDir="$4" + intermediatesDir="$5" + target="$6" + cmakeArgs="$7" + message="$8" # All set to commence the build echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__TargetArch.$__BuildType in $intermediatesDir" diff --git a/src/coreclr/build-runtime.sh b/src/coreclr/build-runtime.sh index 52fcb9ef3714cf..5649f95c788346 100755 --- a/src/coreclr/build-runtime.sh +++ b/src/coreclr/build-runtime.sh @@ -58,6 +58,11 @@ handle_arguments_local() { __SubDir="$2" __ShiftArgs=1 ;; + + runtimeflavor|-runtimeflavor) + __RuntimeFlavor="$2" + __ShiftArgs=1 + ;; *) __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" @@ -180,7 +185,7 @@ fi eval "$__RepoRootDir/eng/native/version/copy_version_files.sh" -build_native "$__HostOS" "$__HostArch" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeTarget" "$__CMakeArgs" "CoreCLR component" +build_native "$__HostOS" "$__HostArch" "$__RuntimeFlavor" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeTarget" "$__CMakeArgs" "CoreCLR component" # Build complete diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index b0bb03f3f0f662..977902ed1c34bf 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -6,6 +6,10 @@ true + + 29 + + @@ -42,6 +46,7 @@ <_CoreClrBuildArg Condition="'$(PgoInstrument)' == 'true'" Include="-pgoinstrument" /> <_CoreClrBuildArg Condition="'$(NativeOptimizationDataSupported)' == 'true' and '$(NoPgoOptimize)' != 'true' and '$(PgoInstrument)' != 'true'" Include="-pgodatapath "$(PgoPackagePath)"" /> <_CoreClrBuildArg Condition="'$(HostArchitecture)' != ''" Include="-hostarch $(HostArchitecture)" /> + <_CoreClrBuildArg Condition="'$(RuntimeFlavor)' != ''" Include="-runtimeflavor $(RuntimeFlavor)" /> <_CoreClrBuildArg Condition="'$(EnableNativeSanitizers)' != ''" Include="-fsanitize $(EnableNativeSanitizers)" /> <_CoreClrBuildArg Condition="'$(HostCrossOS)' != ''" Include="-hostos $(HostCrossOS)" /> <_CoreClrBuildArg Include="-outputrid $(OutputRID)" /> diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index e3f9e73c3c0196..3e4803cb7c64d0 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -18,8 +18,9 @@ <_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native <_IcuDirArg Condition="'$(_IcuDir)' != ''"> icudir "$(_IcuDir)" + <_RuntimeFlavorArg> runtimeflavor "$(RuntimeFlavor)" - <_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_UsePThreads) + <_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_RuntimeFlavorArg)$(_UsePThreads) diff --git a/src/native/libs/build-native.sh b/src/native/libs/build-native.sh index 5169732c2d641b..4b9c8e02a0f3d0 100755 --- a/src/native/libs/build-native.sh +++ b/src/native/libs/build-native.sh @@ -28,6 +28,11 @@ handle_arguments() { staticliblink|-staticliblink) __StaticLibLink=1 ;; + + runtimeflavor|-runtimeflavor) + __runtimeFlavor="$2" + __ShiftArgs=1 + ;; *) __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" @@ -174,4 +179,4 @@ setup_dirs check_prereqs # Build the corefx native components. -build_native "$__TargetOS" "$__TargetArch" "$__nativeroot" "$__IntermediatesDir" "install" "$__CMakeArgs" "native libraries component" +build_native "$__TargetOS" "$__TargetArch" "$__runtimeFlavor" "$__nativeroot" "$__IntermediatesDir" "install" "$__CMakeArgs" "native libraries component" From 83d394bfb4a3097bdeee32690e76d2dadb73f5cd Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 16 Jan 2025 20:45:28 -0500 Subject: [PATCH 15/63] Disable ThreadStatic optimizations until emulated TLS support is added --- src/coreclr/runtime.proj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index 977902ed1c34bf..f0398cd35d31c9 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -7,7 +7,8 @@ - 29 + + 28 From 0f53984072bbc48b1dbee240aa45e60f912f38d2 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 16 Jan 2025 21:39:20 -0500 Subject: [PATCH 16/63] Using API level 21 should be good now --- eng/native/build-commons.sh | 11 +++++------ src/coreclr/build-runtime.sh | 7 +------ src/coreclr/runtime.proj | 6 ------ src/native/libs/build-native.proj | 3 +-- src/native/libs/build-native.sh | 7 +------ 5 files changed, 8 insertions(+), 26 deletions(-) diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 327459ae9efd2c..b27eae7765a0d3 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -54,12 +54,11 @@ build_native() targetOS="$1" hostArch="$2" - runtimeFlavor="$3" - cmakeDir="$4" - intermediatesDir="$5" - target="$6" - cmakeArgs="$7" - message="$8" + cmakeDir="$3" + intermediatesDir="$4" + target="$5" + cmakeArgs="$6" + message="$7" # All set to commence the build echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__TargetArch.$__BuildType in $intermediatesDir" diff --git a/src/coreclr/build-runtime.sh b/src/coreclr/build-runtime.sh index 5649f95c788346..52fcb9ef3714cf 100755 --- a/src/coreclr/build-runtime.sh +++ b/src/coreclr/build-runtime.sh @@ -58,11 +58,6 @@ handle_arguments_local() { __SubDir="$2" __ShiftArgs=1 ;; - - runtimeflavor|-runtimeflavor) - __RuntimeFlavor="$2" - __ShiftArgs=1 - ;; *) __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" @@ -185,7 +180,7 @@ fi eval "$__RepoRootDir/eng/native/version/copy_version_files.sh" -build_native "$__HostOS" "$__HostArch" "$__RuntimeFlavor" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeTarget" "$__CMakeArgs" "CoreCLR component" +build_native "$__HostOS" "$__HostArch" "$__ProjectRoot" "$__IntermediatesDir" "$__CMakeTarget" "$__CMakeArgs" "CoreCLR component" # Build complete diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index f0398cd35d31c9..b0bb03f3f0f662 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -6,11 +6,6 @@ true - - - 28 - - @@ -47,7 +42,6 @@ <_CoreClrBuildArg Condition="'$(PgoInstrument)' == 'true'" Include="-pgoinstrument" /> <_CoreClrBuildArg Condition="'$(NativeOptimizationDataSupported)' == 'true' and '$(NoPgoOptimize)' != 'true' and '$(PgoInstrument)' != 'true'" Include="-pgodatapath "$(PgoPackagePath)"" /> <_CoreClrBuildArg Condition="'$(HostArchitecture)' != ''" Include="-hostarch $(HostArchitecture)" /> - <_CoreClrBuildArg Condition="'$(RuntimeFlavor)' != ''" Include="-runtimeflavor $(RuntimeFlavor)" /> <_CoreClrBuildArg Condition="'$(EnableNativeSanitizers)' != ''" Include="-fsanitize $(EnableNativeSanitizers)" /> <_CoreClrBuildArg Condition="'$(HostCrossOS)' != ''" Include="-hostos $(HostCrossOS)" /> <_CoreClrBuildArg Include="-outputrid $(OutputRID)" /> diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index 3e4803cb7c64d0..e3f9e73c3c0196 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -18,9 +18,8 @@ <_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native <_IcuDirArg Condition="'$(_IcuDir)' != ''"> icudir "$(_IcuDir)" - <_RuntimeFlavorArg> runtimeflavor "$(RuntimeFlavor)" - <_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_RuntimeFlavorArg)$(_UsePThreads) + <_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_UsePThreads) diff --git a/src/native/libs/build-native.sh b/src/native/libs/build-native.sh index 4b9c8e02a0f3d0..5169732c2d641b 100755 --- a/src/native/libs/build-native.sh +++ b/src/native/libs/build-native.sh @@ -28,11 +28,6 @@ handle_arguments() { staticliblink|-staticliblink) __StaticLibLink=1 ;; - - runtimeflavor|-runtimeflavor) - __runtimeFlavor="$2" - __ShiftArgs=1 - ;; *) __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" @@ -179,4 +174,4 @@ setup_dirs check_prereqs # Build the corefx native components. -build_native "$__TargetOS" "$__TargetArch" "$__runtimeFlavor" "$__nativeroot" "$__IntermediatesDir" "install" "$__CMakeArgs" "native libraries component" +build_native "$__TargetOS" "$__TargetArch" "$__nativeroot" "$__IntermediatesDir" "install" "$__CMakeArgs" "native libraries component" From 55cc33cd106bf14dfc48f7de08766ad03663f3a1 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Fri, 17 Jan 2025 12:14:49 +0100 Subject: [PATCH 17/63] Set runtime feature flag in cmake config --- eng/native/configuretools.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/eng/native/configuretools.cmake b/eng/native/configuretools.cmake index de4571f905a5e5..7a0f366fc59760 100644 --- a/eng/native/configuretools.cmake +++ b/eng/native/configuretools.cmake @@ -115,3 +115,12 @@ if (CLR_CMAKE_HOST_LINUX) set(CLR_CMAKE_TARGET_LINUX_MUSL 1) endif() endif() + +# Common configuration for all runtimes, set runtime feature flag +string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER) + +if(PROJECT_NAME_LOWER STREQUAL "coreclr") + set(CLR_CMAKE_RUNTIME_CORECLR 1) +elseif(PROJECT_NAME_LOWER STREQUAL "mono") + set(CLR_CMAKE_RUNTIME_MONO 1) +endif() From 0b007c37deed80296c09331d593128a3dda8b69e Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Sat, 18 Jan 2025 09:15:15 -0500 Subject: [PATCH 18/63] Don't get in the way of building coreclr+mono runtimes together. Works on arm64 right now --- eng/Subsets.props | 9 ++++----- eng/pipelines/runtime-official.yml | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/eng/Subsets.props b/eng/Subsets.props index cb522ee3f7c71f..624e44aa51da53 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -57,11 +57,6 @@ $(DefaultPrimaryRuntimeFlavor) - - - false - - clr+mono+libs+tools+host+packs mono+libs+packs @@ -92,7 +87,11 @@ <_subset Condition="'$(Subset)' != ''">+$(Subset.ToLowerInvariant())+ <_subset Condition="'$(Subset)' == ''">+$(DefaultSubsets)+ +<<<<<<< HEAD +======= + +>>>>>>> 5a94dea4066 (Don't get in the way of building coreclr+mono runtimes together. Works on arm64 right now) CoreCLR diff --git a/eng/pipelines/runtime-official.yml b/eng/pipelines/runtime-official.yml index 75953e0a1ab557..03c4308e13aebf 100644 --- a/eng/pipelines/runtime-official.yml +++ b/eng/pipelines/runtime-official.yml @@ -256,7 +256,7 @@ extends: - linux_bionic_arm64 jobParameters: templatePath: 'templates-official' - buildArgs: -c $(_BuildConfig) /p:BuildMonoAOTCrossCompiler=false /p:DotNetBuildAllRuntimePacks=true /p:PrimaryRuntimeFlavor=Mono + buildArgs: -c $(_BuildConfig) /p:BuildMonoAOTCrossCompiler=false /p:DotNetBuildAllRuntimePacks=true nameSuffix: AllRuntimes isOfficialBuild: ${{ variables.isOfficialBuild }} postBuildSteps: From 686bace31b798784df494313ec9a29f29dde50d1 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 22 Jan 2025 16:52:14 -0500 Subject: [PATCH 19/63] Allow cross build on osx when targeting arm32, fix bad arm32 linker arg, and exclude asm routines on x64 build --- eng/native/tryrun.cmake | 1 + src/coreclr/tools/aot/crossgen2/crossgen2.props | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/eng/native/tryrun.cmake b/eng/native/tryrun.cmake index 2397f8dcc8f209..e6aea985591cee 100644 --- a/eng/native/tryrun.cmake +++ b/eng/native/tryrun.cmake @@ -1,5 +1,6 @@ set(CROSS_ROOTFS $ENV{ROOTFS_DIR}) set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH}) +set(ANDROID_BUILD $ENV{ANDROID_BUILD}) # Also allow building as Android without specifying `-cross`. if(NOT DEFINED TARGET_ARCH_NAME AND DEFINED ANDROID_BUILD) diff --git a/src/coreclr/tools/aot/crossgen2/crossgen2.props b/src/coreclr/tools/aot/crossgen2/crossgen2.props index a2de4becafa015..2ec464eaa54bd5 100644 --- a/src/coreclr/tools/aot/crossgen2/crossgen2.props +++ b/src/coreclr/tools/aot/crossgen2/crossgen2.props @@ -43,13 +43,6 @@ - - <_LibPrefix Condition="'$(CrossHostArch)' == 'true'">$(LibPrefix) - <_LibPrefix Condition="'$(CrossHostArch)' != 'true'">$(HostLibPrefix) - <_LibSuffix Condition="'$(CrossHostArch)' == 'true'">$(LibSuffix) - <_LibSuffix Condition="'$(CrossHostArch)' != 'true'">$(HostLibSuffix) - - $(TargetArchitecture) $(CrossHostArch) From 6f01f1d774f518bc332543e9d0cba7767858ea93 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 22 Jan 2025 17:30:44 -0500 Subject: [PATCH 20/63] Revert CLR_CMAKE_RUNTIME_CORECLR and enable event pipe TCP stuff --- eng/native/configuretools.cmake | 9 --------- 1 file changed, 9 deletions(-) diff --git a/eng/native/configuretools.cmake b/eng/native/configuretools.cmake index 7a0f366fc59760..de4571f905a5e5 100644 --- a/eng/native/configuretools.cmake +++ b/eng/native/configuretools.cmake @@ -115,12 +115,3 @@ if (CLR_CMAKE_HOST_LINUX) set(CLR_CMAKE_TARGET_LINUX_MUSL 1) endif() endif() - -# Common configuration for all runtimes, set runtime feature flag -string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER) - -if(PROJECT_NAME_LOWER STREQUAL "coreclr") - set(CLR_CMAKE_RUNTIME_CORECLR 1) -elseif(PROJECT_NAME_LOWER STREQUAL "mono") - set(CLR_CMAKE_RUNTIME_MONO 1) -endif() From 614333951b399e576bc8d44f6fdf90dbd35ba7ae Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Wed, 22 Jan 2025 21:02:59 -0500 Subject: [PATCH 21/63] Exclude arm and x86 from generating packages / Always set CrossBuild=true when dealing with android --- eng/Subsets.props | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eng/Subsets.props b/eng/Subsets.props index 624e44aa51da53..c43840784acef3 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -87,11 +87,7 @@ <_subset Condition="'$(Subset)' != ''">+$(Subset.ToLowerInvariant())+ <_subset Condition="'$(Subset)' == ''">+$(DefaultSubsets)+ -<<<<<<< HEAD -======= - ->>>>>>> 5a94dea4066 (Don't get in the way of building coreclr+mono runtimes together. Works on arm64 right now) CoreCLR From d662757161f03badafbb7c56a1fc21718d2e8403 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 24 Jan 2025 21:08:38 +0100 Subject: [PATCH 22/63] Initial Android CoreCLR initialization function implementation Not tested at run time yet (require some changes in the XA runtime first) --- .../dlls/mscoree/coreclr/CMakeLists.txt | 4 + src/coreclr/dlls/mscoree/exports.cpp | 137 ++++++++++++++++++ .../dlls/mscoree/mscorwks_unixexports.src | 3 + src/coreclr/hosts/inc/coreclrhost.h | 13 ++ src/native/corehost/host_runtime_contract.h | 13 ++ 5 files changed, 170 insertions(+) diff --git a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt index 2ecb150aa97327..2355bd12091f43 100644 --- a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt @@ -187,6 +187,10 @@ endif() target_sources(coreclr PUBLIC $) target_link_libraries(coreclr PUBLIC ${CORECLR_LIBRARIES} ${CLRJIT_STATIC} cee_wks ${FOUNDATION}) +if (CLR_CMAKE_TARGET_ANDROID) +target_link_libraries(coreclr PUBLIC log) +endif() + target_sources(coreclr_static PUBLIC $) target_link_libraries(coreclr_static PUBLIC ${CORECLR_LIBRARIES} clrjit_static cee_wks_mergeable ${FOUNDATION}) target_compile_definitions(coreclr_static PUBLIC CORECLR_EMBEDDED) diff --git a/src/coreclr/dlls/mscoree/exports.cpp b/src/coreclr/dlls/mscoree/exports.cpp index 8c28aa0545a85c..b7e16faf1512bb 100644 --- a/src/coreclr/dlls/mscoree/exports.cpp +++ b/src/coreclr/dlls/mscoree/exports.cpp @@ -23,6 +23,10 @@ #include #include +#if defined(TARGET_ANDROID) +#include +#endif // TARGET_ANDROID + #define ASSERTE_ALL_BUILDS(expr) _ASSERTE_ALL_BUILDS((expr)) #ifdef TARGET_UNIX @@ -74,6 +78,19 @@ class ConstWStringArrayHolder : public NewArrayHolder } }; +#if defined(TARGET_ANDROID) +namespace { + constexpr static char ANDROID_LOGCAT_TAG[] { "CoreCLR" }; + void LogErrorToLogcat(int priority, const char* format, ...) noexcept + { + va_list args; + va_start(args, format); + __android_log_vprint(priority, ANDROID_LOGCAT_TAG, format, args); + va_end(args); + } +} +#endif + // Convert 8 bit string to unicode static LPCWSTR StringToUnicode(LPCSTR str) { @@ -130,6 +147,30 @@ static void InitializeStartupFlags(STARTUP_FLAGS* startupFlagsRef) *startupFlagsRef = startupFlags; } +#if defined(TARGET_ANDROID) +static void ConvertConfigPropertiesToUnicode( + const host_configuration_properties* properties, + LPCWSTR** propertyKeysWRef, + LPCWSTR** propertyValuesWRef) +{ + LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[properties->nitems]; + ASSERTE_ALL_BUILDS(propertyKeysW != nullptr); + + LPCWSTR* propertyValuesW = new (nothrow) LPCWSTR[properties->nitems]; + ASSERTE_ALL_BUILDS(propertyValuesW != nullptr); + + for (size_t propertyIndex = 0; propertyIndex < properties->nitems; ++propertyIndex) + { + host_configuration_property const& prop = properties->data[propertyIndex]; + propertyKeysW[propertyIndex] = prop.name; + propertyValuesW[propertyIndex] = prop.value; + } + + *propertyKeysWRef = propertyKeysW; + *propertyValuesWRef = propertyValuesW; +} +#endif + static void ConvertConfigPropertiesToUnicode( const char** propertyKeys, const char** propertyValues, @@ -214,6 +255,102 @@ GetInfoForMethodDelegate getInfoForMethodDelegate = NULL; extern "C" int coreclr_create_delegate(void*, unsigned int, const char*, const char*, const char*, void**); #endif //FEATURE_GDBJIT +#if defined(TARGET_ANDROID) +extern "C" +NOINLINE +DLLEXPORT +int android_coreclr_initialize( + const char* appName, + const char16_t* appDomainFriendlyName, + host_runtime_contract* hostContract, + const host_configuration_properties* properties, + void **hostHandle, + unsigned int* domainId) +{ + HostingApiFrameHolder apiFrameHolder(_ReturnAddress()); + + if (properties == nullptr) { [[unlikely]] + LogErrorToLogcat(ANDROID_LOG_FATAL, "Initialization routine was not passed the required configuration properties pointer."); + return HOST_E_INVALIDOPERATION; + } + + if (properties->data == nullptr) { [[unlikely]] + LogErrorToLogcat(ANDROID_LOG_FATAL, "Initialization routine was not passed valid configuration properties data."); + return HOST_E_INVALIDOPERATION; + } + + if (hostContract == nullptr) { [[unlikely]] + LogErrorToLogcat(ANDROID_LOG_FATAL, "Initialization routine was not passed the required host contract pointer."); + return HOST_E_INVALIDOPERATION; + } + + if (hostContract->pinvoke_override == nullptr) { [[unlikely]] + LogErrorToLogcat(ANDROID_LOG_FATAL, "Host contract isn't initialized properly: missing p/invoke override handler."); + return HOST_E_INVALIDOPERATION; + } + + if (hostContract->bundle_probe == nullptr) { [[unlikely]] + LogErrorToLogcat(ANDROID_LOG_FATAL, "Host contract isn't initialized properly: missing bundle probe handler."); + return HOST_E_INVALIDOPERATION; + } + + LPCWSTR* propertyKeysW = nullptr; + LPCWSTR* propertyValuesW = nullptr; + ConvertConfigPropertiesToUnicode (properties, &propertyKeysW, &propertyValuesW); + + // Android doesn't have executables as such (at least as far as Android applications are concerned), + // so we will use application name (package name) as the "executable path" here. + DWORD error = PAL_InitializeCoreCLR(appName, g_coreclr_embedded); + HRESULT hr = HRESULT_FROM_WIN32(error); + + // If PAL initialization failed, then we should return right away and avoid + // calling any other APIs because they can end up calling into the PAL layer again. + if (FAILED(hr)) + { + return hr; + } + + HostInformation::SetContract(hostContract); + PInvokeOverride::SetPInvokeOverride(hostContract->pinvoke_override, PInvokeOverride::Source::RuntimeConfiguration); + + ReleaseHolder host; + hr = CorHost2::CreateObject(IID_ICLRRuntimeHost4, (void**)&host); + IfFailRet(hr); + + static Bundle bundle(appName, hostContract->bundle_probe); + Bundle::AppBundle = &bundle; + + // This will take ownership of propertyKeysWTemp and propertyValuesWTemp + Configuration::InitializeConfigurationKnobs(static_cast(properties->nitems), propertyKeysW, propertyValuesW); + + STARTUP_FLAGS startupFlags; + InitializeStartupFlags(&startupFlags); + + hr = host->SetStartupFlags(startupFlags); + IfFailRet(hr); + + hr = host->Start(); + IfFailRet(hr); + + hr = host->CreateAppDomainWithManager( + appDomainFriendlyName, + APPDOMAIN_SECURITY_DEFAULT, + nullptr, // Name of the assembly that contains the AppDomainManager implementation + nullptr, // The AppDomainManager implementation type name + static_cast(properties->nitems), + propertyKeysW, + propertyValuesW, + (DWORD *)domainId); + + if (SUCCEEDED(hr)) + { + host.SuppressRelease(); + *hostHandle = host; + } + return hr; +} +#endif // TARGET_ANDROID + // // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain // diff --git a/src/coreclr/dlls/mscoree/mscorwks_unixexports.src b/src/coreclr/dlls/mscoree/mscorwks_unixexports.src index 3eacb7fa484856..4e52fcf5a997e2 100644 --- a/src/coreclr/dlls/mscoree/mscorwks_unixexports.src +++ b/src/coreclr/dlls/mscoree/mscorwks_unixexports.src @@ -1,3 +1,6 @@ +; Android hosting API +android_coreclr_initialize + ; Unix hosting API coreclr_create_delegate coreclr_execute_assembly diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index 0a72016cebf8aa..c29e41c9508454 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -22,6 +22,10 @@ #define CORECLR_HOSTING_API_LINKAGE #endif +#if defined(TARGET_ANDROID) +#include "corehost/host_runtime_contract.h" +#endif + // For each hosting API, we define a function prototype and a function pointer // The prototype is useful for implicit linking against the dynamic coreclr // library and the pointer for explicit dynamic loading (dlopen, LoadLibrary) @@ -29,6 +33,15 @@ CORECLR_HOSTING_API_LINKAGE int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) +#if defined(TARGET_ANDROID) +CORECLR_HOSTING_API(android_coreclr_initialize, + const char* appName, + const char16_t* appDomainFriendlyName, + host_runtime_contract* hostContract, + const host_configuration_properties* properties, + void **hostHandle, + unsigned int* domainId); +#endif // // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain // diff --git a/src/native/corehost/host_runtime_contract.h b/src/native/corehost/host_runtime_contract.h index 7806e5ae345969..c7be6cd94f6aec 100644 --- a/src/native/corehost/host_runtime_contract.h +++ b/src/native/corehost/host_runtime_contract.h @@ -53,4 +53,17 @@ struct host_runtime_contract const char* entry_point_name); }; +#if defined(TARGET_ANDROID) +struct host_configuration_property +{ + const char16_t* name; + const char16_t* value; +}; + +struct host_configuration_properties +{ + size_t nitems; + const host_configuration_property* data; +}; +#endif #endif // __HOST_RUNTIME_CONTRACT_H__ From 73fd37ecf1805ae9c920f5682a5feea6e3130238 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 28 Jan 2025 22:08:50 +0100 Subject: [PATCH 23/63] Preparing bundle mode for Android --- src/coreclr/dlls/mscoree/exports.cpp | 14 ++++++--- src/coreclr/hosts/inc/coreclrhost.h | 4 +++ src/coreclr/inc/bundle.h | 26 ++++++++++++---- src/coreclr/vm/bundle.cpp | 33 ++++++++++++++++++--- src/coreclr/vm/peimage.cpp | 14 +++++++-- src/coreclr/vm/peimage.h | 5 ++++ src/coreclr/vm/peimage.inl | 18 ++++++++++- src/native/corehost/host_runtime_contract.h | 6 ++++ 8 files changed, 104 insertions(+), 16 deletions(-) diff --git a/src/coreclr/dlls/mscoree/exports.cpp b/src/coreclr/dlls/mscoree/exports.cpp index b7e16faf1512bb..6031fd807862f4 100644 --- a/src/coreclr/dlls/mscoree/exports.cpp +++ b/src/coreclr/dlls/mscoree/exports.cpp @@ -169,7 +169,8 @@ static void ConvertConfigPropertiesToUnicode( *propertyKeysWRef = propertyKeysW; *propertyValuesWRef = propertyValuesW; } -#endif + +#else // TARGET_ANDROID static void ConvertConfigPropertiesToUnicode( const char** propertyKeys, @@ -229,7 +230,7 @@ static void ConvertConfigPropertiesToUnicode( *propertyKeysWRef = propertyKeysW; *propertyValuesWRef = propertyValuesW; } - +#endif // !TARGET_ANDROID coreclr_error_writer_callback_fn g_errorWriter = nullptr; // @@ -289,7 +290,7 @@ int android_coreclr_initialize( return HOST_E_INVALIDOPERATION; } - if (hostContract->bundle_probe == nullptr) { [[unlikely]] + if (hostContract->android_bundle_probe == nullptr) { [[unlikely]] LogErrorToLogcat(ANDROID_LOG_FATAL, "Host contract isn't initialized properly: missing bundle probe handler."); return HOST_E_INVALIDOPERATION; } @@ -317,7 +318,7 @@ int android_coreclr_initialize( hr = CorHost2::CreateObject(IID_ICLRRuntimeHost4, (void**)&host); IfFailRet(hr); - static Bundle bundle(appName, hostContract->bundle_probe); + static Bundle bundle(appName, hostContract->android_bundle_probe); Bundle::AppBundle = &bundle; // This will take ownership of propertyKeysWTemp and propertyValuesWTemp @@ -349,6 +350,7 @@ int android_coreclr_initialize( } return hr; } + #endif // TARGET_ANDROID // @@ -378,6 +380,7 @@ int coreclr_initialize( void** hostHandle, unsigned int* domainId) { +#if !defined(TARGET_ANDROID) HRESULT hr; LPCWSTR* propertyKeysW; @@ -482,6 +485,9 @@ int coreclr_initialize( #endif } return hr; +#else // TARGET_ANDROID + return HOST_E_INVALIDOPERATION; +#endif } // diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index c29e41c9508454..d588a9693f7be9 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -163,7 +163,11 @@ CORECLR_HOSTING_API(coreclr_execute_assembly, // // Callback types used by the hosts // +#if defined(TARGET_ANDROID) +using BundleProbeFn = bool(const char* path, void** data_start, int64_t* size); +#else typedef bool(CORECLR_CALLING_CONVENTION BundleProbeFn)(const char* path, int64_t* offset, int64_t* size, int64_t* compressedSize); +#endif typedef const void* (CORECLR_CALLING_CONVENTION PInvokeOverrideFn)(const char* libraryName, const char* entrypointName); diff --git a/src/coreclr/inc/bundle.h b/src/coreclr/inc/bundle.h index 3d55a54b3515b4..5305510c019ff6 100644 --- a/src/coreclr/inc/bundle.h +++ b/src/coreclr/inc/bundle.h @@ -18,23 +18,37 @@ class Bundle; struct BundleFileLocation { INT64 Size; +#if defined(TARGET_ANDROID) + void* DataStart; + constexpr static INT64 Offset = 0; + constexpr static INT64 UncompresedSize = 0; +#else INT64 Offset; INT64 UncompresedSize; +#endif BundleFileLocation() - { + { LIMITED_METHOD_CONTRACT; Size = 0; - Offset = 0; +#if defined(TARGET_ANDROID) + DataStart = INVALID_HANDLE_VALUE; +#else + Offset = 0; UncompresedSize = 0; +#endif } static BundleFileLocation Invalid() { LIMITED_METHOD_CONTRACT; return BundleFileLocation(); } const SString &Path() const; - +#if defined(TARGET_ANDROID) + const SString &AppName() const; + bool IsValid() const { LIMITED_METHOD_CONTRACT; return DataStart != nullptr; } +#else // TARGET_ANDROID bool IsValid() const { LIMITED_METHOD_CONTRACT; return Offset != 0; } +#endif // !TARGET_ANDROID }; class Bundle @@ -51,12 +65,14 @@ class Bundle static BundleFileLocation ProbeAppBundle(const SString& path, bool pathIsBundleRelative = false); private: - +#if defined(TARGET_ANDROID) + SString m_appName; +#endif SString m_path; // The path to single-file executable BundleProbeFn *m_probe; SString m_basePath; // The prefix to denote a path within the bundle - COUNT_T m_basePathLength; + COUNT_T m_basePathLength = 0; }; #endif // _BUNDLE_H_ diff --git a/src/coreclr/vm/bundle.cpp b/src/coreclr/vm/bundle.cpp index 592372a3a7266a..f555837ac9988d 100644 --- a/src/coreclr/vm/bundle.cpp +++ b/src/coreclr/vm/bundle.cpp @@ -30,14 +30,28 @@ const SString &BundleFileLocation::Path() const return Bundle::AppBundle->Path(); } +#if defined(TARGET_ANDROID) +const SString &BundleFileLocation::AppName() const +{ + LIMITED_METHOD_CONTRACT; + + _ASSERTE(IsValid()); + _ASSERTE(Bundle::AppBundle != nullptr); + + return Bundle::AppBundle->Path(); +} +#endif + Bundle::Bundle(LPCSTR bundlePath, BundleProbeFn *probe) { STANDARD_VM_CONTRACT; _ASSERTE(probe != nullptr); - - m_path.SetUTF8(bundlePath); m_probe = probe; +#if defined(TARGET_ANDROID) + m_appName.SetUTF8(bundlePath); +#else + m_path.SetUTF8(bundlePath); // The bundle-base path is the directory containing the single-file bundle. // When the Probe() function searches within the bundle, it masks out the basePath from the assembly-path (if found). @@ -47,6 +61,7 @@ Bundle::Bundle(LPCSTR bundlePath, BundleProbeFn *probe) size_t baseLen = pos - bundlePath + 1; // Include DIRECTORY_SEPARATOR_CHAR_A in m_basePath m_basePath.SetUTF8(bundlePath, (COUNT_T)baseLen); m_basePathLength = (COUNT_T)baseLen; +#endif // !TARGET_ANDROID } BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) const @@ -64,6 +79,13 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) pathBuffer.SetAndConvertToUTF8(path.GetUnicode()); LPCSTR utf8Path(pathBuffer.GetUTF8()); +#if defined(TARGET_ANDROID) + // On Android we always strip away the assembly path, if any + LPCSTR pos = strrchr(utf8Path, DIRECTORY_SEPARATOR_CHAR_A); + if (pos != nullptr) { + utf8Path = pos + 1; // one past the last directory separator char + } +#else // TARGET_ANDROID if (!pathIsBundleRelative) { #ifdef TARGET_UNIX @@ -80,10 +102,13 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) return loc; } } - +#endif // !TARGET_ANDROID INT64 fileSize = 0; INT64 compressedSize = 0; +#if defined(TARGET_ANDROID) + m_probe(utf8Path, &loc.DataStart, &loc.Size); +#else m_probe(utf8Path, &loc.Offset, &fileSize, &compressedSize); if (compressedSize) @@ -96,7 +121,7 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) loc.Size = fileSize; loc.UncompresedSize = 0; } - +#endif return loc; } diff --git a/src/coreclr/vm/peimage.cpp b/src/coreclr/vm/peimage.cpp index 7592ef2a3bf3b7..0b2ddbc486856c 100644 --- a/src/coreclr/vm/peimage.cpp +++ b/src/coreclr/vm/peimage.cpp @@ -850,7 +850,14 @@ HANDLE PEImage::GetFileHandle() if (m_hFile == INVALID_HANDLE_VALUE) { #if !defined(DACCESS_COMPILE) - EEFileLoadException::Throw(GetPathToLoad(), hr); + EEFileLoadException::Throw( +#if defined(TARGET_ANDROID) + AndroidGetAppName(), +#else + GetPathToLoad(), +#endif + hr + ); #else // defined(DACCESS_COMPILE) ThrowHR(hr); #endif // !defined(DACCESS_COMPILE) @@ -869,6 +876,9 @@ HRESULT PEImage::TryOpenFile(bool takeLock) return S_OK; ErrorModeHolder mode{}; +#if defined(TARGET_ANDROID) + m_hFile = AndroidGetDataStart (); +#else m_hFile=WszCreateFile((LPCWSTR)GetPathToLoad(), GENERIC_READ #if TARGET_WINDOWS @@ -881,7 +891,7 @@ HRESULT PEImage::TryOpenFile(bool takeLock) OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - +#endif if (m_hFile != INVALID_HANDLE_VALUE) return S_OK; diff --git a/src/coreclr/vm/peimage.h b/src/coreclr/vm/peimage.h index ad885ebbabc9c7..8bd0e85c6b2f2e 100644 --- a/src/coreclr/vm/peimage.h +++ b/src/coreclr/vm/peimage.h @@ -133,7 +133,12 @@ class PEImage final PTR_PEImageLayout GetFlatLayout(); const SString& GetPath(); +#if defined(TARGET_ANDROID) + const HANDLE AndroidGetDataStart(); + const SString& AndroidGetAppName(); +#else const SString& GetPathToLoad(); +#endif LPCWSTR GetPathForErrorMessages() { return GetPath(); } BOOL IsFile(); diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index c3a07d65392b64..9c759927f6f9a6 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -32,12 +32,25 @@ inline const SString &PEImage::GetPath() return m_path; } +#if defined(TARGET_ANDROID) +inline const HANDLE PEImage::AndroidGetDataStart() +{ + LIMITED_METHOD_CONTRACT; + return m_bundleFileLocation.DataStart; +} + +inline const SString& PEImage::AndroidGetAppName() +{ + return m_bundleFileLocation.AppName(); +} +#else inline const SString& PEImage::GetPathToLoad() { LIMITED_METHOD_DAC_CONTRACT; return IsInBundle() ? m_bundleFileLocation.Path() : m_path; } +#endif // !TARGET_ANDROID inline INT64 PEImage::GetOffset() const { @@ -98,8 +111,11 @@ inline const SString &PEImage::GetModuleFileNameHintForDAC() inline BOOL PEImage::IsFile() { WRAPPER_NO_CONTRACT; - +#if defined(TARGET_ANDROID) + return false; +#else return !GetPathToLoad().IsEmpty(); +#endif } // diff --git a/src/native/corehost/host_runtime_contract.h b/src/native/corehost/host_runtime_contract.h index c7be6cd94f6aec..46d8aa4e939369 100644 --- a/src/native/corehost/host_runtime_contract.h +++ b/src/native/corehost/host_runtime_contract.h @@ -38,6 +38,12 @@ struct host_runtime_contract size_t value_buffer_size, void* contract_context); +#if defined(TARGET_ANDROID) + bool(HOST_CONTRACT_CALLTYPE* android_bundle_probe)( + const char* path, + void **data_start, + int64_t* size); +#endif // Probe an app bundle for `path`. Sets its location (`offset`, `size`) in the bundle if found. // Returns true if found, false otherwise. bool(HOST_CONTRACT_CALLTYPE* bundle_probe)( From 6f32ec34840a629c9620f9dfcb26125cc8fb1eb9 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 31 Jan 2025 19:22:07 +0100 Subject: [PATCH 24/63] Tracking why System.Private.CoreLib.dll load fails --- eng/native/build-commons.sh | 25 ++++++++++++++----------- src/coreclr/dlls/mscoree/exports.cpp | 10 ++++++++++ src/coreclr/vm/appdomain.cpp | 5 +++-- src/coreclr/vm/common.h | 6 +++--- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index b27eae7765a0d3..e9d7b1ce5fd165 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -63,6 +63,20 @@ build_native() # All set to commence the build echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__TargetArch.$__BuildType in $intermediatesDir" + SAVED_CFLAGS="${CFLAGS}" + SAVED_CXXFLAGS="${CXXFLAGS}" + SAVED_LDFLAGS="${LDFLAGS}" + + # Let users provide additional compiler/linker flags via EXTRA_CFLAGS/EXTRA_CXXFLAGS/EXTRA_LDFLAGS. + # If users directly override CFLAG/CXXFLAGS/LDFLAGS, that may lead to some configure tests working incorrectly. + # See https://github.com/dotnet/runtime/issues/35727 for more information. + # + # These flags MUST be exported before gen-buildsys.sh runs or cmake will ignore them + # + export CFLAGS="${CFLAGS} ${EXTRA_CFLAGS}" + export CXXFLAGS="${CXXFLAGS} ${EXTRA_CXXFLAGS}" + export LDFLAGS="${LDFLAGS} ${EXTRA_LDFLAGS}" + if [[ "$targetOS" == osx || "$targetOS" == maccatalyst ]]; then if [[ "$hostArch" == x64 ]]; then cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $cmakeArgs" @@ -194,17 +208,6 @@ build_native() return fi - SAVED_CFLAGS="${CFLAGS}" - SAVED_CXXFLAGS="${CXXFLAGS}" - SAVED_LDFLAGS="${LDFLAGS}" - - # Let users provide additional compiler/linker flags via EXTRA_CFLAGS/EXTRA_CXXFLAGS/EXTRA_LDFLAGS. - # If users directly override CFLAG/CXXFLAGS/LDFLAGS, that may lead to some configure tests working incorrectly. - # See https://github.com/dotnet/runtime/issues/35727 for more information. - export CFLAGS="${CFLAGS} ${EXTRA_CFLAGS}" - export CXXFLAGS="${CXXFLAGS} ${EXTRA_CXXFLAGS}" - export LDFLAGS="${LDFLAGS} ${EXTRA_LDFLAGS}" - local exit_code if [[ "$__StaticAnalyzer" == 1 ]]; then pushd "$intermediatesDir" diff --git a/src/coreclr/dlls/mscoree/exports.cpp b/src/coreclr/dlls/mscoree/exports.cpp index 6031fd807862f4..15b7de3acac8e3 100644 --- a/src/coreclr/dlls/mscoree/exports.cpp +++ b/src/coreclr/dlls/mscoree/exports.cpp @@ -652,3 +652,13 @@ void LogErrorToHost(const char* format, ...) va_end(args); } } + +#if defined(TARGET_ANDROID) +void LogDebugToHost(const char* format, ...) +{ + va_list args; + va_start(args, format); + __android_log_vprint(ANDROID_LOG_DEBUG, ANDROID_LOGCAT_TAG, format, args); + va_end(args); +} +#endif diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 7762d755052033..b0f23c8a74f104 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -1017,12 +1017,13 @@ void SystemDomain::LoadBaseSystemClasses() EX_TRY { + LogDebugToHost ("Here #00.01"); m_pSystemPEAssembly = PEAssembly::OpenSystem(); - + LogDebugToHost ("Here #00.02"); // Only partially load the system assembly. Other parts of the code will want to access // the globals in this function before finishing the load. m_pSystemAssembly = DefaultDomain()->LoadAssembly(NULL, m_pSystemPEAssembly, FILE_LOAD_BEFORE_TYPE_LOAD); - + LogDebugToHost ("Here #00.03"); // Set up binder for CoreLib CoreLibBinder::AttachModule(m_pSystemAssembly->GetModule()); diff --git a/src/coreclr/vm/common.h b/src/coreclr/vm/common.h index b2e9dd295d02ee..02d0a712251aec 100644 --- a/src/coreclr/vm/common.h +++ b/src/coreclr/vm/common.h @@ -397,7 +397,7 @@ extern DummyGlobalContract ___contract; #endif void LogErrorToHost(const char* format, ...); - +#if defined(TARGET_ANDROID) +void LogDebugToHost(const char* format, ...); +#endif #endif // !_common_h_ - - From 439962d2408ae3f39a0c873eb0fdbb5b6035ae04 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Mon, 3 Feb 2025 21:11:43 +0100 Subject: [PATCH 25/63] Don't try to mmap assembly image on Android --- src/coreclr/dlls/mscordac/mscordac.cpp | 6 ++++++ src/coreclr/vm/appdomain.cpp | 5 ++--- src/coreclr/vm/peimagelayout.cpp | 17 ++++++++++++++--- .../corehost/apphost/static/CMakeLists.txt | 8 ++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/coreclr/dlls/mscordac/mscordac.cpp b/src/coreclr/dlls/mscordac/mscordac.cpp index 53616c2269615b..9456931df06dee 100644 --- a/src/coreclr/dlls/mscordac/mscordac.cpp +++ b/src/coreclr/dlls/mscordac/mscordac.cpp @@ -1,2 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if defined(TARGET_ANDROID) +void LogDebugToHost(const char* format, ...) +{ + // No-op, just to get the build working. Will be removed later. +} +#endif diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index b0f23c8a74f104..7762d755052033 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -1017,13 +1017,12 @@ void SystemDomain::LoadBaseSystemClasses() EX_TRY { - LogDebugToHost ("Here #00.01"); m_pSystemPEAssembly = PEAssembly::OpenSystem(); - LogDebugToHost ("Here #00.02"); + // Only partially load the system assembly. Other parts of the code will want to access // the globals in this function before finishing the load. m_pSystemAssembly = DefaultDomain()->LoadAssembly(NULL, m_pSystemPEAssembly, FILE_LOAD_BEFORE_TYPE_LOAD); - LogDebugToHost ("Here #00.03"); + // Set up binder for CoreLib CoreLibBinder::AttachModule(m_pSystemAssembly->GetModule()); diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index a3188e13e87a9a..3f363bda309a63 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -617,11 +617,10 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) } CONTRACTL_END; m_pOwner=pOwner; - +#if !defined(TARGET_ANDROID) HANDLE hFile = pOwner->GetFileHandle(); INT64 offset = pOwner->GetOffset(); INT64 size = pOwner->GetSize(); - #ifdef LOGGING SString ownerPath{ pOwner->GetPath() }; LOG((LF_LOADER, LL_INFO100, "PEImage: Opening flat %s\n", ownerPath.GetUTF8())); @@ -636,12 +635,19 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) ThrowLastError(); } } - +#else // !TARGET_ANDROID + INT64 size = pOwner->GetSize(); + HANDLE mapBegin = pOwner->AndroidGetDataStart(); + if (size == 0) { + // TODO: throw something + } +#endif // TARGET_ANDROID LPVOID addr = 0; // It's okay if resource files are length zero if (size > 0) { +#if !defined(TARGET_ANDROID) INT64 uncompressedSize = pOwner->GetUncompressedSize(); DWORD mapAccess = PAGE_READONLY; @@ -725,6 +731,11 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) ThrowHR(E_FAIL); // we don't have any indication of what kind of failure. Possibly a corrupt image. #endif } +#else // !TARGET_ANDROID + m_FileMap.Assign(mapBegin); + m_FileView.Assign(mapBegin); + addr = (LPVOID)mapBegin; +#endif // TARGET_ANDROID } Init(addr, (COUNT_T)size); diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 0ceebea335bc42..7c3121fc45027f 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -306,6 +306,14 @@ target_link_libraries( ${END_WHOLE_ARCHIVE} ) +if(CLR_CMAKE_TARGET_ANDROID) + target_link_libraries( + singlefilehost + PRIVATE + log + ) +endif() + target_link_libraries(singlefilehost PRIVATE hostmisc) add_sanitizer_runtime_support(singlefilehost) From 0e6fe94d4cbdc3bf010483294ee64795026edb91 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 4 Feb 2025 22:15:03 +0100 Subject: [PATCH 26/63] Tracking abort() calls --- src/coreclr/dlls/mscordac/CMakeLists.txt | 4 ++++ src/coreclr/jit/CMakeLists.txt | 7 +++++++ src/coreclr/pal/src/thread/process.cpp | 9 ++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/coreclr/dlls/mscordac/CMakeLists.txt b/src/coreclr/dlls/mscordac/CMakeLists.txt index 0b580604c54bc2..69ca7baabaf5ee 100644 --- a/src/coreclr/dlls/mscordac/CMakeLists.txt +++ b/src/coreclr/dlls/mscordac/CMakeLists.txt @@ -163,6 +163,10 @@ set(COREDAC_LIBRARIES ${END_LIBRARY_GROUP} # End group of libraries that have circular references ) +if(CLR_CMAKE_TARGET_ANDROID) + list(APPEND COREDAC_LIBRARIES log) +endif() + if(CLR_CMAKE_HOST_WIN32) # mscordac.def should be generated before mscordaccore.dll is built add_dependencies(mscordaccore mscordaccore_def) diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index 6f9a360ec2daa8..150ccfcbccf425 100644 --- a/src/coreclr/jit/CMakeLists.txt +++ b/src/coreclr/jit/CMakeLists.txt @@ -607,6 +607,13 @@ function(add_jit jitName) ${JIT_ARCH_LINK_LIBRARIES} ) + if(CLR_CMAKE_TARGET_ANDROID) + target_link_libraries(${jitName} + PRIVATE + log + ) + endif() + if (CLR_CMAKE_HOST_WIN32) link_natvis_sources_for_target(${jitName} PRIVATE clrjit.natvis) endif() diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 20c09eb357dd2e..10431818c00045 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -71,6 +71,10 @@ SET_DEFAULT_DEBUG_CHANNEL(PROCESS); // some headers have code with asserts, so d #include #endif +#if defined(TARGET_ANDROID) +#include +#endif + #ifdef __APPLE__ #include #include @@ -2546,6 +2550,9 @@ PROCAbort(int signal, siginfo_t* siginfo) SEHCleanupSignals(false /* isChildProcess */); // Abort the process after waiting for the core dump to complete +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "Aborting in %s:%u", __FILE_NAME__, __LINE__); +#endif abort(); } @@ -2822,7 +2829,7 @@ CorUnix::InitializeProcessCommandLine( ERROR("Invalid full path\n"); palError = ERROR_INTERNAL_ERROR; goto exit; - } + } lpwstr[0] = '\0'; size_t n = PAL_wcslen(lpwstrFullPath) + 1; From d69a55016c9a4af41bb5a45d590f2df4d4c649bf Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 5 Feb 2025 20:26:31 +0100 Subject: [PATCH 27/63] For now --- src/coreclr/pal/src/thread/process.cpp | 24 +++++++++++++++++-- src/coreclr/vm/eepolicy.cpp | 12 ++++++++-- src/coreclr/vm/excep.cpp | 10 ++++++++ src/coreclr/vm/exceptionhandling.cpp | 21 +++++++++++++++- src/coreclr/vm/jithelpers.cpp | 8 ++++++- .../Unix/System.Native/Interop.Stat.cs | 11 +++++++++ .../System.Diagnostics.FileVersionInfo.csproj | 1 + .../src/System.Diagnostics.Process.csproj | 1 + .../src/System.Formats.Tar.csproj | 1 + .../src/System.IO.Compression.ZipFile.csproj | 1 + .../src/System.IO.Compression.csproj | 1 + .../src/System.IO.FileSystem.Watcher.csproj | 1 + .../src/System.IO.MemoryMappedFiles.csproj | 1 + .../src/System.IO.Pipes.csproj | 1 + .../src/System.Net.Sockets.csproj | 1 + .../src/System/IO/FileSystem.Exists.Unix.cs | 2 +- .../src/System/IO/FileSystem.Unix.cs | 12 +++++----- .../src/System/IO/Path.Unix.cs | 2 +- src/native/libs/Common/pal_error_common.h | 3 +++ .../System.IO.Ports.Native/CMakeLists.txt | 7 ++++++ src/native/libs/System.Native/pal_io.c | 7 ++++-- 21 files changed, 112 insertions(+), 16 deletions(-) diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 10431818c00045..feba564495ea22 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -1153,6 +1153,9 @@ ExitProcess( else { WARN("thread re-called ExitProcess\n"); +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif PROCEndProcess(GetCurrentProcess(), uExitCode, FALSE); } } @@ -1177,6 +1180,9 @@ ExitProcess( */ if (PALInitLock() && PALIsInitialized()) { +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif PROCEndProcess(GetCurrentProcess(), uExitCode, FALSE); /* Should not get here, because we terminate the current process */ @@ -1214,7 +1220,9 @@ TerminateProcess( PERF_ENTRY(TerminateProcess); ENTRY("TerminateProcess(hProcess=%p, uExitCode=%u)\n",hProcess, uExitCode ); - +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif ret = PROCEndProcess(hProcess, uExitCode, TRUE); LOGEXIT("TerminateProcess returns BOOL %d\n", ret); @@ -1239,6 +1247,9 @@ RaiseFailFastException( PERF_ENTRY(RaiseFailFastException); ENTRY("RaiseFailFastException"); +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "About to abort at %s:%u", __FILE_NAME__, __LINE__); +#endif TerminateCurrentProcessNoExit(TRUE); for (;;) PROCAbort(); @@ -1318,6 +1329,9 @@ static BOOL PROCEndProcess(HANDLE hProcess, UINT uExitCode, BOOL bTerminateUncon // (2) can invoke CrashReporter or produce a coredump, which is appropriate for TerminateProcess calls // TerminationRequestHandlingRoutine in synchmanager.cpp sets the exit code to this special value. The // Watson analyzer needs to know that the process was terminated with a SIGTERM. +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "About to abort in %s:%u", __FILE_NAME__, __LINE__); +#endif PROCAbort(uExitCode == (128 + SIGTERM) ? SIGTERM : SIGABRT); } else @@ -2620,12 +2634,18 @@ InitializeFlushProcessWriteBuffers() #endif // TARGET_APPLE } +#if defined(TARGET_ANDROID) +#define FATAL_ASSERT_PRINT(msg) __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "About to abort in %s:%u. %s", __FILE_NAME__, __LINE__, (msg)) +#else +#define FATAL_ASSERT_PRINT(msg) fprintf(stderr, "FATAL ERROR: " msg) +#endif + #define FATAL_ASSERT(e, msg) \ do \ { \ if (!(e)) \ { \ - fprintf(stderr, "FATAL ERROR: " msg); \ + FATAL_ASSERT_PRINT(msg); \ PROCAbort(); \ } \ } \ diff --git a/src/coreclr/vm/eepolicy.cpp b/src/coreclr/vm/eepolicy.cpp index 62909498efe387..e2c65163693e55 100644 --- a/src/coreclr/vm/eepolicy.cpp +++ b/src/coreclr/vm/eepolicy.cpp @@ -20,6 +20,10 @@ #include "dwreport.h" #endif // !TARGET_UNIX +#if defined(TARGET_ANDROID) +#include +#endif + #include "eventtrace.h" #undef ExitProcess @@ -58,7 +62,9 @@ void SafeExitProcess(UINT exitCode, ShutdownCompleteAction sca = SCA_ExitProcess { // disabled because if we fault in this code path we will trigger our Watson code CONTRACT_VIOLATION(ThrowsViolation); - +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif CrashDumpAndTerminateProcess(exitCode); } else if (sca == SCA_ExitProcessWhenShutdownComplete) @@ -734,7 +740,9 @@ void DECLSPEC_NORETURN EEPolicy::HandleFatalStackOverflow(EXCEPTION_POINTERS *pE WatsonLastChance(pThread, pExceptionInfo, (fTreatAsNativeUnhandledException == FALSE)? TypeOfReportedError::UnhandledException: TypeOfReportedError::NativeThreadUnhandledException); } - +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif CrashDumpAndTerminateProcess(COR_E_STACKOVERFLOW); UNREACHABLE(); } diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index 985310c640a942..0299066f40b1e0 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -25,6 +25,10 @@ #include "virtualcallstub.h" #include "typestring.h" +#if defined(TARGET_ANDROID) +#include +#endif + #ifndef TARGET_UNIX #include "dwreport.h" #endif // !TARGET_UNIX @@ -3944,6 +3948,9 @@ void CrashDumpAndTerminateProcess(UINT exitCode) { #ifdef HOST_WINDOWS CreateCrashDumpIfEnabled(exitCode == COR_E_STACKOVERFLOW); +#endif +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); #endif TerminateProcess(GetCurrentProcess(), exitCode); } @@ -4074,6 +4081,9 @@ LONG UserBreakpointFilter(EXCEPTION_POINTERS* pEP) } // Otherwise, we terminate the process. +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif CrashDumpAndTerminateProcess(STATUS_BREAKPOINT); // Shouldn't get here ... diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index 271f12d4cf51b7..ac183acc6d391c 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -21,6 +21,10 @@ #include "exinfo.h" #include "configuration.h" +#if defined(TARGET_ANDROID) +#include +#endif + #if defined(TARGET_X86) #define USE_CURRENT_CONTEXT_IN_FILTER #endif // TARGET_X86 @@ -4905,6 +4909,9 @@ VOID DECLSPEC_NORETURN UnwindManagedExceptionPass1(PAL_SEHException& ex, CONTEXT LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers); _ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH); } +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif CrashDumpAndTerminateProcess(1); } else @@ -4964,6 +4971,9 @@ VOID DECLSPEC_NORETURN UnwindManagedExceptionPass1(PAL_SEHException& ex, CONTEXT LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers); _ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH); } +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif CrashDumpAndTerminateProcess(1); UNREACHABLE(); } @@ -5032,6 +5042,9 @@ VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHar // There are no managed frames on the stack, so the exception was not handled LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers); _ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH); +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif CrashDumpAndTerminateProcess(1); UNREACHABLE(); } @@ -5910,7 +5923,7 @@ void FixupDispatcherContext(DISPATCHER_CONTEXT* pDispatcherContext, CONTEXT* pCo } pDispatcherContext->ControlPc = (UINT_PTR) GetIP(pDispatcherContext->ContextRecord); - + #if defined(TARGET_ARM64) // Since this routine is used to fixup contexts for async exceptions, // clear the CONTEXT_UNWOUND_TO_CALL flag since, semantically, frames @@ -8498,6 +8511,9 @@ extern "C" bool QCALLTYPE SfiInit(StackFrameIterator* pThis, CONTEXT* pStackwalk GetThread()->SetThreadStateNC(Thread::TSNC_ProcessedUnhandledException); RaiseException(pExInfo->m_ExceptionCode, EXCEPTION_NONCONTINUABLE_EXCEPTION, pExInfo->m_ptrs.ExceptionRecord->NumberParameters, pExInfo->m_ptrs.ExceptionRecord->ExceptionInformation); #else +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif CrashDumpAndTerminateProcess(pExInfo->m_ExceptionCode); #endif } @@ -8617,6 +8633,9 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla GetThread()->SetThreadStateNC(Thread::TSNC_ProcessedUnhandledException); RaiseException(pTopExInfo->m_ExceptionCode, EXCEPTION_NONCONTINUABLE_EXCEPTION, pTopExInfo->m_ptrs.ExceptionRecord->NumberParameters, pTopExInfo->m_ptrs.ExceptionRecord->ExceptionInformation); #else +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif CrashDumpAndTerminateProcess(pTopExInfo->m_ExceptionCode); #endif } diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index fe5564e299060d..39a70d6b74e275 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -25,6 +25,10 @@ #include "dynamicinterfacecastable.h" #include "comsynchronizable.h" +#if defined(TARGET_ANDROID) +#include +#endif + #ifndef TARGET_UNIX // Included for referencing __report_gsfailure #include "process.h" @@ -2014,7 +2018,9 @@ void DoJITFailFast () COR_E_EXECUTIONENGINE, GetClrInstanceId()); } - +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); +#endif CrashDumpAndTerminateProcess(STATUS_STACK_BUFFER_OVERRUN); #endif // !TARGET_UNIX } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.cs index 0796599a096497..d71009860ed4fd 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Diagnostics; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; @@ -63,5 +64,15 @@ internal enum FileStatusFlags [LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat", StringMarshalling = StringMarshalling.Utf8, SetLastError = true)] internal static partial int LStat(string path, out FileStatus output); + + [LibraryImport("log", EntryPoint="__android_log_write", StringMarshalling = StringMarshalling.Utf8, SetLastError = false)] + static partial void AndroidLog (int prio, string tag, string message); + + internal static int LStatWrap(string path, out FileStatus output) + { + AndroidLog (4, "CoreCLR", $"LStat (\"{path}\""); + AndroidLog (4, "CoreCLR", new StackTrace (false).ToString ()); + return LStat (path, out output); + } } } diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj b/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj index 230451074f3e08..9a726c5c8a68cb 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj +++ b/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj @@ -57,6 +57,7 @@ + diff --git a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj index 97e289045e324a..495e542701e4fd 100644 --- a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj +++ b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj @@ -387,6 +387,7 @@ + diff --git a/src/libraries/System.Formats.Tar/src/System.Formats.Tar.csproj b/src/libraries/System.Formats.Tar/src/System.Formats.Tar.csproj index 6f34a34cc6e7de..1f75915a9e59ff 100644 --- a/src/libraries/System.Formats.Tar/src/System.Formats.Tar.csproj +++ b/src/libraries/System.Formats.Tar/src/System.Formats.Tar.csproj @@ -79,6 +79,7 @@ + diff --git a/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj b/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj index 0613ab5e4848a0..d8ee616c411311 100644 --- a/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj +++ b/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj @@ -49,6 +49,7 @@ + diff --git a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj index 1ad16f09e8af6e..96fc8e4f92154d 100644 --- a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj +++ b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj @@ -79,6 +79,7 @@ + diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj index 8544de48d095d5..ff372a63c7095a 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj @@ -128,6 +128,7 @@ + diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj b/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj index 1710a652f6d6e3..79b69e9b3fdab3 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj +++ b/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj @@ -133,6 +133,7 @@ + diff --git a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj index b36765a036839e..853f740f774499 100644 --- a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj +++ b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj @@ -194,6 +194,7 @@ + diff --git a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj index a7776ec2dec283..215eafae8d6c3d 100644 --- a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj +++ b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj @@ -317,6 +317,7 @@ + diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Exists.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Exists.Unix.cs index 172a956201dd86..8a96321d6b601c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Exists.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Exists.Unix.cs @@ -46,7 +46,7 @@ private static bool FileExists(ReadOnlySpan fullPath, out Interop.ErrorInf // See http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 for details. fullPath = Path.TrimEndingDirectorySeparator(fullPath); - if (Interop.Sys.LStat(fullPath, out fileinfo) < 0) + if (Interop.Sys.LStatWrap(fullPath.ToString (), out fileinfo) < 0) { errorInfo = Interop.Sys.GetLastErrorInfo(); return false; diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs index 69ed0a6016adcf..9b7e2afc516bcd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs @@ -123,7 +123,7 @@ public static void ReplaceFile(string sourceFullPath, string destFullPath, strin { // Unix rename works in more cases, we limit to what is allowed by Windows File.Replace. // These checks are not atomic, the file could change after a check was performed and before it is renamed. - Interop.CheckIo(Interop.Sys.LStat(sourceFullPath, out Interop.Sys.FileStatus sourceStat), sourceFullPath); + Interop.CheckIo(Interop.Sys.LStatWrap(sourceFullPath, out Interop.Sys.FileStatus sourceStat), sourceFullPath); // Check source is not a directory. if ((sourceStat.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR) @@ -132,7 +132,7 @@ public static void ReplaceFile(string sourceFullPath, string destFullPath, strin } Interop.Sys.FileStatus destStat; - if (Interop.Sys.LStat(destFullPath, out destStat) == 0) + if (Interop.Sys.LStatWrap(destFullPath, out destStat) == 0) { // Check destination is not a directory. if ((destStat.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR) @@ -222,8 +222,8 @@ public static void MoveFile(string sourceFullPath, string destFullPath, bool ove // link/unlink approach and generating any exceptional messages from there as necessary. Interop.Sys.FileStatus sourceStat, destStat; - if (Interop.Sys.LStat(sourceFullPath, out sourceStat) == 0 && // source file exists - (Interop.Sys.LStat(destFullPath, out destStat) != 0 || // dest file does not exist + if (Interop.Sys.LStatWrap(sourceFullPath, out sourceStat) == 0 && // source file exists + (Interop.Sys.LStatWrap(destFullPath, out destStat) != 0 || // dest file does not exist (sourceStat.Dev == destStat.Dev && // source and dest are on the same device sourceStat.Ino == destStat.Ino)) && // source and dest are the same file on that device Interop.Sys.Rename(sourceFullPath, destFullPath) == 0) // try the rename @@ -411,12 +411,12 @@ private static void MoveDirectory(string sourceFullPath, string destFullPath, bo // The destination must not exist (unless it is a case-sensitive rename). // On Unix 'rename' will overwrite the destination file if it already exists, we need to manually check. - if (!isCaseSensitiveRename && Interop.Sys.LStat(destNoDirectorySeparator, out Interop.Sys.FileStatus destFileStatus) >= 0) + if (!isCaseSensitiveRename && Interop.Sys.LStatWrap(destNoDirectorySeparator.ToString (), out Interop.Sys.FileStatus destFileStatus) >= 0) { // Maintain order of exceptions as on Windows. // Throw if the source doesn't exist. - if (Interop.Sys.LStat(srcNoDirectorySeparator, out Interop.Sys.FileStatus sourceFileStatus) < 0) + if (Interop.Sys.LStatWrap(srcNoDirectorySeparator.ToString (), out Interop.Sys.FileStatus sourceFileStatus) < 0) { throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, sourceFullPath)); } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs index 075a14d936c943..69c98d1713ca05 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs @@ -16,7 +16,7 @@ public static partial class Path // Checks if the given path is available for use. private static bool ExistsCore(string fullPath, out bool isDirectory) { - bool result = Interop.Sys.LStat(fullPath, out Interop.Sys.FileStatus fileInfo) == Interop.Errors.ERROR_SUCCESS; + bool result = Interop.Sys.LStatWrap(fullPath, out Interop.Sys.FileStatus fileInfo) == Interop.Errors.ERROR_SUCCESS; isDirectory = result && (fileInfo.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR; return result; diff --git a/src/native/libs/Common/pal_error_common.h b/src/native/libs/Common/pal_error_common.h index 7541132da7b188..103e81c6e3efc1 100644 --- a/src/native/libs/Common/pal_error_common.h +++ b/src/native/libs/Common/pal_error_common.h @@ -145,6 +145,9 @@ typedef enum inline static int32_t ConvertErrorPlatformToPal(int32_t platformErrno) { +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "%s at %s:%d. platformErrno == %d", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__, platformErrno); +#endif switch (platformErrno) { case 0: diff --git a/src/native/libs/System.IO.Ports.Native/CMakeLists.txt b/src/native/libs/System.IO.Ports.Native/CMakeLists.txt index a53be1dd8c9b7d..5a01ada023d589 100644 --- a/src/native/libs/System.IO.Ports.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Ports.Native/CMakeLists.txt @@ -22,6 +22,13 @@ if (GEN_SHARED_LIB) -lnetwork ) endif() + + if (CLR_CMAKE_TARGET_ANDROID) + target_link_libraries(System.IO.Ports.Native + PRIVATE + log + ) + endif() endif() add_library(System.IO.Ports.Native-Static diff --git a/src/native/libs/System.Native/pal_io.c b/src/native/libs/System.Native/pal_io.c index 3777ad55151f9d..b6f6198bf2b6ca 100644 --- a/src/native/libs/System.Native/pal_io.c +++ b/src/native/libs/System.Native/pal_io.c @@ -260,6 +260,9 @@ int32_t SystemNative_FStat(intptr_t fd, FileStatus* output) int32_t SystemNative_LStat(const char* path, FileStatus* output) { +#if defined(TARGET_ANDROID) + __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "%s at %s:%d. path == '%s'", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__, path); +#endif struct stat_ result; int ret = lstat_(path, &result); @@ -399,7 +402,7 @@ int32_t SystemNative_IsMemfdSupported(void) } #endif - // Note that the name has no affect on file descriptor behavior. From linux manpage: + // Note that the name has no affect on file descriptor behavior. From linux manpage: // Names do not affect the behavior of the file descriptor, and as such multiple files can have the same name without any side effects. int32_t fd = (int32_t)syscall(__NR_memfd_create, "test", MFD_CLOEXEC | MFD_ALLOW_SEALING); if (fd < 0) return 0; @@ -1976,7 +1979,7 @@ static int GetAllowedVectorCount(IOVector* vectors, int32_t vectorCount) // For macOS preadv and pwritev can fail with EINVAL when the total length // of all vectors overflows a 32-bit integer. size_t totalLength = 0; - for (int i = 0; i < allowedCount; i++) + for (int i = 0; i < allowedCount; i++) { assert(INT_MAX >= vectors[i].Count); From 5895ad838ecfd9349ecd89fe8d8b067a896ffbac Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 6 Feb 2025 11:31:50 +0100 Subject: [PATCH 28/63] Revert "For now" This reverts commit 1f6ddc2714f71d0bed6300158ad121cfcb82cb8b. --- src/coreclr/pal/src/thread/process.cpp | 24 ++----------------- src/coreclr/vm/eepolicy.cpp | 12 ++-------- src/coreclr/vm/excep.cpp | 10 -------- src/coreclr/vm/exceptionhandling.cpp | 21 +--------------- src/coreclr/vm/jithelpers.cpp | 8 +------ .../Unix/System.Native/Interop.Stat.cs | 11 --------- .../System.Diagnostics.FileVersionInfo.csproj | 1 - .../src/System.Diagnostics.Process.csproj | 1 - .../src/System.Formats.Tar.csproj | 1 - .../src/System.IO.Compression.ZipFile.csproj | 1 - .../src/System.IO.Compression.csproj | 1 - .../src/System.IO.FileSystem.Watcher.csproj | 1 - .../src/System.IO.MemoryMappedFiles.csproj | 1 - .../src/System.IO.Pipes.csproj | 1 - .../src/System.Net.Sockets.csproj | 1 - .../src/System/IO/FileSystem.Exists.Unix.cs | 2 +- .../src/System/IO/FileSystem.Unix.cs | 12 +++++----- .../src/System/IO/Path.Unix.cs | 2 +- src/native/libs/Common/pal_error_common.h | 3 --- .../System.IO.Ports.Native/CMakeLists.txt | 7 ------ src/native/libs/System.Native/pal_io.c | 7 ++---- 21 files changed, 16 insertions(+), 112 deletions(-) diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index feba564495ea22..10431818c00045 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -1153,9 +1153,6 @@ ExitProcess( else { WARN("thread re-called ExitProcess\n"); -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif PROCEndProcess(GetCurrentProcess(), uExitCode, FALSE); } } @@ -1180,9 +1177,6 @@ ExitProcess( */ if (PALInitLock() && PALIsInitialized()) { -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif PROCEndProcess(GetCurrentProcess(), uExitCode, FALSE); /* Should not get here, because we terminate the current process */ @@ -1220,9 +1214,7 @@ TerminateProcess( PERF_ENTRY(TerminateProcess); ENTRY("TerminateProcess(hProcess=%p, uExitCode=%u)\n",hProcess, uExitCode ); -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif + ret = PROCEndProcess(hProcess, uExitCode, TRUE); LOGEXIT("TerminateProcess returns BOOL %d\n", ret); @@ -1247,9 +1239,6 @@ RaiseFailFastException( PERF_ENTRY(RaiseFailFastException); ENTRY("RaiseFailFastException"); -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "About to abort at %s:%u", __FILE_NAME__, __LINE__); -#endif TerminateCurrentProcessNoExit(TRUE); for (;;) PROCAbort(); @@ -1329,9 +1318,6 @@ static BOOL PROCEndProcess(HANDLE hProcess, UINT uExitCode, BOOL bTerminateUncon // (2) can invoke CrashReporter or produce a coredump, which is appropriate for TerminateProcess calls // TerminationRequestHandlingRoutine in synchmanager.cpp sets the exit code to this special value. The // Watson analyzer needs to know that the process was terminated with a SIGTERM. -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "About to abort in %s:%u", __FILE_NAME__, __LINE__); -#endif PROCAbort(uExitCode == (128 + SIGTERM) ? SIGTERM : SIGABRT); } else @@ -2634,18 +2620,12 @@ InitializeFlushProcessWriteBuffers() #endif // TARGET_APPLE } -#if defined(TARGET_ANDROID) -#define FATAL_ASSERT_PRINT(msg) __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "About to abort in %s:%u. %s", __FILE_NAME__, __LINE__, (msg)) -#else -#define FATAL_ASSERT_PRINT(msg) fprintf(stderr, "FATAL ERROR: " msg) -#endif - #define FATAL_ASSERT(e, msg) \ do \ { \ if (!(e)) \ { \ - FATAL_ASSERT_PRINT(msg); \ + fprintf(stderr, "FATAL ERROR: " msg); \ PROCAbort(); \ } \ } \ diff --git a/src/coreclr/vm/eepolicy.cpp b/src/coreclr/vm/eepolicy.cpp index e2c65163693e55..62909498efe387 100644 --- a/src/coreclr/vm/eepolicy.cpp +++ b/src/coreclr/vm/eepolicy.cpp @@ -20,10 +20,6 @@ #include "dwreport.h" #endif // !TARGET_UNIX -#if defined(TARGET_ANDROID) -#include -#endif - #include "eventtrace.h" #undef ExitProcess @@ -62,9 +58,7 @@ void SafeExitProcess(UINT exitCode, ShutdownCompleteAction sca = SCA_ExitProcess { // disabled because if we fault in this code path we will trigger our Watson code CONTRACT_VIOLATION(ThrowsViolation); -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif + CrashDumpAndTerminateProcess(exitCode); } else if (sca == SCA_ExitProcessWhenShutdownComplete) @@ -740,9 +734,7 @@ void DECLSPEC_NORETURN EEPolicy::HandleFatalStackOverflow(EXCEPTION_POINTERS *pE WatsonLastChance(pThread, pExceptionInfo, (fTreatAsNativeUnhandledException == FALSE)? TypeOfReportedError::UnhandledException: TypeOfReportedError::NativeThreadUnhandledException); } -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif + CrashDumpAndTerminateProcess(COR_E_STACKOVERFLOW); UNREACHABLE(); } diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index 0299066f40b1e0..985310c640a942 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -25,10 +25,6 @@ #include "virtualcallstub.h" #include "typestring.h" -#if defined(TARGET_ANDROID) -#include -#endif - #ifndef TARGET_UNIX #include "dwreport.h" #endif // !TARGET_UNIX @@ -3948,9 +3944,6 @@ void CrashDumpAndTerminateProcess(UINT exitCode) { #ifdef HOST_WINDOWS CreateCrashDumpIfEnabled(exitCode == COR_E_STACKOVERFLOW); -#endif -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); #endif TerminateProcess(GetCurrentProcess(), exitCode); } @@ -4081,9 +4074,6 @@ LONG UserBreakpointFilter(EXCEPTION_POINTERS* pEP) } // Otherwise, we terminate the process. -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif CrashDumpAndTerminateProcess(STATUS_BREAKPOINT); // Shouldn't get here ... diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index ac183acc6d391c..271f12d4cf51b7 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -21,10 +21,6 @@ #include "exinfo.h" #include "configuration.h" -#if defined(TARGET_ANDROID) -#include -#endif - #if defined(TARGET_X86) #define USE_CURRENT_CONTEXT_IN_FILTER #endif // TARGET_X86 @@ -4909,9 +4905,6 @@ VOID DECLSPEC_NORETURN UnwindManagedExceptionPass1(PAL_SEHException& ex, CONTEXT LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers); _ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH); } -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif CrashDumpAndTerminateProcess(1); } else @@ -4971,9 +4964,6 @@ VOID DECLSPEC_NORETURN UnwindManagedExceptionPass1(PAL_SEHException& ex, CONTEXT LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers); _ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH); } -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif CrashDumpAndTerminateProcess(1); UNREACHABLE(); } @@ -5042,9 +5032,6 @@ VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHar // There are no managed frames on the stack, so the exception was not handled LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers); _ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH); -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif CrashDumpAndTerminateProcess(1); UNREACHABLE(); } @@ -5923,7 +5910,7 @@ void FixupDispatcherContext(DISPATCHER_CONTEXT* pDispatcherContext, CONTEXT* pCo } pDispatcherContext->ControlPc = (UINT_PTR) GetIP(pDispatcherContext->ContextRecord); - + #if defined(TARGET_ARM64) // Since this routine is used to fixup contexts for async exceptions, // clear the CONTEXT_UNWOUND_TO_CALL flag since, semantically, frames @@ -8511,9 +8498,6 @@ extern "C" bool QCALLTYPE SfiInit(StackFrameIterator* pThis, CONTEXT* pStackwalk GetThread()->SetThreadStateNC(Thread::TSNC_ProcessedUnhandledException); RaiseException(pExInfo->m_ExceptionCode, EXCEPTION_NONCONTINUABLE_EXCEPTION, pExInfo->m_ptrs.ExceptionRecord->NumberParameters, pExInfo->m_ptrs.ExceptionRecord->ExceptionInformation); #else -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif CrashDumpAndTerminateProcess(pExInfo->m_ExceptionCode); #endif } @@ -8633,9 +8617,6 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla GetThread()->SetThreadStateNC(Thread::TSNC_ProcessedUnhandledException); RaiseException(pTopExInfo->m_ExceptionCode, EXCEPTION_NONCONTINUABLE_EXCEPTION, pTopExInfo->m_ptrs.ExceptionRecord->NumberParameters, pTopExInfo->m_ptrs.ExceptionRecord->ExceptionInformation); #else -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif CrashDumpAndTerminateProcess(pTopExInfo->m_ExceptionCode); #endif } diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 39a70d6b74e275..fe5564e299060d 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -25,10 +25,6 @@ #include "dynamicinterfacecastable.h" #include "comsynchronizable.h" -#if defined(TARGET_ANDROID) -#include -#endif - #ifndef TARGET_UNIX // Included for referencing __report_gsfailure #include "process.h" @@ -2018,9 +2014,7 @@ void DoJITFailFast () COR_E_EXECUTIONENGINE, GetClrInstanceId()); } -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "End process at %s:%u", __FILE_NAME__, __LINE__); -#endif + CrashDumpAndTerminateProcess(STATUS_STACK_BUFFER_OVERRUN); #endif // !TARGET_UNIX } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.cs index d71009860ed4fd..0796599a096497 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Diagnostics; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; @@ -64,15 +63,5 @@ internal enum FileStatusFlags [LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat", StringMarshalling = StringMarshalling.Utf8, SetLastError = true)] internal static partial int LStat(string path, out FileStatus output); - - [LibraryImport("log", EntryPoint="__android_log_write", StringMarshalling = StringMarshalling.Utf8, SetLastError = false)] - static partial void AndroidLog (int prio, string tag, string message); - - internal static int LStatWrap(string path, out FileStatus output) - { - AndroidLog (4, "CoreCLR", $"LStat (\"{path}\""); - AndroidLog (4, "CoreCLR", new StackTrace (false).ToString ()); - return LStat (path, out output); - } } } diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj b/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj index 9a726c5c8a68cb..230451074f3e08 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj +++ b/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj @@ -57,7 +57,6 @@ - diff --git a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj index 495e542701e4fd..97e289045e324a 100644 --- a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj +++ b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj @@ -387,7 +387,6 @@ - diff --git a/src/libraries/System.Formats.Tar/src/System.Formats.Tar.csproj b/src/libraries/System.Formats.Tar/src/System.Formats.Tar.csproj index 1f75915a9e59ff..6f34a34cc6e7de 100644 --- a/src/libraries/System.Formats.Tar/src/System.Formats.Tar.csproj +++ b/src/libraries/System.Formats.Tar/src/System.Formats.Tar.csproj @@ -79,7 +79,6 @@ - diff --git a/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj b/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj index d8ee616c411311..0613ab5e4848a0 100644 --- a/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj +++ b/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj @@ -49,7 +49,6 @@ - diff --git a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj index 96fc8e4f92154d..1ad16f09e8af6e 100644 --- a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj +++ b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj @@ -79,7 +79,6 @@ - diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj index ff372a63c7095a..8544de48d095d5 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj @@ -128,7 +128,6 @@ - diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj b/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj index 79b69e9b3fdab3..1710a652f6d6e3 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj +++ b/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj @@ -133,7 +133,6 @@ - diff --git a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj index 853f740f774499..b36765a036839e 100644 --- a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj +++ b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj @@ -194,7 +194,6 @@ - diff --git a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj index 215eafae8d6c3d..a7776ec2dec283 100644 --- a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj +++ b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj @@ -317,7 +317,6 @@ - diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Exists.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Exists.Unix.cs index 8a96321d6b601c..172a956201dd86 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Exists.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Exists.Unix.cs @@ -46,7 +46,7 @@ private static bool FileExists(ReadOnlySpan fullPath, out Interop.ErrorInf // See http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 for details. fullPath = Path.TrimEndingDirectorySeparator(fullPath); - if (Interop.Sys.LStatWrap(fullPath.ToString (), out fileinfo) < 0) + if (Interop.Sys.LStat(fullPath, out fileinfo) < 0) { errorInfo = Interop.Sys.GetLastErrorInfo(); return false; diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs index 9b7e2afc516bcd..69ed0a6016adcf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs @@ -123,7 +123,7 @@ public static void ReplaceFile(string sourceFullPath, string destFullPath, strin { // Unix rename works in more cases, we limit to what is allowed by Windows File.Replace. // These checks are not atomic, the file could change after a check was performed and before it is renamed. - Interop.CheckIo(Interop.Sys.LStatWrap(sourceFullPath, out Interop.Sys.FileStatus sourceStat), sourceFullPath); + Interop.CheckIo(Interop.Sys.LStat(sourceFullPath, out Interop.Sys.FileStatus sourceStat), sourceFullPath); // Check source is not a directory. if ((sourceStat.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR) @@ -132,7 +132,7 @@ public static void ReplaceFile(string sourceFullPath, string destFullPath, strin } Interop.Sys.FileStatus destStat; - if (Interop.Sys.LStatWrap(destFullPath, out destStat) == 0) + if (Interop.Sys.LStat(destFullPath, out destStat) == 0) { // Check destination is not a directory. if ((destStat.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR) @@ -222,8 +222,8 @@ public static void MoveFile(string sourceFullPath, string destFullPath, bool ove // link/unlink approach and generating any exceptional messages from there as necessary. Interop.Sys.FileStatus sourceStat, destStat; - if (Interop.Sys.LStatWrap(sourceFullPath, out sourceStat) == 0 && // source file exists - (Interop.Sys.LStatWrap(destFullPath, out destStat) != 0 || // dest file does not exist + if (Interop.Sys.LStat(sourceFullPath, out sourceStat) == 0 && // source file exists + (Interop.Sys.LStat(destFullPath, out destStat) != 0 || // dest file does not exist (sourceStat.Dev == destStat.Dev && // source and dest are on the same device sourceStat.Ino == destStat.Ino)) && // source and dest are the same file on that device Interop.Sys.Rename(sourceFullPath, destFullPath) == 0) // try the rename @@ -411,12 +411,12 @@ private static void MoveDirectory(string sourceFullPath, string destFullPath, bo // The destination must not exist (unless it is a case-sensitive rename). // On Unix 'rename' will overwrite the destination file if it already exists, we need to manually check. - if (!isCaseSensitiveRename && Interop.Sys.LStatWrap(destNoDirectorySeparator.ToString (), out Interop.Sys.FileStatus destFileStatus) >= 0) + if (!isCaseSensitiveRename && Interop.Sys.LStat(destNoDirectorySeparator, out Interop.Sys.FileStatus destFileStatus) >= 0) { // Maintain order of exceptions as on Windows. // Throw if the source doesn't exist. - if (Interop.Sys.LStatWrap(srcNoDirectorySeparator.ToString (), out Interop.Sys.FileStatus sourceFileStatus) < 0) + if (Interop.Sys.LStat(srcNoDirectorySeparator, out Interop.Sys.FileStatus sourceFileStatus) < 0) { throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, sourceFullPath)); } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs index 69c98d1713ca05..075a14d936c943 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs @@ -16,7 +16,7 @@ public static partial class Path // Checks if the given path is available for use. private static bool ExistsCore(string fullPath, out bool isDirectory) { - bool result = Interop.Sys.LStatWrap(fullPath, out Interop.Sys.FileStatus fileInfo) == Interop.Errors.ERROR_SUCCESS; + bool result = Interop.Sys.LStat(fullPath, out Interop.Sys.FileStatus fileInfo) == Interop.Errors.ERROR_SUCCESS; isDirectory = result && (fileInfo.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR; return result; diff --git a/src/native/libs/Common/pal_error_common.h b/src/native/libs/Common/pal_error_common.h index 103e81c6e3efc1..7541132da7b188 100644 --- a/src/native/libs/Common/pal_error_common.h +++ b/src/native/libs/Common/pal_error_common.h @@ -145,9 +145,6 @@ typedef enum inline static int32_t ConvertErrorPlatformToPal(int32_t platformErrno) { -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "%s at %s:%d. platformErrno == %d", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__, platformErrno); -#endif switch (platformErrno) { case 0: diff --git a/src/native/libs/System.IO.Ports.Native/CMakeLists.txt b/src/native/libs/System.IO.Ports.Native/CMakeLists.txt index 5a01ada023d589..a53be1dd8c9b7d 100644 --- a/src/native/libs/System.IO.Ports.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Ports.Native/CMakeLists.txt @@ -22,13 +22,6 @@ if (GEN_SHARED_LIB) -lnetwork ) endif() - - if (CLR_CMAKE_TARGET_ANDROID) - target_link_libraries(System.IO.Ports.Native - PRIVATE - log - ) - endif() endif() add_library(System.IO.Ports.Native-Static diff --git a/src/native/libs/System.Native/pal_io.c b/src/native/libs/System.Native/pal_io.c index b6f6198bf2b6ca..3777ad55151f9d 100644 --- a/src/native/libs/System.Native/pal_io.c +++ b/src/native/libs/System.Native/pal_io.c @@ -260,9 +260,6 @@ int32_t SystemNative_FStat(intptr_t fd, FileStatus* output) int32_t SystemNative_LStat(const char* path, FileStatus* output) { -#if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "%s at %s:%d. path == '%s'", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__, path); -#endif struct stat_ result; int ret = lstat_(path, &result); @@ -402,7 +399,7 @@ int32_t SystemNative_IsMemfdSupported(void) } #endif - // Note that the name has no affect on file descriptor behavior. From linux manpage: + // Note that the name has no affect on file descriptor behavior. From linux manpage: // Names do not affect the behavior of the file descriptor, and as such multiple files can have the same name without any side effects. int32_t fd = (int32_t)syscall(__NR_memfd_create, "test", MFD_CLOEXEC | MFD_ALLOW_SEALING); if (fd < 0) return 0; @@ -1979,7 +1976,7 @@ static int GetAllowedVectorCount(IOVector* vectors, int32_t vectorCount) // For macOS preadv and pwritev can fail with EINVAL when the total length // of all vectors overflows a 32-bit integer. size_t totalLength = 0; - for (int i = 0; i < allowedCount; i++) + for (int i = 0; i < allowedCount; i++) { assert(INT_MAX >= vectors[i].Count); From d4cdf664c78fce995637ff401a0e78adcb461d82 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 6 Feb 2025 18:45:34 +0100 Subject: [PATCH 29/63] Logging to Android logcat --- src/coreclr/dlls/mscordbi/CMakeLists.txt | 4 ++++ src/coreclr/inc/clrconfigvalues.h | 1 + src/coreclr/utilcode/log.cpp | 17 +++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/coreclr/dlls/mscordbi/CMakeLists.txt b/src/coreclr/dlls/mscordbi/CMakeLists.txt index 87e566175a25c0..aa9ea05710af93 100644 --- a/src/coreclr/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/dlls/mscordbi/CMakeLists.txt @@ -122,6 +122,10 @@ elseif(CLR_CMAKE_HOST_UNIX) # find all symbols. target_link_libraries(mscordbi PRIVATE ${COREDBI_LIBRARIES} ${COREDBI_LIBRARIES}) + if(CLR_CMAKE_TARGET_ANDROID) + target_link_libraries(mscordbi PRIVATE log) + endif() + add_dependencies(mscordbi mscordaccore) if(CLR_CMAKE_HOST_LINUX) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index ffc68923d7ddc9..6b94606faa727b 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -383,6 +383,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_LogToConsole, W("LogToConsole"), 0 , "Writes t CONFIG_DWORD_INFO(INTERNAL_LogToDebugger, W("LogToDebugger"), 0 , "Writes the CLR log to debugger (OutputDebugStringA).") CONFIG_DWORD_INFO(INTERNAL_LogToFile, W("LogToFile"), 0 , "Writes the CLR log to a file.") CONFIG_DWORD_INFO(INTERNAL_LogWithPid, W("LogWithPid"), FALSE, "Appends pid to filename for the CLR log.") +CONFIG_DWORD_INFO(INTERNAL_LogToAndroid, W("LogToAndroid"), 0 , "Writes the CLR log to android logcat") /// /// MetaData diff --git a/src/coreclr/utilcode/log.cpp b/src/coreclr/utilcode/log.cpp index 56ddf6aef9c20e..ab8d3980ff56f4 100644 --- a/src/coreclr/utilcode/log.cpp +++ b/src/coreclr/utilcode/log.cpp @@ -18,6 +18,10 @@ #include "log.h" #include "utilcode.h" +#if defined(TARGET_ANDROID) +#include +#endif + #ifdef LOGGING #define DEFAULT_LOGFILE_NAME W("COMPLUS.LOG") @@ -28,7 +32,7 @@ #define LOG_ENABLE_APPEND_FILE 0x0010 #define LOG_ENABLE_DEBUGGER_LOGGING 0x0020 #define LOG_ENABLE 0x0040 - +#define LOG_ENABLE_ANDROID_LOGGING 0x0080 static DWORD LogFlags = 0; static CQuickWSTR szLogFileName; @@ -55,6 +59,7 @@ VOID InitLogging() LogFlags |= (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogToDebugger) != 0) ? LOG_ENABLE_DEBUGGER_LOGGING : 0; LogFlags |= (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogToFile) != 0) ? LOG_ENABLE_FILE_LOGGING : 0; LogFlags |= (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogToConsole) != 0) ? LOG_ENABLE_CONSOLE_LOGGING : 0; + LogFlags |= (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogToAndroid) != 0) ? LOG_ENABLE_ANDROID_LOGGING : 0; LogFacilityMask2 = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogFacility2, LogFacilityMask2) | LF_ALWAYS; @@ -383,6 +388,15 @@ VOID LogSpewAlwaysValist(const char *fmt, va_list args) OutputDebugStringA(pBuffer); } +#if defined(TARGET_ANDROID) + if (LogFlags & LOG_ENABLE_ANDROID_LOGGING) + { + // TODO: priority should be configurable here (best, passed via a parameter) + // likewise for the tag + __android_log_write (ANDROID_LOG_INFO, "CoreCLR", pBuffer); + } +#endif // TARGET_ANDROID + LeaveLogLock(); } @@ -417,4 +431,3 @@ VOID LogSpewAlways (const char *fmt, ... ) } #endif // LOGGING - From 75c6e4c50410b8ebad45a47b9832c0767bc7e465 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 6 Feb 2025 20:16:16 +0100 Subject: [PATCH 30/63] Write to logcat instead of stderr --- src/coreclr/vm/util.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/coreclr/vm/util.cpp b/src/coreclr/vm/util.cpp index cb2cf1a938b7fb..fb93eb8e0fdb1b 100644 --- a/src/coreclr/vm/util.cpp +++ b/src/coreclr/vm/util.cpp @@ -15,6 +15,9 @@ #ifndef DACCESS_COMPILE +#if defined(TARGET_ANDROID) +#include +#endif thread_local size_t t_ThreadType; @@ -179,8 +182,13 @@ void PrintToStdErrA(const char *pszString) { HANDLE Handle = GetStdHandle(STD_ERROR_HANDLE); +#if defined(TARGET_ANDROID) + // TODO: make priority configurable? + __android_log_write(ANDROID_LOG_INFO, "CoreCLR", pszString); +#else size_t len = strlen(pszString); NPrintToHandleA(Handle, pszString, len); +#endif } void PrintToStdErrW(const WCHAR *pwzString) From 91772f404cbdb88c2afab5582a7a32238401d6d5 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 19 Feb 2025 19:05:01 +0100 Subject: [PATCH 31/63] This should work... --- src/coreclr/utilcode/log.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/utilcode/log.cpp b/src/coreclr/utilcode/log.cpp index ab8d3980ff56f4..9d21aab9253215 100644 --- a/src/coreclr/utilcode/log.cpp +++ b/src/coreclr/utilcode/log.cpp @@ -389,11 +389,12 @@ VOID LogSpewAlwaysValist(const char *fmt, va_list args) } #if defined(TARGET_ANDROID) + __android_log_write (ANDROID_LOG_INFO, "CoreCLR-log", "This should be logged"); if (LogFlags & LOG_ENABLE_ANDROID_LOGGING) { // TODO: priority should be configurable here (best, passed via a parameter) // likewise for the tag - __android_log_write (ANDROID_LOG_INFO, "CoreCLR", pBuffer); + __android_log_write (ANDROID_LOG_INFO, "CoreCLR-log", pBuffer); } #endif // TARGET_ANDROID From 32ee9a9cbee802acd3680cb71a7e2d4e4d5e488d Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 19 Feb 2025 21:30:49 +0000 Subject: [PATCH 32/63] Update src/coreclr/vm/peimage.inl Co-authored-by: Aaron Robinson --- src/coreclr/vm/peimage.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index 9c759927f6f9a6..54d8ffc38fca34 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -112,7 +112,7 @@ inline BOOL PEImage::IsFile() { WRAPPER_NO_CONTRACT; #if defined(TARGET_ANDROID) - return false; + return FALSE; #else return !GetPathToLoad().IsEmpty(); #endif From 4026a7bd8b9874793bb02b47dae75780950b7bfa Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 19 Feb 2025 21:31:12 +0000 Subject: [PATCH 33/63] Update src/coreclr/vm/peimage.cpp Co-authored-by: Aaron Robinson --- src/coreclr/vm/peimage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/peimage.cpp b/src/coreclr/vm/peimage.cpp index 0b2ddbc486856c..1b228699b1a1ad 100644 --- a/src/coreclr/vm/peimage.cpp +++ b/src/coreclr/vm/peimage.cpp @@ -891,7 +891,7 @@ HRESULT PEImage::TryOpenFile(bool takeLock) OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -#endif +#endif // TARGET_ANDROID if (m_hFile != INVALID_HANDLE_VALUE) return S_OK; From cc4e7347e301d3a8e2786b61f1ac7bf0b9dd1c1b Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 20 Feb 2025 11:00:57 +0100 Subject: [PATCH 34/63] Post-rebase adjustments --- src/coreclr/clrfeatures.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreclr/clrfeatures.cmake b/src/coreclr/clrfeatures.cmake index 1b1eec6c3aefc5..83cf4818add318 100644 --- a/src/coreclr/clrfeatures.cmake +++ b/src/coreclr/clrfeatures.cmake @@ -47,5 +47,4 @@ endif() if (CLR_CMAKE_TARGET_WIN32) set(FEATURE_TYPEEQUIVALENCE 1) -endif(CLR_CMAKE_TARGET_WIN32) - +endif(CLR_CMAKE_TARGET_WIN32) \ No newline at end of file From 0650ae73cd3d013fac888c88a46746671d32b3b4 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 20 Feb 2025 13:04:57 +0100 Subject: [PATCH 35/63] [WIP] Remove android_coreclr_initialize and modify the existing one Signature is altered on Android, by adding a pointer to the host contract structure. The host contract structure also gains a new pointer, `external_assembly_probe` (proposed in https://github.com/dotnet/runtime/issues/112706) which is used, if present, when `bundle_probe` is `nullptr` or if it returns `false` when called. Either `bundle_probe` or `external_assembly_probe` must be set in the contract --- src/coreclr/dlls/mscoree/exports.cpp | 137 +----------------- .../dlls/mscoree/mscorwks_unixexports.src | 3 - src/coreclr/hosts/corerun/corerun.cpp | 3 + src/coreclr/hosts/inc/coreclrhost.h | 18 +-- src/coreclr/inc/bundle.h | 11 +- src/coreclr/vm/bundle.cpp | 28 +++- src/coreclr/vm/peimagelayout.cpp | 2 +- src/native/corehost/host_runtime_contract.h | 6 +- 8 files changed, 42 insertions(+), 166 deletions(-) diff --git a/src/coreclr/dlls/mscoree/exports.cpp b/src/coreclr/dlls/mscoree/exports.cpp index 15b7de3acac8e3..57e5015458bea9 100644 --- a/src/coreclr/dlls/mscoree/exports.cpp +++ b/src/coreclr/dlls/mscoree/exports.cpp @@ -147,31 +147,6 @@ static void InitializeStartupFlags(STARTUP_FLAGS* startupFlagsRef) *startupFlagsRef = startupFlags; } -#if defined(TARGET_ANDROID) -static void ConvertConfigPropertiesToUnicode( - const host_configuration_properties* properties, - LPCWSTR** propertyKeysWRef, - LPCWSTR** propertyValuesWRef) -{ - LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[properties->nitems]; - ASSERTE_ALL_BUILDS(propertyKeysW != nullptr); - - LPCWSTR* propertyValuesW = new (nothrow) LPCWSTR[properties->nitems]; - ASSERTE_ALL_BUILDS(propertyValuesW != nullptr); - - for (size_t propertyIndex = 0; propertyIndex < properties->nitems; ++propertyIndex) - { - host_configuration_property const& prop = properties->data[propertyIndex]; - propertyKeysW[propertyIndex] = prop.name; - propertyValuesW[propertyIndex] = prop.value; - } - - *propertyKeysWRef = propertyKeysW; - *propertyValuesWRef = propertyValuesW; -} - -#else // TARGET_ANDROID - static void ConvertConfigPropertiesToUnicode( const char** propertyKeys, const char** propertyValues, @@ -230,7 +205,6 @@ static void ConvertConfigPropertiesToUnicode( *propertyKeysWRef = propertyKeysW; *propertyValuesWRef = propertyValuesW; } -#endif // !TARGET_ANDROID coreclr_error_writer_callback_fn g_errorWriter = nullptr; // @@ -256,103 +230,6 @@ GetInfoForMethodDelegate getInfoForMethodDelegate = NULL; extern "C" int coreclr_create_delegate(void*, unsigned int, const char*, const char*, const char*, void**); #endif //FEATURE_GDBJIT -#if defined(TARGET_ANDROID) -extern "C" -NOINLINE -DLLEXPORT -int android_coreclr_initialize( - const char* appName, - const char16_t* appDomainFriendlyName, - host_runtime_contract* hostContract, - const host_configuration_properties* properties, - void **hostHandle, - unsigned int* domainId) -{ - HostingApiFrameHolder apiFrameHolder(_ReturnAddress()); - - if (properties == nullptr) { [[unlikely]] - LogErrorToLogcat(ANDROID_LOG_FATAL, "Initialization routine was not passed the required configuration properties pointer."); - return HOST_E_INVALIDOPERATION; - } - - if (properties->data == nullptr) { [[unlikely]] - LogErrorToLogcat(ANDROID_LOG_FATAL, "Initialization routine was not passed valid configuration properties data."); - return HOST_E_INVALIDOPERATION; - } - - if (hostContract == nullptr) { [[unlikely]] - LogErrorToLogcat(ANDROID_LOG_FATAL, "Initialization routine was not passed the required host contract pointer."); - return HOST_E_INVALIDOPERATION; - } - - if (hostContract->pinvoke_override == nullptr) { [[unlikely]] - LogErrorToLogcat(ANDROID_LOG_FATAL, "Host contract isn't initialized properly: missing p/invoke override handler."); - return HOST_E_INVALIDOPERATION; - } - - if (hostContract->android_bundle_probe == nullptr) { [[unlikely]] - LogErrorToLogcat(ANDROID_LOG_FATAL, "Host contract isn't initialized properly: missing bundle probe handler."); - return HOST_E_INVALIDOPERATION; - } - - LPCWSTR* propertyKeysW = nullptr; - LPCWSTR* propertyValuesW = nullptr; - ConvertConfigPropertiesToUnicode (properties, &propertyKeysW, &propertyValuesW); - - // Android doesn't have executables as such (at least as far as Android applications are concerned), - // so we will use application name (package name) as the "executable path" here. - DWORD error = PAL_InitializeCoreCLR(appName, g_coreclr_embedded); - HRESULT hr = HRESULT_FROM_WIN32(error); - - // If PAL initialization failed, then we should return right away and avoid - // calling any other APIs because they can end up calling into the PAL layer again. - if (FAILED(hr)) - { - return hr; - } - - HostInformation::SetContract(hostContract); - PInvokeOverride::SetPInvokeOverride(hostContract->pinvoke_override, PInvokeOverride::Source::RuntimeConfiguration); - - ReleaseHolder host; - hr = CorHost2::CreateObject(IID_ICLRRuntimeHost4, (void**)&host); - IfFailRet(hr); - - static Bundle bundle(appName, hostContract->android_bundle_probe); - Bundle::AppBundle = &bundle; - - // This will take ownership of propertyKeysWTemp and propertyValuesWTemp - Configuration::InitializeConfigurationKnobs(static_cast(properties->nitems), propertyKeysW, propertyValuesW); - - STARTUP_FLAGS startupFlags; - InitializeStartupFlags(&startupFlags); - - hr = host->SetStartupFlags(startupFlags); - IfFailRet(hr); - - hr = host->Start(); - IfFailRet(hr); - - hr = host->CreateAppDomainWithManager( - appDomainFriendlyName, - APPDOMAIN_SECURITY_DEFAULT, - nullptr, // Name of the assembly that contains the AppDomainManager implementation - nullptr, // The AppDomainManager implementation type name - static_cast(properties->nitems), - propertyKeysW, - propertyValuesW, - (DWORD *)domainId); - - if (SUCCEEDED(hr)) - { - host.SuppressRelease(); - *hostHandle = host; - } - return hr; -} - -#endif // TARGET_ANDROID - // // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain // @@ -372,6 +249,9 @@ extern "C" NOINLINE DLLEXPORT int coreclr_initialize( +#if defined(TARGET_ANDROID) + host_runtime_contract* contract, +#endif const char* exePath, const char* appDomainFriendlyName, int propertyCount, @@ -380,14 +260,13 @@ int coreclr_initialize( void** hostHandle, unsigned int* domainId) { -#if !defined(TARGET_ANDROID) HRESULT hr; LPCWSTR* propertyKeysW; LPCWSTR* propertyValuesW; BundleProbeFn* bundleProbe = nullptr; PInvokeOverrideFn* pinvokeOverride = nullptr; - host_runtime_contract* hostContract = nullptr; + host_runtime_contract* hostContract = contract; #ifdef TARGET_UNIX HostingApiFrameHolder apiFrameHolder(_ReturnAddress()); @@ -432,9 +311,10 @@ int coreclr_initialize( ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName); - if (bundleProbe != nullptr) + ExternalAssemblyProbeFn* externalAssemblyProbe = contract != nullptr ? contract->external_assembly_probe : nullptr; + if (bundleProbe != nullptr || externalAssemblyProbe != nullptr) { - static Bundle bundle(exePath, bundleProbe); + static Bundle bundle(exePath, bundleProbe, externalAssemblyProbe); Bundle::AppBundle = &bundle; } @@ -485,9 +365,6 @@ int coreclr_initialize( #endif } return hr; -#else // TARGET_ANDROID - return HOST_E_INVALIDOPERATION; -#endif } // diff --git a/src/coreclr/dlls/mscoree/mscorwks_unixexports.src b/src/coreclr/dlls/mscoree/mscorwks_unixexports.src index 4e52fcf5a997e2..3eacb7fa484856 100644 --- a/src/coreclr/dlls/mscoree/mscorwks_unixexports.src +++ b/src/coreclr/dlls/mscoree/mscorwks_unixexports.src @@ -1,6 +1,3 @@ -; Android hosting API -android_coreclr_initialize - ; Unix hosting API coreclr_create_delegate coreclr_execute_assembly diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index f17f19f6f2942c..a725eed9fe6c83 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -404,6 +404,9 @@ static int run(const configuration& config) int result; result = coreclr_init_func( +#if defined(TARGET_ANDROID) + nullptr, // contract +#endif exe_path_utf8.c_str(), "corerun", propertyCount, diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index d588a9693f7be9..14c74f78f886aa 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -33,19 +33,11 @@ CORECLR_HOSTING_API_LINKAGE int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) -#if defined(TARGET_ANDROID) -CORECLR_HOSTING_API(android_coreclr_initialize, - const char* appName, - const char16_t* appDomainFriendlyName, - host_runtime_contract* hostContract, - const host_configuration_properties* properties, - void **hostHandle, - unsigned int* domainId); -#endif // // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain // // Parameters: +// hostContract - (Android only) pointer to the host contract structure // exePath - Absolute path of the executable that invoked the ExecuteAssembly (the native host application) // appDomainFriendlyName - Friendly name of the app domain that will be created to execute the assembly // propertyCount - Number of properties (elements of the following two arguments) @@ -58,6 +50,9 @@ CORECLR_HOSTING_API(android_coreclr_initialize, // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed // CORECLR_HOSTING_API(coreclr_initialize, +#if defined(TARGET_ANDROID) + host_runtime_contract* contract, +#endif const char* exePath, const char* appDomainFriendlyName, int propertyCount, @@ -163,11 +158,8 @@ CORECLR_HOSTING_API(coreclr_execute_assembly, // // Callback types used by the hosts // -#if defined(TARGET_ANDROID) -using BundleProbeFn = bool(const char* path, void** data_start, int64_t* size); -#else +using ExternalAssemblyProbeFn = bool(const char* path, void** data_start, int64_t* size); typedef bool(CORECLR_CALLING_CONVENTION BundleProbeFn)(const char* path, int64_t* offset, int64_t* size, int64_t* compressedSize); -#endif typedef const void* (CORECLR_CALLING_CONVENTION PInvokeOverrideFn)(const char* libraryName, const char* entrypointName); diff --git a/src/coreclr/inc/bundle.h b/src/coreclr/inc/bundle.h index 5305510c019ff6..c56c09f42429bd 100644 --- a/src/coreclr/inc/bundle.h +++ b/src/coreclr/inc/bundle.h @@ -18,26 +18,18 @@ class Bundle; struct BundleFileLocation { INT64 Size; -#if defined(TARGET_ANDROID) void* DataStart; - constexpr static INT64 Offset = 0; - constexpr static INT64 UncompresedSize = 0; -#else INT64 Offset; INT64 UncompresedSize; -#endif BundleFileLocation() { LIMITED_METHOD_CONTRACT; Size = 0; -#if defined(TARGET_ANDROID) DataStart = INVALID_HANDLE_VALUE; -#else Offset = 0; UncompresedSize = 0; -#endif } static BundleFileLocation Invalid() { LIMITED_METHOD_CONTRACT; return BundleFileLocation(); } @@ -54,7 +46,7 @@ struct BundleFileLocation class Bundle { public: - Bundle(LPCSTR bundlePath, BundleProbeFn *probe); + Bundle(LPCSTR bundlePath, BundleProbeFn *probe, ExternalAssemblyProbeFn* externalAssemblyProbe = nullptr); BundleFileLocation Probe(const SString& path, bool pathIsBundleRelative = false) const; const SString &Path() const { LIMITED_METHOD_CONTRACT; return m_path; } @@ -70,6 +62,7 @@ class Bundle #endif SString m_path; // The path to single-file executable BundleProbeFn *m_probe; + ExternalAssemblyProbeFn *m_externalAssemblyProbe; SString m_basePath; // The prefix to denote a path within the bundle COUNT_T m_basePathLength = 0; diff --git a/src/coreclr/vm/bundle.cpp b/src/coreclr/vm/bundle.cpp index f555837ac9988d..535ae9bcb42a67 100644 --- a/src/coreclr/vm/bundle.cpp +++ b/src/coreclr/vm/bundle.cpp @@ -42,12 +42,13 @@ const SString &BundleFileLocation::AppName() const } #endif -Bundle::Bundle(LPCSTR bundlePath, BundleProbeFn *probe) +Bundle::Bundle(LPCSTR bundlePath, BundleProbeFn *probe, ExternalAssemblyProbeFn* externalAssemblyProbe) { STANDARD_VM_CONTRACT; - _ASSERTE(probe != nullptr); + _ASSERTE(probe != nullptr || externalAssemblyProbe != nullptr); m_probe = probe; + m_externalAssemblyProbe = externalAssemblyProbe; #if defined(TARGET_ANDROID) m_appName.SetUTF8(bundlePath); #else @@ -105,11 +106,24 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) #endif // !TARGET_ANDROID INT64 fileSize = 0; INT64 compressedSize = 0; + bool assemblyFound = false; -#if defined(TARGET_ANDROID) - m_probe(utf8Path, &loc.DataStart, &loc.Size); -#else - m_probe(utf8Path, &loc.Offset, &fileSize, &compressedSize); + if (m_probe != nullptr) + { + assemblyFound = m_probe(utf8Path, &loc.Offset, &fileSize, &compressedSize); + loc.DataStart = nullptr; // Location is based on the bundle file start + } + + if (!assemblyFound && m_externalAssemblyProbe != nullptr) + { + m_externalAssemblyProbe (utf8Path, &loc.DataStart, &fileSize); + + // Host takes care of decompression, if any + compressedSize = 0; + + // Must always be 0 in this mode, since loc.DataStart points to the beginning of data + loc.Offset = 0; + } if (compressedSize) { @@ -121,7 +135,7 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) loc.Size = fileSize; loc.UncompresedSize = 0; } -#endif + return loc; } diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index 3f363bda309a63..7f01500ee6fccb 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -638,7 +638,7 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) #else // !TARGET_ANDROID INT64 size = pOwner->GetSize(); HANDLE mapBegin = pOwner->AndroidGetDataStart(); - if (size == 0) { + if (size == 0 || mapBegin == nullptr) { // TODO: throw something } #endif // TARGET_ANDROID diff --git a/src/native/corehost/host_runtime_contract.h b/src/native/corehost/host_runtime_contract.h index 46d8aa4e939369..f6ca7a0bb105f8 100644 --- a/src/native/corehost/host_runtime_contract.h +++ b/src/native/corehost/host_runtime_contract.h @@ -38,12 +38,12 @@ struct host_runtime_contract size_t value_buffer_size, void* contract_context); -#if defined(TARGET_ANDROID) - bool(HOST_CONTRACT_CALLTYPE* android_bundle_probe)( + // Probe the host for `path`. Sets pointer to data start and its size, if found. + bool(HOST_CONTRACT_CALLTYPE* external_assembly_probe)( const char* path, void **data_start, int64_t* size); -#endif + // Probe an app bundle for `path`. Sets its location (`offset`, `size`) in the bundle if found. // Returns true if found, false otherwise. bool(HOST_CONTRACT_CALLTYPE* bundle_probe)( From 562c8e9c7f3575290a269e9cf1719494ff0244b4 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 20 Feb 2025 10:44:54 -0500 Subject: [PATCH 36/63] Cleanup - build failed locally for arm64. Removed unused blocks --- eng/native/gen-buildsys.sh | 1 + eng/native/tryrun.cmake | 1 - src/coreclr/dlls/mscordac/CMakeLists.txt | 4 ---- src/coreclr/dlls/mscordac/mscordac.cpp | 8 +------- src/coreclr/dlls/mscoree/exports.cpp | 10 ---------- src/coreclr/hosts/inc/coreclrhost.h | 2 +- src/coreclr/pal/src/CMakeLists.txt | 4 +++- src/coreclr/vm/common.h | 3 --- src/native/corehost/host_runtime_contract.h | 13 ------------- 9 files changed, 6 insertions(+), 40 deletions(-) diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index d4028cb9577ade..d1adb1534ec503 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -106,6 +106,7 @@ if [[ "$host_arch" == "wasm" ]]; then fi fi +echo "$cmake_command --no-warn-unused-cli -G \"$generator\" \"-DCMAKE_BUILD_TYPE=$buildtype\" \"-DCMAKE_INSTALL_PREFIX=$__CMakeBinDir\" $cmake_extra_defines $__UnprocessedCMakeArgs \"${cmake_extra_defines_wasm[@]}\" -S \"$1\" -B \"$2\"" $cmake_command \ --no-warn-unused-cli \ -G "$generator" \ diff --git a/eng/native/tryrun.cmake b/eng/native/tryrun.cmake index e6aea985591cee..2397f8dcc8f209 100644 --- a/eng/native/tryrun.cmake +++ b/eng/native/tryrun.cmake @@ -1,6 +1,5 @@ set(CROSS_ROOTFS $ENV{ROOTFS_DIR}) set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH}) -set(ANDROID_BUILD $ENV{ANDROID_BUILD}) # Also allow building as Android without specifying `-cross`. if(NOT DEFINED TARGET_ARCH_NAME AND DEFINED ANDROID_BUILD) diff --git a/src/coreclr/dlls/mscordac/CMakeLists.txt b/src/coreclr/dlls/mscordac/CMakeLists.txt index 69ca7baabaf5ee..0b580604c54bc2 100644 --- a/src/coreclr/dlls/mscordac/CMakeLists.txt +++ b/src/coreclr/dlls/mscordac/CMakeLists.txt @@ -163,10 +163,6 @@ set(COREDAC_LIBRARIES ${END_LIBRARY_GROUP} # End group of libraries that have circular references ) -if(CLR_CMAKE_TARGET_ANDROID) - list(APPEND COREDAC_LIBRARIES log) -endif() - if(CLR_CMAKE_HOST_WIN32) # mscordac.def should be generated before mscordaccore.dll is built add_dependencies(mscordaccore mscordaccore_def) diff --git a/src/coreclr/dlls/mscordac/mscordac.cpp b/src/coreclr/dlls/mscordac/mscordac.cpp index 9456931df06dee..b3c2ea2f326938 100644 --- a/src/coreclr/dlls/mscordac/mscordac.cpp +++ b/src/coreclr/dlls/mscordac/mscordac.cpp @@ -1,8 +1,2 @@ // Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -#if defined(TARGET_ANDROID) -void LogDebugToHost(const char* format, ...) -{ - // No-op, just to get the build working. Will be removed later. -} -#endif +// The .NET Foundation licenses this file to you under the MIT license. \ No newline at end of file diff --git a/src/coreclr/dlls/mscoree/exports.cpp b/src/coreclr/dlls/mscoree/exports.cpp index 57e5015458bea9..dadc13ad521122 100644 --- a/src/coreclr/dlls/mscoree/exports.cpp +++ b/src/coreclr/dlls/mscoree/exports.cpp @@ -529,13 +529,3 @@ void LogErrorToHost(const char* format, ...) va_end(args); } } - -#if defined(TARGET_ANDROID) -void LogDebugToHost(const char* format, ...) -{ - va_list args; - va_start(args, format); - __android_log_vprint(ANDROID_LOG_DEBUG, ANDROID_LOGCAT_TAG, format, args); - va_end(args); -} -#endif diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index 14c74f78f886aa..e8157d9dcfa003 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -158,7 +158,7 @@ CORECLR_HOSTING_API(coreclr_execute_assembly, // // Callback types used by the hosts // -using ExternalAssemblyProbeFn = bool(const char* path, void** data_start, int64_t* size); +typedef bool(CORECLR_CALLING_CONVENTION ExternalAssemblyProbeFn)(const char* path, void** data_start, int64_t* size); typedef bool(CORECLR_CALLING_CONVENTION BundleProbeFn)(const char* path, int64_t* offset, int64_t* size, int64_t* compressedSize); typedef const void* (CORECLR_CALLING_CONVENTION PInvokeOverrideFn)(const char* libraryName, const char* entrypointName); diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index a46316b56413ee..b9d99abe7563b7 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -301,7 +301,9 @@ if(CLR_CMAKE_TARGET_LINUX) target_link_libraries(coreclrpal PUBLIC ${ANDROID_GLOB} - ${LZMA}) + ${LZMA} + PRIVATE + log) endif(NOT CLR_CMAKE_TARGET_ANDROID) target_link_libraries(coreclrpal diff --git a/src/coreclr/vm/common.h b/src/coreclr/vm/common.h index 02d0a712251aec..af2817e8b9c2c8 100644 --- a/src/coreclr/vm/common.h +++ b/src/coreclr/vm/common.h @@ -397,7 +397,4 @@ extern DummyGlobalContract ___contract; #endif void LogErrorToHost(const char* format, ...); -#if defined(TARGET_ANDROID) -void LogDebugToHost(const char* format, ...); -#endif #endif // !_common_h_ diff --git a/src/native/corehost/host_runtime_contract.h b/src/native/corehost/host_runtime_contract.h index f6ca7a0bb105f8..ea3a90fd0c9517 100644 --- a/src/native/corehost/host_runtime_contract.h +++ b/src/native/corehost/host_runtime_contract.h @@ -59,17 +59,4 @@ struct host_runtime_contract const char* entry_point_name); }; -#if defined(TARGET_ANDROID) -struct host_configuration_property -{ - const char16_t* name; - const char16_t* value; -}; - -struct host_configuration_properties -{ - size_t nitems; - const host_configuration_property* data; -}; -#endif #endif // __HOST_RUNTIME_CONTRACT_H__ From 493a18662e7d0b998012a74c19c1957a9fd7fa9b Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 20 Feb 2025 11:44:02 -0500 Subject: [PATCH 37/63] Remove host_runtime_contract from coreclr_initialize. Current expectation is that it needs to be encoded as a base64 string --- src/coreclr/dlls/mscoree/exports.cpp | 7 ++----- src/coreclr/hosts/corerun/corerun.cpp | 3 --- src/coreclr/hosts/inc/coreclrhost.h | 3 --- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/coreclr/dlls/mscoree/exports.cpp b/src/coreclr/dlls/mscoree/exports.cpp index dadc13ad521122..5f816e153592d1 100644 --- a/src/coreclr/dlls/mscoree/exports.cpp +++ b/src/coreclr/dlls/mscoree/exports.cpp @@ -249,9 +249,6 @@ extern "C" NOINLINE DLLEXPORT int coreclr_initialize( -#if defined(TARGET_ANDROID) - host_runtime_contract* contract, -#endif const char* exePath, const char* appDomainFriendlyName, int propertyCount, @@ -266,7 +263,7 @@ int coreclr_initialize( LPCWSTR* propertyValuesW; BundleProbeFn* bundleProbe = nullptr; PInvokeOverrideFn* pinvokeOverride = nullptr; - host_runtime_contract* hostContract = contract; + host_runtime_contract* hostContract = nullptr; #ifdef TARGET_UNIX HostingApiFrameHolder apiFrameHolder(_ReturnAddress()); @@ -311,7 +308,7 @@ int coreclr_initialize( ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName); - ExternalAssemblyProbeFn* externalAssemblyProbe = contract != nullptr ? contract->external_assembly_probe : nullptr; + ExternalAssemblyProbeFn* externalAssemblyProbe = hostContract != nullptr ? hostContract->external_assembly_probe : nullptr; if (bundleProbe != nullptr || externalAssemblyProbe != nullptr) { static Bundle bundle(exePath, bundleProbe, externalAssemblyProbe); diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index a725eed9fe6c83..f17f19f6f2942c 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -404,9 +404,6 @@ static int run(const configuration& config) int result; result = coreclr_init_func( -#if defined(TARGET_ANDROID) - nullptr, // contract -#endif exe_path_utf8.c_str(), "corerun", propertyCount, diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index e8157d9dcfa003..9b1e645ee5d1ab 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -50,9 +50,6 @@ // HRESULT indicating status of the operation. S_OK if the assembly was successfully executed // CORECLR_HOSTING_API(coreclr_initialize, -#if defined(TARGET_ANDROID) - host_runtime_contract* contract, -#endif const char* exePath, const char* appDomainFriendlyName, int propertyCount, From 3e97a9e817c01a059669b108a0f8ad8bf669a4b6 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 20 Feb 2025 17:37:45 +0000 Subject: [PATCH 38/63] Update src/coreclr/hosts/inc/coreclrhost.h Co-authored-by: Jan Kotas --- src/coreclr/hosts/inc/coreclrhost.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index 9b1e645ee5d1ab..35f8b2bb3a250c 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -37,7 +37,6 @@ // Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain // // Parameters: -// hostContract - (Android only) pointer to the host contract structure // exePath - Absolute path of the executable that invoked the ExecuteAssembly (the native host application) // appDomainFriendlyName - Friendly name of the app domain that will be created to execute the assembly // propertyCount - Number of properties (elements of the following two arguments) From f398c6e22bd1556d4facbd391afb611af0f22c48 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 20 Feb 2025 17:38:54 +0000 Subject: [PATCH 39/63] Update src/coreclr/inc/bundle.h Co-authored-by: Jan Kotas --- src/coreclr/inc/bundle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/inc/bundle.h b/src/coreclr/inc/bundle.h index c56c09f42429bd..309bd082e4e413 100644 --- a/src/coreclr/inc/bundle.h +++ b/src/coreclr/inc/bundle.h @@ -27,7 +27,7 @@ struct BundleFileLocation LIMITED_METHOD_CONTRACT; Size = 0; - DataStart = INVALID_HANDLE_VALUE; + DataStart = nullptr; Offset = 0; UncompresedSize = 0; } From 7127b59283a7e97cfa98fec36f21f6a36d28b03a Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 20 Feb 2025 17:39:18 +0000 Subject: [PATCH 40/63] Update src/coreclr/hosts/inc/coreclrhost.h Co-authored-by: Jan Kotas --- src/coreclr/hosts/inc/coreclrhost.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index 35f8b2bb3a250c..12099870c9714a 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -22,10 +22,6 @@ #define CORECLR_HOSTING_API_LINKAGE #endif -#if defined(TARGET_ANDROID) -#include "corehost/host_runtime_contract.h" -#endif - // For each hosting API, we define a function prototype and a function pointer // The prototype is useful for implicit linking against the dynamic coreclr // library and the pointer for explicit dynamic loading (dlopen, LoadLibrary) From e1e7e3246fad3726a3c62732df43f2aa1472c452 Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Thu, 20 Feb 2025 19:04:39 +0100 Subject: [PATCH 41/63] Address feedback --- src/coreclr/inc/bundle.h | 5 +---- src/coreclr/vm/bundle.cpp | 7 +++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/coreclr/inc/bundle.h b/src/coreclr/inc/bundle.h index 309bd082e4e413..69ebfc3625b74b 100644 --- a/src/coreclr/inc/bundle.h +++ b/src/coreclr/inc/bundle.h @@ -57,10 +57,7 @@ class Bundle static BundleFileLocation ProbeAppBundle(const SString& path, bool pathIsBundleRelative = false); private: -#if defined(TARGET_ANDROID) - SString m_appName; -#endif - SString m_path; // The path to single-file executable + SString m_path; // The path to single-file executable or package name/id on Android BundleProbeFn *m_probe; ExternalAssemblyProbeFn *m_externalAssemblyProbe; diff --git a/src/coreclr/vm/bundle.cpp b/src/coreclr/vm/bundle.cpp index 535ae9bcb42a67..ebe8a94dc47fef 100644 --- a/src/coreclr/vm/bundle.cpp +++ b/src/coreclr/vm/bundle.cpp @@ -49,11 +49,10 @@ Bundle::Bundle(LPCSTR bundlePath, BundleProbeFn *probe, ExternalAssemblyProbeFn* _ASSERTE(probe != nullptr || externalAssemblyProbe != nullptr); m_probe = probe; m_externalAssemblyProbe = externalAssemblyProbe; -#if defined(TARGET_ANDROID) - m_appName.SetUTF8(bundlePath); -#else - m_path.SetUTF8(bundlePath); + // On Android this is not a real path, but rather the application's package name + m_path.SetUTF8(bundlePath); +#if !defined(TARGET_ANDROID) // The bundle-base path is the directory containing the single-file bundle. // When the Probe() function searches within the bundle, it masks out the basePath from the assembly-path (if found). From 7d4254a660f41c41b5bff9d988262d1d6fa3eb31 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Fri, 21 Feb 2025 09:20:03 -0500 Subject: [PATCH 42/63] Remove some logging related things since Elinor's PR landed --- src/coreclr/dlls/mscordbi/CMakeLists.txt | 3 --- src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt | 3 --- src/coreclr/dlls/mscoree/exports.cpp | 17 ----------------- src/coreclr/jit/CMakeLists.txt | 7 ------- 4 files changed, 30 deletions(-) diff --git a/src/coreclr/dlls/mscordbi/CMakeLists.txt b/src/coreclr/dlls/mscordbi/CMakeLists.txt index aa9ea05710af93..9fdc94dfa1f3f6 100644 --- a/src/coreclr/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/dlls/mscordbi/CMakeLists.txt @@ -122,9 +122,6 @@ elseif(CLR_CMAKE_HOST_UNIX) # find all symbols. target_link_libraries(mscordbi PRIVATE ${COREDBI_LIBRARIES} ${COREDBI_LIBRARIES}) - if(CLR_CMAKE_TARGET_ANDROID) - target_link_libraries(mscordbi PRIVATE log) - endif() add_dependencies(mscordbi mscordaccore) diff --git a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt index 43ebab63e11cf3..b6cf126b1be7d2 100644 --- a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt @@ -187,9 +187,6 @@ endif() target_sources(coreclr PUBLIC $) target_link_libraries(coreclr PUBLIC ${CORECLR_LIBRARIES} ${CLRJIT_STATIC} cee_wks ${FOUNDATION}) -if (CLR_CMAKE_TARGET_ANDROID) -target_link_libraries(coreclr PUBLIC log) -endif() target_sources(coreclr_static PUBLIC $) target_link_libraries(coreclr_static PUBLIC ${CORECLR_LIBRARIES} clrjit_static cee_wks_mergeable ${FOUNDATION}) diff --git a/src/coreclr/dlls/mscoree/exports.cpp b/src/coreclr/dlls/mscoree/exports.cpp index 5f816e153592d1..473bedf1b94815 100644 --- a/src/coreclr/dlls/mscoree/exports.cpp +++ b/src/coreclr/dlls/mscoree/exports.cpp @@ -23,10 +23,6 @@ #include #include -#if defined(TARGET_ANDROID) -#include -#endif // TARGET_ANDROID - #define ASSERTE_ALL_BUILDS(expr) _ASSERTE_ALL_BUILDS((expr)) #ifdef TARGET_UNIX @@ -78,19 +74,6 @@ class ConstWStringArrayHolder : public NewArrayHolder } }; -#if defined(TARGET_ANDROID) -namespace { - constexpr static char ANDROID_LOGCAT_TAG[] { "CoreCLR" }; - void LogErrorToLogcat(int priority, const char* format, ...) noexcept - { - va_list args; - va_start(args, format); - __android_log_vprint(priority, ANDROID_LOGCAT_TAG, format, args); - va_end(args); - } -} -#endif - // Convert 8 bit string to unicode static LPCWSTR StringToUnicode(LPCSTR str) { diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index db01dc8487c71c..840b954c00193e 100644 --- a/src/coreclr/jit/CMakeLists.txt +++ b/src/coreclr/jit/CMakeLists.txt @@ -611,13 +611,6 @@ function(add_jit jitName) ${JIT_ARCH_LINK_LIBRARIES} ) - if(CLR_CMAKE_TARGET_ANDROID) - target_link_libraries(${jitName} - PRIVATE - log - ) - endif() - if (CLR_CMAKE_HOST_WIN32) link_natvis_sources_for_target(${jitName} PRIVATE clrjit.natvis) endif() From a16e3ed954f2b52cc22214a314a208f06a66ecf4 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 10:13:39 -0800 Subject: [PATCH 43/63] Fix HostRuntimeContract tests --- .../HostApiInvokerApp/HostRuntimeContract.cs | 1 + src/native/corehost/host_runtime_contract.h | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/installer/tests/Assets/Projects/HostApiInvokerApp/HostRuntimeContract.cs b/src/installer/tests/Assets/Projects/HostApiInvokerApp/HostRuntimeContract.cs index 4ecf59b2761ace..4498f4de9c7e2d 100644 --- a/src/installer/tests/Assets/Projects/HostApiInvokerApp/HostRuntimeContract.cs +++ b/src/installer/tests/Assets/Projects/HostApiInvokerApp/HostRuntimeContract.cs @@ -18,6 +18,7 @@ internal struct host_runtime_contract public delegate* unmanaged[Stdcall] get_runtime_property; public delegate* unmanaged[Stdcall] bundle_probe; public IntPtr pinvoke_override; + public delegate* unmanaged[Stdcall] external_assembly_probe; } #pragma warning restore CS0649 diff --git a/src/native/corehost/host_runtime_contract.h b/src/native/corehost/host_runtime_contract.h index ea3a90fd0c9517..1aaf2212ccfad1 100644 --- a/src/native/corehost/host_runtime_contract.h +++ b/src/native/corehost/host_runtime_contract.h @@ -38,12 +38,6 @@ struct host_runtime_contract size_t value_buffer_size, void* contract_context); - // Probe the host for `path`. Sets pointer to data start and its size, if found. - bool(HOST_CONTRACT_CALLTYPE* external_assembly_probe)( - const char* path, - void **data_start, - int64_t* size); - // Probe an app bundle for `path`. Sets its location (`offset`, `size`) in the bundle if found. // Returns true if found, false otherwise. bool(HOST_CONTRACT_CALLTYPE* bundle_probe)( @@ -57,6 +51,12 @@ struct host_runtime_contract const void* (HOST_CONTRACT_CALLTYPE* pinvoke_override)( const char* library_name, const char* entry_point_name); + + // Probe the host for `path`. Sets pointer to data start and its size, if found. + bool(HOST_CONTRACT_CALLTYPE* external_assembly_probe)( + const char* path, + void **data_start, + int64_t* size); }; #endif // __HOST_RUNTIME_CONTRACT_H__ From 99e2bbf00a1e916addbe84bcdbeb3c94527ee6c5 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 10:49:57 -0800 Subject: [PATCH 44/63] AndroidGetDataStart -> GetData --- src/coreclr/vm/peimage.cpp | 2 +- src/coreclr/vm/peimage.h | 2 +- src/coreclr/vm/peimage.inl | 16 ++++++++++------ src/coreclr/vm/peimagelayout.cpp | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/coreclr/vm/peimage.cpp b/src/coreclr/vm/peimage.cpp index 1b228699b1a1ad..f84ee8ace6e450 100644 --- a/src/coreclr/vm/peimage.cpp +++ b/src/coreclr/vm/peimage.cpp @@ -877,7 +877,7 @@ HRESULT PEImage::TryOpenFile(bool takeLock) ErrorModeHolder mode{}; #if defined(TARGET_ANDROID) - m_hFile = AndroidGetDataStart (); + m_hFile = GetData(nullptr); #else m_hFile=WszCreateFile((LPCWSTR)GetPathToLoad(), GENERIC_READ diff --git a/src/coreclr/vm/peimage.h b/src/coreclr/vm/peimage.h index 8bd0e85c6b2f2e..90727774690211 100644 --- a/src/coreclr/vm/peimage.h +++ b/src/coreclr/vm/peimage.h @@ -134,7 +134,6 @@ class PEImage final const SString& GetPath(); #if defined(TARGET_ANDROID) - const HANDLE AndroidGetDataStart(); const SString& AndroidGetAppName(); #else const SString& GetPathToLoad(); @@ -143,6 +142,7 @@ class PEImage final BOOL IsFile(); BOOL IsInBundle() const; + void* GetData(INT64* size); INT64 GetOffset() const; INT64 GetSize() const; INT64 GetUncompressedSize() const; diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index 54d8ffc38fca34..03a87bc51b775b 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -33,12 +33,6 @@ inline const SString &PEImage::GetPath() } #if defined(TARGET_ANDROID) -inline const HANDLE PEImage::AndroidGetDataStart() -{ - LIMITED_METHOD_CONTRACT; - return m_bundleFileLocation.DataStart; -} - inline const SString& PEImage::AndroidGetAppName() { return m_bundleFileLocation.AppName(); @@ -52,6 +46,16 @@ inline const SString& PEImage::GetPathToLoad() } #endif // !TARGET_ANDROID +inline void* PEImage::GetData(INT64* size) +{ + LIMITED_METHOD_CONTRACT; + + if (size != nullptr) + *size = m_bundleFileLocation.Size; + + return m_bundleFileLocation.DataStart; +} + inline INT64 PEImage::GetOffset() const { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index 7f01500ee6fccb..f2a96ce51f7157 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -636,8 +636,8 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) } } #else // !TARGET_ANDROID - INT64 size = pOwner->GetSize(); - HANDLE mapBegin = pOwner->AndroidGetDataStart(); + INT64 size; + void* mapBegin = pOwner->GetData(&size); if (size == 0 || mapBegin == nullptr) { // TODO: throw something } From cf72fbedf78733ad13ce69185c256eff41bcbceb Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 11:26:00 -0800 Subject: [PATCH 45/63] Don't try to manage external assembly not mapped by the runtime --- src/coreclr/vm/peimagelayout.cpp | 34 +++++++++++++++----------------- src/coreclr/vm/peimagelayout.h | 10 ++++++---- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index f2a96ce51f7157..f89f2ef996f3ee 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -616,16 +616,26 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) PRECONDITION(CheckPointer(pOwner)); } CONTRACTL_END; - m_pOwner=pOwner; -#if !defined(TARGET_ANDROID) - HANDLE hFile = pOwner->GetFileHandle(); - INT64 offset = pOwner->GetOffset(); - INT64 size = pOwner->GetSize(); + m_pOwner = pOwner; + #ifdef LOGGING SString ownerPath{ pOwner->GetPath() }; LOG((LF_LOADER, LL_INFO100, "PEImage: Opening flat %s\n", ownerPath.GetUTF8())); #endif // LOGGING +// TODO: Any image from external_assembly_probe should go down this path, not just on Android +#if defined(TARGET_ANDROID) + INT64 dataSize; + void* data = pOwner->GetData(&dataSize); + _ASSERTE(dataSize != 0 && data != nullptr); + Init(data, (COUNT_T)dataSize); + return; +#endif + + HANDLE hFile = pOwner->GetFileHandle(); + INT64 offset = pOwner->GetOffset(); + INT64 size = pOwner->GetSize(); + // If a size is not specified, load the whole file if (size == 0) { @@ -635,19 +645,12 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) ThrowLastError(); } } -#else // !TARGET_ANDROID - INT64 size; - void* mapBegin = pOwner->GetData(&size); - if (size == 0 || mapBegin == nullptr) { - // TODO: throw something - } -#endif // TARGET_ANDROID + LPVOID addr = 0; // It's okay if resource files are length zero if (size > 0) { -#if !defined(TARGET_ANDROID) INT64 uncompressedSize = pOwner->GetUncompressedSize(); DWORD mapAccess = PAGE_READONLY; @@ -731,11 +734,6 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) ThrowHR(E_FAIL); // we don't have any indication of what kind of failure. Possibly a corrupt image. #endif } -#else // !TARGET_ANDROID - m_FileMap.Assign(mapBegin); - m_FileView.Assign(mapBegin); - addr = (LPVOID)mapBegin; -#endif // TARGET_ANDROID } Init(addr, (COUNT_T)size); diff --git a/src/coreclr/vm/peimagelayout.h b/src/coreclr/vm/peimagelayout.h index 64afafba136a3d..8f92e00ded16a1 100644 --- a/src/coreclr/vm/peimagelayout.h +++ b/src/coreclr/vm/peimagelayout.h @@ -81,11 +81,7 @@ class FlatImageLayout : public PEImageLayout { VPTR_VTABLE_CLASS(FlatImageLayout, PEImageLayout) VPTR_UNIQUE(0x59) -protected: - CLRMapViewHolder m_FileView; public: - HandleHolder m_FileMap; - #ifndef DACCESS_COMPILE FlatImageLayout(PEImage* pOwner); FlatImageLayout(PEImage* pOwner, const BYTE* array, COUNT_T size); @@ -94,6 +90,12 @@ class FlatImageLayout : public PEImageLayout void* LoadImageByMappingParts(SIZE_T* m_imageParts) const; #endif #endif + +private: + // Handles for the mapped image. + // These will be null if the image data is not mapped by the runtime (for example, provided via an external assembly probe). + CLRMapViewHolder m_FileView; + HandleHolder m_FileMap; }; // ConvertedImageView is for the case when we construct a loaded From f286e150855fe26a2eed1ca3104fb757afe062cb Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 11:29:44 -0800 Subject: [PATCH 46/63] Remove newline-only changes --- src/coreclr/dlls/mscordac/mscordac.cpp | 2 +- src/coreclr/dlls/mscordbi/CMakeLists.txt | 1 - src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt | 1 - src/coreclr/dlls/mscoree/exports.cpp | 1 + 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreclr/dlls/mscordac/mscordac.cpp b/src/coreclr/dlls/mscordac/mscordac.cpp index b3c2ea2f326938..53616c2269615b 100644 --- a/src/coreclr/dlls/mscordac/mscordac.cpp +++ b/src/coreclr/dlls/mscordac/mscordac.cpp @@ -1,2 +1,2 @@ // Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. \ No newline at end of file +// The .NET Foundation licenses this file to you under the MIT license. diff --git a/src/coreclr/dlls/mscordbi/CMakeLists.txt b/src/coreclr/dlls/mscordbi/CMakeLists.txt index 9fdc94dfa1f3f6..87e566175a25c0 100644 --- a/src/coreclr/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/dlls/mscordbi/CMakeLists.txt @@ -122,7 +122,6 @@ elseif(CLR_CMAKE_HOST_UNIX) # find all symbols. target_link_libraries(mscordbi PRIVATE ${COREDBI_LIBRARIES} ${COREDBI_LIBRARIES}) - add_dependencies(mscordbi mscordaccore) if(CLR_CMAKE_HOST_LINUX) diff --git a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt index b6cf126b1be7d2..4b7d533bb19ea5 100644 --- a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt @@ -187,7 +187,6 @@ endif() target_sources(coreclr PUBLIC $) target_link_libraries(coreclr PUBLIC ${CORECLR_LIBRARIES} ${CLRJIT_STATIC} cee_wks ${FOUNDATION}) - target_sources(coreclr_static PUBLIC $) target_link_libraries(coreclr_static PUBLIC ${CORECLR_LIBRARIES} clrjit_static cee_wks_mergeable ${FOUNDATION}) target_compile_definitions(coreclr_static PUBLIC CORECLR_EMBEDDED) diff --git a/src/coreclr/dlls/mscoree/exports.cpp b/src/coreclr/dlls/mscoree/exports.cpp index 473bedf1b94815..dc31e2e2ef995c 100644 --- a/src/coreclr/dlls/mscoree/exports.cpp +++ b/src/coreclr/dlls/mscoree/exports.cpp @@ -188,6 +188,7 @@ static void ConvertConfigPropertiesToUnicode( *propertyKeysWRef = propertyKeysW; *propertyValuesWRef = propertyValuesW; } + coreclr_error_writer_callback_fn g_errorWriter = nullptr; // From 1533d9fc499ba70d260fd7048375ba37e939141d Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 11:44:59 -0800 Subject: [PATCH 47/63] Explicitly check / document checking return value of probes --- src/coreclr/vm/bundle.cpp | 55 ++++++++++----------- src/native/corehost/host_runtime_contract.h | 7 +-- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/coreclr/vm/bundle.cpp b/src/coreclr/vm/bundle.cpp index ebe8a94dc47fef..314ab2f5d927bc 100644 --- a/src/coreclr/vm/bundle.cpp +++ b/src/coreclr/vm/bundle.cpp @@ -68,8 +68,6 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) { STANDARD_VM_CONTRACT; - BundleFileLocation loc; - // Skip over m_base_path, if any. For example: // Bundle.Probe("lib.dll") => m_probe("lib.dll") // Bundle.Probe("path/to/exe/lib.dll") => m_probe("lib.dll") @@ -99,43 +97,44 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) else { // This is not a file within the bundle - return loc; + return BundleFileLocation::Invalid(); } } #endif // !TARGET_ANDROID - INT64 fileSize = 0; - INT64 compressedSize = 0; - bool assemblyFound = false; - if (m_probe != nullptr) { - assemblyFound = m_probe(utf8Path, &loc.Offset, &fileSize, &compressedSize); - loc.DataStart = nullptr; // Location is based on the bundle file start - } - - if (!assemblyFound && m_externalAssemblyProbe != nullptr) - { - m_externalAssemblyProbe (utf8Path, &loc.DataStart, &fileSize); - - // Host takes care of decompression, if any - compressedSize = 0; + BundleFileLocation loc; + INT64 fileSize = 0; + INT64 compressedSize = 0; + if (m_probe(utf8Path, &loc.Offset, &fileSize, &compressedSize)) + { + // Found assembly in bundle + if (compressedSize) + { + loc.Size = compressedSize; + loc.UncompresedSize = fileSize; + } + else + { + loc.Size = fileSize; + loc.UncompresedSize = 0; + } - // Must always be 0 in this mode, since loc.DataStart points to the beginning of data - loc.Offset = 0; + return loc; + } } - if (compressedSize) - { - loc.Size = compressedSize; - loc.UncompresedSize = fileSize; - } - else + if (m_externalAssemblyProbe != nullptr) { - loc.Size = fileSize; - loc.UncompresedSize = 0; + BundleFileLocation loc; + if (m_externalAssemblyProbe(utf8Path, &loc.DataStart, &loc.Size)) + { + // Found via external assembly probe + return loc; + } } - return loc; + return BundleFileLocation::Invalid(); } BundleFileLocation Bundle::ProbeAppBundle(const SString& path, bool pathIsBundleRelative) diff --git a/src/native/corehost/host_runtime_contract.h b/src/native/corehost/host_runtime_contract.h index 1aaf2212ccfad1..9d03c52cf24bf0 100644 --- a/src/native/corehost/host_runtime_contract.h +++ b/src/native/corehost/host_runtime_contract.h @@ -39,7 +39,7 @@ struct host_runtime_contract void* contract_context); // Probe an app bundle for `path`. Sets its location (`offset`, `size`) in the bundle if found. - // Returns true if found, false otherwise. + // Returns true if found, false otherwise. If false, out parameter values are ignored by the runtime. bool(HOST_CONTRACT_CALLTYPE* bundle_probe)( const char* path, /*out*/ int64_t* offset, @@ -53,10 +53,11 @@ struct host_runtime_contract const char* entry_point_name); // Probe the host for `path`. Sets pointer to data start and its size, if found. + // Returns true if found, false otherwise. If false, out parameter values are ignored by the runtime. bool(HOST_CONTRACT_CALLTYPE* external_assembly_probe)( const char* path, - void **data_start, - int64_t* size); + /*out*/ void **data_start, + /*out*/ int64_t* size); }; #endif // __HOST_RUNTIME_CONTRACT_H__ From 1cdb0ce98fd21b2e2c7962fc97fe6f0754106f34 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 11:54:10 -0800 Subject: [PATCH 48/63] Check for non-file data instead of assuming that is the case on Android --- src/coreclr/vm/peimagelayout.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index f89f2ef996f3ee..3f634712331184 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -623,14 +623,19 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) LOG((LF_LOADER, LL_INFO100, "PEImage: Opening flat %s\n", ownerPath.GetUTF8())); #endif // LOGGING -// TODO: Any image from external_assembly_probe should go down this path, not just on Android -#if defined(TARGET_ANDROID) - INT64 dataSize; - void* data = pOwner->GetData(&dataSize); - _ASSERTE(dataSize != 0 && data != nullptr); - Init(data, (COUNT_T)dataSize); - return; -#endif + if (!pOwner->IsFile()) + { + INT64 dataSize; + void* data = pOwner->GetData(&dataSize); + if (data != nullptr) + { + // Image was provided as flat data via external assembly probing. + // We do not manage the data - just initialize with it directly. + _ASSERTE(dataSize != 0); + Init(data, (COUNT_T)dataSize); + return; + } + } HANDLE hFile = pOwner->GetFileHandle(); INT64 offset = pOwner->GetOffset(); From 5a97afff610568fe51ace47f0f0a3fec721bf24c Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 12:17:59 -0800 Subject: [PATCH 49/63] Remove unnecessary check --- src/coreclr/vm/peimagelayout.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index 3f634712331184..d9eba3e8dee317 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -623,18 +623,15 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) LOG((LF_LOADER, LL_INFO100, "PEImage: Opening flat %s\n", ownerPath.GetUTF8())); #endif // LOGGING - if (!pOwner->IsFile()) + INT64 dataSize; + void* data = pOwner->GetData(&dataSize); + if (data != nullptr) { - INT64 dataSize; - void* data = pOwner->GetData(&dataSize); - if (data != nullptr) - { - // Image was provided as flat data via external assembly probing. - // We do not manage the data - just initialize with it directly. - _ASSERTE(dataSize != 0); - Init(data, (COUNT_T)dataSize); - return; - } + // Image was provided as flat data via external assembly probing. + // We do not manage the data - just initialize with it directly. + _ASSERTE(dataSize != 0); + Init(data, (COUNT_T)dataSize); + return; } HANDLE hFile = pOwner->GetFileHandle(); From 885d1175968b52b1393a8cf44c17f210ce59ed35 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 13:12:34 -0800 Subject: [PATCH 50/63] Don't set file handle for non-file data --- src/coreclr/vm/coreassemblyspec.cpp | 9 ++++++--- src/coreclr/vm/peimage.cpp | 10 ++++------ src/coreclr/vm/peimage.h | 3 +-- src/coreclr/vm/peimage.inl | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index 886df7e4afbe5d..a6b5f9752374b0 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -89,10 +89,13 @@ STDAPI BinderAcquirePEImage(LPCWSTR wszAssemblyPath, PEImageHolder pImage = PEImage::OpenImage(wszAssemblyPath, MDInternalImport_Default, bundleFileLocation); // Make sure that the IL image can be opened. - hr=pImage->TryOpenFile(); - if (FAILED(hr)) + if (pImage->IsFile()) { - goto Exit; + hr = pImage->TryOpenFile(); + if (FAILED(hr)) + { + goto Exit; + } } if (pImage) diff --git a/src/coreclr/vm/peimage.cpp b/src/coreclr/vm/peimage.cpp index f84ee8ace6e450..844a19cc6742e3 100644 --- a/src/coreclr/vm/peimage.cpp +++ b/src/coreclr/vm/peimage.cpp @@ -870,16 +870,15 @@ HRESULT PEImage::TryOpenFile(bool takeLock) { STANDARD_VM_CONTRACT; + _ASSERTE(IsFile()); + SimpleWriteLockHolder lock(m_pLayoutLock, takeLock); - if (m_hFile!=INVALID_HANDLE_VALUE) + if (m_hFile != INVALID_HANDLE_VALUE) return S_OK; ErrorModeHolder mode{}; -#if defined(TARGET_ANDROID) - m_hFile = GetData(nullptr); -#else - m_hFile=WszCreateFile((LPCWSTR)GetPathToLoad(), + m_hFile = WszCreateFile((LPCWSTR)GetPathToLoad(), GENERIC_READ #if TARGET_WINDOWS // the file may have native code sections, make sure we are allowed to execute the file @@ -891,7 +890,6 @@ HRESULT PEImage::TryOpenFile(bool takeLock) OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -#endif // TARGET_ANDROID if (m_hFile != INVALID_HANDLE_VALUE) return S_OK; diff --git a/src/coreclr/vm/peimage.h b/src/coreclr/vm/peimage.h index 90727774690211..aff93945b11a28 100644 --- a/src/coreclr/vm/peimage.h +++ b/src/coreclr/vm/peimage.h @@ -133,10 +133,9 @@ class PEImage final PTR_PEImageLayout GetFlatLayout(); const SString& GetPath(); + const SString& GetPathToLoad(); #if defined(TARGET_ANDROID) const SString& AndroidGetAppName(); -#else - const SString& GetPathToLoad(); #endif LPCWSTR GetPathForErrorMessages() { return GetPath(); } diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index 03a87bc51b775b..8f352344ace4f0 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -37,14 +37,14 @@ inline const SString& PEImage::AndroidGetAppName() { return m_bundleFileLocation.AppName(); } -#else +#endif // !TARGET_ANDROID + inline const SString& PEImage::GetPathToLoad() { LIMITED_METHOD_DAC_CONTRACT; return IsInBundle() ? m_bundleFileLocation.Path() : m_path; } -#endif // !TARGET_ANDROID inline void* PEImage::GetData(INT64* size) { From 54ad33ca9e6161d9455332bc6674cebb72be367a Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 13:18:37 -0800 Subject: [PATCH 51/63] Check for null data instead of always returns FALSE for PEImage::IsFile on Android --- src/coreclr/vm/peimage.inl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index 8f352344ace4f0..72637319c3fa5b 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -115,11 +115,7 @@ inline const SString &PEImage::GetModuleFileNameHintForDAC() inline BOOL PEImage::IsFile() { WRAPPER_NO_CONTRACT; -#if defined(TARGET_ANDROID) - return FALSE; -#else - return !GetPathToLoad().IsEmpty(); -#endif + return m_bundleFileLocation.DataStart == nullptr && !GetPathToLoad().IsEmpty(); } // From 2821e75c7c98a1d17a17b90d722f8ca6584cdd81 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 13:22:25 -0800 Subject: [PATCH 52/63] GetData -> GetExternalData --- src/coreclr/vm/peimage.h | 2 +- src/coreclr/vm/peimage.inl | 2 +- src/coreclr/vm/peimagelayout.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/vm/peimage.h b/src/coreclr/vm/peimage.h index aff93945b11a28..57aec628314e3b 100644 --- a/src/coreclr/vm/peimage.h +++ b/src/coreclr/vm/peimage.h @@ -141,7 +141,7 @@ class PEImage final BOOL IsFile(); BOOL IsInBundle() const; - void* GetData(INT64* size); + void* GetExternalData(INT64* size); INT64 GetOffset() const; INT64 GetSize() const; INT64 GetUncompressedSize() const; diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index 72637319c3fa5b..63db5de957d9c9 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -46,7 +46,7 @@ inline const SString& PEImage::GetPathToLoad() return IsInBundle() ? m_bundleFileLocation.Path() : m_path; } -inline void* PEImage::GetData(INT64* size) +inline void* PEImage::GetExternalData(INT64* size) { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/peimagelayout.cpp b/src/coreclr/vm/peimagelayout.cpp index d9eba3e8dee317..8d5f02b2671ebd 100644 --- a/src/coreclr/vm/peimagelayout.cpp +++ b/src/coreclr/vm/peimagelayout.cpp @@ -624,7 +624,7 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner) #endif // LOGGING INT64 dataSize; - void* data = pOwner->GetData(&dataSize); + void* data = pOwner->GetExternalData(&dataSize); if (data != nullptr) { // Image was provided as flat data via external assembly probing. From ff9021d1af0c02c43d20eff4433b2e4d93d212ce Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 13:24:24 -0800 Subject: [PATCH 53/63] Remove AndroidGetAppName --- src/coreclr/vm/peimage.cpp | 4 ---- src/coreclr/vm/peimage.h | 3 --- src/coreclr/vm/peimage.inl | 7 ------- 3 files changed, 14 deletions(-) diff --git a/src/coreclr/vm/peimage.cpp b/src/coreclr/vm/peimage.cpp index 844a19cc6742e3..0677c02535d4c2 100644 --- a/src/coreclr/vm/peimage.cpp +++ b/src/coreclr/vm/peimage.cpp @@ -851,11 +851,7 @@ HANDLE PEImage::GetFileHandle() { #if !defined(DACCESS_COMPILE) EEFileLoadException::Throw( -#if defined(TARGET_ANDROID) - AndroidGetAppName(), -#else GetPathToLoad(), -#endif hr ); #else // defined(DACCESS_COMPILE) diff --git a/src/coreclr/vm/peimage.h b/src/coreclr/vm/peimage.h index 57aec628314e3b..5711a83e6d7264 100644 --- a/src/coreclr/vm/peimage.h +++ b/src/coreclr/vm/peimage.h @@ -134,9 +134,6 @@ class PEImage final const SString& GetPath(); const SString& GetPathToLoad(); -#if defined(TARGET_ANDROID) - const SString& AndroidGetAppName(); -#endif LPCWSTR GetPathForErrorMessages() { return GetPath(); } BOOL IsFile(); diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index 63db5de957d9c9..3ff85df15769b1 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -32,13 +32,6 @@ inline const SString &PEImage::GetPath() return m_path; } -#if defined(TARGET_ANDROID) -inline const SString& PEImage::AndroidGetAppName() -{ - return m_bundleFileLocation.AppName(); -} -#endif // !TARGET_ANDROID - inline const SString& PEImage::GetPathToLoad() { LIMITED_METHOD_DAC_CONTRACT; From 38c63769aeb3f43c9226e96d9b1c9f9870e8361c Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 13:35:26 -0800 Subject: [PATCH 54/63] Remove BundleFileLocation::AppName --- src/coreclr/inc/bundle.h | 8 ++------ src/coreclr/vm/bundle.cpp | 12 ------------ 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/coreclr/inc/bundle.h b/src/coreclr/inc/bundle.h index 69ebfc3625b74b..4b9100e25f3135 100644 --- a/src/coreclr/inc/bundle.h +++ b/src/coreclr/inc/bundle.h @@ -35,12 +35,8 @@ struct BundleFileLocation static BundleFileLocation Invalid() { LIMITED_METHOD_CONTRACT; return BundleFileLocation(); } const SString &Path() const; -#if defined(TARGET_ANDROID) - const SString &AppName() const; - bool IsValid() const { LIMITED_METHOD_CONTRACT; return DataStart != nullptr; } -#else // TARGET_ANDROID - bool IsValid() const { LIMITED_METHOD_CONTRACT; return Offset != 0; } -#endif // !TARGET_ANDROID + + bool IsValid() const { LIMITED_METHOD_CONTRACT; return DataStart != nullptr || Offset != 0; } }; class Bundle diff --git a/src/coreclr/vm/bundle.cpp b/src/coreclr/vm/bundle.cpp index 314ab2f5d927bc..2f44f6e2575e6d 100644 --- a/src/coreclr/vm/bundle.cpp +++ b/src/coreclr/vm/bundle.cpp @@ -30,18 +30,6 @@ const SString &BundleFileLocation::Path() const return Bundle::AppBundle->Path(); } -#if defined(TARGET_ANDROID) -const SString &BundleFileLocation::AppName() const -{ - LIMITED_METHOD_CONTRACT; - - _ASSERTE(IsValid()); - _ASSERTE(Bundle::AppBundle != nullptr); - - return Bundle::AppBundle->Path(); -} -#endif - Bundle::Bundle(LPCSTR bundlePath, BundleProbeFn *probe, ExternalAssemblyProbeFn* externalAssemblyProbe) { STANDARD_VM_CONTRACT; From 8c60c1a80dda09b7ec2ee3f2da8ede25e67a7be7 Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Fri, 21 Feb 2025 18:02:55 -0800 Subject: [PATCH 55/63] Remove LogToAndroid. Scenario should now use LogToConsole. Minor nits. --- src/coreclr/inc/bundle.h | 2 +- src/coreclr/inc/clrconfigvalues.h | 1 - src/coreclr/pal/src/thread/process.cpp | 7 ++++--- src/coreclr/utilcode/log.cpp | 18 ++++++------------ src/coreclr/vm/bundle.cpp | 7 ++++--- src/coreclr/vm/peimage.inl | 4 ++-- src/coreclr/vm/util.cpp | 7 +++---- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/coreclr/inc/bundle.h b/src/coreclr/inc/bundle.h index 4b9100e25f3135..6384ec6c1ec7e1 100644 --- a/src/coreclr/inc/bundle.h +++ b/src/coreclr/inc/bundle.h @@ -58,7 +58,7 @@ class Bundle ExternalAssemblyProbeFn *m_externalAssemblyProbe; SString m_basePath; // The prefix to denote a path within the bundle - COUNT_T m_basePathLength = 0; + COUNT_T m_basePathLength; }; #endif // _BUNDLE_H_ diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index 6b94606faa727b..ffc68923d7ddc9 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -383,7 +383,6 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_LogToConsole, W("LogToConsole"), 0 , "Writes t CONFIG_DWORD_INFO(INTERNAL_LogToDebugger, W("LogToDebugger"), 0 , "Writes the CLR log to debugger (OutputDebugStringA).") CONFIG_DWORD_INFO(INTERNAL_LogToFile, W("LogToFile"), 0 , "Writes the CLR log to a file.") CONFIG_DWORD_INFO(INTERNAL_LogWithPid, W("LogWithPid"), FALSE, "Appends pid to filename for the CLR log.") -CONFIG_DWORD_INFO(INTERNAL_LogToAndroid, W("LogToAndroid"), 0 , "Writes the CLR log to android logcat") /// /// MetaData diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 10431818c00045..4dc377648608b6 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -73,7 +73,7 @@ SET_DEFAULT_DEBUG_CHANNEL(PROCESS); // some headers have code with asserts, so d #if defined(TARGET_ANDROID) #include -#endif +#endif // defined(TARGET_ANDROID) #ifdef __APPLE__ #include @@ -2549,10 +2549,11 @@ PROCAbort(int signal, siginfo_t* siginfo) // the others to prevent multiple core dumps from being generated. SEHCleanupSignals(false /* isChildProcess */); - // Abort the process after waiting for the core dump to complete #if defined(TARGET_ANDROID) __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "Aborting in %s:%u", __FILE_NAME__, __LINE__); -#endif +#endif // defined(TARGET_ANDROID) + + // Abort the process after waiting for the core dump to complete abort(); } diff --git a/src/coreclr/utilcode/log.cpp b/src/coreclr/utilcode/log.cpp index 9d21aab9253215..7fe1a03bce3141 100644 --- a/src/coreclr/utilcode/log.cpp +++ b/src/coreclr/utilcode/log.cpp @@ -32,7 +32,6 @@ #define LOG_ENABLE_APPEND_FILE 0x0010 #define LOG_ENABLE_DEBUGGER_LOGGING 0x0020 #define LOG_ENABLE 0x0040 -#define LOG_ENABLE_ANDROID_LOGGING 0x0080 static DWORD LogFlags = 0; static CQuickWSTR szLogFileName; @@ -59,7 +58,6 @@ VOID InitLogging() LogFlags |= (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogToDebugger) != 0) ? LOG_ENABLE_DEBUGGER_LOGGING : 0; LogFlags |= (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogToFile) != 0) ? LOG_ENABLE_FILE_LOGGING : 0; LogFlags |= (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogToConsole) != 0) ? LOG_ENABLE_CONSOLE_LOGGING : 0; - LogFlags |= (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogToAndroid) != 0) ? LOG_ENABLE_ANDROID_LOGGING : 0; LogFacilityMask2 = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogFacility2, LogFacilityMask2) | LF_ALWAYS; @@ -377,10 +375,16 @@ VOID LogSpewAlwaysValist(const char *fmt, va_list args) if (LogFlags & LOG_ENABLE_CONSOLE_LOGGING) { +#if !defined(TARGET_ANDROID) WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), pBuffer, buflen, &written, 0); //@TODO ...Unnecessary to flush console? if (LogFlags & LOG_ENABLE_FLUSH_FILE) FlushFileBuffers( GetStdHandle(STD_OUTPUT_HANDLE) ); +#else + // TODO: priority should be configurable here (best, passed via a parameter) + // likewise for the tag + __android_log_write(ANDROID_LOG_INFO, "CoreCLR-log", pBuffer); +#endif // defined(TARGET_ANDROID) } if (LogFlags & LOG_ENABLE_DEBUGGER_LOGGING) @@ -388,16 +392,6 @@ VOID LogSpewAlwaysValist(const char *fmt, va_list args) OutputDebugStringA(pBuffer); } -#if defined(TARGET_ANDROID) - __android_log_write (ANDROID_LOG_INFO, "CoreCLR-log", "This should be logged"); - if (LogFlags & LOG_ENABLE_ANDROID_LOGGING) - { - // TODO: priority should be configurable here (best, passed via a parameter) - // likewise for the tag - __android_log_write (ANDROID_LOG_INFO, "CoreCLR-log", pBuffer); - } -#endif // TARGET_ANDROID - LeaveLogLock(); } diff --git a/src/coreclr/vm/bundle.cpp b/src/coreclr/vm/bundle.cpp index 2f44f6e2575e6d..72946fd9b0fb0e 100644 --- a/src/coreclr/vm/bundle.cpp +++ b/src/coreclr/vm/bundle.cpp @@ -31,12 +31,13 @@ const SString &BundleFileLocation::Path() const } Bundle::Bundle(LPCSTR bundlePath, BundleProbeFn *probe, ExternalAssemblyProbeFn* externalAssemblyProbe) + : m_probe(probe) + , m_externalAssemblyProbe(externalAssemblyProbe) + , m_basePathLength(0) { STANDARD_VM_CONTRACT; - _ASSERTE(probe != nullptr || externalAssemblyProbe != nullptr); - m_probe = probe; - m_externalAssemblyProbe = externalAssemblyProbe; + _ASSERTE(m_probe != nullptr || m_externalAssemblyProbe != nullptr); // On Android this is not a real path, but rather the application's package name m_path.SetUTF8(bundlePath); diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index 3ff85df15769b1..57196222215cf1 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -43,9 +43,9 @@ inline void* PEImage::GetExternalData(INT64* size) { LIMITED_METHOD_CONTRACT; - if (size != nullptr) - *size = m_bundleFileLocation.Size; + _ASSERTE(size != nullptr); + *size = m_bundleFileLocation.Size; return m_bundleFileLocation.DataStart; } diff --git a/src/coreclr/vm/util.cpp b/src/coreclr/vm/util.cpp index fb93eb8e0fdb1b..15f06a5b98bb76 100644 --- a/src/coreclr/vm/util.cpp +++ b/src/coreclr/vm/util.cpp @@ -17,7 +17,7 @@ #if defined(TARGET_ANDROID) #include -#endif +#endif // defined(TARGET_ANDROID) thread_local size_t t_ThreadType; @@ -180,15 +180,14 @@ void PrintToStdErrA(const char *pszString) { } CONTRACTL_END - HANDLE Handle = GetStdHandle(STD_ERROR_HANDLE); - #if defined(TARGET_ANDROID) // TODO: make priority configurable? __android_log_write(ANDROID_LOG_INFO, "CoreCLR", pszString); #else + HANDLE Handle = GetStdHandle(STD_ERROR_HANDLE); size_t len = strlen(pszString); NPrintToHandleA(Handle, pszString, len); -#endif +#endif // defined(TARGET_ANDROID) } void PrintToStdErrW(const WCHAR *pwzString) From 57553d4b1ac3e281502e9c7fd1271e151b76ff02 Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Fri, 21 Feb 2025 19:02:04 -0800 Subject: [PATCH 56/63] Feedback --- src/coreclr/pal/src/thread/process.cpp | 2 +- src/coreclr/utilcode/log.cpp | 2 +- src/coreclr/vm/util.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 4dc377648608b6..b3b7b812731123 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -2550,7 +2550,7 @@ PROCAbort(int signal, siginfo_t* siginfo) SEHCleanupSignals(false /* isChildProcess */); #if defined(TARGET_ANDROID) - __android_log_print (ANDROID_LOG_INFO, "CoreCLR", "Aborting in %s:%u", __FILE_NAME__, __LINE__); + __android_log_print(ANDROID_LOG_FATAL, MAIN_CLR_MODULE_NAME_A, "Aborting in %s:%u", __FILE_NAME__, __LINE__); #endif // defined(TARGET_ANDROID) // Abort the process after waiting for the core dump to complete diff --git a/src/coreclr/utilcode/log.cpp b/src/coreclr/utilcode/log.cpp index 7fe1a03bce3141..23611fcda0a36e 100644 --- a/src/coreclr/utilcode/log.cpp +++ b/src/coreclr/utilcode/log.cpp @@ -383,7 +383,7 @@ VOID LogSpewAlwaysValist(const char *fmt, va_list args) #else // TODO: priority should be configurable here (best, passed via a parameter) // likewise for the tag - __android_log_write(ANDROID_LOG_INFO, "CoreCLR-log", pBuffer); + __android_log_write(ANDROID_LOG_INFO, MAIN_CLR_MODULE_NAME_A, pBuffer); #endif // defined(TARGET_ANDROID) } diff --git a/src/coreclr/vm/util.cpp b/src/coreclr/vm/util.cpp index 15f06a5b98bb76..9c3862bff0a96a 100644 --- a/src/coreclr/vm/util.cpp +++ b/src/coreclr/vm/util.cpp @@ -182,7 +182,7 @@ void PrintToStdErrA(const char *pszString) { #if defined(TARGET_ANDROID) // TODO: make priority configurable? - __android_log_write(ANDROID_LOG_INFO, "CoreCLR", pszString); + __android_log_write(ANDROID_LOG_ERROR, MAIN_CLR_MODULE_NAME_A, pszString); #else HANDLE Handle = GetStdHandle(STD_ERROR_HANDLE); size_t len = strlen(pszString); From dfc64dbf89677546ad90bc573da4962986ea778b Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Fri, 21 Feb 2025 21:31:35 -0800 Subject: [PATCH 57/63] Fix the build --- src/coreclr/dlls/mscordbi/CMakeLists.txt | 6 ++++++ src/coreclr/pal/src/thread/process.cpp | 4 +++- src/coreclr/utilcode/log.cpp | 12 ++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/coreclr/dlls/mscordbi/CMakeLists.txt b/src/coreclr/dlls/mscordbi/CMakeLists.txt index 87e566175a25c0..86a3defd6ac7df 100644 --- a/src/coreclr/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/dlls/mscordbi/CMakeLists.txt @@ -106,6 +106,12 @@ elseif(CLR_CMAKE_HOST_UNIX) ) endif(CLR_CMAKE_HOST_HAIKU) + if(CLR_CMAKE_TARGET_ANDROID) + list(APPEND COREDBI_LIBRARIES + log + ) + endif(CLR_CMAKE_TARGET_ANDROID) + # Before llvm 16, lld was setting `--undefined-version` by default. The default was # flipped to `--no-undefined-version` in lld 16, so we will explicitly set it to # `--undefined-version` for our use-case. diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index b3b7b812731123..a662b7e989471f 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -2550,7 +2550,9 @@ PROCAbort(int signal, siginfo_t* siginfo) SEHCleanupSignals(false /* isChildProcess */); #if defined(TARGET_ANDROID) - __android_log_print(ANDROID_LOG_FATAL, MAIN_CLR_MODULE_NAME_A, "Aborting in %s:%u", __FILE_NAME__, __LINE__); + // Ideally, MAIN_CLR_MODULE_NAME_A would be used, but cor.h can't + // currently be included in the pal. + __android_log_print(ANDROID_LOG_FATAL, "coreclr", "Aborting in %s:%u", __FILE_NAME__, __LINE__); #endif // defined(TARGET_ANDROID) // Abort the process after waiting for the core dump to complete diff --git a/src/coreclr/utilcode/log.cpp b/src/coreclr/utilcode/log.cpp index 23611fcda0a36e..9c24ecca944ab9 100644 --- a/src/coreclr/utilcode/log.cpp +++ b/src/coreclr/utilcode/log.cpp @@ -20,7 +20,7 @@ #if defined(TARGET_ANDROID) #include -#endif +#endif // defined(TARGET_ANDROID) #ifdef LOGGING @@ -375,15 +375,15 @@ VOID LogSpewAlwaysValist(const char *fmt, va_list args) if (LogFlags & LOG_ENABLE_CONSOLE_LOGGING) { -#if !defined(TARGET_ANDROID) +#if defined(TARGET_ANDROID) + // TODO: priority should be configurable here (best, passed via a parameter) + // likewise for the tag + __android_log_write(ANDROID_LOG_INFO, MAIN_CLR_MODULE_NAME_A, pBuffer); +#else WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), pBuffer, buflen, &written, 0); //@TODO ...Unnecessary to flush console? if (LogFlags & LOG_ENABLE_FLUSH_FILE) FlushFileBuffers( GetStdHandle(STD_OUTPUT_HANDLE) ); -#else - // TODO: priority should be configurable here (best, passed via a parameter) - // likewise for the tag - __android_log_write(ANDROID_LOG_INFO, MAIN_CLR_MODULE_NAME_A, pBuffer); #endif // defined(TARGET_ANDROID) } From 656a6fda77578f5a519ab7c4fd10df0481831ffc Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Fri, 21 Feb 2025 21:42:45 -0800 Subject: [PATCH 58/63] Update src/coreclr/vm/peimage.cpp Co-authored-by: Jan Kotas --- src/coreclr/vm/peimage.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/coreclr/vm/peimage.cpp b/src/coreclr/vm/peimage.cpp index 0677c02535d4c2..24431e41830c92 100644 --- a/src/coreclr/vm/peimage.cpp +++ b/src/coreclr/vm/peimage.cpp @@ -850,10 +850,7 @@ HANDLE PEImage::GetFileHandle() if (m_hFile == INVALID_HANDLE_VALUE) { #if !defined(DACCESS_COMPILE) - EEFileLoadException::Throw( - GetPathToLoad(), - hr - ); + EEFileLoadException::Throw(GetPathToLoad(), hr); #else // defined(DACCESS_COMPILE) ThrowHR(hr); #endif // !defined(DACCESS_COMPILE) From d890acc051101733f6e879fc28fd2db48c8cd214 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 21 Feb 2025 22:15:15 -0800 Subject: [PATCH 59/63] Update src/coreclr/vm/util.cpp --- src/coreclr/vm/util.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreclr/vm/util.cpp b/src/coreclr/vm/util.cpp index 9c3862bff0a96a..4fc2242095a37b 100644 --- a/src/coreclr/vm/util.cpp +++ b/src/coreclr/vm/util.cpp @@ -181,8 +181,7 @@ void PrintToStdErrA(const char *pszString) { CONTRACTL_END #if defined(TARGET_ANDROID) - // TODO: make priority configurable? - __android_log_write(ANDROID_LOG_ERROR, MAIN_CLR_MODULE_NAME_A, pszString); + __android_log_write(ANDROID_LOG_FATAL, MAIN_CLR_MODULE_NAME_A, pszString); #else HANDLE Handle = GetStdHandle(STD_ERROR_HANDLE); size_t len = strlen(pszString); From f4fe37aed2faca62fad6680db8d118fb6c12fca7 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Mon, 24 Feb 2025 10:44:02 -0500 Subject: [PATCH 60/63] Remove stripping away path. Dedup script echo --- eng/native/gen-buildsys.sh | 15 ++++----------- src/coreclr/vm/bundle.cpp | 9 +-------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index d1adb1534ec503..9a6de67d40ce77 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -106,16 +106,9 @@ if [[ "$host_arch" == "wasm" ]]; then fi fi -echo "$cmake_command --no-warn-unused-cli -G \"$generator\" \"-DCMAKE_BUILD_TYPE=$buildtype\" \"-DCMAKE_INSTALL_PREFIX=$__CMakeBinDir\" $cmake_extra_defines $__UnprocessedCMakeArgs \"${cmake_extra_defines_wasm[@]}\" -S \"$1\" -B \"$2\"" -$cmake_command \ - --no-warn-unused-cli \ - -G "$generator" \ - "-DCMAKE_BUILD_TYPE=$buildtype" \ - "-DCMAKE_INSTALL_PREFIX=$__CMakeBinDir" \ - $cmake_extra_defines \ - $__UnprocessedCMakeArgs \ - "${cmake_extra_defines_wasm[@]}" \ - -S "$1" \ - -B "$2" +buildsys_command="$cmake_command --no-warn-unused-cli -G \"$generator\" \"-DCMAKE_BUILD_TYPE=$buildtype\" \"-DCMAKE_INSTALL_PREFIX=$__CMakeBinDir\" $cmake_extra_defines $__UnprocessedCMakeArgs \"${cmake_extra_defines_wasm[@]}\" -S \"$1\" -B \"$2\"" +buildsys_command=$(echo $buildsys_command | sed 's/""//g') +echo $buildsys_command +eval $buildsys_command # don't add anything after this line so the cmake exit code gets propagated correctly diff --git a/src/coreclr/vm/bundle.cpp b/src/coreclr/vm/bundle.cpp index 72946fd9b0fb0e..5e79d527ed5bc6 100644 --- a/src/coreclr/vm/bundle.cpp +++ b/src/coreclr/vm/bundle.cpp @@ -66,13 +66,6 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) pathBuffer.SetAndConvertToUTF8(path.GetUnicode()); LPCSTR utf8Path(pathBuffer.GetUTF8()); -#if defined(TARGET_ANDROID) - // On Android we always strip away the assembly path, if any - LPCSTR pos = strrchr(utf8Path, DIRECTORY_SEPARATOR_CHAR_A); - if (pos != nullptr) { - utf8Path = pos + 1; // one past the last directory separator char - } -#else // TARGET_ANDROID if (!pathIsBundleRelative) { #ifdef TARGET_UNIX @@ -89,7 +82,7 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) return BundleFileLocation::Invalid(); } } -#endif // !TARGET_ANDROID + if (m_probe != nullptr) { BundleFileLocation loc; From cf2aae659aab9a9520e0e4499f9d01020054382e Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Mon, 24 Feb 2025 11:44:45 -0500 Subject: [PATCH 61/63] Remove logging - ivan will follow up in a separate PR --- src/coreclr/dlls/mscordbi/CMakeLists.txt | 6 ------ src/coreclr/pal/src/CMakeLists.txt | 5 +---- src/coreclr/pal/src/thread/process.cpp | 10 ---------- src/coreclr/utilcode/log.cpp | 10 ---------- src/native/corehost/apphost/static/CMakeLists.txt | 2 -- 5 files changed, 1 insertion(+), 32 deletions(-) diff --git a/src/coreclr/dlls/mscordbi/CMakeLists.txt b/src/coreclr/dlls/mscordbi/CMakeLists.txt index 86a3defd6ac7df..87e566175a25c0 100644 --- a/src/coreclr/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/dlls/mscordbi/CMakeLists.txt @@ -106,12 +106,6 @@ elseif(CLR_CMAKE_HOST_UNIX) ) endif(CLR_CMAKE_HOST_HAIKU) - if(CLR_CMAKE_TARGET_ANDROID) - list(APPEND COREDBI_LIBRARIES - log - ) - endif(CLR_CMAKE_TARGET_ANDROID) - # Before llvm 16, lld was setting `--undefined-version` by default. The default was # flipped to `--no-undefined-version` in lld 16, so we will explicitly set it to # `--undefined-version` for our use-case. diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index b9d99abe7563b7..e40b0fb02f09be 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -300,10 +300,7 @@ if(CLR_CMAKE_TARGET_LINUX) else(NOT CLR_CMAKE_TARGET_ANDROID) target_link_libraries(coreclrpal PUBLIC - ${ANDROID_GLOB} - ${LZMA} - PRIVATE - log) + ${ANDROID_GLOB}) endif(NOT CLR_CMAKE_TARGET_ANDROID) target_link_libraries(coreclrpal diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index a662b7e989471f..f77cb48109155b 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -71,10 +71,6 @@ SET_DEFAULT_DEBUG_CHANNEL(PROCESS); // some headers have code with asserts, so d #include #endif -#if defined(TARGET_ANDROID) -#include -#endif // defined(TARGET_ANDROID) - #ifdef __APPLE__ #include #include @@ -2549,12 +2545,6 @@ PROCAbort(int signal, siginfo_t* siginfo) // the others to prevent multiple core dumps from being generated. SEHCleanupSignals(false /* isChildProcess */); -#if defined(TARGET_ANDROID) - // Ideally, MAIN_CLR_MODULE_NAME_A would be used, but cor.h can't - // currently be included in the pal. - __android_log_print(ANDROID_LOG_FATAL, "coreclr", "Aborting in %s:%u", __FILE_NAME__, __LINE__); -#endif // defined(TARGET_ANDROID) - // Abort the process after waiting for the core dump to complete abort(); } diff --git a/src/coreclr/utilcode/log.cpp b/src/coreclr/utilcode/log.cpp index 9c24ecca944ab9..86e9b33ff1ad28 100644 --- a/src/coreclr/utilcode/log.cpp +++ b/src/coreclr/utilcode/log.cpp @@ -18,10 +18,6 @@ #include "log.h" #include "utilcode.h" -#if defined(TARGET_ANDROID) -#include -#endif // defined(TARGET_ANDROID) - #ifdef LOGGING #define DEFAULT_LOGFILE_NAME W("COMPLUS.LOG") @@ -375,16 +371,10 @@ VOID LogSpewAlwaysValist(const char *fmt, va_list args) if (LogFlags & LOG_ENABLE_CONSOLE_LOGGING) { -#if defined(TARGET_ANDROID) - // TODO: priority should be configurable here (best, passed via a parameter) - // likewise for the tag - __android_log_write(ANDROID_LOG_INFO, MAIN_CLR_MODULE_NAME_A, pBuffer); -#else WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), pBuffer, buflen, &written, 0); //@TODO ...Unnecessary to flush console? if (LogFlags & LOG_ENABLE_FLUSH_FILE) FlushFileBuffers( GetStdHandle(STD_OUTPUT_HANDLE) ); -#endif // defined(TARGET_ANDROID) } if (LogFlags & LOG_ENABLE_DEBUGGER_LOGGING) diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 7c3121fc45027f..36b4d39f622bea 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -309,8 +309,6 @@ target_link_libraries( if(CLR_CMAKE_TARGET_ANDROID) target_link_libraries( singlefilehost - PRIVATE - log ) endif() From 7c0350ba8c0f95359da38625bbfa2dbb47683500 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Mon, 24 Feb 2025 13:41:28 -0500 Subject: [PATCH 62/63] Remove redundant target_link_libraries --- src/native/corehost/apphost/static/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 36b4d39f622bea..0ceebea335bc42 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -306,12 +306,6 @@ target_link_libraries( ${END_WHOLE_ARCHIVE} ) -if(CLR_CMAKE_TARGET_ANDROID) - target_link_libraries( - singlefilehost - ) -endif() - target_link_libraries(singlefilehost PRIVATE hostmisc) add_sanitizer_runtime_support(singlefilehost) From 1df4b0dddf0c9a5bab722b0da2a401bf4ecd4688 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 24 Feb 2025 13:35:37 -0800 Subject: [PATCH 63/63] Revert files with whitespace-only changes --- src/coreclr/pal/src/thread/process.cpp | 2 +- src/coreclr/utilcode/log.cpp | 2 ++ src/coreclr/vm/common.h | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index f77cb48109155b..20c09eb357dd2e 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -2822,7 +2822,7 @@ CorUnix::InitializeProcessCommandLine( ERROR("Invalid full path\n"); palError = ERROR_INTERNAL_ERROR; goto exit; - } + } lpwstr[0] = '\0'; size_t n = PAL_wcslen(lpwstrFullPath) + 1; diff --git a/src/coreclr/utilcode/log.cpp b/src/coreclr/utilcode/log.cpp index 86e9b33ff1ad28..56ddf6aef9c20e 100644 --- a/src/coreclr/utilcode/log.cpp +++ b/src/coreclr/utilcode/log.cpp @@ -29,6 +29,7 @@ #define LOG_ENABLE_DEBUGGER_LOGGING 0x0020 #define LOG_ENABLE 0x0040 + static DWORD LogFlags = 0; static CQuickWSTR szLogFileName; static HANDLE LogFileHandle = INVALID_HANDLE_VALUE; @@ -416,3 +417,4 @@ VOID LogSpewAlways (const char *fmt, ... ) } #endif // LOGGING + diff --git a/src/coreclr/vm/common.h b/src/coreclr/vm/common.h index af2817e8b9c2c8..b2e9dd295d02ee 100644 --- a/src/coreclr/vm/common.h +++ b/src/coreclr/vm/common.h @@ -397,4 +397,7 @@ extern DummyGlobalContract ___contract; #endif void LogErrorToHost(const char* format, ...); + #endif // !_common_h_ + +