From e9fa899d9d39d0df0ca539b195ed0304d5ff6ccf Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 30 Sep 2024 22:45:34 -0700 Subject: [PATCH] Add comments to host error_codes.h (#107775) Include basic descriptions of host error codes in `error_codes.h`. Slight clean-up (and some renames) of some error codes - these are all failures with no expected programmatic recovery, so the value change should be fine: - Merged `LibHostCurExeFindFailure` with `CurrentHostFindFailure` - Merged `LibHostSdkFindFailure` with `SdkResolveFailure` - Merged `LibHostUnknownCommand` with `LibHostInvalidArgs` --- docs/design/features/host-error-codes.md | 57 +++++++------- .../NativeHosting/HostContext.cs | 6 +- src/native/corehost/corehost.cpp | 4 +- src/native/corehost/error_codes.h | 78 +++++++++---------- src/native/corehost/fxr/fx_muxer.cpp | 6 +- src/native/corehost/fxr/hostfxr.cpp | 10 +-- src/native/corehost/fxr_resolver.h | 2 +- src/native/corehost/host_startup_info.cpp | 2 +- src/native/corehost/hostfxr.h | 2 +- src/native/corehost/hostpolicy/hostpolicy.cpp | 2 +- .../standalone/coreclr_resolver.cpp | 11 ++- src/native/corehost/ijwhost/ijwhost.cpp | 2 +- src/native/corehost/ijwhost/ijwthunk.cpp | 2 +- 13 files changed, 92 insertions(+), 92 deletions(-) diff --git a/docs/design/features/host-error-codes.md b/docs/design/features/host-error-codes.md index c5ca7c1a4df1e..4376bd5f895d7 100644 --- a/docs/design/features/host-error-codes.md +++ b/docs/design/features/host-error-codes.md @@ -8,45 +8,42 @@ Note that the exit code returned by running an application via `dotnet.exe` or ` | ------------------------------------- | ------------ | ---------------------- | ------------- | ----------- | | `Success` | `0x00000000` | `0` | `0` | Operation was successful. | | `Success_HostAlreadyInitialized` | `0x00000001` | `1` | `1` | Initialization was successful, but another host context is already initialized, so the returned context is "secondary". The requested context was otherwise fully compatible with the already initialized context. This is returned by `hostfxr_initialize_for_runtime_config` if it's called when the host is already initialized in the process. Comes from `corehost_initialize` in `hostpolicy`. | -| `Success_DifferentRuntimeProperties` | `0x00000002` | `2` | `2` | Initialization was successful, but another host context is already initialized and the requested context specified some runtime properties which are not the same (either in value or in presence) to the already initialized context. This is returned by `hostfxr_initialize_for_runtime_config` if it's called when the host is already initialized in the process. Comes from `corehost_initialize` in `hostpolicy`. | +| `Success_DifferentRuntimeProperties` | `0x00000002` | `2` | `2` | Initialization was successful, but another host context is already initialized and the requested context specified runtime properties which are not the same (either in value or in presence) to the already initialized context. This is returned by `hostfxr_initialize_for_runtime_config` if it's called when the host is already initialized in the process. Comes from `corehost_initialize` in `hostpolicy`. | ### Failure error/exit codes | Name | Value | Value (signed, 32-bit) | Value (8-bit) | Description | | ------------------------------------- | ------------ | ---------------------- | ------------- | ----------- | -| `InvalidArgFailure` | `0x80008081` | `-2147450751` | `129` | One of the specified arguments for the operation is invalid. | -| `CoreHostLibLoadFailure` | `0x80008082` | `-2147450750` | `130` | There was a failure loading a dependent library. If any of the hosting components calls `LoadLibrary`/`dlopen` on a dependent library and the call fails, this error code is returned. The most common case for this failure is if the dependent library is missing some of its dependencies (for example the necessary CRT is missing on the machine), likely corrupt or incomplete install. This error code is also returned from `corehost_resolve_component_dependencies` if it's called on a `hostpolicy` which has not been initialized via the hosting layer. This would typically happen if `coreclr` is loaded directly without the hosting layer and then `AssemblyDependencyResolver` is used (which is an unsupported scenario). | -| `CoreHostLibMissingFailure` | `0x80008083` | `-2147450749` | `131` | One of the dependent libraries is missing. Typically when the `hostfxr`, `hostpolicy` or `coreclr` dynamic libraries are not present in the expected locations. Probably means corrupted or incomplete installation. | -| `CoreHostEntryPointFailure` | `0x80008084` | `-2147450748` | `132` | One of the dependent libraries is missing a required entry point. | -| `CoreHostCurHostFindFailure` | `0x80008085` | `-2147450747` | `133` | If the hosting component is trying to use the path to the current module (the hosting component itself) and from it deduce the location of the installation. Either the location of the current module could not be determined (some weird OS call failure) or the location is not in the right place relative to other expected components. For example the `hostfxr` may look at its location and try to deduce the location of the `shared` folder with the framework from it. It assumes the typical install layout on disk. If this doesn't work, this error will be returned. | -| `CoreClrResolveFailure` | `0x80008087` | `-2147450745` | `135` | If the `coreclr` library could not be found. The hosting layer (`hostpolicy`) looks for `coreclr` library either next to the app itself (for self-contained) or in the root framework (for framework-dependent). This search can be done purely by looking at disk or more commonly by looking into the respective `.deps.json`. If the `coreclr` library is missing in `.deps.json` or it's there but doesn't exist on disk, this error is returned. | -| `CoreClrBindFailure` | `0x80008088` | `-2147450744` | `136` | The loaded `coreclr` library doesn't have one of the required entry points. | -| `CoreClrInitFailure` | `0x80008089` | `-2147450743` | `137` | The call to `coreclr_initialize` failed. The actual error returned by `coreclr` is reported in the error message. | -| `CoreClrExeFailure` | `0x8000808a` | `-2147450742` | `138` | The call to `coreclr_execute_assembly` failed. Note that this does not mean anything about the app's exit code, this failure occurs if `coreclr` failed to run the app itself. | +| `InvalidArgFailure` | `0x80008081` | `-2147450751` | `129` | One or more arguments are invalid. | +| `CoreHostLibLoadFailure` | `0x80008082` | `-2147450750` | `130` | Failed to load a [hosting component](./host-components.md). If loading a hosting component via `LoadLibrary`/`dlopen` fails, this error code is returned. The most common case for this failure is if the library is missing some of its dependencies (for example the necessary CRT is missing on the machine), likely corrupt or incomplete install. This error code is also returned from `corehost_resolve_component_dependencies` if it's called on a `hostpolicy` which has not been initialized via the hosting layer. This would typically happen if `coreclr` is loaded directly without the hosting layer and then `AssemblyDependencyResolver` is used (which is an unsupported scenario). | +| `CoreHostLibMissingFailure` | `0x80008083` | `-2147450749` | `131` | One of the [hosting components](./host-components.md) is missing. Typically when the `hostfxr`, `hostpolicy` or `coreclr` dynamic libraries are not present in the expected locations. Probably means corrupted or incomplete installation. | +| `CoreHostEntryPointFailure` | `0x80008084` | `-2147450748` | `132` | One of the hosting components is missing a required entry point. | +| `CoreHostCurHostFindFailure` | `0x80008085` | `-2147450747` | `133` | Failed to get the path of the current hosting component and determine the .NET installation location. Either the location of the current module could not be determined (some weird OS call failure) or the location is not in the right place relative to other expected components. For example the `hostfxr` may look at its location and try to deduce the location of the `shared` folder with the framework from it. It assumes the typical install layout on disk. If this doesn't work, this error will be returned. | +| `CoreClrResolveFailure` | `0x80008087` | `-2147450745` | `135` | The `coreclr` library could not be found. The hosting layer (`hostpolicy`) looks for `coreclr` either next to the app itself (for self-contained) or in the root framework (for framework-dependent). This search can be done purely by looking at disk or more commonly by looking into the respective `.deps.json`. If the `coreclr` library is missing in `.deps.json` or it's there but doesn't exist on disk, this error is returned. | +| `CoreClrBindFailure` | `0x80008088` | `-2147450744` | `136` | Failed to load the `coreclr` library or finding one of the required entry points. | +| `CoreClrInitFailure` | `0x80008089` | `-2147450743` | `137` | Call to `coreclr_initialize` failed. The actual error returned by `coreclr` is reported in the error message. | +| `CoreClrExeFailure` | `0x8000808a` | `-2147450742` | `138` | Call to `coreclr_execute_assembly` failed. Note that this does not mean anything about the app's exit code, this failure occurs if `coreclr` failed to run the app itself. | | `ResolverInitFailure` | `0x8000808b` | `-2147450741` | `139` | Initialization of the `hostpolicy` dependency resolver failed. This can be: | | `ResolverResolveFailure` | `0x8000808c` | `-2147450740` | `140` | Resolution of dependencies in `hostpolicy` failed. This can mean many different things, but in general one of the processed `.deps.json` contains entry for a file which could not found, or its resolution failed for some other reason (conflict for example). | -| `LibHostCurExeFindFailure` | `0x8000808d` | `-2147450739` | `141` | Failure to determine the location of the current executable. The hosting layer uses the current executable path to deduce the install location in some cases. If this path can't be obtained (OS call fails, or the returned path doesn't exist), this error is returned. | | `LibHostInitFailure` | `0x8000808e` | `-2147450738` | `142` | Initialization of the `hostpolicy` library failed. The `corehost_load` method takes a structure with lot of initialization parameters. If the version of this structure doesn't match the expected value, this error code is returned. This would in general mean incompatibility between the `hostfxr` and `hostpolicy`, which should really only happen if somehow a newer `hostpolicy` is used by older `hostfxr`. This typically means corrupted installation. | -| `LibHostSdkFindFailure` | `0x80008091` | `-2147450735` | `145` | Failure to find the requested SDK. This happens in the `hostfxr` when an SDK (also called CLI) command is used with `dotnet`. In this case the hosting layer tries to find an installed .NET SDK to run the command on. The search is based on deduced install location and on the requested version from potential `global.json` file. If either no matching SDK version can be found, or that version exists, but it's missing the `dotnet.dll` file, this error code is returned. | -| `LibHostInvalidArgs` | `0x80008092` | `-2147450734` | `146` | Arguments to `hostpolicy` are invalid. This is used in three unrelated places in the `hostpolicy`, but in all cases it means the component calling `hostpolicy` did something wrong: | +| `LibHostSdkFindFailure` | `0x80008091` | `-2147450735` | `145` | Failed to find the requested SDK. This happens in the `hostfxr` when an SDK (also called CLI) command is used with `dotnet`. In this case the hosting layer tries to find an installed .NET SDK to run the command on. The search is based on deduced install location and on the requested version from potential `global.json` file. If either no matching SDK version can be found, or that version exists, but it's missing the `dotnet.dll` file, this error code is returned. | +| `LibHostInvalidArgs` | `0x80008092` | `-2147450734` | `146` | Arguments to `hostpolicy` are invalid. This is used in various separate places in `hostpolicy`, but in all cases it means the component calling `hostpolicy` did something wrong: | | `InvalidConfigFile` | `0x80008093` | `-2147450733` | `147` | The `.runtimeconfig.json` file is invalid. The reasons for this failure can be among these: | | `AppArgNotRunnable` | `0x80008094` | `-2147450732` | `148` | Used internally when the command line for `dotnet.exe` doesn't contain path to the application to run. In such case the command line is considered to be a CLI/SDK command. This error code should never be returned to external caller. | | `AppHostExeNotBoundFailure` | `0x80008095` | `-2147450731` | `149` | `apphost` failed to determine which application to run. This can mean: | -| `FrameworkMissingFailure` | `0x80008096` | `-2147450730` | `150` | It was not possible to find a compatible framework version. This originates in `hostfxr` (`resolve_framework_reference`) and means that the app specified a reference to a framework in its `.runtimeconfig.json` which could not be resolved. The failure to resolve can mean that no such framework is available on the disk, or that the available frameworks don't match the minimum version specified or that the roll forward options specified excluded all available frameworks. Typically this would be used if a 3.0 app is trying to run on a machine which has no 3.0 installed. It would also be used for example if a 32bit 3.0 app is running on a machine which has 3.0 installed but only for 64bit. | -| `HostApiFailed` | `0x80008097` | `-2147450729` | `151` | Returned by `hostfxr_get_native_search_directories` if the `hostpolicy` could not calculate the `NATIVE_DLL_SEARCH_DIRECTORIES`. | -| `HostApiBufferTooSmall` | `0x80008098` | `-2147450728` | `152` | Returned when the buffer specified to an API is not big enough to fit the requested value. Can be returned from: | -| `LibHostUnknownCommand` | `0x80008099` | `-2147450727` | `153` | Returned by `hostpolicy` if the `corehost_main_with_output_buffer` is called with unsupported host command. This error code means there is incompatibility between the `hostfxr` and `hostpolicy`. In reality this should pretty much never happen. | -| `LibHostAppRootFindFailure` | `0x8000809a` | `-2147450726` | `154` | Returned by `apphost` if the imprinted application path doesn't exist. This would happen if the app is built with an executable (the `apphost`) and the main `app.dll` is missing. | -| `SdkResolverResolveFailure` | `0x8000809b` | `-2147450725` | `155` | Returned from `hostfxr_resolve_sdk2` when it fails to find matching SDK. Similar to `LibHostSdkFindFailure` but only used in the `hostfxr_resolve_sdk2`. | -| `FrameworkCompatFailure` | `0x8000809c` | `-2147450724` | `156` | During processing of `.runtimeconfig.json` there were two framework references to the same framework which were not compatible. This can happen if the app specified a framework reference to a lower-level framework which is also specified by a higher-level framework which is also used by the app. For example, this would happen if the app referenced `Microsoft.AspNet.App` version 2.0 and `Microsoft.NETCore.App` version 3.0. In such case the `Microsoft.AspNet.App` has `.runtimeconfig.json` which also references `Microsoft.NETCore.App` but it only allows versions 2.0 up to 2.9 (via roll forward options). So the version 3.0 requested by the app is incompatible. | +| `FrameworkMissingFailure` | `0x80008096` | `-2147450730` | `150` | Failed to finding a compatible framework version. This originates in `hostfxr` (`resolve_framework_reference`) and means that the app specified a reference to a framework in its `.runtimeconfig.json` which could not be resolved. The failure to resolve can mean that no such framework is available on the disk, or that the available frameworks don't match the minimum version specified or that the roll forward options specified excluded all available frameworks. Typically this would be used if a 3.0 app is trying to run on a machine which has no 3.0 installed. It would also be used for example if a 32bit 3.0 app is running on a machine which has 3.0 installed but only for 64bit. | +| `HostApiFailed` | `0x80008097` | `-2147450729` | `151` | Host command failed. Returned by `hostfxr_get_native_search_directories` if the `hostpolicy` could not calculate the `NATIVE_DLL_SEARCH_DIRECTORIES`. | +| `HostApiBufferTooSmall` | `0x80008098` | `-2147450728` | `152` | Buffer provided to a host API is too small to fit the requested value. Can be returned from: | +| `AppPathFindFailure` | `0x8000809a` | `-2147450726` | `154` | Application path imprinted in `apphost` doesn't exist. This would happen if the app is built with an executable (the `apphost`) and the main `app.dll` is missing. | +| `SdkResolveFailure` | `0x8000809b` | `-2147450725` | `155` | Failed to find the requested SDK. This happens in the `hostfxr` when an SDK (also called CLI) command is used with `dotnet` or when calling the `hostfxr_resolve_sdk2` API. In this case the hosting layer tries to find an installed .NET SDK to run the command on. The search is based on deduced install location and on the requested version from potential `global.json` file. If either no matching SDK version can be found, or that version exists, but it's missing the `dotnet.dll` file, this error code is returned. | +| `FrameworkCompatFailure` | `0x8000809c` | `-2147450724` | `156` | Application has multiple references to the same framework which are not compatible - found during processing of `.runtimeconfig.json`. This can happen if the app specified a framework reference to a lower-level framework which is also specified by a higher-level framework which is also used by the app. For example, this would happen if the app referenced `Microsoft.AspNet.App` version 2.0 and `Microsoft.NETCore.App` version 3.0. In such case the `Microsoft.AspNet.App` has `.runtimeconfig.json` which also references `Microsoft.NETCore.App` but it only allows versions 2.0 up to 2.9 (via roll forward options). So the version 3.0 requested by the app is incompatible. | | `FrameworkCompatRetry` | `0x8000809d` | `-2147450723` | `157` | Error used internally if the processing of framework references from `.runtimeconfig.json` reached a point where it needs to reprocess another already processed framework reference. If this error is returned to the external caller, it would mean there's a bug in the framework resolution algorithm. | -| `AppHostExeNotBundle` | `0x8000809e` | `-2147450722` | `158` | Error reading the bundle footer metadata from a single-file `apphost`. This would mean a corrupted `apphost`. | -| `BundleExtractionFailure` | `0x8000809f` | `-2147450721` | `159` | Error extracting single-file `apphost` bundle. This is used in case of any error related to the bundle itself. Typically would mean a corrupted bundle. | -| `BundleExtractionIOError` | `0x800080a0` | `-2147450720` | `160` | Error reading or writing files during single-file `apphost` bundle extraction. | -| `LibHostDuplicateProperty` | `0x800080a1` | `-2147450719` | `161` | The `.runtimeconfig.json` specified by the app contains a runtime property which is also produced by the hosting layer. For example if the `.runtimeconfig.json` would specify a property `TRUSTED_PLATFORM_ROOTS`, this error code would be returned. It is not allowed to specify properties which are otherwise populated by the hosting layer (`hostpolicy`) as there is not good way to resolve such conflicts. | -| `HostApiUnsupportedVersion` | `0x800080a2` | `-2147450718` | `162` | Feature which requires certain version of the hosting layer binaries was used on a version which doesn't support it. For example if COM component specified to run on 2.0 `Microsoft.NETCore.App` - as that contains older version of `hostpolicy` which doesn't support the necessary features to provide COM services. | -| `HostInvalidState` | `0x800080a3` | `-2147450717` | `163` | Error code returned by the hosting APIs in `hostfxr` if the current state is incompatible with the requested operation. There are many such cases, please refer to the documentation of the hosting APIs for details. For example if `hostfxr_get_runtime_property_value` is called with the `host_context_handle` `nullptr` (meaning get property from the active runtime) but there's no active runtime in the process. | -| `HostPropertyNotFound` | `0x800080a4` | `-2147450716` | `164` | property requested by `hostfxr_get_runtime_property_value` doesn't exist. | -| `CoreHostIncompatibleConfig` | `0x800080a5` | `-2147450715` | `165` | Error returned by `hostfxr_initialize_for_runtime_config` if the component being initialized requires framework which is not available or incompatible with the frameworks loaded by the runtime already in the process. For example trying to load a component which requires 3.0 into a process which is already running a 2.0 runtime. | -| `HostApiUnsupportedScenario` | `0x800080a6` | `-2147450714` | `166` | Error returned by `hostfxr_get_runtime_delegate` when `hostfxr` doesn't currently support requesting the given delegate type using the given context. | -| `HostFeatureDisabled` | `0x800080a7` | `-2147450713` | `167` | Error returned by `hostfxr_get_runtime_delegate` when managed feature support for native host is disabled. | +| `BundleExtractionFailure` | `0x8000809f` | `-2147450721` | `159` | Error extracting single-file bundle. This is used in case of any error related to the bundle itself. Typically would mean a corrupted bundle. | +| `BundleExtractionIOError` | `0x800080a0` | `-2147450720` | `160` | Error reading or writing files during single-file bundle extraction. | +| `LibHostDuplicateProperty` | `0x800080a1` | `-2147450719` | `161` | The application's `.runtimeconfig.json` contains a runtime property which is produced by the hosting layer. For example if the `.runtimeconfig.json` would specify a property `TRUSTED_PLATFORM_ROOTS`, this error code would be returned. It is not allowed to specify properties which are otherwise populated by the hosting layer (`hostpolicy`) as there is not good way to resolve such conflicts. | +| `HostApiUnsupportedVersion` | `0x800080a2` | `-2147450718` | `162` | Feature which requires certain version of the hosting layer was used on a version which doesn't support it. For example if COM component specified to run on 2.0 `Microsoft.NETCore.App` - as that contains older version of `hostpolicy` which doesn't support the necessary features to provide COM services. | +| `HostInvalidState` | `0x800080a3` | `-2147450717` | `163` | Current state is incompatible with the requested operation - returned by the hosting APIs in `hostfxr`. There are many such cases, please refer to the documentation of the hosting APIs for details. For example if `hostfxr_get_runtime_property_value` is called with the `host_context_handle` `nullptr` (meaning get property from the active runtime) but there's no active runtime in the process. | +| `HostPropertyNotFound` | `0x800080a4` | `-2147450716` | `164` | Property requested by `hostfxr_get_runtime_property_value` doesn't exist. | +| `HostIncompatibleConfig` | `0x800080a5` | `-2147450715` | `165` | Host configuration is incompatible with existing host context - returned by `hostfxr_initialize_for_runtime_config`. The component being initialized requires framework which is not available or incompatible with the frameworks loaded by the runtime already in the process. For example trying to load a component which requires 3.0 into a process which is already running a 2.0 runtime. | +| `HostApiUnsupportedScenario` | `0x800080a6` | `-2147450714` | `166` | Hosting API does not support the requested scenario. Returned by `hostfxr_get_runtime_delegate` when `hostfxr` doesn't support requesting the given delegate type using the given context. | +| `HostFeatureDisabled` | `0x800080a7` | `-2147450713` | `167` | Support for a requested feature is disabled. Returned by `hostfxr_get_runtime_delegate` when managed feature support for native host is disabled. | diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.cs index 439224531549c..d1c87d8ade406 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/HostContext.cs @@ -54,7 +54,7 @@ public enum CommandLine private const int InvalidArgFailure = unchecked((int)0x80008081); private const int HostInvalidState = unchecked((int)0x800080a3); private const int HostPropertyNotFound = unchecked((int)0x800080a4); - private const int CoreHostIncompatibleConfig = unchecked((int)0x800080a5); + private const int HostIncompatibleConfig = unchecked((int)0x800080a5); private const int Success_HostAlreadyInitialized = 0x00000001; private const int Success_DifferentRuntimeProperties = 0x00000002; @@ -420,14 +420,14 @@ public void CompatibilityCheck_Frameworks(string scenario, FrameworkCompatibilit else { result.Should().Fail() - .And.FailToInitializeContextForConfig(CoreHostIncompatibleConfig) + .And.FailToInitializeContextForConfig(HostIncompatibleConfig) .And.HaveStdErrMatching($".*The specified framework '{frameworkName}', version '{version}', apply_patches=[0-1], version_compatibility_range=[^ ]* is incompatible with the previously loaded version '{SharedTestState.NetCoreAppVersion}'.*"); } } else { result.Should().Fail() - .And.FailToInitializeContextForConfig(CoreHostIncompatibleConfig) + .And.FailToInitializeContextForConfig(HostIncompatibleConfig) .And.HaveStdErrContaining($"The specified framework '{frameworkName}' is not present in the previously loaded runtime"); } } diff --git a/src/native/corehost/corehost.cpp b/src/native/corehost/corehost.cpp index c8a94312c5d6d..6de7acfbd0857 100644 --- a/src/native/corehost/corehost.cpp +++ b/src/native/corehost/corehost.cpp @@ -118,7 +118,7 @@ int exe_start(const int argc, const pal::char_t* argv[]) if (!pal::get_own_executable_path(&host_path) || !pal::realpath(&host_path)) { trace::error(_X("Failed to resolve full path of the current executable [%s]"), host_path.c_str()); - return StatusCode::CoreHostCurHostFindFailure; + return StatusCode::CurrentHostFindFailure; } pal::string_t app_path; @@ -153,7 +153,7 @@ int exe_start(const int argc, const pal::char_t* argv[]) else if (!pal::fullpath(&app_path)) { trace::error(_X("The application to execute does not exist: '%s'."), app_path.c_str()); - return StatusCode::LibHostAppRootFindFailure; + return StatusCode::AppPathFindFailure; } app_root.assign(get_directory(app_path)); diff --git a/src/native/corehost/error_codes.h b/src/native/corehost/error_codes.h index d532edaaf6352..5757d3b3125c6 100644 --- a/src/native/corehost/error_codes.h +++ b/src/native/corehost/error_codes.h @@ -8,50 +8,50 @@ enum StatusCode { // Success - Success = 0, - Success_HostAlreadyInitialized = 0x00000001, - Success_DifferentRuntimeProperties = 0x00000002, + Success = 0, // Operation was successful + Success_HostAlreadyInitialized = 0x00000001, // Initialization was successful, but another host context is already initialized + Success_DifferentRuntimeProperties = 0x00000002, // Initialization was successful, but another host context is already initialized and the requested context specified runtime properties which are not the same // Failure - InvalidArgFailure = 0x80008081, - CoreHostLibLoadFailure = 0x80008082, - CoreHostLibMissingFailure = 0x80008083, - CoreHostEntryPointFailure = 0x80008084, - CoreHostCurHostFindFailure = 0x80008085, + InvalidArgFailure = 0x80008081, // One or more arguments are invalid + CoreHostLibLoadFailure = 0x80008082, // Failed to load a hosting component + CoreHostLibMissingFailure = 0x80008083, // One of the hosting components is missing + CoreHostEntryPointFailure = 0x80008084, // One of the hosting components is missing a required entry point + CurrentHostFindFailure = 0x80008085, // Failed to get the path of the current hosting component and determine the .NET installation location // unused = 0x80008086, - CoreClrResolveFailure = 0x80008087, - CoreClrBindFailure = 0x80008088, - CoreClrInitFailure = 0x80008089, - CoreClrExeFailure = 0x8000808a, - ResolverInitFailure = 0x8000808b, - ResolverResolveFailure = 0x8000808c, - LibHostCurExeFindFailure = 0x8000808d, - LibHostInitFailure = 0x8000808e, + CoreClrResolveFailure = 0x80008087, // The `coreclr` library could not be found + CoreClrBindFailure = 0x80008088, // Failed to load the `coreclr` library or finding one of the required entry points + CoreClrInitFailure = 0x80008089, // Call to `coreclr_initialize` failed + CoreClrExeFailure = 0x8000808a, // Call to `coreclr_execute_assembly` failed + ResolverInitFailure = 0x8000808b, // Initialization of the `hostpolicy` dependency resolver failed + ResolverResolveFailure = 0x8000808c, // Resolution of dependencies in `hostpolicy` failed + // unused = 0x8000808d, + LibHostInitFailure = 0x8000808e, // Initialization of the `hostpolicy` library failed // unused = 0x8000808f, - LibHostExecModeFailure = 0x80008090, - LibHostSdkFindFailure = 0x80008091, - LibHostInvalidArgs = 0x80008092, - InvalidConfigFile = 0x80008093, - AppArgNotRunnable = 0x80008094, - AppHostExeNotBoundFailure = 0x80008095, - FrameworkMissingFailure = 0x80008096, - HostApiFailed = 0x80008097, - HostApiBufferTooSmall = 0x80008098, - LibHostUnknownCommand = 0x80008099, - LibHostAppRootFindFailure = 0x8000809a, - SdkResolverResolveFailure = 0x8000809b, - FrameworkCompatFailure = 0x8000809c, - FrameworkCompatRetry = 0x8000809d, + // unused = 0x80008090, + // unused = 0x80008091, + LibHostInvalidArgs = 0x80008092, // Arguments to `hostpolicy` are invalid + InvalidConfigFile = 0x80008093, // The `.runtimeconfig.json` file is invalid + AppArgNotRunnable = 0x80008094, // [internal usage only] + AppHostExeNotBoundFailure = 0x80008095, // `apphost` failed to determine which application to run + FrameworkMissingFailure = 0x80008096, // Failed to find a compatible framework version + HostApiFailed = 0x80008097, // Host command failed + HostApiBufferTooSmall = 0x80008098, // Buffer provided to a host API is too small to fit the requested value + // unused = 0x80008099, + AppPathFindFailure = 0x8000809a, // Application path imprinted in `apphost` doesn't exist + SdkResolveFailure = 0x8000809b, // Failed to find the requested SDK + FrameworkCompatFailure = 0x8000809c, // Application has multiple references to the same framework which are not compatible + FrameworkCompatRetry = 0x8000809d, // [internal usage only] // unused = 0x8000809e, - BundleExtractionFailure = 0x8000809f, - BundleExtractionIOError = 0x800080a0, - LibHostDuplicateProperty = 0x800080a1, - HostApiUnsupportedVersion = 0x800080a2, - HostInvalidState = 0x800080a3, - HostPropertyNotFound = 0x800080a4, - CoreHostIncompatibleConfig = 0x800080a5, - HostApiUnsupportedScenario = 0x800080a6, - HostFeatureDisabled = 0x800080a7, + BundleExtractionFailure = 0x8000809f, // Error extracting single-file bundle + BundleExtractionIOError = 0x800080a0, // Error reading or writing files during single-file bundle extraction + LibHostDuplicateProperty = 0x800080a1, // The application's `.runtimeconfig.json` contains a runtime property which is produced by the hosting layer + HostApiUnsupportedVersion = 0x800080a2, // Feature which requires certain version of the hosting layer was used on a version which doesn't support it + HostInvalidState = 0x800080a3, // Current state is incompatible with the requested operation + HostPropertyNotFound = 0x800080a4, // Property requested by `hostfxr_get_runtime_property_value` doesn't exist + HostIncompatibleConfig = 0x800080a5, // Host configuration is incompatible with existing host context + HostApiUnsupportedScenario = 0x800080a6, // Hosting API does not support the requested scenario + HostFeatureDisabled = 0x800080a7, // Support for a requested feature is disabled }; #define STATUS_CODE_SUCCEEDED(status_code) ((static_cast(static_cast(status_code))) >= 0) diff --git a/src/native/corehost/fxr/fx_muxer.cpp b/src/native/corehost/fxr/fx_muxer.cpp index b6706b00b8800..642e26e923482 100644 --- a/src/native/corehost/fxr/fx_muxer.cpp +++ b/src/native/corehost/fxr/fx_muxer.cpp @@ -666,13 +666,13 @@ namespace { // Framework dependent apps always know their frameworks if (!fx_resolver_t::is_config_compatible_with_frameworks(app_config, existing_context->fx_versions_by_name)) - return StatusCode::CoreHostIncompatibleConfig; + return StatusCode::HostIncompatibleConfig; } else if (!existing_context->included_fx_versions_by_name.empty()) { // Self-contained apps can include information about their frameworks in `includedFrameworks` property in runtime config if (!fx_resolver_t::is_config_compatible_with_frameworks(app_config, existing_context->included_fx_versions_by_name)) - return StatusCode::CoreHostIncompatibleConfig; + return StatusCode::HostIncompatibleConfig; } else { @@ -1067,7 +1067,7 @@ int fx_muxer_t::handle_cli( app_candidate.c_str()); resolver.print_resolution_error(host_info.dotnet_root, _X(" ")); - return StatusCode::LibHostSdkFindFailure; + return StatusCode::SdkResolveFailure; } append_path(&sdk_dotnet, SDK_DOTNET_DLL); diff --git a/src/native/corehost/fxr/hostfxr.cpp b/src/native/corehost/fxr/hostfxr.cpp index 7a071bc4c305d..98c2ae26a14f9 100644 --- a/src/native/corehost/fxr/hostfxr.cpp +++ b/src/native/corehost/fxr/hostfxr.cpp @@ -230,7 +230,7 @@ typedef void (HOSTFXR_CALLTYPE *hostfxr_resolve_sdk2_result_fn)( // // Return value: // 0 on success, otherwise failure -// 0x8000809b - SDK could not be resolved (SdkResolverResolveFailure) +// 0x8000809b - SDK could not be resolved (SdkResolveFailure) // // String encoding: // Windows - UTF-16 (pal::char_t is 2 byte wchar_t) @@ -289,7 +289,7 @@ SHARED_API int32_t HOSTFXR_CALLTYPE hostfxr_resolve_sdk2( return !resolved_sdk_dir.empty() ? StatusCode::Success - : StatusCode::SdkResolverResolveFailure; + : StatusCode::SdkResolveFailure; } @@ -550,7 +550,7 @@ namespace if (!pal::get_own_executable_path(&startup_info.host_path) || !pal::fullpath(&startup_info.host_path)) { trace::error(_X("Failed to resolve full path of the current host [%s]"), startup_info.host_path.c_str()); - return StatusCode::CoreHostCurHostFindFailure; + return StatusCode::CurrentHostFindFailure; } } @@ -558,13 +558,13 @@ namespace { pal::string_t mod_path; if (!pal::get_method_module_path(&mod_path, (void*)&hostfxr_set_error_writer)) - return StatusCode::CoreHostCurHostFindFailure; + return StatusCode::CurrentHostFindFailure; startup_info.dotnet_root = get_dotnet_root_from_fxr_path(mod_path); if (!pal::fullpath(&startup_info.dotnet_root)) { trace::error(_X("Failed to resolve full path of dotnet root [%s]"), startup_info.dotnet_root.c_str()); - return StatusCode::CoreHostCurHostFindFailure; + return StatusCode::CurrentHostFindFailure; } } diff --git a/src/native/corehost/fxr_resolver.h b/src/native/corehost/fxr_resolver.h index 0c82fc4585120..022021ede153b 100644 --- a/src/native/corehost/fxr_resolver.h +++ b/src/native/corehost/fxr_resolver.h @@ -37,7 +37,7 @@ int load_fxr_and_get_delegate(hostfxr_delegate_type type, THostPathToConfigCallb if (!pal::get_own_module_path(&host_path) || !pal::fullpath(&host_path)) { trace::error(_X("Failed to resolve full path of the current host module [%s]"), host_path.c_str()); - return StatusCode::CoreHostCurHostFindFailure; + return StatusCode::CurrentHostFindFailure; } pal::string_t dotnet_root; diff --git a/src/native/corehost/host_startup_info.cpp b/src/native/corehost/host_startup_info.cpp index d2fdcbe358550..0574d0e6dc7df 100644 --- a/src/native/corehost/host_startup_info.cpp +++ b/src/native/corehost/host_startup_info.cpp @@ -89,7 +89,7 @@ const pal::string_t host_startup_info_t::get_app_name() const if (host_path->empty() && (!pal::get_own_executable_path(host_path) || !pal::fullpath(host_path))) { trace::error(_X("Failed to resolve full path of the current executable [%s]"), host_path->c_str()); - return StatusCode::LibHostCurExeFindFailure; + return StatusCode::CurrentHostFindFailure; } return 0; diff --git a/src/native/corehost/hostfxr.h b/src/native/corehost/hostfxr.h index 0c316a59b1159..329cf31cabd2c 100644 --- a/src/native/corehost/hostfxr.h +++ b/src/native/corehost/hostfxr.h @@ -130,7 +130,7 @@ typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_initialize_for_dotnet_command_line_fn) // Success - Hosting components were successfully initialized // Success_HostAlreadyInitialized - Config is compatible with already initialized hosting components // Success_DifferentRuntimeProperties - Config has runtime properties that differ from already initialized hosting components -// CoreHostIncompatibleConfig - Config is incompatible with already initialized hosting components +// HostIncompatibleConfig - Config is incompatible with already initialized hosting components // // This function will process the .runtimeconfig.json to resolve frameworks and prepare everything needed // to load the runtime. It will only process the .deps.json from frameworks (not any app/component that diff --git a/src/native/corehost/hostpolicy/hostpolicy.cpp b/src/native/corehost/hostpolicy/hostpolicy.cpp index f96f00e2962e6..165cc092f621b 100644 --- a/src/native/corehost/hostpolicy/hostpolicy.cpp +++ b/src/native/corehost/hostpolicy/hostpolicy.cpp @@ -463,7 +463,7 @@ SHARED_API int HOSTPOLICY_CALLTYPE corehost_main_with_output_buffer(const int ar else { trace::error(_X("Unknown command: %s"), g_init.host_command.c_str()); - rc = StatusCode::LibHostUnknownCommand; + rc = StatusCode::LibHostInvalidArgs; } return rc; diff --git a/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp b/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp index b040c3e854627..0e4ec4cfd1840 100644 --- a/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp +++ b/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp @@ -25,10 +25,13 @@ bool coreclr_resolver_t::resolve_coreclr(const pal::string_t& libcoreclr_path, c coreclr_resolver_contract.coreclr_create_delegate = reinterpret_cast(pal::get_symbol(coreclr_resolver_contract.coreclr, "coreclr_create_delegate")); // Only the coreclr_set_error_writer is optional - assert(coreclr_resolver_contract.coreclr_initialize != nullptr - && coreclr_resolver_contract.coreclr_shutdown != nullptr - && coreclr_resolver_contract.coreclr_execute_assembly != nullptr - && coreclr_resolver_contract.coreclr_create_delegate != nullptr); + if (coreclr_resolver_contract.coreclr_initialize == nullptr + || coreclr_resolver_contract.coreclr_shutdown == nullptr + || coreclr_resolver_contract.coreclr_execute_assembly == nullptr + || coreclr_resolver_contract.coreclr_create_delegate == nullptr) + { + return false; + } return true; } diff --git a/src/native/corehost/ijwhost/ijwhost.cpp b/src/native/corehost/ijwhost/ijwhost.cpp index e64e01a56580f..5ea726cab92ad 100644 --- a/src/native/corehost/ijwhost/ijwhost.cpp +++ b/src/native/corehost/ijwhost/ijwhost.cpp @@ -31,7 +31,7 @@ pal::hresult_t get_load_in_memory_assembly_delegate(pal::dll_t handle, load_in_m if (!pal::get_module_path(handle, &mod_path)) { trace::error(_X("Failed to resolve full path of the current mixed-mode module [%s]"), host_path.c_str()); - return StatusCode::LibHostCurExeFindFailure; + return StatusCode::CurrentHostFindFailure; } pal::string_t config_path_local { strip_file_ext(mod_path) }; diff --git a/src/native/corehost/ijwhost/ijwthunk.cpp b/src/native/corehost/ijwhost/ijwthunk.cpp index 2c24f4d6f9207..2a2bb9c293655 100644 --- a/src/native/corehost/ijwhost/ijwthunk.cpp +++ b/src/native/corehost/ijwhost/ijwthunk.cpp @@ -143,7 +143,7 @@ extern "C" std::uintptr_t __stdcall start_runtime_and_get_target_address(std::ui { #pragma warning (push) #pragma warning (disable: 4297) - throw StatusCode::LibHostCurExeFindFailure; + throw StatusCode::CurrentHostFindFailure; #pragma warning (pop) }