-
Notifications
You must be signed in to change notification settings - Fork 23
Selectable library loaders, including link-time #30
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0668b0f
Extract library loading code into its own file
bartbes ded519c
Make library loader selectable
bartbes 56a1ed1
Add link-time library loader
bartbes 938d49a
Fix missing cast in WindowsLibraryLoader
bartbes 2fb36d9
Make sure at least C++11 is used
bartbes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
namespace LibraryLoader | ||
{ | ||
using handle = void; | ||
using function = void(); | ||
|
||
handle *OpenLibrary(const char *name); | ||
void CloseLibrary(handle *handle); | ||
handle* GetCurrentProcessHandle(); | ||
|
||
function *GetFunction(handle *handle, const char *name); | ||
|
||
template<class T> | ||
inline bool LoadSymbol(T& var, handle *handle, const char *name) | ||
{ | ||
var = reinterpret_cast<T>(GetFunction(handle, name)); | ||
return var != nullptr; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "../common/config.h" | ||
#include "../common/LibraryLoader.h" | ||
|
||
#ifdef HTTPS_LIBRARY_LOADER_LINKTIME | ||
|
||
#include <cstring> | ||
|
||
#ifdef HTTPS_BACKEND_CURL | ||
#include <curl/curl.h> | ||
|
||
static char CurlHandle; | ||
#endif | ||
|
||
#if defined(HTTPS_BACKEND_OPENSSL) || defined(HTTPS_BACKEND_ANDROID) | ||
# error "Selected backends that are not compatible with this loader" | ||
#endif | ||
|
||
namespace LibraryLoader | ||
{ | ||
handle *OpenLibrary(const char *name) | ||
{ | ||
#ifdef HTTPS_BACKEND_CURL | ||
if (strstr(name, "libcurl") == name) | ||
return reinterpret_cast<handle *>(&CurlHandle); | ||
#endif | ||
return nullptr; | ||
} | ||
|
||
void CloseLibrary(handle *) | ||
{ | ||
} | ||
|
||
handle* GetCurrentProcessHandle() | ||
{ | ||
return nullptr; | ||
} | ||
|
||
function *GetFunction(handle *handle, const char *name) | ||
{ | ||
#define RETURN_MATCHING_FUNCTION(func) \ | ||
if (strcmp(name, #func) == 0) \ | ||
return reinterpret_cast<function *>(&func); | ||
|
||
#ifdef HTTPS_BACKEND_CURL | ||
if (handle == &CurlHandle) | ||
{ | ||
RETURN_MATCHING_FUNCTION(curl_global_init); | ||
RETURN_MATCHING_FUNCTION(curl_global_cleanup); | ||
RETURN_MATCHING_FUNCTION(curl_easy_init); | ||
RETURN_MATCHING_FUNCTION(curl_easy_cleanup); | ||
RETURN_MATCHING_FUNCTION(curl_easy_setopt); | ||
RETURN_MATCHING_FUNCTION(curl_easy_perform); | ||
RETURN_MATCHING_FUNCTION(curl_easy_getinfo); | ||
RETURN_MATCHING_FUNCTION(curl_slist_append); | ||
RETURN_MATCHING_FUNCTION(curl_slist_free_all); | ||
} | ||
#endif | ||
|
||
#undef RETURN_MATCHING_FUNCTION | ||
|
||
return nullptr; | ||
} | ||
} | ||
|
||
#endif // HTTPS_LIBRARY_LOADER_LINKTIME | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.