Show better error messages for when required symbols aren't found

This commit is contained in:
UnknownShadow200 2025-01-11 06:53:21 +11:00
parent 80957f9668
commit 5092b5ac7f
13 changed files with 74 additions and 61 deletions

View file

@ -17,10 +17,10 @@ CC_KERN32_FUNC void (NTAPI *_RtlCaptureContext)(CONTEXT* ContextRecord);
static void Kernel32_LoadDynamicFuncs(void) { static void Kernel32_LoadDynamicFuncs(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(AttachConsole), DynamicLib_OptSym(AttachConsole),
DynamicLib_Sym(IsDebuggerPresent), DynamicLib_OptSym(IsDebuggerPresent),
DynamicLib_Sym(GetSystemTimeAsFileTime), DynamicLib_OptSym(GetSystemTimeAsFileTime),
DynamicLib_Sym(RtlCaptureContext) DynamicLib_OptSym(RtlCaptureContext)
}; };
static const cc_string kernel32 = String_FromConst("KERNEL32.DLL"); static const cc_string kernel32 = String_FromConst("KERNEL32.DLL");

View file

@ -12,7 +12,7 @@ CC_CRYPT32_FUNC BOOL (WINAPI *_CryptUnprotectData)(DATA_BLOB* dataIn, PWSTR* dat
static void Crypt32_LoadDynamicFuncs(void) { static void Crypt32_LoadDynamicFuncs(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(CryptProtectData), DynamicLib_Sym(CryptUnprotectData) DynamicLib_OptSym(CryptProtectData), DynamicLib_OptSym(CryptUnprotectData)
}; };
static const cc_string crypt32 = String_FromConst("CRYPT32.DLL"); static const cc_string crypt32 = String_FromConst("CRYPT32.DLL");

View file

@ -147,14 +147,14 @@ CC_WINSOCK_FUNC void (WINAPI* _freeaddrinfo)(ADDRINFOA* addrInfo);
static void Winsock_LoadDynamicFuncs(void) { static void Winsock_LoadDynamicFuncs(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(WSAStartup), DynamicLib_Sym(WSACleanup), DynamicLib_ReqSym(WSAStartup), DynamicLib_ReqSym(WSACleanup),
DynamicLib_Sym(WSAGetLastError), DynamicLib_Sym(WSAStringToAddressW), DynamicLib_ReqSym(WSAGetLastError), DynamicLib_OptSym(WSAStringToAddressW),
DynamicLib_Sym(socket), DynamicLib_Sym(closesocket), DynamicLib_ReqSym(socket), DynamicLib_ReqSym(closesocket),
DynamicLib_Sym(connect), DynamicLib_Sym(shutdown), DynamicLib_ReqSym(connect), DynamicLib_ReqSym(shutdown),
DynamicLib_Sym(ioctlsocket), DynamicLib_Sym(getsockopt), DynamicLib_ReqSym(ioctlsocket), DynamicLib_ReqSym(getsockopt),
DynamicLib_Sym(gethostbyname), DynamicLib_Sym(htons), DynamicLib_ReqSym(gethostbyname), DynamicLib_ReqSym(htons),
DynamicLib_Sym(getaddrinfo), DynamicLib_Sym(freeaddrinfo), DynamicLib_OptSym(getaddrinfo), DynamicLib_OptSym(freeaddrinfo),
DynamicLib_Sym(recv), DynamicLib_Sym(send), DynamicLib_Sym(select) DynamicLib_ReqSym(recv), DynamicLib_ReqSym(send), DynamicLib_ReqSym(select)
}; };
static const cc_string winsock1 = String_FromConst("wsock32.DLL"); static const cc_string winsock1 = String_FromConst("wsock32.DLL");
static const cc_string winsock2 = String_FromConst("WS2_32.DLL"); static const cc_string winsock2 = String_FromConst("WS2_32.DLL");
@ -162,5 +162,5 @@ static void Winsock_LoadDynamicFuncs(void) {
DynamicLib_LoadAll(&winsock2, funcs, Array_Elems(funcs), &lib); DynamicLib_LoadAll(&winsock2, funcs, Array_Elems(funcs), &lib);
/* Windows 95 is missing WS2_32 dll */ /* Windows 95 is missing WS2_32 dll */
if (!_WSAStartup) DynamicLib_LoadAll(&winsock1, funcs, Array_Elems(funcs), &lib); if (!lib) DynamicLib_LoadAll(&winsock1, funcs, Array_Elems(funcs), &lib);
} }

