[channels] fix function pointer casts

* Cast freerdp_load_channel_addin_entry return with a union (removes the
  incompatible function pointer cast warnings)
* Typedef function pointers in tables.h
This commit is contained in:
akallabeth
2024-09-03 11:23:02 +02:00
parent c851dfcb7f
commit ff62730419
3 changed files with 102 additions and 22 deletions

View File

@@ -59,19 +59,40 @@ foreach(STATIC_ENTRY ${CHANNEL_STATIC_CLIENT_ENTRIES})
endforeach()
endforeach()
set(CLIENT_STATIC_ENTRY_TABLES_LIST "${CLIENT_STATIC_ENTRY_TABLES_LIST}\nextern const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[];\nconst STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[] =\n{")
string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "\nextern const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[];\n")
string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[] =\n{")
foreach(STATIC_ENTRY ${CHANNEL_STATIC_CLIENT_ENTRIES})
set(CLIENT_STATIC_ENTRY_IMPORTS "${CLIENT_STATIC_ENTRY_IMPORTS}\n${${STATIC_ENTRY}_IMPORTS}")
set(CLIENT_STATIC_ENTRY_TABLES "${CLIENT_STATIC_ENTRY_TABLES}\nextern const STATIC_ENTRY CLIENT_${STATIC_ENTRY}_TABLE[];\nconst STATIC_ENTRY CLIENT_${STATIC_ENTRY}_TABLE[] =\n{")
set(CLIENT_STATIC_ENTRY_TABLES "${CLIENT_STATIC_ENTRY_TABLES}\n${${STATIC_ENTRY}_TABLE}")
set(CLIENT_STATIC_ENTRY_TABLES "${CLIENT_STATIC_ENTRY_TABLES}\n\t{ NULL, NULL }\n};")
set(CLIENT_STATIC_ENTRY_TABLES_LIST "${CLIENT_STATIC_ENTRY_TABLES_LIST}\n\t{ \"${STATIC_ENTRY}\", CLIENT_${STATIC_ENTRY}_TABLE },")
if(${STATIC_ENTRY} STREQUAL "VirtualChannelEntry")
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_VC")
set(CLIENT_STATIC_ENTRY_INITIALIZER ".csevc")
elseif(${STATIC_ENTRY} STREQUAL "VirtualChannelEntryEx")
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_VCEX")
set(CLIENT_STATIC_ENTRY_INITIALIZER ".csevcex")
elseif(${STATIC_ENTRY} MATCHES "DVCPluginEntry$")
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_DVC")
set(CLIENT_STATIC_ENTRY_INITIALIZER ".csedvc")
elseif(${STATIC_ENTRY} MATCHES "DeviceServiceEntry$")
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_DSE")
set(CLIENT_STATIC_ENTRY_INITIALIZER ".csedse")
else()
set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY")
set(CLIENT_STATIC_ENTRY_INITIALIZER ".cse")
endif()
string(APPEND CLIENT_STATIC_ENTRY_TABLES "\nextern const ${CLIENT_STATIC_ENTRY_TYPE} CLIENT_${STATIC_ENTRY}_TABLE[];\n")
string(APPEND CLIENT_STATIC_ENTRY_TABLES "const ${CLIENT_STATIC_ENTRY_TYPE} CLIENT_${STATIC_ENTRY}_TABLE[] =\n{")
string(APPEND CLIENT_STATIC_ENTRY_TABLES "\n${${STATIC_ENTRY}_TABLE}")
string(APPEND CLIENT_STATIC_ENTRY_TABLES "\n\t{ NULL, NULL }\n};")
string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "\n\t{ \"${STATIC_ENTRY}\", { ${CLIENT_STATIC_ENTRY_INITIALIZER} = CLIENT_${STATIC_ENTRY}_TABLE } },")
endforeach()
set(CLIENT_STATIC_ENTRY_TABLES_LIST "${CLIENT_STATIC_ENTRY_TABLES_LIST}\n\t{ NULL, NULL }\n};")
string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "\n\t{ NULL, { .cse = NULL } }\n};")
set(CLIENT_STATIC_ADDIN_TABLE "extern const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[];\n")
string(APPEND CLIENT_STATIC_ADDIN_TABLE "const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[] =\n{")
set(CLIENT_STATIC_ADDIN_TABLE "extern const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[];\nconst STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[] =\n{")
foreach(STATIC_MODULE ${CHANNEL_STATIC_CLIENT_MODULES})
set(STATIC_MODULE_NAME ${${STATIC_MODULE}_CLIENT_NAME})
set(STATIC_MODULE_CHANNEL ${${STATIC_MODULE}_CLIENT_CHANNEL})
@@ -91,24 +112,36 @@ foreach(STATIC_MODULE ${CHANNEL_STATIC_CLIENT_MODULES})
endif()
string(LENGTH "${STATIC_SUBSYSTEM_TYPE}" _type_length)
set(SUBSYSTEM_MODULE_NAME "${STATIC_MODULE_NAME}-${STATIC_SUBSYSTEM}")
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${SUBSYSTEM_MODULE_NAME})
list(APPEND ${MODULE_PREFIX}_LIBS ${SUBSYSTEM_MODULE_NAME})
if(_type_length GREATER 0)
set(STATIC_SUBSYSTEM_ENTRY "${STATIC_SUBSYSTEM_NAME}_freerdp_${STATIC_MODULE_CHANNEL}_client_${STATIC_SUBSYSTEM_TYPE}_subsystem_entry")
else()
set(STATIC_SUBSYSTEM_ENTRY "${STATIC_SUBSYSTEM_NAME}_freerdp_${STATIC_MODULE_CHANNEL}_client_subsystem_entry")
endif()
set(SUBSYSTEM_TABLE "${SUBSYSTEM_TABLE}\n\t{ \"${STATIC_SUBSYSTEM_NAME}\", \"${STATIC_SUBSYSTEM_TYPE}\", ${STATIC_SUBSYSTEM_ENTRY} },")
string(APPEND SUBSYSTEM_TABLE "\n\t{ \"${STATIC_SUBSYSTEM_NAME}\", \"${STATIC_SUBSYSTEM_TYPE}\", ${STATIC_SUBSYSTEM_ENTRY} },")
set(SUBSYSTEM_IMPORT "extern UINT VCAPITYPE ${STATIC_SUBSYSTEM_ENTRY}(void*);")
set(CLIENT_STATIC_SUBSYSTEM_IMPORTS "${CLIENT_STATIC_SUBSYSTEM_IMPORTS}\n${SUBSYSTEM_IMPORT}")
string(APPEND CLIENT_STATIC_SUBSYSTEM_IMPORTS "\n${SUBSYSTEM_IMPORT}")
endforeach()
set(SUBSYSTEM_TABLE "${SUBSYSTEM_TABLE}\n\t{ NULL, NULL, NULL }\n};")
set(CLIENT_STATIC_SUBSYSTEM_TABLES "${CLIENT_STATIC_SUBSYSTEM_TABLES}\n${SUBSYSTEM_TABLE}")
string(APPEND SUBSYSTEM_TABLE "\n\t{ NULL, NULL, NULL }\n};")
string(APPEND CLIENT_STATIC_SUBSYSTEM_TABLES "\n${SUBSYSTEM_TABLE}")
foreach(ENTRY ${${STATIC_MODULE}_CLIENT_ENTRY})
set (ENTRY_POINT_NAME ${STATIC_MODULE_CHANNEL}_${ENTRY})
set(CLIENT_STATIC_ADDIN_TABLE "${CLIENT_STATIC_ADDIN_TABLE}\n\t{ \"${STATIC_MODULE_CHANNEL}\", \"${ENTRY}\", ${ENTRY_POINT_NAME}, ${SUBSYSTEM_TABLE_NAME} },")
if(${ENTRY} STREQUAL "VirtualChannelEntry")
set(ENTRY_INITIALIZER ".csevc")
elseif(${ENTRY} STREQUAL "VirtualChannelEntryEx")
set(ENTRY_INITIALIZER ".csevcex")
elseif(${ENTRY} MATCHES "DVCPluginEntry$")
set(ENTRY_INITIALIZER ".csedvc")
elseif(${ENTRY} MATCHES "DeviceServiceEntry$")
set(ENTRY_INITIALIZER ".csedse")
else()
set(ENTRY_INITIALIZER ".cse")
endif()
string(APPEND CLIENT_STATIC_ADDIN_TABLE "\n\t{ \"${STATIC_MODULE_CHANNEL}\", \"${ENTRY}\", { ${ENTRY_INITIALIZER} = ${ENTRY_POINT_NAME} }, ${SUBSYSTEM_TABLE_NAME} },")
endforeach()
endforeach()
set(CLIENT_STATIC_ADDIN_TABLE "${CLIENT_STATIC_ADDIN_TABLE}\n\t{ NULL, NULL, NULL, NULL }\n};")
string(APPEND CLIENT_STATIC_ADDIN_TABLE "\n\t{ NULL, NULL, { .cse = NULL }, NULL }\n};")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tables.c.in ${CMAKE_CURRENT_BINARY_DIR}/tables.c)

