4#include "../Foundation/Memory.h"
5#include "../Foundation/PrimitiveTypes.h"
12#if SC_COMPILER_MSVC || SC_COMPILER_CLANG_CL
13#define SC_PLUGIN_EXPORT __declspec(dllexport)
15#define SC_PLUGIN_EXPORT __attribute__((visibility("default")))
19#define SC_PLUGIN_LINKER_OPERATORS \
20 void* operator new(SC::size_t len) { return SC::Memory::allocate(len, 8); } \
21 void* operator new[](SC::size_t len) { return SC::Memory::allocate(len, 8); } \
22 void operator delete(void* p, SC::size_t) noexcept \
26 SC::Memory::release(p); \
29 void operator delete(void* p) noexcept \
33 SC::Memory::release(p); \
38#define SC_PLUGIN_LINKER_DEFINITIONS \
39 SC_PLUGIN_LINKER_OPERATORS \
40 extern "C" void __CxxFrameHandler4() {} \
41 extern "C" void __CxxFrameHandler3() {} \
42 int __stdcall DllMain(void*, unsigned int, void*) { return 1; } \
43 extern "C" int _fltused = 0;
49#define SC_PLUGIN_LINKER_DEFINITIONS \
50 SC_PLUGIN_LINKER_OPERATORS \
51 extern "C" void bzero(void* s, SC::size_t n) \
53 unsigned char* p = reinterpret_cast<unsigned char*>(s); \
59 extern "C" int memcmp(const void* s1, const void* s2, SC::size_t n) \
61 const unsigned char* p1 = reinterpret_cast<const unsigned char*>(s1); \
62 const unsigned char* p2 = reinterpret_cast<const unsigned char*>(s2); \
76 extern "C" int __cxa_guard_acquire(SC::uint64_t* guard_object) \
78 if (*reinterpret_cast<const SC::uint8_t*>(guard_object) != 0) \
82 extern "C" void __cxa_guard_release(SC::uint64_t* guard_object) \
84 *reinterpret_cast<SC::uint8_t*>(guard_object) = 1; \
89#define SC_PLUGIN_LINKER_DEFINITIONS
95#define SC_PLUGIN_DEFINE(PluginName) \
96 SC_PLUGIN_LINKER_DEFINITIONS \
97 extern "C" SC_PLUGIN_EXPORT bool PluginName##Init(PluginName*& instance) \
99 instance = new PluginName(); \
100 return instance->init(); \
103 extern "C" SC_PLUGIN_EXPORT bool PluginName##Close(PluginName* instance) \
105 auto res = instance->close(); \
110#define SC_PLUGIN_EXPORT_INTERFACES(PluginName, ...) \
111 extern "C" SC_PLUGIN_EXPORT bool PluginName##QueryInterface(PluginName* plugin, SC::uint32_t hash, \
112 void** pluginInterface) \
114 return SC::PluginCastInterface<PluginName, __VA_ARGS__>()(plugin, hash, pluginInterface); \
120template <
typename PluginClass,
typename... InterfaceClasses>
121struct PluginCastInterface;
123template <
typename PluginClass>
124struct PluginCastInterface<PluginClass>
126 bool operator()(PluginClass*, uint32_t,
void**) {
return false; }
129template <
typename PluginClass,
typename InterfaceClass,
typename... InterfaceClasses>
130struct PluginCastInterface<PluginClass, InterfaceClass, InterfaceClasses...>
132 bool operator()(PluginClass* plugin, uint32_t hash,
void** pluginInterface)
134 if (hash == InterfaceClass::InterfaceHash)
136 *pluginInterface =
static_cast<InterfaceClass*
>(plugin);
139 return PluginCastInterface<PluginClass, InterfaceClasses...>()(plugin, hash, pluginInterface);