Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/design-docs/host-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The .NET Core default hosting setup consists of several components which are des
* `comhost` (library) - which is used to enable COM server hosting. Component which wants to expose COM server objects will be built with this dynamic library in its output. The `comhost` then acts as the main entry point for the OS.

The executable does just one thing, it finds the `hostfxr` library and passes control to it. It also exposes the right entry points for its purpose (so the "main" for `dotnet` and `apphost`, the COM exports for `comhost` and so on).
* `dotnet` host - `hostfxr` is obtained from the `./shared/host/fxr<highestversion>` folder (relative to the location of the `dotnet` host).
* `dotnet` host - `hostfxr` is obtained from the `./host/fxr<highestversion>` folder (relative to the location of the `dotnet` host).
* `apphost` and `comhost` - `hostfxr` is located by
1. The app's folder is searched first. This is either the folder where the `apphost` or `comhost` lives or in case of `apphost` it is the path it has embedded in it as the app path.
1. If the `DOTNET_ROOT` environment variable is defined, that path is searched
Expand Down
3 changes: 3 additions & 0 deletions signing/sign.proj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<FilesToSign Include="$(OutDir)corehost/**/ijwhost.dll">
<Authenticode>$(CertificateId)</Authenticode>
</FilesToSign>
<FilesToSign Include="$(OutDir)corehost/**/nethost.dll">
<Authenticode>$(CertificateId)</Authenticode>
</FilesToSign>
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/corehost/Windows/gen-buildsys-win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& .\Win
popd

:DoGen
echo "%CMakePath%" %__sourceDir% %__SDKVersion% "-DCLI_CMAKE_RUNTIME_ID:STRING=%cm_BaseRid%" "-DCLI_CMAKE_HOST_VER:STRING=%__HostVersion%" "-DCLI_CMAKE_APPHOST_VER:STRING=%__AppHostVersion%" "-DCLI_CMAKE_COMHOST_VER:STRING=%__AppHostVersion%" "-DCLI_CMAKE_IJWHOST_VER:STRING=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER:STRING=%__HostFxrVersion%" "-DCLI_CMAKE_HOST_POLICY_VER:STRING=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID:STRING=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH:STRING=%__LatestCommit%" "-DCLI_CMAKE_PLATFORM_ARCH_%cm_Arch%=1" "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLI_CMAKE_RESOURCE_DIR:STRING=%__ResourcesDir%" -G "Visual Studio %__VSString%" %__ExtraCmakeParams%
"%CMakePath%" %__sourceDir% %__SDKVersion% "-DCLI_CMAKE_RUNTIME_ID:STRING=%cm_BaseRid%" "-DCLI_CMAKE_HOST_VER:STRING=%__HostVersion%" "-DCLI_CMAKE_APPHOST_VER:STRING=%__AppHostVersion%" "-DCLI_CMAKE_COMHOST_VER:STRING=%__AppHostVersion%" "-DCLI_CMAKE_IJWHOST_VER:STRING=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER:STRING=%__HostFxrVersion%" "-DCLI_CMAKE_HOST_POLICY_VER:STRING=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID:STRING=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH:STRING=%__LatestCommit%" "-DCLI_CMAKE_PLATFORM_ARCH_%cm_Arch%=1" "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLI_CMAKE_RESOURCE_DIR:STRING=%__ResourcesDir%" -G "Visual Studio %__VSString%" %__ExtraCmakeParams%
echo "%CMakePath%" %__sourceDir% %__SDKVersion% "-DCLI_CMAKE_RUNTIME_ID:STRING=%cm_BaseRid%" "-DCLI_CMAKE_HOST_VER:STRING=%__HostVersion%" "-DCLI_CMAKE_COMMON_HOST_VER:STRING=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER:STRING=%__HostFxrVersion%" "-DCLI_CMAKE_HOST_POLICY_VER:STRING=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID:STRING=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH:STRING=%__LatestCommit%" "-DCLI_CMAKE_PLATFORM_ARCH_%cm_Arch%=1" "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLI_CMAKE_RESOURCE_DIR:STRING=%__ResourcesDir%" -G "Visual Studio %__VSString%" %__ExtraCmakeParams%
"%CMakePath%" %__sourceDir% %__SDKVersion% "-DCLI_CMAKE_RUNTIME_ID:STRING=%cm_BaseRid%" "-DCLI_CMAKE_HOST_VER:STRING=%__HostVersion%" "-DCLI_CMAKE_COMMON_HOST_VER:STRING=%__AppHostVersion%" "-DCLI_CMAKE_HOST_FXR_VER:STRING=%__HostFxrVersion%" "-DCLI_CMAKE_HOST_POLICY_VER:STRING=%__HostPolicyVersion%" "-DCLI_CMAKE_PKG_RID:STRING=%cm_BaseRid%" "-DCLI_CMAKE_COMMIT_HASH:STRING=%__LatestCommit%" "-DCLI_CMAKE_PLATFORM_ARCH_%cm_Arch%=1" "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLI_CMAKE_RESOURCE_DIR:STRING=%__ResourcesDir%" -G "Visual Studio %__VSString%" %__ExtraCmakeParams%
endlocal
Comment thread
elinor-fung marked this conversation as resolved.
GOTO :DONE

