diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 48972cc67af02..c5fa2f7db8830 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -1,7 +1,3 @@ -# Due to how we build the libraries native build as part of the CoreCLR build as well as standalone, -# we can end up coming to this file twice. Only run it once to simplify our build. -include_guard() - include(${CMAKE_CURRENT_LIST_DIR}/configuretools.cmake) # Set initial flags for each configuration diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index b1cb09d662043..337538a6ba163 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -637,7 +637,7 @@ endfunction() function(add_sanitizer_runtime_support targetName) # Add sanitizer support functions. if (CLR_CMAKE_ENABLE_ASAN) - target_sources(${targetName} PRIVATE "$<$,EXECUTABLE>:${CLR_SRC_NATIVE_DIR}/minipal/asansupport.cpp>") + target_link_libraries(${targetName} PRIVATE $<$,EXECUTABLE>:minipal_sanitizer_support>) endif() endfunction() diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 2e9a6c76743e5..732c3b765379e 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -127,6 +127,7 @@ include (${CLR_SRC_NATIVE_DIR}/eventpipe/configure.cmake) add_subdirectory(${CLR_SRC_NATIVE_DIR}/containers containers) add_subdirectory(${CLR_SRC_NATIVE_DIR}/eventpipe eventpipe) +add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal shared_minipal) if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) add_subdirectory(debug/debug-pal) diff --git a/src/coreclr/debug/createdump/CMakeLists.txt b/src/coreclr/debug/createdump/CMakeLists.txt index 3c72b8a0fa42b..bdd648c2670c3 100644 --- a/src/coreclr/debug/createdump/CMakeLists.txt +++ b/src/coreclr/debug/createdump/CMakeLists.txt @@ -68,7 +68,6 @@ else(CLR_CMAKE_HOST_WIN32) datatarget.cpp dumpwriter.cpp crashreportwriter.cpp - ${CLR_SRC_NATIVE_DIR}/minipal/utf8.c ) if(CLR_CMAKE_HOST_OSX) @@ -88,6 +87,7 @@ else() ${CREATEDUMP_SOURCES} ) endif(CLR_CMAKE_HOST_OSX) +target_link_libraries(createdump_static PRIVATE minipal) add_executable_clr(createdump main.cpp @@ -104,6 +104,8 @@ endif(CLR_CMAKE_HOST_OSX) endif(CLR_CMAKE_HOST_WIN32) +target_link_libraries(createdump PRIVATE minipal) + if (CLR_CMAKE_HOST_APPLE) adhoc_sign_with_entitlements(createdump "${CLR_ENG_NATIVE_DIR}/createdump-entitlements.plist") endif() diff --git a/src/coreclr/minipal/CMakeLists.txt b/src/coreclr/minipal/CMakeLists.txt index 78a1726af3e81..298e1d6fba381 100644 --- a/src/coreclr/minipal/CMakeLists.txt +++ b/src/coreclr/minipal/CMakeLists.txt @@ -5,4 +5,3 @@ if (CLR_CMAKE_HOST_UNIX) else (CLR_CMAKE_HOST_UNIX) add_subdirectory(Windows) endif (CLR_CMAKE_HOST_UNIX) - diff --git a/src/coreclr/minipal/Unix/CMakeLists.txt b/src/coreclr/minipal/Unix/CMakeLists.txt index 6cb70d1e34469..aa4ea90d5e270 100644 --- a/src/coreclr/minipal/Unix/CMakeLists.txt +++ b/src/coreclr/minipal/Unix/CMakeLists.txt @@ -1,19 +1,11 @@ set(SOURCES doublemapping.cpp dn-u16.cpp - ${CLR_SRC_NATIVE_DIR}/minipal/time.c ) -if(NOT CLR_CROSS_COMPONENTS_BUILD) - list(APPEND SOURCES - ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c - ) -endif() - add_library(coreclrminipal STATIC ${SOURCES} ) -include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(coreclrminipal PRIVATE minipal) diff --git a/src/coreclr/minipal/Windows/CMakeLists.txt b/src/coreclr/minipal/Windows/CMakeLists.txt index b1f1cb88a3e6a..90ed6ddf4ea95 100644 --- a/src/coreclr/minipal/Windows/CMakeLists.txt +++ b/src/coreclr/minipal/Windows/CMakeLists.txt @@ -1,17 +1,10 @@ set(SOURCES doublemapping.cpp dn-u16.cpp - ${CLR_SRC_NATIVE_DIR}/minipal/utf8.c - ${CLR_SRC_NATIVE_DIR}/minipal/time.c ) - -if(NOT CLR_CROSS_COMPONENTS_BUILD) - list(APPEND SOURCES - ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c - ) -endif() - add_library(coreclrminipal STATIC ${SOURCES} ) + +target_link_libraries(coreclrminipal PRIVATE minipal) diff --git a/src/coreclr/nativeaot/Bootstrap/main.cpp b/src/coreclr/nativeaot/Bootstrap/main.cpp index 16ffe8f9dbcb0..2e1cfdb063e30 100644 --- a/src/coreclr/nativeaot/Bootstrap/main.cpp +++ b/src/coreclr/nativeaot/Bootstrap/main.cpp @@ -230,7 +230,7 @@ int main(int argc, char* argv[]) // the linker can detect that we have ASAN components early enough in the build. // Include our asan support sources for executable projects here to ensure they // are compiled into the bootstrapper object. -#include "minipal/asansupport.cpp" +#include "minipal/sansupport.c" #endif // HAS_ADDRESS_SANITIZER #endif // !NATIVEAOT_DLL diff --git a/src/coreclr/nativeaot/Runtime/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/CMakeLists.txt index b763e76af80e9..d723c9aa9145b 100644 --- a/src/coreclr/nativeaot/Runtime/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/CMakeLists.txt @@ -49,9 +49,6 @@ set(COMMON_RUNTIME_SOURCES ${GC_DIR}/handletablescan.cpp ${GC_DIR}/objecthandle.cpp ${GC_DIR}/softwarewritewatch.cpp - - ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c - ${CLR_SRC_NATIVE_DIR}/minipal/time.c ) set(SERVER_GC_SOURCES @@ -276,7 +273,6 @@ else() add_definitions(-DFEATURE_READONLY_GS_COOKIE) endif() include(unix/configure.cmake) - include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) include_directories(${CMAKE_CURRENT_BINARY_DIR}) endif() diff --git a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt index f9b390e18d117..9f569c5078fdc 100644 --- a/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt @@ -28,9 +28,11 @@ endif (CLR_CMAKE_TARGET_WIN32) add_library(Runtime.WorkstationGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${RUNTIME_ARCH_ASM_OBJECTS}) add_dependencies(Runtime.WorkstationGC aot_eventing_headers) +target_link_libraries(Runtime.WorkstationGC PRIVATE minipal_objects_no_lto) add_library(Runtime.ServerGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES} ${RUNTIME_ARCH_ASM_OBJECTS}) add_dependencies(Runtime.ServerGC aot_eventing_headers) +target_link_libraries(Runtime.ServerGC PRIVATE minipal_objects_no_lto) add_library(standalonegc-disabled STATIC ${STANDALONEGC_DISABLED_SOURCES}) add_dependencies(standalonegc-disabled aot_eventing_headers) @@ -60,11 +62,16 @@ if (CLR_CMAKE_TARGET_WIN32) add_library(Runtime.ServerGC.GuardCF STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOURCES} ${RUNTIME_SOURCES_ARCH_ASM} ${SERVER_GC_SOURCES} ${RUNTIME_ARCH_ASM_OBJECTS}) target_compile_definitions(Runtime.ServerGC.GuardCF PRIVATE -DFEATURE_SVR_GC) set_target_properties(Runtime.ServerGC.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON) + target_link_libraries(Runtime.ServerGC.GuardCF PRIVATE minipal_objects_no_lto) if (CLR_CMAKE_TARGET_ARCH_AMD64) add_library(Runtime.VxsortEnabled.GuardCF STATIC ${VXSORT_SOURCES}) set_target_properties(Runtime.VxsortEnabled.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON) endif (CLR_CMAKE_TARGET_ARCH_AMD64) + + set_target_properties(minipal_objects_no_lto PROPERTIES + COMPILE_PDB_NAME "minipal" + COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$") endif (CLR_CMAKE_TARGET_WIN32) # Get the current list of definitions @@ -120,6 +127,7 @@ if (CLR_CMAKE_TARGET_WIN32) add_dependencies(Runtime.ServerGC.GuardCF aot_eventing_headers) install_static_library(standalonegc-disabled.GuardCF aotsdk nativeaot) install_static_library(standalonegc-enabled.GuardCF aotsdk nativeaot) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$/minipal.pdb" DESTINATION aotsdk COMPONENT nativeaot) endif (CLR_CMAKE_TARGET_WIN32) if (CLR_CMAKE_TARGET_ARCH_AMD64) install_static_library(Runtime.VxsortEnabled aotsdk nativeaot) @@ -127,4 +135,4 @@ if (CLR_CMAKE_TARGET_ARCH_AMD64) if (CLR_CMAKE_TARGET_WIN32) install_static_library(Runtime.VxsortEnabled.GuardCF aotsdk nativeaot) endif (CLR_CMAKE_TARGET_WIN32) -endif (CLR_CMAKE_TARGET_ARCH_AMD64) \ No newline at end of file +endif (CLR_CMAKE_TARGET_ARCH_AMD64) diff --git a/src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt index b9d2c3f5c3c14..e6738df3e4200 100644 --- a/src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/Portable/CMakeLists.txt @@ -6,6 +6,7 @@ project(PortableRuntime) add_definitions(-DUSE_PORTABLE_HELPERS) add_library(PortableRuntime STATIC ${COMMON_RUNTIME_SOURCES} ${PORTABLE_RUNTIME_SOURCES}) +target_link_libraries(PortableRuntime PRIVATE minipal_objects) # Get the current list of definitions get_compile_definitions(DEFINITIONS) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt index 537e2f5f2b5f4..333180b43eb2d 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt @@ -106,25 +106,8 @@ endif() set(AOT_EVENTPIPE_SHIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -set (MINIPAL_SOURCES "") set (EVENTPIPE_SOURCES "") -set (SHARED_MINIPAL_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/minipal") - -list(APPEND MINIPAL_SOURCES - utf8.c -) - -if(CLR_CMAKE_HOST_UNIX) - include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) - list(APPEND MINIPAL_SOURCES - random.c - ) - -endif(CLR_CMAKE_HOST_UNIX) - -addprefix(MINIPAL_SOURCES ${SHARED_MINIPAL_SOURCE_PATH} "${MINIPAL_SOURCES}") - list(APPEND AOT_EVENTPIPE_SHIM_SOURCES ${AOT_EVENTPIPE_SHIM_DIR}/ep-rt-aot.cpp ${AOT_EVENTPIPE_SHIM_DIR}/ds-rt-aot.cpp @@ -218,7 +201,6 @@ list(APPEND EVENTPIPE_SOURCES ${AOT_EVENTTRACE_SOURCES} ${GEN_EVENTPIPE_PROVIDER_SOURCES} ${GEN_EVENTPIPE_PLAT_AGNOSTIC_SOURCES} - ${MINIPAL_SOURCES} ) list(APPEND AOT_EVENTPIPE_DISABLED_SOURCES diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index cc301eb275731..db5d430ed011b 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -149,8 +149,6 @@ set(SOURCES init/sxs.cpp loader/module.cpp locale/unicode.cpp - ${CLR_SRC_NATIVE_DIR}/minipal/utf8.c - ${CLR_SRC_NATIVE_DIR}/minipal/unicodedata.c map/common.cpp map/map.cpp map/virtual.cpp @@ -338,6 +336,9 @@ if(CLR_CMAKE_TARGET_SUNOS) ) endif(CLR_CMAKE_TARGET_SUNOS) +target_link_libraries(coreclrpal + PRIVATE minipal) + if(FEATURE_EVENT_TRACE) add_subdirectory(eventprovider) endif(FEATURE_EVENT_TRACE) diff --git a/src/coreclr/tools/aot/jitinterface/CMakeLists.txt b/src/coreclr/tools/aot/jitinterface/CMakeLists.txt index 6a612e1486985..6c2512a0ca848 100644 --- a/src/coreclr/tools/aot/jitinterface/CMakeLists.txt +++ b/src/coreclr/tools/aot/jitinterface/CMakeLists.txt @@ -5,15 +5,10 @@ set(NATIVE_SOURCES jitinterface.cpp jitwrapper.cpp corinfoexception.cpp - - ${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c ) if(CLR_CMAKE_TARGET_WIN32) set(JITINTERFACE_RESOURCES Native.rc) -else() - include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) endif() add_library_clr(jitinterface_${ARCH_HOST_NAME} @@ -22,5 +17,7 @@ add_library_clr(jitinterface_${ARCH_HOST_NAME} ${JITINTERFACE_RESOURCES} ) +target_link_libraries(jitinterface_${ARCH_HOST_NAME} PRIVATE minipal) + install_clr(TARGETS jitinterface_${ARCH_HOST_NAME} DESTINATIONS . COMPONENT jit) install_clr(TARGETS jitinterface_${ARCH_HOST_NAME} DESTINATIONS . COMPONENT alljits) diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 7078eb1230631..51af329391dea 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -886,6 +886,7 @@ endif() ### End of OS specific checks include_directories("${CLR_SRC_NATIVE_DIR}") +add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal minipal) if(NOT DISABLE_LIBS) set(INSTALL_MONO_API 1) diff --git a/src/mono/mono/eglib/CMakeLists.txt b/src/mono/mono/eglib/CMakeLists.txt index 951c098de72da..f4d6b31ab0142 100644 --- a/src/mono/mono/eglib/CMakeLists.txt +++ b/src/mono/mono/eglib/CMakeLists.txt @@ -38,12 +38,7 @@ set(eglib_common_sources gpath.c gfile.c gfile-posix.c - gutf8.c - ${CLR_SRC_NATIVE_DIR}/minipal/utf8.c) - -if(CMAKE_C_BYTE_ORDER STREQUAL "BIG_ENDIAN") - set_source_files_properties("${CLR_SRC_NATIVE_DIR}/minipal/utf8.c" PROPERTIES COMPILE_FLAGS "-DBIGENDIAN=1") -endif() + gutf8.c) set(eglib_headers glib.h @@ -67,3 +62,4 @@ target_include_directories(eglib_objects PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}) target_link_libraries (eglib_objects PUBLIC eglib_api) +target_link_libraries(eglib_objects PUBLIC minipal) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index af9987869f5ac..35f3fdbb1cfcd 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -335,7 +335,7 @@ if(NOT HOST_WIN32) target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT) endif() -add_library(monosgen-static STATIC $ $ $ $ $) +add_library(monosgen-static STATIC $ $ $ $ $ $) set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME ${MONO_LIB_NAME}) target_link_libraries(monosgen-static PRIVATE dn-containers) @@ -369,10 +369,10 @@ if(NOT DISABLE_SHARED_LIBS) list(APPEND MONOSGENSHARED_LINKABLE_LIBS zlib) endif() if(HOST_WIN32) - list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects_shared sgen_objects_shared metadata_objects_shared) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects_shared sgen_objects_shared metadata_objects_shared minipal) target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) else() - list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects sgen_objects metadata_objects) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects sgen_objects metadata_objects minipal) target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) endif() target_include_directories (monosgen-shared PRIVATE monoapi) @@ -436,7 +436,7 @@ if(NOT DISABLE_SHARED_LIBS) target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT) set(FRAMEWORKCONFIG_LINKABLE_LIBS "") - list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers) + list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers minipal) if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS zlib) endif() diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index f25e639fb7fda..7503fd76d4487 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -2,10 +2,15 @@ cmake_minimum_required(VERSION 3.20) include(CheckCCompilerFlag) -project(CoreFX C) +project(LibsNative C) -include(../../../eng/native/configurepaths.cmake) -include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake) +if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") + # This is our root CMakeList.txt, so we need to set up some global settings and include the minipal here. + include(../../../eng/native/configurepaths.cmake) + include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake) + + add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal minipal) +endif() include_directories(${CLR_SRC_NATIVE_DIR}) diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 7e00e0ed0a271..ea059b923e057 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -8,16 +8,6 @@ if (CLR_CMAKE_TARGET_OSX) add_definitions(-D_DARWIN_C_SOURCE) endif () -set (MINIPAL_SOURCES "") -set (SHARED_MINIPAL_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/minipal") - -include(${CLR_SRC_NATIVE_DIR}/minipal/configure.cmake) -list(APPEND MINIPAL_SOURCES - random.c -) - -addprefix(MINIPAL_SOURCES ${SHARED_MINIPAL_SOURCE_PATH} "${MINIPAL_SOURCES}") - set(NATIVE_SOURCES pal_errno.c pal_interfaceaddresses.c @@ -35,10 +25,6 @@ set(NATIVE_SOURCES pal_sysctl.c ) -list(APPEND NATIVE_SOURCES - ${MINIPAL_SOURCES} -) - if (NOT CLR_CMAKE_TARGET_WASI) list (APPEND NATIVE_SOURCES pal_dynamicload.c @@ -126,6 +112,7 @@ if (GEN_SHARED_LIB) target_link_libraries(System.Native PRIVATE + minipal ${NATIVE_LIBS_EXTRA} ) diff --git a/src/native/minipal/CMakeLists.txt b/src/native/minipal/CMakeLists.txt new file mode 100644 index 0000000000000..3636298716f4d --- /dev/null +++ b/src/native/minipal/CMakeLists.txt @@ -0,0 +1,27 @@ +include(configure.cmake) + +set(SOURCES + cpufeatures.c + random.c + time.c + unicodedata.c + utf8.c +) + +# Provide an object library for scenarios where we ship static libraries +include_directories(${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +add_library(minipal_objects OBJECT ${SOURCES}) +set_target_properties(minipal_objects PROPERTIES CLR_CONTROL_FLOW_GUARD ON) + +add_library(minipal_objects_no_lto OBJECT ${SOURCES}) +set_target_properties(minipal_objects_no_lto PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF CLR_CONTROL_FLOW_GUARD ON) + +# Provide a static library for our shared library and executable scenarios +# for easier usability. +add_library(minipal STATIC) +target_link_libraries(minipal PRIVATE minipal_objects) + +add_library(minipal_sanitizer_support OBJECT + sansupport.c) +set_target_properties(minipal_sanitizer_support PROPERTIES CLR_CONTROL_FLOW_GUARD ON) diff --git a/src/native/minipal/configure.cmake b/src/native/minipal/configure.cmake index 5394fb8774b9c..8a5dd2346a0e0 100644 --- a/src/native/minipal/configure.cmake +++ b/src/native/minipal/configure.cmake @@ -7,10 +7,16 @@ check_function_exists(sysctlbyname HAVE_SYSCTLBYNAME) check_symbol_exists(arc4random_buf "stdlib.h" HAVE_ARC4RANDOM_BUF) check_symbol_exists(O_CLOEXEC fcntl.h HAVE_O_CLOEXEC) +check_include_files("windows.h" HAVE_WINDOWS_H) +check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H) check_symbol_exists( clock_gettime_nsec_np time.h HAVE_CLOCK_GETTIME_NSEC_NP) +if(CMAKE_C_BYTE_ORDER STREQUAL "BIG_ENDIAN") + set(BIGENDIAN 1) +endif() + configure_file(${CMAKE_CURRENT_LIST_DIR}/minipalconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/minipalconfig.h) diff --git a/src/native/minipal/minipalconfig.h.in b/src/native/minipal/minipalconfig.h.in index d51f47de26103..00764722ef1b8 100644 --- a/src/native/minipal/minipalconfig.h.in +++ b/src/native/minipal/minipalconfig.h.in @@ -6,5 +6,8 @@ #cmakedefine01 HAVE_O_CLOEXEC #cmakedefine01 HAVE_SYSCTLBYNAME #cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP +#cmakedefine01 BIGENDIAN +#cmakedefine01 HAVE_BCRYPT_H +#cmakedefine01 HAVE_WINDOWS_H #endif diff --git a/src/native/minipal/random.c b/src/native/minipal/random.c index 20fcc07802e65..3c2b33ac7463b 100644 --- a/src/native/minipal/random.c +++ b/src/native/minipal/random.c @@ -1,20 +1,26 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#include "minipalconfig.h" + #include #include #include -#include -#include #include -#include #include #include +#if HAVE_BCRYPT_H +#include +#include +#else +#include +#include +#include +#endif #if defined(__APPLE__) && __APPLE__ #include #endif -#include "minipalconfig.h" #include "random.h" /* @@ -29,6 +35,9 @@ void minipal_get_non_cryptographically_secure_random_bytes(uint8_t* buffer, int3 #if HAVE_ARC4RANDOM_BUF arc4random_buf(buffer, (size_t)bufferLength); +#elif HAVE_BCRYPT_H + // Fall back to the secure version + minipal_get_cryptographically_secure_random_bytes(buffer, bufferLength); #else long num = 0; static bool sInitializedMRand; @@ -86,6 +95,9 @@ int32_t minipal_get_cryptographically_secure_random_bytes(uint8_t* buffer, int32 { return 0; } +#elif HAVE_BCRYPT_H + NTSTATUS status = BCryptGenRandom(NULL, buffer, (ULONG)bufferLength, BCRYPT_USE_SYSTEM_PREFERRED_RNG); + return BCRYPT_SUCCESS(status) ? 0 : -1; #else static volatile int rand_des = -1; diff --git a/src/native/minipal/asansupport.cpp b/src/native/minipal/sansupport.c similarity index 79% rename from src/native/minipal/asansupport.cpp rename to src/native/minipal/sansupport.c index b5873cd95b6de..d9891e1bc8557 100644 --- a/src/native/minipal/asansupport.cpp +++ b/src/native/minipal/sansupport.c @@ -4,7 +4,10 @@ // Use a typedef here as __declspec + pointer return type causes a parse error in MSVC typedef const char* charptr_t; -extern "C" charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options() { + +charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options(void); + +charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options(void) { // symbolize=1 to get symbolized stack traces // use_sigaltstack=0 as coreclr uses own alternate stack for signal handlers // detect_leaks=0 as coreclr intentionally doesn't clean up all memory on exit @@ -15,5 +18,6 @@ extern "C" charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options() { return "symbolize=1 use_sigaltstack=0 detect_leaks=0 handle_segv=0 allocator_may_return_null=1"; } -extern "C" void SANITIZER_CALLBACK_CALLCONV __asan_on_error() { +void SANITIZER_CALLBACK_CALLCONV __asan_on_error(void); +void SANITIZER_CALLBACK_CALLCONV __asan_on_error(void) { } diff --git a/src/native/minipal/time.c b/src/native/minipal/time.c index 0a76df5d45342..8051731b7d13b 100644 --- a/src/native/minipal/time.c +++ b/src/native/minipal/time.c @@ -3,8 +3,9 @@ #include #include +#include "minipalconfig.h" -#ifdef HOST_WINDOWS +#if HAVE_WINDOWS_H #include @@ -22,7 +23,7 @@ int64_t minipal_hires_tick_frequency() return ts.QuadPart; } -#else // HOST_WINDOWS +#else // HAVE_WINDOWS_H #include "minipalconfig.h" @@ -53,12 +54,12 @@ inline static void YieldProcessor() } #define tccSecondsToNanoSeconds 1000000000 // 10^9 -int64_t minipal_hires_tick_frequency() +int64_t minipal_hires_tick_frequency(void) { return tccSecondsToNanoSeconds; } -int64_t minipal_hires_ticks() +int64_t minipal_hires_ticks(void) { #if HAVE_CLOCK_GETTIME_NSEC_NP return (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW); @@ -74,11 +75,11 @@ int64_t minipal_hires_ticks() #endif } -#endif // !HOST_WINDOWS +#endif // !HAVE_WINDOWS_H void minipal_microdelay(uint32_t usecs, uint32_t* usecsSinceYield) { -#ifdef HOST_WINDOWS +#if HAVE_WINDOWS_H if (usecs > 1000) { SleepEx(usecs / 1000, FALSE); diff --git a/src/native/minipal/time.h b/src/native/minipal/time.h index 313aeb695607c..27359aa407c75 100644 --- a/src/native/minipal/time.h +++ b/src/native/minipal/time.h @@ -12,10 +12,10 @@ extern "C" #endif // __cplusplus // Returns current count of high resolution monotonically increasing timer ticks - int64_t minipal_hires_ticks(); + int64_t minipal_hires_ticks(void); // Returns the frequency of high resolution timer ticks in Hz - int64_t minipal_hires_tick_frequency(); + int64_t minipal_hires_tick_frequency(void); // Delays execution of current thread by `usecs` microseconds. // The delay is best-effort and may take longer than desired.