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

Remove all uses of non Ex version of LoadLibrary API from PAL #91693

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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: 2 additions & 2 deletions src/coreclr/debug/di/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ STDAPI DLLEXPORT OpenVirtualProcessImpl2(
CLR_DEBUGGING_PROCESS_FLAGS* pFlagsOut)
{
#ifdef TARGET_WINDOWS
HMODULE hDac = LoadLibraryExW(pDacModulePath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
HMODULE hDac = WszLoadLibrary(pDacModulePath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
#else
HMODULE hDac = LoadLibraryW(pDacModulePath);
HMODULE hDac = WszLoadLibrary(pDacModulePath);
#endif // !TARGET_WINDOWS
if (hDac == NULL)
{
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/debug/di/shimprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,11 +1609,7 @@ HMODULE ShimProcess::GetDacModule(PathString& dacModulePath)
ThrowLastError();
}

// Dac Dll is named:
// mscordaccore.dll <-- coreclr
// mscordacwks.dll <-- desktop
PCWSTR eeFlavor = MAKEDLLNAME_W(W("mscordaccore"));

wszAccessDllPath.Append(eeFlavor);
}
hDacDll = WszLoadLibrary(wszAccessDllPath);
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/dlls/mscordac/mscordac_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ nativeStringResourceTable_mscorrc
#GetTempPathW
#InitializeCriticalSection
#LeaveCriticalSection
#LoadLibraryA
#LoadLibraryW
#LoadLibraryExA
#LoadLibraryExW
#MapViewOfFile
#MapViewOfFileEx
Expand Down
6 changes: 1 addition & 5 deletions src/coreclr/inc/winwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
#undef OpenSemaphore
#undef CreateWaitableTimer
#undef CreateFileMapping
#undef LoadLibrary
#undef LoadLibraryEx
#undef GetModuleFileName
#undef GetModuleHandle
#undef GetModuleHandleEx
Expand Down Expand Up @@ -191,12 +189,10 @@
//Note only the functions which are currently used are defined
#ifdef HOST_WINDOWS
#define WszLoadLibrary LoadLibraryExWrapper
#define WszLoadLibraryEx LoadLibraryExWrapper
#define WszCreateFile CreateFileWrapper
#define WszGetFileAttributesEx GetFileAttributesExWrapper
#else // HOST_WINDOWS
#define WszLoadLibrary LoadLibraryW
#define WszLoadLibraryEx LoadLibraryExW
#define WszLoadLibrary LoadLibraryExW
#define WszCreateFile CreateFileW
#define WszGetFileAttributesEx GetFileAttributesExW
#endif // HOST_WINDOWS
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/md/enc/stgio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ HRESULT StgIO::Open( // Return code.
// most of the security risk anyway).
if ((fFlags & DBPROP_TMODEF_TRYLOADLIBRARY) != 0)
{
m_hModule = WszLoadLibraryEx(szName, NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE);
m_hModule = WszLoadLibrary(szName, NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE);
if (m_hModule != NULL)
{
m_iType = STGIO_HMODULE;
Expand Down
19 changes: 2 additions & 17 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2826,20 +2826,13 @@ PALAPI
UnmapViewOfFile(
IN LPCVOID lpBaseAddress);


PALIMPORT
HMODULE
PALAPI
LoadLibraryW(
IN LPCWSTR lpLibFileName);

PALIMPORT
HMODULE
PALAPI
LoadLibraryExW(
IN LPCWSTR lpLibFileName,
IN /*Reserved*/ HANDLE hFile,
IN DWORD dwFlags);
IN /*Reserved*/ HANDLE hFile = NULL,
IN DWORD dwFlags = 0);

PALIMPORT
NATIVE_LIBRARY_HANDLE
Expand Down Expand Up @@ -2919,14 +2912,6 @@ BOOL
PALAPI
PAL_LOADMarkSectionAsNotNeeded(void * ptr);

#ifdef UNICODE
#define LoadLibrary LoadLibraryW
#define LoadLibraryEx LoadLibraryExW
#else
#define LoadLibrary LoadLibraryA
#define LoadLibraryEx LoadLibraryExA
#endif

PALIMPORT
FARPROC
PALAPI
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/pal/inc/palprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ OpenMutexA(
IN BOOL bInheritHandle,
IN LPCSTR lpName);

PALIMPORT
HMODULE
PALAPI
LoadLibraryA(
IN LPCSTR lpLibFileName);

PALIMPORT
HMODULE
PALAPI
Expand Down
30 changes: 1 addition & 29 deletions src/coreclr/pal/src/loader/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,34 +104,6 @@ static BOOL LOADCallDllMainSafe(MODSTRUCT *module, DWORD dwReason, LPVOID lpRese

/* API function definitions ***************************************************/

/*++
Function:
LoadLibraryA

See MSDN doc.
--*/
HMODULE
PALAPI
LoadLibraryA(
IN LPCSTR lpLibFileName)
{
return LoadLibraryExA(lpLibFileName, nullptr, 0);
}

/*++
Function:
LoadLibraryW

See MSDN doc.
--*/
HMODULE
PALAPI
LoadLibraryW(
IN LPCWSTR lpLibFileName)
{
return LoadLibraryExW(lpLibFileName, nullptr, 0);
}

/*++
Function:
LoadLibraryExA
Expand All @@ -154,7 +126,7 @@ LoadLibraryExA(

HMODULE hModule = nullptr;

PERF_ENTRY(LoadLibraryA);
PERF_ENTRY(LoadLibraryExA);
ENTRY("LoadLibraryExA (lpLibFileName=%p (%s)) \n",
(lpLibFileName) ? lpLibFileName : "NULL",
(lpLibFileName) ? lpLibFileName : "NULL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ PALTEST(filemapping_memmgt_FreeLibrary_test1_paltest_freelibrary_test1, "filemap
{
return (FAIL);
}

/*Load library (DLL). */
hLib = LoadLibrary(LibraryName);
hLib = LoadLibraryExA(LibraryName, NULL, 0);

if(hLib == NULL)
{
Fail("ERROR:%u:Unable to load library %s\n",
GetLastError(),
Fail("ERROR:%u:Unable to load library %s\n",
GetLastError(),
LibraryName);
}

Expand All @@ -54,10 +54,10 @@ PALTEST(filemapping_memmgt_FreeLibrary_test1_paltest_freelibrary_test1, "filemap
Fail("");
}

/* Call the FreeLibrary API. */
/* Call the FreeLibrary API. */
if (!FreeLibrary(hLib))
{
Fail("ERROR:%u: Unable to free library \"%s\"\n",
Fail("ERROR:%u: Unable to free library \"%s\"\n",
GetLastError(),
LibraryName);
}
Expand All @@ -83,7 +83,7 @@ BOOL PALAPI TestDll(HMODULE hLib, int testResult)
#else
char FunctName[] = "DllTest";
#endif
FARPROC DllAddr;
FARPROC DllAddr;

/* Attempt to grab the proc address of the dll function.
* This one should succeed.*/
Expand All @@ -92,12 +92,12 @@ BOOL PALAPI TestDll(HMODULE hLib, int testResult)
DllAddr = GetProcAddress(hLib, FunctName);
if(DllAddr == NULL)
{
Trace("ERROR: Unable to load function \"%s\" library \"%s\"\n",
Trace("ERROR: Unable to load function \"%s\" library \"%s\"\n",
FunctName,
LibraryName);
return (FALSE);
}
/* Run the function in the DLL,
/* Run the function in the DLL,
* to ensure that the DLL was loaded properly.*/
RetVal = DllAddr();
if (RetVal != 1)
Expand All @@ -117,8 +117,8 @@ BOOL PALAPI TestDll(HMODULE hLib, int testResult)
if(DllAddr != NULL)
{
Trace("ERROR: Able to load function \"%s\" from free'd"
" library \"%s\"\n",
FunctName,
" library \"%s\"\n",
FunctName,
LibraryName);
return (FALSE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PALTEST(filemapping_memmgt_GetModuleFileNameA_test1_paltest_getmodulefilenamea_t


//load a module
ModuleHandle = LoadLibrary(ModuleName);
ModuleHandle = LoadLibraryExA(ModuleName, NULL, 0);
if(!ModuleHandle)
{
Fail("Failed to call LoadLibrary API!\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PALTEST(filemapping_memmgt_GetModuleFileNameW_test1_paltest_getmodulefilenamew_t
lpModuleName = convert(ModuleName);

//load a module
ModuleHandle = LoadLibrary(lpModuleName);
ModuleHandle = LoadLibraryExW(lpModuleName, NULL, 0);

//free the memory
free(lpModuleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
** Source: test1.c (filemapping_memmgt\getprocaddress\test1)
**
** Purpose: Positive test the GetProcAddress API.
** The first test calls GetProcAddress to retrieve the
** address of SimpleFunction inside testlib by its name,
** then calls the function and checks that it worked.
** The first test calls GetProcAddress to retrieve the
** address of SimpleFunction inside testlib by its name,
** then calls the function and checks that it worked.
**
**
**===========================================================================*/
Expand Down Expand Up @@ -43,7 +43,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test1_paltest_getprocaddress_test1, "f


/* load a module */
hModule = LoadLibrary(lpModuleName);
hModule = LoadLibraryExA(lpModuleName, NULL, 0);
if(!hModule)
{
Fail("Unexpected error: "
Expand All @@ -54,7 +54,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test1_paltest_getprocaddress_test1, "f
/*
* Test 1
*
* Get the address of a function
* Get the address of a function
*/
procAddressByName = (SIMPLEFUNCTION) GetProcAddress(hModule,FunctionName);
if(!procAddressByName)
Expand All @@ -67,7 +67,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test1_paltest_getprocaddress_test1, "f
err = FreeLibrary(hModule);
if(0 == err)
{
Fail("Unexpected error: Failed to FreeLibrary %s\n",
Fail("Unexpected error: Failed to FreeLibrary %s\n",
lpModuleName);
}
Fail("");
Expand All @@ -76,14 +76,14 @@ PALTEST(filemapping_memmgt_GetProcAddress_test1_paltest_getprocaddress_test1, "f
/* Call the function to see that it really worked */
/* Simple function adds 1 to the argument passed */
if( 2 != ((procAddressByName)(1)))
{
{
Trace("ERROR: Problem calling the function by its address.\n");

/* Cleanup */
err = FreeLibrary(hModule);
if(0 == err)
{
Fail("Unexpected error: Failed to FreeLibrary %s\n",
Fail("Unexpected error: Failed to FreeLibrary %s\n",
lpModuleName);
}
Fail("");
Expand All @@ -93,7 +93,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test1_paltest_getprocaddress_test1, "f
err = FreeLibrary(hModule);
if(0 == err)
{
Fail("Unexpected error: Failed to FreeLibrary %s\n",
Fail("Unexpected error: Failed to FreeLibrary %s\n",
lpModuleName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
** Source: test2.c (filemapping_memmgt\getprocaddress\test2)
**
** Purpose: This test tries to call GetProcAddress with
** a NULL handle, with a NULL function name, with an empty
** function name, with an invalid name and with an
** a NULL handle, with a NULL function name, with an empty
** function name, with an invalid name and with an
** invalid ordinal value.
**
**
Expand Down Expand Up @@ -39,7 +39,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test2_paltest_getprocaddress_test2, "f
}

/* load a module */
hModule = LoadLibrary(lpModuleName);
hModule = LoadLibraryExA(lpModuleName, NULL, 0);
if(!hModule)
{
Fail("Unexpected error: "
Expand All @@ -63,7 +63,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test2_paltest_getprocaddress_test2, "f
err = FreeLibrary(hModule);
if(0 == err)
{
Fail("Unexpected error: Failed to FreeLibrary %s\n",
Fail("Unexpected error: Failed to FreeLibrary %s\n",
lpModuleName);
}
Fail("");
Expand All @@ -86,7 +86,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test2_paltest_getprocaddress_test2, "f
err = FreeLibrary(hModule);
if(0 == err)
{
Fail("Unexpected error: Failed to FreeLibrary %s\n",
Fail("Unexpected error: Failed to FreeLibrary %s\n",
lpModuleName);
}
Fail("");
Expand All @@ -109,7 +109,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test2_paltest_getprocaddress_test2, "f
err = FreeLibrary(hModule);
if(0 == err)
{
Fail("Unexpected error: Failed to FreeLibrary %s\n",
Fail("Unexpected error: Failed to FreeLibrary %s\n",
lpModuleName);
}
Fail("");
Expand All @@ -132,7 +132,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test2_paltest_getprocaddress_test2, "f
err = FreeLibrary(hModule);
if(0 == err)
{
Fail("Unexpected error: Failed to FreeLibrary %s\n",
Fail("Unexpected error: Failed to FreeLibrary %s\n",
lpModuleName);
}
Fail("");
Expand All @@ -142,7 +142,7 @@ PALTEST(filemapping_memmgt_GetProcAddress_test2_paltest_getprocaddress_test2, "f
err = FreeLibrary(hModule);
if(0 == err)
{
Fail("Unexpected error: Failed to FreeLibrary %s\n",
Fail("Unexpected error: Failed to FreeLibrary %s\n",
lpModuleName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** Source: loadlibrarya.c
**
** Purpose: Positive test the LoadLibrary API.
** Call LoadLibrary to map a module into the calling
** Call LoadLibrary to map a module into the calling
** process address space(DLL file)
**
**
Expand Down Expand Up @@ -34,7 +34,7 @@ PALTEST(loader_LoadLibraryA_test1_paltest_loadlibrarya_test1, "loader/LoadLibrar
}

/* load a module */
ModuleHandle = LoadLibrary(ModuleName);
ModuleHandle = LoadLibraryExA(ModuleName, NULL, 0);
if(!ModuleHandle)
{
Fail("Failed to call LoadLibrary API!\n");
Expand Down
Loading