Skip to content

Convert fxr_resolver and its hostmisc dependencies to C - #129480

Merged
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c
Jun 22, 2026
Merged

Convert fxr_resolver and its hostmisc dependencies to C#129480
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c

Conversation

@elinor-fung

@elinor-fungelinor-fung commented Jun 16, 2026

Copy link
Copy Markdown
Member

This is another slice of breaking up #126367. It continues the conversion of the corehost stack from C++ to C, building on top of #128420 (which converted trace and fx_ver). This converts fxr_resolver and the hostmisc PAL/utils helpers that fxr_resolver depends on.

cc @dotnet/appmodel @AaronRobinsonMSFT

  • fxr_resolver
    • fxr_resolver.c replaces most of fxr_resolver.cpp
    • fxr_resolver.h has the C-compatible surface
  • pal / utils
    • Adds the implementations needed by fxr_resolver.
  • Build wiring
    • Defines CLR_CMAKE_TARGET_ARCH_UPPER for an uppercase version of the arch

Windows x64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost136,704124,416−12,288−8.99%
nethost87,55271,680−15,872−18.13%
ijwhost108,03294,208−13,824−12.80%
comhost165,376151,552−13,824−8.36%
dotnet133,632123,392−10,240−7.66%

macOS arm64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost116,38495,232−21,152−18.17%
dotnet97,15294,896−2,256−2.32%
libnethost.dylib114,30492,368−21,936−19.19%

linux x64 Release

BinaryBaselineThis BranchΔ bytesΔ %
apphost73,89649,248−24,648−33.4%
dotnet56,28839,904−16,384−29.1%
libnethost.so68,02443,376−24,648−36.2%

elinor-fungand others added 10 commits June 12, 2026 15:27
Add C implementations for pal_strdup, pal_fullpath, pal_file_exists,
pal_readdir_onlydirectories (callback-based), and pal_is_running_in_wow64.
These are the simple pal helpers fxr_resolver needs that can be converted
before the install-location and utils helpers.
Rewrite the corresponding pal::* C++ functions as thin delegating wrappers
around the new C helpers, preserving the existing namespace and default
parameter on pal::fullpath for C++ callers (deps_format.cpp etc).
pal::realpath and the pattern overload of pal::readdir_onlydirectories
remain unchanged (no current C consumer).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add C-callable versions of the no-arch install-location pal helpers used by
fxr_resolver, plus a small C shim for the test-only env override:
- pal_get_dotnet_self_registered_dir
- pal_get_default_installation_dir
- pal_get_dotnet_self_registered_config_location
- pal_is_emulating_x64
- utils_test_only_getenv (delegates to C++ test_only_getenv)
The C++ no-arch pal::* overloads become thin wrappers around the new C
helpers. The arch-explicit *_for_arch overloads (still used by
install_info.cpp) are left untouched.
The _STRINGIFY macro and configure.h include are moved up to the shared
section of pal.h (before extern ""C"") so the new C files can use
_STRINGIFY(CURRENT_ARCH_NAME) to embed the build-time architecture name
without duplicating the definitions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- utils_append_path
- utils_file_exists_in_dir_alloc
- utils_get_directory_alloc
- utils_get_dotnet_root_env_var_for_current_arch
- utils_get_file_path_from_env
- utils_get_dotnet_root_from_env
- utils_get_download_url (C-callable shim around the existing C++ impl)
C++ counterparts in utils.cpp become thin wrappers around the new C helpers
where the data shape allows. append_path and get_dotnet_root_env_var_for_arch
keep their existing C++ implementations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- get_latest_fxr (static)
- fxr_resolver_try_get_path
- fxr_resolver_try_get_path_from_dotnet_root
try_get_existing_fxr stays in C++ because pal::get_loaded_library is a templated helper. The C++ namespace members in fxr_resolver.cpp become thin wrappers around the new C entry points.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the grow-style append_str helper (repeated realloc) with a stack-allocated array of string fragments that is concatenated in a single pass. The size and copy loops walk the parts array once each, giving a clear three-phase structure: collect parts -> compute size -> copy.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pal.unix.c install-location helpers:
- Inline compose_install_location_file_path into its only caller.
- Simplify pal_get_dotnet_self_registered_dir: in-place truncation of
the "_<arch>" suffix, single cleanup path, rename `ok` to `success`,
assert that file_found is true on success.
- Remove ascii_lower_dup helper.
- Drop private join_path_alloc in favor of utils_append_path_alloc.
pal.windows.c registry helpers:
- get_dotnet_install_location_registry_path and format_registry_path
use pal_str_printf instead of hand-rolled memcpy concatenation.
- get_dotnet_install_location_registry_path inlines the suffix into the
format string and uses STRING_LENGTH for the compile-time size,
matching format_registry_path's pattern.
pal_char_t string ops:
- Use pal_strlen instead of bare wcslen/strlen on pal_char_t* values
in pal.windows.c and pal.unix.c.
utils:
- Add utils_append_path_alloc (delegates to utils_append_path).
- Rename utils_file_exists_in_dir_alloc -> utils_find_file_in_dir and
utils_get_directory_alloc -> utils_get_directory (no non-alloc twin).
- Change utils_get_filename to return void; sole caller already used
the empty-string sentinel for failure.
- Rename utils_append_path parameters to path_buffer/path_buffer_len.
- Add asserts on the overflow paths in utils_append_path and
utils_get_filename.
- utils_append_path: merge the empty-buffer special case into the
unified flow (single overflow check, no early return).
- utils_get_directory: build the result up front and use pal_strrchr
on the working copy after trimming trailing separators.
- utils_get_file_path_from_env: rename the env getenv result to
env_value and the canonicalized path to file_path.
fxr_resolver.c:
- Rename emit_missing_runtime_error -> print_missing_runtime_error.
Doc cleanups:
- "NUL-terminated" -> "null-terminated" across pal.h, trace.c, utils.h,
and an inline comment in utils.c.
- Rewrite the doc comment on get_dotnet_install_location_registry_path
in pal.windows.c.
- Trim a few obvious comments in utils.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the test-only environment variable helper to utils.c as
utils_test_only_getenv. The C++ test_only_getenv now wraps the C
version, so existing C++ callers (pal.unix.cpp, pal.windows.cpp) are
unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add utils_get_download_url and utils_get_runtime_id in C, and reduce
the C++ versions to thin wrappers around them. fxr_resolver.c now
writes into a stack-allocated MAX_DOWNLOAD_URL_LEN buffer instead of
allocating with malloc.
The C download URL drops runtime OS detection (was
pal_get_current_os_rid_platform on Linux); the URL now always uses the
build-time FALLBACK_HOST_OS, which is acceptable since it is purely
informational and aka.ms accepts either form.
Move HOST_RID_PLATFORM out of the C++-only section of pal.h so the C
implementations can use it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The C++ pal::readdir_onlydirectories normalized the directory path via
LongFile::ShouldNormalize + pal::fullpath before enumerating. When the
single-arg overload was re-pointed at the new C pal_readdir_onlydirectories,
that normalization was lost, so enumerating version-numbered folders under a
long (>= MAX_PATH) or not-fully-qualified fxr root would fail where it
previously succeeded.
Replicate the ShouldNormalize gate in C (is_path_not_fully_qualified /
should_normalize_path) and canonicalize via pal_fullpath before building the
FindFirstFileExW search string. Also add named defines for the long-path
prefixes and path separators and reuse them across is_path_normalized,
pal_fullpath, and is_path_not_fully_qualified.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The singlefilehost is built from the coreclr tree (src/coreclr/CMakeLists.txt),
which runs apphost/static/CMakeLists.txt's own configure_file for configure.h.in.
CLR_CMAKE_TARGET_ARCH_UPPER was only set in corehost/CMakeLists.txt, so it was
empty in this scope, making CURRENT_ARCH_NAME_UPPER empty and degrading
DOTNET_ROOT_<ARCH> to DOTNET_ROOT_ for single-file apps. Compute the uppercase
arch in the static path before configuring the header.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the corehost C-conversion work by introducing a C implementation of fxr_resolver and expanding the C PAL/utils surface that fxr_resolver depends on, while keeping the existing C++ entry points as thin wrappers.

Changes:

  • Add fxr_resolver.c (C implementation) and update fxr_resolver.{h,cpp} to expose a C API and delegate from the C++ wrapper layer.
  • Expand hostmisc C helpers in utils.c and implement additional PAL functionality in pal.{unix,windows}.c, updating the C++ PAL wrappers to call into the new C APIs.
  • Wire the new C sources into corehost and singlefilehost builds; extend generated configure.h with CURRENT_ARCH_NAME_UPPER.
Show a summary per file
FileDescription
src/native/corehost/hostmisc/utils.hAdds C-callable utils declarations and DOTNET_ROOT_<ARCH> env-var macro for C consumers.
src/native/corehost/hostmisc/utils.cppSwitches C++ helpers to call C utils_* implementations and manage returned allocations.
src/native/corehost/hostmisc/utils.cImplements additional C utils_* helpers needed by fxr_resolver (path ops, env lookup, download URL, RID).
src/native/corehost/hostmisc/trace.cSmall comment tweak; continues using utils_get_filename from C utils.
src/native/corehost/hostmisc/pal.windows.cppUpdates C++ PAL to delegate to new Windows C PAL APIs (paths, readdir-only-dirs, WOW64/emulation, install roots).
src/native/corehost/hostmisc/pal.windows.cAdds Windows C PAL functionality used by C host code (fullpath, file exists, registry install location, etc.).
src/native/corehost/hostmisc/pal.unix.cppUpdates C++ PAL to delegate to new Unix C PAL APIs (fullpath, readdir-only-dirs, install roots).
src/native/corehost/hostmisc/pal.unix.cAdds Unix C PAL functionality used by C host code (fullpath, readdir-only-dirs, install roots, Rosetta detection).
src/native/corehost/hostmisc/pal.hExtends the C-callable PAL surface and moves some shared macros/config includes into the C section.
src/native/corehost/fxr_resolver.hIntroduces C ABI for fxr resolver search flags and functions; maps C++ enum to C enum values.
src/native/corehost/fxr_resolver.cppBecomes a C++ shim that marshals to fxr_resolver.c.
src/native/corehost/fxr_resolver.cNew C implementation of fxr resolution + missing-runtime error composition.
src/native/corehost/configure.h.inAdds CURRENT_ARCH_NAME_UPPER for arch-specific env-var naming.
src/native/corehost/CMakeLists.txtEnsures CLR_CMAKE_TARGET_ARCH_UPPER is computed and builds fxr_resolver.c alongside the C++ wrapper.
src/native/corehost/apphost/static/CMakeLists.txtComputes CLR_CMAKE_TARGET_ARCH_UPPER and compiles fxr_resolver.c into singlefilehost.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 3

Comment threadsrc/native/corehost/fxr_resolver.c
Comment threadsrc/native/corehost/fxr_resolver.c Outdated
Comment threadsrc/native/corehost/hostmisc/pal.windows.c
…ARATOR
Guard NULL registered_config_location and the message-buffer malloc in print_missing_runtime_error so the missing-runtime diagnostic degrades gracefully on OOM instead of dereferencing NULL. Remove the redundant DIR_SEPARATOR redefinition in pal.windows.c and use the one from pal.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 4

Comment threadsrc/native/corehost/hostmisc/utils.cpp
Comment threadsrc/native/corehost/hostmisc/trace.c
Comment threadsrc/native/corehost/hostmisc/pal.h
Comment threadsrc/native/corehost/hostmisc/utils.c Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 17, 2026 21:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 2

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/fxr_resolver.c
CopilotAI review requested due to automatic review settings June 17, 2026 21:22

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 1

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/hostmisc/pal.h Outdated
Comment threadsrc/native/corehost/fxr_resolver.c
…ert dotnet_root, merge wow64/emulation into pal_get_process_emulation enum
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@elinor-fung

Copy link
Copy Markdown
MemberAuthor

/ba-g unrelated win-arm64 timeouts

@elinor-fung
elinor-fung merged commit fc23f44 into dotnet:mainJun 22, 2026
175 of 183 checks passed
@elinor-fung
elinor-fung deleted the fxr-resolver-c branch June 22, 2026 17:33
elinor-fung added a commit that referenced this pull request Jun 22, 2026
Reconcile the apphost-in-C rewrite with the smaller C conversions that were
extracted from this branch and merged separately upstream:
- #128420 Convert corehost hostmisc trace and fx_ver to C
- #129480 Convert fxr_resolver and its hostmisc dependencies to C
Adopt upstream's now-merged C conversions (trace.c, fx_ver.c, fxr_resolver.c,
pal.unix.c/pal.windows.c, utils.c and their headers) and drop this branch's
redundant/divergent copies (hostmisc/fxr_resolver.c, pal.windows.c_impl.cpp,
hostmisc_c object library). Keep only the apphost-in-C delta on top:
apphost/apphost.c, apphost_hostfxr_resolver.{c,cpp,h}, dotnet/dotnet.cpp
(replacing corehost.cpp) and bundle_marker.c.
Adapt the apphost C layer to upstream's allocating C API (pal_get_own_executable_path,
pal_fullpath, utils_get_directory) and add the few apphost-only C helpers upstream
lacked: pal_load_library/unload_library/get_symbol/is_path_fully_qualified/utf8_to_palstr
(extern "C" wrappers in pal.windows.cpp/pal.unix.cpp) and utils_get_current_arch_name/
utils_get_host_version_description. Wire standalone apphost to link hostmisc+fxr_resolver
like dotnet, and singlefilehost to use apphost.c.
Validated: standalone apphost, dotnet, and singlefilehost all compile and link.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 23, 2026
@elinor-fungelinor-fung mentioned this pull request Jun 25, 2026
elinor-fung added a commit that referenced this pull request Jul 2, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
This is another slice of breaking up #126367. It continues the
conversion of the corehost stack from C++ to C, building on top of
#128420 (which converted `trace` and `fx_ver`). This converts
`fxr_resolver` and the `hostmisc` PAL/utils helpers that `fxr_resolver`
depends on.
- **`fxr_resolver`**
- `fxr_resolver.c` replaces most of `fxr_resolver.cpp`
- `fxr_resolver.h` has the C-compatible surface
- **pal** / **utils**
- Adds the implementations needed by `fxr_resolver`. - **Build wiring**
- Defines `CLR_CMAKE_TARGET_ARCH_UPPER` for an uppercase version of the
arch
**Windows x64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 136,704 | 124,416 | −12,288 | −8.99% |
| nethost | 87,552 | 71,680 | −15,872 | −18.13% |
| ijwhost | 108,032 | 94,208 | −13,824 | −12.80% |
| comhost | 165,376 | 151,552 | −13,824 | −8.36% |
| dotnet | 133,632 | 123,392 | −10,240 | −7.66% |
**macOS arm64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 116,384 | 95,232 | −21,152 | −18.17% |
| dotnet | 97,152 | 94,896 | −2,256 | −2.32% |
| libnethost.dylib | 114,304 | 92,368 | −21,936 | −19.19% |
**linux x64 Release**
| Binary | Baseline | This Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 73,896 | 49,248 | −24,648 | −33.4% |
| dotnet | 56,288 | 39,904 | −16,384 | −29.1% |
| libnethost.so | 68,024 | 43,376 | −24,648 | −36.2% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@elinor-fung@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Convert fxr_resolver and its hostmisc dependencies to C by elinor-fung · Pull Request #129480 · dotnet/runtime · GitHub
Skip to content

Convert fxr_resolver and its hostmisc dependencies to C - #129480

Merged
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c
Jun 22, 2026
Merged

Convert fxr_resolver and its hostmisc dependencies to C#129480
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c

Conversation

@elinor-fung