View File

@@ -48,7 +48,7 @@ static void* freerdp_channels_find_static_entry_in_table(const STATIC_ENTRY_TABL
const char* identifier)
{
size_t index = 0;
const STATIC_ENTRY* pEntry = &table->table[index++];
const STATIC_ENTRY* pEntry = &table->table.cse[index++];
while (pEntry->entry != NULL)
{
@@ -63,7 +63,7 @@ static void* freerdp_channels_find_static_entry_in_table(const STATIC_ENTRY_TABL
return cnv.pv;
}
pEntry = &table->table[index++];
pEntry = &table->table.cse[index++];
}
return NULL;
@@ -74,7 +74,7 @@ void* freerdp_channels_client_find_static_entry(const char* name, const char* id
size_t index = 0;
const STATIC_ENTRY_TABLE* pEntry = &CLIENT_STATIC_ENTRY_TABLES[index++];
while (pEntry->table != NULL)
while (pEntry->table.cse != NULL)
{
if (strcmp(pEntry->name, name) == 0)
{
@@ -514,7 +514,7 @@ PVIRTUALCHANNELENTRY freerdp_channels_load_static_addin_entry(LPCSTR pszName, LP
return NULL;
}
return (PVIRTUALCHANNELENTRY)table->entry;
return table->entry.csevc;
}
}
}

View File

@@ -20,6 +20,8 @@
#include <winpr/platform.h>
#include <winpr/wtsapi.h>
#include <freerdp/svc.h>
#include <freerdp/dvc.h>
#include <freerdp/channels/rdpdr.h>
/* The 'entry' function pointers have variable arguments. */
WINPR_PRAGMA_DIAG_PUSH
@@ -32,13 +34,59 @@ typedef struct
static_entry_fn_t entry;
} STATIC_ENTRY;
typedef BOOL(VCAPITYPE* static_entry_vc_fn_t)(PCHANNEL_ENTRY_POINTS);
typedef struct
{
const char* name;
const STATIC_ENTRY* table;
static_entry_vc_fn_t entry;
} STATIC_ENTRY_VC;
typedef BOOL(VCAPITYPE* static_entry_vcex_fn_t)(PCHANNEL_ENTRY_POINTS, PVOID);
typedef struct
{
const char* name;
static_entry_vcex_fn_t entry;
} STATIC_ENTRY_VCEX;
typedef UINT(VCAPITYPE* static_entry_dvc_fn_t)(IDRDYNVC_ENTRY_POINTS*);
typedef struct
{
const char* name;
static_entry_dvc_fn_t entry;
} STATIC_ENTRY_DVC;
typedef UINT(VCAPITYPE* static_entry_dse_fn_t)(PDEVICE_SERVICE_ENTRY_POINTS);
typedef struct
{
const char* name;
static_entry_dse_fn_t entry;
} STATIC_ENTRY_DSE;
typedef union
{
const STATIC_ENTRY* cse;
const STATIC_ENTRY_VC* csevc;
const STATIC_ENTRY_VCEX* csevcex;
const STATIC_ENTRY_DVC* csedvc;
const STATIC_ENTRY_DSE* csedse;
} static_entry_u;
typedef union
{
static_entry_fn_t cse;
static_entry_vc_fn_t csevc;
static_entry_vcex_fn_t csevcex;
static_entry_dvc_fn_t csedvc;
static_entry_dse_fn_t csedse;
} static_entry_fn_u;
typedef struct
{
const char* name;
static_entry_u table;
} STATIC_ENTRY_TABLE;
typedef UINT(VCAPITYPE* static_subsystem_entry_fn_t)();
typedef UINT(VCAPITYPE* static_subsystem_entry_fn_t)(void*);
typedef struct
{
const char* name;
@@ -46,12 +94,11 @@ typedef struct
static_subsystem_entry_fn_t entry;
} STATIC_SUBSYSTEM_ENTRY;
typedef UINT(VCAPITYPE* static_addin_entry_fn_t)();
typedef struct
{
const char* name;
const char* type;
static_addin_entry_fn_t entry;
static_entry_fn_u entry;
const STATIC_SUBSYSTEM_ENTRY* table;
} STATIC_ADDIN_TABLE;