Merge pull request #10555 from akallabeth/cast-fix-tls

[crypto,tls] simplify function pointer cast
This commit is contained in:
akallabeth 2024-09-05 17:18:27 +02:00 committed by GitHub
commit 749023bacb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
39 changed files with 195 additions and 245 deletions

View File

@ -811,14 +811,10 @@ static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin, const char* name, cons
FREERDP_AUDIN_DEVICE_ENTRY_POINTS entryPoints = { 0 };
UINT error = ERROR_INTERNAL_ERROR;
union
{
PVIRTUALCHANNELENTRY pvce;
PFREERDP_AUDIN_DEVICE_ENTRY entry;
} cnv;
cnv.pvce = freerdp_load_channel_addin_entry(AUDIN_CHANNEL_NAME, name, NULL, 0);
PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry(AUDIN_CHANNEL_NAME, name, NULL, 0);
PFREERDP_AUDIN_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_AUDIN_DEVICE_ENTRY);
if (cnv.entry == NULL)
if (entry == NULL)
{
WLog_Print(audin->log, WLOG_ERROR,
"freerdp_load_channel_addin_entry did not return any function pointers for %s ",
@ -831,7 +827,7 @@ static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin, const char* name, cons
entryPoints.args = args;
entryPoints.rdpcontext = audin->rdpcontext;
error = cnv.entry(&entryPoints);
error = entry(&entryPoints);
if (error)
{
WLog_Print(audin->log, WLOG_ERROR, "%s entry returned error %" PRIu32 ".", name, error);

View File

@ -52,16 +52,9 @@ static void* freerdp_channels_find_static_entry_in_table(const STATIC_ENTRY_TABL
while (pEntry->entry != NULL)
{
static_entry_fn_t fkt = pEntry->entry;
if (strcmp(pEntry->name, identifier) == 0)
{
union
{
void* pv;
static_entry_fn_t entry;
} cnv;
cnv.entry = pEntry->entry;
return cnv.pv;
}
return WINPR_FUNC_PTR_CAST(fkt, void*);
pEntry = &table->table.cse[index++];
}
@ -494,15 +487,15 @@ PVIRTUALCHANNELENTRY freerdp_channels_load_static_addin_entry(LPCSTR pszName, LP
0) || /* we only want to know if strnlen is > 0 */
(strncmp(subsystems->name, pszSubsystem, MAX_PATH) == 0))
{
static_subsystem_entry_fn_t fkt = subsystems->entry;
if (pszType)
{
if (strncmp(subsystems->type, pszType, MAX_PATH) == 0)
return (PVIRTUALCHANNELENTRY)subsystems->entry;
return WINPR_FUNC_PTR_CAST(fkt, PVIRTUALCHANNELENTRY);
}
else
{
return (PVIRTUALCHANNELENTRY)subsystems->entry;
}
return WINPR_FUNC_PTR_CAST(fkt, PVIRTUALCHANNELENTRY);
}
}
}

View File

@ -359,15 +359,11 @@ static UINT dvcman_load_addin(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager*
WLog_Print(drdynvc->log, WLOG_INFO, "Loading Dynamic Virtual Channel %s", args->argv[0]);
union
{
PVIRTUALCHANNELENTRY pvce;
PDVC_PLUGIN_ENTRY pDVCPluginEntry;
} cnv;
cnv.pvce =
PVIRTUALCHANNELENTRY pvce =
freerdp_load_channel_addin_entry(args->argv[0], NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC);
PDVC_PLUGIN_ENTRY pDVCPluginEntry = WINPR_FUNC_PTR_CAST(pvce, PDVC_PLUGIN_ENTRY);
if (cnv.pDVCPluginEntry)
if (pDVCPluginEntry)
{
DVCMAN_ENTRY_POINTS entryPoints = { 0 };
@ -379,7 +375,7 @@ static UINT dvcman_load_addin(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager*
entryPoints.dvcman = (DVCMAN*)pChannelMgr;
entryPoints.args = args;
entryPoints.context = context;
return cnv.pDVCPluginEntry(&entryPoints.iface);
return pDVCPluginEntry(&entryPoints.iface);
}
return ERROR_INVALID_FUNCTION;

View File

@ -1049,18 +1049,13 @@ error_out:
static rdpPrinterDriver* printer_load_backend(const char* backend)
{
typedef UINT (*backend_load_t)(rdpPrinterDriver**);
union
{
PVIRTUALCHANNELENTRY entry;
backend_load_t backend;
} fktconv;
fktconv.entry = freerdp_load_channel_addin_entry("printer", backend, NULL, 0);
if (!fktconv.entry)
PVIRTUALCHANNELENTRY entry = freerdp_load_channel_addin_entry("printer", backend, NULL, 0);
backend_load_t func = WINPR_FUNC_PTR_CAST(entry, backend_load_t);
if (!func)
return NULL;
rdpPrinterDriver* printer = NULL;
const UINT rc = fktconv.backend(&printer);
const UINT rc = func(&printer);
if (rc != CHANNEL_RC_OK)
return NULL;

View File

@ -187,11 +187,6 @@ UINT devman_load_device_service(DEVMAN* devman, const RDPDR_DEVICE* device, rdpC
const char* ServiceName = NULL;
DEVICE_SERVICE_ENTRY_POINTS ep = { 0 };
union
{
PVIRTUALCHANNELENTRY pvce;
PDEVICE_SERVICE_ENTRY entry;
} cnv;
union
{
const RDPDR_DEVICE* cdp;
RDPDR_DEVICE* dp;
@ -223,9 +218,11 @@ UINT devman_load_device_service(DEVMAN* devman, const RDPDR_DEVICE* device, rdpC
else
WLog_INFO(TAG, "Loading device service %s (static)", ServiceName);
cnv.pvce = freerdp_load_channel_addin_entry(ServiceName, NULL, "DeviceServiceEntry", 0);
PVIRTUALCHANNELENTRY pvce =
freerdp_load_channel_addin_entry(ServiceName, NULL, "DeviceServiceEntry", 0);
PDEVICE_SERVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PDEVICE_SERVICE_ENTRY);
if (!cnv.entry)
if (!entry)
{
WLog_INFO(TAG, "freerdp_load_channel_addin_entry failed!");
return ERROR_INTERNAL_ERROR;
@ -235,5 +232,5 @@ UINT devman_load_device_service(DEVMAN* devman, const RDPDR_DEVICE* device, rdpC
ep.RegisterDevice = devman_register_device;
ep.device = devconv.dp;
ep.rdpcontext = rdpcontext;
return cnv.entry(&ep);
return entry(&ep);
}

View File

@ -848,27 +848,23 @@ static void rdpsnd_register_device_plugin(rdpsndPlugin* rdpsnd, rdpsndDevicePlug
static UINT rdpsnd_load_device_plugin(rdpsndPlugin* rdpsnd, const char* name,
const ADDIN_ARGV* args)
{
union
{
PVIRTUALCHANNELENTRY pvce;
PFREERDP_RDPSND_DEVICE_ENTRY entry;
} cnv;
FREERDP_RDPSND_DEVICE_ENTRY_POINTS entryPoints = { 0 };
UINT error = 0;
DWORD flags = FREERDP_ADDIN_CHANNEL_STATIC | FREERDP_ADDIN_CHANNEL_ENTRYEX;
if (rdpsnd->dynamic)
flags = FREERDP_ADDIN_CHANNEL_DYNAMIC;
cnv.pvce = freerdp_load_channel_addin_entry(RDPSND_CHANNEL_NAME, name, NULL, flags);
PVIRTUALCHANNELENTRY pvce =
freerdp_load_channel_addin_entry(RDPSND_CHANNEL_NAME, name, NULL, flags);
PFREERDP_RDPSND_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_RDPSND_DEVICE_ENTRY);
if (!cnv.entry)
if (!entry)
return ERROR_INTERNAL_ERROR;
entryPoints.rdpsnd = rdpsnd;
entryPoints.pRegisterRdpsndDevice = rdpsnd_register_device_plugin;
entryPoints.args = args;
error = cnv.entry(&entryPoints);
error = entry(&entryPoints);
if (error)
WLog_ERR(TAG, "%s %s entry returns error %" PRIu32 "", rdpsnd_is_dyn_str(rdpsnd->dynamic),
name, error);

View File

@ -770,21 +770,19 @@ static UINT urbdrc_load_udevman_addin(IWTSPlugin* pPlugin, LPCSTR name, const AD
{
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin;
FREERDP_URBDRC_SERVICE_ENTRY_POINTS entryPoints = { 0 };
union
{
PVIRTUALCHANNELENTRY pvce;
PFREERDP_URBDRC_DEVICE_ENTRY entry;
} cnv;
cnv.pvce = freerdp_load_channel_addin_entry(URBDRC_CHANNEL_NAME, name, NULL, 0);
if (!cnv.entry)
PVIRTUALCHANNELENTRY pvce =
freerdp_load_channel_addin_entry(URBDRC_CHANNEL_NAME, name, NULL, 0);
PFREERDP_URBDRC_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_URBDRC_DEVICE_ENTRY);
if (!entry)
return ERROR_INVALID_OPERATION;
entryPoints.plugin = pPlugin;
entryPoints.pRegisterUDEVMAN = urbdrc_register_udevman_addin;
entryPoints.args = args;
const UINT error = cnv.entry(&entryPoints);
const UINT error = entry(&entryPoints);
if (error)
{
WLog_Print(urbdrc->log, WLOG_ERROR, "%s entry returns error.", name);

View File

@ -22,6 +22,7 @@
#include <freerdp/config.h>
#include <winpr/windows.h>
#include <winpr/library.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
@ -1396,9 +1397,9 @@ static int wfreerdp_client_start(rdpContext* context)
if (module)
{
GetDpiForWindow_t pGetDpiForWindow =
(GetDpiForWindow_t)GetProcAddress(module, "GetDpiForWindow");
GetProcAddressAs(module, "GetDpiForWindow", GetDpiForWindow_t);
SetProcessDPIAware_t pSetProcessDPIAware =
(SetProcessDPIAware_t)GetProcAddress(module, "SetProcessDPIAware");
GetProcAddressAs(module, "SetProcessDPIAware", SetProcessDPIAware_t);
if (pGetDpiForWindow && pSetProcessDPIAware)
{
const UINT dpiAwareness = pGetDpiForWindow(hWndParent);

View File

@ -31,6 +31,7 @@
#include <winuser.h>
#include <winpr/assert.h>
#include <winpr/library.h>
#include <winpr/crt.h>
#include <winpr/tchar.h>
@ -2473,12 +2474,12 @@ BOOL wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr)
if (clipboard->hUser32)
{
clipboard->AddClipboardFormatListener = (fnAddClipboardFormatListener)GetProcAddress(
clipboard->hUser32, "AddClipboardFormatListener");
clipboard->RemoveClipboardFormatListener = (fnRemoveClipboardFormatListener)GetProcAddress(
clipboard->hUser32, "RemoveClipboardFormatListener");
clipboard->GetUpdatedClipboardFormats = (fnGetUpdatedClipboardFormats)GetProcAddress(
clipboard->hUser32, "GetUpdatedClipboardFormats");
clipboard->AddClipboardFormatListener = GetProcAddressAs(
clipboard->hUser32, "AddClipboardFormatListener", fnAddClipboardFormatListener);
clipboard->RemoveClipboardFormatListener = GetProcAddressAs(
clipboard->hUser32, "RemoveClipboardFormatListener", fnRemoveClipboardFormatListener);
clipboard->GetUpdatedClipboardFormats = GetProcAddressAs(
clipboard->hUser32, "GetUpdatedClipboardFormats", fnGetUpdatedClipboardFormats);
}
if (!(clipboard->hUser32 && clipboard->AddClipboardFormatListener &&

View File

@ -1311,17 +1311,12 @@ static DWORD WINAPI xf_handle_pipe(void* arg)
return 0;
}
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_QUALIFIERS
freerdp_add_signal_cleanup_handler(pipe, cleanup_pipe);
WINPR_PRAGMA_DIAG_POP
void* ctx = WINPR_CAST_CONST_PTR_AWAY(pipe, void*);
freerdp_add_signal_cleanup_handler(ctx, cleanup_pipe);
xf_process_pipe(context, pipe);
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_QUALIFIERS
freerdp_del_signal_cleanup_handler(pipe, cleanup_pipe);
WINPR_PRAGMA_DIAG_POP
freerdp_del_signal_cleanup_handler(ctx, cleanup_pipe);
unlink(pipe);
return 0;

View File

@ -5716,22 +5716,17 @@ fail:
static BOOL freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpSettings* settings,
const char* name, void* data)
{
union
{
PVIRTUALCHANNELENTRY pvce;
PVIRTUALCHANNELENTRYEX pvceex;
} cnv;
PVIRTUALCHANNELENTRY entry = NULL;
cnv.pvce = freerdp_load_channel_addin_entry(
PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry(
name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC | FREERDP_ADDIN_CHANNEL_ENTRYEX);
PVIRTUALCHANNELENTRYEX pvceex = WINPR_FUNC_PTR_CAST(pvce, PVIRTUALCHANNELENTRYEX);
if (!cnv.pvceex)
if (!pvceex)
entry = freerdp_load_channel_addin_entry(name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC);
if (cnv.pvceex)
if (pvceex)
{
if (freerdp_channels_client_load_ex(channels, settings, cnv.pvceex, data) == 0)
if (freerdp_channels_client_load_ex(channels, settings, pvceex, data) == 0)
{
WLog_DBG(TAG, "loading channelEx %s", name);
return TRUE;

View File

@ -17,6 +17,7 @@
* limitations under the License.
*/
#include <winpr/winpr.h>
#include <freerdp/log.h>
#include <freerdp/codec/h264.h>
@ -466,12 +467,13 @@ static BOOL mf_init(H264_CONTEXT* h264)
if (!sys->mfplat)
goto error;
sys->MFStartup = (pfnMFStartup)GetProcAddress(sys->mfplat, "MFStartup");
sys->MFShutdown = (pfnMFShutdown)GetProcAddress(sys->mfplat, "MFShutdown");
sys->MFCreateSample = (pfnMFCreateSample)GetProcAddress(sys->mfplat, "MFCreateSample");
sys->MFStartup = GetProcAddressAs(sys->mfplat, "MFStartup", pfnMFStartup);
sys->MFShutdown = GetProcAddressAs(sys->mfplat, "MFShutdown", pfnMFShutdown);
sys->MFCreateSample = GetProcAddressAs(sys->mfplat, "MFCreateSample", pfnMFCreateSample);
sys->MFCreateMemoryBuffer =
(pfnMFCreateMemoryBuffer)GetProcAddress(sys->mfplat, "MFCreateMemoryBuffer");
sys->MFCreateMediaType = (pfnMFCreateMediaType)GetProcAddress(sys->mfplat, "MFCreateMediaType");
GetProcAddressAs(sys->mfplat, "MFCreateMemoryBuffer", pfnMFCreateMemoryBuffer);
sys->MFCreateMediaType =
GetProcAddressAs(sys->mfplat, "MFCreateMediaType", pfnMFCreateMediaType);
if (!mf_plat_loaded(sys))
goto error;

View File

@ -467,15 +467,15 @@ static BOOL openh264_load_functionpointers(H264_CONTEXT* h264, const char* name)
return FALSE;
sysContexts->WelsGetCodecVersionEx =
(pWelsGetCodecVersionEx)GetProcAddress(sysContexts->lib, "WelsGetCodecVersionEx");
GetProcAddressAs(sysContexts->lib, "WelsGetCodecVersionEx", pWelsGetCodecVersionEx);
sysContexts->WelsCreateDecoder =
(pWelsCreateDecoder)GetProcAddress(sysContexts->lib, "WelsCreateDecoder");
GetProcAddressAs(sysContexts->lib, "WelsCreateDecoder", pWelsCreateDecoder);
sysContexts->WelsDestroyDecoder =
(pWelsDestroyDecoder)GetProcAddress(sysContexts->lib, "WelsDestroyDecoder");
GetProcAddressAs(sysContexts->lib, "WelsDestroyDecoder", pWelsDestroyDecoder);
sysContexts->WelsCreateSVCEncoder =
(pWelsCreateSVCEncoder)GetProcAddress(sysContexts->lib, "WelsCreateSVCEncoder");
GetProcAddressAs(sysContexts->lib, "WelsCreateSVCEncoder", pWelsCreateSVCEncoder);
sysContexts->WelsDestroySVCEncoder =
(pWelsDestroySVCEncoder)GetProcAddress(sysContexts->lib, "WelsDestroySVCEncoder");
GetProcAddressAs(sysContexts->lib, "WelsDestroySVCEncoder", pWelsDestroySVCEncoder);
if (!sysContexts->WelsCreateDecoder || !sysContexts->WelsDestroyDecoder ||
!sysContexts->WelsCreateSVCEncoder || !sysContexts->WelsDestroySVCEncoder ||

View File

@ -237,13 +237,7 @@ PVIRTUALCHANNELENTRY freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPa
if (!library)
goto fail;
union
{
FARPROC fp;
PVIRTUALCHANNELENTRY entry;
} cnv;
cnv.fp = GetProcAddress(library, pszEntryName);
entry = cnv.entry;
entry = GetProcAddressAs(library, pszEntryName, PVIRTUALCHANNELENTRY);
fail:
free(pszRelativeFilePath);
free(pszAddinFile);

View File

@ -470,19 +470,15 @@ static BOOL createChildSessionTransport(HANDLE* pFile)
WCHAR pipePath[0x80] = { 0 };
char pipePathA[0x80] = { 0 };
union
{
FARPROC fp;
WinStationCreateChildSessionTransportFn createChildSessionFn;
} cnv;
cnv.fp = GetProcAddress(hModule, "WinStationCreateChildSessionTransport");
if (!cnv.createChildSessionFn)
WinStationCreateChildSessionTransportFn createChildSessionFn = GetProcAddressAs(
hModule, "WinStationCreateChildSessionTransport", WinStationCreateChildSessionTransportFn);
if (!createChildSessionFn)
{
WLog_ERR(TAG, "unable to retrieve WinStationCreateChildSessionTransport function");
goto out;
}
HRESULT hStatus = cnv.createChildSessionFn(pipePath, 0x80);
HRESULT hStatus = createChildSessionFn(pipePath, 0x80);
if (!SUCCEEDED(hStatus))
{
WLog_ERR(TAG, "error 0x%x when creating childSessionTransport", hStatus);

View File

@ -814,20 +814,16 @@ static SecurityFunctionTable* auth_resolve_sspi_table(const rdpSettings* setting
WLog_INFO(TAG, "Using SSPI Module: %s", module_name);
union
{
FARPROC fp;
INIT_SECURITY_INTERFACE InitSecurityInterface_ptr;
} cnv;
cnv.fp = GetProcAddress(hSSPI, proc_name);
if (!cnv.InitSecurityInterface_ptr)
INIT_SECURITY_INTERFACE InitSecurityInterface_ptr =
GetProcAddressAs(hSSPI, proc_name, INIT_SECURITY_INTERFACE);
if (!InitSecurityInterface_ptr)
{
WLog_ERR(TAG, "Failed to load SSPI module: %s, no function %s", module_name, proc_name);
free(sspi_module);
return FALSE;
}
free(sspi_module);
return cnv.InitSecurityInterface_ptr();
return InitSecurityInterface_ptr();
}
return InitSecurityInterfaceEx(0);

View File

@ -313,16 +313,10 @@ static long bio_rdp_tls_ctrl(BIO* bio, int cmd, long num, void* ptr)
* we get a function pointer returned and have to cast it to ULONG_PTR
* to return the value to the caller.
*
* This, of course, is something compilers warn about. So silence it by casting
* by the means of a union */
* This, of course, is something compilers warn about. So silence it by casting */
{
union
{
void (*fkt)(const SSL*, int, int);
ULONG_PTR uptr;
} cnv;
cnv.fkt = SSL_get_info_callback(tls->ssl);
*((ULONG_PTR*)ptr) = cnv.uptr;
void* vptr = (void*)SSL_get_info_callback(tls->ssl);
*((void**)ptr) = vptr;
status = 1;
}
break;
@ -545,17 +539,13 @@ static long bio_rdp_tls_callback_ctrl(BIO* bio, int cmd, bio_info_cb* fp)
case BIO_CTRL_SET_CALLBACK:
{
typedef void (*fkt_t)(const SSL*, int, int);
/* Documented since https://www.openssl.org/docs/man1.1.1/man3/BIO_set_callback.html
* the argument is not really of type bio_info_cb* and must be cast
* to the required type */
union
{
fkt_t fkt;
bio_info_cb* fp;
} cnv;
cnv.fp = fp;
SSL_set_info_callback(tls->ssl, cnv.fkt);
fkt_t fkt = WINPR_FUNC_PTR_CAST(fp, fkt_t);
SSL_set_info_callback(tls->ssl, fkt);
status = 1;
}
break;

View File

@ -377,8 +377,7 @@ void primitives_init_copy(primitives_t* prims)
/* Start with the default. */
prims->copy_8u = general_copy_8u;
prims->copy_8u_AC4r = general_copy_8u_AC4r;
/* This is just an alias with void* parameters */
prims->copy = (__copy_t)(prims->copy_8u);
prims->copy = WINPR_FUNC_PTR_CAST(prims->copy_8u, __copy_t);
prims->copy_no_overlap = generic_image_copy_no_overlap;
}

View File

@ -194,21 +194,15 @@ static BOOL freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpS
const char* name, void* data)
{
PVIRTUALCHANNELENTRY entry = NULL;
union
{
PVIRTUALCHANNELENTRY entry;
PVIRTUALCHANNELENTRYEX entryEx;
} cnv;
cnv.entry = freerdp_load_channel_addin_entry(
PVIRTUALCHANNELENTRY lentry = freerdp_load_channel_addin_entry(
name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC | FREERDP_ADDIN_CHANNEL_ENTRYEX);
if (!cnv.entryEx)
PVIRTUALCHANNELENTRYEX entryEx = WINPR_FUNC_PTR_CAST(lentry, PVIRTUALCHANNELENTRYEX);
if (!entryEx)
entry = freerdp_load_channel_addin_entry(name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC);
if (cnv.entryEx)
if (entryEx)
{
if (freerdp_channels_client_load_ex(channels, settings, cnv.entryEx, data) == 0)
if (freerdp_channels_client_load_ex(channels, settings, entryEx, data) == 0)
{
WLog_INFO(TAG, "loading channelEx %s", name);
return TRUE;

View File

@ -491,13 +491,9 @@ static BOOL pf_modules_load_module(const char* module_path, proxyModule* module,
return FALSE;
}
union
{
FARPROC fp;
proxyModuleEntryPoint pEntryPoint;
} cnv;
cnv.fp = GetProcAddress(handle, MODULE_ENTRY_POINT);
if (!cnv.pEntryPoint)
proxyModuleEntryPoint pEntryPoint =
GetProcAddressAs(handle, MODULE_ENTRY_POINT, proxyModuleEntryPoint);
if (!pEntryPoint)
{
WLog_ERR(TAG, "GetProcAddress failed while loading %s", module_path);
goto error;
@ -507,7 +503,7 @@ static BOOL pf_modules_load_module(const char* module_path, proxyModule* module,
WLog_ERR(TAG, "ArrayList_Append failed!");
goto error;
}
return pf_modules_add(module, cnv.pEntryPoint, userdata);
return pf_modules_add(module, pEntryPoint, userdata);
error:
FreeLibrary(handle);

View File

@ -20,6 +20,7 @@
#include <winpr/crt.h>
#include <winpr/print.h>
#include <winpr/library.h>
#include <freerdp/log.h>
#include "win_dxgi.h"
@ -288,7 +289,7 @@ static void win_shadow_d3d11_module_init()
if (!d3d11_module)
return;
pfnD3D11CreateDevice = (fnD3D11CreateDevice)GetProcAddress(d3d11_module, "D3D11CreateDevice");
pfnD3D11CreateDevice = GetProcAddressAs(d3d11_module, "D3D11CreateDevice", fnD3D11CreateDevice);
}
int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem)

View File

@ -85,6 +85,8 @@ extern "C"
}
#endif
#define GetProcAddressAs(module, name, type) WINPR_FUNC_PTR_CAST(GetProcAddress(module, name), type)
#if !defined(_WIN32) && !defined(__CYGWIN__)
#ifdef __cplusplus

View File

@ -136,4 +136,31 @@ WINPR_API const char* winpr_get_build_config(void);
#define WINPR_UNUSED(x) (void)(x)
#if defined(__GNUC__) || defined(__clang__)
#define WINPR_CAST_CONST_PTR_AWAY(ptr, dstType) \
({ \
union \
{ \
typeof(ptr) src; \
dstType dst; \
} cnv; \
cnv.src = ptr; \
cnv.dst; \
})
#define WINPR_FUNC_PTR_CAST(ptr, dstType) \
({ \
union \
{ \
typeof(ptr) src; \
dstType dst; \
} cnv; \
cnv.src = ptr; \
cnv.dst; \
})
#else
#define WINPR_CAST_CONST_PTR_AWAY(ptr, dstType) (dstType) ptr
#define WINPR_FUNC_PTR_CAST(ptr, dstType) (dstType)(uintptr_t) ptr
#endif
#endif /* WINPR_H */

View File

@ -230,17 +230,14 @@ BOOL winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, WINPR_MD_TYPE md, const void* key, siz
#if defined(WITH_OPENSSL)
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
const char* hash = winpr_md_type_to_string(md);
char* hash = WINPR_CAST_CONST_PTR_AWAY(winpr_md_type_to_string(md), char*);
if (!ctx->xhmac)
return FALSE;
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_QUALIFIERS
const char* param_name = OSSL_MAC_PARAM_DIGEST;
const OSSL_PARAM param[] = { OSSL_PARAM_construct_utf8_string(param_name, hash, 0),
OSSL_PARAM_construct_end() };
WINPR_PRAGMA_DIAG_POP
if (EVP_MAC_init(ctx->xhmac, key, keylen, param) == 1)
return TRUE;

View File

@ -47,13 +47,13 @@ int TestLibraryGetProcAddress(int argc, char* argv[])
return -1;
}
if (!(pFunctionA = (TEST_AB_FN)GetProcAddress(library, "FunctionA")))
if (!(pFunctionA = GetProcAddressAs(library, "FunctionA", TEST_AB_FN)))
{
printf("%s: GetProcAddress failure (FunctionA)\n", __func__);
return -1;
}
if (!(pFunctionB = (TEST_AB_FN)GetProcAddress(library, "FunctionB")))
if (!(pFunctionB = GetProcAddressAs(library, "FunctionB", TEST_AB_FN)))
{
printf("%s: GetProcAddress failure (FunctionB)\n", __func__);
return -1;

View File

@ -18,6 +18,7 @@
*/
#include <winpr/assert.h>
#include <winpr/library.h>
#include <winpr/ncrypt.h>
#ifndef _WIN32
@ -267,14 +268,13 @@ SECURITY_STATUS winpr_NCryptOpenStorageProviderEx(NCRYPT_PROV_HANDLE* phProvider
{
typedef SECURITY_STATUS (*NCryptOpenStorageProviderFn)(NCRYPT_PROV_HANDLE * phProvider,
LPCWSTR pszProviderName, DWORD dwFlags);
NCryptOpenStorageProviderFn ncryptOpenStorageProviderFn;
SECURITY_STATUS ret;
SECURITY_STATUS ret = NTE_PROV_DLL_NOT_FOUND;
HANDLE lib = LoadLibraryA("ncrypt.dll");
if (!lib)
return NTE_PROV_DLL_NOT_FOUND;
ncryptOpenStorageProviderFn =
(NCryptOpenStorageProviderFn)GetProcAddress(lib, "NCryptOpenStorageProvider");
NCryptOpenStorageProviderFn ncryptOpenStorageProviderFn =
GetProcAddressAs(lib, "NCryptOpenStorageProvider", NCryptOpenStorageProviderFn);
if (!ncryptOpenStorageProviderFn)
{
ret = NTE_PROV_DLL_NOT_FOUND;

View File

@ -1261,20 +1261,16 @@ SECURITY_STATUS NCryptOpenP11StorageProviderEx(NCRYPT_PROV_HANDLE* phProvider,
goto out_load_library;
}
union
{
FARPROC fp;
c_get_function_list_t c_get_function_list;
} cnv;
cnv.fp = GetProcAddress(library, "C_GetFunctionList");
c_get_function_list_t c_get_function_list =
GetProcAddressAs(library, "C_GetFunctionList", c_get_function_list_t);
if (!cnv.c_get_function_list)
if (!c_get_function_list)
{
status = NTE_PROV_TYPE_ENTRY_BAD;
goto out_load_library;
}
status = initialize_pkcs11(library, cnv.c_get_function_list, phProvider);
status = initialize_pkcs11(library, c_get_function_list, phProvider);
if (status != ERROR_SUCCESS)
{
status = NTE_PROVIDER_DLL_FAIL;

View File

@ -26,16 +26,16 @@
#ifdef WINPR_THREAD_POOL
#ifdef _WIN32
typedef BOOL(WINAPI* pCallbackMayRunLong_t)(PTP_CALLBACK_INSTANCE pci);
static INIT_ONCE init_once_module = INIT_ONCE_STATIC_INIT;
static BOOL(WINAPI* pCallbackMayRunLong)(PTP_CALLBACK_INSTANCE pci);
static pCallbackMayRunLong_t pCallbackMayRunLong = NULL;
static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context)
{
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
if (kernel32)
{
pCallbackMayRunLong = (void*)GetProcAddress(kernel32, "CallbackMayRunLong");
}
pCallbackMayRunLong =
GetProcAddressAs(kernel32, "CallbackMayRunLong", pCallbackMayRunLong_t);
return TRUE;
}
#endif

View File

@ -44,17 +44,17 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context)
if (kernel32)
{
pSetEventWhenCallbackReturns =
(void*)GetProcAddress(kernel32, "SetEventWhenCallbackReturns");
GetProcAddressAs(kernel32, "SetEventWhenCallbackReturns"), void*);
pReleaseSemaphoreWhenCallbackReturns =
(void*)GetProcAddress(kernel32, "ReleaseSemaphoreWhenCallbackReturns");
GetProcAddressAs(kernel32, "ReleaseSemaphoreWhenCallbackReturns", void*);
pReleaseMutexWhenCallbackReturns =
(void*)GetProcAddress(kernel32, "ReleaseMutexWhenCallbackReturns");
GetProcAddressAs(kernel32, "ReleaseMutexWhenCallbackReturns", void*);
pLeaveCriticalSectionWhenCallbackReturns =
(void*)GetProcAddress(kernel32, "LeaveCriticalSectionWhenCallbackReturns");
GetProcAddressAs(kernel32, "LeaveCriticalSectionWhenCallbackReturns", void*);
pFreeLibraryWhenCallbackReturns =
(void*)GetProcAddress(kernel32, "FreeLibraryWhenCallbackReturns");
GetProcAddressAs(kernel32, "FreeLibraryWhenCallbackReturns", void*);
pDisassociateCurrentThreadFromCallback =
(void*)GetProcAddress(kernel32, "DisassociateCurrentThreadFromCallback");
GetProcAddressAs(kernel32, "DisassociateCurrentThreadFromCallback", void*);
}
return TRUE;
}

View File

@ -19,6 +19,7 @@
#include <winpr/config.h>
#include <winpr/winpr.h>
#include <winpr/crt.h>
#include <winpr/pool.h>
#include <winpr/library.h>
@ -42,11 +43,11 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context)
if (kernel32)
{
pCreateThreadpoolCleanupGroup =
(void*)GetProcAddress(kernel32, "CreateThreadpoolCleanupGroup");
GetProcAddressAs(kernel32, "CreateThreadpoolCleanupGroup", void*);
pCloseThreadpoolCleanupGroupMembers =
(void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroupMembers");
GetProcAddressAs(kernel32, "CloseThreadpoolCleanupGroupMembers", void*);
pCloseThreadpoolCleanupGroup =
(void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroup");
GetProcAddressAs(kernel32, "CloseThreadpoolCleanupGroup", void*);
}
return TRUE;

View File

@ -40,10 +40,12 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context)
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
if (kernel32)
{
pCreateThreadpool = (void*)GetProcAddress(kernel32, "CreateThreadpool");
pCloseThreadpool = (void*)GetProcAddress(kernel32, "CloseThreadpool");
pSetThreadpoolThreadMinimum = (void*)GetProcAddress(kernel32, "SetThreadpoolThreadMinimum");
pSetThreadpoolThreadMaximum = (void*)GetProcAddress(kernel32, "SetThreadpoolThreadMaximum");
pCreateThreadpool = GetProcAddressAs(kernel32, "CreateThreadpool", void*);
pCloseThreadpool = GetProcAddressAs(kernel32, "CloseThreadpool", void*);
pSetThreadpoolThreadMinimum =
GetProcAddressAs(kernel32, "SetThreadpoolThreadMinimum", void*);
pSetThreadpoolThreadMaximum =
GetProcAddressAs(kernel32, "SetThreadpoolThreadMaximum", void*);
}
return TRUE;
}

View File

@ -46,13 +46,13 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context)
if (kernel32)
{
pCreateThreadpoolWork = (void*)GetProcAddress(kernel32, "CreateThreadpoolWork");
pCloseThreadpoolWork = (void*)GetProcAddress(kernel32, "CloseThreadpoolWork");
pSubmitThreadpoolWork = (void*)GetProcAddress(kernel32, "SubmitThreadpoolWork");
pCreateThreadpoolWork = GetProcAddressAs(kernel32, "CreateThreadpoolWork", void*);
pCloseThreadpoolWork = GetProcAddressAs(kernel32, "CloseThreadpoolWork", void*);
pSubmitThreadpoolWork = GetProcAddressAs(kernel32, "SubmitThreadpoolWork", void*);
pTrySubmitThreadpoolCallback =
(void*)GetProcAddress(kernel32, "TrySubmitThreadpoolCallback");
GetProcAddressAs(kernel32, "TrySubmitThreadpoolCallback", void*);
pWaitForThreadpoolWorkCallbacks =
(void*)GetProcAddress(kernel32, "WaitForThreadpoolWorkCallbacks");
GetProcAddressAs(kernel32, "WaitForThreadpoolWorkCallbacks", void*);
}
return TRUE;

View File

@ -1100,13 +1100,13 @@ WINSCARDAPI char* WINAPI SCardGetReaderStateString(DWORD dwReaderState)
return buffer;
}
#define WINSCARD_LOAD_PROC(_name, ...) \
do \
{ \
WINPR_PRAGMA_DIAG_PUSH \
WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \
pWinSCardApiTable->pfn##_name = (fn##_name)GetProcAddress(hWinSCardLibrary, #_name); \
WINPR_PRAGMA_DIAG_POP \
#define WINSCARD_LOAD_PROC(_name, ...) \
do \
{ \
WINPR_PRAGMA_DIAG_PUSH \
WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \
pWinSCardApiTable->pfn##_name = GetProcAddressAs(hWinSCardLibrary, #_name, fn##_name); \
WINPR_PRAGMA_DIAG_POP \
} while (0)
BOOL WinSCard_LoadApiTableFunctions(PSCardApiFunctionTable pWinSCardApiTable,

View File

@ -48,13 +48,13 @@
#include "../log.h"
#define TAG WINPR_TAG("smartcard")
#define WINSCARD_LOAD_PROC_EX(module, pcsc, _fname, _name, ...) \
do \
{ \
WINPR_PRAGMA_DIAG_PUSH \
WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \
pcsc.pfn##_fname = (fnPCSC##_fname)GetProcAddress(module, #_name); \
WINPR_PRAGMA_DIAG_POP \
#define WINSCARD_LOAD_PROC_EX(module, pcsc, _fname, _name, ...) \
do \
{ \
WINPR_PRAGMA_DIAG_PUSH \
WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \
pcsc.pfn##_fname = GetProcAddressAs(module, #_name, fnPCSC##_fname); \
WINPR_PRAGMA_DIAG_POP \
} while (0)
#define WINSCARD_LOAD_PROC(module, pcsc, _name, ...) \

View File

@ -108,9 +108,9 @@ BOOL InitializeSspiModule_Native(void)
return FALSE;
pInitSecurityInterfaceW =
(INIT_SECURITY_INTERFACE_W)GetProcAddress(g_SspiModule, "InitSecurityInterfaceW");
GetProcAddressAs(g_SspiModule, "InitSecurityInterfaceW", INIT_SECURITY_INTERFACE_W);
pInitSecurityInterfaceA =
(INIT_SECURITY_INTERFACE_A)GetProcAddress(g_SspiModule, "InitSecurityInterfaceA");
GetProcAddressAs(g_SspiModule, "InitSecurityInterfaceA", INIT_SECURITY_INTERFACE_A);
if (pInitSecurityInterfaceW)
{
@ -124,11 +124,11 @@ BOOL InitializeSspiModule_Native(void)
g_SspiW->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3;
g_SspiW->SetContextAttributesW =
(SET_CONTEXT_ATTRIBUTES_FN_W)GetProcAddress(g_SspiModule, "SetContextAttributesW");
g_SspiW->SetContextAttributesW = GetProcAddressAs(g_SspiModule, "SetContextAttributesW",
SET_CONTEXT_ATTRIBUTES_FN_W);
g_SspiW->SetCredentialsAttributesW = (SET_CREDENTIALS_ATTRIBUTES_FN_W)GetProcAddress(
g_SspiModule, "SetCredentialsAttributesW");
g_SspiW->SetCredentialsAttributesW = GetProcAddressAs(
g_SspiModule, "SetCredentialsAttributesW", SET_CREDENTIALS_ATTRIBUTES_FN_W);
}
}
@ -144,11 +144,11 @@ BOOL InitializeSspiModule_Native(void)
g_SspiA->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3;
g_SspiA->SetContextAttributesA =
(SET_CONTEXT_ATTRIBUTES_FN_W)GetProcAddress(g_SspiModule, "SetContextAttributesA");
g_SspiA->SetContextAttributesA = GetProcAddressAs(g_SspiModule, "SetContextAttributesA",
SET_CONTEXT_ATTRIBUTES_FN_W);
g_SspiA->SetCredentialsAttributesA = (SET_CREDENTIALS_ATTRIBUTES_FN_W)GetProcAddress(
g_SspiModule, "SetCredentialsAttributesA");
g_SspiA->SetCredentialsAttributesA = GetProcAddressAs(
g_SspiModule, "SetCredentialsAttributesA", SET_CREDENTIALS_ATTRIBUTES_FN_W);
}
}

View File

@ -67,14 +67,13 @@ static BOOL CALLBACK InitOnce_Barrier(PINIT_ONCE once, PVOID param, PVOID* conte
if (!g_Kernel32)
return TRUE;
pfnInitializeSynchronizationBarrier = (fnInitializeSynchronizationBarrier)GetProcAddress(
g_Kernel32, "InitializeSynchronizationBarrier");
pfnInitializeSynchronizationBarrier = GetProcAddressAs(
g_Kernel32, "InitializeSynchronizationBarrier", fnInitializeSynchronizationBarrier);
pfnEnterSynchronizationBarrier =
(fnEnterSynchronizationBarrier)GetProcAddress(g_Kernel32, "EnterSynchronizationBarrier");
pfnDeleteSynchronizationBarrier =
(fnDeleteSynchronizationBarrier)GetProcAddress(g_Kernel32, "DeleteSynchronizationBarrier");
GetProcAddressAs(g_Kernel32, "EnterSynchronizationBarrier", fnEnterSynchronizationBarrier);
pfnDeleteSynchronizationBarrier = GetProcAddressAs(g_Kernel32, "DeleteSynchronizationBarrier",
fnDeleteSynchronizationBarrier);
if (pfnInitializeSynchronizationBarrier && pfnEnterSynchronizationBarrier &&
pfnDeleteSynchronizationBarrier)

View File

@ -52,10 +52,10 @@ static WtsApiFunctionTable WtsApi32_WtsApiFunctionTable = { 0 };
#ifdef __MINGW32__
#define WTSAPI32_LOAD_PROC(NAME, TYPE) \
WtsApi32_WtsApiFunctionTable.p##NAME = (TYPE)GetProcAddress(g_WtsApi32Module, "WTS" #NAME);
WtsApi32_WtsApiFunctionTable.p##NAME = GetProcAddressAs(g_WtsApi32Module, "WTS" #NAME, TYPE);
#else
#define WTSAPI32_LOAD_PROC(NAME, TYPE) \
WtsApi32_WtsApiFunctionTable.p##NAME = (##TYPE)GetProcAddress(g_WtsApi32Module, "WTS" #NAME);
WtsApi32_WtsApiFunctionTable.p##NAME = GetProcAddressAs(g_WtsApi32Module, "WTS" #NAME, ##TYPE);
#endif
static BOOL WtsApi32_InitializeWtsApi(void)
@ -700,17 +700,12 @@ static BOOL LoadAndInitialize(char* library)
if (!g_WtsApiModule)
return FALSE;
union
{
FARPROC fp;
INIT_WTSAPI_FN pInitWtsApi;
} cnv;
cnv.fp = GetProcAddress(g_WtsApiModule, "InitWtsApi");
INIT_WTSAPI_FN pInitWtsApi = GetProcAddressAs(g_WtsApiModule, "InitWtsApi", INIT_WTSAPI_FN);
if (!cnv.pInitWtsApi)
if (!pInitWtsApi)
return FALSE;
g_WtsApi = cnv.pInitWtsApi();
g_WtsApi = pInitWtsApi();
return TRUE;
}

View File

@ -785,9 +785,9 @@ BOOL Win32_InitializeWinSta(PWtsApiFunctionTable pWtsApi)
return FALSE;
pfnWinStationVirtualOpen =
(fnWinStationVirtualOpen)GetProcAddress(g_WinStaModule, "WinStationVirtualOpen");
GetProcAddressAs(g_WinStaModule, "WinStationVirtualOpen", fnWinStationVirtualOpen);
pfnWinStationVirtualOpenEx =
(fnWinStationVirtualOpenEx)GetProcAddress(g_WinStaModule, "WinStationVirtualOpenEx");
GetProcAddressAs(g_WinStaModule, "WinStationVirtualOpenEx", fnWinStationVirtualOpenEx);
if (!pfnWinStationVirtualOpen | !pfnWinStationVirtualOpenEx)
return FALSE;

View File

@ -261,8 +261,9 @@ fallback:
return computerName;
}
static int command_line_pre_filter(MAKECERT_CONTEXT* context, int index, int argc, LPCSTR* argv)
static int command_line_pre_filter(void* pvctx, int index, int argc, LPSTR* argv)
{
MAKECERT_CONTEXT* context = pvctx;
if (!context || !argv || (index < 0) || (argc < 0))
return -1;
@ -299,8 +300,7 @@ static int makecert_context_parse_arguments(MAKECERT_CONTEXT* context,
CommandLineClearArgumentsA(args);
flags = COMMAND_LINE_SEPARATOR_SPACE | COMMAND_LINE_SIGIL_DASH;
status =
CommandLineParseArgumentsA(argc, argv, args, flags, context,
(COMMAND_LINE_PRE_FILTER_FN_A)command_line_pre_filter, NULL);
CommandLineParseArgumentsA(argc, argv, args, flags, context, command_line_pre_filter, NULL);
if (status & COMMAND_LINE_STATUS_PRINT_HELP)
{