@elinor-fungelinor-fung commented Jun 16, 2026

Copy link
Copy Markdown
Member

This is another slice of breaking up #126367. It continues the conversion of the corehost stack from C++ to C, building on top of #128420 (which converted trace and fx_ver). This converts fxr_resolver and the hostmisc PAL/utils helpers that fxr_resolver depends on.

cc @dotnet/appmodel @AaronRobinsonMSFT

  • fxr_resolver
    • fxr_resolver.c replaces most of fxr_resolver.cpp
    • fxr_resolver.h has the C-compatible surface
  • pal / utils
    • Adds the implementations needed by fxr_resolver.
  • Build wiring
    • Defines CLR_CMAKE_TARGET_ARCH_UPPER for an uppercase version of the arch

Windows x64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost136,704124,416−12,288−8.99%
nethost87,55271,680−15,872−18.13%
ijwhost108,03294,208−13,824−12.80%
comhost165,376151,552−13,824−8.36%
dotnet133,632123,392−10,240−7.66%

macOS arm64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost116,38495,232−21,152−18.17%
dotnet97,15294,896−2,256−2.32%
libnethost.dylib114,30492,368−21,936−19.19%

linux x64 Release

BinaryBaselineThis BranchΔ bytesΔ %
apphost73,89649,248−24,648−33.4%
dotnet56,28839,904−16,384−29.1%
libnethost.so68,02443,376−24,648−36.2%

elinor-fungand others added 10 commits June 12, 2026 15:27
Add C implementations for pal_strdup, pal_fullpath, pal_file_exists,
pal_readdir_onlydirectories (callback-based), and pal_is_running_in_wow64.
These are the simple pal helpers fxr_resolver needs that can be converted
before the install-location and utils helpers.
Rewrite the corresponding pal::* C++ functions as thin delegating wrappers
around the new C helpers, preserving the existing namespace and default
parameter on pal::fullpath for C++ callers (deps_format.cpp etc).
pal::realpath and the pattern overload of pal::readdir_onlydirectories
remain unchanged (no current C consumer).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add C-callable versions of the no-arch install-location pal helpers used by
fxr_resolver, plus a small C shim for the test-only env override:
- pal_get_dotnet_self_registered_dir
- pal_get_default_installation_dir
- pal_get_dotnet_self_registered_config_location
- pal_is_emulating_x64
- utils_test_only_getenv (delegates to C++ test_only_getenv)
The C++ no-arch pal::* overloads become thin wrappers around the new C
helpers. The arch-explicit *_for_arch overloads (still used by
install_info.cpp) are left untouched.
The _STRINGIFY macro and configure.h include are moved up to the shared
section of pal.h (before extern ""C"") so the new C files can use
_STRINGIFY(CURRENT_ARCH_NAME) to embed the build-time architecture name
without duplicating the definitions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- utils_append_path
- utils_file_exists_in_dir_alloc
- utils_get_directory_alloc
- utils_get_dotnet_root_env_var_for_current_arch
- utils_get_file_path_from_env
- utils_get_dotnet_root_from_env
- utils_get_download_url (C-callable shim around the existing C++ impl)
C++ counterparts in utils.cpp become thin wrappers around the new C helpers
where the data shape allows. append_path and get_dotnet_root_env_var_for_arch
keep their existing C++ implementations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- get_latest_fxr (static)
- fxr_resolver_try_get_path
- fxr_resolver_try_get_path_from_dotnet_root
try_get_existing_fxr stays in C++ because pal::get_loaded_library is a templated helper. The C++ namespace members in fxr_resolver.cpp become thin wrappers around the new C entry points.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the grow-style append_str helper (repeated realloc) with a stack-allocated array of string fragments that is concatenated in a single pass. The size and copy loops walk the parts array once each, giving a clear three-phase structure: collect parts -> compute size -> copy.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pal.unix.c install-location helpers:
- Inline compose_install_location_file_path into its only caller.
- Simplify pal_get_dotnet_self_registered_dir: in-place truncation of
the "_<arch>" suffix, single cleanup path, rename `ok` to `success`,
assert that file_found is true on success.
- Remove ascii_lower_dup helper.
- Drop private join_path_alloc in favor of utils_append_path_alloc.
pal.windows.c registry helpers:
- get_dotnet_install_location_registry_path and format_registry_path
use pal_str_printf instead of hand-rolled memcpy concatenation.
- get_dotnet_install_location_registry_path inlines the suffix into the
format string and uses STRING_LENGTH for the compile-time size,
matching format_registry_path's pattern.
pal_char_t string ops:
- Use pal_strlen instead of bare wcslen/strlen on pal_char_t* values
in pal.windows.c and pal.unix.c.
utils:
- Add utils_append_path_alloc (delegates to utils_append_path).
- Rename utils_file_exists_in_dir_alloc -> utils_find_file_in_dir and
utils_get_directory_alloc -> utils_get_directory (no non-alloc twin).
- Change utils_get_filename to return void; sole caller already used
the empty-string sentinel for failure.
- Rename utils_append_path parameters to path_buffer/path_buffer_len.
- Add asserts on the overflow paths in utils_append_path and
utils_get_filename.
- utils_append_path: merge the empty-buffer special case into the
unified flow (single overflow check, no early return).
- utils_get_directory: build the result up front and use pal_strrchr
on the working copy after trimming trailing separators.
- utils_get_file_path_from_env: rename the env getenv result to
env_value and the canonicalized path to file_path.
fxr_resolver.c:
- Rename emit_missing_runtime_error -> print_missing_runtime_error.
Doc cleanups:
- "NUL-terminated" -> "null-terminated" across pal.h, trace.c, utils.h,
and an inline comment in utils.c.
- Rewrite the doc comment on get_dotnet_install_location_registry_path
in pal.windows.c.
- Trim a few obvious comments in utils.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the test-only environment variable helper to utils.c as
utils_test_only_getenv. The C++ test_only_getenv now wraps the C
version, so existing C++ callers (pal.unix.cpp, pal.windows.cpp) are
unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add utils_get_download_url and utils_get_runtime_id in C, and reduce
the C++ versions to thin wrappers around them. fxr_resolver.c now
writes into a stack-allocated MAX_DOWNLOAD_URL_LEN buffer instead of
allocating with malloc.
The C download URL drops runtime OS detection (was
pal_get_current_os_rid_platform on Linux); the URL now always uses the
build-time FALLBACK_HOST_OS, which is acceptable since it is purely
informational and aka.ms accepts either form.
Move HOST_RID_PLATFORM out of the C++-only section of pal.h so the C
implementations can use it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The C++ pal::readdir_onlydirectories normalized the directory path via
LongFile::ShouldNormalize + pal::fullpath before enumerating. When the
single-arg overload was re-pointed at the new C pal_readdir_onlydirectories,
that normalization was lost, so enumerating version-numbered folders under a
long (>= MAX_PATH) or not-fully-qualified fxr root would fail where it
previously succeeded.
Replicate the ShouldNormalize gate in C (is_path_not_fully_qualified /
should_normalize_path) and canonicalize via pal_fullpath before building the
FindFirstFileExW search string. Also add named defines for the long-path
prefixes and path separators and reuse them across is_path_normalized,
pal_fullpath, and is_path_not_fully_qualified.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The singlefilehost is built from the coreclr tree (src/coreclr/CMakeLists.txt),
which runs apphost/static/CMakeLists.txt's own configure_file for configure.h.in.
CLR_CMAKE_TARGET_ARCH_UPPER was only set in corehost/CMakeLists.txt, so it was
empty in this scope, making CURRENT_ARCH_NAME_UPPER empty and degrading
DOTNET_ROOT_<ARCH> to DOTNET_ROOT_ for single-file apps. Compute the uppercase
arch in the static path before configuring the header.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the corehost C-conversion work by introducing a C implementation of fxr_resolver and expanding the C PAL/utils surface that fxr_resolver depends on, while keeping the existing C++ entry points as thin wrappers.

Changes:

  • Add fxr_resolver.c (C implementation) and update fxr_resolver.{h,cpp} to expose a C API and delegate from the C++ wrapper layer.
  • Expand hostmisc C helpers in utils.c and implement additional PAL functionality in pal.{unix,windows}.c, updating the C++ PAL wrappers to call into the new C APIs.
  • Wire the new C sources into corehost and singlefilehost builds; extend generated configure.h with CURRENT_ARCH_NAME_UPPER.
Show a summary per file
FileDescription
src/native/corehost/hostmisc/utils.hAdds C-callable utils declarations and DOTNET_ROOT_<ARCH> env-var macro for C consumers.
src/native/corehost/hostmisc/utils.cppSwitches C++ helpers to call C utils_* implementations and manage returned allocations.
src/native/corehost/hostmisc/utils.cImplements additional C utils_* helpers needed by fxr_resolver (path ops, env lookup, download URL, RID).
src/native/corehost/hostmisc/trace.cSmall comment tweak; continues using utils_get_filename from C utils.
src/native/corehost/hostmisc/pal.windows.cppUpdates C++ PAL to delegate to new Windows C PAL APIs (paths, readdir-only-dirs, WOW64/emulation, install roots).
src/native/corehost/hostmisc/pal.windows.cAdds Windows C PAL functionality used by C host code (fullpath, file exists, registry install location, etc.).
src/native/corehost/hostmisc/pal.unix.cppUpdates C++ PAL to delegate to new Unix C PAL APIs (fullpath, readdir-only-dirs, install roots).
src/native/corehost/hostmisc/pal.unix.cAdds Unix C PAL functionality used by C host code (fullpath, readdir-only-dirs, install roots, Rosetta detection).
src/native/corehost/hostmisc/pal.hExtends the C-callable PAL surface and moves some shared macros/config includes into the C section.
src/native/corehost/fxr_resolver.hIntroduces C ABI for fxr resolver search flags and functions; maps C++ enum to C enum values.
src/native/corehost/fxr_resolver.cppBecomes a C++ shim that marshals to fxr_resolver.c.
src/native/corehost/fxr_resolver.cNew C implementation of fxr resolution + missing-runtime error composition.
src/native/corehost/configure.h.inAdds CURRENT_ARCH_NAME_UPPER for arch-specific env-var naming.
src/native/corehost/CMakeLists.txtEnsures CLR_CMAKE_TARGET_ARCH_UPPER is computed and builds fxr_resolver.c alongside the C++ wrapper.
src/native/corehost/apphost/static/CMakeLists.txtComputes CLR_CMAKE_TARGET_ARCH_UPPER and compiles fxr_resolver.c into singlefilehost.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 3

Comment threadsrc/native/corehost/fxr_resolver.c
Comment threadsrc/native/corehost/fxr_resolver.c Outdated
Comment threadsrc/native/corehost/hostmisc/pal.windows.c
…ARATOR
Guard NULL registered_config_location and the message-buffer malloc in print_missing_runtime_error so the missing-runtime diagnostic degrades gracefully on OOM instead of dereferencing NULL. Remove the redundant DIR_SEPARATOR redefinition in pal.windows.c and use the one from pal.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 4

Comment threadsrc/native/corehost/hostmisc/utils.cpp
Comment threadsrc/native/corehost/hostmisc/trace.c
Comment threadsrc/native/corehost/hostmisc/pal.h
Comment threadsrc/native/corehost/hostmisc/utils.c Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 17, 2026 21:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 2

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/fxr_resolver.c
CopilotAI review requested due to automatic review settings June 17, 2026 21:22

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 1

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/hostmisc/pal.h Outdated
Comment threadsrc/native/corehost/fxr_resolver.c
…ert dotnet_root, merge wow64/emulation into pal_get_process_emulation enum
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@elinor-fung

Copy link
Copy Markdown
MemberAuthor

/ba-g unrelated win-arm64 timeouts

@elinor-fung
elinor-fung merged commit fc23f44 into dotnet:mainJun 22, 2026
175 of 183 checks passed
@elinor-fung
elinor-fung deleted the fxr-resolver-c branch June 22, 2026 17:33
elinor-fung added a commit that referenced this pull request Jun 22, 2026
Reconcile the apphost-in-C rewrite with the smaller C conversions that were
extracted from this branch and merged separately upstream:
- #128420 Convert corehost hostmisc trace and fx_ver to C
- #129480 Convert fxr_resolver and its hostmisc dependencies to C
Adopt upstream's now-merged C conversions (trace.c, fx_ver.c, fxr_resolver.c,
pal.unix.c/pal.windows.c, utils.c and their headers) and drop this branch's
redundant/divergent copies (hostmisc/fxr_resolver.c, pal.windows.c_impl.cpp,
hostmisc_c object library). Keep only the apphost-in-C delta on top:
apphost/apphost.c, apphost_hostfxr_resolver.{c,cpp,h}, dotnet/dotnet.cpp
(replacing corehost.cpp) and bundle_marker.c.
Adapt the apphost C layer to upstream's allocating C API (pal_get_own_executable_path,
pal_fullpath, utils_get_directory) and add the few apphost-only C helpers upstream
lacked: pal_load_library/unload_library/get_symbol/is_path_fully_qualified/utf8_to_palstr
(extern "C" wrappers in pal.windows.cpp/pal.unix.cpp) and utils_get_current_arch_name/
utils_get_host_version_description. Wire standalone apphost to link hostmisc+fxr_resolver
like dotnet, and singlefilehost to use apphost.c.
Validated: standalone apphost, dotnet, and singlefilehost all compile and link.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 23, 2026
@elinor-fungelinor-fung mentioned this pull request Jun 25, 2026
elinor-fung added a commit that referenced this pull request Jul 2, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
This is another slice of breaking up #126367. It continues the
conversion of the corehost stack from C++ to C, building on top of
#128420 (which converted `trace` and `fx_ver`). This converts
`fxr_resolver` and the `hostmisc` PAL/utils helpers that `fxr_resolver`
depends on.
- **`fxr_resolver`**
- `fxr_resolver.c` replaces most of `fxr_resolver.cpp`
- `fxr_resolver.h` has the C-compatible surface
- **pal** / **utils**
- Adds the implementations needed by `fxr_resolver`. - **Build wiring**
- Defines `CLR_CMAKE_TARGET_ARCH_UPPER` for an uppercase version of the
arch
**Windows x64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 136,704 | 124,416 | −12,288 | −8.99% |
| nethost | 87,552 | 71,680 | −15,872 | −18.13% |
| ijwhost | 108,032 | 94,208 | −13,824 | −12.80% |
| comhost | 165,376 | 151,552 | −13,824 | −8.36% |
| dotnet | 133,632 | 123,392 | −10,240 | −7.66% |
**macOS arm64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 116,384 | 95,232 | −21,152 | −18.17% |
| dotnet | 97,152 | 94,896 | −2,256 | −2.32% |
| libnethost.dylib | 114,304 | 92,368 | −21,936 | −19.19% |
**linux x64 Release**
| Binary | Baseline | This Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 73,896 | 49,248 | −24,648 | −33.4% |
| dotnet | 56,288 | 39,904 | −16,384 | −29.1% |
| libnethost.so | 68,024 | 43,376 | −24,648 | −36.2% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@elinor-fung@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Convert fxr_resolver and its hostmisc dependencies to C by elinor-fung · Pull Request #129480 · dotnet/runtime · GitHub
Skip to content

Convert fxr_resolver and its hostmisc dependencies to C - #129480

Merged
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c
Jun 22, 2026
Merged

Convert fxr_resolver and its hostmisc dependencies to C#129480
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c

Conversation

@elinor-fung

@elinor-fungelinor-fung commented Jun 16, 2026

Copy link
Copy Markdown
Member

This is another slice of breaking up #126367. It continues the conversion of the corehost stack from C++ to C, building on top of #128420 (which converted trace and fx_ver). This converts fxr_resolver and the hostmisc PAL/utils helpers that fxr_resolver depends on.