Expand Down
19 changes: 11 additions & 8 deletions src/corehost/build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- Target that builds dotnet, hostfxr and hostpolicy with the same version as what NetCoreApp will be built for
since the build produced artifacts should always version the same (even if they may not get used).
-->
<Target Name="Build" DependsOnTargets="BuildCoreHostUnix;BuildCoreHostWindows" />
<Target Name="Build" DependsOnTargets="BuildCoreHostUnix;BuildCoreHostWindows" />

<PropertyGroup Condition="'$(OSGroup)' != 'Windows_NT'">
<GenerateVersionSourceFile>true</GenerateVersionSourceFile>
Expand All @@ -19,11 +19,11 @@
DependsOnTargets="GetLatestCommitHash;GenerateVersionSourceFile">
<PropertyGroup>
<CMakeBuildDir>$(IntermediateOutputRootPath)corehost\cmake\</CMakeBuildDir>

<BuildArgs>--configuration $(ConfigurationGroup) --arch $(TargetArchitecture) --apphostver $(AppHostVersion) --hostver $(HostVersion) --fxrver $(HostResolverVersion) --policyver $(HostPolicyVersion) --commithash $(LatestCommit)</BuildArgs>
<BuildArgs Condition="'$(PortableBuild)' == 'true'">$(BuildArgs) -portable</BuildArgs>
<BuildArgs Condition="'$(CrossBuild)' == 'true'">$(BuildArgs) --cross</BuildArgs>
<BuildArgs Condition="'$(StripSymbols)' == 'true'">$(BuildArgs) --stripsymbols</BuildArgs>
<BuildArgs Condition="'$(PortableBuild)' == 'true'">$(BuildArgs) -portable</BuildArgs>
<BuildArgs Condition="'$(CrossBuild)' == 'true'">$(BuildArgs) --cross</BuildArgs>
<BuildArgs Condition="'$(StripSymbols)' == 'true'">$(BuildArgs) --stripsymbols</BuildArgs>
</PropertyGroup>

<Message Text="$(MSBuildProjectDirectory)\build.sh $(BuildArgs)" Importance="High"/>
Expand Down Expand Up @@ -51,15 +51,18 @@
<HostFiles Include="ijwhost">
<FileDescription>.NET Core IJW Host</FileDescription>
</HostFiles>
<HostFiles Include="nethost">
<FileDescription>.NET Core Component Host</FileDescription>
</HostFiles>
</ItemGroup>

