From e98fb61d8b4bb6687ccddead861d8b140751647b Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Thu, 17 Dec 2020 20:43:16 -0800 Subject: [PATCH] Moving the rest of Unix libraries to the 'overrider' mechanism when linked into static host. (#45995) * System.Net.Security.Native * System.Native * fix for OSX * fix for wasm * fix for IOS * Fix for FreeBSD * System.Security.Cryptography.Native.OpenSsl * fix OSX * Add script to validate entrypoints.c against dll entries * add missing CryptoNative entries * Added verification in more projects * Add missing entries in other files * System.Security.Cryptography.Native.Apple * fix for IOS/TVOS * Change .py verification script to bash * Update the verify_entrypoints.sh to not to use awk and work on macOS * PR feedback * reduce exports of System.IO.Compression.Native.dll on Windows to what is actually used and to match Unix. * unixexports for System.IO.Compression.Native * trying to fix IOS/TVOS * move awk and linker flavor detection to configuretools.cmake Co-authored-by: Jan Vorlicek --- eng/native/configurecompiler.cmake | 19 - eng/native/configuretools.cmake | 22 ++ eng/native/functions.cmake | 4 +- src/coreclr/vm/dllimport.cpp | 21 -- .../cli/apphost/static/CMakeLists.txt | 100 +++--- .../cli/hostpolicy/hostpolicy_context.cpp | 41 ++- .../Directory.Build.props | 4 - .../CMakeLists.txt | 27 +- ...stem.IO.Compression.Native_unixexports.src | 21 ++ .../Native/Unix/System.Native/CMakeLists.txt | 25 +- .../Native/Unix/System.Native/entrypoints.c | 243 +++++++++++++ .../Unix/System.Native/extra_libs.cmake | 6 +- .../System.Native/pal_interfaceaddresses.c | 8 + .../System.Native/pal_interfaceaddresses.h | 2 - .../Native/Unix/System.Native/pal_io.c | 10 +- .../Native/Unix/System.Native/pal_io.h | 4 - .../Unix/System.Native/pal_networkchange.c | 14 +- .../System.Native/pal_networkstatistics.c | 87 ++++- .../Native/Unix/System.Native/pal_process.c | 16 + .../Native/Unix/System.Native/pal_process.h | 4 - .../Unix/System.Native/pal_searchpath.c | 12 + .../Native/Unix/System.Native/pal_sysctl.c | 21 +- .../System.Net.Security.Native/CMakeLists.txt | 12 + .../System.Net.Security.Native/entrypoints.c | 36 ++ .../CMakeLists.txt | 10 +- .../entrypoints.c | 115 ++++++ .../extra_libs.cmake | 7 + .../CMakeLists.txt | 16 + .../entrypoints.c | 331 ++++++++++++++++++ .../extra_libs.cmake | 2 +- .../Native/Unix/verify-entrypoints.sh | 40 +++ .../System.IO.Compression.Native.def | 37 +- src/mono/wasm/runtime/driver.c | 9 - 33 files changed, 1137 insertions(+), 189 deletions(-) create mode 100644 src/libraries/Native/Unix/System.IO.Compression.Native/System.IO.Compression.Native_unixexports.src create mode 100644 src/libraries/Native/Unix/System.Native/entrypoints.c create mode 100644 src/libraries/Native/Unix/System.Native/pal_searchpath.c create mode 100644 src/libraries/Native/Unix/System.Net.Security.Native/entrypoints.c create mode 100644 src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/entrypoints.c create mode 100644 src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/extra_libs.cmake create mode 100644 src/libraries/Native/Unix/System.Security.Cryptography.Native/entrypoints.c create mode 100755 src/libraries/Native/Unix/verify-entrypoints.sh diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index e3a026fc5a81b..3676f9571a78a 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -641,23 +641,4 @@ if (CLR_CMAKE_HOST_WIN32) else (CLR_CMAKE_HOST_WIN32) enable_language(ASM) - # Ensure that awk is present - find_program(AWK awk) - if (AWK STREQUAL "AWK-NOTFOUND") - message(FATAL_ERROR "AWK not found") - endif() - - # detect linker - set(ldVersion ${CMAKE_C_COMPILER};-Wl,--version) - execute_process(COMMAND ${ldVersion} - ERROR_QUIET - OUTPUT_VARIABLE ldVersionOutput) - - if("${ldVersionOutput}" MATCHES "GNU ld" OR "${ldVersionOutput}" MATCHES "GNU gold" OR "${ldVersionOutput}" MATCHES "GNU linkers") - set(LD_GNU 1) - elseif("${ldVersionOutput}" MATCHES "Solaris Link") - set(LD_SOLARIS 1) - else(CLR_CMAKE_HOST_OSX) - set(LD_OSX 1) - endif() endif(CLR_CMAKE_HOST_WIN32) diff --git a/eng/native/configuretools.cmake b/eng/native/configuretools.cmake index 85e6bac96c7d1..873e6d3a38733 100644 --- a/eng/native/configuretools.cmake +++ b/eng/native/configuretools.cmake @@ -62,3 +62,25 @@ if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER) locate_toolchain_exec(objcopy CMAKE_OBJCOPY) endif() endif() + +if (NOT CLR_CMAKE_HOST_WIN32) + # Ensure that awk is present + find_program(AWK awk) + if (AWK STREQUAL "AWK-NOTFOUND") + message(FATAL_ERROR "AWK not found") + endif() + + # detect linker + set(ldVersion ${CMAKE_C_COMPILER};-Wl,--version) + execute_process(COMMAND ${ldVersion} + ERROR_QUIET + OUTPUT_VARIABLE ldVersionOutput) + + if("${ldVersionOutput}" MATCHES "GNU ld" OR "${ldVersionOutput}" MATCHES "GNU gold" OR "${ldVersionOutput}" MATCHES "GNU linkers") + set(LD_GNU 1) + elseif("${ldVersionOutput}" MATCHES "Solaris Link") + set(LD_SOLARIS 1) + else(CLR_CMAKE_HOST_OSX) + set(LD_OSX 1) + endif() +endif() diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index fdf803a696775..88c7160f35e73 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -211,11 +211,11 @@ function(generate_exports_file) list(GET INPUT_LIST -1 outputFilename) list(REMOVE_AT INPUT_LIST -1) - if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) set(AWK_SCRIPT generateexportedsymbols.awk) else() set(AWK_SCRIPT generateversionscript.awk) - endif(CMAKE_SYSTEM_NAME STREQUAL Darwin) + endif() add_custom_command( OUTPUT ${outputFilename} diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp index 187a344b85422..a2f029487d923 100644 --- a/src/coreclr/vm/dllimport.cpp +++ b/src/coreclr/vm/dllimport.cpp @@ -6158,27 +6158,6 @@ namespace } #endif // FEATURE_CORESYSTEM && !TARGET_UNIX -#if defined(TARGET_LINUX) - if (g_coreclr_embedded) - { - // this matches exactly the names in Interop.Libraries.cs - static const LPCWSTR toRedirect[] = { - W("libSystem.Native"), - W("libSystem.Net.Security.Native"), - W("libSystem.Security.Cryptography.Native.OpenSsl") - }; - - int count = lengthof(toRedirect); - for (int i = 0; i < count; ++i) - { - if (wcscmp(wszLibName, toRedirect[i]) == 0) - { - return PAL_LoadLibraryDirect(NULL); - } - } - } -#endif - if (g_hostpolicy_embedded) { #ifdef TARGET_WINDOWS diff --git a/src/installer/corehost/cli/apphost/static/CMakeLists.txt b/src/installer/corehost/cli/apphost/static/CMakeLists.txt index 530806e4ae240..6b4986ba310ea 100644 --- a/src/installer/corehost/cli/apphost/static/CMakeLists.txt +++ b/src/installer/corehost/cli/apphost/static/CMakeLists.txt @@ -102,13 +102,6 @@ if(CLR_CMAKE_TARGET_WIN32) add_linker_flag("/INCREMENTAL:NO") endif() -# Specify non-default Windows libs to be used for Arm/Arm64 builds -if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64)) - target_link_libraries(singlefilehost Advapi32.lib shell32.lib) -endif() - -set(NATIVE_LIBS_EXTRA) - # Path like: artifacts/bin/coreclr/windows.x64.Release/lib or # /root/runtime/artifacts/transport/coreclr/lib set(CORECLR_STATIC_LIB_LOCATION "${CORECLR_ARTIFACTS}/lib") @@ -116,7 +109,7 @@ set(CORECLR_STATIC_LIB_LOCATION "${CORECLR_ARTIFACTS}/lib") message ("Looking for coreclr_static lib at location: '${CORECLR_STATIC_LIB_LOCATION}'.") if(CLR_CMAKE_TARGET_WIN32) - set(CORECLR_LIBRARIES + set(NATIVE_LIBS ${CORECLR_STATIC_LIB_LOCATION}/coreclr_static.lib ${CORECLR_STATIC_LIB_LOCATION}/System.Globalization.Native.lib ${CORECLR_STATIC_LIB_LOCATION}/System.IO.Compression.Native.lib @@ -132,10 +125,13 @@ if(CLR_CMAKE_TARGET_WIN32) RuntimeObject.lib ) else() - set(CORECLR_LIBRARIES + set(NATIVE_LIBS ${CORECLR_STATIC_LIB_LOCATION}/libcoreclr_static.a ${CORECLR_STATIC_LIB_LOCATION}/libSystem.Globalization.Native.a ${CORECLR_STATIC_LIB_LOCATION}/libSystem.IO.Compression.Native.a + ${CORECLR_STATIC_LIB_LOCATION}/libSystem.Net.Security.Native.a + ${CORECLR_STATIC_LIB_LOCATION}/libSystem.Native.a + ${CORECLR_STATIC_LIB_LOCATION}/libSystem.Security.Cryptography.Native.OpenSsl.a ${CORECLR_STATIC_LIB_LOCATION}/libpalrt.a ${CORECLR_STATIC_LIB_LOCATION}/libcoreclrpal.a ${CORECLR_STATIC_LIB_LOCATION}/libeventprovider.a @@ -144,7 +140,41 @@ else() # additional requirements for System.IO.Compression.Native include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.IO.Compression.Native/extra_libs.cmake) - append_extra_compression_libs(NATIVE_LIBS_EXTRA) + append_extra_compression_libs(NATIVE_LIBS) + + # Additional requirements for System.Net.Security.Native + include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Net.Security.Native/extra_libs.cmake) + append_extra_security_libs(NATIVE_LIBS) + + # Additional requirements for System.Native + include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Native/extra_libs.cmake) + append_extra_system_libs(NATIVE_LIBS) + + # Additional requirements for System.Security.Cryptography.Native.OpenSsl + include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake) + append_extra_cryptography_libs(NATIVE_LIBS) +endif() + +if(CLR_CMAKE_TARGET_OSX) + LIST(APPEND NATIVE_LIBS + ${CORECLR_STATIC_LIB_LOCATION}/libSystem.Security.Cryptography.Native.Apple.a + ) + + # Additional requirements for System.Security.Cryptography.Native.Apple + include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/extra_libs.cmake) + append_extra_cryptography_apple_libs(NATIVE_LIBS) +endif() + +# +# Additional requirements for coreclr +# + +# Specify non-default Windows libs to be used for Arm/Arm64 builds +if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64)) + LIST(APPEND NATIVE_LIBS + Advapi32.lib + shell32.lib + ) endif() if(CLR_CMAKE_TARGET_OSX) @@ -153,7 +183,7 @@ if(CLR_CMAKE_TARGET_OSX) find_library(SECURITY Security) find_library(SYSTEM System) - LIST(APPEND CORECLR_LIBRARIES + LIST(APPEND NATIVE_LIBS ${COREFOUNDATION} ${CORESERVICES} ${SECURITY} @@ -162,11 +192,11 @@ if(CLR_CMAKE_TARGET_OSX) elseif(CLR_CMAKE_TARGET_NETBSD) find_library(KVM kvm) - LIST(APPEND CORECLR_LIBRARIES + LIST(APPEND NATIVE_LIBS ${KVM} ) elseif (CLR_CMAKE_TARGET_SUNOS) - LIST(APPEND CORECLR_LIBRARIES + LIST(APPEND NATIVE_LIBS socket ) endif(CLR_CMAKE_TARGET_OSX) @@ -179,50 +209,12 @@ endif() if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND) find_unwind_libs(UNWIND_LIBS) - LIST(APPEND CORECLR_LIBRARIES + LIST(APPEND NATIVE_LIBS ${UNWIND_LIBS} ) endif() -# Path like: artifacts/bin/native/net5.0-Linux-Release-arm/ -set(NATIVE_LIBS_LOCATION "${NATIVE_LIBS_ARTIFACTS}") -message ("Looking for native libs at location: '${NATIVE_LIBS_LOCATION}'.") - -# These native libs are linked into singlefilehost only on Linux (for now). -if(CLR_CMAKE_TARGET_LINUX) - set(NATIVE_LIBS - ${NATIVE_LIBS_LOCATION}/libSystem.Native.a - ${NATIVE_LIBS_LOCATION}/libSystem.Net.Security.Native.a - ${NATIVE_LIBS_LOCATION}/libSystem.Security.Cryptography.Native.OpenSsl.a - ) - - # Additional requirements for System.Native - include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Native/extra_libs.cmake) - append_extra_system_libs(NATIVE_LIBS_EXTRA) - - # Additional requirements for System.Net.Security.Native - include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Net.Security.Native/extra_libs.cmake) - append_extra_security_libs(NATIVE_LIBS_EXTRA) - - # Additional requirements for System.Security.Cryptography.Native.OpenSsl - include(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake) - append_extra_cryptography_libs(NATIVE_LIBS_EXTRA) -endif() - -if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS) - # These options are used to force every object to be included even if it's unused. - set(START_WHOLE_ARCHIVE -Wl,--whole-archive) - set(END_WHOLE_ARCHIVE -Wl,--no-whole-archive) -endif(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS) - -set_property(TARGET singlefilehost PROPERTY ENABLE_EXPORTS 1) - -target_link_libraries(singlefilehost - ${CORECLR_LIBRARIES} - - ${START_WHOLE_ARCHIVE} +target_link_libraries( + singlefilehost ${NATIVE_LIBS} - ${END_WHOLE_ARCHIVE} - - ${NATIVE_LIBS_EXTRA} ) diff --git a/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp b/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp index 6abafe19a841b..4c7ad15f2cb2b 100644 --- a/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp +++ b/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp @@ -45,22 +45,49 @@ namespace #if defined(NATIVE_LIBS_EMBEDDED) extern "C" const void* CompressionResolveDllImport(const char* name); - -#if defined(_WIN32) -#define COMPRESSION_DLL_NAME "System.IO.Compression.Native" -#else -#define COMPRESSION_DLL_NAME "libSystem.IO.Compression.Native" -#endif + extern "C" const void* SecurityResolveDllImport(const char* name); + extern "C" const void* SystemResolveDllImport(const char* name); + extern "C" const void* CryptoResolveDllImport(const char* name); + extern "C" const void* CryptoAppleResolveDllImport(const char* name); // pinvoke_override: // Check if given function belongs to one of statically linked libraries and return a pointer if found. const void* STDMETHODCALLTYPE pinvoke_override(const char* libraryName, const char* entrypointName) { - if (strcmp(libraryName, COMPRESSION_DLL_NAME) == 0) +#if defined(_WIN32) + if (strcmp(libraryName, "System.IO.Compression.Native") == 0) + { + return CompressionResolveDllImport(entrypointName); + } +#else + if (strcmp(libraryName, "libSystem.IO.Compression.Native") == 0) { return CompressionResolveDllImport(entrypointName); } + if (strcmp(libraryName, "libSystem.Net.Security.Native") == 0) + { + return SecurityResolveDllImport(entrypointName); + } + + if (strcmp(libraryName, "libSystem.Native") == 0) + { + return SystemResolveDllImport(entrypointName); + } + + if (strcmp(libraryName, "libSystem.Security.Cryptography.Native.OpenSsl") == 0) + { + return CryptoResolveDllImport(entrypointName); + } +#endif + +#if defined(TARGET_OSX) + if (strcmp(libraryName, "libSystem.Security.Cryptography.Native.Apple") == 0) + { + return CryptoAppleResolveDllImport(entrypointName); + } +#endif + return nullptr; } #endif diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index a475dd2e71f16..b72203c38f8b6 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -14,10 +14,6 @@ - - - - diff --git a/src/libraries/Native/Unix/System.IO.Compression.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.IO.Compression.Native/CMakeLists.txt index 28f57b4f5593e..8934a5f0933a7 100644 --- a/src/libraries/Native/Unix/System.IO.Compression.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.IO.Compression.Native/CMakeLists.txt @@ -14,8 +14,6 @@ set(NATIVECOMPRESSION_SOURCES ) if (NOT CLR_CMAKE_TARGET_BROWSER) - add_definitions(-DBROTLI_SHARED_COMPILATION) - #Include Brotli include files include_directories("../../AnyOS/brotli/include") @@ -58,6 +56,8 @@ if (NOT CLR_CMAKE_TARGET_BROWSER) endif() if (GEN_SHARED_LIB) + add_definitions(-DBROTLI_SHARED_COMPILATION) + add_library(System.IO.Compression.Native SHARED ${NATIVECOMPRESSION_SOURCES} @@ -67,6 +67,29 @@ if (GEN_SHARED_LIB) target_link_libraries(System.IO.Compression.Native ${NATIVE_LIBS_EXTRA} ) + + set(DEF_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/System.IO.Compression.Native_unixexports.src) + set(EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/System.IO.Compression.Native.exports) + generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE}) + set_exports_linker_option(${EXPORTS_FILE}) + + add_custom_target(System.IO.Compression.Native_exports DEPENDS ${EXPORTS_FILE}) + add_dependencies(System.IO.Compression.Native System.IO.Compression.Native_exports) + + set_property(TARGET System.IO.Compression.Native APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION}) + set_property(TARGET System.IO.Compression.Native APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE}) + + if (NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID) + add_custom_command(TARGET System.IO.Compression.Native POST_BUILD + COMMENT "Verifying System.IO.Compression.Native entry points against entrypoints.c " + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-entrypoints.sh + $ + ${CMAKE_CURRENT_SOURCE_DIR}/../../AnyOS/System.IO.Compression.Native/entrypoints.c + ${CMAKE_NM} + VERBATIM + ) + endif() + install_with_stripped_symbols (System.IO.Compression.Native PROGRAMS .) endif () diff --git a/src/libraries/Native/Unix/System.IO.Compression.Native/System.IO.Compression.Native_unixexports.src b/src/libraries/Native/Unix/System.IO.Compression.Native/System.IO.Compression.Native_unixexports.src new file mode 100644 index 0000000000000..08dd1700a52f2 --- /dev/null +++ b/src/libraries/Native/Unix/System.IO.Compression.Native/System.IO.Compression.Native_unixexports.src @@ -0,0 +1,21 @@ +; Licensed to the .NET Foundation under one or more agreements. +; The .NET Foundation licenses this file to you under the MIT license. + +BrotliDecoderCreateInstance +BrotliDecoderDecompress +BrotliDecoderDecompressStream +BrotliDecoderDestroyInstance +BrotliDecoderIsFinished +BrotliEncoderCompress +BrotliEncoderCompressStream +BrotliEncoderCreateInstance +BrotliEncoderDestroyInstance +BrotliEncoderHasMoreOutput +BrotliEncoderSetParameter +CompressionNative_Crc32 +CompressionNative_Deflate +CompressionNative_DeflateEnd +CompressionNative_DeflateInit2_ +CompressionNative_Inflate +CompressionNative_InflateEnd +CompressionNative_InflateInit2_ diff --git a/src/libraries/Native/Unix/System.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.Native/CMakeLists.txt index d41bb807b0cba..68f4df1f7ea17 100644 --- a/src/libraries/Native/Unix/System.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.Native/CMakeLists.txt @@ -35,22 +35,13 @@ if (CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) pal_searchpath.m) else () set(NATIVE_SOURCES ${NATIVE_SOURCES} + pal_searchpath.c pal_console.c pal_log.c) endif () -if (CLR_CMAKE_TARGET_LINUX AND NOT CLR_CMAKE_TARGET_BROWSER) +if (NOT CLR_CMAKE_TARGET_BROWSER) set(NATIVE_SOURCES ${NATIVE_SOURCES} pal_networkchange.c) - - if (!HAVE_LINUX_RTNETLINK_H) - message(FATAL_ERROR "Could not find linux/rtnetlink.h") - endif () -elseif (CLR_CMAKE_TARGET_FREEBSD) - set(NATIVE_SOURCES ${NATIVE_SOURCES} pal_networkchange.c) - - if (!HAVE_RT_MSGHDR) - message(FATAL_ERROR "Could not find net/route.h") - endif () endif () include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) @@ -69,12 +60,24 @@ if (GEN_SHARED_LIB) ${NATIVE_LIBS_EXTRA} ) + if (NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID) + add_custom_command(TARGET System.Native POST_BUILD + COMMENT "Verifying System.Native entry points against entrypoints.c " + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-entrypoints.sh + $ + ${CMAKE_CURRENT_SOURCE_DIR}/entrypoints.c + ${CMAKE_NM} + VERBATIM + ) + endif() + install_with_stripped_symbols (System.Native PROGRAMS .) endif () add_library(System.Native-Static STATIC ${NATIVE_SOURCES} + entrypoints.c ) set_target_properties(System.Native-Static PROPERTIES OUTPUT_NAME System.Native CLEAN_DIRECT_OUTPUT 1) diff --git a/src/libraries/Native/Unix/System.Native/entrypoints.c b/src/libraries/Native/Unix/System.Native/entrypoints.c new file mode 100644 index 0000000000000..4a6c65ac505e4 --- /dev/null +++ b/src/libraries/Native/Unix/System.Native/entrypoints.c @@ -0,0 +1,243 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "../../AnyOS/entrypoints.h" + +// Include System.Native headers +#include "pal_console.h" +#include "pal_datetime.h" +#include "pal_errno.h" +#include "pal_interfaceaddresses.h" +#include "pal_io.h" +#include "pal_log.h" +#include "pal_memory.h" +#include "pal_mount.h" +#include "pal_networkchange.h" +#include "pal_networking.h" +#include "pal_networkstatistics.h" +#include "pal_process.h" +#include "pal_random.h" +#include "pal_runtimeextensions.h" +#include "pal_runtimeinformation.h" +#include "pal_searchpath.h" +#include "pal_signal.h" +#include "pal_string.h" +#include "pal_sysctl.h" +#include "pal_tcpstate.h" +#include "pal_threading.h" +#include "pal_time.h" +#include "pal_uid.h" + +static const Entry s_sysNative[] = +{ + DllImportEntry(SystemNative_FStat) + DllImportEntry(SystemNative_GetWindowSize) + DllImportEntry(SystemNative_IsATty) + DllImportEntry(SystemNative_InitializeTerminalAndSignalHandling) + DllImportEntry(SystemNative_SetKeypadXmit) + DllImportEntry(SystemNative_GetControlCharacters) + DllImportEntry(SystemNative_StdinReady) + DllImportEntry(SystemNative_InitializeConsoleBeforeRead) + DllImportEntry(SystemNative_UninitializeConsoleAfterRead) + DllImportEntry(SystemNative_ConfigureTerminalForChildProcess) + DllImportEntry(SystemNative_ReadStdin) + DllImportEntry(SystemNative_GetSignalForBreak) + DllImportEntry(SystemNative_SetSignalForBreak) + DllImportEntry(SystemNative_GetSystemTimeAsTicks) + DllImportEntry(SystemNative_ConvertErrorPlatformToPal) + DllImportEntry(SystemNative_ConvertErrorPalToPlatform) + DllImportEntry(SystemNative_StrErrorR) + DllImportEntry(SystemNative_EnumerateInterfaceAddresses) + DllImportEntry(SystemNative_GetNetworkInterfaces) + DllImportEntry(SystemNative_EnumerateGatewayAddressesForInterface) + DllImportEntry(SystemNative_Stat) + DllImportEntry(SystemNative_LStat) + DllImportEntry(SystemNative_Open) + DllImportEntry(SystemNative_Close) + DllImportEntry(SystemNative_Dup) + DllImportEntry(SystemNative_Unlink) + DllImportEntry(SystemNative_ShmOpen) + DllImportEntry(SystemNative_ShmUnlink) + DllImportEntry(SystemNative_GetReadDirRBufferSize) + DllImportEntry(SystemNative_ReadDirR) + DllImportEntry(SystemNative_OpenDir) + DllImportEntry(SystemNative_CloseDir) + DllImportEntry(SystemNative_Pipe) + DllImportEntry(SystemNative_FcntlSetFD) + DllImportEntry(SystemNative_FcntlGetFD) + DllImportEntry(SystemNative_FcntlCanGetSetPipeSz) + DllImportEntry(SystemNative_FcntlGetPipeSz) + DllImportEntry(SystemNative_FcntlSetPipeSz) + DllImportEntry(SystemNative_FcntlSetIsNonBlocking) + DllImportEntry(SystemNative_FcntlGetIsNonBlocking) + DllImportEntry(SystemNative_MkDir) + DllImportEntry(SystemNative_ChMod) + DllImportEntry(SystemNative_FChMod) + DllImportEntry(SystemNative_FSync) + DllImportEntry(SystemNative_FLock) + DllImportEntry(SystemNative_ChDir) + DllImportEntry(SystemNative_Access) + DllImportEntry(SystemNative_LSeek) + DllImportEntry(SystemNative_Link) + DllImportEntry(SystemNative_MksTemps) + DllImportEntry(SystemNative_MMap) + DllImportEntry(SystemNative_MUnmap) + DllImportEntry(SystemNative_MAdvise) + DllImportEntry(SystemNative_MSync) + DllImportEntry(SystemNative_SysConf) + DllImportEntry(SystemNative_FTruncate) + DllImportEntry(SystemNative_Poll) + DllImportEntry(SystemNative_PosixFAdvise) + DllImportEntry(SystemNative_Read) + DllImportEntry(SystemNative_ReadLink) + DllImportEntry(SystemNative_Rename) + DllImportEntry(SystemNative_RmDir) + DllImportEntry(SystemNative_Sync) + DllImportEntry(SystemNative_Write) + DllImportEntry(SystemNative_CopyFile) + DllImportEntry(SystemNative_INotifyInit) + DllImportEntry(SystemNative_INotifyAddWatch) + DllImportEntry(SystemNative_INotifyRemoveWatch) + DllImportEntry(SystemNative_RealPath) + DllImportEntry(SystemNative_GetPeerID) + DllImportEntry(SystemNative_LockFileRegion) + DllImportEntry(SystemNative_LChflags) + DllImportEntry(SystemNative_LChflagsCanSetHiddenFlag) + DllImportEntry(SystemNative_ReadProcessStatusInfo) + DllImportEntry(SystemNative_Log) + DllImportEntry(SystemNative_MemAlloc) + DllImportEntry(SystemNative_MemReAlloc) + DllImportEntry(SystemNative_MemFree) + DllImportEntry(SystemNative_MemSet) + DllImportEntry(SystemNative_GetSpaceInfoForMountPoint) + DllImportEntry(SystemNative_GetFormatInfoForMountPoint) + DllImportEntry(SystemNative_GetAllMountPoints) + DllImportEntry(SystemNative_ReadEvents) + DllImportEntry(SystemNative_CreateNetworkChangeListenerSocket) + DllImportEntry(SystemNative_CloseNetworkChangeListenerSocket) + DllImportEntry(SystemNative_GetHostEntryForName) + DllImportEntry(SystemNative_FreeHostEntry) + DllImportEntry(SystemNative_GetNameInfo) + DllImportEntry(SystemNative_GetDomainName) + DllImportEntry(SystemNative_GetHostName) + DllImportEntry(SystemNative_GetIPSocketAddressSizes) + DllImportEntry(SystemNative_GetAddressFamily) + DllImportEntry(SystemNative_SetAddressFamily) + DllImportEntry(SystemNative_GetPort) + DllImportEntry(SystemNative_SetPort) + DllImportEntry(SystemNative_GetIPv4Address) + DllImportEntry(SystemNative_SetIPv4Address) + DllImportEntry(SystemNative_GetIPv6Address) + DllImportEntry(SystemNative_SetIPv6Address) + DllImportEntry(SystemNative_GetControlMessageBufferSize) + DllImportEntry(SystemNative_TryGetIPPacketInformation) + DllImportEntry(SystemNative_GetIPv4MulticastOption) + DllImportEntry(SystemNative_SetIPv4MulticastOption) + DllImportEntry(SystemNative_GetIPv6MulticastOption) + DllImportEntry(SystemNative_SetIPv6MulticastOption) + DllImportEntry(SystemNative_GetLingerOption) + DllImportEntry(SystemNative_SetLingerOption) + DllImportEntry(SystemNative_SetReceiveTimeout) + DllImportEntry(SystemNative_SetSendTimeout) + DllImportEntry(SystemNative_Receive) + DllImportEntry(SystemNative_ReceiveMessage) + DllImportEntry(SystemNative_Send) + DllImportEntry(SystemNative_SendMessage) + DllImportEntry(SystemNative_Accept) + DllImportEntry(SystemNative_Bind) + DllImportEntry(SystemNative_Connect) + DllImportEntry(SystemNative_GetPeerName) + DllImportEntry(SystemNative_GetSockName) + DllImportEntry(SystemNative_Listen) + DllImportEntry(SystemNative_Shutdown) + DllImportEntry(SystemNative_GetSocketErrorOption) + DllImportEntry(SystemNative_GetSockOpt) + DllImportEntry(SystemNative_GetRawSockOpt) + DllImportEntry(SystemNative_SetSockOpt) + DllImportEntry(SystemNative_SetRawSockOpt) + DllImportEntry(SystemNative_Socket) + DllImportEntry(SystemNative_GetSocketType) + DllImportEntry(SystemNative_GetAtOutOfBandMark) + DllImportEntry(SystemNative_GetBytesAvailable) + DllImportEntry(SystemNative_CreateSocketEventPort) + DllImportEntry(SystemNative_CloseSocketEventPort) + DllImportEntry(SystemNative_CreateSocketEventBuffer) + DllImportEntry(SystemNative_FreeSocketEventBuffer) + DllImportEntry(SystemNative_TryChangeSocketEventRegistration) + DllImportEntry(SystemNative_WaitForSocketEvents) + DllImportEntry(SystemNative_PlatformSupportsDualModeIPv4PacketInfo) + DllImportEntry(SystemNative_GetPeerUserName) + DllImportEntry(SystemNative_GetDomainSocketSizes) + DllImportEntry(SystemNative_GetMaximumAddressSize) + DllImportEntry(SystemNative_SendFile) + DllImportEntry(SystemNative_Disconnect) + DllImportEntry(SystemNative_InterfaceNameToIndex) + DllImportEntry(SystemNative_GetTcpGlobalStatistics) + DllImportEntry(SystemNative_GetIPv4GlobalStatistics) + DllImportEntry(SystemNative_GetUdpGlobalStatistics) + DllImportEntry(SystemNative_GetIcmpv4GlobalStatistics) + DllImportEntry(SystemNative_GetIcmpv6GlobalStatistics) + DllImportEntry(SystemNative_GetEstimatedTcpConnectionCount) + DllImportEntry(SystemNative_GetActiveTcpConnectionInfos) + DllImportEntry(SystemNative_GetEstimatedUdpListenerCount) + DllImportEntry(SystemNative_GetActiveUdpListeners) + DllImportEntry(SystemNative_GetNativeIPInterfaceStatistics) + DllImportEntry(SystemNative_GetNumRoutes) + DllImportEntry(SystemNative_ForkAndExecProcess) + DllImportEntry(SystemNative_GetRLimit) + DllImportEntry(SystemNative_SetRLimit) + DllImportEntry(SystemNative_Kill) + DllImportEntry(SystemNative_GetPid) + DllImportEntry(SystemNative_GetSid) + DllImportEntry(SystemNative_SysLog) + DllImportEntry(SystemNative_WaitIdAnyExitedNoHangNoWait) + DllImportEntry(SystemNative_WaitPidExitedNoHang) + DllImportEntry(SystemNative_PathConf) + DllImportEntry(SystemNative_GetPriority) + DllImportEntry(SystemNative_SetPriority) + DllImportEntry(SystemNative_GetCwd) + DllImportEntry(SystemNative_SchedSetAffinity) + DllImportEntry(SystemNative_SchedGetAffinity) + DllImportEntry(SystemNative_GetProcessPath) + DllImportEntry(SystemNative_GetNonCryptographicallySecureRandomBytes) + DllImportEntry(SystemNative_GetCryptographicallySecureRandomBytes) + DllImportEntry(SystemNative_GetNodeName) + DllImportEntry(SystemNative_GetUnixName) + DllImportEntry(SystemNative_GetUnixRelease) + DllImportEntry(SystemNative_GetUnixVersion) + DllImportEntry(SystemNative_GetOSArchitecture) + DllImportEntry(SystemNative_GetProcessArchitecture) + DllImportEntry(SystemNative_SearchPath) + DllImportEntry(SystemNative_RegisterForCtrl) + DllImportEntry(SystemNative_UnregisterForCtrl) + DllImportEntry(SystemNative_RegisterForSigChld) + DllImportEntry(SystemNative_RestoreAndHandleCtrl) + DllImportEntry(SystemNative_SetTerminalInvalidationHandler) + DllImportEntry(SystemNative_InitializeTerminalAndSignalHandling) + DllImportEntry(SystemNative_SNPrintF) + DllImportEntry(SystemNative_Sysctl) + DllImportEntry(SystemNative_MapTcpState) + DllImportEntry(SystemNative_LowLevelMonitor_Destroy) + DllImportEntry(SystemNative_LowLevelMonitor_Acquire) + DllImportEntry(SystemNative_LowLevelMonitor_Release) + DllImportEntry(SystemNative_LowLevelMonitor_Wait) + DllImportEntry(SystemNative_LowLevelMonitor_Signal_Release) + DllImportEntry(SystemNative_UTimensat) + DllImportEntry(SystemNative_GetTimestamp) + DllImportEntry(SystemNative_GetCpuUtilization) + DllImportEntry(SystemNative_GetPwUidR) + DllImportEntry(SystemNative_GetPwNamR) + DllImportEntry(SystemNative_GetEUid) + DllImportEntry(SystemNative_GetEGid) + DllImportEntry(SystemNative_SetEUid) + DllImportEntry(SystemNative_GetGroupList) + DllImportEntry(SystemNative_GetUid) + DllImportEntry(SystemNative_LowLevelMonitor_Create) +}; + +EXTERN_C const void* SystemResolveDllImport(const char* name); + +EXTERN_C const void* SystemResolveDllImport(const char* name) +{ + return ResolveDllImport(s_sysNative, lengthof(s_sysNative), name); +} diff --git a/src/libraries/Native/Unix/System.Native/extra_libs.cmake b/src/libraries/Native/Unix/System.Native/extra_libs.cmake index b0cb4c1aa58f2..0b3f8424d2954 100644 --- a/src/libraries/Native/Unix/System.Native/extra_libs.cmake +++ b/src/libraries/Native/Unix/System.Native/extra_libs.cmake @@ -4,10 +4,8 @@ macro(append_extra_system_libs NativeLibsExtra) list(APPEND ${NativeLibsExtra} rt) elseif (CLR_CMAKE_TARGET_FREEBSD) list(APPEND ${NativeLibsExtra} pthread) - if (HAVE_INOTIFY) - find_library(INOTIFY_LIBRARY inotify HINTS /usr/local/lib) - list(APPEND ${NativeLibsExtra} ${INOTIFY_LIBRARY}) - endif () + find_library(INOTIFY_LIBRARY inotify HINTS /usr/local/lib) + list(APPEND ${NativeLibsExtra} ${INOTIFY_LIBRARY}) elseif (CLR_CMAKE_TARGET_SUNOS) list(APPEND ${NativeLibsExtra} socket) endif () diff --git a/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c b/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c index 092fdc27381d5..0d4659683650f 100644 --- a/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c +++ b/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c @@ -565,4 +565,12 @@ int32_t SystemNative_EnumerateGatewayAddressesForInterface(uint32_t interfaceInd free(buffer); return 0; } +#else +int32_t SystemNative_EnumerateGatewayAddressesForInterface(uint32_t interfaceIndex, GatewayAddressFound onGatewayFound) +{ + (void)interfaceIndex; + (void)onGatewayFound; + errno = ENOTSUP; + return -1; +} #endif // HAVE_RT_MSGHDR diff --git a/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.h b/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.h index cb9e2b2c455f3..09d7910ed9c92 100644 --- a/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.h +++ b/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.h @@ -56,6 +56,4 @@ PALEXPORT int32_t SystemNative_EnumerateInterfaceAddresses( IPv4AddressFound onIpv4Found, IPv6AddressFound onIpv6Found, LinkLayerAddressFound onLinkLayerFound); PALEXPORT int32_t SystemNative_GetNetworkInterfaces(int32_t * interfaceCount, NetworkInterfaceInfo** interfaces, int32_t * addressCount, IpAddressInfo **addressList); -#if HAVE_RT_MSGHDR PALEXPORT int32_t SystemNative_EnumerateGatewayAddressesForInterface(uint32_t interfaceIndex, GatewayAddressFound onGatewayFound); -#endif diff --git a/src/libraries/Native/Unix/System.Native/pal_io.c b/src/libraries/Native/Unix/System.Native/pal_io.c index 3d7420e9253dc..3f678db8367e3 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.c +++ b/src/libraries/Native/Unix/System.Native/pal_io.c @@ -1309,10 +1309,9 @@ int32_t SystemNative_LChflagsCanSetHiddenFlag(void) #endif } -#ifdef __sun - int32_t SystemNative_ReadProcessStatusInfo(pid_t pid, ProcessStatus* processStatus) { +#ifdef __sun char statusFilename[64]; snprintf(statusFilename, sizeof(statusFilename), "/proc/%d/psinfo", pid); @@ -1333,6 +1332,9 @@ int32_t SystemNative_ReadProcessStatusInfo(pid_t pid, ProcessStatus* processStat } return 0; -} - +#else + (void)pid, (void)processStatus; + errno = ENOTSUP; + return -1; #endif // __sun +} diff --git a/src/libraries/Native/Unix/System.Native/pal_io.h b/src/libraries/Native/Unix/System.Native/pal_io.h index 69b210765e20c..e82cffe8a8c3a 100644 --- a/src/libraries/Native/Unix/System.Native/pal_io.h +++ b/src/libraries/Native/Unix/System.Native/pal_io.h @@ -35,13 +35,11 @@ typedef struct uint32_t UserFlags; // user defined flags } FileStatus; -#ifdef __sun typedef struct { size_t ResidentSetSize; // add more fields when needed. } ProcessStatus; -#endif /* Provide consistent access to nanosecond fields, if they exist. */ /* Seconds are always available through st_atime, st_mtime, st_ctime. */ @@ -719,11 +717,9 @@ PALEXPORT int32_t SystemNative_LChflags(const char* path, uint32_t flags); */ PALEXPORT int32_t SystemNative_LChflagsCanSetHiddenFlag(void); -#ifdef __sun /** * Reads the psinfo_t struct and converts into ProcessStatus. * * Returns 1 if the process status was read; otherwise, 0. */ PALEXPORT int32_t SystemNative_ReadProcessStatusInfo(pid_t pid, ProcessStatus* processStatus); -#endif diff --git a/src/libraries/Native/Unix/System.Native/pal_networkchange.c b/src/libraries/Native/Unix/System.Native/pal_networkchange.c index c0062307e818a..725dfe677b952 100644 --- a/src/libraries/Native/Unix/System.Native/pal_networkchange.c +++ b/src/libraries/Native/Unix/System.Native/pal_networkchange.c @@ -17,9 +17,11 @@ #if HAVE_LINUX_RTNETLINK_H #include #elif HAVE_RT_MSGHDR -#include +#if HAVE_IOS_NET_ROUTE_H +#include "ios/net/route.h" #else -#error System must have linux/rtnetlink.h or net/route.h. +#include +#endif #endif #pragma clang diagnostic ignored "-Wcast-align" // NLMSG_* macros trigger this @@ -162,4 +164,12 @@ void SystemNative_ReadEvents(int32_t sock, NetworkChangeEvent onNetworkChange) } } } +#else +void SystemNative_ReadEvents(int32_t sock, NetworkChangeEvent onNetworkChange) +{ + (void)sock; + (void)onNetworkChange; + // unreachable + abort(); +} #endif diff --git a/src/libraries/Native/Unix/System.Native/pal_networkstatistics.c b/src/libraries/Native/Unix/System.Native/pal_networkstatistics.c index bf475764bfbc7..c0ab5dfc3ad94 100644 --- a/src/libraries/Native/Unix/System.Native/pal_networkstatistics.c +++ b/src/libraries/Native/Unix/System.Native/pal_networkstatistics.c @@ -3,6 +3,12 @@ #include "pal_config.h" +#include "pal_errno.h" +#include "pal_networkstatistics.h" + +#include +#include + // These functions are only used for platforms which support // using sysctl to gather protocol statistics information. // Currently, this is all keyed off of whether the include tcp_var.h @@ -11,13 +17,9 @@ #if HAVE_NETINET_TCP_VAR_H #include "pal_utilities.h" -#include "pal_networkstatistics.h" -#include "pal_errno.h" #include "pal_tcpstate.h" #include "pal_safecrt.h" -#include -#include #include #if HAVE_IOS_NET_ROUTE_H #include "ios/net/route.h" @@ -690,4 +692,81 @@ int32_t SystemNative_GetNumRoutes() #endif // HAVE_RT_MSGHDR2 return count; } +#else +int32_t SystemNative_GetTcpGlobalStatistics(TcpGlobalStatistics* retStats) +{ + (void)retStats; + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetIPv4GlobalStatistics(IPv4GlobalStatistics* retStats) +{ + (void)retStats; + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetUdpGlobalStatistics(UdpGlobalStatistics* retStats) +{ + (void)retStats; + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetIcmpv4GlobalStatistics(Icmpv4GlobalStatistics* retStats) +{ + (void)retStats; + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetIcmpv6GlobalStatistics(Icmpv6GlobalStatistics* retStats) +{ + (void)retStats; + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetEstimatedTcpConnectionCount(void) +{ + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetActiveTcpConnectionInfos(NativeTcpConnectionInformation* infos, int32_t* infoCount) +{ + (void)infos; + (void)infoCount; + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetEstimatedUdpListenerCount(void) +{ + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetActiveUdpListeners(IPEndPointInfo* infos, int32_t* infoCount) +{ + (void)infos; + (void)infoCount; + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetNativeIPInterfaceStatistics(char* interfaceName, NativeIPInterfaceStatistics* retStats) +{ + (void)interfaceName; + (void)retStats; + errno = ENOTSUP; + return -1; +} + +int32_t SystemNative_GetNumRoutes(void) +{ + errno = ENOTSUP; + return -1; +} #endif // HAVE_NETINET_TCP_VAR_H diff --git a/src/libraries/Native/Unix/System.Native/pal_process.c b/src/libraries/Native/Unix/System.Native/pal_process.c index d0fba26d8d420..036aac97cfd33 100644 --- a/src/libraries/Native/Unix/System.Native/pal_process.c +++ b/src/libraries/Native/Unix/System.Native/pal_process.c @@ -840,6 +840,14 @@ int32_t SystemNative_SchedSetAffinity(int32_t pid, intptr_t* mask) return sched_setaffinity(pid, sizeof(cpu_set_t), &set); } +#else +int32_t SystemNative_SchedSetAffinity(int32_t pid, intptr_t* mask) +{ + (void)pid; + (void)mask; + errno = ENOTSUP; + return -1; +} #endif #if HAVE_SCHED_GETAFFINITY @@ -872,6 +880,14 @@ int32_t SystemNative_SchedGetAffinity(int32_t pid, intptr_t* mask) return result; } +#else +int32_t SystemNative_SchedGetAffinity(int32_t pid, intptr_t* mask) +{ + (void)pid; + (void)mask; + errno = ENOTSUP; + return -1; +} #endif char* SystemNative_GetProcessPath() diff --git a/src/libraries/Native/Unix/System.Native/pal_process.h b/src/libraries/Native/Unix/System.Native/pal_process.h index c8ae2d2dff4f1..cd7c0b7ab241d 100644 --- a/src/libraries/Native/Unix/System.Native/pal_process.h +++ b/src/libraries/Native/Unix/System.Native/pal_process.h @@ -225,23 +225,19 @@ PALEXPORT int32_t SystemNative_SetPriority(PriorityWhich which, int32_t who, int */ PALEXPORT char* SystemNative_GetCwd(char* buffer, int32_t bufferSize); -#if HAVE_SCHED_SETAFFINITY /** * Sets the CPU affinity mask for a specified thread (or the current thread if 0). * * Returns 0 on success; otherwise, -1 is returned and errno is set */ PALEXPORT int32_t SystemNative_SchedSetAffinity(int32_t pid, intptr_t* mask); -#endif -#if HAVE_SCHED_GETAFFINITY /** * Gets the affinity mask of the specified thread (or the current thread if 0). * * Returns 0 on success; otherwise, -1 is returned and errno is set. */ PALEXPORT int32_t SystemNative_SchedGetAffinity(int32_t pid, intptr_t* mask); -#endif /** * Returns the path of the executable that started the currently executing process, diff --git a/src/libraries/Native/Unix/System.Native/pal_searchpath.c b/src/libraries/Native/Unix/System.Native/pal_searchpath.c new file mode 100644 index 0000000000000..fbf3d903df01c --- /dev/null +++ b/src/libraries/Native/Unix/System.Native/pal_searchpath.c @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "pal_searchpath.h" +#include + +const char* SystemNative_SearchPath(int32_t folderId) +{ + (void)folderId; + __builtin_unreachable(); + return NULL; +} diff --git a/src/libraries/Native/Unix/System.Native/pal_sysctl.c b/src/libraries/Native/Unix/System.Native/pal_sysctl.c index b2053c9fabd01..3316923f45eb8 100644 --- a/src/libraries/Native/Unix/System.Native/pal_sysctl.c +++ b/src/libraries/Native/Unix/System.Native/pal_sysctl.c @@ -2,6 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. #include "pal_config.h" +#include "pal_sysctl.h" + +#include "pal_errno.h" +#include +#include // These functions are only used for platforms which support // using sysctl to gather system information. @@ -9,13 +14,8 @@ #if HAVE_SYS_SYSCTL_H #include "pal_utilities.h" -#include "pal_sysctl.h" -#include "pal_errno.h" #include "pal_safecrt.h" -#include - -#include #include int32_t SystemNative_Sysctl(int* name, unsigned int namelen, void* value, size_t* len) @@ -29,5 +29,14 @@ int32_t SystemNative_Sysctl(int* name, unsigned int namelen, void* value, size_t return sysctl(name, namelen, value, len, newp, newlen); #endif } - +#else +int32_t SystemNative_Sysctl(int* name, unsigned int namelen, void* value, size_t* len) +{ + (void)name; + (void)namelen; + (void)value; + (void)len; + errno = ENOTSUP; + return -1; +} #endif // HAVE_SYSCTL_H diff --git a/src/libraries/Native/Unix/System.Net.Security.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.Net.Security.Native/CMakeLists.txt index bdc1678d765fd..e5cdf212dab6a 100644 --- a/src/libraries/Native/Unix/System.Net.Security.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.Net.Security.Native/CMakeLists.txt @@ -22,6 +22,7 @@ endif() add_library(System.Net.Security.Native-Static STATIC ${NATIVEGSS_SOURCES} + entrypoints.c ) set_target_properties(System.Net.Security.Native-Static PROPERTIES OUTPUT_NAME System.Net.Security.Native CLEAN_DIRECT_OUTPUT 1) @@ -31,6 +32,17 @@ if (GEN_SHARED_LIB) ${NATIVE_LIBS_EXTRA} ) + if (NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID) + add_custom_command(TARGET System.Net.Security.Native POST_BUILD + COMMENT "Verifying System.Net.Security.Native entry points against entrypoints.c " + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-entrypoints.sh + $ + ${CMAKE_CURRENT_SOURCE_DIR}/entrypoints.c + ${CMAKE_NM} + VERBATIM + ) + endif() + install_with_stripped_symbols (System.Net.Security.Native PROGRAMS .) endif() diff --git a/src/libraries/Native/Unix/System.Net.Security.Native/entrypoints.c b/src/libraries/Native/Unix/System.Net.Security.Native/entrypoints.c new file mode 100644 index 0000000000000..ac702e9040090 --- /dev/null +++ b/src/libraries/Native/Unix/System.Net.Security.Native/entrypoints.c @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "../../AnyOS/entrypoints.h" + +// Include System.Net.Security.Native headers +#include "pal_gssapi.h" + +static const Entry s_securityNative[] = +{ + DllImportEntry(NetSecurityNative_AcceptSecContext) + DllImportEntry(NetSecurityNative_AcquireAcceptorCred) + DllImportEntry(NetSecurityNative_DeleteSecContext) + DllImportEntry(NetSecurityNative_DisplayMajorStatus) + DllImportEntry(NetSecurityNative_DisplayMinorStatus) + DllImportEntry(NetSecurityNative_GetUser) + DllImportEntry(NetSecurityNative_ImportPrincipalName) + DllImportEntry(NetSecurityNative_ImportUserName) + DllImportEntry(NetSecurityNative_InitiateCredSpNego) + DllImportEntry(NetSecurityNative_InitiateCredWithPassword) + DllImportEntry(NetSecurityNative_InitSecContext) + DllImportEntry(NetSecurityNative_InitSecContextEx) + DllImportEntry(NetSecurityNative_IsNtlmInstalled) + DllImportEntry(NetSecurityNative_ReleaseCred) + DllImportEntry(NetSecurityNative_ReleaseGssBuffer) + DllImportEntry(NetSecurityNative_ReleaseName) + DllImportEntry(NetSecurityNative_Unwrap) + DllImportEntry(NetSecurityNative_Wrap) +}; + +EXTERN_C const void* SecurityResolveDllImport(const char* name); + +EXTERN_C const void* SecurityResolveDllImport(const char* name) +{ + return ResolveDllImport(s_securityNative, lengthof(s_securityNative), name); +} diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/CMakeLists.txt b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/CMakeLists.txt index d8e985dcc0fb9..a133a938cfe23 100644 --- a/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/CMakeLists.txt @@ -1,7 +1,9 @@ project(System.Security.Cryptography.Native.Apple C) -find_library(COREFOUNDATION_LIBRARY CoreFoundation) -find_library(SECURITY_LIBRARY Security) +include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) + +set(NATIVE_LIBS_EXTRA) +append_extra_cryptography_apple_libs(NATIVE_LIBS_EXTRA) set(NATIVECRYPTO_SOURCES pal_digest.c @@ -40,14 +42,14 @@ endif() add_library(System.Security.Cryptography.Native.Apple-Static STATIC ${NATIVECRYPTO_SOURCES} + entrypoints.c ) set_target_properties(System.Security.Cryptography.Native.Apple-Static PROPERTIES OUTPUT_NAME System.Security.Cryptography.Native.Apple CLEAN_DIRECT_OUTPUT 1) if (GEN_SHARED_LIB) target_link_libraries(System.Security.Cryptography.Native.Apple - ${COREFOUNDATION_LIBRARY} - ${SECURITY_LIBRARY} + ${NATIVE_LIBS_EXTRA} ) endif() diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/entrypoints.c b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/entrypoints.c new file mode 100644 index 0000000000000..3736fee0c1865 --- /dev/null +++ b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/entrypoints.c @@ -0,0 +1,115 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#if !defined(TARGET_IOS) && !defined(TARGET_TVOS) + +#include "../../AnyOS/entrypoints.h" + +// Include System.Security.Cryptography.Native.Apple headers +#include "pal_digest.h" +#include "pal_ecc.h" +#include "pal_hmac.h" +#include "pal_keychain.h" +#include "pal_random.h" +#include "pal_rsa.h" +#include "pal_sec.h" +#include "pal_seckey.h" +#include "pal_signverify.h" +#include "pal_ssl.h" +#include "pal_symmetric.h" +#include "pal_trust.h" +#include "pal_x509.h" +#include "pal_x509chain.h" + +static const Entry s_cryptoAppleNative[] = +{ + DllImportEntry(AppleCryptoNative_DigestFree) + DllImportEntry(AppleCryptoNative_DigestCreate) + DllImportEntry(AppleCryptoNative_DigestUpdate) + DllImportEntry(AppleCryptoNative_DigestFinal) + DllImportEntry(AppleCryptoNative_DigestCurrent) + DllImportEntry(AppleCryptoNative_DigestOneShot) + DllImportEntry(AppleCryptoNative_EccGenerateKey) + DllImportEntry(AppleCryptoNative_EccGetKeySizeInBits) + DllImportEntry(AppleCryptoNative_HmacFree) + DllImportEntry(AppleCryptoNative_HmacCreate) + DllImportEntry(AppleCryptoNative_HmacInit) + DllImportEntry(AppleCryptoNative_HmacUpdate) + DllImportEntry(AppleCryptoNative_HmacFinal) + DllImportEntry(AppleCryptoNative_HmacCurrent) + DllImportEntry(AppleCryptoNative_SecKeychainItemCopyKeychain) + DllImportEntry(AppleCryptoNative_SecKeychainCreate) + DllImportEntry(AppleCryptoNative_SecKeychainDelete) + DllImportEntry(AppleCryptoNative_SecKeychainCopyDefault) + DllImportEntry(AppleCryptoNative_SecKeychainOpen) + DllImportEntry(AppleCryptoNative_SecKeychainUnlock) + DllImportEntry(AppleCryptoNative_SetKeychainNeverLock) + DllImportEntry(AppleCryptoNative_SecKeychainEnumerateIdentities) + DllImportEntry(AppleCryptoNative_GetRandomBytes) + DllImportEntry(AppleCryptoNative_RsaGenerateKey) + DllImportEntry(AppleCryptoNative_RsaDecryptOaep) + DllImportEntry(AppleCryptoNative_RsaDecryptPkcs) + DllImportEntry(AppleCryptoNative_RsaEncryptOaep) + DllImportEntry(AppleCryptoNative_RsaEncryptPkcs) + DllImportEntry(AppleCryptoNative_RsaSignaturePrimitive) + DllImportEntry(AppleCryptoNative_RsaDecryptionPrimitive) + DllImportEntry(AppleCryptoNative_RsaEncryptionPrimitive) + DllImportEntry(AppleCryptoNative_RsaVerificationPrimitive) + DllImportEntry(AppleCryptoNative_SecCopyErrorMessageString) + DllImportEntry(AppleCryptoNative_SecKeyExport) + DllImportEntry(AppleCryptoNative_SecKeyImportEphemeral) + DllImportEntry(AppleCryptoNative_SecKeyGetSimpleKeySizeInBytes) + DllImportEntry(AppleCryptoNative_GenerateSignature) + DllImportEntry(AppleCryptoNative_GenerateSignatureWithHashAlgorithm) + DllImportEntry(AppleCryptoNative_VerifySignatureWithHashAlgorithm) + DllImportEntry(AppleCryptoNative_VerifySignature) + DllImportEntry(AppleCryptoNative_SslCreateContext) + DllImportEntry(AppleCryptoNative_SslSetAcceptClientCert) + DllImportEntry(AppleCryptoNative_SslSetMinProtocolVersion) + DllImportEntry(AppleCryptoNative_SslSetMaxProtocolVersion) + DllImportEntry(AppleCryptoNative_SslSetCertificate) + DllImportEntry(AppleCryptoNative_SslSetTargetName) + DllImportEntry(AppleCryptoNative_SSLSetALPNProtocols) + DllImportEntry(AppleCryptoNative_SslGetAlpnSelected) + DllImportEntry(AppleCryptoNative_SslHandshake) + DllImportEntry(AppleCryptoNative_SslShutdown) + DllImportEntry(AppleCryptoNative_SslGetProtocolVersion) + DllImportEntry(AppleCryptoNative_SslGetCipherSuite) + DllImportEntry(AppleCryptoNative_SslSetEnabledCipherSuites) + DllImportEntry(AppleCryptoNative_CryptorFree) + DllImportEntry(AppleCryptoNative_CryptorCreate) + DllImportEntry(AppleCryptoNative_CryptorUpdate) + DllImportEntry(AppleCryptoNative_CryptorFinal) + DllImportEntry(AppleCryptoNative_CryptorReset) + DllImportEntry(AppleCryptoNative_StoreEnumerateUserRoot) + DllImportEntry(AppleCryptoNative_StoreEnumerateMachineRoot) + DllImportEntry(AppleCryptoNative_StoreEnumerateUserDisallowed) + DllImportEntry(AppleCryptoNative_StoreEnumerateMachineDisallowed) + DllImportEntry(AppleCryptoNative_X509GetContentType) + DllImportEntry(AppleCryptoNative_X509CopyCertFromIdentity) + DllImportEntry(AppleCryptoNative_X509CopyPrivateKeyFromIdentity) + DllImportEntry(AppleCryptoNative_X509ImportCollection) + DllImportEntry(AppleCryptoNative_X509ImportCertificate) + DllImportEntry(AppleCryptoNative_X509ExportData) + DllImportEntry(AppleCryptoNative_X509GetRawData) + DllImportEntry(AppleCryptoNative_X509CopyWithPrivateKey) + DllImportEntry(AppleCryptoNative_X509MoveToKeychain) + DllImportEntry(AppleCryptoNative_X509ChainCreateDefaultPolicy) + DllImportEntry(AppleCryptoNative_X509ChainCreateRevocationPolicy) + DllImportEntry(AppleCryptoNative_X509ChainEvaluate) + DllImportEntry(AppleCryptoNative_X509ChainGetChainSize) + DllImportEntry(AppleCryptoNative_X509ChainGetCertificateAtIndex) + DllImportEntry(AppleCryptoNative_X509ChainGetTrustResults) + DllImportEntry(AppleCryptoNative_X509ChainGetStatusAtIndex) + DllImportEntry(AppleCryptoNative_GetOSStatusForChainStatus) + DllImportEntry(AppleCryptoNative_X509ChainSetTrustAnchorCertificates) +}; + +EXTERN_C const void* CryptoAppleResolveDllImport(const char* name); + +EXTERN_C const void* CryptoAppleResolveDllImport(const char* name) +{ + return ResolveDllImport(s_cryptoAppleNative, lengthof(s_cryptoAppleNative), name); +} + +#endif // !defined(TARGET_IOS) && !defined(TARGET_TVOS) diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/extra_libs.cmake b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/extra_libs.cmake new file mode 100644 index 0000000000000..9ed82cd31bc29 --- /dev/null +++ b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/extra_libs.cmake @@ -0,0 +1,7 @@ + +macro(append_extra_cryptography_apple_libs NativeLibsExtra) + find_library(COREFOUNDATION_LIBRARY CoreFoundation) + find_library(SECURITY_LIBRARY Security) + + list(APPEND ${NativeLibsExtra} ${COREFOUNDATION_LIBRARY} ${SECURITY_LIBRARY}) +endmacro() diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.Security.Cryptography.Native/CMakeLists.txt index 2ca4f23546155..b9c01c3915949 100644 --- a/src/libraries/Native/Unix/System.Security.Cryptography.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.Security.Cryptography.Native/CMakeLists.txt @@ -49,6 +49,10 @@ set(NATIVECRYPTO_SOURCES # that use OpenSSL at runtime. if (CLR_CMAKE_TARGET_OSX) set(FEATURE_DISTRO_AGNOSTIC_SSL True) + + # by default uninitialized variables like the shim _ptr functions, will turn into common symbols + # and on OSX those have linking problems in libraries (ELF vs. Mach-O difference) + add_compile_options(-fno-common) endif() if (FEATURE_DISTRO_AGNOSTIC_SSL) @@ -70,6 +74,7 @@ endif() add_library(System.Security.Cryptography.Native.OpenSsl-Static STATIC $ + entrypoints.c ) set_target_properties(System.Security.Cryptography.Native.OpenSsl-Static PROPERTIES OUTPUT_NAME System.Security.Cryptography.Native.OpenSsl CLEAN_DIRECT_OUTPUT 1) @@ -92,6 +97,17 @@ if (GEN_SHARED_LIB) endif() endif() + if (NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID) + add_custom_command(TARGET System.Security.Cryptography.Native.OpenSsl POST_BUILD + COMMENT "Verifying System.Security.Cryptography.Native.OpenSsl entry points against entrypoints.c " + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-entrypoints.sh + $ + ${CMAKE_CURRENT_SOURCE_DIR}/entrypoints.c + ${CMAKE_NM} + VERBATIM + ) + endif() + target_link_libraries(System.Security.Cryptography.Native.OpenSsl ${NATIVE_LIBS_EXTRA} ) diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native/entrypoints.c b/src/libraries/Native/Unix/System.Security.Cryptography.Native/entrypoints.c new file mode 100644 index 0000000000000..9856a0b10f1f0 --- /dev/null +++ b/src/libraries/Native/Unix/System.Security.Cryptography.Native/entrypoints.c @@ -0,0 +1,331 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "../../AnyOS/entrypoints.h" + +// Include System.Security.Cryptography.Native headers +#include "openssl.h" +#include "pal_asn1.h" +#include "pal_bignum.h" +#include "pal_bio.h" +#include "pal_dsa.h" +#include "pal_ecc_import_export.h" +#include "pal_ecdsa.h" +#include "pal_eckey.h" +#include "pal_err.h" +#include "pal_evp.h" +#include "pal_evp_cipher.h" +#include "pal_evp_pkey.h" +#include "pal_evp_pkey_dsa.h" +#include "pal_evp_pkey_ecdh.h" +#include "pal_evp_pkey_eckey.h" +#include "pal_evp_pkey_rsa.h" +#include "pal_hmac.h" +#include "pal_ocsp.h" +#include "pal_pkcs7.h" +#include "pal_rsa.h" +#include "pal_ssl.h" +#include "pal_x509.h" +#include "pal_x509ext.h" +#include "pal_x509_name.h" +#include "pal_x509_root.h" + + +static const Entry s_cryptoNative[] = +{ + DllImportEntry(CryptoNative_Asn1BitStringFree) + DllImportEntry(CryptoNative_Asn1ObjectFree) + DllImportEntry(CryptoNative_Asn1OctetStringFree) + DllImportEntry(CryptoNative_Asn1OctetStringNew) + DllImportEntry(CryptoNative_Asn1OctetStringSet) + DllImportEntry(CryptoNative_BigNumDestroy) + DllImportEntry(CryptoNative_BigNumFromBinary) + DllImportEntry(CryptoNative_BigNumToBinary) + DllImportEntry(CryptoNative_BioCtrlPending) + DllImportEntry(CryptoNative_BioDestroy) + DllImportEntry(CryptoNative_BioGets) + DllImportEntry(CryptoNative_BioNewFile) + DllImportEntry(CryptoNative_BioRead) + DllImportEntry(CryptoNative_BioSeek) + DllImportEntry(CryptoNative_BioTell) + DllImportEntry(CryptoNative_BioWrite) + DllImportEntry(CryptoNative_CheckX509Hostname) + DllImportEntry(CryptoNative_CheckX509IpAddress) + DllImportEntry(CryptoNative_CreateMemoryBio) + DllImportEntry(CryptoNative_D2IPkcs7Bio) + DllImportEntry(CryptoNative_DecodeAsn1BitString) + DllImportEntry(CryptoNative_DecodeExtendedKeyUsage) + DllImportEntry(CryptoNative_DecodeOcspResponse) + DllImportEntry(CryptoNative_DecodePkcs7) + DllImportEntry(CryptoNative_DecodeRsaPublicKey) + DllImportEntry(CryptoNative_DecodeX509) + DllImportEntry(CryptoNative_DecodeX509BasicConstraints2Extension) + DllImportEntry(CryptoNative_DecodeX509Crl) + DllImportEntry(CryptoNative_DsaDestroy) + DllImportEntry(CryptoNative_DsaGenerateKey) + DllImportEntry(CryptoNative_DsaKeyCreateByExplicitParameters) + DllImportEntry(CryptoNative_DsaSign) + DllImportEntry(CryptoNative_DsaSizeP) + DllImportEntry(CryptoNative_DsaSizeQ) + DllImportEntry(CryptoNative_DsaSizeSignature) + DllImportEntry(CryptoNative_DsaUpRef) + DllImportEntry(CryptoNative_DsaVerify) + DllImportEntry(CryptoNative_EcDsaSign) + DllImportEntry(CryptoNative_EcDsaSize) + DllImportEntry(CryptoNative_EcDsaVerify) + DllImportEntry(CryptoNative_EcKeyCreateByExplicitParameters) + DllImportEntry(CryptoNative_EcKeyCreateByKeyParameters) + DllImportEntry(CryptoNative_EcKeyCreateByOid) + DllImportEntry(CryptoNative_EcKeyDestroy) + DllImportEntry(CryptoNative_EcKeyGenerateKey) + DllImportEntry(CryptoNative_EcKeyGetCurveName2) + DllImportEntry(CryptoNative_EcKeyGetSize) + DllImportEntry(CryptoNative_EcKeyUpRef) + DllImportEntry(CryptoNative_EncodeAsn1Integer) + DllImportEntry(CryptoNative_EncodeOcspRequest) + DllImportEntry(CryptoNative_EncodePkcs7) + DllImportEntry(CryptoNative_EncodeX509) + DllImportEntry(CryptoNative_EncodeX509SubjectPublicKeyInfo) + DllImportEntry(CryptoNative_ErrClearError) + DllImportEntry(CryptoNative_ErrErrorStringN) + DllImportEntry(CryptoNative_ErrGetErrorAlloc) + DllImportEntry(CryptoNative_ErrPeekError) + DllImportEntry(CryptoNative_ErrPeekLastError) + DllImportEntry(CryptoNative_ErrReasonErrorString) + DllImportEntry(CryptoNative_EvpAes128Cbc) + DllImportEntry(CryptoNative_EvpAes128Ccm) + DllImportEntry(CryptoNative_EvpAes128Cfb128) + DllImportEntry(CryptoNative_EvpAes128Cfb8) + DllImportEntry(CryptoNative_EvpAes128Ecb) + DllImportEntry(CryptoNative_EvpAes128Gcm) + DllImportEntry(CryptoNative_EvpAes192Cbc) + DllImportEntry(CryptoNative_EvpAes192Ccm) + DllImportEntry(CryptoNative_EvpAes192Cfb128) + DllImportEntry(CryptoNative_EvpAes192Cfb8) + DllImportEntry(CryptoNative_EvpAes192Ecb) + DllImportEntry(CryptoNative_EvpAes192Gcm) + DllImportEntry(CryptoNative_EvpAes256Cbc) + DllImportEntry(CryptoNative_EvpAes256Ccm) + DllImportEntry(CryptoNative_EvpAes256Cfb128) + DllImportEntry(CryptoNative_EvpAes256Cfb8) + DllImportEntry(CryptoNative_EvpAes256Ecb) + DllImportEntry(CryptoNative_EvpAes256Gcm) + DllImportEntry(CryptoNative_EvpCipherCreate2) + DllImportEntry(CryptoNative_EvpCipherCreatePartial) + DllImportEntry(CryptoNative_EvpCipherCtxSetPadding) + DllImportEntry(CryptoNative_EvpCipherDestroy) + DllImportEntry(CryptoNative_EvpCipherFinalEx) + DllImportEntry(CryptoNative_EvpCipherGetCcmTag) + DllImportEntry(CryptoNative_EvpCipherGetGcmTag) + DllImportEntry(CryptoNative_EvpCipherReset) + DllImportEntry(CryptoNative_EvpCipherSetCcmNonceLength) + DllImportEntry(CryptoNative_EvpCipherSetCcmTag) + DllImportEntry(CryptoNative_EvpCipherSetGcmNonceLength) + DllImportEntry(CryptoNative_EvpCipherSetGcmTag) + DllImportEntry(CryptoNative_EvpCipherSetKeyAndIV) + DllImportEntry(CryptoNative_EvpCipherUpdate) + DllImportEntry(CryptoNative_EvpDes3Cbc) + DllImportEntry(CryptoNative_EvpDes3Cfb64) + DllImportEntry(CryptoNative_EvpDes3Cfb8) + DllImportEntry(CryptoNative_EvpDes3Ecb) + DllImportEntry(CryptoNative_EvpDesCbc) + DllImportEntry(CryptoNative_EvpDesCfb8) + DllImportEntry(CryptoNative_EvpDesEcb) + DllImportEntry(CryptoNative_EvpDigestCurrent) + DllImportEntry(CryptoNative_EvpDigestFinalEx) + DllImportEntry(CryptoNative_EvpDigestOneShot) + DllImportEntry(CryptoNative_EvpDigestReset) + DllImportEntry(CryptoNative_EvpDigestUpdate) + DllImportEntry(CryptoNative_EvpMd5) + DllImportEntry(CryptoNative_EvpMdCtxCreate) + DllImportEntry(CryptoNative_EvpMdCtxDestroy) + DllImportEntry(CryptoNative_EvpMdSize) + DllImportEntry(CryptoNative_EvpPkeyCreate) + DllImportEntry(CryptoNative_EvpPKeyCtxCreate) + DllImportEntry(CryptoNative_EvpPKeyCtxDestroy) + DllImportEntry(CryptoNative_EvpPKeyDeriveSecretAgreement) + DllImportEntry(CryptoNative_EvpPkeyDestroy) + DllImportEntry(CryptoNative_EvpPkeyGetDsa) + DllImportEntry(CryptoNative_EvpPkeyGetEcKey) + DllImportEntry(CryptoNative_EvpPkeyGetRsa) + DllImportEntry(CryptoNative_EvpPkeySetDsa) + DllImportEntry(CryptoNative_EvpPkeySetEcKey) + DllImportEntry(CryptoNative_EvpPkeySetRsa) + DllImportEntry(CryptoNative_EvpRC2Cbc) + DllImportEntry(CryptoNative_EvpRC2Ecb) + DllImportEntry(CryptoNative_EvpSha1) + DllImportEntry(CryptoNative_EvpSha256) + DllImportEntry(CryptoNative_EvpSha384) + DllImportEntry(CryptoNative_EvpSha512) + DllImportEntry(CryptoNative_ExtendedKeyUsageDestory) + DllImportEntry(CryptoNative_GetAsn1IntegerDerSize) + DllImportEntry(CryptoNative_GetAsn1StringBytes) + DllImportEntry(CryptoNative_GetBigNumBytes) + DllImportEntry(CryptoNative_GetDsaParameters) + DllImportEntry(CryptoNative_GetECCurveParameters) + DllImportEntry(CryptoNative_GetECKeyParameters) + DllImportEntry(CryptoNative_GetMaxMdSize) + DllImportEntry(CryptoNative_GetMemoryBioSize) + DllImportEntry(CryptoNative_GetObjectDefinitionByName) + DllImportEntry(CryptoNative_GetOcspRequestDerSize) + DllImportEntry(CryptoNative_GetPkcs7Certificates) + DllImportEntry(CryptoNative_GetPkcs7DerSize) + DllImportEntry(CryptoNative_GetRandomBytes) + DllImportEntry(CryptoNative_GetRsaParameters) + DllImportEntry(CryptoNative_GetX509CrlNextUpdate) + DllImportEntry(CryptoNative_GetX509DerSize) + DllImportEntry(CryptoNative_GetX509EkuField) + DllImportEntry(CryptoNative_GetX509EkuFieldCount) + DllImportEntry(CryptoNative_GetX509EvpPublicKey) + DllImportEntry(CryptoNative_GetX509NameInfo) + DllImportEntry(CryptoNative_GetX509NameRawBytes) + DllImportEntry(CryptoNative_GetX509NameStackField) + DllImportEntry(CryptoNative_GetX509NameStackFieldCount) + DllImportEntry(CryptoNative_GetX509NotAfter) + DllImportEntry(CryptoNative_GetX509NotBefore) + DllImportEntry(CryptoNative_GetX509PublicKeyAlgorithm) + DllImportEntry(CryptoNative_GetX509PublicKeyBytes) + DllImportEntry(CryptoNative_GetX509PublicKeyParameterBytes) + DllImportEntry(CryptoNative_GetX509RootStoreFile) + DllImportEntry(CryptoNative_GetX509RootStorePath) + DllImportEntry(CryptoNative_GetX509SignatureAlgorithm) + DllImportEntry(CryptoNative_GetX509StackField) + DllImportEntry(CryptoNative_GetX509StackFieldCount) + DllImportEntry(CryptoNative_GetX509SubjectPublicKeyInfoDerSize) + DllImportEntry(CryptoNative_GetX509Thumbprint) + DllImportEntry(CryptoNative_GetX509Version) + DllImportEntry(CryptoNative_HmacCreate) + DllImportEntry(CryptoNative_HmacCurrent) + DllImportEntry(CryptoNative_HmacDestroy) + DllImportEntry(CryptoNative_HmacFinal) + DllImportEntry(CryptoNative_HmacReset) + DllImportEntry(CryptoNative_HmacUpdate) + DllImportEntry(CryptoNative_LookupFriendlyNameByOid) + DllImportEntry(CryptoNative_NewX509Stack) + DllImportEntry(CryptoNative_ObjNid2Obj) + DllImportEntry(CryptoNative_ObjObj2Txt) + DllImportEntry(CryptoNative_ObjSn2Nid) + DllImportEntry(CryptoNative_ObjTxt2Nid) + DllImportEntry(CryptoNative_ObjTxt2Obj) + DllImportEntry(CryptoNative_OcspRequestDestroy) + DllImportEntry(CryptoNative_OcspResponseDestroy) + DllImportEntry(CryptoNative_PemReadBioPkcs7) + DllImportEntry(CryptoNative_PemReadBioX509Crl) + DllImportEntry(CryptoNative_PemReadX509FromBio) + DllImportEntry(CryptoNative_PemReadX509FromBioAux) + DllImportEntry(CryptoNative_PemWriteBioX509Crl) + DllImportEntry(CryptoNative_Pkcs7CreateCertificateCollection) + DllImportEntry(CryptoNative_Pkcs7Destroy) + DllImportEntry(CryptoNative_PushX509StackField) + DllImportEntry(CryptoNative_ReadX509AsDerFromBio) + DllImportEntry(CryptoNative_RecursiveFreeX509Stack) + DllImportEntry(CryptoNative_RsaCreate) + DllImportEntry(CryptoNative_RsaDestroy) + DllImportEntry(CryptoNative_RsaGenerateKeyEx) + DllImportEntry(CryptoNative_RsaPrivateDecrypt) + DllImportEntry(CryptoNative_RsaPublicEncrypt) + DllImportEntry(CryptoNative_RsaSign) + DllImportEntry(CryptoNative_RsaSignPrimitive) + DllImportEntry(CryptoNative_RsaSize) + DllImportEntry(CryptoNative_RsaUpRef) + DllImportEntry(CryptoNative_RsaVerificationPrimitive) + DllImportEntry(CryptoNative_RsaVerify) + DllImportEntry(CryptoNative_SetRsaParameters) + DllImportEntry(CryptoNative_UpRefEvpPkey) + DllImportEntry(CryptoNative_X509ChainBuildOcspRequest) + DllImportEntry(CryptoNative_X509ChainGetCachedOcspStatus) + DllImportEntry(CryptoNative_X509ChainNew) + DllImportEntry(CryptoNative_X509ChainVerifyOcsp) + DllImportEntry(CryptoNative_X509CheckPurpose) + DllImportEntry(CryptoNative_X509CrlDestroy) + DllImportEntry(CryptoNative_X509Destroy) + DllImportEntry(CryptoNative_X509ExtensionCreateByObj) + DllImportEntry(CryptoNative_X509ExtensionDestroy) + DllImportEntry(CryptoNative_X509ExtensionGetCritical) + DllImportEntry(CryptoNative_X509ExtensionGetData) + DllImportEntry(CryptoNative_X509ExtensionGetOid) + DllImportEntry(CryptoNative_X509FindExtensionData) + DllImportEntry(CryptoNative_X509GetExt) + DllImportEntry(CryptoNative_X509GetExtCount) + DllImportEntry(CryptoNative_X509GetIssuerName) + DllImportEntry(CryptoNative_X509GetSerialNumber) + DllImportEntry(CryptoNative_X509GetSubjectName) + DllImportEntry(CryptoNative_X509IssuerNameHash) + DllImportEntry(CryptoNative_X509StackAddDirectoryStore) + DllImportEntry(CryptoNative_X509StackAddMultiple) + DllImportEntry(CryptoNative_X509StoreAddCrl) + DllImportEntry(CryptoNative_X509StoreCtxCommitToChain) + DllImportEntry(CryptoNative_X509StoreCtxCreate) + DllImportEntry(CryptoNative_X509StoreCtxDestroy) + DllImportEntry(CryptoNative_X509StoreCtxGetChain) + DllImportEntry(CryptoNative_X509StoreCtxGetCurrentCert) + DllImportEntry(CryptoNative_X509StoreCtxGetError) + DllImportEntry(CryptoNative_X509StoreCtxGetErrorDepth) + DllImportEntry(CryptoNative_X509StoreCtxGetSharedUntrusted) + DllImportEntry(CryptoNative_X509StoreCtxInit) + DllImportEntry(CryptoNative_X509StoreCtxRebuildChain) + DllImportEntry(CryptoNative_X509StoreCtxReset) + DllImportEntry(CryptoNative_X509StoreCtxResetForSignatureError) + DllImportEntry(CryptoNative_X509StoreCtxSetVerifyCallback) + DllImportEntry(CryptoNative_X509StoreDestory) + DllImportEntry(CryptoNative_X509StoreSetRevocationFlag) + DllImportEntry(CryptoNative_X509StoreSetVerifyTime) + DllImportEntry(CryptoNative_X509UpRef) + DllImportEntry(CryptoNative_X509V3ExtPrint) + DllImportEntry(CryptoNative_X509VerifyCert) + DllImportEntry(CryptoNative_X509VerifyCertErrorString) + DllImportEntry(CryptoNative_EnsureOpenSslInitialized) + DllImportEntry(CryptoNative_OpenSslGetProtocolSupport) + DllImportEntry(CryptoNative_OpenSslVersionNumber) + DllImportEntry(CryptoNative_BioWrite) + DllImportEntry(CryptoNative_EnsureLibSslInitialized) + DllImportEntry(CryptoNative_GetOpenSslCipherSuiteName) + DllImportEntry(CryptoNative_IsSslRenegotiatePending) + DllImportEntry(CryptoNative_IsSslStateOK) + DllImportEntry(CryptoNative_SetCiphers) + DllImportEntry(CryptoNative_SetEncryptionPolicy) + DllImportEntry(CryptoNative_SetProtocolOptions) + DllImportEntry(CryptoNative_SslAddExtraChainCert) + DllImportEntry(CryptoNative_SslCreate) + DllImportEntry(CryptoNative_SslCtxCheckPrivateKey) + DllImportEntry(CryptoNative_SslCtxCreate) + DllImportEntry(CryptoNative_SslCtxDestroy) + DllImportEntry(CryptoNative_SslCtxSetAlpnProtos) + DllImportEntry(CryptoNative_SslCtxSetAlpnSelectCb) + DllImportEntry(CryptoNative_SslCtxSetQuietShutdown) + DllImportEntry(CryptoNative_SslCtxSetVerify) + DllImportEntry(CryptoNative_SslCtxUseCertificate) + DllImportEntry(CryptoNative_SslCtxUsePrivateKey) + DllImportEntry(CryptoNative_SslDestroy) + DllImportEntry(CryptoNative_SslDoHandshake) + DllImportEntry(CryptoNative_SslGetClientCAList) + DllImportEntry(CryptoNative_SslGetCurrentCipherId) + DllImportEntry(CryptoNative_SslGetError) + DllImportEntry(CryptoNative_SslGetFinished) + DllImportEntry(CryptoNative_SslGetPeerCertChain) + DllImportEntry(CryptoNative_SslGetPeerCertificate) + DllImportEntry(CryptoNative_SslGetPeerFinished) + DllImportEntry(CryptoNative_SslGetVersion) + DllImportEntry(CryptoNative_SslRead) + DllImportEntry(CryptoNative_SslSessionReused) + DllImportEntry(CryptoNative_SslSetAcceptState) + DllImportEntry(CryptoNative_SslSetBio) + DllImportEntry(CryptoNative_SslSetConnectState) + DllImportEntry(CryptoNative_SslSetQuietShutdown) + DllImportEntry(CryptoNative_SslSetTlsExtHostName) + DllImportEntry(CryptoNative_SslShutdown) + DllImportEntry(CryptoNative_SslV2_3Method) + DllImportEntry(CryptoNative_SslWrite) + DllImportEntry(CryptoNative_X509StoreCtxGetTargetCert) + DllImportEntry(CryptoNative_Tls13Supported) + DllImportEntry(CryptoNative_X509Duplicate) + DllImportEntry(CryptoNative_SslGet0AlpnSelected) + DllImportEntry(CryptoNative_Asn1StringFree) +}; + +EXTERN_C const void* CryptoResolveDllImport(const char* name); + +EXTERN_C const void* CryptoResolveDllImport(const char* name) +{ + return ResolveDllImport(s_cryptoNative, lengthof(s_cryptoNative), name); +} diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake b/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake index 9d7521f51d509..3162edec02eb2 100644 --- a/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake +++ b/src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake @@ -30,7 +30,7 @@ macro(append_extra_cryptography_libs NativeLibsExtra) endif(NOT OPENSSL_FOUND) - if (FEATURE_DISTRO_AGNOSTIC_SSL) + if (FEATURE_DISTRO_AGNOSTIC_SSL OR CLR_CMAKE_TARGET_OSX) # Link with libdl.so to get the dlopen / dlsym / dlclose list(APPEND ${NativeLibsExtra} dl) else() diff --git a/src/libraries/Native/Unix/verify-entrypoints.sh b/src/libraries/Native/Unix/verify-entrypoints.sh new file mode 100755 index 0000000000000..6c625b331bd93 --- /dev/null +++ b/src/libraries/Native/Unix/verify-entrypoints.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +if (( $# != 3 )); then + echo "Usage:" + echo "verify-entrypoints.sh " + exit 1 +fi + +nmCommand=$3 + +IFS=$'\n' +dllList=() +for line in $($nmCommand $1); do + pattern='^[[:xdigit:]]+ T _?([[:alnum:]_]+)' + if [[ $line =~ $pattern ]]; then + # skip symbols that we don't want to consider + case ${BASH_REMATCH[1]} in + init) ;; + fini) ;; + *) dllList+=(${BASH_REMATCH[1]});; + esac + fi +done + +entriesList=() +for line in $(<$2); do + pattern='^[[:space:]]+DllImportEntry\(([[:alnum:]_]+)\)' + if [[ $line =~ $pattern ]]; then + entriesList+=(${BASH_REMATCH[1]}) + fi +done + +diffList=$(echo -n ${entriesList[@]} ${dllList[@]} | tr " " "\n" | sort | uniq -u) + +if [ -n "$diffList" ]; then + echo "ERROR: $2 file did not match entries exported from $1" >&2 + echo "DIFFERENCES FOUND: " >&2 + echo $diffList | tr " " "," >&2 + exit 2 +fi diff --git a/src/libraries/Native/Windows/System.IO.Compression.Native/System.IO.Compression.Native.def b/src/libraries/Native/Windows/System.IO.Compression.Native/System.IO.Compression.Native.def index a5d192ee42e83..6821d0e538f51 100644 --- a/src/libraries/Native/Windows/System.IO.Compression.Native/System.IO.Compression.Native.def +++ b/src/libraries/Native/Windows/System.IO.Compression.Native/System.IO.Compression.Native.def @@ -1,34 +1,21 @@ LIBRARY System.IO.Compression.Native.dll EXPORTS - CompressionNative_Crc32 - CompressionNative_DeflateInit2_ - CompressionNative_Deflate - CompressionNative_DeflateEnd - CompressionNative_InflateInit2_ - CompressionNative_Inflate - CompressionNative_InflateEnd + BrotliDecoderCreateInstance + BrotliDecoderDecompress + BrotliDecoderDecompressStream + BrotliDecoderDestroyInstance + BrotliDecoderIsFinished BrotliEncoderCompress BrotliEncoderCompressStream BrotliEncoderCreateInstance BrotliEncoderDestroyInstance BrotliEncoderHasMoreOutput - BrotliEncoderIsFinished - BrotliEncoderMaxCompressedSize BrotliEncoderSetParameter - BrotliEncoderTakeOutput - BrotliEncoderVersion - BrotliDecoderCreateInstance - BrotliDecoderDecompress - BrotliDecoderDecompressStream - BrotliDecoderDestroyInstance - BrotliDecoderErrorString - BrotliDecoderGetErrorCode - BrotliDecoderHasMoreOutput - BrotliDecoderIsFinished - BrotliDecoderIsUsed - BrotliDecoderSetParameter - BrotliDecoderTakeOutput - BrotliDecoderVersion - BrotliGetDictionary - BrotliSetDictionaryData + CompressionNative_Crc32 + CompressionNative_Deflate + CompressionNative_DeflateEnd + CompressionNative_DeflateInit2_ + CompressionNative_Inflate + CompressionNative_InflateEnd + CompressionNative_InflateInit2_ diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c index 50d0c7868409d..1e66fcd913aa3 100644 --- a/src/mono/wasm/runtime/driver.c +++ b/src/mono/wasm/runtime/driver.c @@ -318,15 +318,6 @@ wasm_dl_symbol (void *handle, const char *name, char **err, void *user_data) return NULL; } -#ifdef ENABLE_NETCORE -/* Missing System.Native symbols */ -int SystemNative_CloseNetworkChangeListenerSocket (int a) { return 0; } -int SystemNative_CreateNetworkChangeListenerSocket (int a) { return 0; } -void SystemNative_ReadEvents (int a,int b) {} -int SystemNative_SchedGetAffinity (int a,int b) { return 0; } -int SystemNative_SchedSetAffinity (int a,int b) { return 0; } -#endif - #if !defined(ENABLE_AOT) || defined(EE_MODE_LLVMONLY_INTERP) #define NEED_INTERP 1 #ifndef LINK_ICALLS