cc @dotnet/appmodel @AaronRobinsonMSFT

  • fxr_resolver
    • fxr_resolver.c replaces most of fxr_resolver.cpp
    • fxr_resolver.h has the C-compatible surface
  • pal / utils
    • Adds the implementations needed by fxr_resolver.
  • Build wiring
    • Defines CLR_CMAKE_TARGET_ARCH_UPPER for an uppercase version of the arch

Windows x64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost136,704124,416−12,288−8.99%
nethost87,55271,680−15,872−18.13%
ijwhost108,03294,208−13,824−12.80%
comhost165,376151,552−13,824−8.36%
dotnet133,632123,392−10,240−7.66%

macOS arm64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost116,38495,232−21,152−18.17%
dotnet97,15294,896−2,256−2.32%
libnethost.dylib114,30492,368−21,936−19.19%

linux x64 Release

BinaryBaselineThis BranchΔ bytesΔ %
apphost73,89649,248−24,648−33.4%
dotnet56,28839,904−16,384−29.1%
libnethost.so68,02443,376−24,648−36.2%

elinor-fungand others added 10 commits June 12, 2026 15:27
Add C implementations for pal_strdup, pal_fullpath, pal_file_exists,
pal_readdir_onlydirectories (callback-based), and pal_is_running_in_wow64.
These are the simple pal helpers fxr_resolver needs that can be converted
before the install-location and utils helpers.
Rewrite the corresponding pal::* C++ functions as thin delegating wrappers
around the new C helpers, preserving the existing namespace and default
parameter on pal::fullpath for C++ callers (deps_format.cpp etc).
pal::realpath and the pattern overload of pal::readdir_onlydirectories
remain unchanged (no current C consumer).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add C-callable versions of the no-arch install-location pal helpers used by
fxr_resolver, plus a small C shim for the test-only env override:
- pal_get_dotnet_self_registered_dir
- pal_get_default_installation_dir
- pal_get_dotnet_self_registered_config_location
- pal_is_emulating_x64
- utils_test_only_getenv (delegates to C++ test_only_getenv)
The C++ no-arch pal::* overloads become thin wrappers around the new C
helpers. The arch-explicit *_for_arch overloads (still used by
install_info.cpp) are left untouched.
The _STRINGIFY macro and configure.h include are moved up to the shared
section of pal.h (before extern ""C"") so the new C files can use
_STRINGIFY(CURRENT_ARCH_NAME) to embed the build-time architecture name
without duplicating the definitions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- utils_append_path
- utils_file_exists_in_dir_alloc
- utils_get_directory_alloc
- utils_get_dotnet_root_env_var_for_current_arch
- utils_get_file_path_from_env
- utils_get_dotnet_root_from_env
- utils_get_download_url (C-callable shim around the existing C++ impl)
C++ counterparts in utils.cpp become thin wrappers around the new C helpers
where the data shape allows. append_path and get_dotnet_root_env_var_for_arch
keep their existing C++ implementations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- get_latest_fxr (static)
- fxr_resolver_try_get_path
- fxr_resolver_try_get_path_from_dotnet_root
try_get_existing_fxr stays in C++ because pal::get_loaded_library is a templated helper. The C++ namespace members in fxr_resolver.cpp become thin wrappers around the new C entry points.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the grow-style append_str helper (repeated realloc) with a stack-allocated array of string fragments that is concatenated in a single pass. The size and copy loops walk the parts array once each, giving a clear three-phase structure: collect parts -> compute size -> copy.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pal.unix.c install-location helpers:
- Inline compose_install_location_file_path into its only caller.
- Simplify pal_get_dotnet_self_registered_dir: in-place truncation of
the "_<arch>" suffix, single cleanup path, rename `ok` to `success`,
assert that file_found is true on success.
- Remove ascii_lower_dup helper.
- Drop private join_path_alloc in favor of utils_append_path_alloc.
pal.windows.c registry helpers:
- get_dotnet_install_location_registry_path and format_registry_path
use pal_str_printf instead of hand-rolled memcpy concatenation.
- get_dotnet_install_location_registry_path inlines the suffix into the
format string and uses STRING_LENGTH for the compile-time size,
matching format_registry_path's pattern.
pal_char_t string ops:
- Use pal_strlen instead of bare wcslen/strlen on pal_char_t* values
in pal.windows.c and pal.unix.c.
utils:
- Add utils_append_path_alloc (delegates to utils_append_path).
- Rename utils_file_exists_in_dir_alloc -> utils_find_file_in_dir and
utils_get_directory_alloc -> utils_get_directory (no non-alloc twin).
- Change utils_get_filename to return void; sole caller already used
the empty-string sentinel for failure.
- Rename utils_append_path parameters to path_buffer/path_buffer_len.
- Add asserts on the overflow paths in utils_append_path and
utils_get_filename.
- utils_append_path: merge the empty-buffer special case into the
unified flow (single overflow check, no early return).
- utils_get_directory: build the result up front and use pal_strrchr
on the working copy after trimming trailing separators.
- utils_get_file_path_from_env: rename the env getenv result to
env_value and the canonicalized path to file_path.
fxr_resolver.c:
- Rename emit_missing_runtime_error -> print_missing_runtime_error.
Doc cleanups:
- "NUL-terminated" -> "null-terminated" across pal.h, trace.c, utils.h,
and an inline comment in utils.c.
- Rewrite the doc comment on get_dotnet_install_location_registry_path
in pal.windows.c.
- Trim a few obvious comments in utils.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the test-only environment variable helper to utils.c as
utils_test_only_getenv. The C++ test_only_getenv now wraps the C
version, so existing C++ callers (pal.unix.cpp, pal.windows.cpp) are
unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add utils_get_download_url and utils_get_runtime_id in C, and reduce
the C++ versions to thin wrappers around them. fxr_resolver.c now
writes into a stack-allocated MAX_DOWNLOAD_URL_LEN buffer instead of
allocating with malloc.
The C download URL drops runtime OS detection (was
pal_get_current_os_rid_platform on Linux); the URL now always uses the
build-time FALLBACK_HOST_OS, which is acceptable since it is purely
informational and aka.ms accepts either form.
Move HOST_RID_PLATFORM out of the C++-only section of pal.h so the C
implementations can use it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The C++ pal::readdir_onlydirectories normalized the directory path via
LongFile::ShouldNormalize + pal::fullpath before enumerating. When the
single-arg overload was re-pointed at the new C pal_readdir_onlydirectories,
that normalization was lost, so enumerating version-numbered folders under a
long (>= MAX_PATH) or not-fully-qualified fxr root would fail where it
previously succeeded.
Replicate the ShouldNormalize gate in C (is_path_not_fully_qualified /
should_normalize_path) and canonicalize via pal_fullpath before building the
FindFirstFileExW search string. Also add named defines for the long-path
prefixes and path separators and reuse them across is_path_normalized,
pal_fullpath, and is_path_not_fully_qualified.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The singlefilehost is built from the coreclr tree (src/coreclr/CMakeLists.txt),
which runs apphost/static/CMakeLists.txt's own configure_file for configure.h.in.
CLR_CMAKE_TARGET_ARCH_UPPER was only set in corehost/CMakeLists.txt, so it was
empty in this scope, making CURRENT_ARCH_NAME_UPPER empty and degrading
DOTNET_ROOT_<ARCH> to DOTNET_ROOT_ for single-file apps. Compute the uppercase
arch in the static path before configuring the header.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the corehost C-conversion work by introducing a C implementation of fxr_resolver and expanding the C PAL/utils surface that fxr_resolver depends on, while keeping the existing C++ entry points as thin wrappers.

Changes:

  • Add fxr_resolver.c (C implementation) and update fxr_resolver.{h,cpp} to expose a C API and delegate from the C++ wrapper layer.
  • Expand hostmisc C helpers in utils.c and implement additional PAL functionality in pal.{unix,windows}.c, updating the C++ PAL wrappers to call into the new C APIs.
  • Wire the new C sources into corehost and singlefilehost builds; extend generated configure.h with CURRENT_ARCH_NAME_UPPER.
Show a summary per file
FileDescription
src/native/corehost/hostmisc/utils.hAdds C-callable utils declarations and DOTNET_ROOT_<ARCH> env-var macro for C consumers.
src/native/corehost/hostmisc/utils.cppSwitches C++ helpers to call C utils_* implementations and manage returned allocations.
src/native/corehost/hostmisc/utils.cImplements additional C utils_* helpers needed by fxr_resolver (path ops, env lookup, download URL, RID).
src/native/corehost/hostmisc/trace.cSmall comment tweak; continues using utils_get_filename from C utils.
src/native/corehost/hostmisc/pal.windows.cppUpdates C++ PAL to delegate to new Windows C PAL APIs (paths, readdir-only-dirs, WOW64/emulation, install roots).
src/native/corehost/hostmisc/pal.windows.cAdds Windows C PAL functionality used by C host code (fullpath, file exists, registry install location, etc.).
src/native/corehost/hostmisc/pal.unix.cppUpdates C++ PAL to delegate to new Unix C PAL APIs (fullpath, readdir-only-dirs, install roots).
src/native/corehost/hostmisc/pal.unix.cAdds Unix C PAL functionality used by C host code (fullpath, readdir-only-dirs, install roots, Rosetta detection).
src/native/corehost/hostmisc/pal.hExtends the C-callable PAL surface and moves some shared macros/config includes into the C section.
src/native/corehost/fxr_resolver.hIntroduces C ABI for fxr resolver search flags and functions; maps C++ enum to C enum values.
src/native/corehost/fxr_resolver.cppBecomes a C++ shim that marshals to fxr_resolver.c.
src/native/corehost/fxr_resolver.cNew C implementation of fxr resolution + missing-runtime error composition.
src/native/corehost/configure.h.inAdds CURRENT_ARCH_NAME_UPPER for arch-specific env-var naming.
src/native/corehost/CMakeLists.txtEnsures CLR_CMAKE_TARGET_ARCH_UPPER is computed and builds fxr_resolver.c alongside the C++ wrapper.
src/native/corehost/apphost/static/CMakeLists.txtComputes CLR_CMAKE_TARGET_ARCH_UPPER and compiles fxr_resolver.c into singlefilehost.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 3

Comment threadsrc/native/corehost/fxr_resolver.c
Comment threadsrc/native/corehost/fxr_resolver.c Outdated
Comment threadsrc/native/corehost/hostmisc/pal.windows.c
…ARATOR
Guard NULL registered_config_location and the message-buffer malloc in print_missing_runtime_error so the missing-runtime diagnostic degrades gracefully on OOM instead of dereferencing NULL. Remove the redundant DIR_SEPARATOR redefinition in pal.windows.c and use the one from pal.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 4

Comment threadsrc/native/corehost/hostmisc/utils.cpp
Comment threadsrc/native/corehost/hostmisc/trace.c
Comment threadsrc/native/corehost/hostmisc/pal.h
Comment threadsrc/native/corehost/hostmisc/utils.c Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 17, 2026 21:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 2

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/fxr_resolver.c
CopilotAI review requested due to automatic review settings June 17, 2026 21:22

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 1

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/hostmisc/pal.h Outdated
Comment threadsrc/native/corehost/fxr_resolver.c
…ert dotnet_root, merge wow64/emulation into pal_get_process_emulation enum
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@elinor-fung

Copy link
Copy Markdown
MemberAuthor

/ba-g unrelated win-arm64 timeouts

@elinor-fung
elinor-fung merged commit fc23f44 into dotnet:mainJun 22, 2026
175 of 183 checks passed
@elinor-fung
elinor-fung deleted the fxr-resolver-c branch June 22, 2026 17:33
elinor-fung added a commit that referenced this pull request Jun 22, 2026
Reconcile the apphost-in-C rewrite with the smaller C conversions that were
extracted from this branch and merged separately upstream:
- #128420 Convert corehost hostmisc trace and fx_ver to C
- #129480 Convert fxr_resolver and its hostmisc dependencies to C
Adopt upstream's now-merged C conversions (trace.c, fx_ver.c, fxr_resolver.c,
pal.unix.c/pal.windows.c, utils.c and their headers) and drop this branch's
redundant/divergent copies (hostmisc/fxr_resolver.c, pal.windows.c_impl.cpp,
hostmisc_c object library). Keep only the apphost-in-C delta on top:
apphost/apphost.c, apphost_hostfxr_resolver.{c,cpp,h}, dotnet/dotnet.cpp
(replacing corehost.cpp) and bundle_marker.c.
Adapt the apphost C layer to upstream's allocating C API (pal_get_own_executable_path,
pal_fullpath, utils_get_directory) and add the few apphost-only C helpers upstream
lacked: pal_load_library/unload_library/get_symbol/is_path_fully_qualified/utf8_to_palstr
(extern "C" wrappers in pal.windows.cpp/pal.unix.cpp) and utils_get_current_arch_name/
utils_get_host_version_description. Wire standalone apphost to link hostmisc+fxr_resolver
like dotnet, and singlefilehost to use apphost.c.
Validated: standalone apphost, dotnet, and singlefilehost all compile and link.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 23, 2026
@elinor-fungelinor-fung mentioned this pull request Jun 25, 2026
elinor-fung added a commit that referenced this pull request Jul 2, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
This is another slice of breaking up #126367. It continues the
conversion of the corehost stack from C++ to C, building on top of
#128420 (which converted `trace` and `fx_ver`). This converts
`fxr_resolver` and the `hostmisc` PAL/utils helpers that `fxr_resolver`
depends on.
- **`fxr_resolver`**
- `fxr_resolver.c` replaces most of `fxr_resolver.cpp`
- `fxr_resolver.h` has the C-compatible surface
- **pal** / **utils**
- Adds the implementations needed by `fxr_resolver`. - **Build wiring**
- Defines `CLR_CMAKE_TARGET_ARCH_UPPER` for an uppercase version of the
arch
**Windows x64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 136,704 | 124,416 | −12,288 | −8.99% |
| nethost | 87,552 | 71,680 | −15,872 | −18.13% |
| ijwhost | 108,032 | 94,208 | −13,824 | −12.80% |
| comhost | 165,376 | 151,552 | −13,824 | −8.36% |
| dotnet | 133,632 | 123,392 | −10,240 | −7.66% |
**macOS arm64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 116,384 | 95,232 | −21,152 | −18.17% |
| dotnet | 97,152 | 94,896 | −2,256 | −2.32% |
| libnethost.dylib | 114,304 | 92,368 | −21,936 | −19.19% |
**linux x64 Release**
| Binary | Baseline | This Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 73,896 | 49,248 | −24,648 | −33.4% |
| dotnet | 56,288 | 39,904 | −16,384 | −29.1% |
| libnethost.so | 68,024 | 43,376 | −24,648 | −36.2% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@elinor-fung@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Convert fxr_resolver and its hostmisc dependencies to C by elinor-fung · Pull Request #129480 · dotnet/runtime · GitHub
Skip to content

Convert fxr_resolver and its hostmisc dependencies to C - #129480

Merged
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c
Jun 22, 2026
Merged

Convert fxr_resolver and its hostmisc dependencies to C#129480
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c

Conversation

@elinor-fung

@elinor-fungelinor-fung commented Jun 16, 2026

Copy link
Copy Markdown
Member

This is another slice of breaking up #126367. It continues the conversion of the corehost stack from C++ to C, building on top of #128420 (which converted trace and fx_ver). This converts fxr_resolver and the hostmisc PAL/utils helpers that fxr_resolver depends on.