View file

@ -47,9 +47,9 @@ CC_USER32_FUNC BOOL (WINAPI *_SetProcessDPIAware)(void);
static void User32_LoadDynamicFuncs(void) { static void User32_LoadDynamicFuncs(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(RegisterRawInputDevices), DynamicLib_OptSym(RegisterRawInputDevices),
DynamicLib_Sym(GetRawInputData), DynamicLib_OptSym(GetRawInputData),
DynamicLib_Sym(SetProcessDPIAware) DynamicLib_OptSym(SetProcessDPIAware)
}; };
static const cc_string user32 = String_FromConst("USER32.DLL"); static const cc_string user32 = String_FromConst("USER32.DLL");
void* lib; void* lib;

View file

@ -105,17 +105,17 @@ static const cc_string alLib = String_FromConst("libopenal.so.1");
static cc_bool LoadALFuncs(void) { static cc_bool LoadALFuncs(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(alcCreateContext), DynamicLib_Sym(alcMakeContextCurrent), DynamicLib_ReqSym(alcCreateContext), DynamicLib_ReqSym(alcMakeContextCurrent),
DynamicLib_Sym(alcDestroyContext), DynamicLib_Sym(alcOpenDevice), DynamicLib_ReqSym(alcDestroyContext), DynamicLib_ReqSym(alcOpenDevice),
DynamicLib_Sym(alcCloseDevice), DynamicLib_Sym(alcGetError), DynamicLib_ReqSym(alcCloseDevice), DynamicLib_ReqSym(alcGetError),
DynamicLib_Sym(alGetError), DynamicLib_ReqSym(alGetError),
DynamicLib_Sym(alGenSources), DynamicLib_Sym(alDeleteSources), DynamicLib_ReqSym(alGenSources), DynamicLib_ReqSym(alDeleteSources),
DynamicLib_Sym(alGetSourcei), DynamicLib_Sym(alSourcef), DynamicLib_ReqSym(alGetSourcei), DynamicLib_ReqSym(alSourcef),
DynamicLib_Sym(alSourcePlay), DynamicLib_Sym(alSourceStop), DynamicLib_ReqSym(alSourcePlay), DynamicLib_ReqSym(alSourceStop),
DynamicLib_Sym(alSourceQueueBuffers), DynamicLib_Sym(alSourceUnqueueBuffers), DynamicLib_ReqSym(alSourceQueueBuffers), DynamicLib_ReqSym(alSourceUnqueueBuffers),
DynamicLib_Sym(alGenBuffers), DynamicLib_Sym(alDeleteBuffers), DynamicLib_ReqSym(alGenBuffers), DynamicLib_ReqSym(alDeleteBuffers),
DynamicLib_Sym(alBufferData), DynamicLib_Sym(alDistanceModel) DynamicLib_ReqSym(alBufferData), DynamicLib_ReqSym(alDistanceModel)
}; };
void* lib; void* lib;
@ -499,10 +499,10 @@ static const cc_string slLib = String_FromConst("libOpenSLES.so");
static cc_bool LoadSLFuncs(void) { static cc_bool LoadSLFuncs(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(slCreateEngine), DynamicLib_Sym(SL_IID_NULL), DynamicLib_ReqSym(slCreateEngine), DynamicLib_ReqSym(SL_IID_NULL),
DynamicLib_Sym(SL_IID_PLAY), DynamicLib_Sym(SL_IID_ENGINE), DynamicLib_ReqSym(SL_IID_PLAY), DynamicLib_ReqSym(SL_IID_ENGINE),
DynamicLib_Sym(SL_IID_BUFFERQUEUE), DynamicLib_Sym(SL_IID_PLAYBACKRATE), DynamicLib_ReqSym(SL_IID_BUFFERQUEUE), DynamicLib_ReqSym(SL_IID_PLAYBACKRATE),
DynamicLib_Sym(SL_IID_VOLUME) DynamicLib_ReqSym(SL_IID_VOLUME)
}; };
void* lib; void* lib;

