Rewrite hostmisc C++ components to wrap C implementations#126367
Rewrite hostmisc C++ components to wrap C implementations#126367
Conversation
Create C source files for apphost that replace the C++ implementation: - apphost_main.c: main entry point - apphost_pal.c/h: platform abstraction layer (Unix) - apphost_trace.c/h: tracing system - apphost_utils.c/h: utility functions - apphost_fx_ver.c/h: semantic version parsing - apphost_fxr_resolver.c/h: hostfxr path resolution - apphost_bundle_marker.c/h: bundle detection - apphost_hostfxr_resolver.c/h: hostfxr loading Uses dn-vector from src/native/containers for collections. Windows builds retain existing C++ sources. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2c33d365-8b70-4325-8eee-7f004ba86639 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
- Add stddef.h includes for size_t in headers - Fix HAVE_DIRENT_D_TYPE guard to use config.h - Fix dn_vector_at calls to pass element size - Add test_only_getenv for test install location overrides - Add test overrides in pal_get_dotnet_self_registered_dir and pal_get_default_installation_dir - Add ctype.h include for tolower Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2c33d365-8b70-4325-8eee-7f004ba86639 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
- Remove dead code block (always-false DIR_SEPARATOR check) in apphost_main.c - Remove unused free_string_entry function in apphost_fxr_resolver.c - Add explicit errno.h include in apphost_pal.c Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2c33d365-8b70-4325-8eee-7f004ba86639 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Move C source files from apphost/standalone/ to hostmisc/: - apphost_trace.c/h, apphost_pal.c/h, apphost_utils.c/h - apphost_fx_ver.c/h, apphost_fxr_resolver.c/h, apphost_bundle_marker.c/h Create hostmisc_c OBJECT library target in hostmisc/CMakeLists.txt with proper include directories and dependencies. Update apphost/standalone/CMakeLists.txt to use hostmisc_c and dn-containers CMake targets instead of compiling C files directly. Add dn-containers subdirectory to corehost and singlefilehost builds for non-Windows platforms. Update apphost_fxr_resolver.c to use <dn-vector.h> include path consistent with the dn-containers CMake target. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/6be87a85-902f-4646-92e6-2fb6783a5f57 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Rewrite bundle_marker.h as a C++ wrapper around the C implementation in apphost_bundle_marker.c. Add extern "C" guards to apphost_bundle_marker.h for C++ compatibility. Remove bundle_marker.cpp since the C implementation in hostmisc_c (apphost_bundle_marker.c) is now the single source of truth. Update standalone/CMakeLists.txt and static/CMakeLists.txt to use apphost_bundle_marker.c instead of the removed bundle_marker.cpp. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/65fd3a5e-99f8-4acc-830f-644976f2cfb1 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
…mutex - Removed trace.cpp (C++ implementation) - Updated apphost_trace.h: Added pal_char_t typedef (wchar_t on Windows, char on Unix), extern C guards, va_list function variants - Updated apphost_trace.c: Added Windows support (wide chars, OutputDebugStringW, WriteConsoleW), replaced spinlock with minipal mutex, added _v versions of variadic functions for C++ forwarding - Updated trace.h: Now a thin C++ wrapper calling C functions via va_list - Updated CMakeLists.txt: Use apphost_trace.c instead of trace.cpp, add minipal/mutex.c to both hostmisc and hostmisc_c" Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2c57cab1-6ebb-4ab7-bbbf-38835b4336b3 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Inline the getenv and xtoi helpers directly in apphost_trace.c to avoid depending on apphost_pal.c which is only in hostmisc_c." Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2c57cab1-6ebb-4ab7-bbbf-38835b4336b3 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
- trace_error_v: Copy va_list before any consumption to avoid using a consumed va_list (undefined behavior per C11 §7.16.1) - trace_warning: Delegate to trace_warning_v instead of duplicating the implementation inline Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2c57cab1-6ebb-4ab7-bbbf-38835b4336b3 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
- fx_ver.cpp: Rewrite to delegate to apphost_fx_ver.c for parse(), compare(), and as_str() operations. Handles char/wchar_t conversion for Windows compatibility. - utils.cpp: On non-Windows, delegate get_current_arch_name(), get_runtime_id(), get_host_version_description(), and get_dotnet_root_env_var_for_arch() to apphost_utils.c. - apphost_fx_ver.h: Add extern "C" guards, rename to c_fx_ver_t to avoid collision with C++ fx_ver_t struct. - apphost_utils.h: Add extern "C" guards, guard macros with #ifndef to avoid conflicts with utils.h. - apphost_pal.h: Add extern "C" guards. - CMakeLists.txt: Add apphost_fx_ver.c to all platforms, add apphost_pal.c and apphost_utils.c on non-Windows. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/15a555ca-6237-4c3e-9a6a-93b3c993d1e9 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
- Revert get_dotnet_root_env_var_for_arch to C++ implementation since the C version ignores the arch parameter - Replace 'auto' with explicit 'pal::char_t' in palstr_to_narrow Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/15a555ca-6237-4c3e-9a6a-93b3c993d1e9 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
|
Tagging subscribers to this area: @agocke, @jeffschwMSFT, @elinor-fung |
Rename all hostmisc C files per review feedback: - apphost_trace.c → trace.c, apphost_trace.h → trace_c.h - apphost_fx_ver.c → fx_ver.c, apphost_fx_ver.h → fx_ver_c.h - apphost_pal.c → pal.c, apphost_pal.h → pal_c.h - apphost_utils.c → utils.c, apphost_utils.h → utils_c.h - apphost_fxr_resolver.c → fxr_resolver.c, apphost_fxr_resolver.h → fxr_resolver_c.h - apphost_bundle_marker.c → bundle_marker.c, apphost_bundle_marker.h → bundle_marker_c.h Update all #include directives, CMakeLists.txt references, header guards, and comments to use the new names. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/869a7b2a-c34a-4b37-ab96-28caca72225e Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Done in 7b1a73c. Renamed all hostmisc C files to drop the |
Move the pal_char_t typedef from trace_c.h to pal_c.h as the canonical location. Define it cross-platform (wchar_t on Windows, char on non-Windows) with #ifndef guards to avoid redefinition conflicts with pal.h (C++ PAL). Update function signatures in pal_c.h, pal.c, utils_c.h, and utils.c to use pal_char_t instead of raw char for platform string parameters. Make trace_c.h include pal_c.h for the typedef instead of defining it locally. Restructure pal_c.h to be includable on all platforms (cross- platform types at top, POSIX-specific parts guarded with #if !defined(_WIN32)). Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/88526fd5-afd6-42dc-b551-5b6cd904b449 Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Change hostfxr_resolver_t struct to use char* instead of char[4096]. Change fxr_resolver_try_get_path API to return malloc'd strings via char** instead of writing to fixed-size caller-provided buffers. Convert local path buffers in apphost_main.c and fxr_resolver.c to use malloc/free instead of stack-allocated fixed arrays. Add utils_file_exists_in_dir_alloc and utils_get_directory_alloc helpers that return dynamically allocated strings. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/84b0096a-a181-477e-a6b7-04df74e9919c Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Fixed in b14e833. The root cause: MSVC enables its conforming C preprocessor when compiling with The fix splits
|
|
@copilot fix the build errors On Windows: And osx-arm64: |
- Move extern void apphost_static_init(void) to file scope to fix MSVC C4210 warning treated as error (nonstandard function declaration in block scope) - Add minipal_objects to libnethost and libhostfxr link libraries so that minipal mutex symbols are included in the shipped static library archives Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/c10177cd-ead8-4be3-9190-52ceb27856e9 Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Fixed in 919d9a4:
|
|
@copilot please fix the following error from win-x86 (likely due to differing calling convention): FAILED: [code=2] Corehost.Static/CMakeFiles/singlefilehost.dir/D_/a/work/1/s/src/native/corehost/fxr/hostfxr.cpp.obj Also fix this error that is only present on browser-wasm builds FAILED: [code=1] hostmisc/CMakeFiles/hostmisc_c.dir/fxr_resolver.c.o |
…riter_fn on Windows Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/efbd098c-d9b7-4fcd-80c9-13feacccdbb6 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Fixed in f5b55d9. On Windows x86, |
|
@copilot the tests that use the "test only product behavior" on linux and mac are failing with For example, |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/39051089-f13e-47be-8bab-f4f71a1b6152 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Confirmed — these failures are caused by this PR. Fixed in b3c62e3. Root cause: the new Fix: introduced a single |
|
@copilot please fix the following error in the CoreCLR browser-wasm build: FAILED: hostmisc/CMakeFiles/hostmisc_c.dir/fxr_resolver.c.o |
… available there Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/460f8e93-e56e-42d8-87f0-2647308d061e Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Fixed in 234bc43. |
|
Test failure: wasm build failure: |
|
@copilot browser WASM CoreCLR is still failing with the following error. Please fix the error, validate the build, fix any subsequent issues, and then push the fix FAILED: browserhost/dotnet.native.js |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/932f8724-2fab-4d64-b14d-9ca0c7c7c831 Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Fixed in 5fb4435. The actual error was |
Rewrites the corehost "hostmisc" and apphost components to expose C-compatible APIs and build more of the host stack from C sources. C++ wrappers are retained where needed (notably Windows PAL wrappers). The goal is to allow C entrypoints (
apphost_main.c,fxr_resolver.c, etc.) to call into platform abstractions consistently across Windows and Unix.Changes Made
trace,utils,fx_ver, andfxr_resolver, plus corresponding C-compatible headers embedded into existing headers via#ifdef __cplusplus.pal.windows.c_impl.cpp) and a Unix C PAL implementation (pal.unix.c) for C consumers.pal_char_ttypedef maps towchar_ton Windows andcharon non-Windows._c.hvariants inlined into their C++ counterparts (pal.h,trace.h,utils.h,fxr_resolver.h,bundle_marker.h,fx_ver.h); C++ surface area gated under#ifdef __cplusplus.apphost_main.cas the entry point.corehost.cppmoved tosrc/native/corehost/dotnet/dotnet.cppand rebuilt only as thedotnetmuxer.hostmiscCMake targets linkminipalviatarget_link_librariesrather than including source files directly.apphost_main.candapphost_hostfxr_resolver.hmoved tosrc/native/corehost/apphost/.dn-containersinclude directories moved intosrc/native/containers/CMakeLists.txt.minipal_objectsadded tolibnethostandlibhostfxrstatic library targets so that minipal mutex symbols are included in the shipped archives. Thehostmisc_cOBJECT library (which containsfxr_resolver.cand depends ondn-vector.h/minipal) is skipped on the browser-wasm build, where only the C++hostmisclibrary is consumed anddn-containers/minipalare not pulled in. Theminipallink dependency on the C++hostmisctarget is also skipped on browser-wasm, since the browser corehost build does not add theminipalsubdirectory (libminipal is supplied directly viaNATIVE_LIBSfor the browserhost link step)._Xmacro inpal.h— uses#ifdef __cplusplusto select the right expansion strategy: single-stepL ## sin C++ mode (required for MSVC non-conforming preprocessor compatibility with__FUNCTION__inpal.windows.cpp) and two-step_X_HELPER(s)in C mode (required for MSVC C11 conforming preprocessor to expand macro arguments likeHOST_VERSIONbefore theL##paste inapphost_main.c).utils_get_directory_allocandutils_get_directory—dir_lenalready includes the trailing separator; removed the extra separator write.trace_error_writer_fncalling convention — typedef now uses__cdeclon Windows (gated under#ifdef _WIN32) and no annotation on non-Windows, ensuring type compatibility withhostfxr_error_writer_fnon all platforms including Windows x86 where calling conventions are distinct.trace_ensure_lock_initializedusingInitOnceExecuteOnceon Windows andpthread_onceon non-Windows.<locale.h>,<share.h>) totrace.c.get_latest_fxr— properly callc_fx_ver_cleanupon non-selected versions and onmax_verafter use.fxr_resolversearch logic —else if (search_global)changed toif (dotnet_root == NULL && search_global)so global install is tried as a fallback when both env and global flags are set but no env var is found.apphost_main.c— removed reference toapp_dllin the unbound-executable error path sinceapp_dllis not yet populated at that point.bundle_marker.c(the signature array is 32 bytes, matching SHA-256).extern void apphost_static_init(void)declaration to file scope inapphost_main.cto avoid the "nonstandard extension used: function given file scope" warning treated as error under/std:c11.TEST_ONLY_MARKERembedded byte sequence into a singleis_test_only_enabled()helper inutils.c. Both the C++test_only_getenv(inutils.cpp) and the Ctest_only_getenv(inpal.unix.c) now delegate to it. Previously the marker was embedded twice in the shipped Unix binaries (once per translation unit), andBinaryUtils.SearchAndReplaceonly flips the first occurrence found by KMP search, leaving the second copy stale. This causedTestOnlyProductBehavior.Enableto leave behavior partially enabled across tests, producing failures like "The backup directory…/.libhostfxr.backupalready exists" inFrameworkResolutionError_ListOtherArchitecturesand other "test only product behavior" tests on Linux/macOS.hostmisc_ctarget on non-browser builds, and skipped thetarget_link_libraries(... minipal)call on browser-wasm inhostmisc/CMakeLists.txt(the browser corehost build does not add theminipalCMake subdirectory, so referencing theminipaltarget broke the browserhost link step).Testing
libhostfxr.so/.a,libnethost.so/.a,apphost,dotnet) now contains exactly one copy of the test-only marker (was two before the consolidation).