cc @dotnet/appmodel @AaronRobinsonMSFT

  • fxr_resolver
    • fxr_resolver.c replaces most of fxr_resolver.cpp
    • fxr_resolver.h has the C-compatible surface
  • pal / utils
    • Adds the implementations needed by fxr_resolver.
  • Build wiring
    • Defines CLR_CMAKE_TARGET_ARCH_UPPER for an uppercase version of the arch

Windows x64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost136,704124,416−12,288−8.99%
nethost87,55271,680−15,872−18.13%
ijwhost108,03294,208−13,824−12.80%
comhost165,376151,552−13,824−8.36%
dotnet133,632123,392−10,240−7.66%

macOS arm64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost116,38495,232−21,152−18.17%
dotnet97,15294,896−2,256−2.32%
libnethost.dylib114,30492,368−21,936−19.19%

linux x64 Release

BinaryBaselineThis BranchΔ bytesΔ %
apphost73,89649,248−24,648−33.4%
dotnet56,28839,904−16,384−29.1%
libnethost.so68,02443,376−24,648−36.2%

elinor-fungand others added 10 commits June 12, 2026 15:27
Add C implementations for pal_strdup, pal_fullpath, pal_file_exists,
pal_readdir_onlydirectories (callback-based), and pal_is_running_in_wow64.
These are the simple pal helpers fxr_resolver needs that can be converted
before the install-location and utils helpers.
Rewrite the corresponding pal::* C++ functions as thin delegating wrappers
around the new C helpers, preserving the existing namespace and default
parameter on pal::fullpath for C++ callers (deps_format.cpp etc).
pal::realpath and the pattern overload of pal::readdir_onlydirectories
remain unchanged (no current C consumer).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add C-callable versions of the no-arch install-location pal helpers used by
fxr_resolver, plus a small C shim for the test-only env override:
- pal_get_dotnet_self_registered_dir
- pal_get_default_installation_dir
- pal_get_dotnet_self_registered_config_location
- pal_is_emulating_x64
- utils_test_only_getenv (delegates to C++ test_only_getenv)
The C++ no-arch pal::* overloads become thin wrappers around the new C
helpers. The arch-explicit *_for_arch overloads (still used by
install_info.cpp) are left untouched.
The _STRINGIFY macro and configure.h include are moved up to the shared
section of pal.h (before extern ""C"") so the new C files can use
_STRINGIFY(CURRENT_ARCH_NAME) to embed the build-time architecture name
without duplicating the definitions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- utils_append_path
- utils_file_exists_in_dir_alloc
- utils_get_directory_alloc
- utils_get_dotnet_root_env_var_for_current_arch
- utils_get_file_path_from_env
- utils_get_dotnet_root_from_env
- utils_get_download_url (C-callable shim around the existing C++ impl)
C++ counterparts in utils.cpp become thin wrappers around the new C helpers
where the data shape allows. append_path and get_dotnet_root_env_var_for_arch
keep their existing C++ implementations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- get_latest_fxr (static)
- fxr_resolver_try_get_path
- fxr_resolver_try_get_path_from_dotnet_root
try_get_existing_fxr stays in C++ because pal::get_loaded_library is a templated helper. The C++ namespace members in fxr_resolver.cpp become thin wrappers around the new C entry points.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the grow-style append_str helper (repeated realloc) with a stack-allocated array of string fragments that is concatenated in a single pass. The size and copy loops walk the parts array once each, giving a clear three-phase structure: collect parts -> compute size -> copy.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pal.unix.c install-location helpers:
- Inline compose_install_location_file_path into its only caller.
- Simplify pal_get_dotnet_self_registered_dir: in-place truncation of
the "_<arch>" suffix, single cleanup path, rename `ok` to `success`,
assert that file_found is true on success.
- Remove ascii_lower_dup helper.
- Drop private join_path_alloc in favor of utils_append_path_alloc.
pal.windows.c registry helpers:
- get_dotnet_install_location_registry_path and format_registry_path
use pal_str_printf instead of hand-rolled memcpy concatenation.
- get_dotnet_install_location_registry_path inlines the suffix into the
format string and uses STRING_LENGTH for the compile-time size,
matching format_registry_path's pattern.
pal_char_t string ops:
- Use pal_strlen instead of bare wcslen/strlen on pal_char_t* values
in pal.windows.c and pal.unix.c.
utils:
- Add utils_append_path_alloc (delegates to utils_append_path).
- Rename utils_file_exists_in_dir_alloc -> utils_find_file_in_dir and
utils_get_directory_alloc -> utils_get_directory (no non-alloc twin).
- Change utils_get_filename to return void; sole caller already used
the empty-string sentinel for failure.
- Rename utils_append_path parameters to path_buffer/path_buffer_len.
- Add asserts on the overflow paths in utils_append_path and
utils_get_filename.
- utils_append_path: merge the empty-buffer special case into the
unified flow (single overflow check, no early return).
- utils_get_directory: build the result up front and use pal_strrchr
on the working copy after trimming trailing separators.
- utils_get_file_path_from_env: rename the env getenv result to
env_value and the canonicalized path to file_path.
fxr_resolver.c:
- Rename emit_missing_runtime_error -> print_missing_runtime_error.
Doc cleanups:
- "NUL-terminated" -> "null-terminated" across pal.h, trace.c, utils.h,
and an inline comment in utils.c.
- Rewrite the doc comment on get_dotnet_install_location_registry_path
in pal.windows.c.
- Trim a few obvious comments in utils.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the test-only environment variable helper to utils.c as
utils_test_only_getenv. The C++ test_only_getenv now wraps the C
version, so existing C++ callers (pal.unix.cpp, pal.windows.cpp) are
unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add utils_get_download_url and utils_get_runtime_id in C, and reduce
the C++ versions to thin wrappers around them. fxr_resolver.c now
writes into a stack-allocated MAX_DOWNLOAD_URL_LEN buffer instead of
allocating with malloc.
The C download URL drops runtime OS detection (was
pal_get_current_os_rid_platform on Linux); the URL now always uses the
build-time FALLBACK_HOST_OS, which is acceptable since it is purely
informational and aka.ms accepts either form.
Move HOST_RID_PLATFORM out of the C++-only section of pal.h so the C
implementations can use it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The C++ pal::readdir_onlydirectories normalized the directory path via
LongFile::ShouldNormalize + pal::fullpath before enumerating. When the
single-arg overload was re-pointed at the new C pal_readdir_onlydirectories,
that normalization was lost, so enumerating version-numbered folders under a
long (>= MAX_PATH) or not-fully-qualified fxr root would fail where it
previously succeeded.
Replicate the ShouldNormalize gate in C (is_path_not_fully_qualified /
should_normalize_path) and canonicalize via pal_fullpath before building the
FindFirstFileExW search string. Also add named defines for the long-path
prefixes and path separators and reuse them across is_path_normalized,
pal_fullpath, and is_path_not_fully_qualified.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The singlefilehost is built from the coreclr tree (src/coreclr/CMakeLists.txt),
which runs apphost/static/CMakeLists.txt's own configure_file for configure.h.in.
CLR_CMAKE_TARGET_ARCH_UPPER was only set in corehost/CMakeLists.txt, so it was
empty in this scope, making CURRENT_ARCH_NAME_UPPER empty and degrading
DOTNET_ROOT_<ARCH> to DOTNET_ROOT_ for single-file apps. Compute the uppercase
arch in the static path before configuring the header.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the corehost C-conversion work by introducing a C implementation of fxr_resolver and expanding the C PAL/utils surface that fxr_resolver depends on, while keeping the existing C++ entry points as thin wrappers.

Changes:

  • Add fxr_resolver.c (C implementation) and update fxr_resolver.{h,cpp} to expose a C API and delegate from the C++ wrapper layer.
  • Expand hostmisc C helpers in utils.c and implement additional PAL functionality in pal.{unix,windows}.c, updating the C++ PAL wrappers to call into the new C APIs.
  • Wire the new C sources into corehost and singlefilehost builds; extend generated configure.h with CURRENT_ARCH_NAME_UPPER.
Show a summary per file
FileDescription
src/native/corehost/hostmisc/utils.hAdds C-callable utils declarations and DOTNET_ROOT_<ARCH> env-var macro for C consumers.
src/native/corehost/hostmisc/utils.cppSwitches C++ helpers to call C utils_* implementations and manage returned allocations.
src/native/corehost/hostmisc/utils.cImplements additional C utils_* helpers needed by fxr_resolver (path ops, env lookup, download URL, RID).
src/native/corehost/hostmisc/trace.cSmall comment tweak; continues using utils_get_filename from C utils.
src/native/corehost/hostmisc/pal.windows.cppUpdates C++ PAL to delegate to new Windows C PAL APIs (paths, readdir-only-dirs, WOW64/emulation, install roots).
src/native/corehost/hostmisc/pal.windows.cAdds Windows C PAL functionality used by C host code (fullpath, file exists, registry install location, etc.).
src/native/corehost/hostmisc/pal.unix.cppUpdates C++ PAL to delegate to new Unix C PAL APIs (fullpath, readdir-only-dirs, install roots).
src/native/corehost/hostmisc/pal.unix.cAdds Unix C PAL functionality used by C host code (fullpath, readdir-only-dirs, install roots, Rosetta detection).
src/native/corehost/hostmisc/pal.hExtends the C-callable PAL surface and moves some shared macros/config includes into the C section.
src/native/corehost/fxr_resolver.hIntroduces C ABI for fxr resolver search flags and functions; maps C++ enum to C enum values.
src/native/corehost/fxr_resolver.cppBecomes a C++ shim that marshals to fxr_resolver.c.
src/native/corehost/fxr_resolver.cNew C implementation of fxr resolution + missing-runtime error composition.
src/native/corehost/configure.h.inAdds CURRENT_ARCH_NAME_UPPER for arch-specific env-var naming.
src/native/corehost/CMakeLists.txtEnsures CLR_CMAKE_TARGET_ARCH_UPPER is computed and builds fxr_resolver.c alongside the C++ wrapper.
src/native/corehost/apphost/static/CMakeLists.txtComputes CLR_CMAKE_TARGET_ARCH_UPPER and compiles fxr_resolver.c into singlefilehost.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 3

Comment threadsrc/native/corehost/fxr_resolver.c
Comment threadsrc/native/corehost/fxr_resolver.c Outdated
Comment threadsrc/native/corehost/hostmisc/pal.windows.c
…ARATOR
Guard NULL registered_config_location and the message-buffer malloc in print_missing_runtime_error so the missing-runtime diagnostic degrades gracefully on OOM instead of dereferencing NULL. Remove the redundant DIR_SEPARATOR redefinition in pal.windows.c and use the one from pal.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 4

Comment threadsrc/native/corehost/hostmisc/utils.cpp
Comment threadsrc/native/corehost/hostmisc/trace.c
Comment threadsrc/native/corehost/hostmisc/pal.h
Comment threadsrc/native/corehost/hostmisc/utils.c Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 17, 2026 21:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 2

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/fxr_resolver.c
CopilotAI review requested due to automatic review settings June 17, 2026 21:22

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 1

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/hostmisc/pal.h Outdated
Comment threadsrc/native/corehost/fxr_resolver.c
…ert dotnet_root, merge wow64/emulation into pal_get_process_emulation enum
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@elinor-fung

Copy link
Copy Markdown
MemberAuthor

/ba-g unrelated win-arm64 timeouts

@elinor-fung
elinor-fung merged commit fc23f44 into dotnet:mainJun 22, 2026
175 of 183 checks passed
@elinor-fung
elinor-fung deleted the fxr-resolver-c branch June 22, 2026 17:33
elinor-fung added a commit that referenced this pull request Jun 22, 2026
Reconcile the apphost-in-C rewrite with the smaller C conversions that were
extracted from this branch and merged separately upstream:
- #128420 Convert corehost hostmisc trace and fx_ver to C
- #129480 Convert fxr_resolver and its hostmisc dependencies to C
Adopt upstream's now-merged C conversions (trace.c, fx_ver.c, fxr_resolver.c,
pal.unix.c/pal.windows.c, utils.c and their headers) and drop this branch's
redundant/divergent copies (hostmisc/fxr_resolver.c, pal.windows.c_impl.cpp,
hostmisc_c object library). Keep only the apphost-in-C delta on top:
apphost/apphost.c, apphost_hostfxr_resolver.{c,cpp,h}, dotnet/dotnet.cpp
(replacing corehost.cpp) and bundle_marker.c.
Adapt the apphost C layer to upstream's allocating C API (pal_get_own_executable_path,
pal_fullpath, utils_get_directory) and add the few apphost-only C helpers upstream
lacked: pal_load_library/unload_library/get_symbol/is_path_fully_qualified/utf8_to_palstr
(extern "C" wrappers in pal.windows.cpp/pal.unix.cpp) and utils_get_current_arch_name/
utils_get_host_version_description. Wire standalone apphost to link hostmisc+fxr_resolver
like dotnet, and singlefilehost to use apphost.c.
Validated: standalone apphost, dotnet, and singlefilehost all compile and link.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 23, 2026
@elinor-fungelinor-fung mentioned this pull request Jun 25, 2026
elinor-fung added a commit that referenced this pull request Jul 2, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
This is another slice of breaking up #126367. It continues the
conversion of the corehost stack from C++ to C, building on top of
#128420 (which converted `trace` and `fx_ver`). This converts
`fxr_resolver` and the `hostmisc` PAL/utils helpers that `fxr_resolver`
depends on.
- **`fxr_resolver`**
- `fxr_resolver.c` replaces most of `fxr_resolver.cpp`
- `fxr_resolver.h` has the C-compatible surface
- **pal** / **utils**
- Adds the implementations needed by `fxr_resolver`. - **Build wiring**
- Defines `CLR_CMAKE_TARGET_ARCH_UPPER` for an uppercase version of the
arch
**Windows x64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 136,704 | 124,416 | −12,288 | −8.99% |
| nethost | 87,552 | 71,680 | −15,872 | −18.13% |
| ijwhost | 108,032 | 94,208 | −13,824 | −12.80% |
| comhost | 165,376 | 151,552 | −13,824 | −8.36% |
| dotnet | 133,632 | 123,392 | −10,240 | −7.66% |
**macOS arm64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 116,384 | 95,232 | −21,152 | −18.17% |
| dotnet | 97,152 | 94,896 | −2,256 | −2.32% |
| libnethost.dylib | 114,304 | 92,368 | −21,936 | −19.19% |
**linux x64 Release**
| Binary | Baseline | This Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 73,896 | 49,248 | −24,648 | −33.4% |
| dotnet | 56,288 | 39,904 | −16,384 | −29.1% |
| libnethost.so | 68,024 | 43,376 | −24,648 | −36.2% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@elinor-fung@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Convert fxr_resolver and its hostmisc dependencies to C by elinor-fung · Pull Request #129480 · dotnet/runtime · GitHub
Skip to content

Convert fxr_resolver and its hostmisc dependencies to C - #129480

Merged
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c
Jun 22, 2026
Merged

Convert fxr_resolver and its hostmisc dependencies to C#129480
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c

Conversation

@elinor-fung

@elinor-fungelinor-fung commented Jun 16, 2026

Copy link
Copy Markdown
Member

This is another slice of breaking up #126367. It continues the conversion of the corehost stack from C++ to C, building on top of #128420 (which converted trace and fx_ver). This converts fxr_resolver and the hostmisc PAL/utils helpers that fxr_resolver depends on.

cc @dotnet/appmodel @AaronRobinsonMSFT

  • fxr_resolver
    • fxr_resolver.c replaces most of fxr_resolver.cpp
    • fxr_resolver.h has the C-compatible surface
  • pal / utils
    • Adds the implementations needed by fxr_resolver.
  • Build wiring
    • Defines CLR_CMAKE_TARGET_ARCH_UPPER for an uppercase version of the arch