View file

@ -107,7 +107,7 @@ static PFN_D3D11_CREATE_DEVICE _D3D11CreateDevice;
static void LoadD3D11Library(void) { static void LoadD3D11Library(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(D3D11CreateDevice) DynamicLib_ReqSym(D3D11CreateDevice)
}; };
static const cc_string path = String_FromConst("d3d11.dll"); static const cc_string path = String_FromConst("d3d11.dll");
void* lib; void* lib;

View file

@ -53,7 +53,7 @@ static IDirect3D9* (WINAPI *_Direct3DCreate9)(UINT SDKVersion);
static void LoadD3D9Library(void) { static void LoadD3D9Library(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(Direct3DCreate9) DynamicLib_ReqSym(Direct3DCreate9)
}; };
static const cc_string path = String_FromConst("d3d9.dll"); static const cc_string path = String_FromConst("d3d9.dll");
void* lib; void* lib;

View file

@ -711,14 +711,14 @@ static void FallbackOpenGL(void) {
static void GLBackend_Init(void) { static void GLBackend_Init(void) {
static const struct DynamicLibSym coreVboFuncs[] = { static const struct DynamicLibSym coreVboFuncs[] = {
DynamicLib_Sym2("glBindBuffer", glBindBuffer), DynamicLib_Sym2("glDeleteBuffers", glDeleteBuffers), DynamicLib_ReqSym2("glBindBuffer", glBindBuffer), DynamicLib_ReqSym2("glDeleteBuffers", glDeleteBuffers),
DynamicLib_Sym2("glGenBuffers", glGenBuffers), DynamicLib_Sym2("glBufferData", glBufferData), DynamicLib_ReqSym2("glGenBuffers", glGenBuffers), DynamicLib_ReqSym2("glBufferData", glBufferData),
DynamicLib_Sym2("glBufferSubData", glBufferSubData) DynamicLib_ReqSym2("glBufferSubData", glBufferSubData)
}; };
static const struct DynamicLibSym arbVboFuncs[] = { static const struct DynamicLibSym arbVboFuncs[] = {
DynamicLib_Sym2("glBindBufferARB", glBindBuffer), DynamicLib_Sym2("glDeleteBuffersARB", glDeleteBuffers), DynamicLib_ReqSym2("glBindBufferARB", glBindBuffer), DynamicLib_ReqSym2("glDeleteBuffersARB", glDeleteBuffers),
DynamicLib_Sym2("glGenBuffersARB", glGenBuffers), DynamicLib_Sym2("glBufferDataARB", glBufferData), DynamicLib_ReqSym2("glGenBuffersARB", glGenBuffers), DynamicLib_ReqSym2("glBufferDataARB", glBufferData),
DynamicLib_Sym2("glBufferSubDataARB", glBufferSubData) DynamicLib_ReqSym2("glBufferSubDataARB", glBufferSubData)
}; };
static const cc_string vboExt = String_FromConst("GL_ARB_vertex_buffer_object"); static const cc_string vboExt = String_FromConst("GL_ARB_vertex_buffer_object");
cc_string extensions = String_FromReadonly((const char*)glGetString(GL_EXTENSIONS)); cc_string extensions = String_FromReadonly((const char*)glGetString(GL_EXTENSIONS));

View file

@ -204,15 +204,19 @@ static const cc_string curlAlt = String_FromConst("libcurl.so.3");
static cc_bool LoadCurlFuncs(void) { static cc_bool LoadCurlFuncs(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
#if !defined CC_BUILD_OS2 #if !defined CC_BUILD_OS2
DynamicLib_Sym(curl_global_init), DynamicLib_Sym(curl_global_cleanup), DynamicLib_ReqSym(curl_global_init), DynamicLib_ReqSym(curl_global_cleanup),
DynamicLib_Sym(curl_easy_init), DynamicLib_Sym(curl_easy_perform), DynamicLib_ReqSym(curl_easy_init), DynamicLib_ReqSym(curl_easy_perform),
DynamicLib_Sym(curl_easy_setopt), DynamicLib_Sym(curl_easy_cleanup), DynamicLib_ReqSym(curl_easy_setopt), DynamicLib_ReqSym(curl_easy_cleanup),
DynamicLib_Sym(curl_slist_free_all), DynamicLib_Sym(curl_slist_append) DynamicLib_ReqSym(curl_slist_free_all), DynamicLib_ReqSym(curl_slist_append),
/* Non-essential function missing in older curl versions */
DynamicLib_OptSym(curl_easy_strerror)
#else #else
DynamicLib_SymC(curl_global_init), DynamicLib_SymC(curl_global_cleanup), DynamicLib_ReqSymC(curl_global_init), DynamicLib_ReqSymC(curl_global_cleanup),
DynamicLib_SymC(curl_easy_init), DynamicLib_SymC(curl_easy_perform), DynamicLib_ReqSymC(curl_easy_init), DynamicLib_ReqSymC(curl_easy_perform),
DynamicLib_SymC(curl_easy_setopt), DynamicLib_SymC(curl_easy_cleanup), DynamicLib_ReqSymC(curl_easy_setopt), DynamicLib_ReqSymC(curl_easy_cleanup),
DynamicLib_SymC(curl_slist_free_all), DynamicLib_SymC(curl_slist_append) DynamicLib_ReqSymC(curl_slist_free_all), DynamicLib_ReqSymC(curl_slist_append),
/* Non-essential function missing in older curl versions */
DynamicLib_OptSymC(curl_easy_strerror)
#endif #endif
}; };
cc_bool success; cc_bool success;
@ -222,9 +226,6 @@ static cc_bool LoadCurlFuncs(void) {
if (!lib) { if (!lib) {
success = DynamicLib_LoadAll(&curlAlt, funcs, Array_Elems(funcs), &lib); success = DynamicLib_LoadAll(&curlAlt, funcs, Array_Elems(funcs), &lib);
} }
/* Non-essential function missing in older curl versions */
_curl_easy_strerror = DynamicLib_Get2(lib, "curl_easy_strerror");
return success; return success;
} }

View file

@ -128,18 +128,23 @@ CC_API cc_result DynamicLib_Load(const cc_string* path, void** lib); /* OBSOLETE
CC_API cc_result DynamicLib_Get(void* lib, const char* name, void** symbol); /* OBSOLETE */ CC_API cc_result DynamicLib_Get(void* lib, const char* name, void** symbol); /* OBSOLETE */
#define DYNAMICLIB_QUOTE(x) #x #define DYNAMICLIB_QUOTE(x) #x
#define DynamicLib_Sym(sym) { DYNAMICLIB_QUOTE(sym), (void**)&_ ## sym } #define DynamicLib_ReqSym(sym) { DYNAMICLIB_QUOTE(sym), (void**)&_ ## sym, true }
#define DynamicLib_Sym2(name, sym) { name, (void**)&_ ## sym } #define DynamicLib_OptSym(sym) { DYNAMICLIB_QUOTE(sym), (void**)&_ ## sym, false }
#define DynamicLib_ReqSym2(name, sym) { name, (void**)&_ ## sym, true }
#define DynamicLib_OptSym2(name, sym) { name, (void**)&_ ## sym, false }
#if defined CC_BUILD_OS2 #if defined CC_BUILD_OS2
#define DynamicLib_SymC(sym) { DYNAMICLIB_QUOTE(_ ## sym), (void**)&_ ## sym } #define DynamicLib_ReqSymC(sym) { DYNAMICLIB_QUOTE(_ ## sym), (void**)&_ ## sym, true }
#define DynamicLib_OptSymC(sym) { DYNAMICLIB_QUOTE(_ ## sym), (void**)&_ ## sym, false }
#endif #endif
/* Contains a name and a pointer to variable that will hold the loaded symbol */ /* Contains a name and a pointer to variable that will hold the loaded symbol */
/* static int (APIENTRY *_myGetError)(void); --- (for example) */ /* static int (APIENTRY *_myGetError)(void); --- (for example) */
/* static struct DynamicLibSym sym = { "myGetError", (void**)&_myGetError }; */ /* static struct DynamicLibSym sym = { "myGetError", (void**)&_myGetError, true }; */
struct DynamicLibSym { const char* name; void** symAddr; }; struct DynamicLibSym { const char* name; void** symAddr; cc_bool required; };
/* Loads all symbols using DynamicLib_Get2 in the given list */ /* Loads all symbols using DynamicLib_Get2 in the given list */
/* Returns true if all symbols were successfully retrieved */ /* Returns true if all required symbols were successfully retrieved */
cc_bool DynamicLib_LoadAll(const cc_string* path, const struct DynamicLibSym* syms, int count, void** lib); cc_bool DynamicLib_LoadAll(const cc_string* path, const struct DynamicLibSym* syms, int count, void** lib);

View file

@ -1085,7 +1085,7 @@ static BOOL (WINAPI *_RtlGenRandom)(PVOID data, ULONG len);
cc_result Platform_GetEntropy(void* data, int len) { cc_result Platform_GetEntropy(void* data, int len) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym2("SystemFunction036", RtlGenRandom) DynamicLib_ReqSym2("SystemFunction036", RtlGenRandom)
}; };
if (!_RtlGenRandom) { if (!_RtlGenRandom) {

View file

@ -48,7 +48,7 @@ void SSLBackend_Init(cc_bool verifyCerts) {
/* then it DOES work. (and on later Windows versions, those functions */ /* then it DOES work. (and on later Windows versions, those functions */
/* exported from schannel.dll are just DLL forwards to secur32.dll */ /* exported from schannel.dll are just DLL forwards to secur32.dll */
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(InitSecurityInterfaceA) DynamicLib_ReqSym(InitSecurityInterfaceA)
}; };
static const cc_string schannel = String_FromConst("schannel.dll"); static const cc_string schannel = String_FromConst("schannel.dll");
_verifyCerts = verifyCerts; _verifyCerts = verifyCerts;

View file

@ -157,7 +157,9 @@ cc_result DynamicLib_Get(void* lib, const char* name, void** symbol) {
cc_bool DynamicLib_LoadAll(const cc_string* path, const struct DynamicLibSym* syms, int count, void** _lib) { cc_bool DynamicLib_LoadAll(const cc_string* path, const struct DynamicLibSym* syms, int count, void** _lib) {
int i, loaded = 0; cc_bool foundAllRequired = true;
cc_string symName;
int i;
void* addr; void* addr;
void* lib; void* lib;
@ -167,8 +169,13 @@ cc_bool DynamicLib_LoadAll(const cc_string* path, const struct DynamicLibSym* sy
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
addr = DynamicLib_Get2(lib, syms[i].name); addr = DynamicLib_Get2(lib, syms[i].name);
if (addr) loaded++;
*syms[i].symAddr = addr; *syms[i].symAddr = addr;
if (addr || !syms[i].required) continue;
symName = String_FromReadonly(syms[i].name);
Logger_DynamicLibWarn("loading symbol", &symName);
foundAllRequired = false;
} }
return loaded == count; return foundAllRequired;
} }