#ifdefined(_WIN32) // Ensure the min/max macro in the header doesn't collide with functions in // std:: # ifndef NOMINMAX # define NOMINMAX # endif # include <windows.h> #else # include <dlfcn.h> #endif
/** *@briefClassthatimplementsthenullsandbox.Thissandboxdoesn'tactually *provideanyisolationandonlyservesasasteppingstonetowardsmigrating *anapplicationtousetheRLBoxAPI.
*/ class rlbox_dylib_sandbox
{
public: // Stick with the system defaults
using T_LongLongType = longlong;
using T_LongType = long;
using T_IntType = int;
using T_PointerType = void*;
using T_ShortType = short; // no-op sandbox can transfer buffers as there is no sandboxings // Thus transfer is a noop
using can_grant_deny_access = void; // if this plugin uses a separate function to lookup internal callbacks
using needs_internal_lookup_symbol = void;
template<uint32_t N, typename T_Ret, typename... T_Args> static T_Ret callback_trampoline(T_Args... params)
{ #ifdef RLBOX_EMBEDDER_PROVIDES_TLS_STATIC_VARIABLES auto& thread_data = *get_rlbox_dylib_sandbox_thread_data(); #endif
thread_data.last_callback_invoked = N;
using T_Func = T_Ret (*)(T_Args...);
T_Func func;
{ #ifndef RLBOX_SINGLE_THREADED_INVOCATIONS
RLBOX_ACQUIRE_SHARED_GUARD(lock, thread_data.sandbox->callback_mutex); #endif
func = reinterpret_cast<T_Func>(thread_data.sandbox->callbacks[N]);
} // Callbacks are invoked through function pointers, cannot use std::forward // as we don't have caller context for T_Args, which means they are all // effectively passed by value return func(params...);
}
protected: #ifdefined(_WIN32)
using path_buf = const LPCWSTR; #else
using path_buf = constchar*; #endif
inlinevoid* impl_get_memory_location()
{ // There isn't any sandbox memory for the dylib_sandbox as we just redirect // to the app. Also, this is mostly used for pointer swizzling or sandbox // bounds checks which is also not present/not required. So we can just // return null return nullptr;
}
void* impl_lookup_symbol(constchar* func_name)
{ #ifdefined(_WIN32) void* ret = GetProcAddress((HMODULE)sandbox, func_name); #else void* ret = dlsym(sandbox, func_name); #endif
detail::dynamic_check(ret != nullptr, "Symbol not found"); return ret;
}
// need a compile time for loop as we we need I to be a compile time value // this is because we are returning the I'th callback trampoline
detail::compile_time_for<MAX_CALLBACKS>([&](auto I) { if (!chosen_trampoline && callback_unique_keys[I.value] == nullptr) {
callback_unique_keys[I.value] = key;
callbacks[I.value] = callback;
chosen_trampoline = reinterpret_cast<void*>(
callback_trampoline<I.value, T_Ret, T_Args...>);
}
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.