Windows x64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost136,704124,416−12,288−8.99%
nethost87,55271,680−15,872−18.13%
ijwhost108,03294,208−13,824−12.80%
comhost165,376151,552−13,824−8.36%
dotnet133,632123,392−10,240−7.66%

macOS arm64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost116,38495,232−21,152−18.17%
dotnet97,15294,896−2,256−2.32%
libnethost.dylib114,30492,368−21,936−19.19%

linux x64 Release

BinaryBaselineThis BranchΔ bytesΔ %
apphost73,89649,248−24,648−33.4%
dotnet56,28839,904−16,384−29.1%
libnethost.so68,02443,376−24,648−36.2%

elinor-fungand others added 10 commits June 12, 2026 15:27
Add C implementations for pal_strdup, pal_fullpath, pal_file_exists,
pal_readdir_onlydirectories (callback-based), and pal_is_running_in_wow64.
These are the simple pal helpers fxr_resolver needs that can be converted
before the install-location and utils helpers.
Rewrite the corresponding pal::* C++ functions as thin delegating wrappers
around the new C helpers, preserving the existing namespace and default
parameter on pal::fullpath for C++ callers (deps_format.cpp etc).
pal::realpath and the pattern overload of pal::readdir_onlydirectories
remain unchanged (no current C consumer).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add C-callable versions of the no-arch install-location pal helpers used by
fxr_resolver, plus a small C shim for the test-only env override:
- pal_get_dotnet_self_registered_dir
- pal_get_default_installation_dir
- pal_get_dotnet_self_registered_config_location
- pal_is_emulating_x64
- utils_test_only_getenv (delegates to C++ test_only_getenv)
The C++ no-arch pal::* overloads become thin wrappers around the new C
helpers. The arch-explicit *_for_arch overloads (still used by
install_info.cpp) are left untouched.
The _STRINGIFY macro and configure.h include are moved up to the shared
section of pal.h (before extern ""C"") so the new C files can use
_STRINGIFY(CURRENT_ARCH_NAME) to embed the build-time architecture name
without duplicating the definitions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- utils_append_path
- utils_file_exists_in_dir_alloc
- utils_get_directory_alloc
- utils_get_dotnet_root_env_var_for_current_arch
- utils_get_file_path_from_env
- utils_get_dotnet_root_from_env
- utils_get_download_url (C-callable shim around the existing C++ impl)
C++ counterparts in utils.cpp become thin wrappers around the new C helpers
where the data shape allows. append_path and get_dotnet_root_env_var_for_arch
keep their existing C++ implementations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- get_latest_fxr (static)
- fxr_resolver_try_get_path
- fxr_resolver_try_get_path_from_dotnet_root
try_get_existing_fxr stays in C++ because pal::get_loaded_library is a templated helper. The C++ namespace members in fxr_resolver.cpp become thin wrappers around the new C entry points.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the grow-style append_str helper (repeated realloc) with a stack-allocated array of string fragments that is concatenated in a single pass. The size and copy loops walk the parts array once each, giving a clear three-phase structure: collect parts -> compute size -> copy.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pal.unix.c install-location helpers:
- Inline compose_install_location_file_path into its only caller.
- Simplify pal_get_dotnet_self_registered_dir: in-place truncation of
the "_<arch>" suffix, single cleanup path, rename `ok` to `success`,
assert that file_found is true on success.
- Remove ascii_lower_dup helper.
- Drop private join_path_alloc in favor of utils_append_path_alloc.
pal.windows.c registry helpers:
- get_dotnet_install_location_registry_path and format_registry_path
use pal_str_printf instead of hand-rolled memcpy concatenation.
- get_dotnet_install_location_registry_path inlines the suffix into the
format string and uses STRING_LENGTH for the compile-time size,
matching format_registry_path's pattern.
pal_char_t string ops:
- Use pal_strlen instead of bare wcslen/strlen on pal_char_t* values
in pal.windows.c and pal.unix.c.
utils:
- Add utils_append_path_alloc (delegates to utils_append_path).
- Rename utils_file_exists_in_dir_alloc -> utils_find_file_in_dir and
utils_get_directory_alloc -> utils_get_directory (no non-alloc twin).
- Change utils_get_filename to return void; sole caller already used
the empty-string sentinel for failure.
- Rename utils_append_path parameters to path_buffer/path_buffer_len.
- Add asserts on the overflow paths in utils_append_path and
utils_get_filename.
- utils_append_path: merge the empty-buffer special case into the
unified flow (single overflow check, no early return).
- utils_get_directory: build the result up front and use pal_strrchr
on the working copy after trimming trailing separators.
- utils_get_file_path_from_env: rename the env getenv result to
env_value and the canonicalized path to file_path.
fxr_resolver.c:
- Rename emit_missing_runtime_error -> print_missing_runtime_error.
Doc cleanups:
- "NUL-terminated" -> "null-terminated" across pal.h, trace.c, utils.h,
and an inline comment in utils.c.
- Rewrite the doc comment on get_dotnet_install_location_registry_path
in pal.windows.c.
- Trim a few obvious comments in utils.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the test-only environment variable helper to utils.c as
utils_test_only_getenv. The C++ test_only_getenv now wraps the C
version, so existing C++ callers (pal.unix.cpp, pal.windows.cpp) are
unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add utils_get_download_url and utils_get_runtime_id in C, and reduce
the C++ versions to thin wrappers around them. fxr_resolver.c now
writes into a stack-allocated MAX_DOWNLOAD_URL_LEN buffer instead of
allocating with malloc.
The C download URL drops runtime OS detection (was
pal_get_current_os_rid_platform on Linux); the URL now always uses the
build-time FALLBACK_HOST_OS, which is acceptable since it is purely
informational and aka.ms accepts either form.
Move HOST_RID_PLATFORM out of the C++-only section of pal.h so the C
implementations can use it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The C++ pal::readdir_onlydirectories normalized the directory path via
LongFile::ShouldNormalize + pal::fullpath before enumerating. When the
single-arg overload was re-pointed at the new C pal_readdir_onlydirectories,
that normalization was lost, so enumerating version-numbered folders under a
long (>= MAX_PATH) or not-fully-qualified fxr root would fail where it
previously succeeded.
Replicate the ShouldNormalize gate in C (is_path_not_fully_qualified /
should_normalize_path) and canonicalize via pal_fullpath before building the
FindFirstFileExW search string. Also add named defines for the long-path
prefixes and path separators and reuse them across is_path_normalized,
pal_fullpath, and is_path_not_fully_qualified.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The singlefilehost is built from the coreclr tree (src/coreclr/CMakeLists.txt),
which runs apphost/static/CMakeLists.txt's own configure_file for configure.h.in.
CLR_CMAKE_TARGET_ARCH_UPPER was only set in corehost/CMakeLists.txt, so it was
empty in this scope, making CURRENT_ARCH_NAME_UPPER empty and degrading
DOTNET_ROOT_<ARCH> to DOTNET_ROOT_ for single-file apps. Compute the uppercase
arch in the static path before configuring the header.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the corehost C-conversion work by introducing a C implementation of fxr_resolver and expanding the C PAL/utils surface that fxr_resolver depends on, while keeping the existing C++ entry points as thin wrappers.

Changes:

  • Add fxr_resolver.c (C implementation) and update fxr_resolver.{h,cpp} to expose a C API and delegate from the C++ wrapper layer.
  • Expand hostmisc C helpers in utils.c and implement additional PAL functionality in pal.{unix,windows}.c, updating the C++ PAL wrappers to call into the new C APIs.
  • Wire the new C sources into corehost and singlefilehost builds; extend generated configure.h with CURRENT_ARCH_NAME_UPPER.
Show a summary per file
FileDescription
src/native/corehost/hostmisc/utils.hAdds C-callable utils declarations and DOTNET_ROOT_<ARCH> env-var macro for C consumers.
src/native/corehost/hostmisc/utils.cppSwitches C++ helpers to call C utils_* implementations and manage returned allocations.
src/native/corehost/hostmisc/utils.cImplements additional C utils_* helpers needed by fxr_resolver (path ops, env lookup, download URL, RID).
src/native/corehost/hostmisc/trace.cSmall comment tweak; continues using utils_get_filename from C utils.
src/native/corehost/hostmisc/pal.windows.cppUpdates C++ PAL to delegate to new Windows C PAL APIs (paths, readdir-only-dirs, WOW64/emulation, install roots).
src/native/corehost/hostmisc/pal.windows.cAdds Windows C PAL functionality used by C host code (fullpath, file exists, registry install location, etc.).
src/native/corehost/hostmisc/pal.unix.cppUpdates C++ PAL to delegate to new Unix C PAL APIs (fullpath, readdir-only-dirs, install roots).
src/native/corehost/hostmisc/pal.unix.cAdds Unix C PAL functionality used by C host code (fullpath, readdir-only-dirs, install roots, Rosetta detection).
src/native/corehost/hostmisc/pal.hExtends the C-callable PAL surface and moves some shared macros/config includes into the C section.
src/native/corehost/fxr_resolver.hIntroduces C ABI for fxr resolver search flags and functions; maps C++ enum to C enum values.
src/native/corehost/fxr_resolver.cppBecomes a C++ shim that marshals to fxr_resolver.c.
src/native/corehost/fxr_resolver.cNew C implementation of fxr resolution + missing-runtime error composition.
src/native/corehost/configure.h.inAdds CURRENT_ARCH_NAME_UPPER for arch-specific env-var naming.
src/native/corehost/CMakeLists.txtEnsures CLR_CMAKE_TARGET_ARCH_UPPER is computed and builds fxr_resolver.c alongside the C++ wrapper.
src/native/corehost/apphost/static/CMakeLists.txtComputes CLR_CMAKE_TARGET_ARCH_UPPER and compiles fxr_resolver.c into singlefilehost.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 3

Comment threadsrc/native/corehost/fxr_resolver.c
Comment threadsrc/native/corehost/fxr_resolver.c Outdated
Comment threadsrc/native/corehost/hostmisc/pal.windows.c
…ARATOR
Guard NULL registered_config_location and the message-buffer malloc in print_missing_runtime_error so the missing-runtime diagnostic degrades gracefully on OOM instead of dereferencing NULL. Remove the redundant DIR_SEPARATOR redefinition in pal.windows.c and use the one from pal.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 4

Comment threadsrc/native/corehost/hostmisc/utils.cpp
Comment threadsrc/native/corehost/hostmisc/trace.c
Comment threadsrc/native/corehost/hostmisc/pal.h
Comment threadsrc/native/corehost/hostmisc/utils.c Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 17, 2026 21:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 2

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/fxr_resolver.c
CopilotAI review requested due to automatic review settings June 17, 2026 21:22

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 1

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/hostmisc/pal.h Outdated
Comment threadsrc/native/corehost/fxr_resolver.c
…ert dotnet_root, merge wow64/emulation into pal_get_process_emulation enum
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@elinor-fung

Copy link
Copy Markdown
MemberAuthor

/ba-g unrelated win-arm64 timeouts

@elinor-fung
elinor-fung merged commit fc23f44 into dotnet:mainJun 22, 2026
175 of 183 checks passed
@elinor-fung
elinor-fung deleted the fxr-resolver-c branch June 22, 2026 17:33
elinor-fung added a commit that referenced this pull request Jun 22, 2026
Reconcile the apphost-in-C rewrite with the smaller C conversions that were
extracted from this branch and merged separately upstream:
- #128420 Convert corehost hostmisc trace and fx_ver to C
- #129480 Convert fxr_resolver and its hostmisc dependencies to C
Adopt upstream's now-merged C conversions (trace.c, fx_ver.c, fxr_resolver.c,
pal.unix.c/pal.windows.c, utils.c and their headers) and drop this branch's
redundant/divergent copies (hostmisc/fxr_resolver.c, pal.windows.c_impl.cpp,
hostmisc_c object library). Keep only the apphost-in-C delta on top:
apphost/apphost.c, apphost_hostfxr_resolver.{c,cpp,h}, dotnet/dotnet.cpp
(replacing corehost.cpp) and bundle_marker.c.
Adapt the apphost C layer to upstream's allocating C API (pal_get_own_executable_path,
pal_fullpath, utils_get_directory) and add the few apphost-only C helpers upstream
lacked: pal_load_library/unload_library/get_symbol/is_path_fully_qualified/utf8_to_palstr
(extern "C" wrappers in pal.windows.cpp/pal.unix.cpp) and utils_get_current_arch_name/
utils_get_host_version_description. Wire standalone apphost to link hostmisc+fxr_resolver
like dotnet, and singlefilehost to use apphost.c.
Validated: standalone apphost, dotnet, and singlefilehost all compile and link.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 23, 2026
@elinor-fungelinor-fung mentioned this pull request Jun 25, 2026
elinor-fung added a commit that referenced this pull request Jul 2, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
This is another slice of breaking up #126367. It continues the
conversion of the corehost stack from C++ to C, building on top of
#128420 (which converted `trace` and `fx_ver`). This converts
`fxr_resolver` and the `hostmisc` PAL/utils helpers that `fxr_resolver`
depends on.
- **`fxr_resolver`**
- `fxr_resolver.c` replaces most of `fxr_resolver.cpp`
- `fxr_resolver.h` has the C-compatible surface
- **pal** / **utils**
- Adds the implementations needed by `fxr_resolver`. - **Build wiring**
- Defines `CLR_CMAKE_TARGET_ARCH_UPPER` for an uppercase version of the
arch
**Windows x64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 136,704 | 124,416 | −12,288 | −8.99% |
| nethost | 87,552 | 71,680 | −15,872 | −18.13% |
| ijwhost | 108,032 | 94,208 | −13,824 | −12.80% |
| comhost | 165,376 | 151,552 | −13,824 | −8.36% |
| dotnet | 133,632 | 123,392 | −10,240 | −7.66% |
**macOS arm64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 116,384 | 95,232 | −21,152 | −18.17% |
| dotnet | 97,152 | 94,896 | −2,256 | −2.32% |
| libnethost.dylib | 114,304 | 92,368 | −21,936 | −19.19% |
**linux x64 Release**
| Binary | Baseline | This Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 73,896 | 49,248 | −24,648 | −33.4% |
| dotnet | 56,288 | 39,904 | −16,384 | −29.1% |
| libnethost.so | 68,024 | 43,376 | −24,648 | −36.2% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@elinor-fung@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Convert fxr_resolver and its hostmisc dependencies to C by elinor-fung · Pull Request #129480 · dotnet/runtime · GitHub
Skip to content

Convert fxr_resolver and its hostmisc dependencies to C - #129480

Merged
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c
Jun 22, 2026
Merged

Convert fxr_resolver and its hostmisc dependencies to C#129480
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c

Conversation

@elinor-fung

@elinor-fungelinor-fung commented Jun 16, 2026

Copy link
Copy Markdown
Member

This is another slice of breaking up #126367. It continues the conversion of the corehost stack from C++ to C, building on top of #128420 (which converted trace and fx_ver). This converts fxr_resolver and the hostmisc PAL/utils helpers that fxr_resolver depends on.

cc @dotnet/appmodel @AaronRobinsonMSFT

  • fxr_resolver
    • fxr_resolver.c replaces most of fxr_resolver.cpp
    • fxr_resolver.h has the C-compatible surface
  • pal / utils
    • Adds the implementations needed by fxr_resolver.
  • Build wiring
    • Defines CLR_CMAKE_TARGET_ARCH_UPPER for an uppercase version of the arch

Windows x64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost136,704124,416−12,288−8.99%
nethost87,55271,680−15,872−18.13%
ijwhost108,03294,208−13,824−12.80%
comhost165,376151,552−13,824−8.36%
dotnet133,632123,392−10,240−7.66%