<MSBuild Projects="$(MSBuildProjectFullPath)"
Properties="GenerateNativeVersionInfo=true;FileDescription=%(HostFiles.FileDescription);NativeVersionFileDir=$(IntermediateOutputRootPath)hostResourceFiles\%(HostFiles.Identity);NativeVersionHeaderFile=$(IntermediateOutputRootPath)hostResourceFiles\%(HostFiles.Identity)\version_info.h"
Targets="GenerateVersionHeader"
Targets="GenerateVersionHeader"
Condition="'$(IncrementalNativeBuild)' != 'true'"/>
<PropertyGroup>
<BuildArgs>$(ConfigurationGroup) $(TargetArchitecture) apphostver $(AppHostVersion) hostver $(HostVersion) fxrver $(HostResolverVersion) policyver $(HostPolicyVersion) commit $(LatestCommit) rid $(OutputRid)</BuildArgs>
<BuildArgs Condition="'$(PortableBuild)' == 'true'">$(BuildArgs) portable</BuildArgs>
<BuildArgs Condition="'$(PortableBuild)' == 'true'">$(BuildArgs) portable</BuildArgs>
<BuildArgs Condition="'$(IncrementalNativeBuild)' == 'true'">$(BuildArgs) incremental-native-build</BuildArgs>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/corehost/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ if [ $__CrossBuild == 1 ]; then
fi
export TARGET_BUILD_ARCH=$__build_arch_lowcase
export __DistroRid=$__rid_plat
cmake "$DIR" -G "Unix Makefiles" $__cmake_defines -DCLI_CMAKE_HOST_VER:STRING=$__host_ver -DCLI_CMAKE_APPHOST_VER:STRING=$__apphost_ver -DCLI_CMAKE_HOST_FXR_VER:STRING=$__fxr_ver -DCLI_CMAKE_HOST_POLICY_VER:STRING=$__policy_ver -DCLI_CMAKE_PKG_RID:STRING=$__base_rid -DCLI_CMAKE_COMMIT_HASH:STRING=$__commit_hash -DCMAKE_INSTALL_PREFIX=$__cmake_bin_prefix -DCMAKE_TOOLCHAIN_FILE=$DIR/../../cross/toolchain.cmake
cmake "$DIR" -G "Unix Makefiles" $__cmake_defines -DCLI_CMAKE_HOST_VER:STRING=$__host_ver -DCLI_CMAKE_COMMON_HOST_VER:STRING=$__apphost_ver -DCLI_CMAKE_HOST_FXR_VER:STRING=$__fxr_ver -DCLI_CMAKE_HOST_POLICY_VER:STRING=$__policy_ver -DCLI_CMAKE_PKG_RID:STRING=$__base_rid -DCLI_CMAKE_COMMIT_HASH:STRING=$__commit_hash -DCMAKE_INSTALL_PREFIX=$__cmake_bin_prefix -DCMAKE_TOOLCHAIN_FILE=$DIR/../../cross/toolchain.cmake
else
cmake "$DIR" -G "Unix Makefiles" $__cmake_defines -DCLI_CMAKE_HOST_VER:STRING=$__host_ver -DCLI_CMAKE_APPHOST_VER:STRING=$__apphost_ver -DCLI_CMAKE_HOST_FXR_VER:STRING=$__fxr_ver -DCLI_CMAKE_HOST_POLICY_VER:STRING=$__policy_ver -DCLI_CMAKE_PKG_RID:STRING=$__base_rid -DCLI_CMAKE_COMMIT_HASH:STRING=$__commit_hash -DCMAKE_INSTALL_PREFIX=$__cmake_bin_prefix
cmake "$DIR" -G "Unix Makefiles" $__cmake_defines -DCLI_CMAKE_HOST_VER:STRING=$__host_ver -DCLI_CMAKE_COMMON_HOST_VER:STRING=$__apphost_ver -DCLI_CMAKE_HOST_FXR_VER:STRING=$__fxr_ver -DCLI_CMAKE_HOST_POLICY_VER:STRING=$__policy_ver -DCLI_CMAKE_PKG_RID:STRING=$__base_rid -DCLI_CMAKE_COMMIT_HASH:STRING=$__commit_hash -DCMAKE_INSTALL_PREFIX=$__cmake_bin_prefix
fi
Comment thread
elinor-fung marked this conversation as resolved.
popd

Expand Down
1 change: 1 addition & 0 deletions src/corehost/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_subdirectory(apphost)
add_subdirectory(dotnet)
add_subdirectory(fxr)
add_subdirectory(hostpolicy)
add_subdirectory(nethost)
add_subdirectory(test_fx_ver)

add_subdirectory(test)
Expand Down
7 changes: 0 additions & 7 deletions src/corehost/cli/comhost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ endif()

include(../lib.cmake)

# Move to setup.cmake if COMHOST is ever built on non-Windows
if("${CLI_CMAKE_COMHOST_VER}" STREQUAL "")
message(FATAL_ERROR "comhost version is not specified")
else()
add_definitions(-DLIBHOST_PKG_VER="${CLI_CMAKE_COMHOST_VER}")
endif()

add_definitions(-DFEATURE_LIBHOST=1)

# Specify non-default Windows libs to be used for Arm/Arm64 builds
Expand Down
6 changes: 3 additions & 3 deletions src/corehost/cli/comhost/comhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace
{
get_comhost_error_stream() << msg;
}

