From 8a13147d2fca4c539f7254f4c9c17fcbb8f01d7b Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 16 Oct 2024 15:05:07 -0700 Subject: [PATCH 01/28] Remove PAL_Random --- .../dlls/mscordac/mscordac_unixexports.src | 1 - src/coreclr/pal/inc/pal.h | 7 - src/coreclr/pal/src/CMakeLists.txt | 1 - src/coreclr/pal/src/misc/miscpalapi.cpp | 131 ------------------ src/coreclr/palrt/guid.cpp | 6 +- .../superpmi/superpmi-shared/spmiutil.cpp | 10 +- .../superpmi/superpmi/parallelsuperpmi.cpp | 7 +- 7 files changed, 10 insertions(+), 153 deletions(-) delete mode 100644 src/coreclr/pal/src/misc/miscpalapi.cpp diff --git a/src/coreclr/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/dlls/mscordac/mscordac_unixexports.src index b7fe8d95f5b793..f40151ef8d9bd0 100644 --- a/src/coreclr/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/dlls/mscordac/mscordac_unixexports.src @@ -40,7 +40,6 @@ nativeStringResourceTable_mscorrc #PAL_CloseProcessMemory #PAL_ReadProcessMemory #PAL_ProbeMemory -#PAL_Random #PAL__wcstoui64 #PAL_wcstoul #PAL_wcstod diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 8d768044f119a0..87198582666a63 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -359,13 +359,6 @@ PALAPI PAL_UnregisterModule( IN HINSTANCE hInstance); -PALIMPORT -VOID -PALAPI -PAL_Random( - IN OUT LPVOID lpBuffer, - IN DWORD dwLength); - PALIMPORT BOOL PALAPI diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index db5d430ed011bb..680332b0843ab3 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -158,7 +158,6 @@ set(SOURCES misc/error.cpp misc/errorstrings.cpp misc/fmtmessage.cpp - misc/miscpalapi.cpp misc/perfjitdump.cpp misc/strutil.cpp misc/sysinfo.cpp diff --git a/src/coreclr/pal/src/misc/miscpalapi.cpp b/src/coreclr/pal/src/misc/miscpalapi.cpp deleted file mode 100644 index f0d32f0388e86f..00000000000000 --- a/src/coreclr/pal/src/misc/miscpalapi.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*++ - - - -Module Name: - - miscpalapi.c - -Abstract: - - Implementation misc PAL APIs - -Revision History: - - - ---*/ - -#include "pal/palinternal.h" -#include "pal/dbgmsg.h" -#include "pal/file.h" -#include "pal/process.h" -#include "pal/module.h" -#include "pal/malloc.hpp" -#include "pal/stackstring.hpp" - -#include -#include -#include -#include -#include -#include - -#include - -#ifdef __APPLE__ -#include -#endif // __APPLE__ - -SET_DEFAULT_DEBUG_CHANNEL(MISC); - -static const char URANDOM_DEVICE_NAME[]="/dev/urandom"; - -VOID -PALAPI -PAL_Random( - IN OUT LPVOID lpBuffer, - IN DWORD dwLength) -{ - int rand_des = -1; - DWORD i; - long num = 0; - static BOOL sMissingDevURandom; - static BOOL sInitializedMRand; - - PERF_ENTRY(PAL_Random); - ENTRY("PAL_Random(lpBuffer=%p, dwLength=%d)\n", lpBuffer, dwLength); - - if (!sMissingDevURandom) - { - do - { - rand_des = open("/dev/urandom", O_RDONLY | O_CLOEXEC); - } - while ((rand_des == -1) && (errno == EINTR)); - - if (rand_des == -1) - { - if (errno == ENOENT) - { - sMissingDevURandom = TRUE; - } - else - { - ASSERT("PAL__open() failed, errno:%d (%s)\n", errno, strerror(errno)); - } - - // Back off and try mrand48. - } - else - { - DWORD offset = 0; - do - { - ssize_t n = read(rand_des, (BYTE*)lpBuffer + offset , dwLength - offset); - if (n == -1) - { - if (errno == EINTR) - { - continue; - } - ASSERT("read() failed, errno:%d (%s)\n", errno, strerror(errno)); - - break; - } - - offset += n; - } - while (offset != dwLength); - - _ASSERTE(offset == dwLength); - - close(rand_des); - } - } - - if (!sInitializedMRand) - { - srand48(time(NULL)); - sInitializedMRand = TRUE; - } - - // always xor srand48 over the whole buffer to get some randomness - // in case /dev/urandom is not really random - - for (i = 0; i < dwLength; i++) - { - if (i % sizeof(long) == 0) { - num = mrand48(); - } - - *(((BYTE*)lpBuffer) + i) ^= num; - num >>= 8; - } - - LOGEXIT("PAL_Random\n"); - PERF_EXIT(PAL_Random); -} diff --git a/src/coreclr/palrt/guid.cpp b/src/coreclr/palrt/guid.cpp index 68cc157d91ca7b..d1de2a4e49a4df 100644 --- a/src/coreclr/palrt/guid.cpp +++ b/src/coreclr/palrt/guid.cpp @@ -10,6 +10,7 @@ // =========================================================================== #define INITGUID +#include #include // These are GUIDs and IIDs that would normally be provided by the system via uuid.lib, @@ -28,7 +29,10 @@ DEFINE_GUID(IID_IStream, 0x0000000c, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x0 STDAPI CoCreateGuid(OUT GUID * pguid) { - PAL_Random(pguid, sizeof(GUID)); + if (!minipal_get_cryptographically_secure_random_bytes(pguid, sizeof(GUID))) + { + return E_FAIL; + } static const USHORT VersionMask = 0xF000; static const USHORT RandomGuidVersion = 0x4000; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp b/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp index fae4cea68159b6..9bba21b1bfd8e5 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp @@ -10,6 +10,7 @@ #include "spmiutil.h" #include +#include static bool breakOnDebugBreakorAV = false; @@ -235,13 +236,8 @@ WCHAR* GetResultFileName(const WCHAR* folderPath, const WCHAR* fileName, const W // Append a random string to improve uniqueness. // - unsigned randomNumber = 0; - -#ifdef TARGET_UNIX - PAL_Random(&randomNumber, sizeof(randomNumber)); -#else // !TARGET_UNIX - rand_s(&randomNumber); -#endif // !TARGET_UNIX + unsigned int randomNumber = 0; + minipal_get_non_cryptographically_secure_random_bytes((uint8_t*)&randomNumber, sizeof(randomNumber)); WCHAR randomString[randomStringLength + 1]; FormatInteger(randomString, randomStringLength + 1, "%08X", randomNumber); diff --git a/src/coreclr/tools/superpmi/superpmi/parallelsuperpmi.cpp b/src/coreclr/tools/superpmi/superpmi/parallelsuperpmi.cpp index 11af679d6d06ba..756664d7a88e5b 100644 --- a/src/coreclr/tools/superpmi/superpmi/parallelsuperpmi.cpp +++ b/src/coreclr/tools/superpmi/superpmi/parallelsuperpmi.cpp @@ -9,6 +9,7 @@ #include "commandline.h" #include "errorhandling.h" #include "fileio.h" +#include // Forward declare the conversion method. Including spmiutil.h pulls in other headers // that cause build breaks. @@ -557,11 +558,7 @@ int doParallelSuperPMI(CommandLine::Options& o) // Add a random number to the temporary file names to allow multiple parallel SuperPMI to happen at once. unsigned int randNumber = 0; -#ifdef TARGET_UNIX - PAL_Random(&randNumber, sizeof(randNumber)); -#else // !TARGET_UNIX - rand_s(&randNumber); -#endif // !TARGET_UNIX + minipal_get_non_cryptographically_secure_random_bytes((uint8_t*)&randNumber, sizeof(randNumber)); for (int i = 0; i < o.workerCount; i++) { From f96014a4378d26e8a5f4591af74074d3b4975190 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 16 Oct 2024 11:58:15 -0700 Subject: [PATCH 02/28] Move the "COM minipal" APIs into the regular repo minipal and update the CoreCLR PAL to also use it. Also remove dangling references to DNCP and remove dead standalone-DNMD infra --- src/coreclr/minipal/Unix/dn-u16.cpp | 8 ++- src/coreclr/palrt/CMakeLists.txt | 3 +- src/coreclr/palrt/comem.cpp | 5 +- src/coreclr/palrt/guid.cpp | 33 ++----------- src/native/minipal/CMakeLists.txt | 3 ++ src/native/minipal/guid.c | 77 +++++++++++++++++++++++++++++ src/native/minipal/guid.h | 43 ++++++++++++++++ src/native/minipal/memory.c | 40 +++++++++++++++ src/native/minipal/memory.h | 15 ++++++ src/native/minipal/strings.c | 14 ++++++ src/native/minipal/strings.h | 8 +++ 11 files changed, 212 insertions(+), 37 deletions(-) create mode 100644 src/native/minipal/guid.c create mode 100644 src/native/minipal/guid.h create mode 100644 src/native/minipal/memory.c create mode 100644 src/native/minipal/memory.h create mode 100644 src/native/minipal/strings.c diff --git a/src/coreclr/minipal/Unix/dn-u16.cpp b/src/coreclr/minipal/Unix/dn-u16.cpp index 7832e501023d3f..aec3fb1ae66388 100644 --- a/src/coreclr/minipal/Unix/dn-u16.cpp +++ b/src/coreclr/minipal/Unix/dn-u16.cpp @@ -5,13 +5,11 @@ typedef char16_t WCHAR; #include #include +#include size_t u16_strlen(const WCHAR* str) { - size_t nChar = 0; - while (*str++) - nChar++; - return nChar; + return minipal_u16_strlen((CHAR16_T*)str); } int u16_strcmp(const WCHAR* str1, const WCHAR* str2) @@ -192,4 +190,4 @@ uint64_t u16_strtoui64(const WCHAR* nptr, WCHAR** endptr, int base) double u16_strtod(const WCHAR* nptr, WCHAR** endptr) { return PAL_wcstod(nptr, endptr); -} \ No newline at end of file +} diff --git a/src/coreclr/palrt/CMakeLists.txt b/src/coreclr/palrt/CMakeLists.txt index eda33fe9e05924..05a604fc3fa9d0 100644 --- a/src/coreclr/palrt/CMakeLists.txt +++ b/src/coreclr/palrt/CMakeLists.txt @@ -11,5 +11,4 @@ add_library_clr(palrt ${PALRT_SOURCES} ) -# Install the static PAL library for VS -install_clr(TARGETS palrt DESTINATIONS lib) +target_link_libraries(palrt PUBLIC minipal) diff --git a/src/coreclr/palrt/comem.cpp b/src/coreclr/palrt/comem.cpp index e56e720cc80c2f..321dd19a3469b2 100644 --- a/src/coreclr/palrt/comem.cpp +++ b/src/coreclr/palrt/comem.cpp @@ -9,13 +9,14 @@ // =========================================================================== #include "common.h" +#include STDAPI_(LPVOID) CoTaskMemAlloc(SIZE_T cb) { - return malloc(cb); + return minipal_co_task_mem_alloc(cb); } STDAPI_(void) CoTaskMemFree(LPVOID pv) { - free(pv); + minipal_co_task_mem_free(pv); } diff --git a/src/coreclr/palrt/guid.cpp b/src/coreclr/palrt/guid.cpp index d1de2a4e49a4df..4f1ad4fefd33b5 100644 --- a/src/coreclr/palrt/guid.cpp +++ b/src/coreclr/palrt/guid.cpp @@ -9,43 +9,20 @@ // PALRT guids // =========================================================================== -#define INITGUID -#include #include +#include -// These are GUIDs and IIDs that would normally be provided by the system via uuid.lib, -// and that the PALRT exposes through headers. - -DEFINE_GUID(GUID_NULL, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); -DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); -DEFINE_GUID(IID_IClassFactory, 0x00000001, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); - - -// objidl.idl -DEFINE_GUID(IID_ISequentialStream, 0x0c733a30, 0x2a1c, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); -DEFINE_GUID(IID_IStream, 0x0000000c, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); - -// Create a random guid based on the https://www.ietf.org/rfc/rfc4122.txt STDAPI CoCreateGuid(OUT GUID * pguid) { - if (!minipal_get_cryptographically_secure_random_bytes(pguid, sizeof(GUID))) + minipal_guid_t guid; + if (!minipal_guid_v4_create(&guid)) { return E_FAIL; } - static const USHORT VersionMask = 0xF000; - static const USHORT RandomGuidVersion = 0x4000; - - static const BYTE ClockSeqHiAndReservedMask = 0xC0; - static const BYTE ClockSeqHiAndReservedValue = 0x80; - - // Modify bits indicating the type of the GUID - - // time_hi_and_version - pguid->Data3 = (pguid->Data3 & ~VersionMask) | RandomGuidVersion; - // clock_seq_hi_and_reserved - pguid->Data4[0] = (pguid->Data4[0] & ~ClockSeqHiAndReservedMask) | ClockSeqHiAndReservedValue; + static_assert(sizeof(GUID) == sizeof(minipal_guid_t), "GUID and minipal_guid_t must be the same size"); + memcpy(pguid, &guid, sizeof(GUID)); return S_OK; } diff --git a/src/native/minipal/CMakeLists.txt b/src/native/minipal/CMakeLists.txt index 56a6c8de10cb45..9af402eb34e46f 100644 --- a/src/native/minipal/CMakeLists.txt +++ b/src/native/minipal/CMakeLists.txt @@ -2,8 +2,11 @@ include(configure.cmake) set(SOURCES cpufeatures.c + guid.c + memory.c random.c debugger.c + strings.c time.c unicodedata.c utf8.c diff --git a/src/native/minipal/guid.c b/src/native/minipal/guid.c new file mode 100644 index 00000000000000..5e1237c4d96a91 --- /dev/null +++ b/src/native/minipal/guid.c @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "guid.h" +#include "random.h" +#include +#ifdef HOST_WINDOWS +#include +#endif + +// Define some well-known GUIDs on non-Windows platforms. +#ifndef HOST_WINDOWS +// 00000000-0000-0000-0000-000000000000 +minipal_guid_t const GUID_NULL = { 0x0, 0x0, 0x0, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; + +// 00000000-0000-0000-C000-000000000046 +minipal_guid_t const IID_IUnknown = { 0x0, 0x0, 0x0, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; + +// 00000001-0000-0000-C000-000000000046 +minipal_guid_t const IID_IClassFactory = { 0x1, 0x0, 0x0, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; + +// 0c733a30-2a1c-11ce-ade5-00aa0044773d +minipal_guid_t const IID_ISequentialStream = { 0x0c733a30, 0x2a1c, 0x11ce, { 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d } }; + +// 0000000C-0000-0000-C000-000000000046 +minipal_guid_t const IID_IStream = { 0xC, 0x0, 0x0, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; +#endif + +// See RFC-4122 section 4.4 on creation of random GUID. +// https://www.ietf.org/rfc/rfc4122.txt +// +// The version 4 UUID is meant for generating UUIDs from truly-random or +// pseudo-random numbers. +// +// The algorithm is as follows: +// +// o Set the two most significant bits (bits 6 and 7) of the +// clock_seq_hi_and_reserved to zero and one, respectively. +// +// o Set the four most significant bits (bits 12 through 15) of the +// time_hi_and_version field to the 4-bit version number from +// Section 4.1.3. +// +// o Set all the other bits to randomly (or pseudo-randomly) chosen +// values. +// +bool minipal_guid_v4_create(minipal_guid_t* guid) +{ +#ifdef HOST_WINDOWS + // Windows has a built-in function for creating v4 GUIDs. + return SUCCEEDED(CoCreateGuid((GUID*)guid)); +#else + if (minipal_get_cryptographically_secure_random_bytes((uint8_t*)guid, sizeof(*guid)) != 0) + return false; + + { + // time_hi_and_version + const uint16_t mask = 0xf000; // b1111000000000000 + const uint16_t value = 0x4000; // b0100000000000000 + guid->data3 = (guid->data3 & ~mask) | value; + } + + { + // clock_seq_hi_and_reserved + const uint8_t mask = 0xc0; // b11000000 + const uint8_t value = 0x80; // b10000000 + guid->data4[0] = (guid->data4[0] & ~mask) | value; + } + + return true; +#endif +} + +bool minipal_guid_equals(minipal_guid_t const* g1, minipal_guid_t const* g2) +{ + return memcmp(g1, g2, sizeof(minipal_guid_t)) == 0; +} diff --git a/src/native/minipal/guid.h b/src/native/minipal/guid.h new file mode 100644 index 00000000000000..77692aef9ff309 --- /dev/null +++ b/src/native/minipal/guid.h @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef MINIPAL_GUID_H +#define MINIPAL_GUID_H + +#include +#include + +#ifdef __cplusplus + extern "C" + { +#endif // __cplusplus + +typedef struct minipal_guid__ +{ + uint32_t data1; + uint16_t data2; + uint16_t data3; + uint8_t data4[8]; +} minipal_guid_t; + +bool minipal_guid_v4_create(minipal_guid_t* guid); + +bool minipal_guid_equals(minipal_guid_t const* g1, minipal_guid_t const* g2); + +#ifdef __cplusplus + } +#endif // __cplusplus + +#ifdef __cplusplus +inline bool operator==(minipal_guid_t const& a, minipal_guid_t const& b) +{ + return minipal_guid_equals(&a, &b); +} + +inline bool operator!=(minipal_guid_t const& a, minipal_guid_t const& b) +{ + return !(a == b); +} +#endif + +#endif // MINIPAL_GUID_H diff --git a/src/native/minipal/memory.c b/src/native/minipal/memory.c new file mode 100644 index 00000000000000..5e147de558f8b0 --- /dev/null +++ b/src/native/minipal/memory.c @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "memory.h" + +#ifdef HOST_WINDOWS +#include + +void* minipal_co_task_mem_alloc(size_t cb) +{ + return CoTaskMemAlloc(cb); +} + +void minipal_co_task_mem_free(void* pv) +{ + CoTaskMemFree(pv); +} +#else +// CoTaskMemAlloc always aligns on an 8-byte boundary. +#define ALIGN 8 + +void* minipal_co_task_mem_alloc(size_t cb) +{ + // Ensure malloc always allocates. + if (cb == 0) + cb = ALIGN; + + // Align the allocation size. + size_t cb_safe = (cb + (ALIGN - 1)) & ~(ALIGN - 1); + if (cb_safe < cb) // Overflow + return NULL; + + return aligned_alloc(ALIGN, cb_safe); +} + +void minipal_co_task_mem_free(void* pv) +{ + free(pv); +} +#endif diff --git a/src/native/minipal/memory.h b/src/native/minipal/memory.h new file mode 100644 index 00000000000000..aac7773c742702 --- /dev/null +++ b/src/native/minipal/memory.h @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef MINIPAL_MEMORY_H +#define MINIPAL_MEMORY_H + +#include + +// Allocate memory on the platform equivalent of the CoTaskMem heap. +void* minipal_co_task_mem_alloc(size_t cb); + +// Free memory allocated on the platform equivalent of the CoTaskMem heap. +void minipal_co_task_mem_free(void* pv); + +#endif // MINIPAL_MEMORY_H diff --git a/src/native/minipal/strings.c b/src/native/minipal/strings.c new file mode 100644 index 00000000000000..1711a9d07cae90 --- /dev/null +++ b/src/native/minipal/strings.c @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "strings.h" + +size_t minipal_u16_strlen(const CHAR16_T* str) +{ + size_t len = 0; + while (*str++) + { + len++; + } + return len; +} diff --git a/src/native/minipal/strings.h b/src/native/minipal/strings.h index 250dada9f539cd..ebeea097d6f07b 100644 --- a/src/native/minipal/strings.h +++ b/src/native/minipal/strings.h @@ -27,6 +27,14 @@ CHAR16_T minipal_toupper_invariant(CHAR16_T code); */ CHAR16_T minipal_tolower_invariant(CHAR16_T code); +/** + * @brief Get the length of a null-terminated UTF-16 string. + * + * @param str The null-terminated UTF-16 string. + * @return The length of the string. + */ +size_t minipal_u16_strlen(const CHAR16_T* str); + #ifdef __cplusplus } #endif // __cplusplus From 5ccbb532c9a32e46f61a4a90766b9a2ebbf3694d Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 16 Oct 2024 13:43:02 -0700 Subject: [PATCH 03/28] Remove direct CoCreateGuid usage from CoreCLR and instead use the minipal --- src/coreclr/debug/inc/dbgtransportsession.h | 6 ++-- .../debug/shared/dbgtransportsession.cpp | 5 ++-- src/coreclr/ilasm/assem.cpp | 9 ------ src/coreclr/ilasm/portable_pdb.cpp | 10 ++++--- src/coreclr/md/compiler/regmeta.cpp | 3 +- src/coreclr/md/enc/metamodelrw.cpp | 3 +- src/coreclr/md/inc/portablepdbmdds.h | 1 + src/coreclr/pal/inc/rt/palrt.h | 3 -- src/coreclr/palrt/CMakeLists.txt | 1 - src/coreclr/palrt/guid.cpp | 28 ------------------- .../vm/eventing/eventpipe/ep-rt-coreclr.h | 3 +- src/coreclr/vm/eventpipeinternal.cpp | 6 ++-- 12 files changed, 23 insertions(+), 55 deletions(-) delete mode 100644 src/coreclr/palrt/guid.cpp diff --git a/src/coreclr/debug/inc/dbgtransportsession.h b/src/coreclr/debug/inc/dbgtransportsession.h index 528590e21d51c1..7a5df64d41eec8 100644 --- a/src/coreclr/debug/inc/dbgtransportsession.h +++ b/src/coreclr/debug/inc/dbgtransportsession.h @@ -11,6 +11,8 @@ #endif // !RIGHT_SIDE_COMPILE +#include + #if defined(FEATURE_DBGIPC_TRANSPORT_VM) || defined(FEATURE_DBGIPC_TRANSPORT_DI) #include @@ -519,7 +521,7 @@ class DbgTransportSession // Struct defining the format of the data block sent with a SessionRequest. struct SessionRequestData { - GUID m_sSessionID; // Unique session ID. Treated as byte blob so no endian-ness + minipal_guid_t m_sSessionID; // Unique session ID. Treated as byte blob so no endian-ness }; // Struct used to track a message that is being (or will soon be) sent but has not yet been acknowledged. @@ -674,7 +676,7 @@ class DbgTransportSession // Session ID randomly allocated by the right side and sent over in the SessionRequest message. This // serves to disambiguate a re-send of the SessionRequest due to a network error versus a SessionRequest // from a different debugger. - GUID m_sSessionID; + minipal_guid_t m_sSessionID; // Lock used to synchronize sending messages and updating the session state. This ensures message bytes // don't become interleaved on the transport connection, the send queue is updated consistently across diff --git a/src/coreclr/debug/shared/dbgtransportsession.cpp b/src/coreclr/debug/shared/dbgtransportsession.cpp index 74692f40e85f75..2df265f22b869e 100644 --- a/src/coreclr/debug/shared/dbgtransportsession.cpp +++ b/src/coreclr/debug/shared/dbgtransportsession.cpp @@ -89,9 +89,8 @@ HRESULT DbgTransportSession::Init(DebuggerIPCControlBlock *pDCB, AppDomainEnumer // The RS randomly allocates a session ID which is sent to the LS in the SessionRequest message. In the // case of network errors during session formation this allows the LS to tell SessionRequest re-sends from // a new request from a different RS. - HRESULT hr = CoCreateGuid(&m_sSessionID); - if (FAILED(hr)) - return hr; + if (!minipal_guid_v4_create(&m_sSessionID)) + return E_FAIL; #endif // RIGHT_SIDE_COMPILE diff --git a/src/coreclr/ilasm/assem.cpp b/src/coreclr/ilasm/assem.cpp index 2cbf02c0eab077..0100feef79a127 100644 --- a/src/coreclr/ilasm/assem.cpp +++ b/src/coreclr/ilasm/assem.cpp @@ -1064,20 +1064,11 @@ BOOL Assembler::EmitClass(Class *pClass) LPCUTF8 szFullName; WCHAR* wzFullName=&wzUniBuf[0]; HRESULT hr = E_FAIL; - GUID guid; size_t L; mdToken tok; if(pClass == NULL) return FALSE; - hr = CoCreateGuid(&guid); - if (FAILED(hr)) - { - printf("Unable to create GUID\n"); - m_State = STATE_FAIL; - return FALSE; - } - if(pClass->m_pEncloser) szFullName = strrchr(pClass->m_szFQN,NESTING_SEP) + 1; else diff --git a/src/coreclr/ilasm/portable_pdb.cpp b/src/coreclr/ilasm/portable_pdb.cpp index 68bd1bd72b950d..83260f107de50d 100644 --- a/src/coreclr/ilasm/portable_pdb.cpp +++ b/src/coreclr/ilasm/portable_pdb.cpp @@ -92,9 +92,11 @@ HRESULT PortablePdbWriter::Init(IMetaDataDispenserEx2* mdDispenser) time_t now; time(&now); m_pdbStream.id.pdbTimeStamp = (ULONG)now; - hr = CoCreateGuid(&m_pdbStream.id.pdbGuid); - - if (FAILED(hr)) goto exit; + if (!minipal_guid_v4_create(reinterpret_cast(&m_pdbStream.id.pdbGuid))) + { + hr = E_FAIL; + goto exit; + } hr = mdDispenser->DefinePortablePdbScope( CLSID_CorMetaDataRuntime, @@ -176,7 +178,7 @@ HRESULT PortablePdbWriter::DefineDocument(char* name, GUID* language) mdDocument docToken = mdDocumentNil; if (FAILED(hr = m_pdbEmitter->DefineDocument( - name, // will be tokenized + name, // will be tokenized &hashAlgorithmUnknown, hashValue, cbHashValue, diff --git a/src/coreclr/md/compiler/regmeta.cpp b/src/coreclr/md/compiler/regmeta.cpp index 85130f4cd40198..eee9a527f04c84 100644 --- a/src/coreclr/md/compiler/regmeta.cpp +++ b/src/coreclr/md/compiler/regmeta.cpp @@ -21,6 +21,7 @@ #include "posterror.h" #include "stgio.h" #include "sstring.h" +#include #include "mdinternalrw.h" @@ -246,7 +247,7 @@ RegMeta::CreateNewMD() ModuleRec *pModule; GUID mvid; IfFailGo(m_pStgdb->m_MiniMd.AddModuleRecord(&pModule, &iRecord)); - IfFailGo(CoCreateGuid(&mvid)); + IfFailGo(minipal_guid_v4_create(reinterpret_cast(&mvid)) ? S_OK : E_FAIL); IfFailGo(m_pStgdb->m_MiniMd.PutGuid(TBL_Module, ModuleRec::COL_Mvid, pModule, mvid)); // Add the dummy module typedef which we are using to parent global items. diff --git a/src/coreclr/md/enc/metamodelrw.cpp b/src/coreclr/md/enc/metamodelrw.cpp index 930a5c98a9446d..50f5c95a0dcd29 100644 --- a/src/coreclr/md/enc/metamodelrw.cpp +++ b/src/coreclr/md/enc/metamodelrw.cpp @@ -19,6 +19,7 @@ #include "../compiler/importhelper.h" #include "metadata.h" #include "streamutil.h" +#include #ifdef _MSC_VER #pragma intrinsic(memcpy) @@ -1196,7 +1197,7 @@ CMiniMdRW::SetOption( PutCol(TBL_Module, ModuleRec::COL_EncBaseId, pMod, uVal); */ // Allocate a new GUID for EncId. - IfFailGo(CoCreateGuid(&encid)); + IfFailGo(minipal_guid_v4_create(reinterpret_cast(&encid)) ? S_OK : E_FAIL); IfFailGo(PutGuid(TBL_Module, ModuleRec::COL_EncId, pMod, encid)); #else //!FEATURE_METADATA_EMIT IfFailGo(E_INVALIDARG); diff --git a/src/coreclr/md/inc/portablepdbmdds.h b/src/coreclr/md/inc/portablepdbmdds.h index 10c82d3dba3186..9caed6cf2eb3e1 100644 --- a/src/coreclr/md/inc/portablepdbmdds.h +++ b/src/coreclr/md/inc/portablepdbmdds.h @@ -16,6 +16,7 @@ #endif #include "corhdr.h" +#include //------------------------------------- //--- PDB stream data structure diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index 05c04a21ca671c..f0d1af00100ed8 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -1093,9 +1093,6 @@ EXTERN_C HRESULT PALAPI PAL_CoCreateInstance(REFCLSID rclsid, // instead of spreading around of if'def FEATURE_PALs for PAL_CoCreateInstance. #define CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv) PAL_CoCreateInstance(rclsid, riid, ppv) -STDAPI -CoCreateGuid(OUT GUID * pguid); - /************** Byte swapping & unaligned access ******************/ #include diff --git a/src/coreclr/palrt/CMakeLists.txt b/src/coreclr/palrt/CMakeLists.txt index 05a604fc3fa9d0..bd28f446d710ce 100644 --- a/src/coreclr/palrt/CMakeLists.txt +++ b/src/coreclr/palrt/CMakeLists.txt @@ -3,7 +3,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(PALRT_SOURCES comem.cpp - guid.cpp ) add_library_clr(palrt diff --git a/src/coreclr/palrt/guid.cpp b/src/coreclr/palrt/guid.cpp deleted file mode 100644 index 4f1ad4fefd33b5..00000000000000 --- a/src/coreclr/palrt/guid.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -// -// =========================================================================== -// File: guid.cpp -// -// PALRT guids -// =========================================================================== - -#include -#include - -STDAPI -CoCreateGuid(OUT GUID * pguid) -{ - minipal_guid_t guid; - if (!minipal_guid_v4_create(&guid)) - { - return E_FAIL; - } - - static_assert(sizeof(GUID) == sizeof(minipal_guid_t), "GUID and minipal_guid_t must be the same size"); - memcpy(pguid, &guid, sizeof(GUID)); - - return S_OK; -} diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 7f66adf7df6314..767e23adfd0d7c 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -17,6 +17,7 @@ #include "typestring.h" #include "clrversion.h" #include "hostinformation.h" +#include #undef EP_INFINITE_WAIT #define EP_INFINITE_WAIT INFINITE @@ -748,7 +749,7 @@ ep_rt_create_activity_id ( EP_ASSERT (activity_id != NULL); EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE); - CoCreateGuid (reinterpret_cast(activity_id)); + minipal_guid_v4_create (reinterpret_cast(activity_id)); } static diff --git a/src/coreclr/vm/eventpipeinternal.cpp b/src/coreclr/vm/eventpipeinternal.cpp index 9d00e848001514..be22b72be47a39 100644 --- a/src/coreclr/vm/eventpipeinternal.cpp +++ b/src/coreclr/vm/eventpipeinternal.cpp @@ -9,6 +9,8 @@ #include "pal.h" #endif // TARGET_UNIX +#include + #ifdef FEATURE_PERFTRACING extern "C" UINT64 QCALLTYPE EventPipeInternal_Enable( @@ -190,7 +192,7 @@ extern "C" int QCALLTYPE EventPipeInternal_EventActivityIdControl(uint32_t contr case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_ID: - CoCreateGuid(pActivityId); + minipal_guid_v4_create(reinterpret_cast(pActivityId)); break; case ActivityControlCode::EVENT_ACTIVITY_CONTROL_GET_SET_ID: @@ -203,7 +205,7 @@ extern "C" int QCALLTYPE EventPipeInternal_EventActivityIdControl(uint32_t contr case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_SET_ID: *pActivityId = *pThread->GetActivityId(); - CoCreateGuid(¤tActivityId); + minipal_guid_v4_create(reinterpret_cast(¤tActivityId)); pThread->SetActivityId(¤tActivityId); break; From cbb3c4a9022e61d82fa7dd4074dfc6ae303e2aff Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 16 Oct 2024 14:48:03 -0700 Subject: [PATCH 04/28] Remove CoTaskMemAlloc/Free usage from xplat code (and instead use the minipal implementation) --- src/coreclr/debug/di/module.cpp | 2 +- src/coreclr/dlls/mscorpe/pewriter.cpp | 4 ++-- src/coreclr/inc/holder.h | 3 ++- src/coreclr/md/enc/stgio.cpp | 2 +- src/coreclr/pal/inc/rt/palrt.h | 4 ---- src/coreclr/palrt/CMakeLists.txt | 13 ------------- src/coreclr/palrt/comem.cpp | 22 ---------------------- src/coreclr/vm/gdbjit.cpp | 14 +++++++------- src/coreclr/vm/ilmarshalers.cpp | 2 +- src/coreclr/vm/olevariant.cpp | 10 +++++----- src/native/minipal/memory.h | 9 +++++++++ 11 files changed, 28 insertions(+), 57 deletions(-) delete mode 100644 src/coreclr/palrt/comem.cpp diff --git a/src/coreclr/debug/di/module.cpp b/src/coreclr/debug/di/module.cpp index 02986839e454bb..d3ab476877b6ee 100644 --- a/src/coreclr/debug/di/module.cpp +++ b/src/coreclr/debug/di/module.cpp @@ -1101,7 +1101,7 @@ void CordbModule::CopyRemoteMetaData( // Allocate space for the local copy of the metadata // No need to zero out the memory since we'll fill it all here. - LPVOID pRawBuffer = CoTaskMemAlloc(buffer.cbSize); + LPVOID pRawBuffer = minipal_co_task_mem_alloc(buffer.cbSize); if (pRawBuffer == NULL) { ThrowOutOfMemory(); diff --git a/src/coreclr/dlls/mscorpe/pewriter.cpp b/src/coreclr/dlls/mscorpe/pewriter.cpp index 5e22e628b368c4..5de2dd6685dc3a 100644 --- a/src/coreclr/dlls/mscorpe/pewriter.cpp +++ b/src/coreclr/dlls/mscorpe/pewriter.cpp @@ -1593,7 +1593,7 @@ HRESULT PEWriter::write(void ** ppImage) size_t lSize = filePos; // allocate the block we are handing back to the caller - void * pImage = (void *) ::CoTaskMemAlloc(lSize); + void * pImage = (void *) ::minipal_co_task_mem_alloc(lSize); if (NULL == pImage) { return E_OUTOFMEMORY; @@ -1626,7 +1626,7 @@ HRESULT PEWriter::write(void ** ppImage) // make sure we wrote the exact numbmer of bytes expected _ASSERTE(lSize == (size_t) (pCur - (char *)pImage)); - // give pointer to memory image back to caller (who must free with ::CoTaskMemFree()) + // give pointer to memory image back to caller (who must free with ::minipal_co_task_mem_free()) *ppImage = pImage; // all done diff --git a/src/coreclr/inc/holder.h b/src/coreclr/inc/holder.h index 353d7f39d5004b..7afd527bb1281c 100644 --- a/src/coreclr/inc/holder.h +++ b/src/coreclr/inc/holder.h @@ -10,6 +10,7 @@ #include "staticcontract.h" #include "volatile.h" #include "palclr.h" +#include #include #include @@ -969,7 +970,7 @@ template FORCEINLINE void DeleteCoTaskMem(TYPE *value) { if (value) - CoTaskMemFree(value); + minipal_co_task_mem_free(value); } template diff --git a/src/coreclr/md/enc/stgio.cpp b/src/coreclr/md/enc/stgio.cpp index aeba5e59f47359..0297478cfb69f8 100644 --- a/src/coreclr/md/enc/stgio.cpp +++ b/src/coreclr/md/enc/stgio.cpp @@ -339,7 +339,7 @@ void StgIO::Close() case STGIO_SHAREDMEM: if (m_pBaseData != NULL) { - CoTaskMemFree(m_pBaseData); + minipal_co_task_mem_free(m_pBaseData); m_pBaseData = NULL; break; } diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index f0d1af00100ed8..61a4ab379666b4 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -274,10 +274,6 @@ typedef union _ULARGE_INTEGER { } ULARGE_INTEGER, *PULARGE_INTEGER; /******************* OLE, BSTR, VARIANT *************************/ - -STDAPI_VIS(DLLEXPORT, LPVOID) CoTaskMemAlloc(SIZE_T cb); -STDAPI_VIS(DLLEXPORT, void) CoTaskMemFree(LPVOID pv); - typedef SHORT VARIANT_BOOL; #define VARIANT_TRUE ((VARIANT_BOOL)-1) #define VARIANT_FALSE ((VARIANT_BOOL)0) diff --git a/src/coreclr/palrt/CMakeLists.txt b/src/coreclr/palrt/CMakeLists.txt index bd28f446d710ce..e69de29bb2d1d6 100644 --- a/src/coreclr/palrt/CMakeLists.txt +++ b/src/coreclr/palrt/CMakeLists.txt @@ -1,13 +0,0 @@ - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(PALRT_SOURCES - comem.cpp -) - -add_library_clr(palrt - STATIC - ${PALRT_SOURCES} -) - -target_link_libraries(palrt PUBLIC minipal) diff --git a/src/coreclr/palrt/comem.cpp b/src/coreclr/palrt/comem.cpp deleted file mode 100644 index 321dd19a3469b2..00000000000000 --- a/src/coreclr/palrt/comem.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -// -// =========================================================================== -// File: comem.cpp -// -// =========================================================================== - -#include "common.h" -#include - -STDAPI_(LPVOID) CoTaskMemAlloc(SIZE_T cb) -{ - return minipal_co_task_mem_alloc(cb); -} - -STDAPI_(void) CoTaskMemFree(LPVOID pv) -{ - minipal_co_task_mem_free(pv); -} diff --git a/src/coreclr/vm/gdbjit.cpp b/src/coreclr/vm/gdbjit.cpp index 2a376726e52854..672cbdb0300939 100644 --- a/src/coreclr/vm/gdbjit.cpp +++ b/src/coreclr/vm/gdbjit.cpp @@ -452,7 +452,7 @@ HRESULT FunctionMember::GetLocalsDebugInfo(NotifyGdb::PTK_TypeInfoMap pTypeMap, MethodDebugInfo::MethodDebugInfo(int numPoints, int numLocals) { - points = (SequencePointInfo*) CoTaskMemAlloc(sizeof(SequencePointInfo) * numPoints); + points = (SequencePointInfo*) minipal_co_task_mem_alloc(sizeof(SequencePointInfo) * numPoints); if (points == nullptr) { COMPlusThrowOM(); @@ -467,10 +467,10 @@ MethodDebugInfo::MethodDebugInfo(int numPoints, int numLocals) return; } - locals = (LocalVarInfo*) CoTaskMemAlloc(sizeof(LocalVarInfo) * numLocals); + locals = (LocalVarInfo*) minipal_co_task_mem_alloc(sizeof(LocalVarInfo) * numLocals); if (locals == nullptr) { - CoTaskMemFree(points); + minipal_co_task_mem_free(points); COMPlusThrowOM(); } memset(locals, 0, sizeof(LocalVarInfo) * numLocals); @@ -482,13 +482,13 @@ MethodDebugInfo::~MethodDebugInfo() if (locals) { for (int i = 0; i < localsSize; i++) - CoTaskMemFree(locals[i].name); - CoTaskMemFree(locals); + minipal_co_task_mem_free(locals[i].name); + minipal_co_task_mem_free(locals); } for (int i = 0; i < size; i++) - CoTaskMemFree(points[i].fileName); - CoTaskMemFree(points); + minipal_co_task_mem_free(points[i].fileName); + minipal_co_task_mem_free(points); } /* Get mapping of IL offsets to source line numbers */ diff --git a/src/coreclr/vm/ilmarshalers.cpp b/src/coreclr/vm/ilmarshalers.cpp index aa9b3d6531553a..1726c63ece42a9 100644 --- a/src/coreclr/vm/ilmarshalers.cpp +++ b/src/coreclr/vm/ilmarshalers.cpp @@ -4302,7 +4302,7 @@ extern "C" void QCALLTYPE MngdNativeArrayMarshaler_ConvertSpaceToNative(MngdNati if ( (!ClrSafeInt::multiply(cElements, cbElement, cbArray)) || cbArray > MAX_SIZE_FOR_INTEROP) COMPlusThrow(kArgumentException, IDS_EE_STRUCTARRAYTOOLARGE); - *pNativeHome = CoTaskMemAlloc(cbArray); + *pNativeHome = minipal_co_task_mem_alloc(cbArray); if (*pNativeHome == NULL) ThrowOutOfMemory(); diff --git a/src/coreclr/vm/olevariant.cpp b/src/coreclr/vm/olevariant.cpp index ab42391080e039..82072d170e5fb2 100644 --- a/src/coreclr/vm/olevariant.cpp +++ b/src/coreclr/vm/olevariant.cpp @@ -1657,7 +1657,7 @@ void OleVariant::MarshalLPWSTRRArrayComToOle(BASEARRAYREF *pComArray, void *oleA // Allocate the string using CoTaskMemAlloc. { GCX_PREEMP(); - lpwstr = (LPWSTR)CoTaskMemAlloc(allocLength); + lpwstr = (LPWSTR)minipal_co_task_mem_alloc(allocLength); } if (lpwstr == NULL) ThrowOutOfMemory(); @@ -1694,7 +1694,7 @@ void OleVariant::ClearLPWSTRArray(void *oleArray, SIZE_T cElements, MethodTable LPWSTR lpwstr = *pOle++; if (lpwstr != NULL) - CoTaskMemFree(lpwstr); + minipal_co_task_mem_free(lpwstr); } } @@ -1801,7 +1801,7 @@ void OleVariant::MarshalLPSTRRArrayComToOle(BASEARRAYREF *pComArray, void *oleAr // Allocate the string using CoTaskMemAlloc. { GCX_PREEMP(); - lpstr = (LPSTR)CoTaskMemAlloc(allocLength); + lpstr = (LPSTR)minipal_co_task_mem_alloc(allocLength); } if (lpstr == NULL) ThrowOutOfMemory(); @@ -1840,7 +1840,7 @@ void OleVariant::ClearLPSTRArray(void *oleArray, SIZE_T cElements, MethodTable * LPSTR lpstr = *pOle++; if (lpstr != NULL) - CoTaskMemFree(lpstr); + minipal_co_task_mem_free(lpstr); } } @@ -2468,7 +2468,7 @@ void OleVariant::MarshalObjectForOleVariant(const VARIANT * pOle, OBJECTREF * co AllocateObject(CoreLibBinder::GetElementType(ELEMENT_TYPE_U1)) ); *(BYTE*)((*pObj)->GetData()) = *(V_UI1REF(pOle)); break; - + case VT_I8: SetObjectReference( pObj, AllocateObject(CoreLibBinder::GetElementType(ELEMENT_TYPE_I8)) ); diff --git a/src/native/minipal/memory.h b/src/native/minipal/memory.h index aac7773c742702..258a3938a8eb67 100644 --- a/src/native/minipal/memory.h +++ b/src/native/minipal/memory.h @@ -6,10 +6,19 @@ #include +#ifdef __cplusplus + extern "C" + { +#endif // __cplusplus + // Allocate memory on the platform equivalent of the CoTaskMem heap. void* minipal_co_task_mem_alloc(size_t cb); // Free memory allocated on the platform equivalent of the CoTaskMem heap. void minipal_co_task_mem_free(void* pv); +#ifdef __cplusplus + } +#endif // __cplusplus + #endif // MINIPAL_MEMORY_H From 995c85889c0356f2add87184bebe6664a0af900b Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 11:11:50 -0700 Subject: [PATCH 05/28] palrt is empty, so remove it. --- src/coreclr/CMakeLists.txt | 4 ---- src/coreclr/dlls/mscordac/CMakeLists.txt | 1 - src/coreclr/dlls/mscordbi/CMakeLists.txt | 1 - .../dlls/mscoree/coreclr/CMakeLists.txt | 1 - src/coreclr/ilasm/CMakeLists.txt | 2 -- src/coreclr/ildasm/exe/CMakeLists.txt | 2 -- src/coreclr/pal/inc/rt/palrt.h | 24 ------------------- src/coreclr/palrt/CMakeLists.txt | 0 src/coreclr/palrt/common.h | 17 ------------- src/coreclr/tools/superpmi/mcs/CMakeLists.txt | 1 - .../superpmi-shim-collector/CMakeLists.txt | 1 - .../superpmi-shim-counter/CMakeLists.txt | 1 - .../superpmi-shim-simple/CMakeLists.txt | 1 - .../tools/superpmi/superpmi/CMakeLists.txt | 1 - .../corehost/apphost/static/CMakeLists.txt | 1 - 15 files changed, 58 deletions(-) delete mode 100644 src/coreclr/palrt/CMakeLists.txt delete mode 100644 src/coreclr/palrt/common.h diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 732c3b765379ed..107859ec58dc5b 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -250,10 +250,6 @@ if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_H add_subdirectory(utilcode) add_subdirectory(inc) - if(CLR_CMAKE_HOST_UNIX) - add_subdirectory(palrt) - endif(CLR_CMAKE_HOST_UNIX) - add_subdirectory(ilasm) add_subdirectory(ildasm) add_subdirectory(gcinfo) diff --git a/src/coreclr/dlls/mscordac/CMakeLists.txt b/src/coreclr/dlls/mscordac/CMakeLists.txt index f031e3fc4b60f7..ef91243448c518 100644 --- a/src/coreclr/dlls/mscordac/CMakeLists.txt +++ b/src/coreclr/dlls/mscordac/CMakeLists.txt @@ -175,7 +175,6 @@ else(CLR_CMAKE_HOST_WIN32) mscorrc ${START_WHOLE_ARCHIVE} # force all PAL objects to be included so all exports are available coreclrpal - palrt coreclrminipal ${END_WHOLE_ARCHIVE} ) diff --git a/src/coreclr/dlls/mscordbi/CMakeLists.txt b/src/coreclr/dlls/mscordbi/CMakeLists.txt index fce244c50d717b..a92f844b0f9d9e 100644 --- a/src/coreclr/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/dlls/mscordbi/CMakeLists.txt @@ -96,7 +96,6 @@ if(CLR_CMAKE_HOST_WIN32) elseif(CLR_CMAKE_HOST_UNIX) list(APPEND COREDBI_LIBRARIES - palrt # share the PAL in the dac module mscordaccore ) diff --git a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt index 7e941521bd51b5..6dd42fe2b2538c 100644 --- a/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt @@ -140,7 +140,6 @@ else() coreclrpal ${END_WHOLE_ARCHIVE} mscorrc - palrt ) endif(CLR_CMAKE_TARGET_WIN32) diff --git a/src/coreclr/ilasm/CMakeLists.txt b/src/coreclr/ilasm/CMakeLists.txt index cca2c6da1858e6..818171c25c749a 100644 --- a/src/coreclr/ilasm/CMakeLists.txt +++ b/src/coreclr/ilasm/CMakeLists.txt @@ -103,7 +103,6 @@ else() list(APPEND ILASM_LINK_LIBRARIES coreclrpal mscorrc - palrt coreclrminipal ) endif(CLR_CMAKE_TARGET_WIN32) @@ -116,7 +115,6 @@ if(CLR_CMAKE_HOST_UNIX) utilcodestaticnohost mscorrc coreclrpal - palrt ${CMAKE_DL_LIBS} ) else() diff --git a/src/coreclr/ildasm/exe/CMakeLists.txt b/src/coreclr/ildasm/exe/CMakeLists.txt index fd5daaaa1525b1..c16fbed72c09f7 100644 --- a/src/coreclr/ildasm/exe/CMakeLists.txt +++ b/src/coreclr/ildasm/exe/CMakeLists.txt @@ -94,7 +94,6 @@ else() list(APPEND ILDASM_LINK_LIBRARIES coreclrpal mscorrc - palrt coreclrminipal ) endif(CLR_CMAKE_HOST_WIN32) @@ -105,7 +104,6 @@ if(CLR_CMAKE_HOST_UNIX) ${ILDASM_LINK_LIBRARIES} mscorrc coreclrpal - palrt ${CMAKE_DL_LIBS} ) else() diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index 61a4ab379666b4..9317654958b63b 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -1065,30 +1065,6 @@ typedef LONG (WINAPI *PTOP_LEVEL_EXCEPTION_FILTER)( ); typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER; -/******************** PAL RT APIs *******************************/ - -typedef struct _HSATELLITE *HSATELLITE; - -EXTERN_C HSATELLITE PALAPI PAL_LoadSatelliteResourceW(LPCWSTR SatelliteResourceFileName); -EXTERN_C HSATELLITE PALAPI PAL_LoadSatelliteResourceA(LPCSTR SatelliteResourceFileName); -EXTERN_C BOOL PALAPI PAL_FreeSatelliteResource(HSATELLITE SatelliteResource); -EXTERN_C UINT PALAPI PAL_LoadSatelliteStringW(HSATELLITE SatelliteResource, - UINT uID, - LPWSTR lpBuffer, - UINT nBufferMax); -EXTERN_C UINT PALAPI PAL_LoadSatelliteStringA(HSATELLITE SatelliteResource, - UINT uID, - LPSTR lpBuffer, - UINT nBufferMax); - -EXTERN_C HRESULT PALAPI PAL_CoCreateInstance(REFCLSID rclsid, - REFIID riid, - void **ppv); - -// So we can have CoCreateInstance in most of the code base, -// instead of spreading around of if'def FEATURE_PALs for PAL_CoCreateInstance. -#define CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv) PAL_CoCreateInstance(rclsid, riid, ppv) - /************** Byte swapping & unaligned access ******************/ #include diff --git a/src/coreclr/palrt/CMakeLists.txt b/src/coreclr/palrt/CMakeLists.txt deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/src/coreclr/palrt/common.h b/src/coreclr/palrt/common.h deleted file mode 100644 index 1040b7c13cec47..00000000000000 --- a/src/coreclr/palrt/common.h +++ /dev/null @@ -1,17 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -//***************************************************************************** -// common.h -// - -// -// Common include file for the palrt code. -//***************************************************************************** - -#ifndef _COMMON_H_ -#define _COMMON_H_ - -#include -#include -#include -#endif // _COMMON_H_ diff --git a/src/coreclr/tools/superpmi/mcs/CMakeLists.txt b/src/coreclr/tools/superpmi/mcs/CMakeLists.txt index 254ec92cb0488f..b11fed72e32e6d 100644 --- a/src/coreclr/tools/superpmi/mcs/CMakeLists.txt +++ b/src/coreclr/tools/superpmi/mcs/CMakeLists.txt @@ -58,7 +58,6 @@ if(CLR_CMAKE_HOST_UNIX) utilcodestaticnohost mscorrc coreclrpal - palrt coreclrminipal ) else() diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/CMakeLists.txt b/src/coreclr/tools/superpmi/superpmi-shim-collector/CMakeLists.txt index 5ddfc257abf746..61ea6207c8b29f 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/CMakeLists.txt +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/CMakeLists.txt @@ -73,7 +73,6 @@ if(CLR_CMAKE_HOST_UNIX) utilcodestaticnohost mscorrc coreclrpal - palrt coreclrminipal ) else() diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/CMakeLists.txt b/src/coreclr/tools/superpmi/superpmi-shim-counter/CMakeLists.txt index 231b5d3253e973..107425a8829743 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/CMakeLists.txt +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/CMakeLists.txt @@ -54,7 +54,6 @@ if(CLR_CMAKE_HOST_UNIX) utilcodestaticnohost mscorrc coreclrpal - palrt coreclrminipal ) else() diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/CMakeLists.txt b/src/coreclr/tools/superpmi/superpmi-shim-simple/CMakeLists.txt index 96ac56a7e85231..f6be551299c166 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/CMakeLists.txt +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/CMakeLists.txt @@ -53,7 +53,6 @@ if(CLR_CMAKE_HOST_UNIX) utilcodestaticnohost mscorrc coreclrpal - palrt coreclrminipal ) else() diff --git a/src/coreclr/tools/superpmi/superpmi/CMakeLists.txt b/src/coreclr/tools/superpmi/superpmi/CMakeLists.txt index ccb766f0d0788b..2b93a45c7c9eb9 100644 --- a/src/coreclr/tools/superpmi/superpmi/CMakeLists.txt +++ b/src/coreclr/tools/superpmi/superpmi/CMakeLists.txt @@ -64,7 +64,6 @@ if(CLR_CMAKE_HOST_UNIX) utilcodestaticnohost mscorrc coreclrpal - palrt coreclrminipal ) else() diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 3ea4d5d043ca3a..c013b3fcce0d71 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -169,7 +169,6 @@ else() System.Native-Static System.Security.Cryptography.Native.OpenSsl-Static - palrt coreclrpal_dac corguids dbgutil From 75c421d0a47cd4dea5282f0fe5540a5ecbf89d26 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 15:12:47 -0700 Subject: [PATCH 06/28] Use minipal_u16_strlen in more places. --- src/coreclr/debug/createdump/crashinfo.cpp | 2 +- src/coreclr/debug/createdump/createdumppal.cpp | 8 -------- src/coreclr/pal/src/locale/unicode.cpp | 2 +- src/mono/mono/eglib/giconv.c | 16 +++------------- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/coreclr/debug/createdump/crashinfo.cpp b/src/coreclr/debug/createdump/crashinfo.cpp index 4026903f289e09..8958cfc05c54f3 100644 --- a/src/coreclr/debug/createdump/crashinfo.cpp +++ b/src/coreclr/debug/createdump/crashinfo.cpp @@ -1026,7 +1026,7 @@ ConvertString(const WCHAR* str) if (str == nullptr) return { }; - size_t cch = u16_strlen(str) + 1; + size_t cch = minipal_u16_strlen((CHAR16_T*)str) + 1; int len = minipal_get_length_utf16_to_utf8((CHAR16_T*)str, cch, 0); if (len == 0) return { }; diff --git a/src/coreclr/debug/createdump/createdumppal.cpp b/src/coreclr/debug/createdump/createdumppal.cpp index 03b06a84a46139..88e57ef7e8541c 100644 --- a/src/coreclr/debug/createdump/createdumppal.cpp +++ b/src/coreclr/debug/createdump/createdumppal.cpp @@ -217,14 +217,6 @@ RaiseException( throw; } -size_t u16_strlen(const WCHAR* str) -{ - size_t nChar = 0; - while (*str++) - nChar++; - return nChar; -} - // // Used by _ASSERTE // diff --git a/src/coreclr/pal/src/locale/unicode.cpp b/src/coreclr/pal/src/locale/unicode.cpp index e966e22821ba09..2c6cf3e55bba97 100644 --- a/src/coreclr/pal/src/locale/unicode.cpp +++ b/src/coreclr/pal/src/locale/unicode.cpp @@ -202,7 +202,7 @@ WideCharToMultiByte( if (CodePage == CP_UTF8 || CodePage == CP_ACP) { if (cchWideChar < 0) - cchWideChar = PAL_wcslen(lpWideCharStr) + 1; + cchWideChar = minipal_u16_strlen((CHAR16_T*)lpWideCharStr) + 1; if (!lpMultiByteStr || cbMultiByte == 0) retval = minipal_get_length_utf16_to_utf8((CHAR16_T*)lpWideCharStr, cchWideChar, dwFlags); diff --git a/src/mono/mono/eglib/giconv.c b/src/mono/mono/eglib/giconv.c index 76743ed5c47c15..fe4d522326bb0f 100644 --- a/src/mono/mono/eglib/giconv.c +++ b/src/mono/mono/eglib/giconv.c @@ -304,11 +304,7 @@ g_utf16_to_utf8_impl (const gunichar2 *str, glong len, glong *items_read, glong flags |= MINIPAL_TREAT_AS_LITTLE_ENDIAN; #endif if (len < 0) { - len = 0; - while (str[len]) - len++; - - len++; + len = minipal_u16_strlen (str) + 1; } glong ret = (glong)minipal_get_length_utf16_to_utf8 (str, len, flags); @@ -349,11 +345,7 @@ g_utf16_to_utf8_custom_alloc (const gunichar2 *str, glong len, glong *items_read errno = 0; if (len < 0) { - len = 0; - while (str[len]) - len++; - - len++; + len = minipal_u16_strlen (str) + 1; } glong ret = (glong)minipal_get_length_utf16_to_utf8 (str, len, 0); @@ -391,9 +383,7 @@ g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *item g_return_val_if_fail (str != NULL, NULL); if (len < 0) { - len = 0; - while (str[len]) - len++; + len = minipal_u16_strlen (str); } inptr = (char *) str; From 4ab9fdf29bab5364556ebf7026f88b43b508b0de Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 15:20:26 -0700 Subject: [PATCH 07/28] Use minipal's random APIs instead of Mono having their own --- src/mono/CMakeLists.txt | 2 +- src/mono/mono/eventpipe/ep-rt-mono.c | 12 +- src/mono/mono/eventpipe/ep-rt-mono.h | 1 - src/mono/mono/mini/aot-compiler.c | 14 +- src/mono/mono/utils/CMakeLists.txt | 3 - src/mono/mono/utils/mono-rand-windows.c | 101 ------- src/mono/mono/utils/mono-rand.c | 380 ------------------------ src/mono/mono/utils/mono-rand.h | 32 -- 8 files changed, 6 insertions(+), 539 deletions(-) delete mode 100644 src/mono/mono/utils/mono-rand-windows.c delete mode 100644 src/mono/mono/utils/mono-rand.c delete mode 100644 src/mono/mono/utils/mono-rand.h diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 70f03a4a9f4dd8..80d82971843e4c 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -565,7 +565,7 @@ if(GCC) if(HOST_WASI) # When building under WASI SDK, it's stricter about discarding 'const' qualifiers, causing some existing - # code (e.g., mono-rand.c:315) to be rejected + # code to be rejected set(WERROR_C "${WERROR_C} -Wno-incompatible-pointer-types-discards-qualifiers") endif() diff --git a/src/mono/mono/eventpipe/ep-rt-mono.c b/src/mono/mono/eventpipe/ep-rt-mono.c index c75bb43007630c..b23ea3f5b5ea3b 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.c +++ b/src/mono/mono/eventpipe/ep-rt-mono.c @@ -10,10 +10,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -29,9 +29,6 @@ gboolean _ep_rt_mono_runtime_initialized; MonoNativeTlsKey _ep_rt_mono_thread_holder_tls_id; static MonoNativeTlsKey _thread_data_tls_id; -// Random byte provider. -static gpointer _rand_provider; - // EventPipe global config lock. ep_rt_spin_lock_handle_t _ep_rt_mono_config_lock = {0}; @@ -67,10 +64,7 @@ ep_rt_mono_rand_try_get_bytes ( uint8_t *buffer, size_t buffer_size) { - EP_ASSERT (_rand_provider != NULL); - - ERROR_DECL (error); - return mono_rand_try_get_bytes (&_rand_provider, (guchar *)buffer, (gssize)buffer_size, error); + return minipal_get_cryptographically_secure_random_bytes(buffer, buffer_size); } char * @@ -816,8 +810,6 @@ ep_rt_mono_init (void) mono_native_tls_alloc (&_thread_data_tls_id, NULL); mono_100ns_ticks (); - mono_rand_open (); - _rand_provider = mono_rand_init (NULL, 0); ep_rt_mono_runtime_provider_init (); ep_rt_mono_profiler_provider_init (); diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 418f3b8e1e93de..19238cc6bc8589 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index df45813a2e30d0..d8eb65c76c5b4c 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -58,11 +58,11 @@ #include #include #include -#include #include #include #include #include +#include #include "aot-compiler.h" #include "aot-runtime.h" @@ -11567,16 +11567,8 @@ emit_extra_methods (MonoAotCompile *acfg) static void generate_aotid (guint8* aotid) { - gpointer rand_handle; - ERROR_DECL (error); - - mono_rand_open (); - rand_handle = mono_rand_init (NULL, 0); - - mono_rand_try_get_bytes (&rand_handle, aotid, 16, error); - mono_error_assert_ok (error); - - mono_rand_close (rand_handle); + bool success = minipal_get_cryptographically_secure_random_bytes (aotid, 16); + g_assert (success); } static void diff --git a/src/mono/mono/utils/CMakeLists.txt b/src/mono/mono/utils/CMakeLists.txt index 2409e92ae5e8ee..ca7f65b7b81c13 100644 --- a/src/mono/mono/utils/CMakeLists.txt +++ b/src/mono/mono/utils/CMakeLists.txt @@ -155,9 +155,6 @@ set(utils_common_sources mono-conc-hashtable.c json.h json.c - mono-rand.c - mono-rand-windows.c - mono-rand.h memfuncs.c memfuncs.h parse.c diff --git a/src/mono/mono/utils/mono-rand-windows.c b/src/mono/mono/utils/mono-rand-windows.c deleted file mode 100644 index ff856bb61bf29b..00000000000000 --- a/src/mono/mono/utils/mono-rand-windows.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * \file - * Windows rand support for Mono. - * - * Copyright 2016 Microsoft - * Licensed under the MIT license. See LICENSE file in the project root for full license information. -*/ -#include -#include -#ifdef HOST_WIN32 -#include -#include "mono-error-internals.h" -#include "mono-rand.h" -#include -#include -#include - -// This implementation requires Windows 7 or newer. - -#define BCRYPT_USE_SYSTEM_PREFERRED_RNG 0x00000002 -const static char mono_rand_provider [ ] = "BCryptGenRandom"; - -/** - * mono_rand_open: - * - * Returns: True if random source is global, false if mono_rand_init can be called repeatedly to get randomness instances. - * - * Initializes entire RNG system. Must be called once per process before calling mono_rand_init. - */ -gboolean -mono_rand_open (void) -{ - return TRUE; -} - -/** - * mono_rand_init: - * \param seed A string containing seed data - * \param seed_size Length of seed string - * Initializes an RNG client. - * \returns On success, a non-NULL handle which can be used to fetch random data from \c mono_rand_try_get_bytes. On failure, NULL. - */ -gpointer -mono_rand_init (const guchar *seed, gssize seed_size) -{ - // NULL will be interpreted as failure; return arbitrary nonzero pointer - return (gpointer)mono_rand_provider; -} - -/** - * mono_rand_try_get_bytes: - * \param handle A pointer to an RNG handle. Handle is set to NULL on failure. - * \param buffer A buffer into which to write random data. - * \param buffer_size Number of bytes to write into buffer. - * \param error Set on error. - * Extracts bytes from an RNG handle. - * \returns FALSE on failure and sets \p error, TRUE on success. - */ -gboolean -mono_rand_try_get_bytes (gpointer *handle, guchar *buffer, gssize buffer_size, MonoError *error) -{ - g_assert (buffer || !buffer_size); - error_init (error); - g_assert (handle); - gpointer const handle_value = *handle; - g_assert (handle_value == 0 || handle_value == mono_rand_provider); - if (!handle_value) - return FALSE; - while (buffer_size > 0) { - ULONG const size = (ULONG)MIN (buffer_size, ULONG_MAX); - NTSTATUS const status = BCryptGenRandom (0, buffer, size, BCRYPT_USE_SYSTEM_PREFERRED_RNG); - if (!BCRYPT_SUCCESS (status)) { - mono_error_set_execution_engine (error, "Failed to gen random bytes (%ld)", status); - // failure, clear provider for future attempts - *handle = 0; - return FALSE; - } - buffer += size; - buffer_size -= size; - } - return TRUE; -} - -/** - * mono_rand_close: - * \param handle An RNG handle. - * Releases an RNG handle. - */ -void -mono_rand_close (gpointer handle) -{ - g_assert (handle == 0 || handle == mono_rand_provider); -} - -#else - -#include - -MONO_EMPTY_SOURCE_FILE (mono_rand_windows); - -#endif /* HOST_WIN32 */ diff --git a/src/mono/mono/utils/mono-rand.c b/src/mono/mono/utils/mono-rand.c deleted file mode 100644 index 0f64d3b9eacdbd..00000000000000 --- a/src/mono/mono/utils/mono-rand.c +++ /dev/null @@ -1,380 +0,0 @@ -/** - * \file - * - * Authors: - * Mark Crichton (crichton@gimp.org) - * Patrik Torstensson (p@rxc.se) - * Sebastien Pouliot (sebastien@ximian.com) - * Ludovic Henry (ludovic.henry@xamarin.com) - * - * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com) - * Copyright 2004-2009 Novell, Inc (http://www.novell.com) - * Copyright 2001 Xamarin, Inc (http://www.novell.com) - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ - -#include -#include - -#include "atomic.h" -#include -#include "mono-error-internals.h" -#include "mono-rand.h" -#include "mono-threads.h" -#include -#include - -#ifdef HOST_WIN32 -// Windows specific implementation in mono-rand-windows.c -#elif defined (HAVE_SYS_UN_H) - -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_SYS_RANDOM_H -#include -#endif - -#ifndef NAME_DEV_URANDOM -#define NAME_DEV_URANDOM "/dev/urandom" -#endif - -static gboolean use_egd = FALSE; -static gint file = -1; - -#ifdef HAVE_GETRANDOM -/* Fill buffer with buffer_size random bytes generated by getrandom(): - - Return 1 on success - - Return 0 if getrandom() is not available (failed with ENOSYS or EPERM) - - Return -1 on error - getrandom() is retried if it failed with EINTR: interrupted by a signal. */ -static gint -mono_getrandom (guchar *buffer, gssize buffer_size, gint flags, MonoError *error) -{ - g_assert (buffer || !buffer_size); - - static gboolean getrandom_fail; - - if (getrandom_fail) - return 0; - - /* Read until the buffer is filled. This may block if random pool isn't initialized. */ - while (buffer_size > 0) { - gssize const err = getrandom (buffer, buffer_size, flags); - if (err < 0) { - if (errno == EINTR) - continue; - if (errno == ENOSYS || errno == EPERM) { - getrandom_fail = TRUE; - return 0; - } - g_warning ("Entropy error! Error in getrandom (%s).", strerror (errno)); - /* exception will be thrown in managed code */ - mono_error_set_execution_engine (error, "Entropy error! Error in getrandom (%s).", strerror (errno)); - return -1; - } - buffer_size -= err; - buffer += err; - } - return 1; -} -#elif HAVE_GETENTROPY -/* Fill buffer with buffer_size random bytes generated by getentropy(): - - Return 1 on success - - Return 0 if getentropy() is not available (failed with ENOSYS or EPERM) - - Return -1 on error - getentropy() is retried if it failed with EINTR: interrupted by a signal. */ -static gint -mono_getentropy (guchar *buffer, gssize buffer_size, MonoError *error) -{ - g_assert (buffer || !buffer_size); - - static gboolean getentropy_fail; - - if (getentropy_fail) - return 0; - - /* Read until the buffer is filled. This may block if random pool isn't initialized. */ - while (buffer_size > 0) { - gssize const len = MIN (buffer_size, 256); - gint const err = getentropy (buffer, len); - if (err < 0) { - if (errno == EINTR) - continue; - if (errno == ENOSYS || errno == EPERM) { - getentropy_fail = TRUE; - return 0; - } - g_warning ("Entropy error! Error in getentropy (%s).", strerror (errno)); - /* exception will be thrown in managed code */ - mono_error_set_execution_engine (error, "Entropy error! Error in getentropy (%s).", strerror (errno)); - return -1; - } - buffer += len; - buffer_size -= len; - } - return 1; -} -#endif /* HAVE_GETENTROPY */ - -#if !defined(DISABLE_EGD_SOCKET) -static void -get_entropy_from_egd (const char *path, guchar *buffer, gssize buffer_size, MonoError *error) -{ - g_assert (buffer || !buffer_size); - - struct sockaddr_un egd_addr; - gint socket_fd; - gint ret; - guint offset = 0; - int err = 0; - - socket_fd = socket (PF_UNIX, SOCK_STREAM, 0); - if (socket_fd < 0) { - ret = -1; - err = errno; - } else { - egd_addr.sun_family = AF_UNIX; - memcpy (egd_addr.sun_path, path, sizeof (egd_addr.sun_path) - 1); - egd_addr.sun_path [sizeof (egd_addr.sun_path) - 1] = '\0'; - ret = connect (socket_fd, (struct sockaddr*) &egd_addr, sizeof (egd_addr)); - err = errno; - } - if (ret == -1) { - if (socket_fd >= 0) - close (socket_fd); - g_warning ("Entropy problem! Can't create or connect to egd socket %s", path); - mono_error_set_execution_engine (error, "Failed to open egd socket %s: %s", path, strerror (err)); - return; - } - - while (buffer_size > 0) { - guchar request [2]; - gint count = 0; - - /* block until daemon can return enough entropy */ - request [0] = 2; - request [1] = buffer_size < 255 ? (guchar)buffer_size : 255; - while (count < 2) { - int sent = write (socket_fd, request + count, 2 - count); - err = errno; - if (sent >= 0) { - count += sent; - } else if (err == EINTR) { - continue; - } else { - close (socket_fd); - g_warning ("Send egd request failed %d", err); - mono_error_set_execution_engine (error, "Failed to send request to egd socket: %s", strerror (err)); - return; - } - } - - count = 0; - while (count != request [1]) { - int received; - received = read (socket_fd, buffer + offset, request [1] - count); - err = errno; - if (received > 0) { - count += received; - offset += received; - } else if (received < 0 && err == EINTR) { - continue; - } else { - close (socket_fd); - g_warning ("Receive egd request failed %d", err); - mono_error_set_execution_engine (error, "Failed to get response from egd socket: %s", strerror(err)); - return; - } - } - - buffer_size -= request [1]; - } - - close (socket_fd); -} - -gboolean -mono_rand_open (void) -{ - static gint32 status; - if (status != 0 || mono_atomic_cas_i32 (&status, 1, 0) != 0) { - while (status != 2) - mono_thread_info_yield (); - return TRUE; - } - -#ifdef NAME_DEV_URANDOM - if (file < 0) - file = open (NAME_DEV_URANDOM, O_RDONLY); -#endif -#ifdef NAME_DEV_RANDOM - if (file < 0) - file = open (NAME_DEV_RANDOM, O_RDONLY); -#endif - if (file < 0) - use_egd = g_hasenv ("MONO_EGD_SOCKET"); - - status = 2; - - return TRUE; -} -#endif /* !DISABLE_EGD_SOCKET */ - -gpointer -mono_rand_init (const guchar *seed, gssize seed_size) -{ - // file < 0 is expected in the egd case - return (!use_egd && file < 0) ? (gpointer)NULL : GINT_TO_POINTER (file); -} - -gboolean -mono_rand_try_get_bytes (gpointer *handle, guchar *buffer, gssize buffer_size, MonoError *error) -{ - g_assert (buffer || !buffer_size); - g_assert (handle); - - error_init (error); - -#if defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY) -#ifdef HAVE_GETRANDOM - gint const res = mono_getrandom (buffer, buffer_size, 0, error); -#else - gint const res = mono_getentropy (buffer, buffer_size, error); -#endif - if (res < 0) - return FALSE; - - if (res == 1) - return TRUE; - -#elif !defined(DISABLE_EGD_SOCKET) - /* getrandom() or getentropy() function is not available: failed with - ENOSYS or EPERM. Fall back on reading from /dev/urandom. */ - - if (use_egd) { - char *socket_path = g_getenv ("MONO_EGD_SOCKET"); - /* exception will be thrown in managed code */ - if (socket_path == NULL) { - *handle = NULL; - return FALSE; - } - get_entropy_from_egd (socket_path, buffer, buffer_size, error); - g_free (socket_path); - return TRUE; - } -#endif - /* Read until the buffer is filled. This may block if using NAME_DEV_RANDOM. */ - while (buffer_size > 0) { - gssize const err = read (file, buffer, buffer_size); - if (err < 0) { - if (errno == EINTR) - continue; - g_warning("Entropy error! Error in read (%s).", strerror (errno)); - /* exception will be thrown in managed code */ - mono_error_set_execution_engine (error, "Entropy error! Error in read (%s).", strerror (errno)); - return FALSE; - } - buffer += err; - buffer_size -= err; - } - return TRUE; -} - -void -mono_rand_close (gpointer provider) -{ -} - -#else - -#include -#include - -gboolean -mono_rand_open (void) -{ - static gint32 status; - if (status != 0 || mono_atomic_cas_i32 (&status, 1, 0) != 0) { - while (status != 2) - mono_thread_info_yield (); - return TRUE; - } - - srand (time (NULL)); - - status = 2; - - return TRUE; -} - -gpointer -mono_rand_init (const guchar *seed, gssize seed_size) -{ - return "srand"; // NULL will be interpreted as failure; return arbitrary nonzero pointer -} - -gboolean -mono_rand_try_get_bytes (gpointer *handle, guchar *buffer, gssize buffer_size, MonoError *error) -{ - // This functions is not used on any mainstream platform, perhaps not at all. - - g_assert (buffer || !buffer_size); - - error_init (error); - - g_static_assert (RAND_MAX >= 0xFF); - - while (buffer_size > 0) { - int const i = rand (); - int j; - if (buffer_size >= (j = 4) && RAND_MAX >= 0xFFFFFFFF) - *(gint32*) buffer = i; - else if (buffer_size >= (j = 2) && RAND_MAX >= 0xFFFF) - *(gint16*) buffer = i; - else { - j = 1; - *(gint8*) buffer = i; - } - buffer += j; - buffer_size -= j; - } - - return TRUE; -} - -void -mono_rand_close (gpointer provider) -{ -} - -#endif - -/** - * mono_rand_try_get_uint32: - * \param handle A pointer to an RNG handle. Handle is set to NULL on failure. - * \param val A pointer to a 32-bit unsigned int, to which the result will be written. - * \param min Result will be greater than or equal to this value. - * \param max Result will be less than or equal to this value. - * Extracts one 32-bit unsigned int from an RNG handle. - * \returns FALSE on failure, TRUE on success. - */ -gboolean -mono_rand_try_get_uint32 (gpointer *handle, guint32 *val, guint32 min, guint32 max, MonoError *error) -{ - g_assert (val); - if (!mono_rand_try_get_bytes (handle, (guchar*) val, sizeof (guint32), error)) - return FALSE; - - double randomDouble = ((gdouble) *val) / ( ((double)G_MAXUINT32) + 1 ); // Range is [0,1) - *val = (guint32) (randomDouble * (max - min + 1) + min); - - g_assert (*val >= min); - g_assert (*val <= max); - - return TRUE; -} diff --git a/src/mono/mono/utils/mono-rand.h b/src/mono/mono/utils/mono-rand.h deleted file mode 100644 index ea1ff7f9d6762a..00000000000000 --- a/src/mono/mono/utils/mono-rand.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * \file - */ - -#ifndef _MONO_UTILS_RAND_H_ -#define _MONO_UTILS_RAND_H_ - -#include - -#include "mono-compiler.h" -#include - -MONO_COMPONENT_API -gboolean -mono_rand_open (void); - -MONO_COMPONENT_API -gpointer -mono_rand_init (const guchar *seed, gssize seed_size); - -MONO_COMPONENT_API -gboolean -mono_rand_try_get_bytes (gpointer *handle, guchar *buffer, gssize buffer_size, MonoError *error); - -gboolean -mono_rand_try_get_uint32 (gpointer *handle, guint32 *val, guint32 min, guint32 max, MonoError *error); - -MONO_COMPONENT_API -void -mono_rand_close (gpointer handle); - -#endif /* _MONO_UTILS_RAND_H_ */ From d44224df400a58db5f92c3608f801b8194a7d17b Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 15:28:55 -0700 Subject: [PATCH 08/28] fixup! Use minipal_u16_strlen in more places. --- src/coreclr/debug/createdump/createdump.h | 1 + src/coreclr/debug/createdump/datatarget.cpp | 2 +- src/coreclr/pal/src/locale/unicode.cpp | 1 + src/mono/mono/eglib/giconv.c | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/coreclr/debug/createdump/createdump.h b/src/coreclr/debug/createdump/createdump.h index 804575c10fed74..551e3da4c9984b 100644 --- a/src/coreclr/debug/createdump/createdump.h +++ b/src/coreclr/debug/createdump/createdump.h @@ -51,6 +51,7 @@ typedef int T_CONTEXT; #include #include #ifdef HOST_UNIX +#include #include #include #include diff --git a/src/coreclr/debug/createdump/datatarget.cpp b/src/coreclr/debug/createdump/datatarget.cpp index 243d8458bda538..7867967e23777e 100644 --- a/src/coreclr/debug/createdump/datatarget.cpp +++ b/src/coreclr/debug/createdump/datatarget.cpp @@ -102,7 +102,7 @@ DumpDataTarget::GetImageBase( *baseAddress = 0; char tempModuleName[MAX_PATH]; - size_t cch = u16_strlen(moduleName) + 1; + size_t cch = minipal_u16_strlen((CHAR16_T*)moduleName) + 1; int length = minipal_convert_utf16_to_utf8((CHAR16_T*)moduleName, cch, tempModuleName, sizeof(tempModuleName), 0); if (length > 0) { diff --git a/src/coreclr/pal/src/locale/unicode.cpp b/src/coreclr/pal/src/locale/unicode.cpp index 2c6cf3e55bba97..a14b414c323484 100644 --- a/src/coreclr/pal/src/locale/unicode.cpp +++ b/src/coreclr/pal/src/locale/unicode.cpp @@ -14,6 +14,7 @@ Implementation of all functions related to Unicode support #include "pal/palinternal.h" #include "pal/dbgmsg.h" #include "pal/file.h" +#include #include #include "pal/cruntime.h" #include "pal/stackstring.hpp" diff --git a/src/mono/mono/eglib/giconv.c b/src/mono/mono/eglib/giconv.c index fe4d522326bb0f..95cf6ac3505dd4 100644 --- a/src/mono/mono/eglib/giconv.c +++ b/src/mono/mono/eglib/giconv.c @@ -29,6 +29,7 @@ #include "../utils/mono-errno.h" #include +#include #ifdef _MSC_VER #define FORCE_INLINE(RET_TYPE) __forceinline RET_TYPE From 2b4779be9c758f5c22d8d9c660ae7c42c4a4a4da Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 15:38:14 -0700 Subject: [PATCH 09/28] Remove 'random' usage in eventpipe and unify all usages of the minipal guid API instead of having three separate implementation of the exact same function body --- .../nativeaot/Runtime/eventpipe/ep-rt-aot.cpp | 40 ------------------- .../nativeaot/Runtime/eventpipe/ep-rt-aot.h | 11 ----- .../nativeaot/Runtime/eventpipeinternal.cpp | 4 +- .../vm/eventing/eventpipe/ep-rt-coreclr.h | 14 ------- src/mono/mono/eventpipe/ep-rt-mono.c | 9 ----- src/mono/mono/eventpipe/ep-rt-mono.h | 37 ----------------- src/native/eventpipe/ds-protocol.c | 2 +- src/native/eventpipe/ep-rt.h | 6 --- src/native/eventpipe/ep-thread.h | 5 ++- src/native/eventpipe/ep-types.h | 1 + 10 files changed, 8 insertions(+), 121 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp index f7ca6d565b4edd..9b2bb852239647 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp @@ -783,46 +783,6 @@ void ep_rt_aot_os_environment_get_utf16 (dn_vector_ptr_t *env_array) #endif } -void ep_rt_aot_create_activity_id (uint8_t *activity_id, uint32_t activity_id_len) -{ - // We call CoCreateGuid for windows, and use a random generator for non-windows - STATIC_CONTRACT_NOTHROW; - EP_ASSERT (activity_id != NULL); - EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE); -#ifdef HOST_WIN32 - CoCreateGuid (reinterpret_cast(activity_id)); -#else - if(minipal_get_cryptographically_secure_random_bytes(activity_id, activity_id_len)==-1) - { - *activity_id=0; - return; - } - - const uint16_t version_mask = 0xF000; - const uint16_t random_guid_version = 0x4000; - const uint8_t clock_seq_hi_and_reserved_mask = 0xC0; - const uint8_t clock_seq_hi_and_reserved_value = 0x80; - - // Modify bits indicating the type of the GUID - uint8_t *activity_id_c = activity_id + sizeof (uint32_t) + sizeof (uint16_t); - uint8_t *activity_id_d = activity_id + sizeof (uint32_t) + sizeof (uint16_t) + sizeof (uint16_t); - - uint16_t c; - memcpy (&c, activity_id_c, sizeof (c)); - - uint8_t d; - memcpy (&d, activity_id_d, sizeof (d)); - - // time_hi_and_version - c = ((c & ~version_mask) | random_guid_version); - // clock_seq_hi_and_reserved - d = ((d & ~clock_seq_hi_and_reserved_mask) | clock_seq_hi_and_reserved_value); - - memcpy (activity_id_c, &c, sizeof (c)); - memcpy (activity_id_d, &d, sizeof (d)); -#endif -} - ep_rt_thread_handle_t ep_rt_aot_thread_get_handle (void) { return ThreadStore::GetCurrentThreadIfAvailable(); diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h index 0513409886ebb2..9c0a120531003a 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h @@ -660,17 +660,6 @@ ep_rt_process_shutdown (void) return false; } -static -inline -void -ep_rt_create_activity_id ( - uint8_t *activity_id, - uint32_t activity_id_len) -{ - extern void ep_rt_aot_create_activity_id (uint8_t *activity_id, uint32_t activity_id_len); - ep_rt_aot_create_activity_id(activity_id, activity_id_len); -} - static inline bool diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index 3febb68b73e785..b08e99e59ea96c 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -198,7 +198,7 @@ EXTERN_C int QCALLTYPE EventPipeInternal_EventActivityIdControl(uint32_t control case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_ID: - ep_rt_create_activity_id(reinterpret_cast(pActivityId), EP_ACTIVITY_ID_SIZE); + ep_thread_create_activity_id(reinterpret_cast(pActivityId), EP_ACTIVITY_ID_SIZE); break; case ActivityControlCode::EVENT_ACTIVITY_CONTROL_GET_SET_ID: @@ -212,7 +212,7 @@ EXTERN_C int QCALLTYPE EventPipeInternal_EventActivityIdControl(uint32_t control case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_SET_ID: ep_rt_thread_get_activity_id (activityIdHandle, reinterpret_cast(pActivityId), EP_ACTIVITY_ID_SIZE); - ep_rt_create_activity_id(reinterpret_cast(¤tActivityId), EP_ACTIVITY_ID_SIZE); + ep_thread_create_activity_id(reinterpret_cast(¤tActivityId), EP_ACTIVITY_ID_SIZE); ep_rt_thread_set_activity_id (activityIdHandle, reinterpret_cast(¤tActivityId), EP_ACTIVITY_ID_SIZE); break; diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 767e23adfd0d7c..4efbb9f8964b28 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -738,20 +738,6 @@ ep_rt_process_shutdown (void) return (bool)g_fEEShutDown; } -static -inline -void -ep_rt_create_activity_id ( - uint8_t *activity_id, - uint32_t activity_id_len) -{ - STATIC_CONTRACT_NOTHROW; - EP_ASSERT (activity_id != NULL); - EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE); - - minipal_guid_v4_create (reinterpret_cast(activity_id)); -} - static inline bool diff --git a/src/mono/mono/eventpipe/ep-rt-mono.c b/src/mono/mono/eventpipe/ep-rt-mono.c index b23ea3f5b5ea3b..f07f5c6d263411 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.c +++ b/src/mono/mono/eventpipe/ep-rt-mono.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -59,14 +58,6 @@ EVENTPIPE_TRACE_CONTEXT MICROSOFT_DOTNETRUNTIME_MONO_PROFILER_PROVIDER_DOTNET_Co void ep_rt_mono_thread_exited (void); -bool -ep_rt_mono_rand_try_get_bytes ( - uint8_t *buffer, - size_t buffer_size) -{ - return minipal_get_cryptographically_secure_random_bytes(buffer, buffer_size); -} - char * ep_rt_mono_get_managed_cmd_line (void) { diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 19238cc6bc8589..94ca5bb94f7e59 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -69,7 +69,6 @@ extern void ep_rt_mono_provider_config_init (EventPipeProviderConfiguration *pro extern void ep_rt_mono_init_providers_and_events (void); extern bool ep_rt_mono_providers_validate_all_disabled (void); extern bool ep_rt_mono_sample_profiler_write_sampling_event_for_threads (ep_rt_thread_handle_t sampling_thread, EventPipeEvent *sampling_event); -extern bool ep_rt_mono_rand_try_get_bytes (uint8_t *buffer,size_t buffer_size); extern void ep_rt_mono_execute_rundown (dn_vector_ptr_t *execution_checkpoints); extern int64_t ep_rt_mono_perf_counter_query (void); extern int64_t ep_rt_mono_perf_frequency_query (void); @@ -772,42 +771,6 @@ ep_rt_process_shutdown (void) return ep_rt_process_detach (); } -static -inline -void -ep_rt_create_activity_id ( - uint8_t *activity_id, - uint32_t activity_id_len) -{ - EP_ASSERT (activity_id != NULL); - EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE); - - ep_rt_mono_rand_try_get_bytes ((guchar *)activity_id, EP_ACTIVITY_ID_SIZE); - - const uint16_t version_mask = 0xF000; - const uint16_t random_guid_version = 0x4000; - const uint8_t clock_seq_hi_and_reserved_mask = 0xC0; - const uint8_t clock_seq_hi_and_reserved_value = 0x80; - - // Modify bits indicating the type of the GUID - uint8_t *activity_id_c = activity_id + sizeof (uint32_t) + sizeof (uint16_t); - uint8_t *activity_id_d = activity_id + sizeof (uint32_t) + sizeof (uint16_t) + sizeof (uint16_t); - - uint16_t c; - memcpy (&c, activity_id_c, sizeof (c)); - - uint8_t d; - memcpy (&d, activity_id_d, sizeof (d)); - - // time_hi_and_version - c = ((c & ~version_mask) | random_guid_version); - // clock_seq_hi_and_reserved - d = ((d & ~clock_seq_hi_and_reserved_mask) | clock_seq_hi_and_reserved_value); - - memcpy (activity_id_c, &c, sizeof (c)); - memcpy (activity_id_d, &d, sizeof (d)); -} - static inline bool diff --git a/src/native/eventpipe/ds-protocol.c b/src/native/eventpipe/ds-protocol.c index 8232d7d9b9db37..d1cbee0ac35782 100644 --- a/src/native/eventpipe/ds-protocol.c +++ b/src/native/eventpipe/ds-protocol.c @@ -80,7 +80,7 @@ ds_ipc_advertise_cookie_v1_get (void) void ds_ipc_advertise_cookie_v1_init (void) { - ep_rt_create_activity_id ((uint8_t *)&_ds_ipc_advertise_cooike_v1, EP_GUID_SIZE); + ep_thread_create_activity_id ((uint8_t *)&_ds_ipc_advertise_cooike_v1, EP_GUID_SIZE); } /** diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index 2f1aef5047aabe..060bb71503befc 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -270,12 +270,6 @@ static bool ep_rt_process_shutdown (void); -static -void -ep_rt_create_activity_id ( - uint8_t *activity_id, - uint32_t activity_id_len); - static bool ep_rt_is_running (void); diff --git a/src/native/eventpipe/ep-thread.h b/src/native/eventpipe/ep-thread.h index 44c683b52d57f8..8a60db2e12ffc6 100644 --- a/src/native/eventpipe/ep-thread.h +++ b/src/native/eventpipe/ep-thread.h @@ -114,7 +114,10 @@ ep_thread_create_activity_id ( uint8_t *activity_id, uint32_t activity_id_len) { - ep_rt_create_activity_id (activity_id, activity_id_len); + EP_ASSERT (activity_id != NULL); + EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE); + + minipal_guid_v4_create (reinterpret_cast(activity_id)); } static diff --git a/src/native/eventpipe/ep-types.h b/src/native/eventpipe/ep-types.h index 79b05ea8bc6718..7a16bc77a3466f 100644 --- a/src/native/eventpipe/ep-types.h +++ b/src/native/eventpipe/ep-types.h @@ -19,6 +19,7 @@ #include #include #include +#include /* * EventFilterDescriptor. From 40077d524747d92b3cd9ec358491633110a1e8e3 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 15:42:41 -0700 Subject: [PATCH 10/28] PR feedback --- src/coreclr/dlls/mscorpe/pewriter.cpp | 4 ++-- src/coreclr/md/compiler/regmeta.cpp | 2 +- src/coreclr/md/enc/metamodelrw.cpp | 2 +- src/coreclr/vm/eventpipeinternal.cpp | 2 +- src/native/minipal/guid.h | 7 +++++++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/coreclr/dlls/mscorpe/pewriter.cpp b/src/coreclr/dlls/mscorpe/pewriter.cpp index 5de2dd6685dc3a..0e5c3526d78137 100644 --- a/src/coreclr/dlls/mscorpe/pewriter.cpp +++ b/src/coreclr/dlls/mscorpe/pewriter.cpp @@ -1593,7 +1593,7 @@ HRESULT PEWriter::write(void ** ppImage) size_t lSize = filePos; // allocate the block we are handing back to the caller - void * pImage = (void *) ::minipal_co_task_mem_alloc(lSize); + void * pImage = (void *) minipal_co_task_mem_alloc(lSize); if (NULL == pImage) { return E_OUTOFMEMORY; @@ -1626,7 +1626,7 @@ HRESULT PEWriter::write(void ** ppImage) // make sure we wrote the exact numbmer of bytes expected _ASSERTE(lSize == (size_t) (pCur - (char *)pImage)); - // give pointer to memory image back to caller (who must free with ::minipal_co_task_mem_free()) + // give pointer to memory image back to caller (who must free with minipal_co_task_mem_free()) *ppImage = pImage; // all done diff --git a/src/coreclr/md/compiler/regmeta.cpp b/src/coreclr/md/compiler/regmeta.cpp index eee9a527f04c84..7022832ae99e4b 100644 --- a/src/coreclr/md/compiler/regmeta.cpp +++ b/src/coreclr/md/compiler/regmeta.cpp @@ -247,7 +247,7 @@ RegMeta::CreateNewMD() ModuleRec *pModule; GUID mvid; IfFailGo(m_pStgdb->m_MiniMd.AddModuleRecord(&pModule, &iRecord)); - IfFailGo(minipal_guid_v4_create(reinterpret_cast(&mvid)) ? S_OK : E_FAIL); + IfFailGo(minipal_guid_v4_create(&mvid) ? S_OK : E_FAIL); IfFailGo(m_pStgdb->m_MiniMd.PutGuid(TBL_Module, ModuleRec::COL_Mvid, pModule, mvid)); // Add the dummy module typedef which we are using to parent global items. diff --git a/src/coreclr/md/enc/metamodelrw.cpp b/src/coreclr/md/enc/metamodelrw.cpp index 50f5c95a0dcd29..45b75bb09ba126 100644 --- a/src/coreclr/md/enc/metamodelrw.cpp +++ b/src/coreclr/md/enc/metamodelrw.cpp @@ -1197,7 +1197,7 @@ CMiniMdRW::SetOption( PutCol(TBL_Module, ModuleRec::COL_EncBaseId, pMod, uVal); */ // Allocate a new GUID for EncId. - IfFailGo(minipal_guid_v4_create(reinterpret_cast(&encid)) ? S_OK : E_FAIL); + IfFailGo(minipal_guid_v4_create(&encid) ? S_OK : E_FAIL); IfFailGo(PutGuid(TBL_Module, ModuleRec::COL_EncId, pMod, encid)); #else //!FEATURE_METADATA_EMIT IfFailGo(E_INVALIDARG); diff --git a/src/coreclr/vm/eventpipeinternal.cpp b/src/coreclr/vm/eventpipeinternal.cpp index be22b72be47a39..0c89c706b30511 100644 --- a/src/coreclr/vm/eventpipeinternal.cpp +++ b/src/coreclr/vm/eventpipeinternal.cpp @@ -205,7 +205,7 @@ extern "C" int QCALLTYPE EventPipeInternal_EventActivityIdControl(uint32_t contr case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_SET_ID: *pActivityId = *pThread->GetActivityId(); - minipal_guid_v4_create(reinterpret_cast(¤tActivityId)); + minipal_guid_v4_create(¤tActivityId); pThread->SetActivityId(¤tActivityId); break; diff --git a/src/native/minipal/guid.h b/src/native/minipal/guid.h index 77692aef9ff309..ef7dcaaadca7b4 100644 --- a/src/native/minipal/guid.h +++ b/src/native/minipal/guid.h @@ -38,6 +38,13 @@ inline bool operator!=(minipal_guid_t const& a, minipal_guid_t const& b) { return !(a == b); } + +template +bool minipal_guid_v4_create(T* guid) +{ + static_assert(sizeof(T) == sizeof(minipal_guid_t), "minipal_guid_t size mismatch"); + return minipal_guid_v4_create(reinterpret_cast(guid)); +} #endif #endif // MINIPAL_GUID_H From 9408aa68d857b0aa538cc28594085851d85120a1 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 15:43:19 -0700 Subject: [PATCH 11/28] Link minipal to bcrypt and flow it so superpmi picks it up --- src/native/minipal/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/native/minipal/CMakeLists.txt b/src/native/minipal/CMakeLists.txt index 9af402eb34e46f..957b05e81dd628 100644 --- a/src/native/minipal/CMakeLists.txt +++ b/src/native/minipal/CMakeLists.txt @@ -17,12 +17,20 @@ include_directories(${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) add_library(minipal_objects OBJECT ${SOURCES}) +if (WIN32) + target_link_libraries(minipal_objects PUBLIC bcrypt) +endif() + # Add a copy of the minipal object library with interprocedural optimization disabled # for NativeAOT scenarios, where we ship static libraries that need to be able to be run with # a variety of toolchain versions, not only the exact one we built with. add_library(minipal_objects_no_lto OBJECT ${SOURCES}) set_target_properties(minipal_objects_no_lto PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) +if (WIN32) + target_link_libraries(minipal_objects_no_lto PUBLIC bcrypt) +endif() + # Provide a static library for our shared library and executable scenarios # for easier usability. add_library(minipal STATIC) From aae4c867b25343c3adc07f12645d548aa2873945 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 15:47:59 -0700 Subject: [PATCH 12/28] Make the co-task-mem-alloc PAL just call malloc --- src/native/minipal/memory.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/native/minipal/memory.c b/src/native/minipal/memory.c index 5e147de558f8b0..d72c7ed0f6ddcd 100644 --- a/src/native/minipal/memory.c +++ b/src/native/minipal/memory.c @@ -16,21 +16,9 @@ void minipal_co_task_mem_free(void* pv) CoTaskMemFree(pv); } #else -// CoTaskMemAlloc always aligns on an 8-byte boundary. -#define ALIGN 8 - void* minipal_co_task_mem_alloc(size_t cb) { - // Ensure malloc always allocates. - if (cb == 0) - cb = ALIGN; - - // Align the allocation size. - size_t cb_safe = (cb + (ALIGN - 1)) & ~(ALIGN - 1); - if (cb_safe < cb) // Overflow - return NULL; - - return aligned_alloc(ALIGN, cb_safe); + return malloc(cb); } void minipal_co_task_mem_free(void* pv) From 9ccdb609dcc4395dd2134c5862d1501bd3e36238 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 16:10:24 -0700 Subject: [PATCH 13/28] We're in C --- src/native/eventpipe/ep-thread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/eventpipe/ep-thread.h b/src/native/eventpipe/ep-thread.h index 8a60db2e12ffc6..a4e6e3b73e4222 100644 --- a/src/native/eventpipe/ep-thread.h +++ b/src/native/eventpipe/ep-thread.h @@ -117,7 +117,7 @@ ep_thread_create_activity_id ( EP_ASSERT (activity_id != NULL); EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE); - minipal_guid_v4_create (reinterpret_cast(activity_id)); + minipal_guid_v4_create ((minipal_guid_t *)(activity_id)); } static From 676c988e36fa00a2ff95cb5408d6ae853230ddf4 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 16:31:45 -0700 Subject: [PATCH 14/28] Add casts for Windows --- src/mono/mono/eglib/giconv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/eglib/giconv.c b/src/mono/mono/eglib/giconv.c index 95cf6ac3505dd4..144d38a5de4c23 100644 --- a/src/mono/mono/eglib/giconv.c +++ b/src/mono/mono/eglib/giconv.c @@ -305,7 +305,7 @@ g_utf16_to_utf8_impl (const gunichar2 *str, glong len, glong *items_read, glong flags |= MINIPAL_TREAT_AS_LITTLE_ENDIAN; #endif if (len < 0) { - len = minipal_u16_strlen (str) + 1; + len = (glong)minipal_u16_strlen (str) + 1; } glong ret = (glong)minipal_get_length_utf16_to_utf8 (str, len, flags); @@ -346,7 +346,7 @@ g_utf16_to_utf8_custom_alloc (const gunichar2 *str, glong len, glong *items_read errno = 0; if (len < 0) { - len = minipal_u16_strlen (str) + 1; + len = (glong)minipal_u16_strlen (str) + 1; } glong ret = (glong)minipal_get_length_utf16_to_utf8 (str, len, 0); @@ -384,7 +384,7 @@ g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *item g_return_val_if_fail (str != NULL, NULL); if (len < 0) { - len = minipal_u16_strlen (str); + len = (glong)minipal_u16_strlen (str); } inptr = (char *) str; From 1be8d8adbc2627b96f9bd0d7303f86b5d0b88797 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 17 Oct 2024 17:49:06 -0700 Subject: [PATCH 15/28] Fix assert --- src/mono/mono/mini/aot-compiler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index d8eb65c76c5b4c..51889fa514b9b3 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -11567,8 +11567,8 @@ emit_extra_methods (MonoAotCompile *acfg) static void generate_aotid (guint8* aotid) { - bool success = minipal_get_cryptographically_secure_random_bytes (aotid, 16); - g_assert (success); + int status = minipal_get_cryptographically_secure_random_bytes (aotid, 16); + g_assert (status == 0); } static void From 4f39154c061545a1d1791d3a05fc90f4aa1c7b88 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 21 Oct 2024 21:06:38 +0000 Subject: [PATCH 16/28] Remove u16_strlen from the CoreCLR minipal --- src/coreclr/debug/daccess/daccess.cpp | 16 +++++----- src/coreclr/debug/daccess/enummem.cpp | 4 +-- src/coreclr/debug/daccess/inspect.cpp | 2 +- src/coreclr/debug/daccess/request.cpp | 6 ++-- src/coreclr/debug/daccess/task.cpp | 4 +-- src/coreclr/debug/dbgutil/dbgutil.cpp | 2 +- src/coreclr/debug/di/process.cpp | 2 +- src/coreclr/debug/di/publish.cpp | 6 ++-- src/coreclr/debug/di/rsmda.cpp | 2 +- src/coreclr/debug/di/rsthread.cpp | 2 +- src/coreclr/debug/di/symbolinfo.cpp | 4 +-- src/coreclr/debug/inc/dbgappdomain.h | 2 +- src/coreclr/debug/inc/dbgipcevents.h | 2 +- src/coreclr/debug/inc/ddmarshalutil.h | 4 +-- src/coreclr/debug/shared/stringcopyholder.cpp | 2 +- src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp | 4 +-- src/coreclr/ilasm/asmman.cpp | 8 ++--- src/coreclr/ilasm/assem.cpp | 2 +- src/coreclr/ilasm/main.cpp | 30 +++++++++---------- src/coreclr/ilasm/writer.cpp | 4 +-- src/coreclr/ildasm/dasm.cpp | 8 ++--- src/coreclr/ildasm/dis.cpp | 2 +- src/coreclr/ildasm/dman.cpp | 18 +++++------ src/coreclr/ildasm/dres.cpp | 12 ++++---- src/coreclr/inc/daccess.h | 4 +-- src/coreclr/inc/eventtracebase.h | 4 +-- src/coreclr/inc/outstring.h | 2 +- src/coreclr/inc/sstring.inl | 2 +- src/coreclr/inc/utilcode.h | 7 +++-- src/coreclr/jit/disasm.cpp | 2 +- .../md/ceefilegen/ceesectionstring.cpp | 2 +- src/coreclr/md/compiler/assemblymd.cpp | 2 +- src/coreclr/md/compiler/mdutil.cpp | 2 +- src/coreclr/md/compiler/regmeta.h | 2 +- src/coreclr/md/compiler/regmeta_import.cpp | 4 +-- src/coreclr/md/enc/liteweightstgdbrw.cpp | 2 +- src/coreclr/md/enc/rwutil.cpp | 2 +- src/coreclr/md/inc/rwutil.h | 2 +- src/coreclr/minipal/Unix/dn-u16.cpp | 11 ++----- src/coreclr/minipal/Windows/dn-u16.cpp | 5 ---- src/coreclr/minipal/dn-u16.h | 3 +- src/coreclr/scripts/genEventPipe.py | 2 +- src/coreclr/tools/metainfo/mdobj.cpp | 2 +- src/coreclr/tools/superpmi/mcs/verbmerge.cpp | 8 ++--- .../superpmi-shared/methodcontext.cpp | 12 ++++---- .../superpmi/superpmi-shared/spmiutil.cpp | 6 ++-- .../superpmi-shim-collector.cpp | 2 +- .../superpmi-shim-counter.cpp | 2 +- .../superpmi-shim-simple.cpp | 2 +- .../tools/superpmi/superpmi/commandline.cpp | 4 +-- .../tools/superpmi/superpmi/jitdebugger.cpp | 4 +-- .../tools/superpmi/superpmi/jithost.cpp | 4 +-- .../tools/superpmi/superpmi/jitinstance.cpp | 2 +- .../superpmi/superpmi/streamingsuperpmi.cpp | 4 +-- src/coreclr/utilcode/ccomprc.cpp | 2 +- src/coreclr/utilcode/clrconfig.cpp | 4 +-- src/coreclr/utilcode/guidfromname.cpp | 2 +- src/coreclr/utilcode/log.cpp | 6 ++-- src/coreclr/utilcode/longfilepathwrappers.cpp | 6 ++-- src/coreclr/utilcode/namespaceutil.cpp | 6 ++-- src/coreclr/utilcode/pedecoder.cpp | 2 +- src/coreclr/utilcode/posterror.cpp | 2 +- src/coreclr/utilcode/prettyprintsig.cpp | 2 +- src/coreclr/utilcode/splitpath.cpp | 2 +- src/coreclr/utilcode/sstring.cpp | 2 +- src/coreclr/utilcode/sstring_com.cpp | 2 +- src/coreclr/utilcode/stresslog.cpp | 4 +-- src/coreclr/utilcode/util.cpp | 4 +-- src/coreclr/utilcode/util_nodependencies.cpp | 2 +- src/coreclr/utilcode/winfix.cpp | 2 +- src/coreclr/vm/appdomain.cpp | 2 +- src/coreclr/vm/assembly.cpp | 4 +-- src/coreclr/vm/autotrace.cpp | 2 +- src/coreclr/vm/ceeload.cpp | 8 ++--- src/coreclr/vm/commtmemberinfomap.cpp | 16 +++++----- src/coreclr/vm/corhost.cpp | 2 +- src/coreclr/vm/debugdebugger.cpp | 4 +-- src/coreclr/vm/dispatchinfo.cpp | 2 +- src/coreclr/vm/dwbucketmanager.hpp | 6 ++-- src/coreclr/vm/eehash.cpp | 2 +- .../vm/eventing/eventpipe/ep-rt-coreclr.h | 2 +- src/coreclr/vm/eventtrace.cpp | 2 +- src/coreclr/vm/gdbjit.cpp | 6 ++-- src/coreclr/vm/genanalysis.cpp | 2 +- src/coreclr/vm/ilmarshalers.cpp | 4 +-- src/coreclr/vm/interoputil.cpp | 6 ++-- src/coreclr/vm/methodtable.cpp | 2 +- src/coreclr/vm/multicorejit.cpp | 2 +- src/coreclr/vm/object.cpp | 2 +- src/coreclr/vm/peimage.inl | 2 +- src/coreclr/vm/profilinghelper.cpp | 2 +- src/coreclr/vm/proftoeeinterfaceimpl.cpp | 8 ++--- src/native/minipal/strings.c | 8 +++++ 93 files changed, 202 insertions(+), 204 deletions(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 81258d9d667ac9..0c31206eac92c8 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -264,7 +264,7 @@ SplitFullName(_In_z_ PCWSTR fullName, else { *params = NULL; - memberEnd = fullName + (u16_strlen(fullName) - 1); + memberEnd = fullName + (minipal_u16_strlen((const CHAR16_T*)fullName) - 1); } if (syntax != SPLIT_TYPE) @@ -5680,7 +5680,7 @@ static int FormatCLRStubName( // Compute the address as a string safely. WCHAR addrString[Max64BitHexString + 1]; FormatInteger(addrString, ARRAY_SIZE(addrString), "%p", stubAddr); - size_t addStringLen = u16_strlen(addrString); + size_t addStringLen = minipal_u16_strlen((const CHAR16_T*)addrString); // Compute maximum length, include the null terminator. size_t formatName_MaxLen = ARRAY_SIZE(formatName_Prefix) // Include trailing null @@ -5691,7 +5691,7 @@ static int FormatCLRStubName( size_t stubManagedNameLen = 0; if (stubNameMaybe != NULL) { - stubManagedNameLen = u16_strlen(stubNameMaybe); + stubManagedNameLen = minipal_u16_strlen((const CHAR16_T*)stubNameMaybe); formatName_MaxLen += ARRAY_SIZE(formatName_OpenBracket) - 1; formatName_MaxLen += ARRAY_SIZE(formatName_CloseBracket) - 1; } @@ -6458,7 +6458,7 @@ ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEAssembly *pPEAssembly, // It is possible that the module is in-memory. That is the wszFilePath here is empty. // We will try to use the module name instead in this case for hosting debugger // to find match. - if (u16_strlen(wszFilePath) == 0) + if (minipal_u16_strlen((const CHAR16_T*)wszFilePath) == 0) { mdImage->GetModuleFileNameHintForDAC().DacGetUnicode(cchFilePath, wszFilePath, &uniPathChars); if (uniPathChars > cchFilePath) @@ -7259,9 +7259,9 @@ STDAPI OutOfProcessExceptionEventCallback(_In_ PDWORD pContext, return hr; } - if ((pwszEventName == NULL) || (*pchSize <= u16_strlen(gmb.wzEventTypeName))) + if ((pwszEventName == NULL) || (*pchSize <= minipal_u16_strlen((const CHAR16_T*)gmb.wzEventTypeName))) { - *pchSize = static_cast(u16_strlen(gmb.wzEventTypeName)) + 1; + *pchSize = static_cast(minipal_u16_strlen((const CHAR16_T*)gmb.wzEventTypeName)) + 1; return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } @@ -7383,9 +7383,9 @@ STDAPI OutOfProcessExceptionEventSignatureCallback(_In_ PDWORD pContext, // Return pwszName as an emptry string to let WER use localized version of "Parameter n" *pwszName = W('\0'); - if ((pwszValue == NULL) || (*pchValue <= u16_strlen(pwszBucketValues[dwIndex]))) + if ((pwszValue == NULL) || (*pchValue <= minipal_u16_strlen((const CHAR16_T*)pwszBucketValues[dwIndex]))) { - *pchValue = static_cast(u16_strlen(pwszBucketValues[dwIndex]))+ 1; + *pchValue = static_cast(minipal_u16_strlen((const CHAR16_T*)pwszBucketValues[dwIndex]))+ 1; return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } diff --git a/src/coreclr/debug/daccess/enummem.cpp b/src/coreclr/debug/daccess/enummem.cpp index 7840bb29070cd0..67105c92825357 100644 --- a/src/coreclr/debug/daccess/enummem.cpp +++ b/src/coreclr/debug/daccess/enummem.cpp @@ -233,14 +233,14 @@ HRESULT ClrDataAccess::EnumMemCLRStatic(IN CLRDataEnumMemoryFlags flags) WCHAR* path = entryAssemblyPath; if (path != NULL) { - size_t pathLen = u16_strlen(path) + 1; + size_t pathLen = minipal_u16_strlen((const CHAR16_T*)path) + 1; // Get the file name based on the last directory separator const WCHAR* name = u16_strrchr(path, DIRECTORY_SEPARATOR_CHAR_W); if (name != NULL) { name += 1; - size_t len = u16_strlen(name) + 1; + size_t len = minipal_u16_strlen((const CHAR16_T*)name) + 1; wcscpy_s(path, len, name); // Null out the rest of the buffer diff --git a/src/coreclr/debug/daccess/inspect.cpp b/src/coreclr/debug/daccess/inspect.cpp index 99667d95918977..aafcfc89a040d8 100644 --- a/src/coreclr/debug/daccess/inspect.cpp +++ b/src/coreclr/debug/daccess/inspect.cpp @@ -1045,7 +1045,7 @@ ClrDataValue::GetString( if (strLen) { - *strLen = static_cast(u16_strlen(msgStr) + 1); + *strLen = static_cast(minipal_u16_strlen((const CHAR16_T*)msgStr) + 1); } status = StringCchCopy(str, bufLen, msgStr) == S_OK ? S_OK : S_FALSE; diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index 5c124d8e76ce7d..e6d07e008b90a9 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -700,7 +700,7 @@ ClrDataAccess::GetRegisterName(int regNum, unsigned int count, _Inout_updates_z_ const WCHAR callerPrefix[] = W("caller."); // Include null terminator in prefixLen/regLen because wcscpy_s will fail otherwise unsigned int prefixLen = (unsigned int)ARRAY_SIZE(callerPrefix); - unsigned int regLen = (unsigned int)u16_strlen(regs[regNum]) + 1; + unsigned int regLen = (unsigned int)minipal_u16_strlen((const CHAR16_T*)regs[regNum]) + 1; unsigned int needed = (callerFrame ? prefixLen - 1 : 0) + regLen; if (pNeeded) *pNeeded = needed; @@ -2140,7 +2140,7 @@ ClrDataAccess::GetFrameName(CLRDATA_ADDRESS vtable, unsigned int count, _Inout_u else { // Turn from bytes to wide characters - unsigned int len = (unsigned int)u16_strlen(pszName); + unsigned int len = (unsigned int)minipal_u16_strlen((const CHAR16_T*)pszName); if (frameName) { @@ -2614,7 +2614,7 @@ ClrDataAccess::GetAppDomainName(CLRDATA_ADDRESS addr, unsigned int count, _Inout if (pAppDomain->m_friendlyName.IsValid()) { LPCWSTR friendlyName = (LPCWSTR)pAppDomain->m_friendlyName; - size_t friendlyNameLen = u16_strlen(friendlyName); + size_t friendlyNameLen = minipal_u16_strlen((const CHAR16_T*)friendlyName); if (pNeeded) { diff --git a/src/coreclr/debug/daccess/task.cpp b/src/coreclr/debug/daccess/task.cpp index 65f14dedd18920..a280cad4a75de8 100644 --- a/src/coreclr/debug/daccess/task.cpp +++ b/src/coreclr/debug/daccess/task.cpp @@ -720,7 +720,7 @@ ClrDataAppDomain::GetName( S_OK : S_FALSE; if (nameLen) { - size_t cchName = u16_strlen(rawName) + 1; + size_t cchName = minipal_u16_strlen((const CHAR16_T*)rawName) + 1; if (FitsIn(cchName)) { *nameLen = (ULONG32) cchName; @@ -4749,7 +4749,7 @@ ClrDataExceptionState::GetString( status = StringCchCopy(str, bufLen, msgStr) == S_OK ? S_OK : S_FALSE; if (strLen != NULL) { - size_t cchName = u16_strlen(msgStr) + 1; + size_t cchName = minipal_u16_strlen((const CHAR16_T*)msgStr) + 1; if (FitsIn(cchName)) { *strLen = (ULONG32) cchName; diff --git a/src/coreclr/debug/dbgutil/dbgutil.cpp b/src/coreclr/debug/dbgutil/dbgutil.cpp index 93011b9d1fe54b..eab6651cf68550 100644 --- a/src/coreclr/debug/dbgutil/dbgutil.cpp +++ b/src/coreclr/debug/dbgutil/dbgutil.cpp @@ -329,7 +329,7 @@ HRESULT GetNextLevelResourceEntryRVAByName(ICorDebugDataTarget* pDataTarget, DWORD* pNextLevelRva) { HRESULT hr = S_OK; - DWORD nameLength = (DWORD)u16_strlen(pwzName); + DWORD nameLength = (DWORD)minipal_u16_strlen((const CHAR16_T*)pwzName); WCHAR entryName[50]; assert(nameLength < 50); // this implementation won't support matching a name longer // than 50 characters. We only look up the hard coded name diff --git a/src/coreclr/debug/di/process.cpp b/src/coreclr/debug/di/process.cpp index 43bd54b71b6abc..cda7fa3219fa8d 100644 --- a/src/coreclr/debug/di/process.cpp +++ b/src/coreclr/debug/di/process.cpp @@ -9619,7 +9619,7 @@ void Ls_Rs_StringBuffer::CopyLSDataToRS(ICorDebugDataTarget * pTarget) // Now we know it's safe to call u16_strlen. The buffer is local, so we know the pages are there. // And we know there's a null capping the max length of the string. - SIZE_T dwActualLenWithNull = u16_strlen(pString) + 1; + SIZE_T dwActualLenWithNull = minipal_u16_strlen((const CHAR16_T*)pString) + 1; if (dwActualLenWithNull != dwExpectedLenWithNull) { ThrowHR(CORDBG_E_TARGET_INCONSISTENT); diff --git a/src/coreclr/debug/di/publish.cpp b/src/coreclr/debug/di/publish.cpp index 0a7bad24642885..4ec621f4d0117b 100644 --- a/src/coreclr/debug/di/publish.cpp +++ b/src/coreclr/debug/di/publish.cpp @@ -418,7 +418,7 @@ CorpubProcess::CorpubProcess(DWORD dwProcessId, if (ret > 0) { // Recompute string length because we don't know if 'ret' is in bytes or char. - SIZE_T len = u16_strlen(szName) + 1; + SIZE_T len = minipal_u16_strlen((const CHAR16_T*)szName) + 1; m_szProcessName = new (nothrow) WCHAR[len]; if (m_szProcessName != NULL) { @@ -602,7 +602,7 @@ HRESULT AllocateAndReadRemoteString( if (SUCCEEDED(hr)) { // Ensure that the string we just read is actually null terminated. - // We can't call u16_strlen() on it yet, since that may AV on a non-null terminated string. + // We can't call minipal_u16_strlen((const CHAR16_T*)) on it yet, since that may AV on a non-null terminated string. WCHAR * pString = *ppNewLocalBuffer; if (pString[ceSize - 1] == W('\0')) @@ -612,7 +612,7 @@ HRESULT AllocateAndReadRemoteString( } pString[ceSize - 1] = W('\0'); - SIZE_T ceTestLen = u16_strlen(pString); + SIZE_T ceTestLen = minipal_u16_strlen((const CHAR16_T*)pString); if (ceTestLen == ceSize - 1) { // String was not previously null-terminated. diff --git a/src/coreclr/debug/di/rsmda.cpp b/src/coreclr/debug/di/rsmda.cpp index b6acace5f43168..b6b2186d365937 100644 --- a/src/coreclr/debug/di/rsmda.cpp +++ b/src/coreclr/debug/di/rsmda.cpp @@ -105,7 +105,7 @@ HRESULT CordbMDA::QueryInterface(REFIID riid, void **ppInterface) HRESULT CopyOutString(LPCWSTR pInputString, ULONG32 cchName, ULONG32 * pcchName, _Out_writes_to_opt_(cchName, *pcchName) WCHAR szName[]) { _ASSERTE(pInputString != NULL); - ULONG32 len = (ULONG32) u16_strlen(pInputString) + 1; + ULONG32 len = (ULONG32) minipal_u16_strlen((const CHAR16_T*)pInputString) + 1; if (cchName == 0) { diff --git a/src/coreclr/debug/di/rsthread.cpp b/src/coreclr/debug/di/rsthread.cpp index 619b37c87ef8b8..458959ded0eb64 100644 --- a/src/coreclr/debug/di/rsthread.cpp +++ b/src/coreclr/debug/di/rsthread.cpp @@ -10205,7 +10205,7 @@ HRESULT CordbEval::NewString(LPCWSTR string) { PUBLIC_API_ENTRY(this); FAIL_IF_NEUTERED(this); - return NewStringWithLength(string, (UINT)u16_strlen(string)); + return NewStringWithLength(string, (UINT)minipal_u16_strlen((const CHAR16_T*)string)); } //--------------------------------------------------------------------------------------- diff --git a/src/coreclr/debug/di/symbolinfo.cpp b/src/coreclr/debug/di/symbolinfo.cpp index 7d293a89a1ddc5..ddd3d75e4992f8 100644 --- a/src/coreclr/debug/di/symbolinfo.cpp +++ b/src/coreclr/debug/di/symbolinfo.cpp @@ -258,7 +258,7 @@ STDMETHODIMP SymbolInfo::GetTypeDefProps ( // S_OK or error. *pdwTypeDefFlags=classInfo->flags; - SIZE_T cch=u16_strlen(classInfo->wszName)+1; + SIZE_T cch=minipal_u16_strlen((const CHAR16_T*)classInfo->wszName.GetUnicode())+1; if (cch > UINT32_MAX) return E_UNEXPECTED; *pchTypeDef=(ULONG)cch; @@ -309,7 +309,7 @@ STDMETHODIMP SymbolInfo::GetMethodProps ( *pClass=m_LastMethod.cls; - SIZE_T cch=u16_strlen(m_LastMethod.wszName)+1; + SIZE_T cch=minipal_u16_strlen((const CHAR16_T*)m_LastMethod.wszName.GetUnicode())+1; if(cch > UINT32_MAX) return E_UNEXPECTED; *pchMethod=(ULONG)cch; diff --git a/src/coreclr/debug/inc/dbgappdomain.h b/src/coreclr/debug/inc/dbgappdomain.h index de8a06b38c9e51..452148d1728cec 100644 --- a/src/coreclr/debug/inc/dbgappdomain.h +++ b/src/coreclr/debug/inc/dbgappdomain.h @@ -43,7 +43,7 @@ struct AppDomainInfo else m_szAppDomainName = W(""); - m_iNameLengthInBytes = (int) (u16_strlen(m_szAppDomainName) + 1) * sizeof(WCHAR); + m_iNameLengthInBytes = (int) (minipal_u16_strlen((const CHAR16_T*)m_szAppDomainName) + 1) * sizeof(WCHAR); } #endif }; diff --git a/src/coreclr/debug/inc/dbgipcevents.h b/src/coreclr/debug/inc/dbgipcevents.h index 6c39939f00307e..5025abca6e2db3 100644 --- a/src/coreclr/debug/inc/dbgipcevents.h +++ b/src/coreclr/debug/inc/dbgipcevents.h @@ -872,7 +872,7 @@ template class MSLAYOUT EmbeddedIPCString { public: - // Set, caller responsibility that u16_strlen(pData) < nMaxLengthIncludingNull + // Set, caller responsibility that minipal_u16_strlen((const CHAR16_T*)pData) < nMaxLengthIncludingNull void SetString(const WCHAR * pData) { // If the string doesn't fit into the buffer, that's an issue (and so this is a real diff --git a/src/coreclr/debug/inc/ddmarshalutil.h b/src/coreclr/debug/inc/ddmarshalutil.h index 190fa071c8d3b4..d6401fe2aae0aa 100644 --- a/src/coreclr/debug/inc/ddmarshalutil.h +++ b/src/coreclr/debug/inc/ddmarshalutil.h @@ -90,7 +90,7 @@ class WriteBuffer : public BaseBuffer if (!fIsNull) { _ASSERTE(pString != NULL); - DWORD len = (DWORD) u16_strlen(pString); + DWORD len = (DWORD) minipal_u16_strlen((const CHAR16_T*)pString); DWORD cbCopy = (len + 1) * sizeof(WCHAR); EnsureSize(cbCopy); @@ -179,7 +179,7 @@ class ReadBuffer : public BaseBuffer else { const WCHAR * pString = (WCHAR*) &m_pBuffer[m_idx]; - DWORD len = (DWORD) u16_strlen(pString); + DWORD len = (DWORD) minipal_u16_strlen((const CHAR16_T*)pString); m_idx += (len + 1) * sizeof(WCHAR); // skip past null _ASSERTE(m_idx <= m_size); return pString; diff --git a/src/coreclr/debug/shared/stringcopyholder.cpp b/src/coreclr/debug/shared/stringcopyholder.cpp index 46bb9971dbd229..6b674380a33422 100644 --- a/src/coreclr/debug/shared/stringcopyholder.cpp +++ b/src/coreclr/debug/shared/stringcopyholder.cpp @@ -68,7 +68,7 @@ HRESULT StringCopyHolder::AssignCopy(const WCHAR * pStringSrc) } else { - SIZE_T cchLen = u16_strlen(pStringSrc) + 1; + SIZE_T cchLen = minipal_u16_strlen((const CHAR16_T*)pStringSrc) + 1; m_szData = new (nothrow) WCHAR[cchLen]; if (m_szData == NULL) { diff --git a/src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp b/src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp index 2de73f9675b027..c85ba436e12e92 100644 --- a/src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp +++ b/src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp @@ -466,7 +466,7 @@ HRESULT CeeFileGenWriter::setOutputFileName(_In_ LPWSTR fileName) { if (m_outputFileName) delete[] m_outputFileName; - size_t len = u16_strlen(fileName) + 1; + size_t len = minipal_u16_strlen((const CHAR16_T*)fileName) + 1; m_outputFileName = (LPWSTR)new (nothrow) WCHAR[len]; TESTANDRETURN(m_outputFileName!=NULL, E_OUTOFMEMORY); wcscpy_s(m_outputFileName, len, fileName); @@ -477,7 +477,7 @@ HRESULT CeeFileGenWriter::setResourceFileName(_In_ LPWSTR fileName) { if (m_resourceFileName) delete[] m_resourceFileName; - size_t len = u16_strlen(fileName) + 1; + size_t len = minipal_u16_strlen((const CHAR16_T*)fileName) + 1; m_resourceFileName = (LPWSTR)new (nothrow) WCHAR[len]; TESTANDRETURN(m_resourceFileName!=NULL, E_OUTOFMEMORY); wcscpy_s(m_resourceFileName, len, fileName); diff --git a/src/coreclr/ilasm/asmman.cpp b/src/coreclr/ilasm/asmman.cpp index 8f42b83bdcd7b7..48701205c4de90 100644 --- a/src/coreclr/ilasm/asmman.cpp +++ b/src/coreclr/ilasm/asmman.cpp @@ -28,10 +28,10 @@ BinStr* BinStrToUnicode(BinStr* pSource, bool Swap) { memset(wz,0,L); MultiByteToWideChar(g_uCodePage,0,pb,-1,wz,l); - tmp->remove(L-(DWORD)u16_strlen(wz)*sizeof(WCHAR)); + tmp->remove(L-(DWORD)minipal_u16_strlen((const CHAR16_T*)wz)*sizeof(WCHAR)); #if BIGENDIAN if (Swap) - SwapStringLength(wz, (DWORD)u16_strlen(wz)); + SwapStringLength(wz, (DWORD)minipal_u16_strlen((const CHAR16_T*)wz)); #endif delete pSource; } @@ -996,8 +996,8 @@ HRESULT AsmMan::EmitManifest() else { m_dwMResSizeTotal += m_dwMResSize[m_dwMResNum]+sizeof(DWORD); - m_wzMResName[m_dwMResNum] = new WCHAR[u16_strlen(wzFileName)+1]; - wcscpy_s(m_wzMResName[m_dwMResNum],u16_strlen(wzFileName)+1,wzFileName); + m_wzMResName[m_dwMResNum] = new WCHAR[minipal_u16_strlen((const CHAR16_T*)wzFileName)+1]; + wcscpy_s(m_wzMResName[m_dwMResNum],minipal_u16_strlen((const CHAR16_T*)wzFileName)+1,wzFileName); m_fMResNew[m_dwMResNum] = TRUE; m_dwMResNum++; } diff --git a/src/coreclr/ilasm/assem.cpp b/src/coreclr/ilasm/assem.cpp index 0100feef79a127..2bc0a8a4d7753b 100644 --- a/src/coreclr/ilasm/assem.cpp +++ b/src/coreclr/ilasm/assem.cpp @@ -1076,7 +1076,7 @@ BOOL Assembler::EmitClass(Class *pClass) MultiByteToWideChar(g_uCodePage,0,szFullName,-1,wzFullName,dwUniBuf); - L = u16_strlen(wzFullName); + L = minipal_u16_strlen((const CHAR16_T*)wzFullName); if((L==0)||(wzFullName[L-1]==L'.')) // Missing class name! { wcscat_s(wzFullName,dwUniBuf,W("$UNNAMED_TYPE$")); diff --git a/src/coreclr/ilasm/main.cpp b/src/coreclr/ilasm/main.cpp index aba3aa78847f35..d9d59c9c85bf95 100644 --- a/src/coreclr/ilasm/main.cpp +++ b/src/coreclr/ilasm/main.cpp @@ -34,7 +34,7 @@ class NarrowForNumberParsing final public: NarrowForNumberParsing(const WCHAR* str) { - size_t len = u16_strlen(str); + size_t len = minipal_u16_strlen((const CHAR16_T*)str); _buffer = (char*)malloc(len + 1); for (size_t i = 0; i < len; ++i) _buffer[i] = (char)str[i]; @@ -83,7 +83,7 @@ void MakeProperSourceFileName(_In_ __nullterminated WCHAR* wzOrigName, _Out_writes_(MAX_FILENAME_LENGTH*3) char* szProperName) { wcscpy_s(wzProperName,MAX_FILENAME_LENGTH, wzOrigName); - size_t j = u16_strlen(wzProperName); + size_t j = minipal_u16_strlen((const CHAR16_T*)wzProperName); do { j--; @@ -263,7 +263,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) if(pStr != NULL) { for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(u16_strlen(pStr)==0) goto InvalidOption; //if no suboption + if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no suboption else { WCHAR wzSubOpt[8]; @@ -377,7 +377,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto ErrorExit; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name + if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no file name pAsm->m_wzResourceFile = pStr; } else @@ -388,7 +388,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name + if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no file name pAsm->m_wzKeySourceName = pStr; } else if (!_stricmp(szOpt, "INC")) @@ -396,7 +396,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name + if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no file name wzIncludePath = pStr; } else if (!_stricmp(szOpt, "OUT")) @@ -404,8 +404,8 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name - if(u16_strlen(pStr) >= MAX_FILENAME_LENGTH) + if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no file name + if(minipal_u16_strlen((const CHAR16_T*)pStr) >= MAX_FILENAME_LENGTH) { fprintf(stderr,"\nError: Output file name exceeds %d characters\n",MAX_FILENAME_LENGTH-1); goto ErrorExit; @@ -417,7 +417,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(u16_strlen(pStr)==0) goto InvalidOption; //if no version string + if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no version string pAsm->m_wzMetadataVersion = pStr; } else if (!_stricmp(szOpt, "MSV")) @@ -425,7 +425,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(u16_strlen(pStr)==0) goto InvalidOption; //if no version + if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no version { int major=-1,minor=-1; NarrowForNumberParsing str{pStr}; @@ -452,7 +452,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(u16_strlen(pStr)==0) goto InvalidOption; //if no version + if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no version { int major=-1,minor=-1; NarrowForNumberParsing str{pStr}; @@ -541,7 +541,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) } else { - if(u16_strlen(argv[i]) >= MAX_FILENAME_LENGTH) + if(minipal_u16_strlen((const CHAR16_T*)argv[i]) >= MAX_FILENAME_LENGTH) { printf("\nError: Input file name exceeds %d characters\n",MAX_FILENAME_LENGTH-1); goto ErrorExit; @@ -620,7 +620,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) if(wzOutputFilename[0] == 0) { wcscpy_s(wzOutputFilename,MAX_FILENAME_LENGTH,pwzInputFiles[0]); - size_t j = u16_strlen(wzOutputFilename); + size_t j = minipal_u16_strlen((const CHAR16_T*)wzOutputFilename); do { j--; @@ -778,7 +778,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) for(iFile = 0; iFile < NumDeltaFiles; iFile++) { wcscpy_s(wzNewOutputFilename,MAX_FILENAME_LENGTH+16,wzOutputFilename); - size_t len = u16_strlen(wzNewOutputFilename); + size_t len = minipal_u16_strlen((const CHAR16_T*)wzNewOutputFilename); wzNewOutputFilename[len] = W('.'); FormatInteger(&wzNewOutputFilename[len + 1], MaxSigned32BitDecString + 1, "%d", iFile+1); MakeProperSourceFileName(pwzDeltaFiles[iFile], uCodePage, wzInputFilename, szInputFilename); @@ -841,7 +841,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR* pc = (WCHAR*)u16_strrchr(wzOutputFilename,W('.')); if(pc==NULL) { - pc = &wzOutputFilename[u16_strlen(wzOutputFilename)]; + pc = &wzOutputFilename[minipal_u16_strlen((const CHAR16_T*)wzOutputFilename)]; *pc = W('.'); } wcscpy_s(pc+1,4,W("PDB")); diff --git a/src/coreclr/ilasm/writer.cpp b/src/coreclr/ilasm/writer.cpp index 2bc9152bfea3b3..3ed22dea3acc22 100644 --- a/src/coreclr/ilasm/writer.cpp +++ b/src/coreclr/ilasm/writer.cpp @@ -336,9 +336,9 @@ HRESULT Assembler::CreateExportDirectory() unsigned i, L, ordBase = 0xFFFFFFFF, Ldllname; // get the DLL name from output file name char* pszDllName; - Ldllname = (unsigned)u16_strlen(m_wzOutputFileName)*3+3; + Ldllname = (unsigned)minipal_u16_strlen((const CHAR16_T*)m_wzOutputFileName)*3+3; NewArrayHolder szOutputFileName(new char[Ldllname]); - memset(szOutputFileName,0,u16_strlen(m_wzOutputFileName)*3+3); + memset(szOutputFileName,0,minipal_u16_strlen((const CHAR16_T*)m_wzOutputFileName)*3+3); WideCharToMultiByte(CP_ACP,0,m_wzOutputFileName,-1,szOutputFileName,Ldllname,NULL,NULL); pszDllName = strrchr(szOutputFileName,DIRECTORY_SEPARATOR_CHAR_A); #ifdef TARGET_WINDOWS diff --git a/src/coreclr/ildasm/dasm.cpp b/src/coreclr/ildasm/dasm.cpp index f514e90cca65e6..573af9ef417fdf 100644 --- a/src/coreclr/ildasm/dasm.cpp +++ b/src/coreclr/ildasm/dasm.cpp @@ -3062,7 +3062,7 @@ char *DumpGenericPars(_Inout_updates_(SZSTRING_SIZE) char* szString, mdToken tok for (i = 1; NumTyPars != 0; i++) { g_pPubImport->GetGenericParamProps(tkTyPar, &ulSequence, &attr, &tkOwner, NULL, wzArgName, UNIBUF_SIZE/2, &chName); - //if(u16_strlen(wzArgName) >= MAX_CLASSNAME_LENGTH) + //if(minipal_u16_strlen((const CHAR16_T*)wzArgName) >= MAX_CLASSNAME_LENGTH) // wzArgName[MAX_CLASSNAME_LENGTH-1] = 0; hEnumTyParConstr = NULL; if (FAILED(g_pPubImport->EnumGenericParamConstraints(&hEnumTyParConstr, tkTyPar, tkConstr, 2048, &NumConstrs))) @@ -3117,7 +3117,7 @@ char *DumpGenericPars(_Inout_updates_(SZSTRING_SIZE) char* szString, mdToken tok } // re-get name, wzUniBuf may not contain it any more g_pPubImport->GetGenericParamProps(tkTyPar, NULL, &attr, NULL, NULL, wzArgName, UNIBUF_SIZE/2, &chName); - //if(u16_strlen(wzArgName) >= MAX_CLASSNAME_LENGTH) + //if(minipal_u16_strlen((const CHAR16_T*)wzArgName) >= MAX_CLASSNAME_LENGTH) // wzArgName[MAX_CLASSNAME_LENGTH-1] = 0; if (chName) { @@ -3187,7 +3187,7 @@ void DumpGenericParsCA(mdToken tok, void* GUICookie/*=NULL*/) if(SUCCEEDED(g_pPubImport->GetGenericParamProps(tkTyPar, NULL, &attr, NULL, NULL, wzArgName, UNIBUF_SIZE/2, &chName)) &&(chName > 0)) { - //if(u16_strlen(wzArgName) >= MAX_CLASSNAME_LENGTH) + //if(minipal_u16_strlen((const CHAR16_T*)wzArgName) >= MAX_CLASSNAME_LENGTH) // wzArgName[MAX_CLASSNAME_LENGTH-1] = 0; char* sz = (char*)(&wzUniBuf[UNIBUF_SIZE/2]); WideCharToMultiByte(CP_UTF8,0,wzArgName,-1,sz,UNIBUF_SIZE,NULL,NULL); @@ -7784,7 +7784,7 @@ BOOL DumpFile() memset(wzResFileName,0,sizeof(wzResFileName)); MultiByteToWideChar(CP_UTF8,0,g_szOutputFile,-1,wzResFileName,2048); pwc = (WCHAR*)u16_strrchr(wzResFileName,L'.'); - if(pwc == NULL) pwc = &wzResFileName[u16_strlen(wzResFileName)]; + if(pwc == NULL) pwc = &wzResFileName[minipal_u16_strlen((const CHAR16_T*)wzResFileName)]; wcscpy_s(pwc, 2048 - (pwc - wzResFileName), L".res"); DWORD ret = DumpResourceToFile(wzResFileName); switch(ret) diff --git a/src/coreclr/ildasm/dis.cpp b/src/coreclr/ildasm/dis.cpp index 44ce665814c1fd..7f6af0add18097 100644 --- a/src/coreclr/ildasm/dis.cpp +++ b/src/coreclr/ildasm/dis.cpp @@ -143,7 +143,7 @@ static void UnicodeToFile(_In_ __nullterminated const WCHAR* wz, FILE* pF) { unsigned endofline = 0x000A000D; int L; - if((L=(int)u16_strlen(wz))) fwrite(wz,L*sizeof(WCHAR),1,pF); + if((L=(int)minipal_u16_strlen((const CHAR16_T*)wz))) fwrite(wz,L*sizeof(WCHAR),1,pF); fwrite(&endofline,4,1,pF); } static void ToGUIOrFile(_In_ __nullterminated const char* sz, void* GUICookie) diff --git a/src/coreclr/ildasm/dman.cpp b/src/coreclr/ildasm/dman.cpp index 91761723a081c1..19d26d46e60ae2 100644 --- a/src/coreclr/ildasm/dman.cpp +++ b/src/coreclr/ildasm/dman.cpp @@ -125,7 +125,7 @@ void DumpScope(void* GUICookie) if(SUCCEEDED(g_pPubImport->GetScopeProps( scopeName, 1024, NULL, &mvid))&& scopeName[0]) { { - UINT32 L = (UINT32)u16_strlen(scopeName)*3+3; + UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)scopeName)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,scopeName,-1,sz,L,NULL,NULL); @@ -423,7 +423,7 @@ void DumpComTypeFQN( } } - UINT32 L = (UINT32)u16_strlen(pCTD->wzName)*3+3; + UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)pCTD->wzName)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,pCTD->wzName,-1,sz,L,NULL,NULL); @@ -446,7 +446,7 @@ void DumpImplementation(mdToken tkImplementation, if(i < nFiles) { { - UINT32 L = (UINT32)u16_strlen(rFile[i].name)*3+3; + UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)rFile[i].name)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,rFile[i].name,-1,sz,L,NULL,NULL); @@ -466,7 +466,7 @@ void DumpImplementation(mdToken tkImplementation, if(i < nAsmRefs) { { - UINT32 L = (UINT32)u16_strlen(rAsmRef[i].name)*3+3; + UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)rAsmRef[i].name)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,rAsmRef[i].name,-1,sz,L,NULL,NULL); @@ -512,7 +512,7 @@ void DumpComType(LocalComTypeDescr* pCTD, char* pc=&szString[strlen(szString)]; { - UINT32 L = (UINT32)u16_strlen(pCTD->wzName)*3+3; + UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)pCTD->wzName)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,pCTD->wzName,-1,sz,L,NULL,NULL); @@ -628,7 +628,7 @@ static BOOL ConvertToLegalFileNameInPlace(__inout LPWSTR wzName) for (size_t i = 0; i < (sizeof(rwzReserved) / sizeof(WCHAR *)); i++) { - _ASSERTE(u16_strlen(rwzReserved[i]) == 3); + _ASSERTE(minipal_u16_strlen((const CHAR16_T*)rwzReserved[i]) == 3); if (_wcsnicmp(wzName, rwzReserved[i], 3) == 0) { LPWSTR pwc = wzName + 3; @@ -801,7 +801,7 @@ void DumpManifestResources(void* GUICookie) #define NAME_ARRAY_ADD(index, str) \ { \ - size_t __dwBufLen = u16_strlen(str) + 1; \ + size_t __dwBufLen = minipal_u16_strlen((const CHAR16_T*)str) + 1; \ \ qbNameArray[index].Init(); \ WCHAR *__wpc = (WCHAR *)qbNameArray[index].AllocNoThrow(__dwBufLen); \ @@ -813,7 +813,7 @@ void DumpManifestResources(void* GUICookie) // add the Win32 resource file name to avoid conflict between the native and a managed resource file WCHAR *pwc = (WCHAR*)u16_strrchr(wzName, L'.'); - if (pwc == NULL) pwc = &wzName[u16_strlen(wzName)]; + if (pwc == NULL) pwc = &wzName[minipal_u16_strlen((const CHAR16_T*)wzName)]; wcscpy_s(pwc, 2048 - (pwc - wzFileName), W(".res")); NAME_ARRAY_ADD(1, wzName); @@ -845,7 +845,7 @@ void DumpManifestResources(void* GUICookie) BOOL fAlias = ConvertToLegalFileNameInPlace(wzName); // check for duplicate file name - WCHAR *wpc = wzName + u16_strlen(wzName); + WCHAR *wpc = wzName + minipal_u16_strlen((const CHAR16_T*)wzName); for (int iIndex = 1;; iIndex++) { BOOL fConflict = FALSE; diff --git a/src/coreclr/ildasm/dres.cpp b/src/coreclr/ildasm/dres.cpp index e1612130ca6065..871083ec533a66 100644 --- a/src/coreclr/ildasm/dres.cpp +++ b/src/coreclr/ildasm/dres.cpp @@ -104,8 +104,8 @@ struct ResourceNode { //fwrite(&(g_prResNodePtr[i]->ResHdr),g_prResNodePtr[i]->ResHdr.dwHeaderSize,1,pF); ResHdr.dwHeaderSize = sizeof(ResourceHeader); - if(wzType) ResHdr.dwHeaderSize += (DWORD)((u16_strlen(wzType) + 1)*sizeof(WCHAR) - sizeof(DWORD)); - if(wzName) ResHdr.dwHeaderSize += (DWORD)((u16_strlen(wzName) + 1)*sizeof(WCHAR) - sizeof(DWORD)); + if(wzType) ResHdr.dwHeaderSize += (DWORD)((minipal_u16_strlen((const CHAR16_T*)wzType) + 1)*sizeof(WCHAR) - sizeof(DWORD)); + if(wzName) ResHdr.dwHeaderSize += (DWORD)((minipal_u16_strlen((const CHAR16_T*)wzName) + 1)*sizeof(WCHAR) - sizeof(DWORD)); //---- Constant part of the header: DWORD,DWORD fwrite(&ResHdr.dwDataSize, sizeof(DWORD),1,pF); @@ -113,15 +113,15 @@ struct ResourceNode //--- Variable part of header: type and name if(wzType) { - fwrite(wzType,(u16_strlen(wzType) + 1)*sizeof(WCHAR), 1, pF); - dwFiller += (DWORD)u16_strlen(wzType) + 1; + fwrite(wzType,(minipal_u16_strlen((const CHAR16_T*)wzType) + 1)*sizeof(WCHAR), 1, pF); + dwFiller += (DWORD)minipal_u16_strlen((const CHAR16_T*)wzType) + 1; } else fwrite(&ResHdr.dwTypeID,sizeof(DWORD),1,pF); if(wzName) { - fwrite(wzName,(u16_strlen(wzName) + 1)*sizeof(WCHAR), 1, pF); - dwFiller += (DWORD)u16_strlen(wzName) + 1; + fwrite(wzName,(minipal_u16_strlen((const CHAR16_T*)wzName) + 1)*sizeof(WCHAR), 1, pF); + dwFiller += (DWORD)minipal_u16_strlen((const CHAR16_T*)wzName) + 1; } else fwrite(&ResHdr.dwNameID,sizeof(DWORD),1,pF); diff --git a/src/coreclr/inc/daccess.h b/src/coreclr/inc/daccess.h index 7bc2baed536e39..3b2b21e8e18713 100644 --- a/src/coreclr/inc/daccess.h +++ b/src/coreclr/inc/daccess.h @@ -575,7 +575,7 @@ #include #include "crosscomp.h" -#include +#include // Information stored in the DAC table of interest to the DAC implementation // Note that this information is shared between all instantiations of ClrDataAccess, so initialize @@ -1524,7 +1524,7 @@ class __Str16Ptr : public __DPtr WCHAR* str = DacInstantiateStringW(m_addr, maxChars, false); if (str) { - DacEnumMemoryRegion(m_addr, u16_strlen(str) + 1); + DacEnumMemoryRegion(m_addr, minipal_u16_strlen((const CHAR16_T*)str) + 1); } } }; diff --git a/src/coreclr/inc/eventtracebase.h b/src/coreclr/inc/eventtracebase.h index 38868fe528f797..f00b156af0a16a 100644 --- a/src/coreclr/inc/eventtracebase.h +++ b/src/coreclr/inc/eventtracebase.h @@ -349,7 +349,7 @@ class XplatEventLoggerConfiguration const WCHAR * end = u16_strchr(start, ComponentDelimiter); if (end == nullptr) { - end = start + u16_strlen(start); + end = start + minipal_u16_strlen((const CHAR16_T*)start); } return ComponentSpan(start, end); @@ -460,7 +460,7 @@ class XplatEventLoggerController #ifdef FEATURE_EVENT_TRACE static LTTNG_TRACE_CONTEXT * const GetProvider(LPCWSTR providerName) { - auto length = u16_strlen(providerName); + auto length = minipal_u16_strlen((const CHAR16_T*)providerName); for (auto provider : ALL_LTTNG_PROVIDERS_CONTEXT) { if (_wcsicmp(provider->Name, providerName) == 0) diff --git a/src/coreclr/inc/outstring.h b/src/coreclr/inc/outstring.h index c719c465457b72..c91f0bbc5f1c90 100644 --- a/src/coreclr/inc/outstring.h +++ b/src/coreclr/inc/outstring.h @@ -73,7 +73,7 @@ class OutString { } OutString& operator<<(const WCHAR* str) { - size_t len = u16_strlen(str); + size_t len = minipal_u16_strlen((const CHAR16_T*)str); if (cur+len > end) Realloc(len); while(str != 0) diff --git a/src/coreclr/inc/sstring.inl b/src/coreclr/inc/sstring.inl index 0b78ec3bc3aaff..05f00321d2c8ba 100644 --- a/src/coreclr/inc/sstring.inl +++ b/src/coreclr/inc/sstring.inl @@ -386,7 +386,7 @@ inline SString::SString(tagUTF8Literal dummytag, const UTF8 *literal) } inline SString::SString(tagLiteral dummytag, const WCHAR *literal) - : SBuffer(Immutable, (const BYTE *) literal, (COUNT_T) (u16_strlen(literal)+1)*sizeof(WCHAR)) + : SBuffer(Immutable, (const BYTE *) literal, (COUNT_T) (minipal_u16_strlen((const CHAR16_T*)literal)+1)*sizeof(WCHAR)) { SS_CONTRACT_VOID { diff --git a/src/coreclr/inc/utilcode.h b/src/coreclr/inc/utilcode.h index 823e83d198334e..dcff853ed86016 100644 --- a/src/coreclr/inc/utilcode.h +++ b/src/coreclr/inc/utilcode.h @@ -36,6 +36,7 @@ using std::nothrow; #include "contract.h" #include +#include #include #include "clrnt.h" @@ -213,7 +214,7 @@ typedef LPSTR LPUTF8; // representable. This is reasonable for writing to the console, but // shouldn't be used for most string conversions. #define MAKE_MULTIBYTE_FROMWIDE_BESTFIT(ptrname, widestr, codepage) \ - int __l##ptrname = (int)u16_strlen(widestr); \ + int __l##ptrname = (int)minipal_u16_strlen((const CHAR16_T*)widestr); \ if (__l##ptrname > MAKE_MAX_LENGTH) \ MAKE_TOOLONGACTION; \ __l##ptrname = (int)((__l##ptrname + 1) * 2 * sizeof(char)); \ @@ -231,7 +232,7 @@ typedef LPSTR LPUTF8; // ptrname will be deleted when it goes out of scope. #define MAKE_UTF8PTR_FROMWIDE_NOTHROW(ptrname, widestr) \ CQuickBytes __qb##ptrname; \ - int __l##ptrname = (int)u16_strlen(widestr); \ + int __l##ptrname = (int)minipal_u16_strlen((const CHAR16_T*)widestr); \ LPUTF8 ptrname = NULL; \ if (__l##ptrname <= MAKE_MAX_LENGTH) { \ __l##ptrname = (int)((__l##ptrname + 1) * 2 * sizeof(char)); \ @@ -2186,7 +2187,7 @@ inline ULONG HashStringN(LPCWSTR szStr, SIZE_T cchStr) ULONG *ptr = (ULONG *)szStr; // we assume that szStr is null-terminated - _ASSERTE(cchStr <= u16_strlen(szStr)); + _ASSERTE(cchStr <= minipal_u16_strlen((const CHAR16_T*)szStr)); SIZE_T cDwordCount = (cchStr + 1) / 2; for (SIZE_T i = 0; i < cDwordCount; i++) diff --git a/src/coreclr/jit/disasm.cpp b/src/coreclr/jit/disasm.cpp index bff93c85150a68..952057ca50d961 100644 --- a/src/coreclr/jit/disasm.cpp +++ b/src/coreclr/jit/disasm.cpp @@ -1210,7 +1210,7 @@ size_t CbDisassembleWithBytes(DIS* pdis, DIS::ADDR addr, const BYTE* pb, size_t { bool fFirst = (pwzBytes == wzBytes); - cchBytes = u16_strlen(pwzBytes); + cchBytes = minipal_u16_strlen((const CHAR16_T*)pwzBytes); if (cchBytes <= cchBytesMax) { diff --git a/src/coreclr/md/ceefilegen/ceesectionstring.cpp b/src/coreclr/md/ceefilegen/ceesectionstring.cpp index 05d305bf8e7b90..ba8bee2ce4249f 100644 --- a/src/coreclr/md/ceefilegen/ceesectionstring.cpp +++ b/src/coreclr/md/ceefilegen/ceesectionstring.cpp @@ -42,7 +42,7 @@ StringTableEntry* CeeSectionString::createEntry(_In_z_ LPWSTR target, ULONG hash entry->m_next = NULL; entry->m_hashId = hashId; entry->m_offset = dataLen(); - size_t len = (u16_strlen(target)+1) * sizeof(WCHAR); + size_t len = (minipal_u16_strlen((const CHAR16_T*)target)+1) * sizeof(WCHAR); if (len > UINT32_MAX) { delete entry; return NULL; diff --git a/src/coreclr/md/compiler/assemblymd.cpp b/src/coreclr/md/compiler/assemblymd.cpp index f81e835bf92679..9e1b08f92eed61 100644 --- a/src/coreclr/md/compiler/assemblymd.cpp +++ b/src/coreclr/md/compiler/assemblymd.cpp @@ -214,7 +214,7 @@ STDMETHODIMP RegMeta::GetExportedTypeProps( // S_OK or error. if (bTruncation || !szName) *pchName = ns::GetFullLength(wzTypeNamespace, wzTypeName); else - *pchName = (ULONG)(u16_strlen(szName) + 1); + *pchName = (ULONG)(minipal_u16_strlen((const CHAR16_T*)szName) + 1); } } if (ptkImplementation) diff --git a/src/coreclr/md/compiler/mdutil.cpp b/src/coreclr/md/compiler/mdutil.cpp index 05b56a25875bb0..8d0de1542a97b1 100644 --- a/src/coreclr/md/compiler/mdutil.cpp +++ b/src/coreclr/md/compiler/mdutil.cpp @@ -480,7 +480,7 @@ ULONG _GetSizeOfConstantBlob( if (cchString != (ULONG) -1) ulSize = cchString * sizeof(WCHAR); else - ulSize = (ULONG)(sizeof(WCHAR) * u16_strlen((LPWSTR)pValue)); + ulSize = (ULONG)(sizeof(WCHAR) * minipal_u16_strlen((const CHAR16_T*)(LPWSTR)pValue)); break; case ELEMENT_TYPE_CLASS: diff --git a/src/coreclr/md/compiler/regmeta.h b/src/coreclr/md/compiler/regmeta.h index 78a854b778b0fe..84d8517fd113db 100644 --- a/src/coreclr/md/compiler/regmeta.h +++ b/src/coreclr/md/compiler/regmeta.h @@ -40,7 +40,7 @@ struct CORDBG_SYMBOL_URL ULONG Size() const { - return (ULONG)(sizeof(GUID) + ((u16_strlen(rcName) + 1) * 2)); + return (ULONG)(sizeof(GUID) + ((minipal_u16_strlen((const CHAR16_T*)rcName) + 1) * 2)); } #ifdef _PREFAST_ diff --git a/src/coreclr/md/compiler/regmeta_import.cpp b/src/coreclr/md/compiler/regmeta_import.cpp index dd260d2f2ff855..3ffe8ffc1a9345 100644 --- a/src/coreclr/md/compiler/regmeta_import.cpp +++ b/src/coreclr/md/compiler/regmeta_import.cpp @@ -765,7 +765,7 @@ RegMeta::GetTypeDefProps( } else { - *pchTypeDef = (ULONG)(u16_strlen(szTypeDef) + 1); + *pchTypeDef = (ULONG)(minipal_u16_strlen((const CHAR16_T*)szTypeDef) + 1); } } } @@ -900,7 +900,7 @@ RegMeta::GetTypeRefProps( } else { - *pchTypeRef = (ULONG)(u16_strlen(szTypeRef) + 1); + *pchTypeRef = (ULONG)(minipal_u16_strlen((const CHAR16_T*)szTypeRef) + 1); } } } diff --git a/src/coreclr/md/enc/liteweightstgdbrw.cpp b/src/coreclr/md/enc/liteweightstgdbrw.cpp index 3b2e2db604297b..31785a75276f18 100644 --- a/src/coreclr/md/enc/liteweightstgdbrw.cpp +++ b/src/coreclr/md/enc/liteweightstgdbrw.cpp @@ -1167,7 +1167,7 @@ CLiteWeightStgdbRW::SetFileName( // Size of the file name incl. null terminator size_t cchFileName; - cchFileName = u16_strlen(wszFileName) + 1; + cchFileName = minipal_u16_strlen((const CHAR16_T*)wszFileName) + 1; // Allocate and copy the file name m_wszFileName = new (nothrow) WCHAR[cchFileName]; diff --git a/src/coreclr/md/enc/rwutil.cpp b/src/coreclr/md/enc/rwutil.cpp index 36c326adc4d7ee..b25237dcfe9a74 100644 --- a/src/coreclr/md/enc/rwutil.cpp +++ b/src/coreclr/md/enc/rwutil.cpp @@ -24,7 +24,7 @@ Unicode2UTF( LPUTF8 szDst, // Buffer for the output UTF8 string. int cbDst) // Size of the buffer for UTF8 string. { - int cchSrc = (int)u16_strlen(wszSrc); + int cchSrc = (int)minipal_u16_strlen((const CHAR16_T*)wszSrc); int cchRet; cchRet = WideCharToMultiByte( diff --git a/src/coreclr/md/inc/rwutil.h b/src/coreclr/md/inc/rwutil.h index f6ee02817fb2b7..42879d96e02f6f 100644 --- a/src/coreclr/md/inc/rwutil.h +++ b/src/coreclr/md/inc/rwutil.h @@ -21,7 +21,7 @@ class UTSemReadWrite; } \ else \ { \ - int cbBuffer = ((int)u16_strlen(wszInput) * 3) + 1; \ + int cbBuffer = ((int)minipal_u16_strlen((const CHAR16_T*)wszInput) * 3) + 1; \ (szOutput) = (char *)_alloca(cbBuffer); \ Unicode2UTF((wszInput), (szOutput), cbBuffer); \ } \ diff --git a/src/coreclr/minipal/Unix/dn-u16.cpp b/src/coreclr/minipal/Unix/dn-u16.cpp index aec3fb1ae66388..688c313a61730f 100644 --- a/src/coreclr/minipal/Unix/dn-u16.cpp +++ b/src/coreclr/minipal/Unix/dn-u16.cpp @@ -7,11 +7,6 @@ typedef char16_t WCHAR; #include #include -size_t u16_strlen(const WCHAR* str) -{ - return minipal_u16_strlen((CHAR16_T*)str); -} - int u16_strcmp(const WCHAR* str1, const WCHAR* str2) { return u16_strncmp(str1, str2, 0x7fffffff); @@ -52,7 +47,7 @@ WCHAR* u16_strcat_s(WCHAR* dst, size_t dstLen, const WCHAR* src) } // concatenate new string - size_t srcLength = u16_strlen(src); + size_t srcLength = minipal_u16_strlen((const CHAR16_T*)src); size_t loopCount = 0; while (*src && loopCount < srcLength) { @@ -94,7 +89,7 @@ WCHAR* u16_strncpy_s(WCHAR* dst, size_t dstLen, const WCHAR* src, size_t count) { ::memset(dst, 0, dstLen * sizeof(WCHAR)); - size_t srcLength = u16_strlen(src); + size_t srcLength = minipal_u16_strlen((const CHAR16_T*)src); size_t length = (count < srcLength) ? count : srcLength; if (length > dstLen) return nullptr; @@ -111,7 +106,7 @@ const WCHAR* u16_strstr(const WCHAR *str, const WCHAR *strCharSet) } // No characters to examine - if (u16_strlen(strCharSet) == 0) + if (minipal_u16_strlen((const CHAR16_T*)strCharSet) == 0) return str; const WCHAR* ret = nullptr; diff --git a/src/coreclr/minipal/Windows/dn-u16.cpp b/src/coreclr/minipal/Windows/dn-u16.cpp index c915a8907bb1ca..54a43f9e7b98e0 100644 --- a/src/coreclr/minipal/Windows/dn-u16.cpp +++ b/src/coreclr/minipal/Windows/dn-u16.cpp @@ -6,11 +6,6 @@ #include -size_t u16_strlen(const WCHAR* str) -{ - return ::wcslen(str); -} - int u16_strcmp(const WCHAR* str1, const WCHAR* str2) { return ::wcscmp(str1, str2); diff --git a/src/coreclr/minipal/dn-u16.h b/src/coreclr/minipal/dn-u16.h index 73279aca16b6c2..0522b14358ce18 100644 --- a/src/coreclr/minipal/dn-u16.h +++ b/src/coreclr/minipal/dn-u16.h @@ -8,7 +8,6 @@ // Wide character (UTF-16) abstraction layer. // -size_t u16_strlen(const WCHAR* str); int u16_strcmp(const WCHAR* str1, const WCHAR* str2); int u16_strncmp(const WCHAR* str1, const WCHAR* str2, size_t count); WCHAR* u16_strcat_s(WCHAR* dst, size_t dstLen, const WCHAR* src); @@ -19,4 +18,4 @@ const WCHAR* u16_strchr(const WCHAR* str, WCHAR ch); const WCHAR* u16_strrchr(const WCHAR* str, WCHAR ch); uint32_t u16_strtoul(const WCHAR* nptr, WCHAR** endptr, int base); uint64_t u16_strtoui64(const WCHAR* nptr, WCHAR** endptr, int base); -double u16_strtod(const WCHAR* nptr, WCHAR** endptr); \ No newline at end of file +double u16_strtod(const WCHAR* nptr, WCHAR** endptr); diff --git a/src/coreclr/scripts/genEventPipe.py b/src/coreclr/scripts/genEventPipe.py index 469852cfc63d8d..64ddc54f6f436c 100644 --- a/src/coreclr/scripts/genEventPipe.py +++ b/src/coreclr/scripts/genEventPipe.py @@ -499,7 +499,7 @@ def getCoreCLREventPipeHelperFileImplPrefix(): bool WriteToBuffer(PCWSTR str, BYTE *&buffer, size_t& offset, size_t& size, bool &fixedBuffer) { if (!str) return true; - size_t byteCount = (u16_strlen(str) + 1) * sizeof(*str); + size_t byteCount = (minipal_u16_strlen((const CHAR16_T*)str) + 1) * sizeof(*str); if (offset + byteCount > size) { diff --git a/src/coreclr/tools/metainfo/mdobj.cpp b/src/coreclr/tools/metainfo/mdobj.cpp index 65cae4e7850a79..107325f8cfac72 100644 --- a/src/coreclr/tools/metainfo/mdobj.cpp +++ b/src/coreclr/tools/metainfo/mdobj.cpp @@ -255,7 +255,7 @@ void DisplayFile(_In_z_ WCHAR* szFile, BOOL isFile, ULONG DumpFilter, _In_opt_z_ // We need to make sure this file isn't too long. Checking _MAX_PATH is probably safe, but since we have a much // larger buffer, we might as well use it all. - if (u16_strlen(szFile) > 1000) + if (minipal_u16_strlen((const CHAR16_T*)szFile) > 1000) return; diff --git a/src/coreclr/tools/superpmi/mcs/verbmerge.cpp b/src/coreclr/tools/superpmi/mcs/verbmerge.cpp index 0ee42013119646..874e8610cc3860 100644 --- a/src/coreclr/tools/superpmi/mcs/verbmerge.cpp +++ b/src/coreclr/tools/superpmi/mcs/verbmerge.cpp @@ -20,8 +20,8 @@ RemoveDup verbMerge::m_removeDups; // static LPWSTR verbMerge::MergePathStrings(LPCWSTR dir, LPCWSTR file) { - size_t dirlen = u16_strlen(dir); - size_t filelen = u16_strlen(file); + size_t dirlen = minipal_u16_strlen((const CHAR16_T*)dir); + size_t filelen = minipal_u16_strlen((const CHAR16_T*)file); size_t newlen = dirlen + 1 /* slash */ + filelen + 1 /* null */; LPWSTR newpath = new WCHAR[newlen]; u16_strcpy_s(newpath, newlen, dir); @@ -352,14 +352,14 @@ int verbMerge::AppendAllInDir(HANDLE hFileOut, const _WIN32_FIND_DATAW& findData = fileArray[i]; LPWSTR fileFullPath = MergePathStrings(dir, findData.cFileName); #ifdef TARGET_WINDOWS - if (u16_strlen(fileFullPath) > MAX_PATH) // This path is too long, use \\?\ to access it. + if (minipal_u16_strlen((const CHAR16_T*)fileFullPath) > MAX_PATH) // This path is too long, use \\?\ to access it. { if (u16_strcmp(dir, W(".")) == 0) { LogError("can't access the relative path with UNC"); goto CLEAN_UP; } - size_t newBufferLen = u16_strlen(fileFullPath) + 30; + size_t newBufferLen = minipal_u16_strlen((const CHAR16_T*)fileFullPath) + 30; LPWSTR newBuffer = new WCHAR[newBufferLen]; u16_strcpy_s(newBuffer, newBufferLen, W("\\\\?\\")); if (*fileFullPath == '\\') // It is UNC path, use \\?\UNC\serverName to access it. diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 8455abdb80d61c..fd888a7c718d99 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -1268,7 +1268,7 @@ void MethodContext::recGetJitTimeLogFilename(LPCWSTR tempFileName) DWORD name_index = -1; if (tempFileName != nullptr) { - name_index = GetJitTimeLogFilename->AddBuffer((unsigned char*)tempFileName, (DWORD)u16_strlen(tempFileName) + 2); + name_index = GetJitTimeLogFilename->AddBuffer((unsigned char*)tempFileName, (DWORD)minipal_u16_strlen((const CHAR16_T*)tempFileName) + 2); } GetJitTimeLogFilename->Add(0, name_index); DEBUG_REC(dmpGetJitTimeLogFilename(0, name_index)); @@ -7089,7 +7089,7 @@ void MethodContext::recGetIntConfigValue(const WCHAR* name, int defaultValue, in ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding DWORD index = - (DWORD)GetIntConfigValue->AddBuffer((unsigned char*)name, sizeof(WCHAR) * ((unsigned int)u16_strlen(name) + 1)); + (DWORD)GetIntConfigValue->AddBuffer((unsigned char*)name, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)name) + 1)); key.nameIndex = index; key.defaultValue = defaultValue; @@ -7119,7 +7119,7 @@ int MethodContext::repGetIntConfigValue(const WCHAR* name, int defaultValue) Agnostic_ConfigIntInfo key; ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding - size_t nameLenInBytes = sizeof(WCHAR) * (u16_strlen(name) + 1); + size_t nameLenInBytes = sizeof(WCHAR) * (minipal_u16_strlen((const CHAR16_T*)name) + 1); int nameIndex = GetIntConfigValue->Contains((unsigned char*)name, (unsigned int)nameLenInBytes); if (nameIndex == -1) // config name not in map return defaultValue; @@ -7147,12 +7147,12 @@ void MethodContext::recGetStringConfigValue(const WCHAR* name, const WCHAR* resu AssertCodeMsg(name != nullptr, EXCEPTIONCODE_MC, "Name can not be nullptr"); DWORD nameIndex = (DWORD)GetStringConfigValue->AddBuffer((unsigned char*)name, - sizeof(WCHAR) * ((unsigned int)u16_strlen(name) + 1)); + sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)name) + 1)); DWORD resultIndex = (DWORD)-1; if (result != nullptr) resultIndex = (DWORD)GetStringConfigValue->AddBuffer((unsigned char*)result, - sizeof(WCHAR) * ((unsigned int)u16_strlen(result) + 1)); + sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)result) + 1)); GetStringConfigValue->Add(nameIndex, resultIndex); DEBUG_REC(dmpGetStringConfigValue(nameIndex, resultIndex)); @@ -7176,7 +7176,7 @@ const WCHAR* MethodContext::repGetStringConfigValue(const WCHAR* name) AssertCodeMsg(name != nullptr, EXCEPTIONCODE_MC, "Name can not be nullptr"); - size_t nameLenInBytes = sizeof(WCHAR) * (u16_strlen(name) + 1); + size_t nameLenInBytes = sizeof(WCHAR) * (minipal_u16_strlen((const CHAR16_T*)name) + 1); int nameIndex = GetStringConfigValue->Contains((unsigned char*)name, (unsigned int)nameLenInBytes); if (nameIndex == -1) // config name not in map return nullptr; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp b/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp index 9bba21b1bfd8e5..4db099f29c6a3c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp @@ -90,7 +90,7 @@ WCHAR* GetEnvironmentVariableWithDefaultW(const WCHAR* envVarName, const WCHAR* { if (defaultValue != nullptr) { - dwRetVal = (DWORD)u16_strlen(defaultValue) + 1; // add one for null terminator + dwRetVal = (DWORD)minipal_u16_strlen((const CHAR16_T*)defaultValue) + 1; // add one for null terminator retString = new WCHAR[dwRetVal]; memcpy_s(retString, dwRetVal * sizeof(WCHAR), defaultValue, dwRetVal * sizeof(WCHAR)); } @@ -190,8 +190,8 @@ void ReplaceIllegalCharacters(WCHAR* fileName) // All lengths in this function exclude the terminal NULL. WCHAR* GetResultFileName(const WCHAR* folderPath, const WCHAR* fileName, const WCHAR* extension) { - const size_t extensionLength = u16_strlen(extension); - const size_t fileNameLength = u16_strlen(fileName); + const size_t extensionLength = minipal_u16_strlen((const CHAR16_T*)extension); + const size_t fileNameLength = minipal_u16_strlen((const CHAR16_T*)fileName); const size_t randomStringLength = 8; const size_t maxPathLength = MAX_PATH - 50; diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp index a8f4046d83d660..2dfd9c6f9a83df 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp @@ -37,7 +37,7 @@ void SetDefaultPaths() if (g_DefaultRealJitPath == nullptr) { - size_t len = u16_strlen(g_HomeDirectory) + 1 + u16_strlen(DEFAULT_REAL_JIT_NAME_W) + 1; + size_t len = minipal_u16_strlen((const CHAR16_T*)g_HomeDirectory) + 1 + minipal_u16_strlen((const CHAR16_T*)DEFAULT_REAL_JIT_NAME_W) + 1; g_DefaultRealJitPath = new WCHAR[len]; wcscpy_s(g_DefaultRealJitPath, len, g_HomeDirectory); wcscat_s(g_DefaultRealJitPath, len, DIRECTORY_SEPARATOR_STR_W); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp index de3cac7cec4b6c..a9d0cf0eac8832 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp @@ -31,7 +31,7 @@ void SetDefaultPaths() if (g_DefaultRealJitPath == nullptr) { - size_t len = u16_strlen(g_HomeDirectory) + 1 + u16_strlen(DEFAULT_REAL_JIT_NAME_W) + 1; + size_t len = minipal_u16_strlen((const CHAR16_T*)g_HomeDirectory) + 1 + minipal_u16_strlen((const CHAR16_T*)DEFAULT_REAL_JIT_NAME_W) + 1; g_DefaultRealJitPath = new WCHAR[len]; wcscpy_s(g_DefaultRealJitPath, len, g_HomeDirectory); wcscat_s(g_DefaultRealJitPath, len, DIRECTORY_SEPARATOR_STR_W); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/superpmi-shim-simple.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/superpmi-shim-simple.cpp index 27fe53c8b4782f..3f8050b24b42b5 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/superpmi-shim-simple.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/superpmi-shim-simple.cpp @@ -29,7 +29,7 @@ void SetDefaultPaths() if (g_DefaultRealJitPath == nullptr) { - size_t len = u16_strlen(g_HomeDirectory) + 1 + u16_strlen(DEFAULT_REAL_JIT_NAME_W) + 1; + size_t len = minipal_u16_strlen((const CHAR16_T*)g_HomeDirectory) + 1 + minipal_u16_strlen((const CHAR16_T*)DEFAULT_REAL_JIT_NAME_W) + 1; g_DefaultRealJitPath = new WCHAR[len]; wcscpy_s(g_DefaultRealJitPath, len, g_HomeDirectory); wcscat_s(g_DefaultRealJitPath, len, DIRECTORY_SEPARATOR_STR_W); diff --git a/src/coreclr/tools/superpmi/superpmi/commandline.cpp b/src/coreclr/tools/superpmi/superpmi/commandline.cpp index ddd42e3a2e098b..62769662cbdcab 100644 --- a/src/coreclr/tools/superpmi/superpmi/commandline.cpp +++ b/src/coreclr/tools/superpmi/superpmi/commandline.cpp @@ -921,9 +921,9 @@ bool CommandLine::AddJitOption(int& currArgument, } DWORD keyIndex = - (DWORD)targetjitOptions->AddBuffer((unsigned char*)key, sizeof(WCHAR) * ((unsigned int)u16_strlen(key) + 1)); + (DWORD)targetjitOptions->AddBuffer((unsigned char*)key, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)key) + 1)); DWORD valueIndex = - (DWORD)targetjitOptions->AddBuffer((unsigned char*)value, sizeof(WCHAR) * ((unsigned int)u16_strlen(value) + 1)); + (DWORD)targetjitOptions->AddBuffer((unsigned char*)value, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)value) + 1)); targetjitOptions->Add(keyIndex, valueIndex); delete[] key; diff --git a/src/coreclr/tools/superpmi/superpmi/jitdebugger.cpp b/src/coreclr/tools/superpmi/superpmi/jitdebugger.cpp index e2878935ba45dd..e7d9941c38cc3a 100644 --- a/src/coreclr/tools/superpmi/superpmi/jitdebugger.cpp +++ b/src/coreclr/tools/superpmi/superpmi/jitdebugger.cpp @@ -154,9 +154,9 @@ HRESULT GetCurrentModuleFileName(_Out_writes_(*pcchBuffer) LPWSTR pBuffer, __ino // If no backslash, use the whole name; if there is a backslash, skip it. appName = appName ? appName + 1 : appPath; - if (*pcchBuffer < u16_strlen(appName)) + if (*pcchBuffer < minipal_u16_strlen((const CHAR16_T*)appName)) { - *pcchBuffer = static_cast(u16_strlen(appName)) + 1; + *pcchBuffer = static_cast(minipal_u16_strlen((const CHAR16_T*)appName)) + 1; return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } diff --git a/src/coreclr/tools/superpmi/superpmi/jithost.cpp b/src/coreclr/tools/superpmi/superpmi/jithost.cpp index 65d4513e276f34..72c4bc79bdc00d 100644 --- a/src/coreclr/tools/superpmi/superpmi/jithost.cpp +++ b/src/coreclr/tools/superpmi/superpmi/jithost.cpp @@ -12,7 +12,7 @@ WCHAR* GetPrefixedEnvironmentVariable(const WCHAR* prefix, size_t prefixLen, const WCHAR* key, JitInstance& jitInstance) { // Prepend prefix to the provided key - size_t keyLen = u16_strlen(key); + size_t keyLen = minipal_u16_strlen((const CHAR16_T*)key); size_t keyBufferLen = keyLen + prefixLen + 1; WCHAR* keyBuffer = reinterpret_cast(jitInstance.allocateArray(sizeof(WCHAR) * keyBufferLen)); @@ -178,7 +178,7 @@ const WCHAR* JitHost::getStringConfigValue(const WCHAR* key) if (result != nullptr && needToDup) { // Now we need to dup it, so you can call freeStringConfigValue() on what we return. - size_t resultLenInChars = u16_strlen(result) + 1; + size_t resultLenInChars = minipal_u16_strlen((const CHAR16_T*)result) + 1; WCHAR* dupResult = (WCHAR*)jitInstance.allocateLongLivedArray(sizeof(WCHAR) * resultLenInChars); wcscpy_s(dupResult, resultLenInChars, result); result = dupResult; diff --git a/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp b/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp index 2f085b2610d86b..b900624a9dd49d 100644 --- a/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp +++ b/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp @@ -527,7 +527,7 @@ const WCHAR* JitInstance::getOption(const WCHAR* key, LightWeightMapContains((unsigned char*)key, (unsigned int)keyLenInBytes); if (keyIndex == -1) { diff --git a/src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp b/src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp index 4da3f0f0561fbd..63392e7390c15e 100644 --- a/src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp +++ b/src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp @@ -30,9 +30,9 @@ static bool AddJitOption(LightWeightMap* map, char* newOption) } DWORD keyIndex = - (DWORD)map->AddBuffer((unsigned char*)key, sizeof(WCHAR) * ((unsigned int)u16_strlen(key) + 1)); + (DWORD)map->AddBuffer((unsigned char*)key, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)key) + 1)); DWORD valueIndex = - (DWORD)map->AddBuffer((unsigned char*)value, sizeof(WCHAR) * ((unsigned int)u16_strlen(value) + 1)); + (DWORD)map->AddBuffer((unsigned char*)value, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)value) + 1)); map->Add(keyIndex, valueIndex); delete[] key; diff --git a/src/coreclr/utilcode/ccomprc.cpp b/src/coreclr/utilcode/ccomprc.cpp index 10d1fd28f66d49..3367da18206e1a 100644 --- a/src/coreclr/utilcode/ccomprc.cpp +++ b/src/coreclr/utilcode/ccomprc.cpp @@ -136,7 +136,7 @@ HRESULT CCompRC::Init(LPCWSTR pResourceFile) { NewArrayHolder pwszResourceFile(NULL); - DWORD lgth = (DWORD) u16_strlen(pResourceFile) + 1; + DWORD lgth = (DWORD) minipal_u16_strlen((const CHAR16_T*)pResourceFile) + 1; pwszResourceFile = new(nothrow) WCHAR[lgth]; if (pwszResourceFile) { diff --git a/src/coreclr/utilcode/clrconfig.cpp b/src/coreclr/utilcode/clrconfig.cpp index b531018eb08ae1..21ba3393b92683 100644 --- a/src/coreclr/utilcode/clrconfig.cpp +++ b/src/coreclr/utilcode/clrconfig.cpp @@ -143,7 +143,7 @@ namespace WCHAR buff[64]; const WCHAR* fallbackPrefix = NULL; - const size_t namelen = u16_strlen(name); + const size_t namelen = minipal_u16_strlen((const CHAR16_T*)name); bool noPrefix = CheckLookupOption(options, LookupOptions::DontPrependPrefix); if (noPrefix) @@ -328,7 +328,7 @@ namespace *pwszTrimmed = NULL; // Get pointers into internal string that show where to do the trimming. - size_t cchOrig = u16_strlen(wszOrig); + size_t cchOrig = minipal_u16_strlen((const CHAR16_T*)wszOrig); if (!FitsIn(cchOrig)) return COR_E_OVERFLOW; DWORD cchAfterTrim = (DWORD) cchOrig; diff --git a/src/coreclr/utilcode/guidfromname.cpp b/src/coreclr/utilcode/guidfromname.cpp index 7c230c977f17cd..1587b3d28eabf4 100644 --- a/src/coreclr/utilcode/guidfromname.cpp +++ b/src/coreclr/utilcode/guidfromname.cpp @@ -206,5 +206,5 @@ void CorGuidFromNameW pGuidResult, COMPLUS_RUNTIME_GUID, wzName, - (DWORD)((cchName == (SIZE_T) -1 ? (u16_strlen(wzName)+1) : cchName) * sizeof(WCHAR))); + (DWORD)((cchName == (SIZE_T) -1 ? (minipal_u16_strlen((const CHAR16_T*)wzName)+1) : cchName) * sizeof(WCHAR))); } diff --git a/src/coreclr/utilcode/log.cpp b/src/coreclr/utilcode/log.cpp index 56ddf6aef9c20e..e1805727ab1328 100644 --- a/src/coreclr/utilcode/log.cpp +++ b/src/coreclr/utilcode/log.cpp @@ -66,7 +66,7 @@ VOID InitLogging() LPWSTR fileName = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogFile); if (fileName != 0) { - if (SUCCEEDED(szLogFileName.ReSizeNoThrow(u16_strlen(fileName) + 32))) + if (SUCCEEDED(szLogFileName.ReSizeNoThrow(minipal_u16_strlen((const CHAR16_T*)fileName) + 32))) { wcscpy_s(szLogFileName.Ptr(), szLogFileName.Size(), fileName); } @@ -98,9 +98,9 @@ VOID InitLogging() NULL); // Some other logging may be going on, try again with another file name - if (LogFileHandle == INVALID_HANDLE_VALUE && u16_strlen(szLogFileName.Ptr()) + 3 <= szLogFileName.Size()) + if (LogFileHandle == INVALID_HANDLE_VALUE && minipal_u16_strlen((const CHAR16_T*)szLogFileName.Ptr()) + 3 <= szLogFileName.Size()) { - WCHAR* ptr = szLogFileName.Ptr() + u16_strlen(szLogFileName.Ptr()) + 1; + WCHAR* ptr = szLogFileName.Ptr() + minipal_u16_strlen((const CHAR16_T*)szLogFileName.Ptr()) + 1; ptr[-1] = W('.'); ptr[0] = W('0'); ptr[1] = 0; diff --git a/src/coreclr/utilcode/longfilepathwrappers.cpp b/src/coreclr/utilcode/longfilepathwrappers.cpp index 09e3118fc8fe05..8316f8541f60fb 100644 --- a/src/coreclr/utilcode/longfilepathwrappers.cpp +++ b/src/coreclr/utilcode/longfilepathwrappers.cpp @@ -530,7 +530,7 @@ HRESULT LongFile::NormalizePath(SString & path) //In this case if path is \\server the extended syntax should be like \\?\UNC\server //The below logic populates the path from prefixLen offset from the start. This ensures that first 2 characters are overwritten // - prefixLen = prefix.GetCount() - (COUNT_T)u16_strlen(UNCPATHPREFIX); + prefixLen = prefix.GetCount() - (COUNT_T)minipal_u16_strlen((const CHAR16_T*)UNCPATHPREFIX); _ASSERTE(prefixLen > 0 ); } @@ -574,10 +574,10 @@ HRESULT LongFile::NormalizePath(SString & path) SString fullpath(SString::Literal,buffer + prefixLen); //Check if the resolved path is a UNC. By default we assume relative path to resolve to disk - if (fullpath.BeginsWith(SL(UNCPathPrefix)) && prefixLen != prefix.GetCount() - (COUNT_T)u16_strlen(UNCPATHPREFIX)) + if (fullpath.BeginsWith(SL(UNCPathPrefix)) && prefixLen != prefix.GetCount() - (COUNT_T)minipal_u16_strlen((const CHAR16_T*)UNCPATHPREFIX)) { //Remove the leading '\\' from the UNC path to be replaced with UNCExtendedPathPrefix - fullpath.Replace(fullpath.Begin(), (COUNT_T)u16_strlen(UNCPATHPREFIX), SL(UNCExtendedPathPrefix)); + fullpath.Replace(fullpath.Begin(), (COUNT_T)minipal_u16_strlen((const CHAR16_T*)UNCPATHPREFIX), SL(UNCExtendedPathPrefix)); path.CloseBuffer(); path.Set(fullpath); } diff --git a/src/coreclr/utilcode/namespaceutil.cpp b/src/coreclr/utilcode/namespaceutil.cpp index c17b07abae3ab5..373879dd321fe5 100644 --- a/src/coreclr/utilcode/namespaceutil.cpp +++ b/src/coreclr/utilcode/namespaceutil.cpp @@ -35,9 +35,9 @@ int ns::GetFullLength( // Number of chars in full name. int iLen = 1; // Null terminator. if (szNameSpace) - iLen += (int)u16_strlen(szNameSpace); + iLen += (int)minipal_u16_strlen((const CHAR16_T*)szNameSpace); if (szName) - iLen += (int)u16_strlen(szName); + iLen += (int)minipal_u16_strlen((const CHAR16_T*)szName); if (szNameSpace && *szNameSpace && szName && *szName) ++iLen; return iLen; @@ -186,7 +186,7 @@ int ns::SplitPath( // true ok, false trunction. ++ptr; else ptr = szPath; - iLen = (int)u16_strlen(ptr); + iLen = (int)minipal_u16_strlen((const CHAR16_T*)ptr); iCopyMax = min(iCopyMax, iLen); wcsncpy_s(szName, cchName, ptr, iCopyMax); szName[iCopyMax] = 0; diff --git a/src/coreclr/utilcode/pedecoder.cpp b/src/coreclr/utilcode/pedecoder.cpp index fd44a050d36eec..011598139d281b 100644 --- a/src/coreclr/utilcode/pedecoder.cpp +++ b/src/coreclr/utilcode/pedecoder.cpp @@ -1756,7 +1756,7 @@ DWORD ReadResourceDirectory(const PEDecoder *pDecoder, DWORD rvaOfResourceSectio return 0; size_t entryNameLen = *(WORD*)pDecoder->GetRvaData(entryNameRva); - if (u16_strlen(name) != entryNameLen) + if (minipal_u16_strlen((const CHAR16_T*)name) != entryNameLen) continue; if (!pDecoder->CheckRva(entryNameRva, (COUNT_T)(sizeof(WORD) * (1 + entryNameLen)))) diff --git a/src/coreclr/utilcode/posterror.cpp b/src/coreclr/utilcode/posterror.cpp index c2a959a9a4381b..58119ff9f2f04e 100644 --- a/src/coreclr/utilcode/posterror.cpp +++ b/src/coreclr/utilcode/posterror.cpp @@ -149,7 +149,7 @@ static HRESULT FormatRuntimeErrorVA( hr = S_OK; // System messages contain a trailing \r\n, which we don't want normally. - size_t iLen = u16_strlen(rcMsg); + size_t iLen = minipal_u16_strlen((const CHAR16_T*)rcMsg); if (iLen > 3 && rcMsg[iLen - 2] == '\r' && rcMsg[iLen - 1] == '\n') rcMsg[iLen - 2] = '\0'; } diff --git a/src/coreclr/utilcode/prettyprintsig.cpp b/src/coreclr/utilcode/prettyprintsig.cpp index 31f6a93c4a194b..b07c56753c8508 100644 --- a/src/coreclr/utilcode/prettyprintsig.cpp +++ b/src/coreclr/utilcode/prettyprintsig.cpp @@ -65,7 +65,7 @@ static HRESULT appendStrW(CQuickBytes *out, const WCHAR* str) } CONTRACTL_END - SIZE_T len = u16_strlen(str) * sizeof(WCHAR); + SIZE_T len = minipal_u16_strlen((const CHAR16_T*)str) * sizeof(WCHAR); SIZE_T oldSize = out->Size(); if (FAILED(out->ReSizeNoThrow(oldSize + len))) return E_OUTOFMEMORY; diff --git a/src/coreclr/utilcode/splitpath.cpp b/src/coreclr/utilcode/splitpath.cpp index 40619f17230a63..d69abfa2522a38 100644 --- a/src/coreclr/utilcode/splitpath.cpp +++ b/src/coreclr/utilcode/splitpath.cpp @@ -86,7 +86,7 @@ void SplitPathInterior( /* extract drive letter and :, if any */ - if ((u16_strlen(wszPath) > (_MAX_DRIVE - 2)) && (*(wszPath + _MAX_DRIVE - 2) == _T(':'))) { + if ((minipal_u16_strlen((const CHAR16_T*)wszPath) > (_MAX_DRIVE - 2)) && (*(wszPath + _MAX_DRIVE - 2) == _T(':'))) { if (pwszDrive && pcchDrive) { *pwszDrive = wszPath; *pcchDrive = _MAX_DRIVE - 1; diff --git a/src/coreclr/utilcode/sstring.cpp b/src/coreclr/utilcode/sstring.cpp index 2fb454c369cab4..3adab615b29a87 100644 --- a/src/coreclr/utilcode/sstring.cpp +++ b/src/coreclr/utilcode/sstring.cpp @@ -244,7 +244,7 @@ void SString::Set(const WCHAR *string) Clear(); else { - Resize((COUNT_T) u16_strlen(string), REPRESENTATION_UNICODE); + Resize((COUNT_T) minipal_u16_strlen((const CHAR16_T*)string), REPRESENTATION_UNICODE); wcscpy_s(GetRawUnicode(), GetBufferSizeInCharIncludeNullChar(), string); } diff --git a/src/coreclr/utilcode/sstring_com.cpp b/src/coreclr/utilcode/sstring_com.cpp index b674556741fcb5..ca5aa1d227e7ef 100644 --- a/src/coreclr/utilcode/sstring_com.cpp +++ b/src/coreclr/utilcode/sstring_com.cpp @@ -73,7 +73,7 @@ HRESULT SString::LoadResourceAndReturnHR(CCompRC::ResourceCategory eCategory, in if (SUCCEEDED(hr)) { - Truncate(Begin() + (COUNT_T) u16_strlen(GetRawUnicode())); + Truncate(Begin() + (COUNT_T) minipal_u16_strlen((const CHAR16_T*)GetRawUnicode())); } Normalize(); diff --git a/src/coreclr/utilcode/stresslog.cpp b/src/coreclr/utilcode/stresslog.cpp index aa3cbcfce70cef..652b83e5ff5cf9 100644 --- a/src/coreclr/utilcode/stresslog.cpp +++ b/src/coreclr/utilcode/stresslog.cpp @@ -177,11 +177,11 @@ void ReplacePid(LPCWSTR original, LPWSTR replaced, size_t replacedLength) wcscat_s(replaced, replacedLength, pidStr); // append the rest of the filename - wcscat_s(replaced, replacedLength, original + pidInx + u16_strlen(pidLit)); + wcscat_s(replaced, replacedLength, original + pidInx + minipal_u16_strlen((const CHAR16_T*)pidLit)); } else { - size_t originalLength = u16_strlen(original); + size_t originalLength = minipal_u16_strlen((const CHAR16_T*)original); wcsncpy_s(replaced, replacedLength, original, originalLength); } } diff --git a/src/coreclr/utilcode/util.cpp b/src/coreclr/utilcode/util.cpp index 01d03df5da050d..26d04b94bf42f9 100644 --- a/src/coreclr/utilcode/util.cpp +++ b/src/coreclr/utilcode/util.cpp @@ -221,7 +221,7 @@ namespace if (phmodDll != nullptr) *phmodDll = nullptr; - bool fIsDllPathPrefix = (wszDllPath != nullptr) && (u16_strlen(wszDllPath) > 0) && (wszDllPath[u16_strlen(wszDllPath) - 1] == W('\\')); + bool fIsDllPathPrefix = (wszDllPath != nullptr) && (minipal_u16_strlen((const CHAR16_T*)wszDllPath) > 0) && (wszDllPath[minipal_u16_strlen((const CHAR16_T*)wszDllPath) - 1] == W('\\')); // - An empty string will be treated as NULL. // - A string ending will a backslash will be treated as a prefix for where to look for the DLL @@ -2619,7 +2619,7 @@ namespace Reg // terminating NULL is not a legitimate scenario for REG_SZ - this must // be done using REG_MULTI_SZ - however this was tolerated in the // past and so it would be a breaking change to stop doing so. - _ASSERTE(u16_strlen(wszValueBuf) <= (size / sizeof(WCHAR)) - 1); + _ASSERTE(minipal_u16_strlen((const CHAR16_T*)wszValueBuf) <= (size / sizeof(WCHAR)) - 1); ssValue.CloseBuffer((COUNT_T)wcsnlen(wszValueBuf, (size_t)size)); } else diff --git a/src/coreclr/utilcode/util_nodependencies.cpp b/src/coreclr/utilcode/util_nodependencies.cpp index 3a08158b0daadb..d15c7286f668d1 100644 --- a/src/coreclr/utilcode/util_nodependencies.cpp +++ b/src/coreclr/utilcode/util_nodependencies.cpp @@ -621,7 +621,7 @@ LPCWSTRToGuid( // covering the 128-bit GUID. The string includes enclosing braces, which are an OLE convention. // Verify the surrounding syntax. - if (u16_strlen(szGuid) != 38 || szGuid[0] != '{' || szGuid[9] != '-' || + if (minipal_u16_strlen((const CHAR16_T*)szGuid) != 38 || szGuid[0] != '{' || szGuid[9] != '-' || szGuid[14] != '-' || szGuid[19] != '-' || szGuid[24] != '-' || szGuid[37] != '}') { return FALSE; diff --git a/src/coreclr/utilcode/winfix.cpp b/src/coreclr/utilcode/winfix.cpp index 9738475350c94b..1951ac5cc1bc54 100644 --- a/src/coreclr/utilcode/winfix.cpp +++ b/src/coreclr/utilcode/winfix.cpp @@ -30,7 +30,7 @@ WszCreateProcess( BOOL fResult; DWORD err; { - size_t commandLineLength = u16_strlen(lpCommandLine) + 1; + size_t commandLineLength = minipal_u16_strlen((const CHAR16_T*)lpCommandLine) + 1; NewArrayHolder nonConstCommandLine(new (nothrow) WCHAR[commandLineLength]); if (nonConstCommandLine == NULL) { diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index ce933c43739a11..cc90cac90af383 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -2975,7 +2975,7 @@ void AppDomain::AddUnmanagedImageToCache(LPCWSTR libraryName, NATIVE_LIBRARY_HAN return; } - size_t len = (u16_strlen(libraryName) + 1) * sizeof(WCHAR); + size_t len = (minipal_u16_strlen((const CHAR16_T*)libraryName) + 1) * sizeof(WCHAR); AllocMemHolder copiedName(GetLowFrequencyHeap()->AllocMem(S_SIZE_T(len))); memcpy(copiedName, libraryName, len); diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 6309f9bfcb10c6..77e4f0d1cb7d7d 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -1043,12 +1043,12 @@ void Assembly::AddDiagnosticStartupHookPath(LPCWSTR wszPath) { LPCWSTR wszDiagnosticStartupHookPathsLocal = s_wszDiagnosticStartupHookPaths; - size_t cchPath = u16_strlen(wszPath); + size_t cchPath = minipal_u16_strlen((const CHAR16_T*)wszPath); size_t cchDiagnosticStartupHookPathsNew = cchPath; size_t cchDiagnosticStartupHookPathsLocal = 0; if (nullptr != wszDiagnosticStartupHookPathsLocal) { - cchDiagnosticStartupHookPathsLocal = u16_strlen(wszDiagnosticStartupHookPathsLocal); + cchDiagnosticStartupHookPathsLocal = minipal_u16_strlen((const CHAR16_T*)wszDiagnosticStartupHookPathsLocal); // Add 1 for the path separator cchDiagnosticStartupHookPathsNew += cchDiagnosticStartupHookPathsLocal + 1; } diff --git a/src/coreclr/vm/autotrace.cpp b/src/coreclr/vm/autotrace.cpp index c41d55537f5f70..023fe40c23eec0 100644 --- a/src/coreclr/vm/autotrace.cpp +++ b/src/coreclr/vm/autotrace.cpp @@ -50,7 +50,7 @@ void auto_trace_init() // Copy in the command - %s wcscpy_s(command, bufferLen, commandTextValue); - written += u16_strlen(commandTextValue); + written += minipal_u16_strlen((const CHAR16_T*)commandTextValue); // Append " -p " wcscat_s(command, bufferLen - written, flagFormat); diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index f4d075b126e139..01539e12da4217 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -3668,7 +3668,7 @@ void Append_Next_Item(LPWSTR* ppCursor, SIZE_T* pRemainingLen, LPCWSTR pItem, bo SIZE_T remainingLen = *pRemainingLen; // Calculate the length of pItem - SIZE_T itemLen = u16_strlen(pItem); + SIZE_T itemLen = minipal_u16_strlen((const CHAR16_T*)pItem); // Append pItem at pCursor wcscpy_s(pCursor, remainingLen, pItem); @@ -3708,14 +3708,14 @@ void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) #else // On UNIX, the PAL doesn't have the command line arguments, so we must build the command line. // osCommandLine contains the full path to the executable. - SIZE_T commandLineLen = (u16_strlen(osCommandLine) + 1); + SIZE_T commandLineLen = (minipal_u16_strlen((const CHAR16_T*)osCommandLine) + 1); // We will append pwzAssemblyPath to the 'corerun' osCommandLine - commandLineLen += (u16_strlen(pwzAssemblyPath) + 1); + commandLineLen += (minipal_u16_strlen((const CHAR16_T*)pwzAssemblyPath) + 1); for (int i = 0; i < argc; i++) { - commandLineLen += (u16_strlen(argv[i]) + 1); + commandLineLen += (minipal_u16_strlen((const CHAR16_T*)argv[i]) + 1); } commandLineLen++; // Add 1 for the null-termination diff --git a/src/coreclr/vm/commtmemberinfomap.cpp b/src/coreclr/vm/commtmemberinfomap.cpp index a451e96287c1fe..bc93983e7ef2e6 100644 --- a/src/coreclr/vm/commtmemberinfomap.cpp +++ b/src/coreclr/vm/commtmemberinfomap.cpp @@ -332,7 +332,7 @@ void ComMTMemberInfoMap::SetupPropsForIClassX(size_t sizeOfPtr) IfFailThrow(pField->GetMDImport()->GetNameOfFieldDef(pField->GetMemberDef(), &pszName)); IfFailThrow(Utf2Quick(pszName, rName)); - ULONG cchpName = ((int)u16_strlen(rName.Ptr())) + 1; + ULONG cchpName = ((int)minipal_u16_strlen((const CHAR16_T*)rName.Ptr())) + 1; m_MethodProps[i].pName = reinterpret_cast(m_sNames.Alloc(cchpName * sizeof(WCHAR))); m_MethodProps[i].pMeth = (MethodDesc*)pFieldMeth; @@ -451,12 +451,12 @@ void ComMTMemberInfoMap::SetupPropsForIClassX(size_t sizeOfPtr) WCHAR *pNewName; //string length + "get" + null terminator. //XXX Fri 11/19/2004 Why is this + 4 rather than +3? - ULONG cchpNewName = ((int)u16_strlen(m_MethodProps[ixGet].pName)) + 4 + 1; + ULONG cchpNewName = ((int)minipal_u16_strlen((const CHAR16_T*)m_MethodProps[ixGet].pName)) + 4 + 1; pNewName = reinterpret_cast(m_sNames.Alloc(cchpNewName * sizeof(WCHAR))); wcscpy_s(pNewName, cchpNewName, W("get")); wcscat_s(pNewName, cchpNewName, m_MethodProps[ixGet].pName); m_MethodProps[ixGet].pName = pNewName; - pNewName = reinterpret_cast(m_sNames.Alloc((int)((4+u16_strlen(m_MethodProps[ixSet].pName))*sizeof(WCHAR)+2))); + pNewName = reinterpret_cast(m_sNames.Alloc((int)((4+minipal_u16_strlen((const CHAR16_T*)m_MethodProps[ixSet].pName))*sizeof(WCHAR)+2))); wcscpy_s(pNewName, cchpNewName, W("set")); wcscat_s(pNewName, cchpNewName, m_MethodProps[ixSet].pName); m_MethodProps[ixSet].pName = pNewName; @@ -775,7 +775,7 @@ void ComMTMemberInfoMap::GetMethodPropsForMeth( } } - ULONG len = ((int)u16_strlen(pName)) + 1; + ULONG len = ((int)minipal_u16_strlen((const CHAR16_T*)pName)) + 1; rProps[ix].pName = reinterpret_cast(sNames.Alloc(len * sizeof(WCHAR))); if (rProps[ix].pName == NULL) { @@ -896,7 +896,7 @@ void ComMTMemberInfoMap::EliminateDuplicateNames( if (bDup) { // Duplicate. - DWORD cchName = (DWORD) u16_strlen(rProps[iCur].pName); + DWORD cchName = (DWORD) minipal_u16_strlen((const CHAR16_T*)rProps[iCur].pName); if (cchName > MAX_CLASSNAME_LENGTH-cchDuplicateDecoration) cchName = MAX_CLASSNAME_LENGTH-cchDuplicateDecoration; @@ -925,7 +925,7 @@ void ComMTMemberInfoMap::EliminateDuplicateNames( } // Remember the new name. - ULONG len = ((int)u16_strlen(rcName)) + 1; + ULONG len = ((int)minipal_u16_strlen((const CHAR16_T*)rcName)) + 1; rProps[iCur].pName = reinterpret_cast(sNames.Alloc(len * sizeof(WCHAR))); if (rProps[iCur].pName == NULL) { @@ -989,7 +989,7 @@ void ComMTMemberInfoMap::EliminateDuplicateNames( iCur = piTable[i]; // Copy name into local buffer - DWORD cchName = (DWORD) u16_strlen(rProps[iCur].pName); + DWORD cchName = (DWORD) minipal_u16_strlen((const CHAR16_T*)rProps[iCur].pName); if (cchName > MAX_CLASSNAME_LENGTH-cchDuplicateDecoration) cchName = MAX_CLASSNAME_LENGTH-cchDuplicateDecoration; @@ -1007,7 +1007,7 @@ void ComMTMemberInfoMap::EliminateDuplicateNames( } while (htNames.Find(rcName) != NULL); // Now rcName has an acceptable (unique) name. Remember the new name. - ULONG len = ((int)u16_strlen(rcName)) + 1; + ULONG len = ((int)minipal_u16_strlen((const CHAR16_T*)rcName)) + 1; rProps[iCur].pName = reinterpret_cast(sNames.Alloc(len * sizeof(WCHAR))); if (rProps[iCur].pName == NULL) { diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index 990eb02b00dc86..e325b4399ffa3a 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -313,7 +313,7 @@ HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId, if (g_EntryAssemblyPath == NULL) { // Store the entry assembly path for diagnostic purposes (for example, dumps) - size_t len = u16_strlen(pwzAssemblyPath) + 1; + size_t len = minipal_u16_strlen((const CHAR16_T*)pwzAssemblyPath) + 1; NewArrayHolder path { new WCHAR[len] }; wcscpy_s(path, len, pwzAssemblyPath); g_EntryAssemblyPath = path.Extract(); diff --git a/src/coreclr/vm/debugdebugger.cpp b/src/coreclr/vm/debugdebugger.cpp index a77dd524d6eaf5..34793d4212ad5b 100644 --- a/src/coreclr/vm/debugdebugger.cpp +++ b/src/coreclr/vm/debugdebugger.cpp @@ -156,7 +156,7 @@ extern "C" void QCALLTYPE DebugDebugger_Log(INT32 Level, PCWSTR pwzModule, PCWST if (pwzModule != NULL) { // truncate if necessary - COUNT_T iLen = (COUNT_T) u16_strlen(pwzModule); + COUNT_T iLen = (COUNT_T) minipal_u16_strlen((const CHAR16_T*)pwzModule); if (iLen > MAX_LOG_SWITCH_NAME_LEN) { iLen = MAX_LOG_SWITCH_NAME_LEN; @@ -167,7 +167,7 @@ extern "C" void QCALLTYPE DebugDebugger_Log(INT32 Level, PCWSTR pwzModule, PCWST SString message; if (pwzMessage != NULL) { - message.Set(pwzMessage, (COUNT_T) u16_strlen(pwzMessage)); + message.Set(pwzMessage, (COUNT_T) minipal_u16_strlen((const CHAR16_T*)pwzMessage)); } g_pDebugInterface->SendLogMessage (Level, &switchName, &message); diff --git a/src/coreclr/vm/dispatchinfo.cpp b/src/coreclr/vm/dispatchinfo.cpp index e1538a8c6c4548..4dd98b29f5be2c 100644 --- a/src/coreclr/vm/dispatchinfo.cpp +++ b/src/coreclr/vm/dispatchinfo.cpp @@ -525,7 +525,7 @@ LPWSTR DispatchMemberInfo::GetMemberName(OBJECTREF MemberInfoObj, ComMTMemberInf // If we managed to get the member's properties then extract the name. if (pMemberProps) { - int MemberNameLen = (INT)u16_strlen(pMemberProps->pName); + int MemberNameLen = (INT)minipal_u16_strlen((const CHAR16_T*)pMemberProps->pName); strMemberName = new WCHAR[MemberNameLen + 1]; memcpy(strMemberName, pMemberProps->pName, (MemberNameLen + 1) * sizeof(WCHAR)); diff --git a/src/coreclr/vm/dwbucketmanager.hpp b/src/coreclr/vm/dwbucketmanager.hpp index dec761a97e5ed3..03f627498c18f7 100644 --- a/src/coreclr/vm/dwbucketmanager.hpp +++ b/src/coreclr/vm/dwbucketmanager.hpp @@ -1027,7 +1027,7 @@ int BaseBucketParamsManager::CopyStringToBucket(_Out_writes_(targetMaxLength) LP 0 }; - int srcLen = static_cast(u16_strlen(pSource)); + int srcLen = static_cast(minipal_u16_strlen((const CHAR16_T*)pSource)); // If the source contains unicode characters, they'll be encoded at 4 chars per char. int targLen = ContainsUnicodeChars(pSource) ? targetMaxLength / 4 : targetMaxLength; @@ -1038,7 +1038,7 @@ int BaseBucketParamsManager::CopyStringToBucket(_Out_writes_(targetMaxLength) LP for (int i = 0; truncations[i]; ++i) { // how long is this suffix? - int slen = static_cast(u16_strlen(truncations[i])); + int slen = static_cast(minipal_u16_strlen((const CHAR16_T*)truncations[i])); // Could the string have this suffix? if (slen < srcLen) @@ -1069,7 +1069,7 @@ int BaseBucketParamsManager::CopyStringToBucket(_Out_writes_(targetMaxLength) LP // String didn't fit, so hash it. SHA1Hash hash; - hash.AddData(reinterpret_cast(const_cast(pSource)), (static_cast(u16_strlen(pSource))) * sizeof(WCHAR)); + hash.AddData(reinterpret_cast(const_cast(pSource)), (static_cast(minipal_u16_strlen((const CHAR16_T*)pSource))) * sizeof(WCHAR)); // Encode in base32. The hash is a fixed size; we'll accept up to maxLen characters of the encoding. BytesToBase32 b32(hash.GetHash(), SHA1_HASH_SIZE); diff --git a/src/coreclr/vm/eehash.cpp b/src/coreclr/vm/eehash.cpp index 4bd014e5dc3b0f..7f083c44b9d800 100644 --- a/src/coreclr/vm/eehash.cpp +++ b/src/coreclr/vm/eehash.cpp @@ -277,7 +277,7 @@ EEHashEntry_t *EEClassFactoryInfoHashTableHelper::AllocateEntry(ClassFactoryInfo _ASSERTE(bDeepCopy && "Non deep copy is not supported by the EEComCompInfoHashTableHelper"); if (pKey->m_strServerName) - cbStringLen = (S_SIZE_T(u16_strlen(pKey->m_strServerName)) + S_SIZE_T(1)) * S_SIZE_T(sizeof(WCHAR)); + cbStringLen = (S_SIZE_T(minipal_u16_strlen((const CHAR16_T*)pKey->m_strServerName)) + S_SIZE_T(1)) * S_SIZE_T(sizeof(WCHAR)); S_SIZE_T cbEntry = S_SIZE_T(SIZEOF_EEHASH_ENTRY + sizeof(ClassFactoryInfo)) + cbStringLen; diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 4efbb9f8964b28..a7c310846de7d4 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -1447,7 +1447,7 @@ ep_rt_utf16_string_len (const ep_char16_t *str) STATIC_CONTRACT_NOTHROW; EP_ASSERT (str != NULL); - return u16_strlen (reinterpret_cast(str)); + return minipal_u16_strlen (str); } static diff --git a/src/coreclr/vm/eventtrace.cpp b/src/coreclr/vm/eventtrace.cpp index 535a44f96dffb7..553c6fa42e150d 100644 --- a/src/coreclr/vm/eventtrace.cpp +++ b/src/coreclr/vm/eventtrace.cpp @@ -4355,7 +4355,7 @@ VOID ETW::LoaderLog::SendModuleEvent(Module *pModule, DWORD dwEventOptions, BOOL } // if we do not have a module path yet, we put the module name - if(bIsDynamicAssembly || ModuleILPath==NULL || u16_strlen(ModuleILPath) <= 2) + if(bIsDynamicAssembly || ModuleILPath==NULL || minipal_u16_strlen((const CHAR16_T*)ModuleILPath) <= 2) { moduleName.SetUTF8(pModule->GetSimpleName()); ModuleILPath = (PWCHAR)moduleName.GetUnicode(); diff --git a/src/coreclr/vm/gdbjit.cpp b/src/coreclr/vm/gdbjit.cpp index 672cbdb0300939..1607113ca6129a 100644 --- a/src/coreclr/vm/gdbjit.cpp +++ b/src/coreclr/vm/gdbjit.cpp @@ -1846,8 +1846,8 @@ static inline bool isListedModule(const WCHAR *wszModuleFile) } if (isUserDebug == FALSE) { - u16_strncpy_s(wszModuleName, g_cBytesNeeded, tmp, u16_strlen(tmp)); - wszModuleName[u16_strlen(tmp)] = W('\0'); + u16_strncpy_s(wszModuleName, g_cBytesNeeded, tmp, minipal_u16_strlen((const CHAR16_T*)tmp)); + wszModuleName[minipal_u16_strlen((const CHAR16_T*)tmp)] = W('\0'); if (u16_strcmp(wszModuleName, wszModuleFile) == 0) { isUserDebug = TRUE; @@ -2570,7 +2570,7 @@ void NotifyGdb::OnMethodPrepared(MethodDesc* methodDescPtr) if (pNIExt) { - u16_strcpy_s(pNIExt, u16_strlen(pNIExt) + 1, W(".dll")); + u16_strcpy_s(pNIExt, minipal_u16_strlen((const CHAR16_T*)pNIExt) + 1, W(".dll")); } if (isListedModule(wszModuleFile)) diff --git a/src/coreclr/vm/genanalysis.cpp b/src/coreclr/vm/genanalysis.cpp index 048e6470ebdf24..ffcfbc05b6f542 100644 --- a/src/coreclr/vm/genanalysis.cpp +++ b/src/coreclr/vm/genanalysis.cpp @@ -28,7 +28,7 @@ bool gcGenAnalysisDump = false; { // Get the managed command line. LPCWSTR pCmdLine = GetCommandLineForDiagnostics(); - match = u16_strncmp(pCmdLine, gcGenAnalysisCmd, u16_strlen(gcGenAnalysisCmd)) == 0; + match = u16_strncmp(pCmdLine, gcGenAnalysisCmd, minipal_u16_strlen((CHAR16_T*)(char16_t*)gcGenAnalysisCmd)) == 0; } if (match && !CLRConfig::IsConfigOptionSpecified(W("GCGenAnalysisGen"))) { diff --git a/src/coreclr/vm/ilmarshalers.cpp b/src/coreclr/vm/ilmarshalers.cpp index 1726c63ece42a9..0e752c278f4c5d 100644 --- a/src/coreclr/vm/ilmarshalers.cpp +++ b/src/coreclr/vm/ilmarshalers.cpp @@ -816,7 +816,7 @@ void ILWSTRBufferMarshaler::EmitConvertSpaceNativeToCLR(ILCodeStream* pslILEmit) if (IsIn(m_dwMarshalFlags) || IsCLRToNative(m_dwMarshalFlags)) { EmitLoadNativeValue(pslILEmit); - // static int System.String.u16_strlen(char *ptr) + // static int System.String.minipal_u16_strlen((const CHAR16_T*)char *ptr) pslILEmit->EmitCALL(METHOD__STRING__WCSLEN, 1, 1); } else @@ -845,7 +845,7 @@ void ILWSTRBufferMarshaler::EmitConvertContentsNativeToCLR(ILCodeStream* pslILEm EmitLoadNativeValue(pslILEmit); pslILEmit->EmitDUP(); - // static int System.String.u16_strlen(char *ptr) + // static int System.String.minipal_u16_strlen((const CHAR16_T*)char *ptr) pslILEmit->EmitCALL(METHOD__STRING__WCSLEN, 1, 1); // void System.Text.StringBuilder.ReplaceBuffer(char* newBuffer, int newLength); diff --git a/src/coreclr/vm/interoputil.cpp b/src/coreclr/vm/interoputil.cpp index 1dc64e79b9e7e5..d53fc2c72df02e 100644 --- a/src/coreclr/vm/interoputil.cpp +++ b/src/coreclr/vm/interoputil.cpp @@ -539,7 +539,7 @@ SIZE_T GetStringizedItfDef(TypeHandle InterfaceType, CQuickArray &rDef) DefineFullyQualifiedNameForClassW(); szName = GetFullyQualifiedNameForClassNestedAwareW(pIntfMT); - cchName = (ULONG)u16_strlen(szName); + cchName = (ULONG)minipal_u16_strlen((const CHAR16_T*)szName); // Start with the interface name. cbCur = cchName * sizeof(WCHAR); @@ -2274,7 +2274,7 @@ ULONG GetStringizedClassItfDef(TypeHandle InterfaceType, CQuickArray &rDef // Get the name of the class. DefineFullyQualifiedNameForClassW(); szName = GetFullyQualifiedNameForClassNestedAwareW(pIntfMT); - cchName = (ULONG)u16_strlen(szName); + cchName = (ULONG)minipal_u16_strlen((const CHAR16_T*)szName); // Start with the interface name. cbCur = cchName * sizeof(WCHAR); @@ -3558,7 +3558,7 @@ static void GetComClassHelper( NewArrayHolder wszRefServer = NULL; if (pClassFactInfo->m_strServerName) { - size_t len = u16_strlen(pClassFactInfo->m_strServerName)+1; + size_t len = minipal_u16_strlen((const CHAR16_T*)pClassFactInfo->m_strServerName)+1; wszRefServer = new WCHAR[len]; wcscpy_s(wszRefServer, len, pClassFactInfo->m_strServerName); } diff --git a/src/coreclr/vm/methodtable.cpp b/src/coreclr/vm/methodtable.cpp index cff22f39c105a9..4b7ef5f8ff1ffb 100644 --- a/src/coreclr/vm/methodtable.cpp +++ b/src/coreclr/vm/methodtable.cpp @@ -6080,7 +6080,7 @@ void MethodTable::GetGuid(GUID *pGuid, BOOL bGenerateIfNotFound, BOOL bClassic / szName = GetFullyQualifiedNameForClassNestedAwareW(this); if (szName == NULL) return; - cchName = u16_strlen(szName); + cchName = minipal_u16_strlen((const CHAR16_T*)szName); // Enlarge buffer for class name. cbCur = cchName * sizeof(WCHAR); diff --git a/src/coreclr/vm/multicorejit.cpp b/src/coreclr/vm/multicorejit.cpp index ab6d2e65fc74ea..01cfb7663dfcf0 100644 --- a/src/coreclr/vm/multicorejit.cpp +++ b/src/coreclr/vm/multicorejit.cpp @@ -946,7 +946,7 @@ HRESULT MulticoreJitRecorder::StartProfile(const WCHAR * pRoot, const WCHAR * pF MulticoreJitTrace(("StartProfile('%s', '%s', %d)", pRootUtf8, pFileUtf8, suffix)); #endif // MULTICOREJIT_LOGGING - size_t lenFile = u16_strlen(pFile); + size_t lenFile = minipal_u16_strlen((const CHAR16_T*)pFile); // Options (only AutoStartProfile using environment variable, for testing) // ([d|D]main-thread-delay) diff --git a/src/coreclr/vm/object.cpp b/src/coreclr/vm/object.cpp index 050f16e09ad04e..367c92b3e38576 100644 --- a/src/coreclr/vm/object.cpp +++ b/src/coreclr/vm/object.cpp @@ -725,7 +725,7 @@ STRINGREF StringObject::NewString(const WCHAR *pwsz) else { - DWORD nch = (DWORD)u16_strlen(pwsz); + DWORD nch = (DWORD)minipal_u16_strlen((const CHAR16_T*)pwsz); if (nch==0) { return GetEmptyString(); } diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index f04078fe6455a6..ad99719c76a074 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -309,7 +309,7 @@ inline PTR_PEImage PEImage::FindByPath(LPCWSTR pPath, BOOL isInBundle) int CaseHashHelper(const WCHAR *buffer, COUNT_T count); PEImageLocator locator(pPath, isInBundle); - DWORD dwHash = CaseHashHelper(pPath, (COUNT_T) u16_strlen(pPath)); + DWORD dwHash = CaseHashHelper(pPath, (COUNT_T) minipal_u16_strlen((const CHAR16_T*)pPath)); return (PEImage *) s_Images->LookupValue(dwHash, &locator); } diff --git a/src/coreclr/vm/profilinghelper.cpp b/src/coreclr/vm/profilinghelper.cpp index 49d95f3b9dedd4..02090c322ea2ca 100644 --- a/src/coreclr/vm/profilinghelper.cpp +++ b/src/coreclr/vm/profilinghelper.cpp @@ -674,7 +674,7 @@ HRESULT ProfilingAPIUtility::AttemptLoadProfilerForStartup() return S_FALSE; } - if ((wszProfilerDLL != NULL) && (u16_strlen(wszProfilerDLL) >= MAX_LONGPATH)) + if ((wszProfilerDLL != NULL) && (minipal_u16_strlen((const CHAR16_T*)(LPWSTR)wszProfilerDLL) >= MAX_LONGPATH)) { LOG((LF_CORPROF, LL_INFO10, "**PROF: Profiling flag set, but CORECLR_PROFILER_PATH was not set properly.\n")); diff --git a/src/coreclr/vm/proftoeeinterfaceimpl.cpp b/src/coreclr/vm/proftoeeinterfaceimpl.cpp index 1d3530c615d1e5..db9fb494eebf6f 100644 --- a/src/coreclr/vm/proftoeeinterfaceimpl.cpp +++ b/src/coreclr/vm/proftoeeinterfaceimpl.cpp @@ -4046,7 +4046,7 @@ HRESULT ProfToEEInterfaceImpl::GetModuleInfo2(ModuleID moduleId, wszFileName = strScopeName.GetUnicode(); } - ULONG trueLen = (ULONG)(u16_strlen(wszFileName) + 1); + ULONG trueLen = (ULONG)(minipal_u16_strlen((const CHAR16_T*)wszFileName) + 1); // Return name of module as required. if (wszName && cchName > 0) @@ -5492,7 +5492,7 @@ HRESULT ProfToEEInterfaceImpl::GetAppDomainInfo(AppDomainID appDomainId, if (szFriendlyName != NULL) { // Get the module file name - ULONG trueLen = (ULONG)(u16_strlen(szFriendlyName) + 1); + ULONG trueLen = (ULONG)(minipal_u16_strlen((const CHAR16_T*)szFriendlyName) + 1); // Return name of module as required. if (szName && cchName > 0) @@ -6354,7 +6354,7 @@ HRESULT ProfToEEInterfaceImpl::GetDynamicFunctionInfo(FunctionID functionId, ss.Normalize(); LPCWSTR methodName = ss.GetUnicode(); - ULONG trueLen = (ULONG)(u16_strlen(methodName) + 1); + ULONG trueLen = (ULONG)(minipal_u16_strlen((const CHAR16_T*)methodName) + 1); // Return name of method as required. if (wszName && cchName > 0) @@ -9682,7 +9682,7 @@ HRESULT ProfToEEInterfaceImpl::GetRuntimeInformation(USHORT * pClrInstanceId, PCWSTR pczVersionString = CLR_PRODUCT_VERSION_L; // Get the module file name - ULONG trueLen = (ULONG)(u16_strlen(pczVersionString) + 1); + ULONG trueLen = (ULONG)(minipal_u16_strlen((const CHAR16_T*)pczVersionString) + 1); // Return name of module as required. if (szVersionString && cchVersionString > 0) diff --git a/src/native/minipal/strings.c b/src/native/minipal/strings.c index 1711a9d07cae90..528c483c2beb1b 100644 --- a/src/native/minipal/strings.c +++ b/src/native/minipal/strings.c @@ -3,12 +3,20 @@ #include "strings.h" +#ifdef HOST_WINDOWS +#include +#endif + size_t minipal_u16_strlen(const CHAR16_T* str) { +#ifdef HOST_WINDOWS + return wcslen((const wchar_t*)str); +#else size_t len = 0; while (*str++) { len++; } return len; +#endif } From 040549dd78d8329d1f001776eeb5468cdfd6ff00 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 21 Oct 2024 22:26:35 +0000 Subject: [PATCH 17/28] PR feedback and fix dbgutil.cpp --- src/coreclr/debug/dbgutil/dbgutil.cpp | 2 +- src/coreclr/vm/ilmarshalers.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/debug/dbgutil/dbgutil.cpp b/src/coreclr/debug/dbgutil/dbgutil.cpp index eab6651cf68550..b38ba65dcda18f 100644 --- a/src/coreclr/debug/dbgutil/dbgutil.cpp +++ b/src/coreclr/debug/dbgutil/dbgutil.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "corhlpr.h" #ifdef HOST_WINDOWS diff --git a/src/coreclr/vm/ilmarshalers.cpp b/src/coreclr/vm/ilmarshalers.cpp index 0e752c278f4c5d..193cf2bf72e9f2 100644 --- a/src/coreclr/vm/ilmarshalers.cpp +++ b/src/coreclr/vm/ilmarshalers.cpp @@ -816,7 +816,7 @@ void ILWSTRBufferMarshaler::EmitConvertSpaceNativeToCLR(ILCodeStream* pslILEmit) if (IsIn(m_dwMarshalFlags) || IsCLRToNative(m_dwMarshalFlags)) { EmitLoadNativeValue(pslILEmit); - // static int System.String.minipal_u16_strlen((const CHAR16_T*)char *ptr) + // static int System.String.wcslen(char *ptr) pslILEmit->EmitCALL(METHOD__STRING__WCSLEN, 1, 1); } else @@ -845,7 +845,7 @@ void ILWSTRBufferMarshaler::EmitConvertContentsNativeToCLR(ILCodeStream* pslILEm EmitLoadNativeValue(pslILEmit); pslILEmit->EmitDUP(); - // static int System.String.minipal_u16_strlen((const CHAR16_T*)char *ptr) + // static int System.String.wcslen(char *ptr) pslILEmit->EmitCALL(METHOD__STRING__WCSLEN, 1, 1); // void System.Text.StringBuilder.ReplaceBuffer(char* newBuffer, int newLength); From 7ab733a9d960546c5db8a2bd4169a32be52aa87b Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 21 Oct 2024 22:54:35 +0000 Subject: [PATCH 18/28] Fix CoreCLR eventpipe runtime. --- src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index a7c310846de7d4..f19b33bd34006c 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -1447,7 +1447,7 @@ ep_rt_utf16_string_len (const ep_char16_t *str) STATIC_CONTRACT_NOTHROW; EP_ASSERT (str != NULL); - return minipal_u16_strlen (str); + return minipal_u16_strlen (reinterpret_cast (str)); } static From 367612de27abef5d5b7964cdea7f13427960b09e Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 22 Oct 2024 08:30:23 -0700 Subject: [PATCH 19/28] Fix windows build --- src/coreclr/vm/genanalysis.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/genanalysis.cpp b/src/coreclr/vm/genanalysis.cpp index ffcfbc05b6f542..dc116616651f91 100644 --- a/src/coreclr/vm/genanalysis.cpp +++ b/src/coreclr/vm/genanalysis.cpp @@ -28,7 +28,7 @@ bool gcGenAnalysisDump = false; { // Get the managed command line. LPCWSTR pCmdLine = GetCommandLineForDiagnostics(); - match = u16_strncmp(pCmdLine, gcGenAnalysisCmd, minipal_u16_strlen((CHAR16_T*)(char16_t*)gcGenAnalysisCmd)) == 0; + match = u16_strncmp(pCmdLine, gcGenAnalysisCmd, minipal_u16_strlen((CHAR16_T*)(LPWSTR)gcGenAnalysisCmd)) == 0; } if (match && !CLRConfig::IsConfigOptionSpecified(W("GCGenAnalysisGen"))) { From f31bcfdd3c8639b766d309f4f5e092ab421c2b91 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 23 Oct 2024 15:21:33 -0700 Subject: [PATCH 20/28] Move guid definitions out of the minipal and back to the CoreCLR PAL (we'll figure out standalone DNMD later) --- src/coreclr/pal/src/CMakeLists.txt | 1 + src/coreclr/pal/src/com/guid.cpp | 25 +++++++++++++++++++++++++ src/native/minipal/guid.c | 21 +++------------------ 3 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 src/coreclr/pal/src/com/guid.cpp diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 680332b0843ab3..2a1bca482c4fa9 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -134,6 +134,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND (CLR_CMAKE_HOST_ARCH_AMD64 OR CLR_CM endif() set(SOURCES + com/guid.cpp cruntime/wchar.cpp debug/debug.cpp exception/seh.cpp diff --git a/src/coreclr/pal/src/com/guid.cpp b/src/coreclr/pal/src/com/guid.cpp new file mode 100644 index 00000000000000..7e091dc62de05d --- /dev/null +++ b/src/coreclr/pal/src/com/guid.cpp @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +// +// =========================================================================== +// File: guid.cpp +// +// PALRT guids +// =========================================================================== + +#define INITGUID +#include + +// These are GUIDs and IIDs that would normally be provided by the system via uuid.lib, +// and that the PALRT exposes through headers. + +DEFINE_GUID(GUID_NULL, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); +DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); +DEFINE_GUID(IID_IClassFactory, 0x00000001, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); + + +// objidl.idl +DEFINE_GUID(IID_ISequentialStream, 0x0c733a30, 0x2a1c, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); +DEFINE_GUID(IID_IStream, 0x0000000c, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); diff --git a/src/native/minipal/guid.c b/src/native/minipal/guid.c index 5e1237c4d96a91..8002e323c40784 100644 --- a/src/native/minipal/guid.c +++ b/src/native/minipal/guid.c @@ -8,24 +8,6 @@ #include #endif -// Define some well-known GUIDs on non-Windows platforms. -#ifndef HOST_WINDOWS -// 00000000-0000-0000-0000-000000000000 -minipal_guid_t const GUID_NULL = { 0x0, 0x0, 0x0, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; - -// 00000000-0000-0000-C000-000000000046 -minipal_guid_t const IID_IUnknown = { 0x0, 0x0, 0x0, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; - -// 00000001-0000-0000-C000-000000000046 -minipal_guid_t const IID_IClassFactory = { 0x1, 0x0, 0x0, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; - -// 0c733a30-2a1c-11ce-ade5-00aa0044773d -minipal_guid_t const IID_ISequentialStream = { 0x0c733a30, 0x2a1c, 0x11ce, { 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d } }; - -// 0000000C-0000-0000-C000-000000000046 -minipal_guid_t const IID_IStream = { 0xC, 0x0, 0x0, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; -#endif - // See RFC-4122 section 4.4 on creation of random GUID. // https://www.ietf.org/rfc/rfc4122.txt // @@ -50,6 +32,9 @@ bool minipal_guid_v4_create(minipal_guid_t* guid) // Windows has a built-in function for creating v4 GUIDs. return SUCCEEDED(CoCreateGuid((GUID*)guid)); #else + // Technically, v4 GUIDs don't require cryptographically secure random bytes; + // however, CoCreateGuid provides that guarantee and we want to ensure + // that guarantee is maintained as customers have taken a dependency on it. if (minipal_get_cryptographically_secure_random_bytes((uint8_t*)guid, sizeof(*guid)) != 0) return false; From 329434fb0bc7aee94a1acd23a9a13bc49024e9ce Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 24 Oct 2024 16:52:26 -0700 Subject: [PATCH 21/28] Fix include path now that we're in the PAL and not palrt --- src/coreclr/pal/src/com/guid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/pal/src/com/guid.cpp b/src/coreclr/pal/src/com/guid.cpp index 7e091dc62de05d..482d45b4af59bb 100644 --- a/src/coreclr/pal/src/com/guid.cpp +++ b/src/coreclr/pal/src/com/guid.cpp @@ -10,7 +10,7 @@ // =========================================================================== #define INITGUID -#include +#include // These are GUIDs and IIDs that would normally be provided by the system via uuid.lib, // and that the PALRT exposes through headers. From 337fcef7c2b473a32dfb8fb839f1caf0d589b1b6 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 25 Oct 2024 17:15:13 +0000 Subject: [PATCH 22/28] Add rt include directory for guid.cpp --- src/coreclr/pal/src/CMakeLists.txt | 6 ++++++ src/coreclr/pal/src/com/guid.cpp | 9 +-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 2a1bca482c4fa9..0a3ed749f29fb0 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -203,6 +203,12 @@ set(SOURCES thread/threadsusp.cpp ) +set_source_files_properties( + com/guid.cpp + PROPERTIES + INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/../inc/rt +) + if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) set(LIBUNWIND_OBJECTS $) endif(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) diff --git a/src/coreclr/pal/src/com/guid.cpp b/src/coreclr/pal/src/com/guid.cpp index 482d45b4af59bb..57b632d86ca68e 100644 --- a/src/coreclr/pal/src/com/guid.cpp +++ b/src/coreclr/pal/src/com/guid.cpp @@ -2,15 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // -// -// =========================================================================== -// File: guid.cpp -// -// PALRT guids -// =========================================================================== - #define INITGUID -#include +#include // These are GUIDs and IIDs that would normally be provided by the system via uuid.lib, // and that the PALRT exposes through headers. From 2d94d0ad53fdc6d3c318064ca189f8b0394bfe28 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 25 Oct 2024 18:02:06 +0000 Subject: [PATCH 23/28] Export GUID_NULL from the dac's copy of the PAL for the dbi. --- src/coreclr/dlls/mscordac/mscordac_unixexports.src | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coreclr/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/dlls/mscordac/mscordac_unixexports.src index f40151ef8d9bd0..05bfd886a75527 100644 --- a/src/coreclr/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/dlls/mscordac/mscordac_unixexports.src @@ -146,3 +146,5 @@ nativeStringResourceTable_mscorrc #WaitForSingleObjectEx #WideCharToMultiByte #WriteFile + +#GUID_NULL From 460b8e5f3671c00555bd7bd659c2f783bad279f1 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 29 Oct 2024 13:37:51 -0700 Subject: [PATCH 24/28] Revert "Remove u16_strlen from the CoreCLR minipal" This reverts commit 4f39154c061545a1d1791d3a05fc90f4aa1c7b88. --- src/coreclr/debug/daccess/daccess.cpp | 16 +++++----- src/coreclr/debug/daccess/enummem.cpp | 4 +-- src/coreclr/debug/daccess/inspect.cpp | 2 +- src/coreclr/debug/daccess/request.cpp | 6 ++-- src/coreclr/debug/daccess/task.cpp | 4 +-- src/coreclr/debug/dbgutil/dbgutil.cpp | 4 +-- src/coreclr/debug/di/process.cpp | 2 +- src/coreclr/debug/di/publish.cpp | 6 ++-- src/coreclr/debug/di/rsmda.cpp | 2 +- src/coreclr/debug/di/rsthread.cpp | 2 +- src/coreclr/debug/di/symbolinfo.cpp | 4 +-- src/coreclr/debug/inc/dbgappdomain.h | 2 +- src/coreclr/debug/inc/dbgipcevents.h | 2 +- src/coreclr/debug/inc/ddmarshalutil.h | 4 +-- src/coreclr/debug/shared/stringcopyholder.cpp | 2 +- src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp | 4 +-- src/coreclr/ilasm/asmman.cpp | 8 ++--- src/coreclr/ilasm/assem.cpp | 2 +- src/coreclr/ilasm/main.cpp | 30 +++++++++---------- src/coreclr/ilasm/writer.cpp | 4 +-- src/coreclr/ildasm/dasm.cpp | 8 ++--- src/coreclr/ildasm/dis.cpp | 2 +- src/coreclr/ildasm/dman.cpp | 18 +++++------ src/coreclr/ildasm/dres.cpp | 12 ++++---- src/coreclr/inc/daccess.h | 4 +-- src/coreclr/inc/eventtracebase.h | 4 +-- src/coreclr/inc/outstring.h | 2 +- src/coreclr/inc/sstring.inl | 2 +- src/coreclr/inc/utilcode.h | 7 ++--- src/coreclr/jit/disasm.cpp | 2 +- .../md/ceefilegen/ceesectionstring.cpp | 2 +- src/coreclr/md/compiler/assemblymd.cpp | 2 +- src/coreclr/md/compiler/mdutil.cpp | 2 +- src/coreclr/md/compiler/regmeta.h | 2 +- src/coreclr/md/compiler/regmeta_import.cpp | 4 +-- src/coreclr/md/enc/liteweightstgdbrw.cpp | 2 +- src/coreclr/md/enc/rwutil.cpp | 2 +- src/coreclr/md/inc/rwutil.h | 2 +- src/coreclr/minipal/Unix/dn-u16.cpp | 11 +++++-- src/coreclr/minipal/Windows/dn-u16.cpp | 5 ++++ src/coreclr/minipal/dn-u16.h | 3 +- src/coreclr/scripts/genEventPipe.py | 2 +- src/coreclr/tools/metainfo/mdobj.cpp | 2 +- src/coreclr/tools/superpmi/mcs/verbmerge.cpp | 8 ++--- .../superpmi-shared/methodcontext.cpp | 12 ++++---- .../superpmi/superpmi-shared/spmiutil.cpp | 6 ++-- .../superpmi-shim-collector.cpp | 2 +- .../superpmi-shim-counter.cpp | 2 +- .../superpmi-shim-simple.cpp | 2 +- .../tools/superpmi/superpmi/commandline.cpp | 4 +-- .../tools/superpmi/superpmi/jitdebugger.cpp | 4 +-- .../tools/superpmi/superpmi/jithost.cpp | 4 +-- .../tools/superpmi/superpmi/jitinstance.cpp | 2 +- .../superpmi/superpmi/streamingsuperpmi.cpp | 4 +-- src/coreclr/utilcode/ccomprc.cpp | 2 +- src/coreclr/utilcode/clrconfig.cpp | 4 +-- src/coreclr/utilcode/guidfromname.cpp | 2 +- src/coreclr/utilcode/log.cpp | 6 ++-- src/coreclr/utilcode/longfilepathwrappers.cpp | 6 ++-- src/coreclr/utilcode/namespaceutil.cpp | 6 ++-- src/coreclr/utilcode/pedecoder.cpp | 2 +- src/coreclr/utilcode/posterror.cpp | 2 +- src/coreclr/utilcode/prettyprintsig.cpp | 2 +- src/coreclr/utilcode/splitpath.cpp | 2 +- src/coreclr/utilcode/sstring.cpp | 2 +- src/coreclr/utilcode/sstring_com.cpp | 2 +- src/coreclr/utilcode/stresslog.cpp | 4 +-- src/coreclr/utilcode/util.cpp | 4 +-- src/coreclr/utilcode/util_nodependencies.cpp | 2 +- src/coreclr/utilcode/winfix.cpp | 2 +- src/coreclr/vm/appdomain.cpp | 2 +- src/coreclr/vm/assembly.cpp | 4 +-- src/coreclr/vm/autotrace.cpp | 2 +- src/coreclr/vm/ceeload.cpp | 8 ++--- src/coreclr/vm/commtmemberinfomap.cpp | 16 +++++----- src/coreclr/vm/corhost.cpp | 2 +- src/coreclr/vm/debugdebugger.cpp | 4 +-- src/coreclr/vm/dispatchinfo.cpp | 2 +- src/coreclr/vm/dwbucketmanager.hpp | 6 ++-- src/coreclr/vm/eehash.cpp | 2 +- .../vm/eventing/eventpipe/ep-rt-coreclr.h | 1 + src/coreclr/vm/eventtrace.cpp | 2 +- src/coreclr/vm/gdbjit.cpp | 6 ++-- src/coreclr/vm/genanalysis.cpp | 2 +- src/coreclr/vm/ilmarshalers.cpp | 4 +-- src/coreclr/vm/interoputil.cpp | 6 ++-- src/coreclr/vm/methodtable.cpp | 2 +- src/coreclr/vm/multicorejit.cpp | 2 +- src/coreclr/vm/object.cpp | 2 +- src/coreclr/vm/peimage.inl | 2 +- src/coreclr/vm/profilinghelper.cpp | 2 +- src/coreclr/vm/proftoeeinterfaceimpl.cpp | 8 ++--- 92 files changed, 205 insertions(+), 194 deletions(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 0c31206eac92c8..81258d9d667ac9 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -264,7 +264,7 @@ SplitFullName(_In_z_ PCWSTR fullName, else { *params = NULL; - memberEnd = fullName + (minipal_u16_strlen((const CHAR16_T*)fullName) - 1); + memberEnd = fullName + (u16_strlen(fullName) - 1); } if (syntax != SPLIT_TYPE) @@ -5680,7 +5680,7 @@ static int FormatCLRStubName( // Compute the address as a string safely. WCHAR addrString[Max64BitHexString + 1]; FormatInteger(addrString, ARRAY_SIZE(addrString), "%p", stubAddr); - size_t addStringLen = minipal_u16_strlen((const CHAR16_T*)addrString); + size_t addStringLen = u16_strlen(addrString); // Compute maximum length, include the null terminator. size_t formatName_MaxLen = ARRAY_SIZE(formatName_Prefix) // Include trailing null @@ -5691,7 +5691,7 @@ static int FormatCLRStubName( size_t stubManagedNameLen = 0; if (stubNameMaybe != NULL) { - stubManagedNameLen = minipal_u16_strlen((const CHAR16_T*)stubNameMaybe); + stubManagedNameLen = u16_strlen(stubNameMaybe); formatName_MaxLen += ARRAY_SIZE(formatName_OpenBracket) - 1; formatName_MaxLen += ARRAY_SIZE(formatName_CloseBracket) - 1; } @@ -6458,7 +6458,7 @@ ClrDataAccess::GetMetaDataFileInfoFromPEFile(PEAssembly *pPEAssembly, // It is possible that the module is in-memory. That is the wszFilePath here is empty. // We will try to use the module name instead in this case for hosting debugger // to find match. - if (minipal_u16_strlen((const CHAR16_T*)wszFilePath) == 0) + if (u16_strlen(wszFilePath) == 0) { mdImage->GetModuleFileNameHintForDAC().DacGetUnicode(cchFilePath, wszFilePath, &uniPathChars); if (uniPathChars > cchFilePath) @@ -7259,9 +7259,9 @@ STDAPI OutOfProcessExceptionEventCallback(_In_ PDWORD pContext, return hr; } - if ((pwszEventName == NULL) || (*pchSize <= minipal_u16_strlen((const CHAR16_T*)gmb.wzEventTypeName))) + if ((pwszEventName == NULL) || (*pchSize <= u16_strlen(gmb.wzEventTypeName))) { - *pchSize = static_cast(minipal_u16_strlen((const CHAR16_T*)gmb.wzEventTypeName)) + 1; + *pchSize = static_cast(u16_strlen(gmb.wzEventTypeName)) + 1; return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } @@ -7383,9 +7383,9 @@ STDAPI OutOfProcessExceptionEventSignatureCallback(_In_ PDWORD pContext, // Return pwszName as an emptry string to let WER use localized version of "Parameter n" *pwszName = W('\0'); - if ((pwszValue == NULL) || (*pchValue <= minipal_u16_strlen((const CHAR16_T*)pwszBucketValues[dwIndex]))) + if ((pwszValue == NULL) || (*pchValue <= u16_strlen(pwszBucketValues[dwIndex]))) { - *pchValue = static_cast(minipal_u16_strlen((const CHAR16_T*)pwszBucketValues[dwIndex]))+ 1; + *pchValue = static_cast(u16_strlen(pwszBucketValues[dwIndex]))+ 1; return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } diff --git a/src/coreclr/debug/daccess/enummem.cpp b/src/coreclr/debug/daccess/enummem.cpp index 67105c92825357..7840bb29070cd0 100644 --- a/src/coreclr/debug/daccess/enummem.cpp +++ b/src/coreclr/debug/daccess/enummem.cpp @@ -233,14 +233,14 @@ HRESULT ClrDataAccess::EnumMemCLRStatic(IN CLRDataEnumMemoryFlags flags) WCHAR* path = entryAssemblyPath; if (path != NULL) { - size_t pathLen = minipal_u16_strlen((const CHAR16_T*)path) + 1; + size_t pathLen = u16_strlen(path) + 1; // Get the file name based on the last directory separator const WCHAR* name = u16_strrchr(path, DIRECTORY_SEPARATOR_CHAR_W); if (name != NULL) { name += 1; - size_t len = minipal_u16_strlen((const CHAR16_T*)name) + 1; + size_t len = u16_strlen(name) + 1; wcscpy_s(path, len, name); // Null out the rest of the buffer diff --git a/src/coreclr/debug/daccess/inspect.cpp b/src/coreclr/debug/daccess/inspect.cpp index aafcfc89a040d8..99667d95918977 100644 --- a/src/coreclr/debug/daccess/inspect.cpp +++ b/src/coreclr/debug/daccess/inspect.cpp @@ -1045,7 +1045,7 @@ ClrDataValue::GetString( if (strLen) { - *strLen = static_cast(minipal_u16_strlen((const CHAR16_T*)msgStr) + 1); + *strLen = static_cast(u16_strlen(msgStr) + 1); } status = StringCchCopy(str, bufLen, msgStr) == S_OK ? S_OK : S_FALSE; diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index e6d07e008b90a9..5c124d8e76ce7d 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -700,7 +700,7 @@ ClrDataAccess::GetRegisterName(int regNum, unsigned int count, _Inout_updates_z_ const WCHAR callerPrefix[] = W("caller."); // Include null terminator in prefixLen/regLen because wcscpy_s will fail otherwise unsigned int prefixLen = (unsigned int)ARRAY_SIZE(callerPrefix); - unsigned int regLen = (unsigned int)minipal_u16_strlen((const CHAR16_T*)regs[regNum]) + 1; + unsigned int regLen = (unsigned int)u16_strlen(regs[regNum]) + 1; unsigned int needed = (callerFrame ? prefixLen - 1 : 0) + regLen; if (pNeeded) *pNeeded = needed; @@ -2140,7 +2140,7 @@ ClrDataAccess::GetFrameName(CLRDATA_ADDRESS vtable, unsigned int count, _Inout_u else { // Turn from bytes to wide characters - unsigned int len = (unsigned int)minipal_u16_strlen((const CHAR16_T*)pszName); + unsigned int len = (unsigned int)u16_strlen(pszName); if (frameName) { @@ -2614,7 +2614,7 @@ ClrDataAccess::GetAppDomainName(CLRDATA_ADDRESS addr, unsigned int count, _Inout if (pAppDomain->m_friendlyName.IsValid()) { LPCWSTR friendlyName = (LPCWSTR)pAppDomain->m_friendlyName; - size_t friendlyNameLen = minipal_u16_strlen((const CHAR16_T*)friendlyName); + size_t friendlyNameLen = u16_strlen(friendlyName); if (pNeeded) { diff --git a/src/coreclr/debug/daccess/task.cpp b/src/coreclr/debug/daccess/task.cpp index a280cad4a75de8..65f14dedd18920 100644 --- a/src/coreclr/debug/daccess/task.cpp +++ b/src/coreclr/debug/daccess/task.cpp @@ -720,7 +720,7 @@ ClrDataAppDomain::GetName( S_OK : S_FALSE; if (nameLen) { - size_t cchName = minipal_u16_strlen((const CHAR16_T*)rawName) + 1; + size_t cchName = u16_strlen(rawName) + 1; if (FitsIn(cchName)) { *nameLen = (ULONG32) cchName; @@ -4749,7 +4749,7 @@ ClrDataExceptionState::GetString( status = StringCchCopy(str, bufLen, msgStr) == S_OK ? S_OK : S_FALSE; if (strLen != NULL) { - size_t cchName = minipal_u16_strlen((const CHAR16_T*)msgStr) + 1; + size_t cchName = u16_strlen(msgStr) + 1; if (FitsIn(cchName)) { *strLen = (ULONG32) cchName; diff --git a/src/coreclr/debug/dbgutil/dbgutil.cpp b/src/coreclr/debug/dbgutil/dbgutil.cpp index b38ba65dcda18f..93011b9d1fe54b 100644 --- a/src/coreclr/debug/dbgutil/dbgutil.cpp +++ b/src/coreclr/debug/dbgutil/dbgutil.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "corhlpr.h" #ifdef HOST_WINDOWS @@ -329,7 +329,7 @@ HRESULT GetNextLevelResourceEntryRVAByName(ICorDebugDataTarget* pDataTarget, DWORD* pNextLevelRva) { HRESULT hr = S_OK; - DWORD nameLength = (DWORD)minipal_u16_strlen((const CHAR16_T*)pwzName); + DWORD nameLength = (DWORD)u16_strlen(pwzName); WCHAR entryName[50]; assert(nameLength < 50); // this implementation won't support matching a name longer // than 50 characters. We only look up the hard coded name diff --git a/src/coreclr/debug/di/process.cpp b/src/coreclr/debug/di/process.cpp index cda7fa3219fa8d..43bd54b71b6abc 100644 --- a/src/coreclr/debug/di/process.cpp +++ b/src/coreclr/debug/di/process.cpp @@ -9619,7 +9619,7 @@ void Ls_Rs_StringBuffer::CopyLSDataToRS(ICorDebugDataTarget * pTarget) // Now we know it's safe to call u16_strlen. The buffer is local, so we know the pages are there. // And we know there's a null capping the max length of the string. - SIZE_T dwActualLenWithNull = minipal_u16_strlen((const CHAR16_T*)pString) + 1; + SIZE_T dwActualLenWithNull = u16_strlen(pString) + 1; if (dwActualLenWithNull != dwExpectedLenWithNull) { ThrowHR(CORDBG_E_TARGET_INCONSISTENT); diff --git a/src/coreclr/debug/di/publish.cpp b/src/coreclr/debug/di/publish.cpp index 4ec621f4d0117b..0a7bad24642885 100644 --- a/src/coreclr/debug/di/publish.cpp +++ b/src/coreclr/debug/di/publish.cpp @@ -418,7 +418,7 @@ CorpubProcess::CorpubProcess(DWORD dwProcessId, if (ret > 0) { // Recompute string length because we don't know if 'ret' is in bytes or char. - SIZE_T len = minipal_u16_strlen((const CHAR16_T*)szName) + 1; + SIZE_T len = u16_strlen(szName) + 1; m_szProcessName = new (nothrow) WCHAR[len]; if (m_szProcessName != NULL) { @@ -602,7 +602,7 @@ HRESULT AllocateAndReadRemoteString( if (SUCCEEDED(hr)) { // Ensure that the string we just read is actually null terminated. - // We can't call minipal_u16_strlen((const CHAR16_T*)) on it yet, since that may AV on a non-null terminated string. + // We can't call u16_strlen() on it yet, since that may AV on a non-null terminated string. WCHAR * pString = *ppNewLocalBuffer; if (pString[ceSize - 1] == W('\0')) @@ -612,7 +612,7 @@ HRESULT AllocateAndReadRemoteString( } pString[ceSize - 1] = W('\0'); - SIZE_T ceTestLen = minipal_u16_strlen((const CHAR16_T*)pString); + SIZE_T ceTestLen = u16_strlen(pString); if (ceTestLen == ceSize - 1) { // String was not previously null-terminated. diff --git a/src/coreclr/debug/di/rsmda.cpp b/src/coreclr/debug/di/rsmda.cpp index b6b2186d365937..b6acace5f43168 100644 --- a/src/coreclr/debug/di/rsmda.cpp +++ b/src/coreclr/debug/di/rsmda.cpp @@ -105,7 +105,7 @@ HRESULT CordbMDA::QueryInterface(REFIID riid, void **ppInterface) HRESULT CopyOutString(LPCWSTR pInputString, ULONG32 cchName, ULONG32 * pcchName, _Out_writes_to_opt_(cchName, *pcchName) WCHAR szName[]) { _ASSERTE(pInputString != NULL); - ULONG32 len = (ULONG32) minipal_u16_strlen((const CHAR16_T*)pInputString) + 1; + ULONG32 len = (ULONG32) u16_strlen(pInputString) + 1; if (cchName == 0) { diff --git a/src/coreclr/debug/di/rsthread.cpp b/src/coreclr/debug/di/rsthread.cpp index 458959ded0eb64..619b37c87ef8b8 100644 --- a/src/coreclr/debug/di/rsthread.cpp +++ b/src/coreclr/debug/di/rsthread.cpp @@ -10205,7 +10205,7 @@ HRESULT CordbEval::NewString(LPCWSTR string) { PUBLIC_API_ENTRY(this); FAIL_IF_NEUTERED(this); - return NewStringWithLength(string, (UINT)minipal_u16_strlen((const CHAR16_T*)string)); + return NewStringWithLength(string, (UINT)u16_strlen(string)); } //--------------------------------------------------------------------------------------- diff --git a/src/coreclr/debug/di/symbolinfo.cpp b/src/coreclr/debug/di/symbolinfo.cpp index ddd3d75e4992f8..7d293a89a1ddc5 100644 --- a/src/coreclr/debug/di/symbolinfo.cpp +++ b/src/coreclr/debug/di/symbolinfo.cpp @@ -258,7 +258,7 @@ STDMETHODIMP SymbolInfo::GetTypeDefProps ( // S_OK or error. *pdwTypeDefFlags=classInfo->flags; - SIZE_T cch=minipal_u16_strlen((const CHAR16_T*)classInfo->wszName.GetUnicode())+1; + SIZE_T cch=u16_strlen(classInfo->wszName)+1; if (cch > UINT32_MAX) return E_UNEXPECTED; *pchTypeDef=(ULONG)cch; @@ -309,7 +309,7 @@ STDMETHODIMP SymbolInfo::GetMethodProps ( *pClass=m_LastMethod.cls; - SIZE_T cch=minipal_u16_strlen((const CHAR16_T*)m_LastMethod.wszName.GetUnicode())+1; + SIZE_T cch=u16_strlen(m_LastMethod.wszName)+1; if(cch > UINT32_MAX) return E_UNEXPECTED; *pchMethod=(ULONG)cch; diff --git a/src/coreclr/debug/inc/dbgappdomain.h b/src/coreclr/debug/inc/dbgappdomain.h index 452148d1728cec..de8a06b38c9e51 100644 --- a/src/coreclr/debug/inc/dbgappdomain.h +++ b/src/coreclr/debug/inc/dbgappdomain.h @@ -43,7 +43,7 @@ struct AppDomainInfo else m_szAppDomainName = W(""); - m_iNameLengthInBytes = (int) (minipal_u16_strlen((const CHAR16_T*)m_szAppDomainName) + 1) * sizeof(WCHAR); + m_iNameLengthInBytes = (int) (u16_strlen(m_szAppDomainName) + 1) * sizeof(WCHAR); } #endif }; diff --git a/src/coreclr/debug/inc/dbgipcevents.h b/src/coreclr/debug/inc/dbgipcevents.h index 5025abca6e2db3..6c39939f00307e 100644 --- a/src/coreclr/debug/inc/dbgipcevents.h +++ b/src/coreclr/debug/inc/dbgipcevents.h @@ -872,7 +872,7 @@ template class MSLAYOUT EmbeddedIPCString { public: - // Set, caller responsibility that minipal_u16_strlen((const CHAR16_T*)pData) < nMaxLengthIncludingNull + // Set, caller responsibility that u16_strlen(pData) < nMaxLengthIncludingNull void SetString(const WCHAR * pData) { // If the string doesn't fit into the buffer, that's an issue (and so this is a real diff --git a/src/coreclr/debug/inc/ddmarshalutil.h b/src/coreclr/debug/inc/ddmarshalutil.h index d6401fe2aae0aa..190fa071c8d3b4 100644 --- a/src/coreclr/debug/inc/ddmarshalutil.h +++ b/src/coreclr/debug/inc/ddmarshalutil.h @@ -90,7 +90,7 @@ class WriteBuffer : public BaseBuffer if (!fIsNull) { _ASSERTE(pString != NULL); - DWORD len = (DWORD) minipal_u16_strlen((const CHAR16_T*)pString); + DWORD len = (DWORD) u16_strlen(pString); DWORD cbCopy = (len + 1) * sizeof(WCHAR); EnsureSize(cbCopy); @@ -179,7 +179,7 @@ class ReadBuffer : public BaseBuffer else { const WCHAR * pString = (WCHAR*) &m_pBuffer[m_idx]; - DWORD len = (DWORD) minipal_u16_strlen((const CHAR16_T*)pString); + DWORD len = (DWORD) u16_strlen(pString); m_idx += (len + 1) * sizeof(WCHAR); // skip past null _ASSERTE(m_idx <= m_size); return pString; diff --git a/src/coreclr/debug/shared/stringcopyholder.cpp b/src/coreclr/debug/shared/stringcopyholder.cpp index 6b674380a33422..46bb9971dbd229 100644 --- a/src/coreclr/debug/shared/stringcopyholder.cpp +++ b/src/coreclr/debug/shared/stringcopyholder.cpp @@ -68,7 +68,7 @@ HRESULT StringCopyHolder::AssignCopy(const WCHAR * pStringSrc) } else { - SIZE_T cchLen = minipal_u16_strlen((const CHAR16_T*)pStringSrc) + 1; + SIZE_T cchLen = u16_strlen(pStringSrc) + 1; m_szData = new (nothrow) WCHAR[cchLen]; if (m_szData == NULL) { diff --git a/src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp b/src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp index c85ba436e12e92..2de73f9675b027 100644 --- a/src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp +++ b/src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp @@ -466,7 +466,7 @@ HRESULT CeeFileGenWriter::setOutputFileName(_In_ LPWSTR fileName) { if (m_outputFileName) delete[] m_outputFileName; - size_t len = minipal_u16_strlen((const CHAR16_T*)fileName) + 1; + size_t len = u16_strlen(fileName) + 1; m_outputFileName = (LPWSTR)new (nothrow) WCHAR[len]; TESTANDRETURN(m_outputFileName!=NULL, E_OUTOFMEMORY); wcscpy_s(m_outputFileName, len, fileName); @@ -477,7 +477,7 @@ HRESULT CeeFileGenWriter::setResourceFileName(_In_ LPWSTR fileName) { if (m_resourceFileName) delete[] m_resourceFileName; - size_t len = minipal_u16_strlen((const CHAR16_T*)fileName) + 1; + size_t len = u16_strlen(fileName) + 1; m_resourceFileName = (LPWSTR)new (nothrow) WCHAR[len]; TESTANDRETURN(m_resourceFileName!=NULL, E_OUTOFMEMORY); wcscpy_s(m_resourceFileName, len, fileName); diff --git a/src/coreclr/ilasm/asmman.cpp b/src/coreclr/ilasm/asmman.cpp index 48701205c4de90..8f42b83bdcd7b7 100644 --- a/src/coreclr/ilasm/asmman.cpp +++ b/src/coreclr/ilasm/asmman.cpp @@ -28,10 +28,10 @@ BinStr* BinStrToUnicode(BinStr* pSource, bool Swap) { memset(wz,0,L); MultiByteToWideChar(g_uCodePage,0,pb,-1,wz,l); - tmp->remove(L-(DWORD)minipal_u16_strlen((const CHAR16_T*)wz)*sizeof(WCHAR)); + tmp->remove(L-(DWORD)u16_strlen(wz)*sizeof(WCHAR)); #if BIGENDIAN if (Swap) - SwapStringLength(wz, (DWORD)minipal_u16_strlen((const CHAR16_T*)wz)); + SwapStringLength(wz, (DWORD)u16_strlen(wz)); #endif delete pSource; } @@ -996,8 +996,8 @@ HRESULT AsmMan::EmitManifest() else { m_dwMResSizeTotal += m_dwMResSize[m_dwMResNum]+sizeof(DWORD); - m_wzMResName[m_dwMResNum] = new WCHAR[minipal_u16_strlen((const CHAR16_T*)wzFileName)+1]; - wcscpy_s(m_wzMResName[m_dwMResNum],minipal_u16_strlen((const CHAR16_T*)wzFileName)+1,wzFileName); + m_wzMResName[m_dwMResNum] = new WCHAR[u16_strlen(wzFileName)+1]; + wcscpy_s(m_wzMResName[m_dwMResNum],u16_strlen(wzFileName)+1,wzFileName); m_fMResNew[m_dwMResNum] = TRUE; m_dwMResNum++; } diff --git a/src/coreclr/ilasm/assem.cpp b/src/coreclr/ilasm/assem.cpp index 2bc0a8a4d7753b..0100feef79a127 100644 --- a/src/coreclr/ilasm/assem.cpp +++ b/src/coreclr/ilasm/assem.cpp @@ -1076,7 +1076,7 @@ BOOL Assembler::EmitClass(Class *pClass) MultiByteToWideChar(g_uCodePage,0,szFullName,-1,wzFullName,dwUniBuf); - L = minipal_u16_strlen((const CHAR16_T*)wzFullName); + L = u16_strlen(wzFullName); if((L==0)||(wzFullName[L-1]==L'.')) // Missing class name! { wcscat_s(wzFullName,dwUniBuf,W("$UNNAMED_TYPE$")); diff --git a/src/coreclr/ilasm/main.cpp b/src/coreclr/ilasm/main.cpp index d9d59c9c85bf95..aba3aa78847f35 100644 --- a/src/coreclr/ilasm/main.cpp +++ b/src/coreclr/ilasm/main.cpp @@ -34,7 +34,7 @@ class NarrowForNumberParsing final public: NarrowForNumberParsing(const WCHAR* str) { - size_t len = minipal_u16_strlen((const CHAR16_T*)str); + size_t len = u16_strlen(str); _buffer = (char*)malloc(len + 1); for (size_t i = 0; i < len; ++i) _buffer[i] = (char)str[i]; @@ -83,7 +83,7 @@ void MakeProperSourceFileName(_In_ __nullterminated WCHAR* wzOrigName, _Out_writes_(MAX_FILENAME_LENGTH*3) char* szProperName) { wcscpy_s(wzProperName,MAX_FILENAME_LENGTH, wzOrigName); - size_t j = minipal_u16_strlen((const CHAR16_T*)wzProperName); + size_t j = u16_strlen(wzProperName); do { j--; @@ -263,7 +263,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) if(pStr != NULL) { for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no suboption + if(u16_strlen(pStr)==0) goto InvalidOption; //if no suboption else { WCHAR wzSubOpt[8]; @@ -377,7 +377,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto ErrorExit; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no file name + if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name pAsm->m_wzResourceFile = pStr; } else @@ -388,7 +388,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no file name + if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name pAsm->m_wzKeySourceName = pStr; } else if (!_stricmp(szOpt, "INC")) @@ -396,7 +396,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no file name + if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name wzIncludePath = pStr; } else if (!_stricmp(szOpt, "OUT")) @@ -404,8 +404,8 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no file name - if(minipal_u16_strlen((const CHAR16_T*)pStr) >= MAX_FILENAME_LENGTH) + if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name + if(u16_strlen(pStr) >= MAX_FILENAME_LENGTH) { fprintf(stderr,"\nError: Output file name exceeds %d characters\n",MAX_FILENAME_LENGTH-1); goto ErrorExit; @@ -417,7 +417,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no version string + if(u16_strlen(pStr)==0) goto InvalidOption; //if no version string pAsm->m_wzMetadataVersion = pStr; } else if (!_stricmp(szOpt, "MSV")) @@ -425,7 +425,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no version + if(u16_strlen(pStr)==0) goto InvalidOption; //if no version { int major=-1,minor=-1; NarrowForNumberParsing str{pStr}; @@ -452,7 +452,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR *pStr = EqualOrColon(argv[i]); if(pStr == NULL) goto InvalidOption; for(pStr++; *pStr == W(' '); pStr++); //skip the blanks - if(minipal_u16_strlen((const CHAR16_T*)pStr)==0) goto InvalidOption; //if no version + if(u16_strlen(pStr)==0) goto InvalidOption; //if no version { int major=-1,minor=-1; NarrowForNumberParsing str{pStr}; @@ -541,7 +541,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) } else { - if(minipal_u16_strlen((const CHAR16_T*)argv[i]) >= MAX_FILENAME_LENGTH) + if(u16_strlen(argv[i]) >= MAX_FILENAME_LENGTH) { printf("\nError: Input file name exceeds %d characters\n",MAX_FILENAME_LENGTH-1); goto ErrorExit; @@ -620,7 +620,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) if(wzOutputFilename[0] == 0) { wcscpy_s(wzOutputFilename,MAX_FILENAME_LENGTH,pwzInputFiles[0]); - size_t j = minipal_u16_strlen((const CHAR16_T*)wzOutputFilename); + size_t j = u16_strlen(wzOutputFilename); do { j--; @@ -778,7 +778,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) for(iFile = 0; iFile < NumDeltaFiles; iFile++) { wcscpy_s(wzNewOutputFilename,MAX_FILENAME_LENGTH+16,wzOutputFilename); - size_t len = minipal_u16_strlen((const CHAR16_T*)wzNewOutputFilename); + size_t len = u16_strlen(wzNewOutputFilename); wzNewOutputFilename[len] = W('.'); FormatInteger(&wzNewOutputFilename[len + 1], MaxSigned32BitDecString + 1, "%d", iFile+1); MakeProperSourceFileName(pwzDeltaFiles[iFile], uCodePage, wzInputFilename, szInputFilename); @@ -841,7 +841,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv) WCHAR* pc = (WCHAR*)u16_strrchr(wzOutputFilename,W('.')); if(pc==NULL) { - pc = &wzOutputFilename[minipal_u16_strlen((const CHAR16_T*)wzOutputFilename)]; + pc = &wzOutputFilename[u16_strlen(wzOutputFilename)]; *pc = W('.'); } wcscpy_s(pc+1,4,W("PDB")); diff --git a/src/coreclr/ilasm/writer.cpp b/src/coreclr/ilasm/writer.cpp index 3ed22dea3acc22..2bc9152bfea3b3 100644 --- a/src/coreclr/ilasm/writer.cpp +++ b/src/coreclr/ilasm/writer.cpp @@ -336,9 +336,9 @@ HRESULT Assembler::CreateExportDirectory() unsigned i, L, ordBase = 0xFFFFFFFF, Ldllname; // get the DLL name from output file name char* pszDllName; - Ldllname = (unsigned)minipal_u16_strlen((const CHAR16_T*)m_wzOutputFileName)*3+3; + Ldllname = (unsigned)u16_strlen(m_wzOutputFileName)*3+3; NewArrayHolder szOutputFileName(new char[Ldllname]); - memset(szOutputFileName,0,minipal_u16_strlen((const CHAR16_T*)m_wzOutputFileName)*3+3); + memset(szOutputFileName,0,u16_strlen(m_wzOutputFileName)*3+3); WideCharToMultiByte(CP_ACP,0,m_wzOutputFileName,-1,szOutputFileName,Ldllname,NULL,NULL); pszDllName = strrchr(szOutputFileName,DIRECTORY_SEPARATOR_CHAR_A); #ifdef TARGET_WINDOWS diff --git a/src/coreclr/ildasm/dasm.cpp b/src/coreclr/ildasm/dasm.cpp index 573af9ef417fdf..f514e90cca65e6 100644 --- a/src/coreclr/ildasm/dasm.cpp +++ b/src/coreclr/ildasm/dasm.cpp @@ -3062,7 +3062,7 @@ char *DumpGenericPars(_Inout_updates_(SZSTRING_SIZE) char* szString, mdToken tok for (i = 1; NumTyPars != 0; i++) { g_pPubImport->GetGenericParamProps(tkTyPar, &ulSequence, &attr, &tkOwner, NULL, wzArgName, UNIBUF_SIZE/2, &chName); - //if(minipal_u16_strlen((const CHAR16_T*)wzArgName) >= MAX_CLASSNAME_LENGTH) + //if(u16_strlen(wzArgName) >= MAX_CLASSNAME_LENGTH) // wzArgName[MAX_CLASSNAME_LENGTH-1] = 0; hEnumTyParConstr = NULL; if (FAILED(g_pPubImport->EnumGenericParamConstraints(&hEnumTyParConstr, tkTyPar, tkConstr, 2048, &NumConstrs))) @@ -3117,7 +3117,7 @@ char *DumpGenericPars(_Inout_updates_(SZSTRING_SIZE) char* szString, mdToken tok } // re-get name, wzUniBuf may not contain it any more g_pPubImport->GetGenericParamProps(tkTyPar, NULL, &attr, NULL, NULL, wzArgName, UNIBUF_SIZE/2, &chName); - //if(minipal_u16_strlen((const CHAR16_T*)wzArgName) >= MAX_CLASSNAME_LENGTH) + //if(u16_strlen(wzArgName) >= MAX_CLASSNAME_LENGTH) // wzArgName[MAX_CLASSNAME_LENGTH-1] = 0; if (chName) { @@ -3187,7 +3187,7 @@ void DumpGenericParsCA(mdToken tok, void* GUICookie/*=NULL*/) if(SUCCEEDED(g_pPubImport->GetGenericParamProps(tkTyPar, NULL, &attr, NULL, NULL, wzArgName, UNIBUF_SIZE/2, &chName)) &&(chName > 0)) { - //if(minipal_u16_strlen((const CHAR16_T*)wzArgName) >= MAX_CLASSNAME_LENGTH) + //if(u16_strlen(wzArgName) >= MAX_CLASSNAME_LENGTH) // wzArgName[MAX_CLASSNAME_LENGTH-1] = 0; char* sz = (char*)(&wzUniBuf[UNIBUF_SIZE/2]); WideCharToMultiByte(CP_UTF8,0,wzArgName,-1,sz,UNIBUF_SIZE,NULL,NULL); @@ -7784,7 +7784,7 @@ BOOL DumpFile() memset(wzResFileName,0,sizeof(wzResFileName)); MultiByteToWideChar(CP_UTF8,0,g_szOutputFile,-1,wzResFileName,2048); pwc = (WCHAR*)u16_strrchr(wzResFileName,L'.'); - if(pwc == NULL) pwc = &wzResFileName[minipal_u16_strlen((const CHAR16_T*)wzResFileName)]; + if(pwc == NULL) pwc = &wzResFileName[u16_strlen(wzResFileName)]; wcscpy_s(pwc, 2048 - (pwc - wzResFileName), L".res"); DWORD ret = DumpResourceToFile(wzResFileName); switch(ret) diff --git a/src/coreclr/ildasm/dis.cpp b/src/coreclr/ildasm/dis.cpp index 7f6af0add18097..44ce665814c1fd 100644 --- a/src/coreclr/ildasm/dis.cpp +++ b/src/coreclr/ildasm/dis.cpp @@ -143,7 +143,7 @@ static void UnicodeToFile(_In_ __nullterminated const WCHAR* wz, FILE* pF) { unsigned endofline = 0x000A000D; int L; - if((L=(int)minipal_u16_strlen((const CHAR16_T*)wz))) fwrite(wz,L*sizeof(WCHAR),1,pF); + if((L=(int)u16_strlen(wz))) fwrite(wz,L*sizeof(WCHAR),1,pF); fwrite(&endofline,4,1,pF); } static void ToGUIOrFile(_In_ __nullterminated const char* sz, void* GUICookie) diff --git a/src/coreclr/ildasm/dman.cpp b/src/coreclr/ildasm/dman.cpp index 19d26d46e60ae2..91761723a081c1 100644 --- a/src/coreclr/ildasm/dman.cpp +++ b/src/coreclr/ildasm/dman.cpp @@ -125,7 +125,7 @@ void DumpScope(void* GUICookie) if(SUCCEEDED(g_pPubImport->GetScopeProps( scopeName, 1024, NULL, &mvid))&& scopeName[0]) { { - UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)scopeName)*3+3; + UINT32 L = (UINT32)u16_strlen(scopeName)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,scopeName,-1,sz,L,NULL,NULL); @@ -423,7 +423,7 @@ void DumpComTypeFQN( } } - UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)pCTD->wzName)*3+3; + UINT32 L = (UINT32)u16_strlen(pCTD->wzName)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,pCTD->wzName,-1,sz,L,NULL,NULL); @@ -446,7 +446,7 @@ void DumpImplementation(mdToken tkImplementation, if(i < nFiles) { { - UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)rFile[i].name)*3+3; + UINT32 L = (UINT32)u16_strlen(rFile[i].name)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,rFile[i].name,-1,sz,L,NULL,NULL); @@ -466,7 +466,7 @@ void DumpImplementation(mdToken tkImplementation, if(i < nAsmRefs) { { - UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)rAsmRef[i].name)*3+3; + UINT32 L = (UINT32)u16_strlen(rAsmRef[i].name)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,rAsmRef[i].name,-1,sz,L,NULL,NULL); @@ -512,7 +512,7 @@ void DumpComType(LocalComTypeDescr* pCTD, char* pc=&szString[strlen(szString)]; { - UINT32 L = (UINT32)minipal_u16_strlen((const CHAR16_T*)pCTD->wzName)*3+3; + UINT32 L = (UINT32)u16_strlen(pCTD->wzName)*3+3; char* sz = new char[L]; memset(sz,0,L); WideCharToMultiByte(CP_UTF8,0,pCTD->wzName,-1,sz,L,NULL,NULL); @@ -628,7 +628,7 @@ static BOOL ConvertToLegalFileNameInPlace(__inout LPWSTR wzName) for (size_t i = 0; i < (sizeof(rwzReserved) / sizeof(WCHAR *)); i++) { - _ASSERTE(minipal_u16_strlen((const CHAR16_T*)rwzReserved[i]) == 3); + _ASSERTE(u16_strlen(rwzReserved[i]) == 3); if (_wcsnicmp(wzName, rwzReserved[i], 3) == 0) { LPWSTR pwc = wzName + 3; @@ -801,7 +801,7 @@ void DumpManifestResources(void* GUICookie) #define NAME_ARRAY_ADD(index, str) \ { \ - size_t __dwBufLen = minipal_u16_strlen((const CHAR16_T*)str) + 1; \ + size_t __dwBufLen = u16_strlen(str) + 1; \ \ qbNameArray[index].Init(); \ WCHAR *__wpc = (WCHAR *)qbNameArray[index].AllocNoThrow(__dwBufLen); \ @@ -813,7 +813,7 @@ void DumpManifestResources(void* GUICookie) // add the Win32 resource file name to avoid conflict between the native and a managed resource file WCHAR *pwc = (WCHAR*)u16_strrchr(wzName, L'.'); - if (pwc == NULL) pwc = &wzName[minipal_u16_strlen((const CHAR16_T*)wzName)]; + if (pwc == NULL) pwc = &wzName[u16_strlen(wzName)]; wcscpy_s(pwc, 2048 - (pwc - wzFileName), W(".res")); NAME_ARRAY_ADD(1, wzName); @@ -845,7 +845,7 @@ void DumpManifestResources(void* GUICookie) BOOL fAlias = ConvertToLegalFileNameInPlace(wzName); // check for duplicate file name - WCHAR *wpc = wzName + minipal_u16_strlen((const CHAR16_T*)wzName); + WCHAR *wpc = wzName + u16_strlen(wzName); for (int iIndex = 1;; iIndex++) { BOOL fConflict = FALSE; diff --git a/src/coreclr/ildasm/dres.cpp b/src/coreclr/ildasm/dres.cpp index 871083ec533a66..e1612130ca6065 100644 --- a/src/coreclr/ildasm/dres.cpp +++ b/src/coreclr/ildasm/dres.cpp @@ -104,8 +104,8 @@ struct ResourceNode { //fwrite(&(g_prResNodePtr[i]->ResHdr),g_prResNodePtr[i]->ResHdr.dwHeaderSize,1,pF); ResHdr.dwHeaderSize = sizeof(ResourceHeader); - if(wzType) ResHdr.dwHeaderSize += (DWORD)((minipal_u16_strlen((const CHAR16_T*)wzType) + 1)*sizeof(WCHAR) - sizeof(DWORD)); - if(wzName) ResHdr.dwHeaderSize += (DWORD)((minipal_u16_strlen((const CHAR16_T*)wzName) + 1)*sizeof(WCHAR) - sizeof(DWORD)); + if(wzType) ResHdr.dwHeaderSize += (DWORD)((u16_strlen(wzType) + 1)*sizeof(WCHAR) - sizeof(DWORD)); + if(wzName) ResHdr.dwHeaderSize += (DWORD)((u16_strlen(wzName) + 1)*sizeof(WCHAR) - sizeof(DWORD)); //---- Constant part of the header: DWORD,DWORD fwrite(&ResHdr.dwDataSize, sizeof(DWORD),1,pF); @@ -113,15 +113,15 @@ struct ResourceNode //--- Variable part of header: type and name if(wzType) { - fwrite(wzType,(minipal_u16_strlen((const CHAR16_T*)wzType) + 1)*sizeof(WCHAR), 1, pF); - dwFiller += (DWORD)minipal_u16_strlen((const CHAR16_T*)wzType) + 1; + fwrite(wzType,(u16_strlen(wzType) + 1)*sizeof(WCHAR), 1, pF); + dwFiller += (DWORD)u16_strlen(wzType) + 1; } else fwrite(&ResHdr.dwTypeID,sizeof(DWORD),1,pF); if(wzName) { - fwrite(wzName,(minipal_u16_strlen((const CHAR16_T*)wzName) + 1)*sizeof(WCHAR), 1, pF); - dwFiller += (DWORD)minipal_u16_strlen((const CHAR16_T*)wzName) + 1; + fwrite(wzName,(u16_strlen(wzName) + 1)*sizeof(WCHAR), 1, pF); + dwFiller += (DWORD)u16_strlen(wzName) + 1; } else fwrite(&ResHdr.dwNameID,sizeof(DWORD),1,pF); diff --git a/src/coreclr/inc/daccess.h b/src/coreclr/inc/daccess.h index 3b2b21e8e18713..7bc2baed536e39 100644 --- a/src/coreclr/inc/daccess.h +++ b/src/coreclr/inc/daccess.h @@ -575,7 +575,7 @@ #include #include "crosscomp.h" -#include +#include // Information stored in the DAC table of interest to the DAC implementation // Note that this information is shared between all instantiations of ClrDataAccess, so initialize @@ -1524,7 +1524,7 @@ class __Str16Ptr : public __DPtr WCHAR* str = DacInstantiateStringW(m_addr, maxChars, false); if (str) { - DacEnumMemoryRegion(m_addr, minipal_u16_strlen((const CHAR16_T*)str) + 1); + DacEnumMemoryRegion(m_addr, u16_strlen(str) + 1); } } }; diff --git a/src/coreclr/inc/eventtracebase.h b/src/coreclr/inc/eventtracebase.h index f00b156af0a16a..38868fe528f797 100644 --- a/src/coreclr/inc/eventtracebase.h +++ b/src/coreclr/inc/eventtracebase.h @@ -349,7 +349,7 @@ class XplatEventLoggerConfiguration const WCHAR * end = u16_strchr(start, ComponentDelimiter); if (end == nullptr) { - end = start + minipal_u16_strlen((const CHAR16_T*)start); + end = start + u16_strlen(start); } return ComponentSpan(start, end); @@ -460,7 +460,7 @@ class XplatEventLoggerController #ifdef FEATURE_EVENT_TRACE static LTTNG_TRACE_CONTEXT * const GetProvider(LPCWSTR providerName) { - auto length = minipal_u16_strlen((const CHAR16_T*)providerName); + auto length = u16_strlen(providerName); for (auto provider : ALL_LTTNG_PROVIDERS_CONTEXT) { if (_wcsicmp(provider->Name, providerName) == 0) diff --git a/src/coreclr/inc/outstring.h b/src/coreclr/inc/outstring.h index c91f0bbc5f1c90..c719c465457b72 100644 --- a/src/coreclr/inc/outstring.h +++ b/src/coreclr/inc/outstring.h @@ -73,7 +73,7 @@ class OutString { } OutString& operator<<(const WCHAR* str) { - size_t len = minipal_u16_strlen((const CHAR16_T*)str); + size_t len = u16_strlen(str); if (cur+len > end) Realloc(len); while(str != 0) diff --git a/src/coreclr/inc/sstring.inl b/src/coreclr/inc/sstring.inl index 05f00321d2c8ba..0b78ec3bc3aaff 100644 --- a/src/coreclr/inc/sstring.inl +++ b/src/coreclr/inc/sstring.inl @@ -386,7 +386,7 @@ inline SString::SString(tagUTF8Literal dummytag, const UTF8 *literal) } inline SString::SString(tagLiteral dummytag, const WCHAR *literal) - : SBuffer(Immutable, (const BYTE *) literal, (COUNT_T) (minipal_u16_strlen((const CHAR16_T*)literal)+1)*sizeof(WCHAR)) + : SBuffer(Immutable, (const BYTE *) literal, (COUNT_T) (u16_strlen(literal)+1)*sizeof(WCHAR)) { SS_CONTRACT_VOID { diff --git a/src/coreclr/inc/utilcode.h b/src/coreclr/inc/utilcode.h index dcff853ed86016..823e83d198334e 100644 --- a/src/coreclr/inc/utilcode.h +++ b/src/coreclr/inc/utilcode.h @@ -36,7 +36,6 @@ using std::nothrow; #include "contract.h" #include -#include #include #include "clrnt.h" @@ -214,7 +213,7 @@ typedef LPSTR LPUTF8; // representable. This is reasonable for writing to the console, but // shouldn't be used for most string conversions. #define MAKE_MULTIBYTE_FROMWIDE_BESTFIT(ptrname, widestr, codepage) \ - int __l##ptrname = (int)minipal_u16_strlen((const CHAR16_T*)widestr); \ + int __l##ptrname = (int)u16_strlen(widestr); \ if (__l##ptrname > MAKE_MAX_LENGTH) \ MAKE_TOOLONGACTION; \ __l##ptrname = (int)((__l##ptrname + 1) * 2 * sizeof(char)); \ @@ -232,7 +231,7 @@ typedef LPSTR LPUTF8; // ptrname will be deleted when it goes out of scope. #define MAKE_UTF8PTR_FROMWIDE_NOTHROW(ptrname, widestr) \ CQuickBytes __qb##ptrname; \ - int __l##ptrname = (int)minipal_u16_strlen((const CHAR16_T*)widestr); \ + int __l##ptrname = (int)u16_strlen(widestr); \ LPUTF8 ptrname = NULL; \ if (__l##ptrname <= MAKE_MAX_LENGTH) { \ __l##ptrname = (int)((__l##ptrname + 1) * 2 * sizeof(char)); \ @@ -2187,7 +2186,7 @@ inline ULONG HashStringN(LPCWSTR szStr, SIZE_T cchStr) ULONG *ptr = (ULONG *)szStr; // we assume that szStr is null-terminated - _ASSERTE(cchStr <= minipal_u16_strlen((const CHAR16_T*)szStr)); + _ASSERTE(cchStr <= u16_strlen(szStr)); SIZE_T cDwordCount = (cchStr + 1) / 2; for (SIZE_T i = 0; i < cDwordCount; i++) diff --git a/src/coreclr/jit/disasm.cpp b/src/coreclr/jit/disasm.cpp index 952057ca50d961..bff93c85150a68 100644 --- a/src/coreclr/jit/disasm.cpp +++ b/src/coreclr/jit/disasm.cpp @@ -1210,7 +1210,7 @@ size_t CbDisassembleWithBytes(DIS* pdis, DIS::ADDR addr, const BYTE* pb, size_t { bool fFirst = (pwzBytes == wzBytes); - cchBytes = minipal_u16_strlen((const CHAR16_T*)pwzBytes); + cchBytes = u16_strlen(pwzBytes); if (cchBytes <= cchBytesMax) { diff --git a/src/coreclr/md/ceefilegen/ceesectionstring.cpp b/src/coreclr/md/ceefilegen/ceesectionstring.cpp index ba8bee2ce4249f..05d305bf8e7b90 100644 --- a/src/coreclr/md/ceefilegen/ceesectionstring.cpp +++ b/src/coreclr/md/ceefilegen/ceesectionstring.cpp @@ -42,7 +42,7 @@ StringTableEntry* CeeSectionString::createEntry(_In_z_ LPWSTR target, ULONG hash entry->m_next = NULL; entry->m_hashId = hashId; entry->m_offset = dataLen(); - size_t len = (minipal_u16_strlen((const CHAR16_T*)target)+1) * sizeof(WCHAR); + size_t len = (u16_strlen(target)+1) * sizeof(WCHAR); if (len > UINT32_MAX) { delete entry; return NULL; diff --git a/src/coreclr/md/compiler/assemblymd.cpp b/src/coreclr/md/compiler/assemblymd.cpp index 9e1b08f92eed61..f81e835bf92679 100644 --- a/src/coreclr/md/compiler/assemblymd.cpp +++ b/src/coreclr/md/compiler/assemblymd.cpp @@ -214,7 +214,7 @@ STDMETHODIMP RegMeta::GetExportedTypeProps( // S_OK or error. if (bTruncation || !szName) *pchName = ns::GetFullLength(wzTypeNamespace, wzTypeName); else - *pchName = (ULONG)(minipal_u16_strlen((const CHAR16_T*)szName) + 1); + *pchName = (ULONG)(u16_strlen(szName) + 1); } } if (ptkImplementation) diff --git a/src/coreclr/md/compiler/mdutil.cpp b/src/coreclr/md/compiler/mdutil.cpp index 8d0de1542a97b1..05b56a25875bb0 100644 --- a/src/coreclr/md/compiler/mdutil.cpp +++ b/src/coreclr/md/compiler/mdutil.cpp @@ -480,7 +480,7 @@ ULONG _GetSizeOfConstantBlob( if (cchString != (ULONG) -1) ulSize = cchString * sizeof(WCHAR); else - ulSize = (ULONG)(sizeof(WCHAR) * minipal_u16_strlen((const CHAR16_T*)(LPWSTR)pValue)); + ulSize = (ULONG)(sizeof(WCHAR) * u16_strlen((LPWSTR)pValue)); break; case ELEMENT_TYPE_CLASS: diff --git a/src/coreclr/md/compiler/regmeta.h b/src/coreclr/md/compiler/regmeta.h index 84d8517fd113db..78a854b778b0fe 100644 --- a/src/coreclr/md/compiler/regmeta.h +++ b/src/coreclr/md/compiler/regmeta.h @@ -40,7 +40,7 @@ struct CORDBG_SYMBOL_URL ULONG Size() const { - return (ULONG)(sizeof(GUID) + ((minipal_u16_strlen((const CHAR16_T*)rcName) + 1) * 2)); + return (ULONG)(sizeof(GUID) + ((u16_strlen(rcName) + 1) * 2)); } #ifdef _PREFAST_ diff --git a/src/coreclr/md/compiler/regmeta_import.cpp b/src/coreclr/md/compiler/regmeta_import.cpp index 3ffe8ffc1a9345..dd260d2f2ff855 100644 --- a/src/coreclr/md/compiler/regmeta_import.cpp +++ b/src/coreclr/md/compiler/regmeta_import.cpp @@ -765,7 +765,7 @@ RegMeta::GetTypeDefProps( } else { - *pchTypeDef = (ULONG)(minipal_u16_strlen((const CHAR16_T*)szTypeDef) + 1); + *pchTypeDef = (ULONG)(u16_strlen(szTypeDef) + 1); } } } @@ -900,7 +900,7 @@ RegMeta::GetTypeRefProps( } else { - *pchTypeRef = (ULONG)(minipal_u16_strlen((const CHAR16_T*)szTypeRef) + 1); + *pchTypeRef = (ULONG)(u16_strlen(szTypeRef) + 1); } } } diff --git a/src/coreclr/md/enc/liteweightstgdbrw.cpp b/src/coreclr/md/enc/liteweightstgdbrw.cpp index 31785a75276f18..3b2e2db604297b 100644 --- a/src/coreclr/md/enc/liteweightstgdbrw.cpp +++ b/src/coreclr/md/enc/liteweightstgdbrw.cpp @@ -1167,7 +1167,7 @@ CLiteWeightStgdbRW::SetFileName( // Size of the file name incl. null terminator size_t cchFileName; - cchFileName = minipal_u16_strlen((const CHAR16_T*)wszFileName) + 1; + cchFileName = u16_strlen(wszFileName) + 1; // Allocate and copy the file name m_wszFileName = new (nothrow) WCHAR[cchFileName]; diff --git a/src/coreclr/md/enc/rwutil.cpp b/src/coreclr/md/enc/rwutil.cpp index b25237dcfe9a74..36c326adc4d7ee 100644 --- a/src/coreclr/md/enc/rwutil.cpp +++ b/src/coreclr/md/enc/rwutil.cpp @@ -24,7 +24,7 @@ Unicode2UTF( LPUTF8 szDst, // Buffer for the output UTF8 string. int cbDst) // Size of the buffer for UTF8 string. { - int cchSrc = (int)minipal_u16_strlen((const CHAR16_T*)wszSrc); + int cchSrc = (int)u16_strlen(wszSrc); int cchRet; cchRet = WideCharToMultiByte( diff --git a/src/coreclr/md/inc/rwutil.h b/src/coreclr/md/inc/rwutil.h index 42879d96e02f6f..f6ee02817fb2b7 100644 --- a/src/coreclr/md/inc/rwutil.h +++ b/src/coreclr/md/inc/rwutil.h @@ -21,7 +21,7 @@ class UTSemReadWrite; } \ else \ { \ - int cbBuffer = ((int)minipal_u16_strlen((const CHAR16_T*)wszInput) * 3) + 1; \ + int cbBuffer = ((int)u16_strlen(wszInput) * 3) + 1; \ (szOutput) = (char *)_alloca(cbBuffer); \ Unicode2UTF((wszInput), (szOutput), cbBuffer); \ } \ diff --git a/src/coreclr/minipal/Unix/dn-u16.cpp b/src/coreclr/minipal/Unix/dn-u16.cpp index 688c313a61730f..aec3fb1ae66388 100644 --- a/src/coreclr/minipal/Unix/dn-u16.cpp +++ b/src/coreclr/minipal/Unix/dn-u16.cpp @@ -7,6 +7,11 @@ typedef char16_t WCHAR; #include #include +size_t u16_strlen(const WCHAR* str) +{ + return minipal_u16_strlen((CHAR16_T*)str); +} + int u16_strcmp(const WCHAR* str1, const WCHAR* str2) { return u16_strncmp(str1, str2, 0x7fffffff); @@ -47,7 +52,7 @@ WCHAR* u16_strcat_s(WCHAR* dst, size_t dstLen, const WCHAR* src) } // concatenate new string - size_t srcLength = minipal_u16_strlen((const CHAR16_T*)src); + size_t srcLength = u16_strlen(src); size_t loopCount = 0; while (*src && loopCount < srcLength) { @@ -89,7 +94,7 @@ WCHAR* u16_strncpy_s(WCHAR* dst, size_t dstLen, const WCHAR* src, size_t count) { ::memset(dst, 0, dstLen * sizeof(WCHAR)); - size_t srcLength = minipal_u16_strlen((const CHAR16_T*)src); + size_t srcLength = u16_strlen(src); size_t length = (count < srcLength) ? count : srcLength; if (length > dstLen) return nullptr; @@ -106,7 +111,7 @@ const WCHAR* u16_strstr(const WCHAR *str, const WCHAR *strCharSet) } // No characters to examine - if (minipal_u16_strlen((const CHAR16_T*)strCharSet) == 0) + if (u16_strlen(strCharSet) == 0) return str; const WCHAR* ret = nullptr; diff --git a/src/coreclr/minipal/Windows/dn-u16.cpp b/src/coreclr/minipal/Windows/dn-u16.cpp index 54a43f9e7b98e0..c915a8907bb1ca 100644 --- a/src/coreclr/minipal/Windows/dn-u16.cpp +++ b/src/coreclr/minipal/Windows/dn-u16.cpp @@ -6,6 +6,11 @@ #include +size_t u16_strlen(const WCHAR* str) +{ + return ::wcslen(str); +} + int u16_strcmp(const WCHAR* str1, const WCHAR* str2) { return ::wcscmp(str1, str2); diff --git a/src/coreclr/minipal/dn-u16.h b/src/coreclr/minipal/dn-u16.h index 0522b14358ce18..73279aca16b6c2 100644 --- a/src/coreclr/minipal/dn-u16.h +++ b/src/coreclr/minipal/dn-u16.h @@ -8,6 +8,7 @@ // Wide character (UTF-16) abstraction layer. // +size_t u16_strlen(const WCHAR* str); int u16_strcmp(const WCHAR* str1, const WCHAR* str2); int u16_strncmp(const WCHAR* str1, const WCHAR* str2, size_t count); WCHAR* u16_strcat_s(WCHAR* dst, size_t dstLen, const WCHAR* src); @@ -18,4 +19,4 @@ const WCHAR* u16_strchr(const WCHAR* str, WCHAR ch); const WCHAR* u16_strrchr(const WCHAR* str, WCHAR ch); uint32_t u16_strtoul(const WCHAR* nptr, WCHAR** endptr, int base); uint64_t u16_strtoui64(const WCHAR* nptr, WCHAR** endptr, int base); -double u16_strtod(const WCHAR* nptr, WCHAR** endptr); +double u16_strtod(const WCHAR* nptr, WCHAR** endptr); \ No newline at end of file diff --git a/src/coreclr/scripts/genEventPipe.py b/src/coreclr/scripts/genEventPipe.py index 64ddc54f6f436c..469852cfc63d8d 100644 --- a/src/coreclr/scripts/genEventPipe.py +++ b/src/coreclr/scripts/genEventPipe.py @@ -499,7 +499,7 @@ def getCoreCLREventPipeHelperFileImplPrefix(): bool WriteToBuffer(PCWSTR str, BYTE *&buffer, size_t& offset, size_t& size, bool &fixedBuffer) { if (!str) return true; - size_t byteCount = (minipal_u16_strlen((const CHAR16_T*)str) + 1) * sizeof(*str); + size_t byteCount = (u16_strlen(str) + 1) * sizeof(*str); if (offset + byteCount > size) { diff --git a/src/coreclr/tools/metainfo/mdobj.cpp b/src/coreclr/tools/metainfo/mdobj.cpp index 107325f8cfac72..65cae4e7850a79 100644 --- a/src/coreclr/tools/metainfo/mdobj.cpp +++ b/src/coreclr/tools/metainfo/mdobj.cpp @@ -255,7 +255,7 @@ void DisplayFile(_In_z_ WCHAR* szFile, BOOL isFile, ULONG DumpFilter, _In_opt_z_ // We need to make sure this file isn't too long. Checking _MAX_PATH is probably safe, but since we have a much // larger buffer, we might as well use it all. - if (minipal_u16_strlen((const CHAR16_T*)szFile) > 1000) + if (u16_strlen(szFile) > 1000) return; diff --git a/src/coreclr/tools/superpmi/mcs/verbmerge.cpp b/src/coreclr/tools/superpmi/mcs/verbmerge.cpp index 874e8610cc3860..0ee42013119646 100644 --- a/src/coreclr/tools/superpmi/mcs/verbmerge.cpp +++ b/src/coreclr/tools/superpmi/mcs/verbmerge.cpp @@ -20,8 +20,8 @@ RemoveDup verbMerge::m_removeDups; // static LPWSTR verbMerge::MergePathStrings(LPCWSTR dir, LPCWSTR file) { - size_t dirlen = minipal_u16_strlen((const CHAR16_T*)dir); - size_t filelen = minipal_u16_strlen((const CHAR16_T*)file); + size_t dirlen = u16_strlen(dir); + size_t filelen = u16_strlen(file); size_t newlen = dirlen + 1 /* slash */ + filelen + 1 /* null */; LPWSTR newpath = new WCHAR[newlen]; u16_strcpy_s(newpath, newlen, dir); @@ -352,14 +352,14 @@ int verbMerge::AppendAllInDir(HANDLE hFileOut, const _WIN32_FIND_DATAW& findData = fileArray[i]; LPWSTR fileFullPath = MergePathStrings(dir, findData.cFileName); #ifdef TARGET_WINDOWS - if (minipal_u16_strlen((const CHAR16_T*)fileFullPath) > MAX_PATH) // This path is too long, use \\?\ to access it. + if (u16_strlen(fileFullPath) > MAX_PATH) // This path is too long, use \\?\ to access it. { if (u16_strcmp(dir, W(".")) == 0) { LogError("can't access the relative path with UNC"); goto CLEAN_UP; } - size_t newBufferLen = minipal_u16_strlen((const CHAR16_T*)fileFullPath) + 30; + size_t newBufferLen = u16_strlen(fileFullPath) + 30; LPWSTR newBuffer = new WCHAR[newBufferLen]; u16_strcpy_s(newBuffer, newBufferLen, W("\\\\?\\")); if (*fileFullPath == '\\') // It is UNC path, use \\?\UNC\serverName to access it. diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index fd888a7c718d99..8455abdb80d61c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -1268,7 +1268,7 @@ void MethodContext::recGetJitTimeLogFilename(LPCWSTR tempFileName) DWORD name_index = -1; if (tempFileName != nullptr) { - name_index = GetJitTimeLogFilename->AddBuffer((unsigned char*)tempFileName, (DWORD)minipal_u16_strlen((const CHAR16_T*)tempFileName) + 2); + name_index = GetJitTimeLogFilename->AddBuffer((unsigned char*)tempFileName, (DWORD)u16_strlen(tempFileName) + 2); } GetJitTimeLogFilename->Add(0, name_index); DEBUG_REC(dmpGetJitTimeLogFilename(0, name_index)); @@ -7089,7 +7089,7 @@ void MethodContext::recGetIntConfigValue(const WCHAR* name, int defaultValue, in ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding DWORD index = - (DWORD)GetIntConfigValue->AddBuffer((unsigned char*)name, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)name) + 1)); + (DWORD)GetIntConfigValue->AddBuffer((unsigned char*)name, sizeof(WCHAR) * ((unsigned int)u16_strlen(name) + 1)); key.nameIndex = index; key.defaultValue = defaultValue; @@ -7119,7 +7119,7 @@ int MethodContext::repGetIntConfigValue(const WCHAR* name, int defaultValue) Agnostic_ConfigIntInfo key; ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding - size_t nameLenInBytes = sizeof(WCHAR) * (minipal_u16_strlen((const CHAR16_T*)name) + 1); + size_t nameLenInBytes = sizeof(WCHAR) * (u16_strlen(name) + 1); int nameIndex = GetIntConfigValue->Contains((unsigned char*)name, (unsigned int)nameLenInBytes); if (nameIndex == -1) // config name not in map return defaultValue; @@ -7147,12 +7147,12 @@ void MethodContext::recGetStringConfigValue(const WCHAR* name, const WCHAR* resu AssertCodeMsg(name != nullptr, EXCEPTIONCODE_MC, "Name can not be nullptr"); DWORD nameIndex = (DWORD)GetStringConfigValue->AddBuffer((unsigned char*)name, - sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)name) + 1)); + sizeof(WCHAR) * ((unsigned int)u16_strlen(name) + 1)); DWORD resultIndex = (DWORD)-1; if (result != nullptr) resultIndex = (DWORD)GetStringConfigValue->AddBuffer((unsigned char*)result, - sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)result) + 1)); + sizeof(WCHAR) * ((unsigned int)u16_strlen(result) + 1)); GetStringConfigValue->Add(nameIndex, resultIndex); DEBUG_REC(dmpGetStringConfigValue(nameIndex, resultIndex)); @@ -7176,7 +7176,7 @@ const WCHAR* MethodContext::repGetStringConfigValue(const WCHAR* name) AssertCodeMsg(name != nullptr, EXCEPTIONCODE_MC, "Name can not be nullptr"); - size_t nameLenInBytes = sizeof(WCHAR) * (minipal_u16_strlen((const CHAR16_T*)name) + 1); + size_t nameLenInBytes = sizeof(WCHAR) * (u16_strlen(name) + 1); int nameIndex = GetStringConfigValue->Contains((unsigned char*)name, (unsigned int)nameLenInBytes); if (nameIndex == -1) // config name not in map return nullptr; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp b/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp index 4db099f29c6a3c..9bba21b1bfd8e5 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp @@ -90,7 +90,7 @@ WCHAR* GetEnvironmentVariableWithDefaultW(const WCHAR* envVarName, const WCHAR* { if (defaultValue != nullptr) { - dwRetVal = (DWORD)minipal_u16_strlen((const CHAR16_T*)defaultValue) + 1; // add one for null terminator + dwRetVal = (DWORD)u16_strlen(defaultValue) + 1; // add one for null terminator retString = new WCHAR[dwRetVal]; memcpy_s(retString, dwRetVal * sizeof(WCHAR), defaultValue, dwRetVal * sizeof(WCHAR)); } @@ -190,8 +190,8 @@ void ReplaceIllegalCharacters(WCHAR* fileName) // All lengths in this function exclude the terminal NULL. WCHAR* GetResultFileName(const WCHAR* folderPath, const WCHAR* fileName, const WCHAR* extension) { - const size_t extensionLength = minipal_u16_strlen((const CHAR16_T*)extension); - const size_t fileNameLength = minipal_u16_strlen((const CHAR16_T*)fileName); + const size_t extensionLength = u16_strlen(extension); + const size_t fileNameLength = u16_strlen(fileName); const size_t randomStringLength = 8; const size_t maxPathLength = MAX_PATH - 50; diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp index 2dfd9c6f9a83df..a8f4046d83d660 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp @@ -37,7 +37,7 @@ void SetDefaultPaths() if (g_DefaultRealJitPath == nullptr) { - size_t len = minipal_u16_strlen((const CHAR16_T*)g_HomeDirectory) + 1 + minipal_u16_strlen((const CHAR16_T*)DEFAULT_REAL_JIT_NAME_W) + 1; + size_t len = u16_strlen(g_HomeDirectory) + 1 + u16_strlen(DEFAULT_REAL_JIT_NAME_W) + 1; g_DefaultRealJitPath = new WCHAR[len]; wcscpy_s(g_DefaultRealJitPath, len, g_HomeDirectory); wcscat_s(g_DefaultRealJitPath, len, DIRECTORY_SEPARATOR_STR_W); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp index a9d0cf0eac8832..de3cac7cec4b6c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp @@ -31,7 +31,7 @@ void SetDefaultPaths() if (g_DefaultRealJitPath == nullptr) { - size_t len = minipal_u16_strlen((const CHAR16_T*)g_HomeDirectory) + 1 + minipal_u16_strlen((const CHAR16_T*)DEFAULT_REAL_JIT_NAME_W) + 1; + size_t len = u16_strlen(g_HomeDirectory) + 1 + u16_strlen(DEFAULT_REAL_JIT_NAME_W) + 1; g_DefaultRealJitPath = new WCHAR[len]; wcscpy_s(g_DefaultRealJitPath, len, g_HomeDirectory); wcscat_s(g_DefaultRealJitPath, len, DIRECTORY_SEPARATOR_STR_W); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/superpmi-shim-simple.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/superpmi-shim-simple.cpp index 3f8050b24b42b5..27fe53c8b4782f 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/superpmi-shim-simple.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/superpmi-shim-simple.cpp @@ -29,7 +29,7 @@ void SetDefaultPaths() if (g_DefaultRealJitPath == nullptr) { - size_t len = minipal_u16_strlen((const CHAR16_T*)g_HomeDirectory) + 1 + minipal_u16_strlen((const CHAR16_T*)DEFAULT_REAL_JIT_NAME_W) + 1; + size_t len = u16_strlen(g_HomeDirectory) + 1 + u16_strlen(DEFAULT_REAL_JIT_NAME_W) + 1; g_DefaultRealJitPath = new WCHAR[len]; wcscpy_s(g_DefaultRealJitPath, len, g_HomeDirectory); wcscat_s(g_DefaultRealJitPath, len, DIRECTORY_SEPARATOR_STR_W); diff --git a/src/coreclr/tools/superpmi/superpmi/commandline.cpp b/src/coreclr/tools/superpmi/superpmi/commandline.cpp index 62769662cbdcab..ddd42e3a2e098b 100644 --- a/src/coreclr/tools/superpmi/superpmi/commandline.cpp +++ b/src/coreclr/tools/superpmi/superpmi/commandline.cpp @@ -921,9 +921,9 @@ bool CommandLine::AddJitOption(int& currArgument, } DWORD keyIndex = - (DWORD)targetjitOptions->AddBuffer((unsigned char*)key, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)key) + 1)); + (DWORD)targetjitOptions->AddBuffer((unsigned char*)key, sizeof(WCHAR) * ((unsigned int)u16_strlen(key) + 1)); DWORD valueIndex = - (DWORD)targetjitOptions->AddBuffer((unsigned char*)value, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)value) + 1)); + (DWORD)targetjitOptions->AddBuffer((unsigned char*)value, sizeof(WCHAR) * ((unsigned int)u16_strlen(value) + 1)); targetjitOptions->Add(keyIndex, valueIndex); delete[] key; diff --git a/src/coreclr/tools/superpmi/superpmi/jitdebugger.cpp b/src/coreclr/tools/superpmi/superpmi/jitdebugger.cpp index e7d9941c38cc3a..e2878935ba45dd 100644 --- a/src/coreclr/tools/superpmi/superpmi/jitdebugger.cpp +++ b/src/coreclr/tools/superpmi/superpmi/jitdebugger.cpp @@ -154,9 +154,9 @@ HRESULT GetCurrentModuleFileName(_Out_writes_(*pcchBuffer) LPWSTR pBuffer, __ino // If no backslash, use the whole name; if there is a backslash, skip it. appName = appName ? appName + 1 : appPath; - if (*pcchBuffer < minipal_u16_strlen((const CHAR16_T*)appName)) + if (*pcchBuffer < u16_strlen(appName)) { - *pcchBuffer = static_cast(minipal_u16_strlen((const CHAR16_T*)appName)) + 1; + *pcchBuffer = static_cast(u16_strlen(appName)) + 1; return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } diff --git a/src/coreclr/tools/superpmi/superpmi/jithost.cpp b/src/coreclr/tools/superpmi/superpmi/jithost.cpp index 72c4bc79bdc00d..65d4513e276f34 100644 --- a/src/coreclr/tools/superpmi/superpmi/jithost.cpp +++ b/src/coreclr/tools/superpmi/superpmi/jithost.cpp @@ -12,7 +12,7 @@ WCHAR* GetPrefixedEnvironmentVariable(const WCHAR* prefix, size_t prefixLen, const WCHAR* key, JitInstance& jitInstance) { // Prepend prefix to the provided key - size_t keyLen = minipal_u16_strlen((const CHAR16_T*)key); + size_t keyLen = u16_strlen(key); size_t keyBufferLen = keyLen + prefixLen + 1; WCHAR* keyBuffer = reinterpret_cast(jitInstance.allocateArray(sizeof(WCHAR) * keyBufferLen)); @@ -178,7 +178,7 @@ const WCHAR* JitHost::getStringConfigValue(const WCHAR* key) if (result != nullptr && needToDup) { // Now we need to dup it, so you can call freeStringConfigValue() on what we return. - size_t resultLenInChars = minipal_u16_strlen((const CHAR16_T*)result) + 1; + size_t resultLenInChars = u16_strlen(result) + 1; WCHAR* dupResult = (WCHAR*)jitInstance.allocateLongLivedArray(sizeof(WCHAR) * resultLenInChars); wcscpy_s(dupResult, resultLenInChars, result); result = dupResult; diff --git a/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp b/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp index b900624a9dd49d..2f085b2610d86b 100644 --- a/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp +++ b/src/coreclr/tools/superpmi/superpmi/jitinstance.cpp @@ -527,7 +527,7 @@ const WCHAR* JitInstance::getOption(const WCHAR* key, LightWeightMapContains((unsigned char*)key, (unsigned int)keyLenInBytes); if (keyIndex == -1) { diff --git a/src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp b/src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp index 63392e7390c15e..4da3f0f0561fbd 100644 --- a/src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp +++ b/src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp @@ -30,9 +30,9 @@ static bool AddJitOption(LightWeightMap* map, char* newOption) } DWORD keyIndex = - (DWORD)map->AddBuffer((unsigned char*)key, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)key) + 1)); + (DWORD)map->AddBuffer((unsigned char*)key, sizeof(WCHAR) * ((unsigned int)u16_strlen(key) + 1)); DWORD valueIndex = - (DWORD)map->AddBuffer((unsigned char*)value, sizeof(WCHAR) * ((unsigned int)minipal_u16_strlen((const CHAR16_T*)value) + 1)); + (DWORD)map->AddBuffer((unsigned char*)value, sizeof(WCHAR) * ((unsigned int)u16_strlen(value) + 1)); map->Add(keyIndex, valueIndex); delete[] key; diff --git a/src/coreclr/utilcode/ccomprc.cpp b/src/coreclr/utilcode/ccomprc.cpp index 3367da18206e1a..10d1fd28f66d49 100644 --- a/src/coreclr/utilcode/ccomprc.cpp +++ b/src/coreclr/utilcode/ccomprc.cpp @@ -136,7 +136,7 @@ HRESULT CCompRC::Init(LPCWSTR pResourceFile) { NewArrayHolder pwszResourceFile(NULL); - DWORD lgth = (DWORD) minipal_u16_strlen((const CHAR16_T*)pResourceFile) + 1; + DWORD lgth = (DWORD) u16_strlen(pResourceFile) + 1; pwszResourceFile = new(nothrow) WCHAR[lgth]; if (pwszResourceFile) { diff --git a/src/coreclr/utilcode/clrconfig.cpp b/src/coreclr/utilcode/clrconfig.cpp index 21ba3393b92683..b531018eb08ae1 100644 --- a/src/coreclr/utilcode/clrconfig.cpp +++ b/src/coreclr/utilcode/clrconfig.cpp @@ -143,7 +143,7 @@ namespace WCHAR buff[64]; const WCHAR* fallbackPrefix = NULL; - const size_t namelen = minipal_u16_strlen((const CHAR16_T*)name); + const size_t namelen = u16_strlen(name); bool noPrefix = CheckLookupOption(options, LookupOptions::DontPrependPrefix); if (noPrefix) @@ -328,7 +328,7 @@ namespace *pwszTrimmed = NULL; // Get pointers into internal string that show where to do the trimming. - size_t cchOrig = minipal_u16_strlen((const CHAR16_T*)wszOrig); + size_t cchOrig = u16_strlen(wszOrig); if (!FitsIn(cchOrig)) return COR_E_OVERFLOW; DWORD cchAfterTrim = (DWORD) cchOrig; diff --git a/src/coreclr/utilcode/guidfromname.cpp b/src/coreclr/utilcode/guidfromname.cpp index 1587b3d28eabf4..7c230c977f17cd 100644 --- a/src/coreclr/utilcode/guidfromname.cpp +++ b/src/coreclr/utilcode/guidfromname.cpp @@ -206,5 +206,5 @@ void CorGuidFromNameW pGuidResult, COMPLUS_RUNTIME_GUID, wzName, - (DWORD)((cchName == (SIZE_T) -1 ? (minipal_u16_strlen((const CHAR16_T*)wzName)+1) : cchName) * sizeof(WCHAR))); + (DWORD)((cchName == (SIZE_T) -1 ? (u16_strlen(wzName)+1) : cchName) * sizeof(WCHAR))); } diff --git a/src/coreclr/utilcode/log.cpp b/src/coreclr/utilcode/log.cpp index e1805727ab1328..56ddf6aef9c20e 100644 --- a/src/coreclr/utilcode/log.cpp +++ b/src/coreclr/utilcode/log.cpp @@ -66,7 +66,7 @@ VOID InitLogging() LPWSTR fileName = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_LogFile); if (fileName != 0) { - if (SUCCEEDED(szLogFileName.ReSizeNoThrow(minipal_u16_strlen((const CHAR16_T*)fileName) + 32))) + if (SUCCEEDED(szLogFileName.ReSizeNoThrow(u16_strlen(fileName) + 32))) { wcscpy_s(szLogFileName.Ptr(), szLogFileName.Size(), fileName); } @@ -98,9 +98,9 @@ VOID InitLogging() NULL); // Some other logging may be going on, try again with another file name - if (LogFileHandle == INVALID_HANDLE_VALUE && minipal_u16_strlen((const CHAR16_T*)szLogFileName.Ptr()) + 3 <= szLogFileName.Size()) + if (LogFileHandle == INVALID_HANDLE_VALUE && u16_strlen(szLogFileName.Ptr()) + 3 <= szLogFileName.Size()) { - WCHAR* ptr = szLogFileName.Ptr() + minipal_u16_strlen((const CHAR16_T*)szLogFileName.Ptr()) + 1; + WCHAR* ptr = szLogFileName.Ptr() + u16_strlen(szLogFileName.Ptr()) + 1; ptr[-1] = W('.'); ptr[0] = W('0'); ptr[1] = 0; diff --git a/src/coreclr/utilcode/longfilepathwrappers.cpp b/src/coreclr/utilcode/longfilepathwrappers.cpp index 8316f8541f60fb..09e3118fc8fe05 100644 --- a/src/coreclr/utilcode/longfilepathwrappers.cpp +++ b/src/coreclr/utilcode/longfilepathwrappers.cpp @@ -530,7 +530,7 @@ HRESULT LongFile::NormalizePath(SString & path) //In this case if path is \\server the extended syntax should be like \\?\UNC\server //The below logic populates the path from prefixLen offset from the start. This ensures that first 2 characters are overwritten // - prefixLen = prefix.GetCount() - (COUNT_T)minipal_u16_strlen((const CHAR16_T*)UNCPATHPREFIX); + prefixLen = prefix.GetCount() - (COUNT_T)u16_strlen(UNCPATHPREFIX); _ASSERTE(prefixLen > 0 ); } @@ -574,10 +574,10 @@ HRESULT LongFile::NormalizePath(SString & path) SString fullpath(SString::Literal,buffer + prefixLen); //Check if the resolved path is a UNC. By default we assume relative path to resolve to disk - if (fullpath.BeginsWith(SL(UNCPathPrefix)) && prefixLen != prefix.GetCount() - (COUNT_T)minipal_u16_strlen((const CHAR16_T*)UNCPATHPREFIX)) + if (fullpath.BeginsWith(SL(UNCPathPrefix)) && prefixLen != prefix.GetCount() - (COUNT_T)u16_strlen(UNCPATHPREFIX)) { //Remove the leading '\\' from the UNC path to be replaced with UNCExtendedPathPrefix - fullpath.Replace(fullpath.Begin(), (COUNT_T)minipal_u16_strlen((const CHAR16_T*)UNCPATHPREFIX), SL(UNCExtendedPathPrefix)); + fullpath.Replace(fullpath.Begin(), (COUNT_T)u16_strlen(UNCPATHPREFIX), SL(UNCExtendedPathPrefix)); path.CloseBuffer(); path.Set(fullpath); } diff --git a/src/coreclr/utilcode/namespaceutil.cpp b/src/coreclr/utilcode/namespaceutil.cpp index 373879dd321fe5..c17b07abae3ab5 100644 --- a/src/coreclr/utilcode/namespaceutil.cpp +++ b/src/coreclr/utilcode/namespaceutil.cpp @@ -35,9 +35,9 @@ int ns::GetFullLength( // Number of chars in full name. int iLen = 1; // Null terminator. if (szNameSpace) - iLen += (int)minipal_u16_strlen((const CHAR16_T*)szNameSpace); + iLen += (int)u16_strlen(szNameSpace); if (szName) - iLen += (int)minipal_u16_strlen((const CHAR16_T*)szName); + iLen += (int)u16_strlen(szName); if (szNameSpace && *szNameSpace && szName && *szName) ++iLen; return iLen; @@ -186,7 +186,7 @@ int ns::SplitPath( // true ok, false trunction. ++ptr; else ptr = szPath; - iLen = (int)minipal_u16_strlen((const CHAR16_T*)ptr); + iLen = (int)u16_strlen(ptr); iCopyMax = min(iCopyMax, iLen); wcsncpy_s(szName, cchName, ptr, iCopyMax); szName[iCopyMax] = 0; diff --git a/src/coreclr/utilcode/pedecoder.cpp b/src/coreclr/utilcode/pedecoder.cpp index 011598139d281b..fd44a050d36eec 100644 --- a/src/coreclr/utilcode/pedecoder.cpp +++ b/src/coreclr/utilcode/pedecoder.cpp @@ -1756,7 +1756,7 @@ DWORD ReadResourceDirectory(const PEDecoder *pDecoder, DWORD rvaOfResourceSectio return 0; size_t entryNameLen = *(WORD*)pDecoder->GetRvaData(entryNameRva); - if (minipal_u16_strlen((const CHAR16_T*)name) != entryNameLen) + if (u16_strlen(name) != entryNameLen) continue; if (!pDecoder->CheckRva(entryNameRva, (COUNT_T)(sizeof(WORD) * (1 + entryNameLen)))) diff --git a/src/coreclr/utilcode/posterror.cpp b/src/coreclr/utilcode/posterror.cpp index 58119ff9f2f04e..c2a959a9a4381b 100644 --- a/src/coreclr/utilcode/posterror.cpp +++ b/src/coreclr/utilcode/posterror.cpp @@ -149,7 +149,7 @@ static HRESULT FormatRuntimeErrorVA( hr = S_OK; // System messages contain a trailing \r\n, which we don't want normally. - size_t iLen = minipal_u16_strlen((const CHAR16_T*)rcMsg); + size_t iLen = u16_strlen(rcMsg); if (iLen > 3 && rcMsg[iLen - 2] == '\r' && rcMsg[iLen - 1] == '\n') rcMsg[iLen - 2] = '\0'; } diff --git a/src/coreclr/utilcode/prettyprintsig.cpp b/src/coreclr/utilcode/prettyprintsig.cpp index b07c56753c8508..31f6a93c4a194b 100644 --- a/src/coreclr/utilcode/prettyprintsig.cpp +++ b/src/coreclr/utilcode/prettyprintsig.cpp @@ -65,7 +65,7 @@ static HRESULT appendStrW(CQuickBytes *out, const WCHAR* str) } CONTRACTL_END - SIZE_T len = minipal_u16_strlen((const CHAR16_T*)str) * sizeof(WCHAR); + SIZE_T len = u16_strlen(str) * sizeof(WCHAR); SIZE_T oldSize = out->Size(); if (FAILED(out->ReSizeNoThrow(oldSize + len))) return E_OUTOFMEMORY; diff --git a/src/coreclr/utilcode/splitpath.cpp b/src/coreclr/utilcode/splitpath.cpp index d69abfa2522a38..40619f17230a63 100644 --- a/src/coreclr/utilcode/splitpath.cpp +++ b/src/coreclr/utilcode/splitpath.cpp @@ -86,7 +86,7 @@ void SplitPathInterior( /* extract drive letter and :, if any */ - if ((minipal_u16_strlen((const CHAR16_T*)wszPath) > (_MAX_DRIVE - 2)) && (*(wszPath + _MAX_DRIVE - 2) == _T(':'))) { + if ((u16_strlen(wszPath) > (_MAX_DRIVE - 2)) && (*(wszPath + _MAX_DRIVE - 2) == _T(':'))) { if (pwszDrive && pcchDrive) { *pwszDrive = wszPath; *pcchDrive = _MAX_DRIVE - 1; diff --git a/src/coreclr/utilcode/sstring.cpp b/src/coreclr/utilcode/sstring.cpp index 3adab615b29a87..2fb454c369cab4 100644 --- a/src/coreclr/utilcode/sstring.cpp +++ b/src/coreclr/utilcode/sstring.cpp @@ -244,7 +244,7 @@ void SString::Set(const WCHAR *string) Clear(); else { - Resize((COUNT_T) minipal_u16_strlen((const CHAR16_T*)string), REPRESENTATION_UNICODE); + Resize((COUNT_T) u16_strlen(string), REPRESENTATION_UNICODE); wcscpy_s(GetRawUnicode(), GetBufferSizeInCharIncludeNullChar(), string); } diff --git a/src/coreclr/utilcode/sstring_com.cpp b/src/coreclr/utilcode/sstring_com.cpp index ca5aa1d227e7ef..b674556741fcb5 100644 --- a/src/coreclr/utilcode/sstring_com.cpp +++ b/src/coreclr/utilcode/sstring_com.cpp @@ -73,7 +73,7 @@ HRESULT SString::LoadResourceAndReturnHR(CCompRC::ResourceCategory eCategory, in if (SUCCEEDED(hr)) { - Truncate(Begin() + (COUNT_T) minipal_u16_strlen((const CHAR16_T*)GetRawUnicode())); + Truncate(Begin() + (COUNT_T) u16_strlen(GetRawUnicode())); } Normalize(); diff --git a/src/coreclr/utilcode/stresslog.cpp b/src/coreclr/utilcode/stresslog.cpp index 652b83e5ff5cf9..aa3cbcfce70cef 100644 --- a/src/coreclr/utilcode/stresslog.cpp +++ b/src/coreclr/utilcode/stresslog.cpp @@ -177,11 +177,11 @@ void ReplacePid(LPCWSTR original, LPWSTR replaced, size_t replacedLength) wcscat_s(replaced, replacedLength, pidStr); // append the rest of the filename - wcscat_s(replaced, replacedLength, original + pidInx + minipal_u16_strlen((const CHAR16_T*)pidLit)); + wcscat_s(replaced, replacedLength, original + pidInx + u16_strlen(pidLit)); } else { - size_t originalLength = minipal_u16_strlen((const CHAR16_T*)original); + size_t originalLength = u16_strlen(original); wcsncpy_s(replaced, replacedLength, original, originalLength); } } diff --git a/src/coreclr/utilcode/util.cpp b/src/coreclr/utilcode/util.cpp index 26d04b94bf42f9..01d03df5da050d 100644 --- a/src/coreclr/utilcode/util.cpp +++ b/src/coreclr/utilcode/util.cpp @@ -221,7 +221,7 @@ namespace if (phmodDll != nullptr) *phmodDll = nullptr; - bool fIsDllPathPrefix = (wszDllPath != nullptr) && (minipal_u16_strlen((const CHAR16_T*)wszDllPath) > 0) && (wszDllPath[minipal_u16_strlen((const CHAR16_T*)wszDllPath) - 1] == W('\\')); + bool fIsDllPathPrefix = (wszDllPath != nullptr) && (u16_strlen(wszDllPath) > 0) && (wszDllPath[u16_strlen(wszDllPath) - 1] == W('\\')); // - An empty string will be treated as NULL. // - A string ending will a backslash will be treated as a prefix for where to look for the DLL @@ -2619,7 +2619,7 @@ namespace Reg // terminating NULL is not a legitimate scenario for REG_SZ - this must // be done using REG_MULTI_SZ - however this was tolerated in the // past and so it would be a breaking change to stop doing so. - _ASSERTE(minipal_u16_strlen((const CHAR16_T*)wszValueBuf) <= (size / sizeof(WCHAR)) - 1); + _ASSERTE(u16_strlen(wszValueBuf) <= (size / sizeof(WCHAR)) - 1); ssValue.CloseBuffer((COUNT_T)wcsnlen(wszValueBuf, (size_t)size)); } else diff --git a/src/coreclr/utilcode/util_nodependencies.cpp b/src/coreclr/utilcode/util_nodependencies.cpp index d15c7286f668d1..3a08158b0daadb 100644 --- a/src/coreclr/utilcode/util_nodependencies.cpp +++ b/src/coreclr/utilcode/util_nodependencies.cpp @@ -621,7 +621,7 @@ LPCWSTRToGuid( // covering the 128-bit GUID. The string includes enclosing braces, which are an OLE convention. // Verify the surrounding syntax. - if (minipal_u16_strlen((const CHAR16_T*)szGuid) != 38 || szGuid[0] != '{' || szGuid[9] != '-' || + if (u16_strlen(szGuid) != 38 || szGuid[0] != '{' || szGuid[9] != '-' || szGuid[14] != '-' || szGuid[19] != '-' || szGuid[24] != '-' || szGuid[37] != '}') { return FALSE; diff --git a/src/coreclr/utilcode/winfix.cpp b/src/coreclr/utilcode/winfix.cpp index 1951ac5cc1bc54..9738475350c94b 100644 --- a/src/coreclr/utilcode/winfix.cpp +++ b/src/coreclr/utilcode/winfix.cpp @@ -30,7 +30,7 @@ WszCreateProcess( BOOL fResult; DWORD err; { - size_t commandLineLength = minipal_u16_strlen((const CHAR16_T*)lpCommandLine) + 1; + size_t commandLineLength = u16_strlen(lpCommandLine) + 1; NewArrayHolder nonConstCommandLine(new (nothrow) WCHAR[commandLineLength]); if (nonConstCommandLine == NULL) { diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index cc90cac90af383..ce933c43739a11 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -2975,7 +2975,7 @@ void AppDomain::AddUnmanagedImageToCache(LPCWSTR libraryName, NATIVE_LIBRARY_HAN return; } - size_t len = (minipal_u16_strlen((const CHAR16_T*)libraryName) + 1) * sizeof(WCHAR); + size_t len = (u16_strlen(libraryName) + 1) * sizeof(WCHAR); AllocMemHolder copiedName(GetLowFrequencyHeap()->AllocMem(S_SIZE_T(len))); memcpy(copiedName, libraryName, len); diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 77e4f0d1cb7d7d..6309f9bfcb10c6 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -1043,12 +1043,12 @@ void Assembly::AddDiagnosticStartupHookPath(LPCWSTR wszPath) { LPCWSTR wszDiagnosticStartupHookPathsLocal = s_wszDiagnosticStartupHookPaths; - size_t cchPath = minipal_u16_strlen((const CHAR16_T*)wszPath); + size_t cchPath = u16_strlen(wszPath); size_t cchDiagnosticStartupHookPathsNew = cchPath; size_t cchDiagnosticStartupHookPathsLocal = 0; if (nullptr != wszDiagnosticStartupHookPathsLocal) { - cchDiagnosticStartupHookPathsLocal = minipal_u16_strlen((const CHAR16_T*)wszDiagnosticStartupHookPathsLocal); + cchDiagnosticStartupHookPathsLocal = u16_strlen(wszDiagnosticStartupHookPathsLocal); // Add 1 for the path separator cchDiagnosticStartupHookPathsNew += cchDiagnosticStartupHookPathsLocal + 1; } diff --git a/src/coreclr/vm/autotrace.cpp b/src/coreclr/vm/autotrace.cpp index 023fe40c23eec0..c41d55537f5f70 100644 --- a/src/coreclr/vm/autotrace.cpp +++ b/src/coreclr/vm/autotrace.cpp @@ -50,7 +50,7 @@ void auto_trace_init() // Copy in the command - %s wcscpy_s(command, bufferLen, commandTextValue); - written += minipal_u16_strlen((const CHAR16_T*)commandTextValue); + written += u16_strlen(commandTextValue); // Append " -p " wcscat_s(command, bufferLen - written, flagFormat); diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 01539e12da4217..f4d075b126e139 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -3668,7 +3668,7 @@ void Append_Next_Item(LPWSTR* ppCursor, SIZE_T* pRemainingLen, LPCWSTR pItem, bo SIZE_T remainingLen = *pRemainingLen; // Calculate the length of pItem - SIZE_T itemLen = minipal_u16_strlen((const CHAR16_T*)pItem); + SIZE_T itemLen = u16_strlen(pItem); // Append pItem at pCursor wcscpy_s(pCursor, remainingLen, pItem); @@ -3708,14 +3708,14 @@ void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) #else // On UNIX, the PAL doesn't have the command line arguments, so we must build the command line. // osCommandLine contains the full path to the executable. - SIZE_T commandLineLen = (minipal_u16_strlen((const CHAR16_T*)osCommandLine) + 1); + SIZE_T commandLineLen = (u16_strlen(osCommandLine) + 1); // We will append pwzAssemblyPath to the 'corerun' osCommandLine - commandLineLen += (minipal_u16_strlen((const CHAR16_T*)pwzAssemblyPath) + 1); + commandLineLen += (u16_strlen(pwzAssemblyPath) + 1); for (int i = 0; i < argc; i++) { - commandLineLen += (minipal_u16_strlen((const CHAR16_T*)argv[i]) + 1); + commandLineLen += (u16_strlen(argv[i]) + 1); } commandLineLen++; // Add 1 for the null-termination diff --git a/src/coreclr/vm/commtmemberinfomap.cpp b/src/coreclr/vm/commtmemberinfomap.cpp index bc93983e7ef2e6..a451e96287c1fe 100644 --- a/src/coreclr/vm/commtmemberinfomap.cpp +++ b/src/coreclr/vm/commtmemberinfomap.cpp @@ -332,7 +332,7 @@ void ComMTMemberInfoMap::SetupPropsForIClassX(size_t sizeOfPtr) IfFailThrow(pField->GetMDImport()->GetNameOfFieldDef(pField->GetMemberDef(), &pszName)); IfFailThrow(Utf2Quick(pszName, rName)); - ULONG cchpName = ((int)minipal_u16_strlen((const CHAR16_T*)rName.Ptr())) + 1; + ULONG cchpName = ((int)u16_strlen(rName.Ptr())) + 1; m_MethodProps[i].pName = reinterpret_cast(m_sNames.Alloc(cchpName * sizeof(WCHAR))); m_MethodProps[i].pMeth = (MethodDesc*)pFieldMeth; @@ -451,12 +451,12 @@ void ComMTMemberInfoMap::SetupPropsForIClassX(size_t sizeOfPtr) WCHAR *pNewName; //string length + "get" + null terminator. //XXX Fri 11/19/2004 Why is this + 4 rather than +3? - ULONG cchpNewName = ((int)minipal_u16_strlen((const CHAR16_T*)m_MethodProps[ixGet].pName)) + 4 + 1; + ULONG cchpNewName = ((int)u16_strlen(m_MethodProps[ixGet].pName)) + 4 + 1; pNewName = reinterpret_cast(m_sNames.Alloc(cchpNewName * sizeof(WCHAR))); wcscpy_s(pNewName, cchpNewName, W("get")); wcscat_s(pNewName, cchpNewName, m_MethodProps[ixGet].pName); m_MethodProps[ixGet].pName = pNewName; - pNewName = reinterpret_cast(m_sNames.Alloc((int)((4+minipal_u16_strlen((const CHAR16_T*)m_MethodProps[ixSet].pName))*sizeof(WCHAR)+2))); + pNewName = reinterpret_cast(m_sNames.Alloc((int)((4+u16_strlen(m_MethodProps[ixSet].pName))*sizeof(WCHAR)+2))); wcscpy_s(pNewName, cchpNewName, W("set")); wcscat_s(pNewName, cchpNewName, m_MethodProps[ixSet].pName); m_MethodProps[ixSet].pName = pNewName; @@ -775,7 +775,7 @@ void ComMTMemberInfoMap::GetMethodPropsForMeth( } } - ULONG len = ((int)minipal_u16_strlen((const CHAR16_T*)pName)) + 1; + ULONG len = ((int)u16_strlen(pName)) + 1; rProps[ix].pName = reinterpret_cast(sNames.Alloc(len * sizeof(WCHAR))); if (rProps[ix].pName == NULL) { @@ -896,7 +896,7 @@ void ComMTMemberInfoMap::EliminateDuplicateNames( if (bDup) { // Duplicate. - DWORD cchName = (DWORD) minipal_u16_strlen((const CHAR16_T*)rProps[iCur].pName); + DWORD cchName = (DWORD) u16_strlen(rProps[iCur].pName); if (cchName > MAX_CLASSNAME_LENGTH-cchDuplicateDecoration) cchName = MAX_CLASSNAME_LENGTH-cchDuplicateDecoration; @@ -925,7 +925,7 @@ void ComMTMemberInfoMap::EliminateDuplicateNames( } // Remember the new name. - ULONG len = ((int)minipal_u16_strlen((const CHAR16_T*)rcName)) + 1; + ULONG len = ((int)u16_strlen(rcName)) + 1; rProps[iCur].pName = reinterpret_cast(sNames.Alloc(len * sizeof(WCHAR))); if (rProps[iCur].pName == NULL) { @@ -989,7 +989,7 @@ void ComMTMemberInfoMap::EliminateDuplicateNames( iCur = piTable[i]; // Copy name into local buffer - DWORD cchName = (DWORD) minipal_u16_strlen((const CHAR16_T*)rProps[iCur].pName); + DWORD cchName = (DWORD) u16_strlen(rProps[iCur].pName); if (cchName > MAX_CLASSNAME_LENGTH-cchDuplicateDecoration) cchName = MAX_CLASSNAME_LENGTH-cchDuplicateDecoration; @@ -1007,7 +1007,7 @@ void ComMTMemberInfoMap::EliminateDuplicateNames( } while (htNames.Find(rcName) != NULL); // Now rcName has an acceptable (unique) name. Remember the new name. - ULONG len = ((int)minipal_u16_strlen((const CHAR16_T*)rcName)) + 1; + ULONG len = ((int)u16_strlen(rcName)) + 1; rProps[iCur].pName = reinterpret_cast(sNames.Alloc(len * sizeof(WCHAR))); if (rProps[iCur].pName == NULL) { diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index e325b4399ffa3a..990eb02b00dc86 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -313,7 +313,7 @@ HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId, if (g_EntryAssemblyPath == NULL) { // Store the entry assembly path for diagnostic purposes (for example, dumps) - size_t len = minipal_u16_strlen((const CHAR16_T*)pwzAssemblyPath) + 1; + size_t len = u16_strlen(pwzAssemblyPath) + 1; NewArrayHolder path { new WCHAR[len] }; wcscpy_s(path, len, pwzAssemblyPath); g_EntryAssemblyPath = path.Extract(); diff --git a/src/coreclr/vm/debugdebugger.cpp b/src/coreclr/vm/debugdebugger.cpp index 34793d4212ad5b..a77dd524d6eaf5 100644 --- a/src/coreclr/vm/debugdebugger.cpp +++ b/src/coreclr/vm/debugdebugger.cpp @@ -156,7 +156,7 @@ extern "C" void QCALLTYPE DebugDebugger_Log(INT32 Level, PCWSTR pwzModule, PCWST if (pwzModule != NULL) { // truncate if necessary - COUNT_T iLen = (COUNT_T) minipal_u16_strlen((const CHAR16_T*)pwzModule); + COUNT_T iLen = (COUNT_T) u16_strlen(pwzModule); if (iLen > MAX_LOG_SWITCH_NAME_LEN) { iLen = MAX_LOG_SWITCH_NAME_LEN; @@ -167,7 +167,7 @@ extern "C" void QCALLTYPE DebugDebugger_Log(INT32 Level, PCWSTR pwzModule, PCWST SString message; if (pwzMessage != NULL) { - message.Set(pwzMessage, (COUNT_T) minipal_u16_strlen((const CHAR16_T*)pwzMessage)); + message.Set(pwzMessage, (COUNT_T) u16_strlen(pwzMessage)); } g_pDebugInterface->SendLogMessage (Level, &switchName, &message); diff --git a/src/coreclr/vm/dispatchinfo.cpp b/src/coreclr/vm/dispatchinfo.cpp index 4dd98b29f5be2c..e1538a8c6c4548 100644 --- a/src/coreclr/vm/dispatchinfo.cpp +++ b/src/coreclr/vm/dispatchinfo.cpp @@ -525,7 +525,7 @@ LPWSTR DispatchMemberInfo::GetMemberName(OBJECTREF MemberInfoObj, ComMTMemberInf // If we managed to get the member's properties then extract the name. if (pMemberProps) { - int MemberNameLen = (INT)minipal_u16_strlen((const CHAR16_T*)pMemberProps->pName); + int MemberNameLen = (INT)u16_strlen(pMemberProps->pName); strMemberName = new WCHAR[MemberNameLen + 1]; memcpy(strMemberName, pMemberProps->pName, (MemberNameLen + 1) * sizeof(WCHAR)); diff --git a/src/coreclr/vm/dwbucketmanager.hpp b/src/coreclr/vm/dwbucketmanager.hpp index 03f627498c18f7..dec761a97e5ed3 100644 --- a/src/coreclr/vm/dwbucketmanager.hpp +++ b/src/coreclr/vm/dwbucketmanager.hpp @@ -1027,7 +1027,7 @@ int BaseBucketParamsManager::CopyStringToBucket(_Out_writes_(targetMaxLength) LP 0 }; - int srcLen = static_cast(minipal_u16_strlen((const CHAR16_T*)pSource)); + int srcLen = static_cast(u16_strlen(pSource)); // If the source contains unicode characters, they'll be encoded at 4 chars per char. int targLen = ContainsUnicodeChars(pSource) ? targetMaxLength / 4 : targetMaxLength; @@ -1038,7 +1038,7 @@ int BaseBucketParamsManager::CopyStringToBucket(_Out_writes_(targetMaxLength) LP for (int i = 0; truncations[i]; ++i) { // how long is this suffix? - int slen = static_cast(minipal_u16_strlen((const CHAR16_T*)truncations[i])); + int slen = static_cast(u16_strlen(truncations[i])); // Could the string have this suffix? if (slen < srcLen) @@ -1069,7 +1069,7 @@ int BaseBucketParamsManager::CopyStringToBucket(_Out_writes_(targetMaxLength) LP // String didn't fit, so hash it. SHA1Hash hash; - hash.AddData(reinterpret_cast(const_cast(pSource)), (static_cast(minipal_u16_strlen((const CHAR16_T*)pSource))) * sizeof(WCHAR)); + hash.AddData(reinterpret_cast(const_cast(pSource)), (static_cast(u16_strlen(pSource))) * sizeof(WCHAR)); // Encode in base32. The hash is a fixed size; we'll accept up to maxLen characters of the encoding. BytesToBase32 b32(hash.GetHash(), SHA1_HASH_SIZE); diff --git a/src/coreclr/vm/eehash.cpp b/src/coreclr/vm/eehash.cpp index 7f083c44b9d800..4bd014e5dc3b0f 100644 --- a/src/coreclr/vm/eehash.cpp +++ b/src/coreclr/vm/eehash.cpp @@ -277,7 +277,7 @@ EEHashEntry_t *EEClassFactoryInfoHashTableHelper::AllocateEntry(ClassFactoryInfo _ASSERTE(bDeepCopy && "Non deep copy is not supported by the EEComCompInfoHashTableHelper"); if (pKey->m_strServerName) - cbStringLen = (S_SIZE_T(minipal_u16_strlen((const CHAR16_T*)pKey->m_strServerName)) + S_SIZE_T(1)) * S_SIZE_T(sizeof(WCHAR)); + cbStringLen = (S_SIZE_T(u16_strlen(pKey->m_strServerName)) + S_SIZE_T(1)) * S_SIZE_T(sizeof(WCHAR)); S_SIZE_T cbEntry = S_SIZE_T(SIZEOF_EEHASH_ENTRY + sizeof(ClassFactoryInfo)) + cbStringLen; diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index f19b33bd34006c..b45e9770a1c4e9 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -18,6 +18,7 @@ #include "clrversion.h" #include "hostinformation.h" #include +#include #undef EP_INFINITE_WAIT #define EP_INFINITE_WAIT INFINITE diff --git a/src/coreclr/vm/eventtrace.cpp b/src/coreclr/vm/eventtrace.cpp index 553c6fa42e150d..535a44f96dffb7 100644 --- a/src/coreclr/vm/eventtrace.cpp +++ b/src/coreclr/vm/eventtrace.cpp @@ -4355,7 +4355,7 @@ VOID ETW::LoaderLog::SendModuleEvent(Module *pModule, DWORD dwEventOptions, BOOL } // if we do not have a module path yet, we put the module name - if(bIsDynamicAssembly || ModuleILPath==NULL || minipal_u16_strlen((const CHAR16_T*)ModuleILPath) <= 2) + if(bIsDynamicAssembly || ModuleILPath==NULL || u16_strlen(ModuleILPath) <= 2) { moduleName.SetUTF8(pModule->GetSimpleName()); ModuleILPath = (PWCHAR)moduleName.GetUnicode(); diff --git a/src/coreclr/vm/gdbjit.cpp b/src/coreclr/vm/gdbjit.cpp index 1607113ca6129a..672cbdb0300939 100644 --- a/src/coreclr/vm/gdbjit.cpp +++ b/src/coreclr/vm/gdbjit.cpp @@ -1846,8 +1846,8 @@ static inline bool isListedModule(const WCHAR *wszModuleFile) } if (isUserDebug == FALSE) { - u16_strncpy_s(wszModuleName, g_cBytesNeeded, tmp, minipal_u16_strlen((const CHAR16_T*)tmp)); - wszModuleName[minipal_u16_strlen((const CHAR16_T*)tmp)] = W('\0'); + u16_strncpy_s(wszModuleName, g_cBytesNeeded, tmp, u16_strlen(tmp)); + wszModuleName[u16_strlen(tmp)] = W('\0'); if (u16_strcmp(wszModuleName, wszModuleFile) == 0) { isUserDebug = TRUE; @@ -2570,7 +2570,7 @@ void NotifyGdb::OnMethodPrepared(MethodDesc* methodDescPtr) if (pNIExt) { - u16_strcpy_s(pNIExt, minipal_u16_strlen((const CHAR16_T*)pNIExt) + 1, W(".dll")); + u16_strcpy_s(pNIExt, u16_strlen(pNIExt) + 1, W(".dll")); } if (isListedModule(wszModuleFile)) diff --git a/src/coreclr/vm/genanalysis.cpp b/src/coreclr/vm/genanalysis.cpp index dc116616651f91..048e6470ebdf24 100644 --- a/src/coreclr/vm/genanalysis.cpp +++ b/src/coreclr/vm/genanalysis.cpp @@ -28,7 +28,7 @@ bool gcGenAnalysisDump = false; { // Get the managed command line. LPCWSTR pCmdLine = GetCommandLineForDiagnostics(); - match = u16_strncmp(pCmdLine, gcGenAnalysisCmd, minipal_u16_strlen((CHAR16_T*)(LPWSTR)gcGenAnalysisCmd)) == 0; + match = u16_strncmp(pCmdLine, gcGenAnalysisCmd, u16_strlen(gcGenAnalysisCmd)) == 0; } if (match && !CLRConfig::IsConfigOptionSpecified(W("GCGenAnalysisGen"))) { diff --git a/src/coreclr/vm/ilmarshalers.cpp b/src/coreclr/vm/ilmarshalers.cpp index 193cf2bf72e9f2..1726c63ece42a9 100644 --- a/src/coreclr/vm/ilmarshalers.cpp +++ b/src/coreclr/vm/ilmarshalers.cpp @@ -816,7 +816,7 @@ void ILWSTRBufferMarshaler::EmitConvertSpaceNativeToCLR(ILCodeStream* pslILEmit) if (IsIn(m_dwMarshalFlags) || IsCLRToNative(m_dwMarshalFlags)) { EmitLoadNativeValue(pslILEmit); - // static int System.String.wcslen(char *ptr) + // static int System.String.u16_strlen(char *ptr) pslILEmit->EmitCALL(METHOD__STRING__WCSLEN, 1, 1); } else @@ -845,7 +845,7 @@ void ILWSTRBufferMarshaler::EmitConvertContentsNativeToCLR(ILCodeStream* pslILEm EmitLoadNativeValue(pslILEmit); pslILEmit->EmitDUP(); - // static int System.String.wcslen(char *ptr) + // static int System.String.u16_strlen(char *ptr) pslILEmit->EmitCALL(METHOD__STRING__WCSLEN, 1, 1); // void System.Text.StringBuilder.ReplaceBuffer(char* newBuffer, int newLength); diff --git a/src/coreclr/vm/interoputil.cpp b/src/coreclr/vm/interoputil.cpp index d53fc2c72df02e..1dc64e79b9e7e5 100644 --- a/src/coreclr/vm/interoputil.cpp +++ b/src/coreclr/vm/interoputil.cpp @@ -539,7 +539,7 @@ SIZE_T GetStringizedItfDef(TypeHandle InterfaceType, CQuickArray &rDef) DefineFullyQualifiedNameForClassW(); szName = GetFullyQualifiedNameForClassNestedAwareW(pIntfMT); - cchName = (ULONG)minipal_u16_strlen((const CHAR16_T*)szName); + cchName = (ULONG)u16_strlen(szName); // Start with the interface name. cbCur = cchName * sizeof(WCHAR); @@ -2274,7 +2274,7 @@ ULONG GetStringizedClassItfDef(TypeHandle InterfaceType, CQuickArray &rDef // Get the name of the class. DefineFullyQualifiedNameForClassW(); szName = GetFullyQualifiedNameForClassNestedAwareW(pIntfMT); - cchName = (ULONG)minipal_u16_strlen((const CHAR16_T*)szName); + cchName = (ULONG)u16_strlen(szName); // Start with the interface name. cbCur = cchName * sizeof(WCHAR); @@ -3558,7 +3558,7 @@ static void GetComClassHelper( NewArrayHolder wszRefServer = NULL; if (pClassFactInfo->m_strServerName) { - size_t len = minipal_u16_strlen((const CHAR16_T*)pClassFactInfo->m_strServerName)+1; + size_t len = u16_strlen(pClassFactInfo->m_strServerName)+1; wszRefServer = new WCHAR[len]; wcscpy_s(wszRefServer, len, pClassFactInfo->m_strServerName); } diff --git a/src/coreclr/vm/methodtable.cpp b/src/coreclr/vm/methodtable.cpp index 4b7ef5f8ff1ffb..cff22f39c105a9 100644 --- a/src/coreclr/vm/methodtable.cpp +++ b/src/coreclr/vm/methodtable.cpp @@ -6080,7 +6080,7 @@ void MethodTable::GetGuid(GUID *pGuid, BOOL bGenerateIfNotFound, BOOL bClassic / szName = GetFullyQualifiedNameForClassNestedAwareW(this); if (szName == NULL) return; - cchName = minipal_u16_strlen((const CHAR16_T*)szName); + cchName = u16_strlen(szName); // Enlarge buffer for class name. cbCur = cchName * sizeof(WCHAR); diff --git a/src/coreclr/vm/multicorejit.cpp b/src/coreclr/vm/multicorejit.cpp index 01cfb7663dfcf0..ab6d2e65fc74ea 100644 --- a/src/coreclr/vm/multicorejit.cpp +++ b/src/coreclr/vm/multicorejit.cpp @@ -946,7 +946,7 @@ HRESULT MulticoreJitRecorder::StartProfile(const WCHAR * pRoot, const WCHAR * pF MulticoreJitTrace(("StartProfile('%s', '%s', %d)", pRootUtf8, pFileUtf8, suffix)); #endif // MULTICOREJIT_LOGGING - size_t lenFile = minipal_u16_strlen((const CHAR16_T*)pFile); + size_t lenFile = u16_strlen(pFile); // Options (only AutoStartProfile using environment variable, for testing) // ([d|D]main-thread-delay) diff --git a/src/coreclr/vm/object.cpp b/src/coreclr/vm/object.cpp index 367c92b3e38576..050f16e09ad04e 100644 --- a/src/coreclr/vm/object.cpp +++ b/src/coreclr/vm/object.cpp @@ -725,7 +725,7 @@ STRINGREF StringObject::NewString(const WCHAR *pwsz) else { - DWORD nch = (DWORD)minipal_u16_strlen((const CHAR16_T*)pwsz); + DWORD nch = (DWORD)u16_strlen(pwsz); if (nch==0) { return GetEmptyString(); } diff --git a/src/coreclr/vm/peimage.inl b/src/coreclr/vm/peimage.inl index ad99719c76a074..f04078fe6455a6 100644 --- a/src/coreclr/vm/peimage.inl +++ b/src/coreclr/vm/peimage.inl @@ -309,7 +309,7 @@ inline PTR_PEImage PEImage::FindByPath(LPCWSTR pPath, BOOL isInBundle) int CaseHashHelper(const WCHAR *buffer, COUNT_T count); PEImageLocator locator(pPath, isInBundle); - DWORD dwHash = CaseHashHelper(pPath, (COUNT_T) minipal_u16_strlen((const CHAR16_T*)pPath)); + DWORD dwHash = CaseHashHelper(pPath, (COUNT_T) u16_strlen(pPath)); return (PEImage *) s_Images->LookupValue(dwHash, &locator); } diff --git a/src/coreclr/vm/profilinghelper.cpp b/src/coreclr/vm/profilinghelper.cpp index 02090c322ea2ca..49d95f3b9dedd4 100644 --- a/src/coreclr/vm/profilinghelper.cpp +++ b/src/coreclr/vm/profilinghelper.cpp @@ -674,7 +674,7 @@ HRESULT ProfilingAPIUtility::AttemptLoadProfilerForStartup() return S_FALSE; } - if ((wszProfilerDLL != NULL) && (minipal_u16_strlen((const CHAR16_T*)(LPWSTR)wszProfilerDLL) >= MAX_LONGPATH)) + if ((wszProfilerDLL != NULL) && (u16_strlen(wszProfilerDLL) >= MAX_LONGPATH)) { LOG((LF_CORPROF, LL_INFO10, "**PROF: Profiling flag set, but CORECLR_PROFILER_PATH was not set properly.\n")); diff --git a/src/coreclr/vm/proftoeeinterfaceimpl.cpp b/src/coreclr/vm/proftoeeinterfaceimpl.cpp index db9fb494eebf6f..1d3530c615d1e5 100644 --- a/src/coreclr/vm/proftoeeinterfaceimpl.cpp +++ b/src/coreclr/vm/proftoeeinterfaceimpl.cpp @@ -4046,7 +4046,7 @@ HRESULT ProfToEEInterfaceImpl::GetModuleInfo2(ModuleID moduleId, wszFileName = strScopeName.GetUnicode(); } - ULONG trueLen = (ULONG)(minipal_u16_strlen((const CHAR16_T*)wszFileName) + 1); + ULONG trueLen = (ULONG)(u16_strlen(wszFileName) + 1); // Return name of module as required. if (wszName && cchName > 0) @@ -5492,7 +5492,7 @@ HRESULT ProfToEEInterfaceImpl::GetAppDomainInfo(AppDomainID appDomainId, if (szFriendlyName != NULL) { // Get the module file name - ULONG trueLen = (ULONG)(minipal_u16_strlen((const CHAR16_T*)szFriendlyName) + 1); + ULONG trueLen = (ULONG)(u16_strlen(szFriendlyName) + 1); // Return name of module as required. if (szName && cchName > 0) @@ -6354,7 +6354,7 @@ HRESULT ProfToEEInterfaceImpl::GetDynamicFunctionInfo(FunctionID functionId, ss.Normalize(); LPCWSTR methodName = ss.GetUnicode(); - ULONG trueLen = (ULONG)(minipal_u16_strlen((const CHAR16_T*)methodName) + 1); + ULONG trueLen = (ULONG)(u16_strlen(methodName) + 1); // Return name of method as required. if (wszName && cchName > 0) @@ -9682,7 +9682,7 @@ HRESULT ProfToEEInterfaceImpl::GetRuntimeInformation(USHORT * pClrInstanceId, PCWSTR pczVersionString = CLR_PRODUCT_VERSION_L; // Get the module file name - ULONG trueLen = (ULONG)(minipal_u16_strlen((const CHAR16_T*)pczVersionString) + 1); + ULONG trueLen = (ULONG)(u16_strlen(pczVersionString) + 1); // Return name of module as required. if (szVersionString && cchVersionString > 0) From 2ef0a5ac94c71888211d649798daa787c14ed1de Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 29 Oct 2024 14:30:09 -0700 Subject: [PATCH 25/28] Go back to a CoTaskMemAlloc PAL --- src/coreclr/debug/di/module.cpp | 2 +- src/coreclr/dlls/mscorpe/pewriter.cpp | 4 ++-- src/coreclr/inc/holder.h | 2 +- src/coreclr/md/enc/stgio.cpp | 2 +- src/coreclr/vm/gdbjit.cpp | 14 +++++++------- src/coreclr/vm/ilmarshalers.cpp | 2 +- src/coreclr/vm/olevariant.cpp | 8 ++++---- src/native/minipal/memory.c | 24 ------------------------ src/native/minipal/memory.h | 14 ++++++++++---- 9 files changed, 27 insertions(+), 45 deletions(-) diff --git a/src/coreclr/debug/di/module.cpp b/src/coreclr/debug/di/module.cpp index d3ab476877b6ee..02986839e454bb 100644 --- a/src/coreclr/debug/di/module.cpp +++ b/src/coreclr/debug/di/module.cpp @@ -1101,7 +1101,7 @@ void CordbModule::CopyRemoteMetaData( // Allocate space for the local copy of the metadata // No need to zero out the memory since we'll fill it all here. - LPVOID pRawBuffer = minipal_co_task_mem_alloc(buffer.cbSize); + LPVOID pRawBuffer = CoTaskMemAlloc(buffer.cbSize); if (pRawBuffer == NULL) { ThrowOutOfMemory(); diff --git a/src/coreclr/dlls/mscorpe/pewriter.cpp b/src/coreclr/dlls/mscorpe/pewriter.cpp index 4d7b0376ab52f3..efbf147e55171a 100644 --- a/src/coreclr/dlls/mscorpe/pewriter.cpp +++ b/src/coreclr/dlls/mscorpe/pewriter.cpp @@ -1589,7 +1589,7 @@ HRESULT PEWriter::write(void ** ppImage) size_t lSize = filePos; // allocate the block we are handing back to the caller - void * pImage = (void *) minipal_co_task_mem_alloc(lSize); + void * pImage = (void *) CoTaskMemAlloc(lSize); if (NULL == pImage) { return E_OUTOFMEMORY; @@ -1622,7 +1622,7 @@ HRESULT PEWriter::write(void ** ppImage) // make sure we wrote the exact numbmer of bytes expected _ASSERTE(lSize == (size_t) (pCur - (char *)pImage)); - // give pointer to memory image back to caller (who must free with minipal_co_task_mem_free()) + // give pointer to memory image back to caller (who must free with CoTaskMemFree()) *ppImage = pImage; // all done diff --git a/src/coreclr/inc/holder.h b/src/coreclr/inc/holder.h index 7afd527bb1281c..9fcd62e08188a3 100644 --- a/src/coreclr/inc/holder.h +++ b/src/coreclr/inc/holder.h @@ -970,7 +970,7 @@ template FORCEINLINE void DeleteCoTaskMem(TYPE *value) { if (value) - minipal_co_task_mem_free(value); + CoTaskMemFree(value); } template diff --git a/src/coreclr/md/enc/stgio.cpp b/src/coreclr/md/enc/stgio.cpp index 0297478cfb69f8..aeba5e59f47359 100644 --- a/src/coreclr/md/enc/stgio.cpp +++ b/src/coreclr/md/enc/stgio.cpp @@ -339,7 +339,7 @@ void StgIO::Close() case STGIO_SHAREDMEM: if (m_pBaseData != NULL) { - minipal_co_task_mem_free(m_pBaseData); + CoTaskMemFree(m_pBaseData); m_pBaseData = NULL; break; } diff --git a/src/coreclr/vm/gdbjit.cpp b/src/coreclr/vm/gdbjit.cpp index 672cbdb0300939..2a376726e52854 100644 --- a/src/coreclr/vm/gdbjit.cpp +++ b/src/coreclr/vm/gdbjit.cpp @@ -452,7 +452,7 @@ HRESULT FunctionMember::GetLocalsDebugInfo(NotifyGdb::PTK_TypeInfoMap pTypeMap, MethodDebugInfo::MethodDebugInfo(int numPoints, int numLocals) { - points = (SequencePointInfo*) minipal_co_task_mem_alloc(sizeof(SequencePointInfo) * numPoints); + points = (SequencePointInfo*) CoTaskMemAlloc(sizeof(SequencePointInfo) * numPoints); if (points == nullptr) { COMPlusThrowOM(); @@ -467,10 +467,10 @@ MethodDebugInfo::MethodDebugInfo(int numPoints, int numLocals) return; } - locals = (LocalVarInfo*) minipal_co_task_mem_alloc(sizeof(LocalVarInfo) * numLocals); + locals = (LocalVarInfo*) CoTaskMemAlloc(sizeof(LocalVarInfo) * numLocals); if (locals == nullptr) { - minipal_co_task_mem_free(points); + CoTaskMemFree(points); COMPlusThrowOM(); } memset(locals, 0, sizeof(LocalVarInfo) * numLocals); @@ -482,13 +482,13 @@ MethodDebugInfo::~MethodDebugInfo() if (locals) { for (int i = 0; i < localsSize; i++) - minipal_co_task_mem_free(locals[i].name); - minipal_co_task_mem_free(locals); + CoTaskMemFree(locals[i].name); + CoTaskMemFree(locals); } for (int i = 0; i < size; i++) - minipal_co_task_mem_free(points[i].fileName); - minipal_co_task_mem_free(points); + CoTaskMemFree(points[i].fileName); + CoTaskMemFree(points); } /* Get mapping of IL offsets to source line numbers */ diff --git a/src/coreclr/vm/ilmarshalers.cpp b/src/coreclr/vm/ilmarshalers.cpp index 1726c63ece42a9..aa9b3d6531553a 100644 --- a/src/coreclr/vm/ilmarshalers.cpp +++ b/src/coreclr/vm/ilmarshalers.cpp @@ -4302,7 +4302,7 @@ extern "C" void QCALLTYPE MngdNativeArrayMarshaler_ConvertSpaceToNative(MngdNati if ( (!ClrSafeInt::multiply(cElements, cbElement, cbArray)) || cbArray > MAX_SIZE_FOR_INTEROP) COMPlusThrow(kArgumentException, IDS_EE_STRUCTARRAYTOOLARGE); - *pNativeHome = minipal_co_task_mem_alloc(cbArray); + *pNativeHome = CoTaskMemAlloc(cbArray); if (*pNativeHome == NULL) ThrowOutOfMemory(); diff --git a/src/coreclr/vm/olevariant.cpp b/src/coreclr/vm/olevariant.cpp index 82072d170e5fb2..b46c5027d097b4 100644 --- a/src/coreclr/vm/olevariant.cpp +++ b/src/coreclr/vm/olevariant.cpp @@ -1657,7 +1657,7 @@ void OleVariant::MarshalLPWSTRRArrayComToOle(BASEARRAYREF *pComArray, void *oleA // Allocate the string using CoTaskMemAlloc. { GCX_PREEMP(); - lpwstr = (LPWSTR)minipal_co_task_mem_alloc(allocLength); + lpwstr = (LPWSTR)CoTaskMemAlloc(allocLength); } if (lpwstr == NULL) ThrowOutOfMemory(); @@ -1694,7 +1694,7 @@ void OleVariant::ClearLPWSTRArray(void *oleArray, SIZE_T cElements, MethodTable LPWSTR lpwstr = *pOle++; if (lpwstr != NULL) - minipal_co_task_mem_free(lpwstr); + CoTaskMemFree(lpwstr); } } @@ -1801,7 +1801,7 @@ void OleVariant::MarshalLPSTRRArrayComToOle(BASEARRAYREF *pComArray, void *oleAr // Allocate the string using CoTaskMemAlloc. { GCX_PREEMP(); - lpstr = (LPSTR)minipal_co_task_mem_alloc(allocLength); + lpstr = (LPSTR)CoTaskMemAlloc(allocLength); } if (lpstr == NULL) ThrowOutOfMemory(); @@ -1840,7 +1840,7 @@ void OleVariant::ClearLPSTRArray(void *oleArray, SIZE_T cElements, MethodTable * LPSTR lpstr = *pOle++; if (lpstr != NULL) - minipal_co_task_mem_free(lpstr); + CoTaskMemFree(lpstr); } } diff --git a/src/native/minipal/memory.c b/src/native/minipal/memory.c index d72c7ed0f6ddcd..b751b539539b11 100644 --- a/src/native/minipal/memory.c +++ b/src/native/minipal/memory.c @@ -2,27 +2,3 @@ // The .NET Foundation licenses this file to you under the MIT license. #include "memory.h" - -#ifdef HOST_WINDOWS -#include - -void* minipal_co_task_mem_alloc(size_t cb) -{ - return CoTaskMemAlloc(cb); -} - -void minipal_co_task_mem_free(void* pv) -{ - CoTaskMemFree(pv); -} -#else -void* minipal_co_task_mem_alloc(size_t cb) -{ - return malloc(cb); -} - -void minipal_co_task_mem_free(void* pv) -{ - free(pv); -} -#endif diff --git a/src/native/minipal/memory.h b/src/native/minipal/memory.h index 258a3938a8eb67..ba85b0e26b028e 100644 --- a/src/native/minipal/memory.h +++ b/src/native/minipal/memory.h @@ -11,11 +11,17 @@ { #endif // __cplusplus -// Allocate memory on the platform equivalent of the CoTaskMem heap. -void* minipal_co_task_mem_alloc(size_t cb); +#ifndef HOST_WINDOWS +inline void* CoTaskMemAlloc(size_t cb) +{ + return malloc(cb); +} -// Free memory allocated on the platform equivalent of the CoTaskMem heap. -void minipal_co_task_mem_free(void* pv); +inline void CoTaskMemFree(void* pv) +{ + free(pv); +} +#endif #ifdef __cplusplus } From 5f4df82897fa4e326cebf3ae039082f4c7956649 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 29 Oct 2024 15:50:48 -0700 Subject: [PATCH 26/28] Use a prefixed name everywhere instead of shiming the Win32 API name or making our own name. --- src/coreclr/debug/di/module.cpp | 2 +- src/coreclr/dlls/mscorpe/pewriter.cpp | 4 ++-- src/coreclr/inc/holder.h | 2 +- src/coreclr/md/enc/stgio.cpp | 2 +- src/coreclr/vm/gdbjit.cpp | 14 +++++++------- src/coreclr/vm/ilmarshalers.cpp | 2 +- src/coreclr/vm/olevariant.cpp | 8 ++++---- src/native/minipal/memory.c | 24 ++++++++++++++++++++++++ src/native/minipal/memory.h | 14 ++++---------- 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/coreclr/debug/di/module.cpp b/src/coreclr/debug/di/module.cpp index 02986839e454bb..9ec196a1d22d4b 100644 --- a/src/coreclr/debug/di/module.cpp +++ b/src/coreclr/debug/di/module.cpp @@ -1101,7 +1101,7 @@ void CordbModule::CopyRemoteMetaData( // Allocate space for the local copy of the metadata // No need to zero out the memory since we'll fill it all here. - LPVOID pRawBuffer = CoTaskMemAlloc(buffer.cbSize); + LPVOID pRawBuffer = minicom_CoTaskMemAlloc(buffer.cbSize); if (pRawBuffer == NULL) { ThrowOutOfMemory(); diff --git a/src/coreclr/dlls/mscorpe/pewriter.cpp b/src/coreclr/dlls/mscorpe/pewriter.cpp index efbf147e55171a..fa307d80a657eb 100644 --- a/src/coreclr/dlls/mscorpe/pewriter.cpp +++ b/src/coreclr/dlls/mscorpe/pewriter.cpp @@ -1589,7 +1589,7 @@ HRESULT PEWriter::write(void ** ppImage) size_t lSize = filePos; // allocate the block we are handing back to the caller - void * pImage = (void *) CoTaskMemAlloc(lSize); + void * pImage = (void *) minicom_CoTaskMemAlloc(lSize); if (NULL == pImage) { return E_OUTOFMEMORY; @@ -1622,7 +1622,7 @@ HRESULT PEWriter::write(void ** ppImage) // make sure we wrote the exact numbmer of bytes expected _ASSERTE(lSize == (size_t) (pCur - (char *)pImage)); - // give pointer to memory image back to caller (who must free with CoTaskMemFree()) + // give pointer to memory image back to caller (who must free with minicom_CoTaskMemFree()) *ppImage = pImage; // all done diff --git a/src/coreclr/inc/holder.h b/src/coreclr/inc/holder.h index 9fcd62e08188a3..0f0f22bff637ed 100644 --- a/src/coreclr/inc/holder.h +++ b/src/coreclr/inc/holder.h @@ -970,7 +970,7 @@ template FORCEINLINE void DeleteCoTaskMem(TYPE *value) { if (value) - CoTaskMemFree(value); + minicom_CoTaskMemFree(value); } template diff --git a/src/coreclr/md/enc/stgio.cpp b/src/coreclr/md/enc/stgio.cpp index aeba5e59f47359..d75018e21e6398 100644 --- a/src/coreclr/md/enc/stgio.cpp +++ b/src/coreclr/md/enc/stgio.cpp @@ -339,7 +339,7 @@ void StgIO::Close() case STGIO_SHAREDMEM: if (m_pBaseData != NULL) { - CoTaskMemFree(m_pBaseData); + minicom_CoTaskMemFree(m_pBaseData); m_pBaseData = NULL; break; } diff --git a/src/coreclr/vm/gdbjit.cpp b/src/coreclr/vm/gdbjit.cpp index 2a376726e52854..a97692485d5c7c 100644 --- a/src/coreclr/vm/gdbjit.cpp +++ b/src/coreclr/vm/gdbjit.cpp @@ -452,7 +452,7 @@ HRESULT FunctionMember::GetLocalsDebugInfo(NotifyGdb::PTK_TypeInfoMap pTypeMap, MethodDebugInfo::MethodDebugInfo(int numPoints, int numLocals) { - points = (SequencePointInfo*) CoTaskMemAlloc(sizeof(SequencePointInfo) * numPoints); + points = (SequencePointInfo*) minicom_CoTaskMemAlloc(sizeof(SequencePointInfo) * numPoints); if (points == nullptr) { COMPlusThrowOM(); @@ -467,10 +467,10 @@ MethodDebugInfo::MethodDebugInfo(int numPoints, int numLocals) return; } - locals = (LocalVarInfo*) CoTaskMemAlloc(sizeof(LocalVarInfo) * numLocals); + locals = (LocalVarInfo*) minicom_CoTaskMemAlloc(sizeof(LocalVarInfo) * numLocals); if (locals == nullptr) { - CoTaskMemFree(points); + minicom_CoTaskMemFree(points); COMPlusThrowOM(); } memset(locals, 0, sizeof(LocalVarInfo) * numLocals); @@ -482,13 +482,13 @@ MethodDebugInfo::~MethodDebugInfo() if (locals) { for (int i = 0; i < localsSize; i++) - CoTaskMemFree(locals[i].name); - CoTaskMemFree(locals); + minicom_CoTaskMemFree(locals[i].name); + minicom_CoTaskMemFree(locals); } for (int i = 0; i < size; i++) - CoTaskMemFree(points[i].fileName); - CoTaskMemFree(points); + minicom_CoTaskMemFree(points[i].fileName); + minicom_CoTaskMemFree(points); } /* Get mapping of IL offsets to source line numbers */ diff --git a/src/coreclr/vm/ilmarshalers.cpp b/src/coreclr/vm/ilmarshalers.cpp index aa9b3d6531553a..60c11c958692ac 100644 --- a/src/coreclr/vm/ilmarshalers.cpp +++ b/src/coreclr/vm/ilmarshalers.cpp @@ -4302,7 +4302,7 @@ extern "C" void QCALLTYPE MngdNativeArrayMarshaler_ConvertSpaceToNative(MngdNati if ( (!ClrSafeInt::multiply(cElements, cbElement, cbArray)) || cbArray > MAX_SIZE_FOR_INTEROP) COMPlusThrow(kArgumentException, IDS_EE_STRUCTARRAYTOOLARGE); - *pNativeHome = CoTaskMemAlloc(cbArray); + *pNativeHome = minicom_CoTaskMemAlloc(cbArray); if (*pNativeHome == NULL) ThrowOutOfMemory(); diff --git a/src/coreclr/vm/olevariant.cpp b/src/coreclr/vm/olevariant.cpp index b46c5027d097b4..a736440cd9fe90 100644 --- a/src/coreclr/vm/olevariant.cpp +++ b/src/coreclr/vm/olevariant.cpp @@ -1657,7 +1657,7 @@ void OleVariant::MarshalLPWSTRRArrayComToOle(BASEARRAYREF *pComArray, void *oleA // Allocate the string using CoTaskMemAlloc. { GCX_PREEMP(); - lpwstr = (LPWSTR)CoTaskMemAlloc(allocLength); + lpwstr = (LPWSTR)minicom_CoTaskMemAlloc(allocLength); } if (lpwstr == NULL) ThrowOutOfMemory(); @@ -1694,7 +1694,7 @@ void OleVariant::ClearLPWSTRArray(void *oleArray, SIZE_T cElements, MethodTable LPWSTR lpwstr = *pOle++; if (lpwstr != NULL) - CoTaskMemFree(lpwstr); + minicom_CoTaskMemFree(lpwstr); } } @@ -1801,7 +1801,7 @@ void OleVariant::MarshalLPSTRRArrayComToOle(BASEARRAYREF *pComArray, void *oleAr // Allocate the string using CoTaskMemAlloc. { GCX_PREEMP(); - lpstr = (LPSTR)CoTaskMemAlloc(allocLength); + lpstr = (LPSTR)minicom_CoTaskMemAlloc(allocLength); } if (lpstr == NULL) ThrowOutOfMemory(); @@ -1840,7 +1840,7 @@ void OleVariant::ClearLPSTRArray(void *oleArray, SIZE_T cElements, MethodTable * LPSTR lpstr = *pOle++; if (lpstr != NULL) - CoTaskMemFree(lpstr); + minicom_CoTaskMemFree(lpstr); } } diff --git a/src/native/minipal/memory.c b/src/native/minipal/memory.c index b751b539539b11..dac3da74aa06be 100644 --- a/src/native/minipal/memory.c +++ b/src/native/minipal/memory.c @@ -2,3 +2,27 @@ // The .NET Foundation licenses this file to you under the MIT license. #include "memory.h" + +#ifdef HOST_WINDOWS +#include + +void* minicom_CoTaskMemAlloc(size_t cb) +{ + return CoTaskMemAlloc(cb); +} + +void minicom_CoTaskMemFree(void* pv) +{ + CoTaskMemFree(pv); +} +#else +void* minicom_CoTaskMemAlloc(size_t cb) +{ + return malloc(cb); +} + +void minicom_CoTaskMemFree(void* pv) +{ + free(pv); +} +#endif diff --git a/src/native/minipal/memory.h b/src/native/minipal/memory.h index ba85b0e26b028e..890e47909a2740 100644 --- a/src/native/minipal/memory.h +++ b/src/native/minipal/memory.h @@ -11,17 +11,11 @@ { #endif // __cplusplus -#ifndef HOST_WINDOWS -inline void* CoTaskMemAlloc(size_t cb) -{ - return malloc(cb); -} +// Allocate memory on the platform equivalent of the CoTaskMem heap. +void* minicom_CoTaskMemAlloc(size_t cb); -inline void CoTaskMemFree(void* pv) -{ - free(pv); -} -#endif +// Free memory allocated on the platform equivalent of the CoTaskMem heap. +void minicom_CoTaskMemFree(void* pv); #ifdef __cplusplus } From c84060e022d2455351033b607498a4d342a0436e Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 29 Oct 2024 15:51:42 -0700 Subject: [PATCH 27/28] Fix target name change after merge --- src/native/minipal/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/minipal/CMakeLists.txt b/src/native/minipal/CMakeLists.txt index 71966f9048a50e..20259837159d70 100644 --- a/src/native/minipal/CMakeLists.txt +++ b/src/native/minipal/CMakeLists.txt @@ -28,7 +28,7 @@ add_library(aotminipal STATIC ${SOURCES}) set_target_properties(aotminipal PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) if (WIN32) - target_link_libraries(minipal_objects_no_lto PUBLIC bcrypt) + target_link_libraries(aotminipal PUBLIC bcrypt) endif() # Provide a static library for our shared library and executable scenarios From 05d141ba290f2cd23588b8ae24a7167dfb0c2782 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 29 Oct 2024 17:12:27 -0700 Subject: [PATCH 28/28] Don't prefix the method but instead put the header in a subfolder. --- src/coreclr/debug/di/module.cpp | 2 +- src/coreclr/dlls/mscorpe/pewriter.cpp | 4 ++-- src/coreclr/inc/holder.h | 4 ++-- src/coreclr/md/enc/stgio.cpp | 2 +- src/coreclr/vm/gdbjit.cpp | 14 ++++++------- src/coreclr/vm/ilmarshalers.cpp | 2 +- src/coreclr/vm/olevariant.cpp | 8 +++---- src/native/minipal/CMakeLists.txt | 1 - src/native/minipal/com/memory.h | 30 +++++++++++++++++++++++++++ src/native/minipal/memory.c | 28 ------------------------- src/native/minipal/memory.h | 24 --------------------- 11 files changed, 48 insertions(+), 71 deletions(-) create mode 100644 src/native/minipal/com/memory.h delete mode 100644 src/native/minipal/memory.c delete mode 100644 src/native/minipal/memory.h diff --git a/src/coreclr/debug/di/module.cpp b/src/coreclr/debug/di/module.cpp index 9ec196a1d22d4b..02986839e454bb 100644 --- a/src/coreclr/debug/di/module.cpp +++ b/src/coreclr/debug/di/module.cpp @@ -1101,7 +1101,7 @@ void CordbModule::CopyRemoteMetaData( // Allocate space for the local copy of the metadata // No need to zero out the memory since we'll fill it all here. - LPVOID pRawBuffer = minicom_CoTaskMemAlloc(buffer.cbSize); + LPVOID pRawBuffer = CoTaskMemAlloc(buffer.cbSize); if (pRawBuffer == NULL) { ThrowOutOfMemory(); diff --git a/src/coreclr/dlls/mscorpe/pewriter.cpp b/src/coreclr/dlls/mscorpe/pewriter.cpp index fa307d80a657eb..efbf147e55171a 100644 --- a/src/coreclr/dlls/mscorpe/pewriter.cpp +++ b/src/coreclr/dlls/mscorpe/pewriter.cpp @@ -1589,7 +1589,7 @@ HRESULT PEWriter::write(void ** ppImage) size_t lSize = filePos; // allocate the block we are handing back to the caller - void * pImage = (void *) minicom_CoTaskMemAlloc(lSize); + void * pImage = (void *) CoTaskMemAlloc(lSize); if (NULL == pImage) { return E_OUTOFMEMORY; @@ -1622,7 +1622,7 @@ HRESULT PEWriter::write(void ** ppImage) // make sure we wrote the exact numbmer of bytes expected _ASSERTE(lSize == (size_t) (pCur - (char *)pImage)); - // give pointer to memory image back to caller (who must free with minicom_CoTaskMemFree()) + // give pointer to memory image back to caller (who must free with CoTaskMemFree()) *ppImage = pImage; // all done diff --git a/src/coreclr/inc/holder.h b/src/coreclr/inc/holder.h index 0f0f22bff637ed..ea0466df2e16dc 100644 --- a/src/coreclr/inc/holder.h +++ b/src/coreclr/inc/holder.h @@ -10,7 +10,7 @@ #include "staticcontract.h" #include "volatile.h" #include "palclr.h" -#include +#include #include #include @@ -970,7 +970,7 @@ template FORCEINLINE void DeleteCoTaskMem(TYPE *value) { if (value) - minicom_CoTaskMemFree(value); + CoTaskMemFree(value); } template diff --git a/src/coreclr/md/enc/stgio.cpp b/src/coreclr/md/enc/stgio.cpp index d75018e21e6398..aeba5e59f47359 100644 --- a/src/coreclr/md/enc/stgio.cpp +++ b/src/coreclr/md/enc/stgio.cpp @@ -339,7 +339,7 @@ void StgIO::Close() case STGIO_SHAREDMEM: if (m_pBaseData != NULL) { - minicom_CoTaskMemFree(m_pBaseData); + CoTaskMemFree(m_pBaseData); m_pBaseData = NULL; break; } diff --git a/src/coreclr/vm/gdbjit.cpp b/src/coreclr/vm/gdbjit.cpp index a97692485d5c7c..2a376726e52854 100644 --- a/src/coreclr/vm/gdbjit.cpp +++ b/src/coreclr/vm/gdbjit.cpp @@ -452,7 +452,7 @@ HRESULT FunctionMember::GetLocalsDebugInfo(NotifyGdb::PTK_TypeInfoMap pTypeMap, MethodDebugInfo::MethodDebugInfo(int numPoints, int numLocals) { - points = (SequencePointInfo*) minicom_CoTaskMemAlloc(sizeof(SequencePointInfo) * numPoints); + points = (SequencePointInfo*) CoTaskMemAlloc(sizeof(SequencePointInfo) * numPoints); if (points == nullptr) { COMPlusThrowOM(); @@ -467,10 +467,10 @@ MethodDebugInfo::MethodDebugInfo(int numPoints, int numLocals) return; } - locals = (LocalVarInfo*) minicom_CoTaskMemAlloc(sizeof(LocalVarInfo) * numLocals); + locals = (LocalVarInfo*) CoTaskMemAlloc(sizeof(LocalVarInfo) * numLocals); if (locals == nullptr) { - minicom_CoTaskMemFree(points); + CoTaskMemFree(points); COMPlusThrowOM(); } memset(locals, 0, sizeof(LocalVarInfo) * numLocals); @@ -482,13 +482,13 @@ MethodDebugInfo::~MethodDebugInfo() if (locals) { for (int i = 0; i < localsSize; i++) - minicom_CoTaskMemFree(locals[i].name); - minicom_CoTaskMemFree(locals); + CoTaskMemFree(locals[i].name); + CoTaskMemFree(locals); } for (int i = 0; i < size; i++) - minicom_CoTaskMemFree(points[i].fileName); - minicom_CoTaskMemFree(points); + CoTaskMemFree(points[i].fileName); + CoTaskMemFree(points); } /* Get mapping of IL offsets to source line numbers */ diff --git a/src/coreclr/vm/ilmarshalers.cpp b/src/coreclr/vm/ilmarshalers.cpp index 60c11c958692ac..aa9b3d6531553a 100644 --- a/src/coreclr/vm/ilmarshalers.cpp +++ b/src/coreclr/vm/ilmarshalers.cpp @@ -4302,7 +4302,7 @@ extern "C" void QCALLTYPE MngdNativeArrayMarshaler_ConvertSpaceToNative(MngdNati if ( (!ClrSafeInt::multiply(cElements, cbElement, cbArray)) || cbArray > MAX_SIZE_FOR_INTEROP) COMPlusThrow(kArgumentException, IDS_EE_STRUCTARRAYTOOLARGE); - *pNativeHome = minicom_CoTaskMemAlloc(cbArray); + *pNativeHome = CoTaskMemAlloc(cbArray); if (*pNativeHome == NULL) ThrowOutOfMemory(); diff --git a/src/coreclr/vm/olevariant.cpp b/src/coreclr/vm/olevariant.cpp index a736440cd9fe90..b46c5027d097b4 100644 --- a/src/coreclr/vm/olevariant.cpp +++ b/src/coreclr/vm/olevariant.cpp @@ -1657,7 +1657,7 @@ void OleVariant::MarshalLPWSTRRArrayComToOle(BASEARRAYREF *pComArray, void *oleA // Allocate the string using CoTaskMemAlloc. { GCX_PREEMP(); - lpwstr = (LPWSTR)minicom_CoTaskMemAlloc(allocLength); + lpwstr = (LPWSTR)CoTaskMemAlloc(allocLength); } if (lpwstr == NULL) ThrowOutOfMemory(); @@ -1694,7 +1694,7 @@ void OleVariant::ClearLPWSTRArray(void *oleArray, SIZE_T cElements, MethodTable LPWSTR lpwstr = *pOle++; if (lpwstr != NULL) - minicom_CoTaskMemFree(lpwstr); + CoTaskMemFree(lpwstr); } } @@ -1801,7 +1801,7 @@ void OleVariant::MarshalLPSTRRArrayComToOle(BASEARRAYREF *pComArray, void *oleAr // Allocate the string using CoTaskMemAlloc. { GCX_PREEMP(); - lpstr = (LPSTR)minicom_CoTaskMemAlloc(allocLength); + lpstr = (LPSTR)CoTaskMemAlloc(allocLength); } if (lpstr == NULL) ThrowOutOfMemory(); @@ -1840,7 +1840,7 @@ void OleVariant::ClearLPSTRArray(void *oleArray, SIZE_T cElements, MethodTable * LPSTR lpstr = *pOle++; if (lpstr != NULL) - minicom_CoTaskMemFree(lpstr); + CoTaskMemFree(lpstr); } } diff --git a/src/native/minipal/CMakeLists.txt b/src/native/minipal/CMakeLists.txt index 20259837159d70..1504424f3d8a7d 100644 --- a/src/native/minipal/CMakeLists.txt +++ b/src/native/minipal/CMakeLists.txt @@ -3,7 +3,6 @@ include(configure.cmake) set(SOURCES cpufeatures.c guid.c - memory.c random.c debugger.c strings.c diff --git a/src/native/minipal/com/memory.h b/src/native/minipal/com/memory.h new file mode 100644 index 00000000000000..1a869f50acec4d --- /dev/null +++ b/src/native/minipal/com/memory.h @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef MINIPAL_COM_MEMORY_H +#define MINIPAL_COM_MEMORY_H + +#include + +#ifdef __cplusplus + extern "C" + { +#endif // __cplusplus + +#ifndef HOST_WINDOWS +inline void* CoTaskMemAlloc(size_t cb) +{ + return malloc(cb); +} + +inline void CoTaskMemFree(void* pv) +{ + free(pv); +} +#endif + +#ifdef __cplusplus + } +#endif // __cplusplus + +#endif // MINIPAL_COM_MEMORY_H diff --git a/src/native/minipal/memory.c b/src/native/minipal/memory.c deleted file mode 100644 index dac3da74aa06be..00000000000000 --- a/src/native/minipal/memory.c +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include "memory.h" - -#ifdef HOST_WINDOWS -#include - -void* minicom_CoTaskMemAlloc(size_t cb) -{ - return CoTaskMemAlloc(cb); -} - -void minicom_CoTaskMemFree(void* pv) -{ - CoTaskMemFree(pv); -} -#else -void* minicom_CoTaskMemAlloc(size_t cb) -{ - return malloc(cb); -} - -void minicom_CoTaskMemFree(void* pv) -{ - free(pv); -} -#endif diff --git a/src/native/minipal/memory.h b/src/native/minipal/memory.h deleted file mode 100644 index 890e47909a2740..00000000000000 --- a/src/native/minipal/memory.h +++ /dev/null @@ -1,24 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#ifndef MINIPAL_MEMORY_H -#define MINIPAL_MEMORY_H - -#include - -#ifdef __cplusplus - extern "C" - { -#endif // __cplusplus - -// Allocate memory on the platform equivalent of the CoTaskMem heap. -void* minicom_CoTaskMemAlloc(size_t cb); - -// Free memory allocated on the platform equivalent of the CoTaskMem heap. -void minicom_CoTaskMemFree(void* pv); - -#ifdef __cplusplus - } -#endif // __cplusplus - -#endif // MINIPAL_MEMORY_H