macOS arm64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost116,38495,232−21,152−18.17%
dotnet97,15294,896−2,256−2.32%
libnethost.dylib114,30492,368−21,936−19.19%

linux x64 Release

BinaryBaselineThis BranchΔ bytesΔ %
apphost73,89649,248−24,648−33.4%
dotnet56,28839,904−16,384−29.1%
libnethost.so68,02443,376−24,648−36.2%

elinor-fungand others added 10 commits June 12, 2026 15:27
Add C implementations for pal_strdup, pal_fullpath, pal_file_exists,
pal_readdir_onlydirectories (callback-based), and pal_is_running_in_wow64.
These are the simple pal helpers fxr_resolver needs that can be converted
before the install-location and utils helpers.
Rewrite the corresponding pal::* C++ functions as thin delegating wrappers
around the new C helpers, preserving the existing namespace and default
parameter on pal::fullpath for C++ callers (deps_format.cpp etc).
pal::realpath and the pattern overload of pal::readdir_onlydirectories
remain unchanged (no current C consumer).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add C-callable versions of the no-arch install-location pal helpers used by
fxr_resolver, plus a small C shim for the test-only env override:
- pal_get_dotnet_self_registered_dir
- pal_get_default_installation_dir
- pal_get_dotnet_self_registered_config_location
- pal_is_emulating_x64
- utils_test_only_getenv (delegates to C++ test_only_getenv)
The C++ no-arch pal::* overloads become thin wrappers around the new C
helpers. The arch-explicit *_for_arch overloads (still used by
install_info.cpp) are left untouched.
The _STRINGIFY macro and configure.h include are moved up to the shared
section of pal.h (before extern ""C"") so the new C files can use
_STRINGIFY(CURRENT_ARCH_NAME) to embed the build-time architecture name
without duplicating the definitions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- utils_append_path
- utils_file_exists_in_dir_alloc
- utils_get_directory_alloc
- utils_get_dotnet_root_env_var_for_current_arch
- utils_get_file_path_from_env
- utils_get_dotnet_root_from_env
- utils_get_download_url (C-callable shim around the existing C++ impl)
C++ counterparts in utils.cpp become thin wrappers around the new C helpers
where the data shape allows. append_path and get_dotnet_root_env_var_for_arch
keep their existing C++ implementations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- get_latest_fxr (static)
- fxr_resolver_try_get_path
- fxr_resolver_try_get_path_from_dotnet_root
try_get_existing_fxr stays in C++ because pal::get_loaded_library is a templated helper. The C++ namespace members in fxr_resolver.cpp become thin wrappers around the new C entry points.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the grow-style append_str helper (repeated realloc) with a stack-allocated array of string fragments that is concatenated in a single pass. The size and copy loops walk the parts array once each, giving a clear three-phase structure: collect parts -> compute size -> copy.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pal.unix.c install-location helpers:
- Inline compose_install_location_file_path into its only caller.
- Simplify pal_get_dotnet_self_registered_dir: in-place truncation of
the "_<arch>" suffix, single cleanup path, rename `ok` to `success`,
assert that file_found is true on success.
- Remove ascii_lower_dup helper.
- Drop private join_path_alloc in favor of utils_append_path_alloc.
pal.windows.c registry helpers:
- get_dotnet_install_location_registry_path and format_registry_path
use pal_str_printf instead of hand-rolled memcpy concatenation.
- get_dotnet_install_location_registry_path inlines the suffix into the
format string and uses STRING_LENGTH for the compile-time size,
matching format_registry_path's pattern.
pal_char_t string ops:
- Use pal_strlen instead of bare wcslen/strlen on pal_char_t* values
in pal.windows.c and pal.unix.c.
utils:
- Add utils_append_path_alloc (delegates to utils_append_path).
- Rename utils_file_exists_in_dir_alloc -> utils_find_file_in_dir and
utils_get_directory_alloc -> utils_get_directory (no non-alloc twin).
- Change utils_get_filename to return void; sole caller already used
the empty-string sentinel for failure.
- Rename utils_append_path parameters to path_buffer/path_buffer_len.
- Add asserts on the overflow paths in utils_append_path and
utils_get_filename.
- utils_append_path: merge the empty-buffer special case into the
unified flow (single overflow check, no early return).
- utils_get_directory: build the result up front and use pal_strrchr
on the working copy after trimming trailing separators.
- utils_get_file_path_from_env: rename the env getenv result to
env_value and the canonicalized path to file_path.
fxr_resolver.c:
- Rename emit_missing_runtime_error -> print_missing_runtime_error.
Doc cleanups:
- "NUL-terminated" -> "null-terminated" across pal.h, trace.c, utils.h,
and an inline comment in utils.c.
- Rewrite the doc comment on get_dotnet_install_location_registry_path
in pal.windows.c.
- Trim a few obvious comments in utils.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the test-only environment variable helper to utils.c as
utils_test_only_getenv. The C++ test_only_getenv now wraps the C
version, so existing C++ callers (pal.unix.cpp, pal.windows.cpp) are
unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add utils_get_download_url and utils_get_runtime_id in C, and reduce
the C++ versions to thin wrappers around them. fxr_resolver.c now
writes into a stack-allocated MAX_DOWNLOAD_URL_LEN buffer instead of
allocating with malloc.
The C download URL drops runtime OS detection (was
pal_get_current_os_rid_platform on Linux); the URL now always uses the
build-time FALLBACK_HOST_OS, which is acceptable since it is purely
informational and aka.ms accepts either form.
Move HOST_RID_PLATFORM out of the C++-only section of pal.h so the C
implementations can use it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The C++ pal::readdir_onlydirectories normalized the directory path via
LongFile::ShouldNormalize + pal::fullpath before enumerating. When the
single-arg overload was re-pointed at the new C pal_readdir_onlydirectories,
that normalization was lost, so enumerating version-numbered folders under a
long (>= MAX_PATH) or not-fully-qualified fxr root would fail where it
previously succeeded.
Replicate the ShouldNormalize gate in C (is_path_not_fully_qualified /
should_normalize_path) and canonicalize via pal_fullpath before building the
FindFirstFileExW search string. Also add named defines for the long-path
prefixes and path separators and reuse them across is_path_normalized,
pal_fullpath, and is_path_not_fully_qualified.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The singlefilehost is built from the coreclr tree (src/coreclr/CMakeLists.txt),
which runs apphost/static/CMakeLists.txt's own configure_file for configure.h.in.
CLR_CMAKE_TARGET_ARCH_UPPER was only set in corehost/CMakeLists.txt, so it was
empty in this scope, making CURRENT_ARCH_NAME_UPPER empty and degrading
DOTNET_ROOT_<ARCH> to DOTNET_ROOT_ for single-file apps. Compute the uppercase
arch in the static path before configuring the header.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the corehost C-conversion work by introducing a C implementation of fxr_resolver and expanding the C PAL/utils surface that fxr_resolver depends on, while keeping the existing C++ entry points as thin wrappers.

Changes:

  • Add fxr_resolver.c (C implementation) and update fxr_resolver.{h,cpp} to expose a C API and delegate from the C++ wrapper layer.
  • Expand hostmisc C helpers in utils.c and implement additional PAL functionality in pal.{unix,windows}.c, updating the C++ PAL wrappers to call into the new C APIs.
  • Wire the new C sources into corehost and singlefilehost builds; extend generated configure.h with CURRENT_ARCH_NAME_UPPER.
Show a summary per file
FileDescription
src/native/corehost/hostmisc/utils.hAdds C-callable utils declarations and DOTNET_ROOT_<ARCH> env-var macro for C consumers.
src/native/corehost/hostmisc/utils.cppSwitches C++ helpers to call C utils_* implementations and manage returned allocations.
src/native/corehost/hostmisc/utils.cImplements additional C utils_* helpers needed by fxr_resolver (path ops, env lookup, download URL, RID).
src/native/corehost/hostmisc/trace.cSmall comment tweak; continues using utils_get_filename from C utils.
src/native/corehost/hostmisc/pal.windows.cppUpdates C++ PAL to delegate to new Windows C PAL APIs (paths, readdir-only-dirs, WOW64/emulation, install roots).
src/native/corehost/hostmisc/pal.windows.cAdds Windows C PAL functionality used by C host code (fullpath, file exists, registry install location, etc.).
src/native/corehost/hostmisc/pal.unix.cppUpdates C++ PAL to delegate to new Unix C PAL APIs (fullpath, readdir-only-dirs, install roots).
src/native/corehost/hostmisc/pal.unix.cAdds Unix C PAL functionality used by C host code (fullpath, readdir-only-dirs, install roots, Rosetta detection).
src/native/corehost/hostmisc/pal.hExtends the C-callable PAL surface and moves some shared macros/config includes into the C section.
src/native/corehost/fxr_resolver.hIntroduces C ABI for fxr resolver search flags and functions; maps C++ enum to C enum values.
src/native/corehost/fxr_resolver.cppBecomes a C++ shim that marshals to fxr_resolver.c.
src/native/corehost/fxr_resolver.cNew C implementation of fxr resolution + missing-runtime error composition.
src/native/corehost/configure.h.inAdds CURRENT_ARCH_NAME_UPPER for arch-specific env-var naming.
src/native/corehost/CMakeLists.txtEnsures CLR_CMAKE_TARGET_ARCH_UPPER is computed and builds fxr_resolver.c alongside the C++ wrapper.
src/native/corehost/apphost/static/CMakeLists.txtComputes CLR_CMAKE_TARGET_ARCH_UPPER and compiles fxr_resolver.c into singlefilehost.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 3

Comment threadsrc/native/corehost/fxr_resolver.c
Comment threadsrc/native/corehost/fxr_resolver.c Outdated
Comment threadsrc/native/corehost/hostmisc/pal.windows.c
…ARATOR
Guard NULL registered_config_location and the message-buffer malloc in print_missing_runtime_error so the missing-runtime diagnostic degrades gracefully on OOM instead of dereferencing NULL. Remove the redundant DIR_SEPARATOR redefinition in pal.windows.c and use the one from pal.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 4

Comment threadsrc/native/corehost/hostmisc/utils.cpp
Comment threadsrc/native/corehost/hostmisc/trace.c
Comment threadsrc/native/corehost/hostmisc/pal.h
Comment threadsrc/native/corehost/hostmisc/utils.c Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 17, 2026 21:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 2

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/fxr_resolver.c
CopilotAI review requested due to automatic review settings June 17, 2026 21:22

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 1

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/hostmisc/pal.h Outdated
Comment threadsrc/native/corehost/fxr_resolver.c
…ert dotnet_root, merge wow64/emulation into pal_get_process_emulation enum
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@elinor-fung

Copy link
Copy Markdown
MemberAuthor

/ba-g unrelated win-arm64 timeouts

@elinor-fung
elinor-fung merged commit fc23f44 into dotnet:mainJun 22, 2026
175 of 183 checks passed
@elinor-fung
elinor-fung deleted the fxr-resolver-c branch June 22, 2026 17:33
elinor-fung added a commit that referenced this pull request Jun 22, 2026
Reconcile the apphost-in-C rewrite with the smaller C conversions that were
extracted from this branch and merged separately upstream:
- #128420 Convert corehost hostmisc trace and fx_ver to C
- #129480 Convert fxr_resolver and its hostmisc dependencies to C
Adopt upstream's now-merged C conversions (trace.c, fx_ver.c, fxr_resolver.c,
pal.unix.c/pal.windows.c, utils.c and their headers) and drop this branch's
redundant/divergent copies (hostmisc/fxr_resolver.c, pal.windows.c_impl.cpp,
hostmisc_c object library). Keep only the apphost-in-C delta on top:
apphost/apphost.c, apphost_hostfxr_resolver.{c,cpp,h}, dotnet/dotnet.cpp
(replacing corehost.cpp) and bundle_marker.c.
Adapt the apphost C layer to upstream's allocating C API (pal_get_own_executable_path,
pal_fullpath, utils_get_directory) and add the few apphost-only C helpers upstream
lacked: pal_load_library/unload_library/get_symbol/is_path_fully_qualified/utf8_to_palstr
(extern "C" wrappers in pal.windows.cpp/pal.unix.cpp) and utils_get_current_arch_name/
utils_get_host_version_description. Wire standalone apphost to link hostmisc+fxr_resolver
like dotnet, and singlefilehost to use apphost.c.
Validated: standalone apphost, dotnet, and singlefilehost all compile and link.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 23, 2026
@elinor-fungelinor-fung mentioned this pull request Jun 25, 2026
elinor-fung added a commit that referenced this pull request Jul 2, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
This is another slice of breaking up #126367. It continues the
conversion of the corehost stack from C++ to C, building on top of
#128420 (which converted `trace` and `fx_ver`). This converts
`fxr_resolver` and the `hostmisc` PAL/utils helpers that `fxr_resolver`
depends on.
- **`fxr_resolver`**
- `fxr_resolver.c` replaces most of `fxr_resolver.cpp`
- `fxr_resolver.h` has the C-compatible surface
- **pal** / **utils**
- Adds the implementations needed by `fxr_resolver`. - **Build wiring**
- Defines `CLR_CMAKE_TARGET_ARCH_UPPER` for an uppercase version of the
arch
**Windows x64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 136,704 | 124,416 | −12,288 | −8.99% |
| nethost | 87,552 | 71,680 | −15,872 | −18.13% |
| ijwhost | 108,032 | 94,208 | −13,824 | −12.80% |
| comhost | 165,376 | 151,552 | −13,824 | −8.36% |
| dotnet | 133,632 | 123,392 | −10,240 | −7.66% |
**macOS arm64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 116,384 | 95,232 | −21,152 | −18.17% |
| dotnet | 97,152 | 94,896 | −2,256 | −2.32% |
| libnethost.dylib | 114,304 | 92,368 | −21,936 | −19.19% |
**linux x64 Release**
| Binary | Baseline | This Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 73,896 | 49,248 | −24,648 | −33.4% |
| dotnet | 56,288 | 39,904 | −16,384 | −29.1% |
| libnethost.so | 68,024 | 43,376 | −24,648 | −36.2% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@elinor-fung@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Convert fxr_resolver and its hostmisc dependencies to C by elinor-fung · Pull Request #129480 · dotnet/runtime · GitHub
Skip to content

Convert fxr_resolver and its hostmisc dependencies to C - #129480

Merged
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c
Jun 22, 2026
Merged

Convert fxr_resolver and its hostmisc dependencies to C#129480
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c

Conversation

@elinor-fung

@elinor-fungelinor-fung commented Jun 16, 2026

Copy link
Copy Markdown
Member

This is another slice of breaking up #126367. It continues the conversion of the corehost stack from C++ to C, building on top of #128420 (which converted trace and fx_ver). This converts fxr_resolver and the hostmisc PAL/utils helpers that fxr_resolver depends on.

cc @dotnet/appmodel @AaronRobinsonMSFT

  • fxr_resolver
    • fxr_resolver.c replaces most of fxr_resolver.cpp
    • fxr_resolver.h has the C-compatible surface
  • pal / utils
    • Adds the implementations needed by fxr_resolver.
  • Build wiring
    • Defines CLR_CMAKE_TARGET_ARCH_UPPER for an uppercase version of the arch

Windows x64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost136,704124,416−12,288−8.99%
nethost87,55271,680−15,872−18.13%
ijwhost108,03294,208−13,824−12.80%
comhost165,376151,552−13,824−8.36%
dotnet133,632123,392−10,240−7.66%

macOS arm64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost116,38495,232−21,152−18.17%
dotnet97,15294,896−2,256−2.32%
libnethost.dylib114,30492,368−21,936−19.19%

linux x64 Release