int get_com_activation_delegate(pal::string_t *app_path, com_activation_fn *delegate)
{
pal::string_t host_path;
Expand All @@ -74,7 +74,7 @@ namespace

pal::string_t dotnet_root;
pal::string_t fxr_path;
if (!resolve_fxr_path(get_directory(host_path), &dotnet_root, &fxr_path))
if (!fxr_resolver::try_get_path(get_directory(host_path), &dotnet_root, &fxr_path))
{
return StatusCode::CoreHostLibMissingFailure;
}
Expand Down Expand Up @@ -130,7 +130,7 @@ COM_API HRESULT STDMETHODCALLTYPE DllGetClassObject(
{
trace::setup();
reset_comhost_error_stream();

error_writer_scope_t writer_scope(comhost_error_writer);

int ec = get_com_activation_delegate(&app_path, &act);
Expand Down
20 changes: 8 additions & 12 deletions src/corehost/cli/fxr_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "pal.h"
#include <pal.h>
#include "fxr_resolver.h"
#include "error_codes.h"
#include "fx_ver.h"
#include "trace.h"
#include "utils.h"
#include <fx_ver.h>
#include <trace.h>
#include <utils.h>

namespace
{
{
bool get_latest_fxr(pal::string_t fxr_root, pal::string_t* out_fxr_path)
{
trace::info(_X("Reading fx resolver directory=[%s]"), fxr_root.c_str());
Expand Down Expand Up @@ -54,20 +53,19 @@ namespace
}
}

bool resolve_fxr_path(const pal::string_t& root_path, pal::string_t* out_dotnet_root, pal::string_t* out_fxr_path)
bool fxr_resolver::try_get_path(const pal::string_t& root_path, pal::string_t* out_dotnet_root, pal::string_t* out_fxr_path)
{
pal::string_t fxr_dir;
#if FEATURE_APPHOST || FEATURE_LIBHOST
// If a hostfxr exists in app_root, then assume self-contained.
if (library_exists_in_dir(root_path, LIBFXR_NAME, out_fxr_path))
// If a hostfxr exists in root_path, then assume self-contained.
if (root_path.length() > 0 && library_exists_in_dir(root_path, LIBFXR_NAME, out_fxr_path))
{
trace::info(_X("Resolved fxr [%s]..."), out_fxr_path->c_str());
out_dotnet_root->assign(root_path);
return true;
}

// For framework-dependent apps, use DOTNET_ROOT

pal::string_t default_install_location;
pal::string_t dotnet_root_env_var_name = get_dotnet_root_env_var_name();
if (get_file_path_from_env(dotnet_root_env_var_name.c_str(), out_dotnet_root))
Expand All @@ -86,8 +84,6 @@ bool resolve_fxr_path(const pal::string_t& root_path, pal::string_t* out_dotnet_
trace::error(_X("A fatal error occurred, the default install location cannot be obtained."));
return false;
}
trace::info(_X("Using default installation location [%s] as runtime location."), default_install_location.c_str());
out_dotnet_root->assign(default_install_location);
Comment thread
sdmaclea marked this conversation as resolved.
}

fxr_dir = *out_dotnet_root;
Expand Down
5 changes: 4 additions & 1 deletion src/corehost/cli/fxr_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include <pal.h>

bool resolve_fxr_path(const pal::string_t& host_path, pal::string_t* out_dotnet_root, pal::string_t* out_fxr_path);
namespace fxr_resolver
{
bool try_get_path(const pal::string_t& root_path, pal::string_t* out_dotnet_root, pal::string_t* out_fxr_path);
}

#endif //_COREHOST_CLI_FXR_RESOLVER_H_
7 changes: 0 additions & 7 deletions src/corehost/cli/ijwhost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ if(WIN32)
Exports.def)
endif()

# Move to setup.cmake if IJWHOST is ever built on non-Windows
if("${CLI_CMAKE_IJWHOST_VER}" STREQUAL "")
message(FATAL_ERROR "ijwhost version is not specified")
else()
add_definitions(-DLIBHOST_PKG_VER="${CLI_CMAKE_IJWHOST_VER}")
endif()

set (ASM_HELPERS_SOURCES
${ARCH_SPECIFIC_FOLDER_NAME}/asmhelpers.asm)

Expand Down
4 changes: 2 additions & 2 deletions src/corehost/cli/ijwhost/ijwhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pal::hresult_t get_load_in_memory_assembly_delegate(pal::dll_t handle, load_in_m

pal::string_t dotnet_root;
pal::string_t fxr_path;
if (!resolve_fxr_path(get_directory(host_path), &dotnet_root, &fxr_path))
if (!fxr_resolver::try_get_path(get_directory(host_path), &dotnet_root, &fxr_path))
{
return StatusCode::CoreHostLibMissingFailure;
}
Expand All @@ -61,7 +61,7 @@ pal::hresult_t get_load_in_memory_assembly_delegate(pal::dll_t handle, load_in_m
trace::error(_X("Failed to resolve full path of the current mixed-mode module [%s]"), host_path.c_str());
return StatusCode::LibHostCurExeFindFailure;
}

return get_delegate_from_hostfxr(host_path.c_str(), dotnet_root.c_str(), app_path.c_str(), hostfxr_delegate_type::load_in_memory_assembly, (void**)delegate);
}

Expand Down
27 changes: 27 additions & 0 deletions src/corehost/cli/nethost/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.
# See the LICENSE file in the project root for more information.

cmake_minimum_required (VERSION 2.6)
project(nethost)

set(DOTNET_PROJECT_NAME "nethost")

# Include directories
include_directories(../fxr)

# CMake does not recommend using globbing since it messes with the freshness checks
set(SOURCES
nethost.cpp
../fxr_resolver.cpp
../fxr/fx_ver.cpp
)

include(../lib.cmake)

add_definitions(-DFEATURE_LIBHOST=1)
add_definitions(-DNETHOST_EXPORT)

install(FILES nethost.h DESTINATION corehost)
install(TARGETS nethost DESTINATION corehost)
install_symbols(nethost corehost)
Comment thread
jkoritzinsky marked this conversation as resolved.
52 changes: 52 additions & 0 deletions src/corehost/cli/nethost/nethost.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "nethost.h"
#include <error_codes.h>
#include <fxr_resolver.h>
#include <pal.h>
#include <trace.h>
#include <utils.h>

namespace
{
// Swallow the trace messages so we don't output to stderr of a process that we do not own unless tracing is enabled.
void swallow_trace(const pal::char_t* msg)
{
(void)msg;
}
}

NETHOST_API int NETHOST_CALLTYPE nethost_get_hostfxr_path(
char_t * result_buffer,
size_t buffer_size,
size_t * out_buffer_required_size,
const char_t * assembly_path)
{
if (out_buffer_required_size == nullptr)
Comment thread
elinor-fung marked this conversation as resolved.
return StatusCode::InvalidArgFailure;

trace::setup();
error_writer_scope_t writer_scope(swallow_trace);

pal::string_t root_path;
if (assembly_path != nullptr)
root_path = get_directory(assembly_path);

pal::string_t dotnet_root;
pal::string_t fxr_path;
if(!fxr_resolver::try_get_path(root_path, &dotnet_root, &fxr_path))
return StatusCode::CoreHostLibMissingFailure;

size_t len = fxr_path.length();
size_t required_size = len + 1; // null terminator

*out_buffer_required_size = required_size;
if (result_buffer == nullptr || buffer_size < required_size)
return StatusCode::HostApiBufferTooSmall;

fxr_path.copy(result_buffer, len);
result_buffer[len] = '\0';
return StatusCode::Success;
}
67 changes: 67 additions & 0 deletions src/corehost/cli/nethost/nethost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#ifndef __NETHOST_H__
#define __NETHOST_H__

#include <cstddef>

#if defined(_WIN32)
#ifdef NETHOST_EXPORT
#define NETHOST_API __declspec(dllexport)
#else
#define NETHOST_API __declspec(dllimport)
#endif

#define NETHOST_CALLTYPE __stdcall
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from all the other libraries (hostfxr/hostpolicy) which I think use _cdecl. @AaronRobinsonMSFT is the expert here.
I'm not against this - I think having __stdcall is better for interoperability (Which is the main goal here) - I just want to make sure that this is intentional and intentionally different.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitek-karas Bah... Yes, you are right. The rest of the core-setup API is __cdecl. I agree that using __stdcall is more consistent with coreclr.dll, comhost, ijwhost, and the proposed winrthost exports. I will say this is annoying since all of hostpolicy and hostfxr are __cdecl. So much annoyance here. Thanks for pointing this out. I think we should keep with __stdcall since it aligns with all non "internal" core-setup scenarios better. I consider interacting directly with hostfxr and hostpolicy more "internal" or at the very least "advanced" as compared to COM, IJW, WinRT, and the native loading scenarios which users could experiment with.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - and I like the consistency among the "public" hosts. hostpolicy is not going to be used externally (it's just too hard to use directly). hostfxr uses will be advanced and so some complexity is OK.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elinor-fung In a previous review @vitek-karas mentioned the need for documentation of these kinds of contracts. I think the fact that we are starting to coalesce around common user scenarios using __stdcall on x86 is an important contract that should be documented and officially defined. I have observed you reading through the documentation of core-setup, is there an existing doc that could contain these kind of details or is a new one needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say we need a new one. Maybe what gets created for #5481 would be a reasonable place (if it is a doc for all exposed APIs - I could also see doing a separate 'advanced' hostfxr/hostpolicy doc and 'public' *host doc)

#ifdef _WCHAR_T_DEFINED
using char_t = wchar_t;
#else
using char_t = unsigned short;
#endif
#else
#ifdef NETHOST_EXPORT
#define NETHOST_API __attribute__((__visibility__("default")))
#else
#define NETHOST_API
#endif

#define NETHOST_CALLTYPE
using char_t = char;
#endif

//
// Get the path to the hostfxr library
//
// Parameters:
// result_buffer
// Buffer that will be populated with the hostfxr path, including a null terminator.
//
// buffer_size
// Size of result_buffer in char_t units
//
// out_buffer_required_size
// Minimum required size in char_t units for a buffer to hold the hostfxr path
//
// assembly_path
// Optional. Path to the compenent's assembly. Whether or not this is specified
// determines the behaviour for locating the hostfxr library.
// If nullptr, hostfxr is located using the enviroment variable or global registration
// If specified, hostfxr is located as if the assembly_path is the apphost
//
// Return value:
// 0 on success, otherwise failure
// 0x80008098 - result_buffer is too small (HostApiBufferTooSmall)
//
// Remarks:
// The full search for the hostfxr library is done on every call. To minimize the need
// to call this function multiple times, pass a large result_buffer (e.g. PATH_MAX).
//
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 - it's great that you wrote this as a header which we can give out to external users of the library.

extern "C" NETHOST_API int NETHOST_CALLTYPE nethost_get_hostfxr_path(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it expected that native hosters carry this dll with them rather than it being app local? Ex if I have a global module, and I wanted to find hostfxr, I would need to have nethost.dll sit side by side with my global module?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the expectation is that a native host application will ship this library as part of the application itself.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need a bit of clarification. The expectation is that a published app will contain the nethost.dll, like:

published/
    nethost.dll
    myapp.dll

Also, is the nethost.dll opt-in or opt-out?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nethost.dll is to be part of the native host - so in the case of ASP.NET it will be part of the ASP.NET IIS module.

  • .NET Core app doesn't need it, since the apphost or muxer will find the hostfxr for it and if it needs the path to hostfxr at runtime it can simply ask for already loaded module.
  • non .NET Core app which uses hostfxr to host .NET Core (this is what we call "native host") will include it in itself.

Basically the ASP.NET IIS module has the "locate hostfxr" code copied into it today, with this it would just carry it as a separate dll.

We don't have a delivery vehicle yet, but we're thinking native (C/C++) NuGet package and probably just raw .zip with the library and header file for all other cases (Linux/macOS, non-C/C++ languages).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our IIS module today installs via an msi, so I'd imagine we should probably include it SxS with the module.

Once we get new bits from core-setup, I will start prototyping and see if all scenarios we used to support still work with nethost.dll.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotalik Just to clarify for me

include it SxS with the module

This means that you would package the nethost with your module and install it into the same folder on the target machine... right?

Re the compatibility - if that's not the case (that is you find a case where it works differently then your existing code), please let us know. It's using the same code as apphost and so if there's a problem in nethost it's likely there is a problem in the other "hosts" as well.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that you would package the nethost with your module and install it into the same folder on the target machine... right?

Yes I believe that is the best course of action.

Re the compatibility - if that's not the case (that is you find a case where it works differently then your existing code), please let us know. It's using the same code as apphost and so if there's a problem in nethost it's likely there is a problem in the other "hosts" as well.

I'm less concerned about that than some of the backups we did. For example, if all else fails with finding dotnet, we search in C:\PF\dotnet as a backup. So we will see!

char_t * result_buffer,
size_t buffer_size,
size_t * out_buffer_required_size,
const char_t * assembly_path);

#endif // __NETHOST_H__
Loading