Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Remove API Set dependency #8624

Merged
merged 1 commit into from
Dec 15, 2016
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
1 change: 0 additions & 1 deletion dir.props
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@

<!-- Central place to set the versions of all nuget packages produced in the repo -->
<PackageVersion Condition="'$(PackageVersion)' == ''">1.2.0</PackageVersion>
<WindowsAPISetPackageVersion>1.0.1</WindowsAPISetPackageVersion>

<!-- Set the boolean below to true to generate packages with stabilized versions -->
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">false</StabilizePackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
<IncludeRuntimeJson>true</IncludeRuntimeJson>
</PropertyGroup>
<ItemGroup>
<!-- ApiSets are only applicable for Windows.
Despite the unconditioned package dependency it is constrained by runtime IDs within it's own package -->
<Dependency Include="Microsoft.NETCore.Windows.ApiSets">
<Version>$(WindowsAPISetPackageVersion)</Version>
</Dependency>
<ProjectReference Include="..\Microsoft.NETCore.Jit\Microsoft.NETCore.Jit.pkgproj" />
<ProjectReference Include="win\Microsoft.NETCore.Runtime.CoreCLR.pkgproj">
<Platform>amd64</Platform>
Expand Down
54 changes: 7 additions & 47 deletions src/gc/gcenv.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,6 @@ void GetProcessMemoryLoad(LPMEMORYSTATUSEX pMSEX)
}
}

#ifdef FEATURE_CORECLR

inline bool RunningOnWin8()
{
// TODO(segilles) platform detection
return false;
}