BinaryBaselineThis BranchΔ bytesΔ %
apphost73,89649,248−24,648−33.4%
dotnet56,28839,904−16,384−29.1%
libnethost.so68,02443,376−24,648−36.2%

elinor-fungand others added 10 commits June 12, 2026 15:27
Add C implementations for pal_strdup, pal_fullpath, pal_file_exists,
pal_readdir_onlydirectories (callback-based), and pal_is_running_in_wow64.
These are the simple pal helpers fxr_resolver needs that can be converted
before the install-location and utils helpers.
Rewrite the corresponding pal::* C++ functions as thin delegating wrappers
around the new C helpers, preserving the existing namespace and default
parameter on pal::fullpath for C++ callers (deps_format.cpp etc).
pal::realpath and the pattern overload of pal::readdir_onlydirectories
remain unchanged (no current C consumer).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add C-callable versions of the no-arch install-location pal helpers used by
fxr_resolver, plus a small C shim for the test-only env override:
- pal_get_dotnet_self_registered_dir
- pal_get_default_installation_dir
- pal_get_dotnet_self_registered_config_location
- pal_is_emulating_x64
- utils_test_only_getenv (delegates to C++ test_only_getenv)
The C++ no-arch pal::* overloads become thin wrappers around the new C
helpers. The arch-explicit *_for_arch overloads (still used by
install_info.cpp) are left untouched.
The _STRINGIFY macro and configure.h include are moved up to the shared
section of pal.h (before extern ""C"") so the new C files can use
_STRINGIFY(CURRENT_ARCH_NAME) to embed the build-time architecture name
without duplicating the definitions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- utils_append_path
- utils_file_exists_in_dir_alloc
- utils_get_directory_alloc
- utils_get_dotnet_root_env_var_for_current_arch
- utils_get_file_path_from_env
- utils_get_dotnet_root_from_env
- utils_get_download_url (C-callable shim around the existing C++ impl)
C++ counterparts in utils.cpp become thin wrappers around the new C helpers
where the data shape allows. append_path and get_dotnet_root_env_var_for_arch
keep their existing C++ implementations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- get_latest_fxr (static)
- fxr_resolver_try_get_path
- fxr_resolver_try_get_path_from_dotnet_root
try_get_existing_fxr stays in C++ because pal::get_loaded_library is a templated helper. The C++ namespace members in fxr_resolver.cpp become thin wrappers around the new C entry points.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the grow-style append_str helper (repeated realloc) with a stack-allocated array of string fragments that is concatenated in a single pass. The size and copy loops walk the parts array once each, giving a clear three-phase structure: collect parts -> compute size -> copy.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pal.unix.c install-location helpers:
- Inline compose_install_location_file_path into its only caller.
- Simplify pal_get_dotnet_self_registered_dir: in-place truncation of
the "_<arch>" suffix, single cleanup path, rename `ok` to `success`,
assert that file_found is true on success.
- Remove ascii_lower_dup helper.
- Drop private join_path_alloc in favor of utils_append_path_alloc.
pal.windows.c registry helpers:
- get_dotnet_install_location_registry_path and format_registry_path
use pal_str_printf instead of hand-rolled memcpy concatenation.
- get_dotnet_install_location_registry_path inlines the suffix into the
format string and uses STRING_LENGTH for the compile-time size,
matching format_registry_path's pattern.
pal_char_t string ops:
- Use pal_strlen instead of bare wcslen/strlen on pal_char_t* values
in pal.windows.c and pal.unix.c.
utils:
- Add utils_append_path_alloc (delegates to utils_append_path).
- Rename utils_file_exists_in_dir_alloc -> utils_find_file_in_dir and
utils_get_directory_alloc -> utils_get_directory (no non-alloc twin).
- Change utils_get_filename to return void; sole caller already used
the empty-string sentinel for failure.
- Rename utils_append_path parameters to path_buffer/path_buffer_len.
- Add asserts on the overflow paths in utils_append_path and
utils_get_filename.
- utils_append_path: merge the empty-buffer special case into the
unified flow (single overflow check, no early return).
- utils_get_directory: build the result up front and use pal_strrchr
on the working copy after trimming trailing separators.
- utils_get_file_path_from_env: rename the env getenv result to
env_value and the canonicalized path to file_path.
fxr_resolver.c:
- Rename emit_missing_runtime_error -> print_missing_runtime_error.
Doc cleanups:
- "NUL-terminated" -> "null-terminated" across pal.h, trace.c, utils.h,
and an inline comment in utils.c.
- Rewrite the doc comment on get_dotnet_install_location_registry_path
in pal.windows.c.
- Trim a few obvious comments in utils.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the test-only environment variable helper to utils.c as
utils_test_only_getenv. The C++ test_only_getenv now wraps the C
version, so existing C++ callers (pal.unix.cpp, pal.windows.cpp) are
unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add utils_get_download_url and utils_get_runtime_id in C, and reduce
the C++ versions to thin wrappers around them. fxr_resolver.c now
writes into a stack-allocated MAX_DOWNLOAD_URL_LEN buffer instead of
allocating with malloc.
The C download URL drops runtime OS detection (was
pal_get_current_os_rid_platform on Linux); the URL now always uses the
build-time FALLBACK_HOST_OS, which is acceptable since it is purely
informational and aka.ms accepts either form.
Move HOST_RID_PLATFORM out of the C++-only section of pal.h so the C
implementations can use it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The C++ pal::readdir_onlydirectories normalized the directory path via
LongFile::ShouldNormalize + pal::fullpath before enumerating. When the
single-arg overload was re-pointed at the new C pal_readdir_onlydirectories,
that normalization was lost, so enumerating version-numbered folders under a
long (>= MAX_PATH) or not-fully-qualified fxr root would fail where it
previously succeeded.
Replicate the ShouldNormalize gate in C (is_path_not_fully_qualified /
should_normalize_path) and canonicalize via pal_fullpath before building the
FindFirstFileExW search string. Also add named defines for the long-path
prefixes and path separators and reuse them across is_path_normalized,
pal_fullpath, and is_path_not_fully_qualified.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The singlefilehost is built from the coreclr tree (src/coreclr/CMakeLists.txt),
which runs apphost/static/CMakeLists.txt's own configure_file for configure.h.in.
CLR_CMAKE_TARGET_ARCH_UPPER was only set in corehost/CMakeLists.txt, so it was
empty in this scope, making CURRENT_ARCH_NAME_UPPER empty and degrading
DOTNET_ROOT_<ARCH> to DOTNET_ROOT_ for single-file apps. Compute the uppercase
arch in the static path before configuring the header.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the corehost C-conversion work by introducing a C implementation of fxr_resolver and expanding the C PAL/utils surface that fxr_resolver depends on, while keeping the existing C++ entry points as thin wrappers.

Changes:

  • Add fxr_resolver.c (C implementation) and update fxr_resolver.{h,cpp} to expose a C API and delegate from the C++ wrapper layer.
  • Expand hostmisc C helpers in utils.c and implement additional PAL functionality in pal.{unix,windows}.c, updating the C++ PAL wrappers to call into the new C APIs.
  • Wire the new C sources into corehost and singlefilehost builds; extend generated configure.h with CURRENT_ARCH_NAME_UPPER.
Show a summary per file
FileDescription
src/native/corehost/hostmisc/utils.hAdds C-callable utils declarations and DOTNET_ROOT_<ARCH> env-var macro for C consumers.
src/native/corehost/hostmisc/utils.cppSwitches C++ helpers to call C utils_* implementations and manage returned allocations.
src/native/corehost/hostmisc/utils.cImplements additional C utils_* helpers needed by fxr_resolver (path ops, env lookup, download URL, RID).
src/native/corehost/hostmisc/trace.cSmall comment tweak; continues using utils_get_filename from C utils.
src/native/corehost/hostmisc/pal.windows.cppUpdates C++ PAL to delegate to new Windows C PAL APIs (paths, readdir-only-dirs, WOW64/emulation, install roots).
src/native/corehost/hostmisc/pal.windows.cAdds Windows C PAL functionality used by C host code (fullpath, file exists, registry install location, etc.).
src/native/corehost/hostmisc/pal.unix.cppUpdates C++ PAL to delegate to new Unix C PAL APIs (fullpath, readdir-only-dirs, install roots).
src/native/corehost/hostmisc/pal.unix.cAdds Unix C PAL functionality used by C host code (fullpath, readdir-only-dirs, install roots, Rosetta detection).
src/native/corehost/hostmisc/pal.hExtends the C-callable PAL surface and moves some shared macros/config includes into the C section.
src/native/corehost/fxr_resolver.hIntroduces C ABI for fxr resolver search flags and functions; maps C++ enum to C enum values.
src/native/corehost/fxr_resolver.cppBecomes a C++ shim that marshals to fxr_resolver.c.
src/native/corehost/fxr_resolver.cNew C implementation of fxr resolution + missing-runtime error composition.
src/native/corehost/configure.h.inAdds CURRENT_ARCH_NAME_UPPER for arch-specific env-var naming.
src/native/corehost/CMakeLists.txtEnsures CLR_CMAKE_TARGET_ARCH_UPPER is computed and builds fxr_resolver.c alongside the C++ wrapper.
src/native/corehost/apphost/static/CMakeLists.txtComputes CLR_CMAKE_TARGET_ARCH_UPPER and compiles fxr_resolver.c into singlefilehost.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 3

Comment threadsrc/native/corehost/fxr_resolver.c
Comment threadsrc/native/corehost/fxr_resolver.c Outdated
Comment threadsrc/native/corehost/hostmisc/pal.windows.c
…ARATOR
Guard NULL registered_config_location and the message-buffer malloc in print_missing_runtime_error so the missing-runtime diagnostic degrades gracefully on OOM instead of dereferencing NULL. Remove the redundant DIR_SEPARATOR redefinition in pal.windows.c and use the one from pal.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 4

Comment threadsrc/native/corehost/hostmisc/utils.cpp
Comment threadsrc/native/corehost/hostmisc/trace.c
Comment threadsrc/native/corehost/hostmisc/pal.h
Comment threadsrc/native/corehost/hostmisc/utils.c Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 17, 2026 21:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 2

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/fxr_resolver.c
CopilotAI review requested due to automatic review settings June 17, 2026 21:22

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 1

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/hostmisc/pal.h Outdated
Comment threadsrc/native/corehost/fxr_resolver.c
…ert dotnet_root, merge wow64/emulation into pal_get_process_emulation enum
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@elinor-fung

Copy link
Copy Markdown
MemberAuthor

/ba-g unrelated win-arm64 timeouts

@elinor-fung
elinor-fung merged commit fc23f44 into dotnet:mainJun 22, 2026
175 of 183 checks passed
@elinor-fung
elinor-fung deleted the fxr-resolver-c branch June 22, 2026 17:33
elinor-fung added a commit that referenced this pull request Jun 22, 2026
Reconcile the apphost-in-C rewrite with the smaller C conversions that were
extracted from this branch and merged separately upstream:
- #128420 Convert corehost hostmisc trace and fx_ver to C
- #129480 Convert fxr_resolver and its hostmisc dependencies to C
Adopt upstream's now-merged C conversions (trace.c, fx_ver.c, fxr_resolver.c,
pal.unix.c/pal.windows.c, utils.c and their headers) and drop this branch's
redundant/divergent copies (hostmisc/fxr_resolver.c, pal.windows.c_impl.cpp,
hostmisc_c object library). Keep only the apphost-in-C delta on top:
apphost/apphost.c, apphost_hostfxr_resolver.{c,cpp,h}, dotnet/dotnet.cpp
(replacing corehost.cpp) and bundle_marker.c.
Adapt the apphost C layer to upstream's allocating C API (pal_get_own_executable_path,
pal_fullpath, utils_get_directory) and add the few apphost-only C helpers upstream
lacked: pal_load_library/unload_library/get_symbol/is_path_fully_qualified/utf8_to_palstr
(extern "C" wrappers in pal.windows.cpp/pal.unix.cpp) and utils_get_current_arch_name/
utils_get_host_version_description. Wire standalone apphost to link hostmisc+fxr_resolver
like dotnet, and singlefilehost to use apphost.c.
Validated: standalone apphost, dotnet, and singlefilehost all compile and link.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 23, 2026
@elinor-fungelinor-fung mentioned this pull request Jun 25, 2026
elinor-fung added a commit that referenced this pull request Jul 2, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
This is another slice of breaking up #126367. It continues the
conversion of the corehost stack from C++ to C, building on top of
#128420 (which converted `trace` and `fx_ver`). This converts
`fxr_resolver` and the `hostmisc` PAL/utils helpers that `fxr_resolver`
depends on.
- **`fxr_resolver`**
- `fxr_resolver.c` replaces most of `fxr_resolver.cpp`
- `fxr_resolver.h` has the C-compatible surface
- **pal** / **utils**
- Adds the implementations needed by `fxr_resolver`. - **Build wiring**
- Defines `CLR_CMAKE_TARGET_ARCH_UPPER` for an uppercase version of the
arch
**Windows x64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 136,704 | 124,416 | −12,288 | −8.99% |
| nethost | 87,552 | 71,680 | −15,872 | −18.13% |
| ijwhost | 108,032 | 94,208 | −13,824 | −12.80% |
| comhost | 165,376 | 151,552 | −13,824 | −8.36% |
| dotnet | 133,632 | 123,392 | −10,240 | −7.66% |
**macOS arm64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 116,384 | 95,232 | −21,152 | −18.17% |
| dotnet | 97,152 | 94,896 | −2,256 | −2.32% |
| libnethost.dylib | 114,304 | 92,368 | −21,936 | −19.19% |
**linux x64 Release**
| Binary | Baseline | This Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 73,896 | 49,248 | −24,648 | −33.4% |
| dotnet | 56,288 | 39,904 | −16,384 | −29.1% |
| libnethost.so | 68,024 | 43,376 | −24,648 | −36.2% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@elinor-fung@AaronRobinsonMSFT
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Convert fxr_resolver and its hostmisc dependencies to C by elinor-fung · Pull Request #129480 · dotnet/runtime · GitHub
Skip to content

Convert fxr_resolver and its hostmisc dependencies to C - #129480

Merged
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c
Jun 22, 2026
Merged

Convert fxr_resolver and its hostmisc dependencies to C#129480
elinor-fung merged 14 commits into
dotnet:mainfrom
elinor-fung:fxr-resolver-c

Conversation

@elinor-fung

@elinor-fungelinor-fung commented Jun 16, 2026

Copy link
Copy Markdown
Member

This is another slice of breaking up #126367. It continues the conversion of the corehost stack from C++ to C, building on top of #128420 (which converted trace and fx_ver). This converts fxr_resolver and the hostmisc PAL/utils helpers that fxr_resolver depends on.

cc @dotnet/appmodel @AaronRobinsonMSFT

  • fxr_resolver
    • fxr_resolver.c replaces most of fxr_resolver.cpp
    • fxr_resolver.h has the C-compatible surface
  • pal / utils
    • Adds the implementations needed by fxr_resolver.
  • Build wiring
    • Defines CLR_CMAKE_TARGET_ARCH_UPPER for an uppercase version of the arch

Windows x64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost136,704124,416−12,288−8.99%
nethost87,55271,680−15,872−18.13%
ijwhost108,03294,208−13,824−12.80%
comhost165,376151,552−13,824−8.36%
dotnet133,632123,392−10,240−7.66%

macOS arm64 Release

BinaryBaselineBranchΔ bytesΔ %
apphost116,38495,232−21,152−18.17%
dotnet97,15294,896−2,256−2.32%
libnethost.dylib114,30492,368−21,936−19.19%

linux x64 Release

BinaryBaselineThis BranchΔ bytesΔ %
apphost73,89649,248−24,648−33.4%
dotnet56,28839,904−16,384−29.1%
libnethost.so68,02443,376−24,648−36.2%

