Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert System.Globalization unix calls to QCalls into coreclr #32132

Merged
merged 16 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/coreclr/src/System.Private.CoreLib/ILLinkTrim.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<linker>
<assembly fullname="System.Private.CoreLib">
<type fullname="Interop/Globalization">
<!-- Internal API used by tests only. -->
<method name="GetICUVersion" />
</type>
<type fullname="System.GC">
<!-- Methods are used to register and unregister frozen segments. They are private and experimental. -->
<method name="_RegisterFrozenSegment" />
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ set(CORECLR_LIBRARIES
gcinfo # Condition="'$(TargetCpu)'=='amd64' or '$(TargetCpu)' == 'arm' or '$(TargetCpu)' == 'arm64'"
ildbsymlib
utilcode
libraries-native
)

if(CLR_CMAKE_TARGET_WIN32)
Expand Down
14 changes: 13 additions & 1 deletion src/coreclr/src/libraries-native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(GLOBALIZATION_NATIVE_DIR ${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Globalization.Native)

# Suppress exporting of the PAL APIs
add_definitions(-DPALEXPORT=)

if(CLR_CMAKE_HOST_UNIX AND NOT CLR_CROSS_COMPONENTS_BUILD)
add_subdirectory(${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/System.Globalization.Native System.Globalization.Native)
include_directories("${CLR_REPO_ROOT_DIR}/src/libraries/Native/Unix/Common")
include_directories("${GLOBALIZATION_NATIVE_DIR}")

add_subdirectory(${GLOBALIZATION_NATIVE_DIR} System.Globalization.Native)
endif()

add_library(libraries-native
STATIC
entrypoints.c
)
65 changes: 65 additions & 0 deletions src/coreclr/src/libraries-native/entrypoints.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#ifndef __LIB_NATIVE_ENTRYPOINTS
#define __LIB_NATIVE_ENTRYPOINTS
#endif

#ifdef TARGET_UNIX
#include "pal_calendarData.h"
#include "pal_casing.h"
#include "pal_collation.h"
#include "pal_locale.h"
#include "pal_localeNumberData.h"
#include "pal_localeStringData.h"
#include "pal_icushim.h"
#include "pal_idna.h"
#include "pal_normalization.h"
#include "pal_timeZoneInfo.h"
#endif // TARGET_UNIX

#define FCFuncStart(name) extern const void* name[]; const void* name[] = {
#define FCFuncEnd() (void*)0x01 /* FCFuncFlag_EndOfArray */ };

#define QCFuncElement(name,impl) \
(void*)0x8 /* FCFuncFlag_QCall */, (void*)(impl), (void*)name,

#ifdef TARGET_UNIX
FCFuncStart(gPalGlobalizationNative)
QCFuncElement("ChangeCase", GlobalizationNative_ChangeCase)
QCFuncElement("ChangeCaseInvariant", GlobalizationNative_ChangeCaseInvariant)
QCFuncElement("ChangeCaseTurkish", GlobalizationNative_ChangeCaseTurkish)
QCFuncElement("CloseSortHandle", GlobalizationNative_CloseSortHandle)
QCFuncElement("CompareString", GlobalizationNative_CompareString)
QCFuncElement("CompareStringOrdinalIgnoreCase", GlobalizationNative_CompareStringOrdinalIgnoreCase)
QCFuncElement("EndsWith", GlobalizationNative_EndsWith)
QCFuncElement("EnumCalendarInfo", GlobalizationNative_EnumCalendarInfo)
QCFuncElement("GetCalendarInfo", GlobalizationNative_GetCalendarInfo)
QCFuncElement("GetCalendars", GlobalizationNative_GetCalendars)
QCFuncElement("GetDefaultLocaleName", GlobalizationNative_GetDefaultLocaleName)
QCFuncElement("GetICUVersion", GlobalizationNative_GetICUVersion)
QCFuncElement("GetJapaneseEraStartDate", GlobalizationNative_GetJapaneseEraStartDate)
QCFuncElement("GetLatestJapaneseEra", GlobalizationNative_GetLatestJapaneseEra)
QCFuncElement("GetLocaleInfoGroupingSizes", GlobalizationNative_GetLocaleInfoGroupingSizes)
QCFuncElement("GetLocaleInfoInt", GlobalizationNative_GetLocaleInfoInt)
QCFuncElement("GetLocaleInfoString", GlobalizationNative_GetLocaleInfoString)
QCFuncElement("GetLocaleName", GlobalizationNative_GetLocaleName)
QCFuncElement("GetLocales", GlobalizationNative_GetLocales)
QCFuncElement("GetLocaleTimeFormat", GlobalizationNative_GetLocaleTimeFormat)
QCFuncElement("GetSortHandle", GlobalizationNative_GetSortHandle)
QCFuncElement("GetSortKey", GlobalizationNative_GetSortKey)
QCFuncElement("GetSortVersion", GlobalizationNative_GetSortVersion)
QCFuncElement("GetTimeZoneDisplayName", GlobalizationNative_GetTimeZoneDisplayName)
QCFuncElement("IndexOf", GlobalizationNative_IndexOf)
QCFuncElement("IndexOfOrdinalIgnoreCase", GlobalizationNative_IndexOfOrdinalIgnoreCase)
QCFuncElement("IsNormalized", GlobalizationNative_IsNormalized)
QCFuncElement("IsPredefinedLocale", GlobalizationNative_IsPredefinedLocale)
QCFuncElement("LastIndexOf", GlobalizationNative_LastIndexOf)
QCFuncElement("LoadICU", GlobalizationNative_LoadICU)
QCFuncElement("NormalizeString", GlobalizationNative_NormalizeString)
QCFuncElement("StartsWith", GlobalizationNative_StartsWith)
QCFuncElement("ToAscii", GlobalizationNative_ToAscii)
QCFuncElement("ToUnicode", GlobalizationNative_ToUnicode)
FCFuncEnd()
#endif // TARGET_UNIX
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4828,7 +4828,7 @@ void NDirect::PopulateNDirectMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSi
if (callConv == pmCallConvThiscall)
ndirectflags |= NDirectMethodDesc::kThisCall;

if (pNMD->GetLoaderModule()->IsSystem() && strcmp(szLibName, "QCall") == 0)
if (pNMD->GetLoaderModule()->IsSystem() && (strcmp(szLibName, "QCall") == 0 || strcmp(szLibName, "System.Globalization.Native") == 0))
{
ndirectflags |= NDirectMethodDesc::kIsQCall;
}
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/src/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,11 @@ FCClassElement("FileLoadException", "System.IO", gFileLoadExceptionFuncs)
FCClassElement("GC", "System", gGCInterfaceFuncs)
FCClassElement("GCHandle", "System.Runtime.InteropServices", gGCHandleFuncs)
FCClassElement("GCSettings", "System.Runtime", gGCSettingsFuncs)
#ifdef TARGET_UNIX
#ifndef CROSSGEN_COMPILE
FCClassElement("Globalization", "", gPalGlobalizationNative)
#endif
#endif
#ifdef FEATURE_COMINTEROP
FCClassElement("IEnumerable", "System.Collections", gStdMngIEnumerableFuncs)
FCClassElement("IEnumerator", "System.Collections", gStdMngIEnumeratorFuncs)
Expand Down
7 changes: 3 additions & 4 deletions src/coreclr/src/vm/mscorlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,14 @@ const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[] =
};
const USHORT c_nMscorlibFieldDescriptions = NumItems(c_rgMscorlibFieldDescriptions) + 1;





///////////////////////////////////////////////////////////////////////////////
//
// ECalls
//

// ECalls defined by libraries-native shims
EXTERN_C const LPVOID gPalGlobalizationNative[];

// When compiling crossgen, we only need the target version of the ecall tables
#if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_MSCORLIB)

Expand Down
4 changes: 3 additions & 1 deletion src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
safern marked this conversation as resolved.
Show resolved Hide resolved

internal static partial class Interop
{
internal static partial class Libraries
{
// Shims
internal const string SystemNative = "System.Native";
internal const string GlobalizationNative = "System.Globalization.Native";
internal const string NetSecurityNative = "System.Net.Security.Native";
internal const string CryptoNative = "System.Security.Cryptography.Native.OpenSsl";
internal const string CompressionNative = "System.IO.Compression.Native";
internal const string IOPortsNative = "System.IO.Ports.Native";
internal const string Libdl = "libdl";
internal const string GlobalizationNative = "System.Globalization.Native";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ internal static partial class Globalization
{
[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LoadICU")]
internal static extern int LoadICU();

[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetICUVersion")]
internal static extern int GetICUVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Reflection;
using System.Runtime.InteropServices;
using System.Xml.Linq;

Expand Down Expand Up @@ -119,7 +120,7 @@ private static Version GetICUVersion()
}
safern marked this conversation as resolved.
Show resolved Hide resolved
else
{
int ver = libc.GlobalizationNative_GetICUVersion();
int ver = libc.GetICUVersion();
return new Version( ver & 0xFF,
(ver >> 8) & 0xFF,
(ver >> 16) & 0xFF,
Expand Down Expand Up @@ -328,8 +329,20 @@ private static class libc
[DllImport("libc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr gnu_get_libc_version();

[DllImport("System.Globalization.Native", SetLastError = true)]
public static extern int GlobalizationNative_GetICUVersion();
public unsafe static int GetICUVersion()
safern marked this conversation as resolved.
Show resolved Hide resolved
safern marked this conversation as resolved.
Show resolved Hide resolved
{
Type interopGlobalization = Type.GetType("Interop+Globalization");
if (interopGlobalization != null)
{
MethodInfo methodInfo = interopGlobalization.GetMethod("GetICUVersion", BindingFlags.NonPublic | BindingFlags.Static);
if (methodInfo != null)
{
return (int)methodInfo.Invoke(null, new object[] { });
}
}

throw new Exception("Failed to find method Interop.Globalization.GetICUVersion.");
}
}
}
}
2 changes: 1 addition & 1 deletion src/libraries/Native/AnyOS/zlib/pal_zlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#else
#include "pal_types.h"
#include "pal_compiler.h"
#define FUNCTIONEXPORT DLLEXPORT
#define FUNCTIONEXPORT PALEXPORT
#define FUNCTIONCALLINGCONVENCTION
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(VERSION_FILE_PATH "${CMAKE_BINARY_DIR}/version.c")

# We mark the function which needs exporting with DLLEXPORT
# We mark the function which needs exporting with PALEXPORT
add_compile_options(-fvisibility=hidden)

add_compile_options(-Wno-format-nonliteral)
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/Native/Unix/Common/pal_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
#define c_static_assert(e) c_static_assert_msg(e, "")
#endif

#define DLLEXPORT __attribute__ ((__visibility__ ("default")))
#ifndef PALEXPORT
#define PALEXPORT __attribute__ ((__visibility__ ("default")))
#endif // ifndef PALEXPORT
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <strings.h>

#include "pal_calendarData.h"
#include "pal_errors_internal.h"
#include "pal_locale_internal.h"

#define GREGORIAN_NAME "gregorian"
#define JAPANESE_NAME "japanese"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <stdlib.h>

#include "pal_compiler.h"
#include "pal_locale.h"
#include "pal_compiler.h"
#include "pal_errors.h"

/*
Expand Down Expand Up @@ -68,25 +68,25 @@ typedef enum
// the function pointer definition for the callback used in EnumCalendarInfo
typedef void (*EnumCalendarInfoCallback)(const UChar*, const void*);

DLLEXPORT int32_t GlobalizationNative_GetCalendars(const UChar* localeName,
PALEXPORT int32_t GlobalizationNative_GetCalendars(const UChar* localeName,
CalendarId* calendars,
int32_t calendarsCapacity);

DLLEXPORT ResultCode GlobalizationNative_GetCalendarInfo(const UChar* localeName,
PALEXPORT ResultCode GlobalizationNative_GetCalendarInfo(const UChar* localeName,
CalendarId calendarId,
CalendarDataType dataType,
UChar* result,
int32_t resultCapacity);

DLLEXPORT int32_t GlobalizationNative_EnumCalendarInfo(EnumCalendarInfoCallback callback,
PALEXPORT int32_t GlobalizationNative_EnumCalendarInfo(EnumCalendarInfoCallback callback,
const UChar* localeName,
CalendarId calendarId,
CalendarDataType dataType,
const void* context);

DLLEXPORT int32_t GlobalizationNative_GetLatestJapaneseEra(void);
PALEXPORT int32_t GlobalizationNative_GetLatestJapaneseEra(void);

DLLEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era,
PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era,
int32_t* startYear,
int32_t* startMonth,
int32_t* startDay);
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#include "pal_compiler.h"
#include "pal_locale.h"
#include "pal_compiler.h"

DLLEXPORT void GlobalizationNative_ChangeCase(const UChar* lpSrc,
PALEXPORT void GlobalizationNative_ChangeCase(const UChar* lpSrc,
int32_t cwSrcLength,
UChar* lpDst,
int32_t cwDstLength,
int32_t bToUpper);

DLLEXPORT void GlobalizationNative_ChangeCaseInvariant(const UChar* lpSrc,
PALEXPORT void GlobalizationNative_ChangeCaseInvariant(const UChar* lpSrc,
int32_t cwSrcLength,
UChar* lpDst,
int32_t cwDstLength,
int32_t bToUpper);

DLLEXPORT void GlobalizationNative_ChangeCaseTurkish(const UChar* lpSrc,
PALEXPORT void GlobalizationNative_ChangeCaseTurkish(const UChar* lpSrc,
int32_t cwSrcLength,
UChar* lpDst,
int32_t cwDstLength,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <string.h>

#include "pal_collation.h"
#include "pal_errors_internal.h"

c_static_assert_msg(UCOL_EQUAL == 0, "managed side requires 0 for equal strings");
c_static_assert_msg(UCOL_LESS < 0, "managed side requires less than zero for a < b");
Expand Down
Loading