// For coresys we need to look for an API in some apiset dll on win8 if we can't find it
// in the traditional dll.
HINSTANCE LoadDllForAPI(const WCHAR* dllTraditional, const WCHAR* dllApiSet)
{
HINSTANCE hinst = LoadLibraryEx(dllTraditional, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);

if (!hinst)
{
if(RunningOnWin8())
hinst = LoadLibraryEx(dllApiSet, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
}

return hinst;
}
#endif

static size_t GetRestrictedPhysicalMemoryLimit()
{
LIMITED_METHOD_CONTRACT;
Expand All @@ -76,19 +52,16 @@ static size_t GetRestrictedPhysicalMemoryLimit()

size_t job_physical_memory_limit = (size_t)UINTPTR_MAX;
BOOL in_job_p = FALSE;
HINSTANCE hinstApiSetPsapiOrKernel32 = 0;
// these 2 modules will need to be freed no matter what as we only use them locally in this method.
HINSTANCE hinstApiSetJob1OrKernel32 = 0;
HINSTANCE hinstApiSetJob2OrKernel32 = 0;
HINSTANCE hinstKernel32 = 0;

PIS_PROCESS_IN_JOB GCIsProcessInJob = 0;
PQUERY_INFORMATION_JOB_OBJECT GCQueryInformationJobObject = 0;

hinstApiSetJob1OrKernel32 = LoadDllForAPI(L"kernel32.dll", L"api-ms-win-core-job-l1-1-0.dll");
if (!hinstApiSetJob1OrKernel32)
hinstKernel32 = LoadLibraryEx(L"kernel32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (!hinstKernel32)
goto exit;

GCIsProcessInJob = (PIS_PROCESS_IN_JOB)GetProcAddress(hinstApiSetJob1OrKernel32, "IsProcessInJob");
GCIsProcessInJob = (PIS_PROCESS_IN_JOB)GetProcAddress(hinstKernel32, "IsProcessInJob");
if (!GCIsProcessInJob)
goto exit;

Expand All @@ -97,20 +70,12 @@ static size_t GetRestrictedPhysicalMemoryLimit()

if (in_job_p)
{
hinstApiSetPsapiOrKernel32 = LoadDllForAPI(L"kernel32.dll", L"api-ms-win-core-psapi-l1-1-0");
if (!hinstApiSetPsapiOrKernel32)
goto exit;

GCGetProcessMemoryInfo = (PGET_PROCESS_MEMORY_INFO)GetProcAddress(hinstApiSetPsapiOrKernel32, "K32GetProcessMemoryInfo");
GCGetProcessMemoryInfo = (PGET_PROCESS_MEMORY_INFO)GetProcAddress(hinstKernel32, "K32GetProcessMemoryInfo");

if (!GCGetProcessMemoryInfo)
goto exit;

hinstApiSetJob2OrKernel32 = LoadDllForAPI(L"kernel32.dll", L"api-ms-win-core-job-l2-1-0");
if (!hinstApiSetJob2OrKernel32)
goto exit;

GCQueryInformationJobObject = (PQUERY_INFORMATION_JOB_OBJECT)GetProcAddress(hinstApiSetJob2OrKernel32, "QueryInformationJobObject");
GCQueryInformationJobObject = (PQUERY_INFORMATION_JOB_OBJECT)GetProcAddress(hinstKernel32, "QueryInformationJobObject");

if (!GCQueryInformationJobObject)
goto exit;
Expand Down Expand Up @@ -153,16 +118,11 @@ static size_t GetRestrictedPhysicalMemoryLimit()
}

exit:
if (hinstApiSetJob1OrKernel32)
FreeLibrary(hinstApiSetJob1OrKernel32);
if (hinstApiSetJob2OrKernel32)
FreeLibrary(hinstApiSetJob2OrKernel32);

if (job_physical_memory_limit == (size_t)UINTPTR_MAX)
{
job_physical_memory_limit = 0;

FreeLibrary(hinstApiSetPsapiOrKernel32);
FreeLibrary(hinstKernel32);
}

VolatileStore(&g_RestrictedPhysicalMemoryLimit, job_physical_memory_limit);
Expand Down
13 changes: 3 additions & 10 deletions src/vm/codeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,16 +1226,9 @@ bool DoesOSSupportAVX()
typedef DWORD64 (WINAPI *PGETENABLEDXSTATEFEATURES)();
PGETENABLEDXSTATEFEATURES pfnGetEnabledXStateFeatures = NULL;

// Probe ApiSet first
HMODULE hMod = WszLoadLibraryEx(W("api-ms-win-core-xstate-l2-1-0.dll"), NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);

if (hMod == NULL)
{
// On older OS's where apiset is not present probe kernel32
hMod = WszLoadLibraryEx(WINDOWS_KERNEL32_DLLNAME_W, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
if(hMod = NULL)
return FALSE;
}
HMODULE hMod = WszLoadLibraryEx(WINDOWS_KERNEL32_DLLNAME_W, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
if(hMod = NULL)
return FALSE;

pfnGetEnabledXStateFeatures = (PGETENABLEDXSTATEFEATURES)GetProcAddress(hMod, "GetEnabledXStateFeatures");

Expand Down
55 changes: 5 additions & 50 deletions src/vm/gcenv.os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,23 +370,6 @@ static size_t g_RestrictedPhysicalMemoryLimit = (size_t)MAX_PTR;
typedef BOOL (WINAPI *PIS_PROCESS_IN_JOB)(HANDLE processHandle, HANDLE jobHandle, BOOL* result);
typedef BOOL (WINAPI *PQUERY_INFORMATION_JOB_OBJECT)(HANDLE jobHandle, JOBOBJECTINFOCLASS jobObjectInfoClass, void* lpJobObjectInfo, DWORD cbJobObjectInfoLength, LPDWORD lpReturnLength);

#ifdef FEATURE_CORECLR
// For coresys we need to look for an API in some apiset dll on win8 if we can't find it
// in the traditional dll.
HINSTANCE LoadDllForAPI(const WCHAR* dllTraditional, const WCHAR* dllApiSet)
{
HINSTANCE hinst = WszLoadLibrary(dllTraditional);

if (!hinst)
{
if(RunningOnWin8())
hinst = WszLoadLibrary(dllApiSet);
}

return hinst;
}
#endif

static size_t GetRestrictedPhysicalMemoryLimit()
{
LIMITED_METHOD_CONTRACT;
Expand All @@ -398,40 +381,27 @@ static size_t GetRestrictedPhysicalMemoryLimit()
size_t job_physical_memory_limit = (size_t)MAX_PTR;
BOOL in_job_p = FALSE;
#ifdef FEATURE_CORECLR
HINSTANCE hinstApiSetPsapiOrKernel32 = 0;
// these 2 modules will need to be freed no matter what as we only use them locally in this method.
HINSTANCE hinstApiSetJob1OrKernel32 = 0;
HINSTANCE hinstApiSetJob2OrKernel32 = 0;
HINSTANCE hinstKernel32 = 0;
#else
HINSTANCE hinstPsapi = 0;
#endif

PIS_PROCESS_IN_JOB GCIsProcessInJob = 0;
PQUERY_INFORMATION_JOB_OBJECT GCQueryInformationJobObject = 0;

#ifdef FEATURE_CORECLR
hinstApiSetJob1OrKernel32 = LoadDllForAPI(L"kernel32.dll", L"api-ms-win-core-job-l1-1-0.dll");
if (!hinstApiSetJob1OrKernel32)
goto exit;

GCIsProcessInJob = (PIS_PROCESS_IN_JOB)GetProcAddress(hinstApiSetJob1OrKernel32, "IsProcessInJob");
if (!GCIsProcessInJob)
goto exit;
#else
GCIsProcessInJob = &(::IsProcessInJob);
#endif

if (!GCIsProcessInJob(GetCurrentProcess(), NULL, &in_job_p))
goto exit;

if (in_job_p)
{
#ifdef FEATURE_CORECLR
hinstApiSetPsapiOrKernel32 = LoadDllForAPI(L"kernel32.dll", L"api-ms-win-core-psapi-l1-1-0");
if (!hinstApiSetPsapiOrKernel32)
hinstKernel32 = WszLoadLibrary(L"kernel32.dll");
if (!hinstKernel32)
goto exit;

GCGetProcessMemoryInfo = (PGET_PROCESS_MEMORY_INFO)GetProcAddress(hinstApiSetPsapiOrKernel32, "K32GetProcessMemoryInfo");
GCGetProcessMemoryInfo = (PGET_PROCESS_MEMORY_INFO)GetProcAddress(hinstKernel32, "K32GetProcessMemoryInfo");
#else
// We need a way to get the working set in a job object and GetProcessMemoryInfo
// is the way to get that. According to MSDN, we should use GetProcessMemoryInfo In order to
Expand All @@ -445,15 +415,7 @@ static size_t GetRestrictedPhysicalMemoryLimit()
if (!GCGetProcessMemoryInfo)
goto exit;

#ifdef FEATURE_CORECLR
hinstApiSetJob2OrKernel32 = LoadDllForAPI(L"kernel32.dll", L"api-ms-win-core-job-l2-1-0");
if (!hinstApiSetJob2OrKernel32)
goto exit;

GCQueryInformationJobObject = (PQUERY_INFORMATION_JOB_OBJECT)GetProcAddress(hinstApiSetJob2OrKernel32, "QueryInformationJobObject");
#else
GCQueryInformationJobObject = &(::QueryInformationJobObject);
#endif

if (!GCQueryInformationJobObject)
goto exit;
Expand Down Expand Up @@ -496,19 +458,12 @@ static size_t GetRestrictedPhysicalMemoryLimit()
}

exit:
#ifdef FEATURE_CORECLR
if (hinstApiSetJob1OrKernel32)
FreeLibrary(hinstApiSetJob1OrKernel32);
if (hinstApiSetJob2OrKernel32)
FreeLibrary(hinstApiSetJob2OrKernel32);
#endif

if (job_physical_memory_limit == (size_t)MAX_PTR)
{
job_physical_memory_limit = 0;

#ifdef FEATURE_CORECLR
FreeLibrary(hinstApiSetPsapiOrKernel32);
FreeLibrary(hinstKernel32);
#else
FreeLibrary(hinstPsapi);
#endif
Expand Down