elinor-fungand others added 10 commits June 12, 2026 15:27
Add C implementations for pal_strdup, pal_fullpath, pal_file_exists,
pal_readdir_onlydirectories (callback-based), and pal_is_running_in_wow64.
These are the simple pal helpers fxr_resolver needs that can be converted
before the install-location and utils helpers.
Rewrite the corresponding pal::* C++ functions as thin delegating wrappers
around the new C helpers, preserving the existing namespace and default
parameter on pal::fullpath for C++ callers (deps_format.cpp etc).
pal::realpath and the pattern overload of pal::readdir_onlydirectories
remain unchanged (no current C consumer).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add C-callable versions of the no-arch install-location pal helpers used by
fxr_resolver, plus a small C shim for the test-only env override:
- pal_get_dotnet_self_registered_dir
- pal_get_default_installation_dir
- pal_get_dotnet_self_registered_config_location
- pal_is_emulating_x64
- utils_test_only_getenv (delegates to C++ test_only_getenv)
The C++ no-arch pal::* overloads become thin wrappers around the new C
helpers. The arch-explicit *_for_arch overloads (still used by
install_info.cpp) are left untouched.
The _STRINGIFY macro and configure.h include are moved up to the shared
section of pal.h (before extern ""C"") so the new C files can use
_STRINGIFY(CURRENT_ARCH_NAME) to embed the build-time architecture name
without duplicating the definitions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- utils_append_path
- utils_file_exists_in_dir_alloc
- utils_get_directory_alloc
- utils_get_dotnet_root_env_var_for_current_arch
- utils_get_file_path_from_env
- utils_get_dotnet_root_from_env
- utils_get_download_url (C-callable shim around the existing C++ impl)
C++ counterparts in utils.cpp become thin wrappers around the new C helpers
where the data shape allows. append_path and get_dotnet_root_env_var_for_arch
keep their existing C++ implementations.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- get_latest_fxr (static)
- fxr_resolver_try_get_path
- fxr_resolver_try_get_path_from_dotnet_root
try_get_existing_fxr stays in C++ because pal::get_loaded_library is a templated helper. The C++ namespace members in fxr_resolver.cpp become thin wrappers around the new C entry points.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the grow-style append_str helper (repeated realloc) with a stack-allocated array of string fragments that is concatenated in a single pass. The size and copy loops walk the parts array once each, giving a clear three-phase structure: collect parts -> compute size -> copy.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pal.unix.c install-location helpers:
- Inline compose_install_location_file_path into its only caller.
- Simplify pal_get_dotnet_self_registered_dir: in-place truncation of
the "_<arch>" suffix, single cleanup path, rename `ok` to `success`,
assert that file_found is true on success.
- Remove ascii_lower_dup helper.
- Drop private join_path_alloc in favor of utils_append_path_alloc.
pal.windows.c registry helpers:
- get_dotnet_install_location_registry_path and format_registry_path
use pal_str_printf instead of hand-rolled memcpy concatenation.
- get_dotnet_install_location_registry_path inlines the suffix into the
format string and uses STRING_LENGTH for the compile-time size,
matching format_registry_path's pattern.
pal_char_t string ops:
- Use pal_strlen instead of bare wcslen/strlen on pal_char_t* values
in pal.windows.c and pal.unix.c.
utils:
- Add utils_append_path_alloc (delegates to utils_append_path).
- Rename utils_file_exists_in_dir_alloc -> utils_find_file_in_dir and
utils_get_directory_alloc -> utils_get_directory (no non-alloc twin).
- Change utils_get_filename to return void; sole caller already used
the empty-string sentinel for failure.
- Rename utils_append_path parameters to path_buffer/path_buffer_len.
- Add asserts on the overflow paths in utils_append_path and
utils_get_filename.
- utils_append_path: merge the empty-buffer special case into the
unified flow (single overflow check, no early return).
- utils_get_directory: build the result up front and use pal_strrchr
on the working copy after trimming trailing separators.
- utils_get_file_path_from_env: rename the env getenv result to
env_value and the canonicalized path to file_path.
fxr_resolver.c:
- Rename emit_missing_runtime_error -> print_missing_runtime_error.
Doc cleanups:
- "NUL-terminated" -> "null-terminated" across pal.h, trace.c, utils.h,
and an inline comment in utils.c.
- Rewrite the doc comment on get_dotnet_install_location_registry_path
in pal.windows.c.
- Trim a few obvious comments in utils.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the test-only environment variable helper to utils.c as
utils_test_only_getenv. The C++ test_only_getenv now wraps the C
version, so existing C++ callers (pal.unix.cpp, pal.windows.cpp) are
unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add utils_get_download_url and utils_get_runtime_id in C, and reduce
the C++ versions to thin wrappers around them. fxr_resolver.c now
writes into a stack-allocated MAX_DOWNLOAD_URL_LEN buffer instead of
allocating with malloc.
The C download URL drops runtime OS detection (was
pal_get_current_os_rid_platform on Linux); the URL now always uses the
build-time FALLBACK_HOST_OS, which is acceptable since it is purely
informational and aka.ms accepts either form.
Move HOST_RID_PLATFORM out of the C++-only section of pal.h so the C
implementations can use it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The C++ pal::readdir_onlydirectories normalized the directory path via
LongFile::ShouldNormalize + pal::fullpath before enumerating. When the
single-arg overload was re-pointed at the new C pal_readdir_onlydirectories,
that normalization was lost, so enumerating version-numbered folders under a
long (>= MAX_PATH) or not-fully-qualified fxr root would fail where it
previously succeeded.
Replicate the ShouldNormalize gate in C (is_path_not_fully_qualified /
should_normalize_path) and canonicalize via pal_fullpath before building the
FindFirstFileExW search string. Also add named defines for the long-path
prefixes and path separators and reuse them across is_path_normalized,
pal_fullpath, and is_path_not_fully_qualified.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The singlefilehost is built from the coreclr tree (src/coreclr/CMakeLists.txt),
which runs apphost/static/CMakeLists.txt's own configure_file for configure.h.in.
CLR_CMAKE_TARGET_ARCH_UPPER was only set in corehost/CMakeLists.txt, so it was
empty in this scope, making CURRENT_ARCH_NAME_UPPER empty and degrading
DOTNET_ROOT_<ARCH> to DOTNET_ROOT_ for single-file apps. Compute the uppercase
arch in the static path before configuring the header.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the corehost C-conversion work by introducing a C implementation of fxr_resolver and expanding the C PAL/utils surface that fxr_resolver depends on, while keeping the existing C++ entry points as thin wrappers.

Changes:

  • Add fxr_resolver.c (C implementation) and update fxr_resolver.{h,cpp} to expose a C API and delegate from the C++ wrapper layer.
  • Expand hostmisc C helpers in utils.c and implement additional PAL functionality in pal.{unix,windows}.c, updating the C++ PAL wrappers to call into the new C APIs.
  • Wire the new C sources into corehost and singlefilehost builds; extend generated configure.h with CURRENT_ARCH_NAME_UPPER.
Show a summary per file
FileDescription
src/native/corehost/hostmisc/utils.hAdds C-callable utils declarations and DOTNET_ROOT_<ARCH> env-var macro for C consumers.
src/native/corehost/hostmisc/utils.cppSwitches C++ helpers to call C utils_* implementations and manage returned allocations.
src/native/corehost/hostmisc/utils.cImplements additional C utils_* helpers needed by fxr_resolver (path ops, env lookup, download URL, RID).
src/native/corehost/hostmisc/trace.cSmall comment tweak; continues using utils_get_filename from C utils.
src/native/corehost/hostmisc/pal.windows.cppUpdates C++ PAL to delegate to new Windows C PAL APIs (paths, readdir-only-dirs, WOW64/emulation, install roots).
src/native/corehost/hostmisc/pal.windows.cAdds Windows C PAL functionality used by C host code (fullpath, file exists, registry install location, etc.).
src/native/corehost/hostmisc/pal.unix.cppUpdates C++ PAL to delegate to new Unix C PAL APIs (fullpath, readdir-only-dirs, install roots).
src/native/corehost/hostmisc/pal.unix.cAdds Unix C PAL functionality used by C host code (fullpath, readdir-only-dirs, install roots, Rosetta detection).
src/native/corehost/hostmisc/pal.hExtends the C-callable PAL surface and moves some shared macros/config includes into the C section.
src/native/corehost/fxr_resolver.hIntroduces C ABI for fxr resolver search flags and functions; maps C++ enum to C enum values.
src/native/corehost/fxr_resolver.cppBecomes a C++ shim that marshals to fxr_resolver.c.
src/native/corehost/fxr_resolver.cNew C implementation of fxr resolution + missing-runtime error composition.
src/native/corehost/configure.h.inAdds CURRENT_ARCH_NAME_UPPER for arch-specific env-var naming.
src/native/corehost/CMakeLists.txtEnsures CLR_CMAKE_TARGET_ARCH_UPPER is computed and builds fxr_resolver.c alongside the C++ wrapper.
src/native/corehost/apphost/static/CMakeLists.txtComputes CLR_CMAKE_TARGET_ARCH_UPPER and compiles fxr_resolver.c into singlefilehost.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 3

Comment threadsrc/native/corehost/fxr_resolver.c
Comment threadsrc/native/corehost/fxr_resolver.c Outdated
Comment threadsrc/native/corehost/hostmisc/pal.windows.c
…ARATOR
Guard NULL registered_config_location and the message-buffer malloc in print_missing_runtime_error so the missing-runtime diagnostic degrades gracefully on OOM instead of dereferencing NULL. Remove the redundant DIR_SEPARATOR redefinition in pal.windows.c and use the one from pal.h.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 4

Comment threadsrc/native/corehost/hostmisc/utils.cpp
Comment threadsrc/native/corehost/hostmisc/trace.c
Comment threadsrc/native/corehost/hostmisc/pal.h
Comment threadsrc/native/corehost/hostmisc/utils.c Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 17, 2026 21:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 2

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/fxr_resolver.c
CopilotAI review requested due to automatic review settings June 17, 2026 21:22

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 1

Comment threadsrc/native/corehost/hostmisc/utils.c
Comment threadsrc/native/corehost/hostmisc/pal.h Outdated
Comment threadsrc/native/corehost/fxr_resolver.c
…ert dotnet_root, merge wow64/emulation into pal_get_process_emulation enum
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@elinor-fung

Copy link
Copy Markdown
MemberAuthor

/ba-g unrelated win-arm64 timeouts

@elinor-fung
elinor-fung merged commit fc23f44 into dotnet:mainJun 22, 2026
175 of 183 checks passed
@elinor-fung
elinor-fung deleted the fxr-resolver-c branch June 22, 2026 17:33
elinor-fung added a commit that referenced this pull request Jun 22, 2026
Reconcile the apphost-in-C rewrite with the smaller C conversions that were
extracted from this branch and merged separately upstream:
- #128420 Convert corehost hostmisc trace and fx_ver to C
- #129480 Convert fxr_resolver and its hostmisc dependencies to C
Adopt upstream's now-merged C conversions (trace.c, fx_ver.c, fxr_resolver.c,
pal.unix.c/pal.windows.c, utils.c and their headers) and drop this branch's
redundant/divergent copies (hostmisc/fxr_resolver.c, pal.windows.c_impl.cpp,
hostmisc_c object library). Keep only the apphost-in-C delta on top:
apphost/apphost.c, apphost_hostfxr_resolver.{c,cpp,h}, dotnet/dotnet.cpp
(replacing corehost.cpp) and bundle_marker.c.
Adapt the apphost C layer to upstream's allocating C API (pal_get_own_executable_path,
pal_fullpath, utils_get_directory) and add the few apphost-only C helpers upstream
lacked: pal_load_library/unload_library/get_symbol/is_path_fully_qualified/utf8_to_palstr
(extern "C" wrappers in pal.windows.cpp/pal.unix.cpp) and utils_get_current_arch_name/
utils_get_host_version_description. Wire standalone apphost to link hostmisc+fxr_resolver
like dotnet, and singlefilehost to use apphost.c.
Validated: standalone apphost, dotnet, and singlefilehost all compile and link.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-botdotnet-milestone-botBot added this to the 11.0-preview6 milestone Jun 23, 2026
@elinor-fungelinor-fung mentioned this pull request Jun 25, 2026
elinor-fung added a commit that referenced this pull request Jul 2, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
This is another slice of breaking up #126367. It continues the
conversion of the corehost stack from C++ to C, building on top of
#128420 (which converted `trace` and `fx_ver`). This converts
`fxr_resolver` and the `hostmisc` PAL/utils helpers that `fxr_resolver`
depends on.
- **`fxr_resolver`**
- `fxr_resolver.c` replaces most of `fxr_resolver.cpp`
- `fxr_resolver.h` has the C-compatible surface
- **pal** / **utils**
- Adds the implementations needed by `fxr_resolver`. - **Build wiring**
- Defines `CLR_CMAKE_TARGET_ARCH_UPPER` for an uppercase version of the
arch
**Windows x64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 136,704 | 124,416 | −12,288 | −8.99% |
| nethost | 87,552 | 71,680 | −15,872 | −18.13% |
| ijwhost | 108,032 | 94,208 | −13,824 | −12.80% |
| comhost | 165,376 | 151,552 | −13,824 | −8.36% |
| dotnet | 133,632 | 123,392 | −10,240 | −7.66% |
**macOS arm64 Release**
| Binary | Baseline | Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 116,384 | 95,232 | −21,152 | −18.17% |
| dotnet | 97,152 | 94,896 | −2,256 | −2.32% |
| libnethost.dylib | 114,304 | 92,368 | −21,936 | −19.19% |
**linux x64 Release**
| Binary | Baseline | This Branch | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| apphost | 73,896 | 49,248 | −24,648 | −33.4% |
| dotnet | 56,288 | 39,904 | −16,384 | −29.1% |
| libnethost.so | 68,024 | 43,376 | −24,648 | −36.2% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Convert `nethost` to C. This builds on #128420 and #129480 to fully
convert `nethost` so it compiles and links as C-only — no C++ runtime
dependency.
- **pal**
- Add a C `pal_get_loaded_library` (look up an already-loaded library
without loading it). The C++ `pal::get_loaded_library` now delegates to
it.
- **fxr_resolver** - Convert the last C++-only piece, `try_get_existing_fxr`, to C.
- Remove the thin C++ wrappers in `fxr_resolver.cpp`
- Move `load_fxr_and_get_delegate` (used by `comhost` and `ijwhost`)
into its own header `load_fxr_and_get_delegate.h`
- **nethost**
- Replace `nethost.cpp` with `nethost.c` using the shared host bits that
have been converted to C. The RAII `error_writer_scope_t` is replaced by
manual save/restore of the error writer.
- **Build**
- Split `hostmisc` into C/C++ sources and add a C-only `hostmisc_c`
object library
**linux x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---|---|---|---|
| `libnethost.a` | 2,743,470 | 532,650 | -2,210,820 | -80.6% |
| `libnethost.so` | 43,376 | 35,072 | -8,304 | -19.1% |
**macOS arm64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|---:|---:|---:|---:|
| `libnethost.a` | 1,097,312 | 268,360 | −828,952 | −75.5% |
| `libnethost.dylib` | 92,368 | 89,088 | −3,280 | −3.6% |
**windows x64 Release**
| Binary | Baseline | PR | Δ bytes | Δ % |
|---|--:|--:|--:|--:|
| `libnethost.lib` | 2,951,176 | 1,677,420 | −1,273,756 | −43.2% |
| `nethost.dll` | 71,168 | 56,832 | −14,336 | −20.1% |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 24, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@elinor-fung@AaronRobinsonMSFT