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 all 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
7 changes: 6 additions & 1 deletion src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ endif(CLR_CROSS_COMPONENTS_BUILD)
#-------------------
include(pgosupport.cmake)

add_subdirectory(src/libraries-native)
#-------------------------------
# Include libraries native shims
#-------------------------------
if(NOT CLR_CROSS_COMPONENTS_BUILD)
add_subdirectory(src/libraries-native)
endif(NOT CLR_CROSS_COMPONENTS_BUILD)

#-----------------------------------------
# Add Projects
Expand Down
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
16 changes: 14 additions & 2 deletions 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)

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)
# Suppress exporting of the PAL APIs
add_definitions(-DPALEXPORT=)

if(CLR_CMAKE_HOST_UNIX)
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
)
67 changes: 67 additions & 0 deletions src/coreclr/src/libraries-native/entrypoints.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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.

#ifdef TARGET_UNIX

#include "pal_types.h"

typedef uint16_t UChar;

// Include System.Globalization.Native headers
#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
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 @@ -113,18 +114,21 @@ public static string LibcVersion

private static Version GetICUVersion()
{
if (IsWindows)
int version = 0;
Type interopGlobalization = Type.GetType("Interop+Globalization");
if (interopGlobalization != null)
{
return new Version(0, 0, 0, 0);
}
else
{
int ver = libc.GlobalizationNative_GetICUVersion();
return new Version( ver & 0xFF,
(ver >> 8) & 0xFF,
(ver >> 16) & 0xFF,
ver >> 24);
MethodInfo methodInfo = interopGlobalization.GetMethod("GetICUVersion", BindingFlags.NonPublic | BindingFlags.Static);
if (methodInfo != null)
{
version = (int)methodInfo.Invoke(null, null);
}
}

return new Version( version & 0xFF,
(version >> 8) & 0xFF,
(version >> 16) & 0xFF,
version >> 24);
}

private static Version GetOSXProductVersion()
Expand Down Expand Up @@ -327,9 +331,6 @@ 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();
}
}
}
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 @@ -7,6 +7,8 @@
#include <string.h>
#include <strings.h>

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

#define GREGORIAN_NAME "gregorian"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#pragma once

#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 +70,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 @@ -6,8 +6,8 @@
#include <assert.h>
#include <stdint.h>

#include "pal_icushim_internal.h"
#include "pal_casing.h"
#include "pal_icushim.h"

// Workaround for warnings produced by U16_NEXT and U16_APPEND macro expansions
#pragma clang diagnostic push
Expand Down
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 @@ -10,6 +10,7 @@
#include <search.h>
#include <string.h>

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

c_static_assert_msg(UCOL_EQUAL == 0, "managed side requires 0 for equal strings");
Expand Down
Loading