From b34377d447e53e506c692552c3cf2c1e06dfb3f4 Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Sun, 16 Aug 2026 18:53:31 +0800 Subject: [PATCH 01/15] Refactor: restructure libloader and drop config parsing - Move loader logic to core/ and rename plantform/ to platform/ - Remove config.toml parsing from loader; pass runtime_dir to Bootstrap directly - Rewrite JvmAttach: RAII detach, drop dead thread_local, merge acquire helpers - Fix initialize() missing namespace qualification - Make GLOB sources pick up new files with CONFIGURE_DEPENDS --- src/libloader/CMakeLists.txt | 12 +-- src/libloader/common/Loader.cpp | 101 ------------------ src/libloader/core/Entry.cpp | 29 +++++ src/libloader/core/Loader.cpp | 60 +++++++++++ src/libloader/includes/JvmAttach.hpp | 101 +++++++----------- src/libloader/includes/Loader.hpp | 11 +- .../windows/DllMain.cpp | 0 .../windows/ReflectiveLoader.c | 0 8 files changed, 139 insertions(+), 175 deletions(-) delete mode 100644 src/libloader/common/Loader.cpp create mode 100644 src/libloader/core/Entry.cpp create mode 100644 src/libloader/core/Loader.cpp rename src/libloader/{plantform => platform}/windows/DllMain.cpp (100%) rename src/libloader/{plantform => platform}/windows/ReflectiveLoader.c (100%) diff --git a/src/libloader/CMakeLists.txt b/src/libloader/CMakeLists.txt index 253a415..26e3ed2 100644 --- a/src/libloader/CMakeLists.txt +++ b/src/libloader/CMakeLists.txt @@ -1,14 +1,14 @@ -file(GLOB_RECURSE loader_sources - ${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/common/*.c +file(GLOB_RECURSE loader_sources CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/core/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/core/*.c ) if (WIN32) message(STATUS "Detected System: Windows") - file(GLOB_RECURSE windows_sources - ${CMAKE_CURRENT_SOURCE_DIR}/plantform/windows/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/plantform/windows/*.c + file(GLOB_RECURSE windows_sources CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/platform/windows/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/platform/windows/*.c ) list(APPEND loader_sources ${windows_sources}) diff --git a/src/libloader/common/Loader.cpp b/src/libloader/common/Loader.cpp deleted file mode 100644 index 0d94365..0000000 --- a/src/libloader/common/Loader.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -namespace JuiceAgent::Loader { - -static bool invoke_juiceagent_init(JNIEnv* env, const LoaderConfig& config) { - const char* bootstrap_class = "cn/xiaozhou233/juiceagent/api/JuiceAgentBootstrap"; - const char* method_name = "start"; - - std::string args = JuiceAgent::Config::Utils::serialize_loader_config(config); - spdlog::debug("Invoke args: {}", args); - - if (!JuiceAgent::Utils::call_java_impl(env, bootstrap_class, method_name, args.c_str())) { - spdlog::error("Failed to init JuiceAgent!"); - return false; - } - - spdlog::info("JuiceAgentBootstrap.start invoked successfully"); - return true; -} - -static void init(const char* runtime_dir, JNIEnv* env, jvmtiEnv* jvmti) { - if (!runtime_dir) { - spdlog::warn("Runtime directory is not set!"); - } - - // Load configuration - JuiceAgent::Config::Config cfg(runtime_dir ? runtime_dir : ""); - if (!cfg.is_valid()) { - spdlog::error("Failed to load configuration!"); - - // TODO: Use default values - // Before impl TODO, must return, or crash will happen - return; - } - - // Print configuration - LoaderConfig config = JuiceAgent::Config::Utils::get_loader_config(cfg); - JuiceAgent::Config::Utils::print_loader_config(config); - - // Save bytes to file - std::string hash = - JuiceAgent::Resource::juiceagent_api_bytes_sha256; - - std::string file_name = - hash.substr(0, 8) + "_" + - JuiceAgent::Resource::juiceagent_api_bytes_name; - - std::string juiceagent_api_path = - JuiceAgent::Utils::File::write_to_tempfile( - JuiceAgent::Resource::juiceagent_api_bytes, - JuiceAgent::Resource::juiceagent_api_bytes_len, - file_name - ); - - spdlog::debug("JuiceAgent API path: {}", juiceagent_api_path); - spdlog::debug("JuiceAgent API size: {}", JuiceAgent::Resource::juiceagent_api_bytes_len); - spdlog::debug("JuiceAgent API sha256: {}", JuiceAgent::Resource::juiceagent_api_bytes_sha256); - - // Load JuiceAgent API to system classloader - jvmtiError status = jvmti->AddToSystemClassLoaderSearch(juiceagent_api_path.c_str()); - if (status != JVMTI_ERROR_NONE) { - spdlog::error("Failed to add JuiceAgent API to system classloader! code: {}", static_cast(status)); - return; - } - - spdlog::info("JuiceAgent API loaded to system classloader!"); - - // Init JuiceAgent - if (!invoke_juiceagent_init(env, config)) { - spdlog::error("Failed to init JuiceAgent!"); - } -} - - -void entrypoint(const char* runtime_dir) { - // Attach to the JVM - Jvm jvm; - if (!jvm.attach()) { - spdlog::error("Failed to attach to JVM!"); - return; - } - - // Get jvm and jni env - JNIEnv* env = jvm.get_env(); - auto* jvmti = jvm.get_jvmti(); - if (!env || !jvmti) { - spdlog::error("Failed to get jni env or jvmti env!"); - return; - } - - // Init JuiceAgent - init(runtime_dir, env, jvmti); -} - -} diff --git a/src/libloader/core/Entry.cpp b/src/libloader/core/Entry.cpp new file mode 100644 index 0000000..3a71201 --- /dev/null +++ b/src/libloader/core/Entry.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +void JuiceAgent::Loader::entrypoint(const char* path) { + // Attach to the JVM + JuiceAgent::Loader::JvmAttach jvmAttach; + + if(!jvmAttach.attach()) { + spdlog::error("Failed to attach to JVM!"); + return; + } + + // Get JNIEnv + JNIEnv* env = jvmAttach.get_env(); + if(!env) { + spdlog::error("Failed to get JNIEnv!"); + return; + } + + // Get JVMTI environment + jvmtiEnv* jvmti = jvmAttach.get_jvmti(); + if(!jvmti) { + spdlog::error("Failed to get JVMTI environment!"); + return; + } + + JuiceAgent::Loader::preload(path, env, jvmti); +} \ No newline at end of file diff --git a/src/libloader/core/Loader.cpp b/src/libloader/core/Loader.cpp new file mode 100644 index 0000000..3b40069 --- /dev/null +++ b/src/libloader/core/Loader.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include + +// Preload section +// Check parameters and load the runtime +void JuiceAgent::Loader::preload(const char* runtime_dir, JNIEnv* env, jvmtiEnv* jvmti) { + // Check parameters + if(!runtime_dir) { + spdlog::warn("[PreLoad] Runtime directory is not specified!"); + } + spdlog::info("[PreLoad] Runtime directory: {}", runtime_dir ? runtime_dir : "NULL"); + + // Extract JuiceAgent API to temp file + std::string hash = + JuiceAgent::Resource::juiceagent_api_bytes_sha256; + + std::string file_name = + hash.substr(0, 8) + "_" + + JuiceAgent::Resource::juiceagent_api_bytes_name; + + std::string juiceagent_api_path = + JuiceAgent::Utils::File::write_to_tempfile( + JuiceAgent::Resource::juiceagent_api_bytes, + JuiceAgent::Resource::juiceagent_api_bytes_len, + file_name + ); + + // Debug + spdlog::debug("JuiceAgent API path: {}", juiceagent_api_path); + spdlog::debug("JuiceAgent API size: {}", JuiceAgent::Resource::juiceagent_api_bytes_len); + spdlog::debug("JuiceAgent API sha256: {}", JuiceAgent::Resource::juiceagent_api_bytes_sha256); + + // Load JuiceAgent API + jvmtiError status = jvmti->AddToSystemClassLoaderSearch(juiceagent_api_path.c_str()); + if (status != JVMTI_ERROR_NONE) { + spdlog::error("Failed to add JuiceAgent API to system classloader! code: {}", static_cast(status)); + return; + } + + spdlog::info("JuiceAgent API loaded to system classloader!"); + + // Init JuiceAgent via JuiceAgent API + JuiceAgent::Loader::initialize(runtime_dir, env, jvmti); +} + +void JuiceAgent::Loader::initialize(const char* runtime_dir, JNIEnv* env, jvmtiEnv* jvmti) { + const char* bootstrap_class = "cn/xiaozhou233/juiceagent/api/JuiceAgentBootstrap"; + const char* method_name = "start"; + + bool result = JuiceAgent::Utils::call_java_impl(env, bootstrap_class, method_name, runtime_dir); + if (!result) { + spdlog::error("Failed to initialize JuiceAgent!"); + return; + } + + spdlog::info("JuiceAgent initialized!"); +} \ No newline at end of file diff --git a/src/libloader/includes/JvmAttach.hpp b/src/libloader/includes/JvmAttach.hpp index e335161..d42f5bf 100644 --- a/src/libloader/includes/JvmAttach.hpp +++ b/src/libloader/includes/JvmAttach.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #include @@ -9,29 +9,50 @@ namespace JuiceAgent::Loader { -class Jvm { +// RAII wrapper: attaches to the running JVM (with retry) and detaches on destruction. +class JvmAttach { public: - explicit Jvm(int max_try = 30, int retry_delay_ms = 1000) + explicit JvmAttach(int max_try = 30, int retry_delay_ms = 1000) : max_try_(max_try), retry_delay_ms_(retry_delay_ms) {} + ~JvmAttach() { detach(); } + + JvmAttach(const JvmAttach&) = delete; + JvmAttach& operator=(const JvmAttach&) = delete; + JavaVM* get_jvm() const { return jvm_; } JNIEnv* get_env() const { return env_; } jvmtiEnv* get_jvmti() const { return jvmti_; } bool attach() { - reset(); + jvm_ = nullptr; + env_ = nullptr; + jvmti_ = nullptr; + attached_ = false; - return acquire_jvm() && acquire_env() && acquire_jvmti(); + return retry("JavaVM", [this] { + return JNI_GetCreatedJavaVMs(&jvm_, 1, nullptr) == JNI_OK && jvm_; + }) && retry("JNIEnv", [this] { + if (jvm_->GetEnv(reinterpret_cast(&env_), JNI_VERSION_1_8) == JNI_OK && env_) + return true; + env_ = nullptr; + if (jvm_->AttachCurrentThread(reinterpret_cast(&env_), nullptr) == JNI_OK && env_) { + attached_ = true; + return true; + } + return false; + }) && retry("JVMTI", [this] { + return jvm_->GetEnv(reinterpret_cast(&jvmti_), JVMTI_VERSION_1_2) == JNI_OK && jvmti_; + }); } - bool detach() { + bool detach() noexcept { if (jvm_ && attached_) { jint res = jvm_->DetachCurrentThread(); if (res != JNI_OK) { spdlog::debug("DetachCurrentThread failed: {}", res); return false; } - spdlog::debug("Thread detached"); attached_ = false; env_ = nullptr; @@ -40,69 +61,23 @@ public: } private: - static inline thread_local JNIEnv* env_ = nullptr; - - JavaVM* jvm_ = nullptr; - jvmtiEnv* jvmti_ = nullptr; - - bool attached_ = false; - int max_try_; - int retry_delay_ms_; - - void reset() { - jvm_ = nullptr; - jvmti_ = nullptr; - env_ = nullptr; - attached_ = false; - } - - void retry(const char* what, int attempt) { - spdlog::debug("Failed to get {}, attempt {}/{}", what, attempt, max_try_); - std::this_thread::sleep_for(std::chrono::milliseconds(retry_delay_ms_)); - } - template - bool acquire(const char* what, Fn&& attempt) { + bool retry(const char* what, Fn&& attempt) { for (int i = 1; i <= max_try_; i++) { - if (attempt()) { + if (attempt()) return true; - } - retry(what, i); + spdlog::debug("Failed to get {}, attempt {}/{}", what, i, max_try_); + std::this_thread::sleep_for(std::chrono::milliseconds(retry_delay_ms_)); } return false; } - bool acquire_jvm() { - return acquire("JavaVM", [this] { - jvm_ = nullptr; - return JNI_GetCreatedJavaVMs(&jvm_, 1, nullptr) == JNI_OK && jvm_ != nullptr; - }); - } - - bool acquire_env() { - return acquire("JNIEnv", [this] { - env_ = nullptr; - if (jvm_->GetEnv(reinterpret_cast(&env_), JNI_VERSION_1_6) == JNI_OK && env_ != nullptr) { - return true; - } - - env_ = nullptr; - if (jvm_->AttachCurrentThread(reinterpret_cast(&env_), nullptr) == JNI_OK && env_ != nullptr) { - attached_ = true; - return true; - } - - env_ = nullptr; - return false; - }); - } - - bool acquire_jvmti() { - return acquire("JVMTI", [this] { - jvmti_ = nullptr; - return jvm_->GetEnv(reinterpret_cast(&jvmti_), JVMTI_VERSION_1_2) == JNI_OK && jvmti_ != nullptr; - }); - } + JavaVM* jvm_ = nullptr; + JNIEnv* env_ = nullptr; + jvmtiEnv* jvmti_ = nullptr; + bool attached_ = false; + int max_try_; + int retry_delay_ms_; }; } // namespace JuiceAgent::Loader diff --git a/src/libloader/includes/Loader.hpp b/src/libloader/includes/Loader.hpp index dbac22b..8ed1758 100644 --- a/src/libloader/includes/Loader.hpp +++ b/src/libloader/includes/Loader.hpp @@ -1,9 +1,10 @@ #pragma once +#include +#include + namespace JuiceAgent::Loader { - -// Attach to the JVM and initialize JuiceAgent. -// runtime_dir: directory containing config.toml, or nullptr to use defaults. -void entrypoint(const char* runtime_dir); - + void entrypoint(const char* runtime_dir); + void preload(const char* runtime_dir, JNIEnv* env, jvmtiEnv* jvmti); + void initialize(const char* runtime_dir, JNIEnv* env, jvmtiEnv* jvmti); } // namespace JuiceAgent::Loader diff --git a/src/libloader/plantform/windows/DllMain.cpp b/src/libloader/platform/windows/DllMain.cpp similarity index 100% rename from src/libloader/plantform/windows/DllMain.cpp rename to src/libloader/platform/windows/DllMain.cpp diff --git a/src/libloader/plantform/windows/ReflectiveLoader.c b/src/libloader/platform/windows/ReflectiveLoader.c similarity index 100% rename from src/libloader/plantform/windows/ReflectiveLoader.c rename to src/libloader/platform/windows/ReflectiveLoader.c From 3b180e719987191243645886c53f98a5f68e288f Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Sun, 16 Aug 2026 21:08:13 +0800 Subject: [PATCH 02/15] Fix: harden libloader config handling - Guard Config against NULL runtime_dir - Read JuiceAgent.Version from config instead of hardcoding 2 - Move LoaderConfig to ConfigStruct.hpp; remove obsolete JuiceAgent.hpp --- includes/JuiceAgent/Config.hpp | 10 +++--- .../{JuiceAgent.hpp => ConfigStruct.hpp} | 7 ++-- src/libloader/core/Loader.cpp | 36 ++++++++++++++++--- 3 files changed, 39 insertions(+), 14 deletions(-) rename includes/JuiceAgent/{JuiceAgent.hpp => ConfigStruct.hpp} (70%) diff --git a/includes/JuiceAgent/Config.hpp b/includes/JuiceAgent/Config.hpp index 40a78df..5f77a2e 100644 --- a/includes/JuiceAgent/Config.hpp +++ b/includes/JuiceAgent/Config.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include #include @@ -142,12 +142,12 @@ namespace Utils { spdlog::info("RuntimeDir: {}", config.RuntimeDir); } - inline std::string serialize_loader_config(const LoaderConfig& config) + inline std::string serialize_loader_config(const Config& config, const LoaderConfig& loader_config) { JuiceAgent::Utils::Serializer ser; - ser.add_kv("Version", 2); - ser.add_kv("JuiceAgentNativeLibraryPath", config.JuiceAgentNativeLibraryPath); - ser.add_kv("RuntimeDir", config.RuntimeDir); + ser.add_kv("Version", config.get("JuiceAgent.Version", 1)); + ser.add_kv("JuiceAgentNativeLibraryPath", loader_config.JuiceAgentNativeLibraryPath); + ser.add_kv("RuntimeDir", loader_config.RuntimeDir); return ser.serialize(); } diff --git a/includes/JuiceAgent/JuiceAgent.hpp b/includes/JuiceAgent/ConfigStruct.hpp similarity index 70% rename from includes/JuiceAgent/JuiceAgent.hpp rename to includes/JuiceAgent/ConfigStruct.hpp index 971abf9..30e4105 100644 --- a/includes/JuiceAgent/JuiceAgent.hpp +++ b/includes/JuiceAgent/ConfigStruct.hpp @@ -2,11 +2,8 @@ #include -namespace JuiceAgent { - struct LoaderConfig { std::string JuiceAgentNativeLibraryPath; - std::string RuntimeDir; -}; -} // namespace JuiceAgent + std::string RuntimeDir; +}; \ No newline at end of file diff --git a/src/libloader/core/Loader.cpp b/src/libloader/core/Loader.cpp index 3b40069..b0ab0a8 100644 --- a/src/libloader/core/Loader.cpp +++ b/src/libloader/core/Loader.cpp @@ -1,18 +1,31 @@ #include #include +#include #include #include +#include +#include #include // Preload section // Check parameters and load the runtime void JuiceAgent::Loader::preload(const char* runtime_dir, JNIEnv* env, jvmtiEnv* jvmti) { + std::string runtime_dir_new; + // Check parameters if(!runtime_dir) { spdlog::warn("[PreLoad] Runtime directory is not specified!"); - } - spdlog::info("[PreLoad] Runtime directory: {}", runtime_dir ? runtime_dir : "NULL"); + runtime_dir_new = std::filesystem::current_path().string(); + + spdlog::warn( "[PreLoad] Using default runtime directory: {}", runtime_dir_new); + } else { + runtime_dir_new = runtime_dir; + } + + spdlog::info("[PreLoad] Runtime directory: {}", runtime_dir_new); + + // TODO: Advanced options // Extract JuiceAgent API to temp file std::string hash = JuiceAgent::Resource::juiceagent_api_bytes_sha256; @@ -43,14 +56,29 @@ void JuiceAgent::Loader::preload(const char* runtime_dir, JNIEnv* env, jvmtiEnv* spdlog::info("JuiceAgent API loaded to system classloader!"); // Init JuiceAgent via JuiceAgent API - JuiceAgent::Loader::initialize(runtime_dir, env, jvmti); + JuiceAgent::Loader::initialize(runtime_dir_new.c_str(), env, jvmti); } void JuiceAgent::Loader::initialize(const char* runtime_dir, JNIEnv* env, jvmtiEnv* jvmti) { const char* bootstrap_class = "cn/xiaozhou233/juiceagent/api/JuiceAgentBootstrap"; const char* method_name = "start"; - bool result = JuiceAgent::Utils::call_java_impl(env, bootstrap_class, method_name, runtime_dir); + // Read JuiceAgent config + JuiceAgent::Config::Config cfg(runtime_dir ? runtime_dir : ""); + if (!cfg.is_valid()) { + spdlog::error("JuiceAgent configuration is invalid!"); + return; + } + + // TODO: Refactor config + LoaderConfig config = JuiceAgent::Config::Utils::get_loader_config(cfg); + JuiceAgent::Config::Utils::print_loader_config(config); + + // Serialize InjectionInfo to string + std::string args = JuiceAgent::Config::Utils::serialize_loader_config(cfg, config); + spdlog::debug("Serialized config: {}", args); + + bool result = JuiceAgent::Utils::call_java_impl(env, bootstrap_class, method_name, args.c_str()); if (!result) { spdlog::error("Failed to initialize JuiceAgent!"); return; From 51bcfbd54911cde60938bf39ca556feccc225a20 Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Sun, 16 Aug 2026 21:14:44 +0800 Subject: [PATCH 03/15] Refactor: rebuild libagent with simplified lifecycle - Replace eventbus/services with Agent preload/init lifecycle - Move JNI header to shared includes; add jni_common.hpp umbrella header - Reduce ClassFileLoadHook to a stub for later implementation - Add eventpp dependency - Document custom API JAR workflow (WIP) --- docs/advanced.md | 24 + ...cn_xiaozhou233_juiceagent_api_JuiceAgent.h | 0 includes/eventpp/callbacklist.h | 498 ++++++++++++++++ includes/eventpp/eventdispatcher.h | 328 ++++++++++ includes/eventpp/eventpolicies.h | 186 ++++++ includes/eventpp/eventqueue.h | 561 ++++++++++++++++++ includes/eventpp/hetercallbacklist.h | 319 ++++++++++ includes/eventpp/hetereventdispatcher.h | 325 ++++++++++ includes/eventpp/hetereventqueue.h | 482 +++++++++++++++ includes/eventpp/internal/eventpolicies_i.h | 191 ++++++ includes/eventpp/internal/eventqueue_i.h | 174 ++++++ .../eventpp/internal/hetercallbacklist_i.h | 292 +++++++++ includes/eventpp/internal/typeutil_i.h | 127 ++++ includes/eventpp/mixins/mixinfilter.h | 75 +++ includes/eventpp/mixins/mixinheterfilter.h | 73 +++ includes/eventpp/utilities/anydata.h | 247 ++++++++ includes/eventpp/utilities/anyid.h | 161 +++++ includes/eventpp/utilities/argumentadapter.h | 136 +++++ .../eventpp/utilities/conditionalfunctor.h | 50 ++ .../eventpp/utilities/conditionalremover.h | 222 +++++++ includes/eventpp/utilities/counterremover.h | 196 ++++++ includes/eventpp/utilities/eventmaker.h | 177 ++++++ includes/eventpp/utilities/eventutil.h | 169 ++++++ includes/eventpp/utilities/orderedqueuelist.h | 81 +++ includes/eventpp/utilities/scopedremover.h | 330 +++++++++++ licenses/eventpp.txt | 16 + src/libagent/JuiceAgent.cpp | 157 +++-- src/libagent/callback/ClassFileLoadHook.cpp | 38 -- src/libagent/callback/MethodEntry.cpp | 15 - src/libagent/callback/MethodExit.cpp | 19 - src/libagent/callbacks/ClassFileLoadHook.cpp | 21 + src/libagent/core/global.cpp | 8 - src/libagent/entry/agent_onload.cpp | 119 ---- src/libagent/entry/jni.cpp | 10 +- src/libagent/includes/JuiceAgent.hpp | 49 +- src/libagent/includes/event/eventbus.hpp | 218 ------- src/libagent/includes/global.hpp | 38 -- src/libagent/includes/jni_common.hpp | 23 + src/libagent/includes/jni_impl.hpp | 40 -- src/libagent/includes/services.hpp | 40 -- src/libagent/includes/utils.hpp | 43 -- src/libagent/jni/bytecode.cpp | 320 ---------- src/libagent/jni/classloader.cpp | 275 --------- src/libagent/jni/instrumentation.cpp | 2 - src/libagent/services/BytecodeService.cpp | 64 -- src/libagent/services/JarLoaderService.cpp | 68 --- src/libagent/services/ServicesManager.cpp | 38 -- 47 files changed, 5583 insertions(+), 1462 deletions(-) create mode 100644 docs/advanced.md rename {src/libagent/includes => includes/JuiceAgent}/cn_xiaozhou233_juiceagent_api_JuiceAgent.h (100%) create mode 100644 includes/eventpp/callbacklist.h create mode 100644 includes/eventpp/eventdispatcher.h create mode 100644 includes/eventpp/eventpolicies.h create mode 100644 includes/eventpp/eventqueue.h create mode 100644 includes/eventpp/hetercallbacklist.h create mode 100644 includes/eventpp/hetereventdispatcher.h create mode 100644 includes/eventpp/hetereventqueue.h create mode 100644 includes/eventpp/internal/eventpolicies_i.h create mode 100644 includes/eventpp/internal/eventqueue_i.h create mode 100644 includes/eventpp/internal/hetercallbacklist_i.h create mode 100644 includes/eventpp/internal/typeutil_i.h create mode 100644 includes/eventpp/mixins/mixinfilter.h create mode 100644 includes/eventpp/mixins/mixinheterfilter.h create mode 100644 includes/eventpp/utilities/anydata.h create mode 100644 includes/eventpp/utilities/anyid.h create mode 100644 includes/eventpp/utilities/argumentadapter.h create mode 100644 includes/eventpp/utilities/conditionalfunctor.h create mode 100644 includes/eventpp/utilities/conditionalremover.h create mode 100644 includes/eventpp/utilities/counterremover.h create mode 100644 includes/eventpp/utilities/eventmaker.h create mode 100644 includes/eventpp/utilities/eventutil.h create mode 100644 includes/eventpp/utilities/orderedqueuelist.h create mode 100644 includes/eventpp/utilities/scopedremover.h create mode 100644 licenses/eventpp.txt delete mode 100644 src/libagent/callback/ClassFileLoadHook.cpp delete mode 100644 src/libagent/callback/MethodEntry.cpp delete mode 100644 src/libagent/callback/MethodExit.cpp create mode 100644 src/libagent/callbacks/ClassFileLoadHook.cpp delete mode 100644 src/libagent/core/global.cpp delete mode 100644 src/libagent/entry/agent_onload.cpp delete mode 100644 src/libagent/includes/event/eventbus.hpp delete mode 100644 src/libagent/includes/global.hpp create mode 100644 src/libagent/includes/jni_common.hpp delete mode 100644 src/libagent/includes/jni_impl.hpp delete mode 100644 src/libagent/includes/services.hpp delete mode 100644 src/libagent/includes/utils.hpp delete mode 100644 src/libagent/jni/bytecode.cpp delete mode 100644 src/libagent/jni/classloader.cpp delete mode 100644 src/libagent/jni/instrumentation.cpp delete mode 100644 src/libagent/services/BytecodeService.cpp delete mode 100644 src/libagent/services/JarLoaderService.cpp delete mode 100644 src/libagent/services/ServicesManager.cpp diff --git a/docs/advanced.md b/docs/advanced.md new file mode 100644 index 0000000..5c9f9c1 --- /dev/null +++ b/docs/advanced.md @@ -0,0 +1,24 @@ +# Advanced + +## Load Custom API / Directly Load Jar +WARN: This feature didn't implement yet. + +### Describe +JuiceAgent loads custom JARs through the following workflow: + +1. Inject `libloader` into the target process. +2. Load **JuiceAgent-API** and execute its initialization entry point. +3. Invoke the `JarLoader` from **JuiceAgent-API** to load the specified JAR into the JVM. + +The second step is fully customizable. You can replace **JuiceAgent-API** with your own JAR and call any class method you specify. + +### Configuration + +Set the following environment variables before launching `libloader`: + +```bat +set JUICEAGENT_API_ENABLED=true +set JUICEAGENT_API_JAR= +set JUICEAGENT_API_CLASS= +set JUICEAGENT_API_METHOD= +``` \ No newline at end of file diff --git a/src/libagent/includes/cn_xiaozhou233_juiceagent_api_JuiceAgent.h b/includes/JuiceAgent/cn_xiaozhou233_juiceagent_api_JuiceAgent.h similarity index 100% rename from src/libagent/includes/cn_xiaozhou233_juiceagent_api_JuiceAgent.h rename to includes/JuiceAgent/cn_xiaozhou233_juiceagent_api_JuiceAgent.h diff --git a/includes/eventpp/callbacklist.h b/includes/eventpp/callbacklist.h new file mode 100644 index 0000000..71267bb --- /dev/null +++ b/includes/eventpp/callbacklist.h @@ -0,0 +1,498 @@ +// eventpp library +// Copyright (C) 2018 Wang Qi (wqking) +// Github: https://github.com/wqking/eventpp +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef CALLBACKLIST_H_588722158669 +#define CALLBACKLIST_H_588722158669 + +#include "eventpolicies.h" + +#include +#include +#include + +namespace eventpp { + +namespace internal_ { + +template < + typename Prototype, + typename PoliciesType +> +class CallbackListBase; + +template < + typename PoliciesType, + typename ReturnType, typename ...Args +> +class CallbackListBase< + ReturnType (Args...), + PoliciesType +> +{ +private: + using Policies = PoliciesType; + + using Threading = typename SelectThreading::value>::Type; + + using Callback_ = typename SelectCallback< + Policies, + HasTypeCallback::value, + std::function + >::Type; + + using CanContinueInvoking = typename SelectCanContinueInvoking< + Policies, HasFunctionCanContinueInvoking::value + >::Type; + + struct Node; + using NodePtr = std::shared_ptr; + + struct Node + { + using Counter = unsigned int; + + Node(const Callback_ & callback, const Counter counter) + : callback(callback), counter(counter) + { + } + + NodePtr previous; + NodePtr next; + Callback_ callback; + Counter counter; + }; + + class Handle_ : public std::weak_ptr + { + private: + using super = std::weak_ptr; + + public: + using super::super; + + operator bool () const noexcept { + return ! this->expired(); + } + }; + + using Counter = typename Node::Counter; + enum : Counter { + removedCounter = 0 + }; + +public: + using Callback = Callback_; + using Handle = Handle_; + using Mutex = typename Threading::Mutex; + +public: + CallbackListBase() noexcept + : + head(), + tail(), + mutex(), + currentCounter(0) + { + } + + CallbackListBase(const CallbackListBase & other) + : CallbackListBase() + { + cloneFrom(other.head); + } + + CallbackListBase(CallbackListBase && other) noexcept + : CallbackListBase() + { + swap(other); + } + + // If we use pass by value idiom and omit the 'this' check, + // when assigning to self there is a deep copy which is inefficient. + CallbackListBase & operator = (const CallbackListBase & other) { + if(this != &other) { + CallbackListBase copied(other); + swap(copied); + } + return *this; + } + + CallbackListBase & operator = (CallbackListBase && other) noexcept { + if(this != &other) { + doFreeAllNodes(); + + head = std::move(other.head); + tail = std::move(other.tail); + currentCounter = other.currentCounter.load(); + } + return *this; + } + + ~CallbackListBase() { + // Don't lock mutex here since it may throw exception + + doFreeAllNodes(); + } + + void swap(CallbackListBase & other) noexcept { + using std::swap; + + swap(head, other.head); + swap(tail, other.tail); + + const auto value = currentCounter.load(); + currentCounter.exchange(other.currentCounter.load()); + other.currentCounter.exchange(value); + } + + bool empty() const { + // Don't lock the mutex for performance reason. + // !head still works even when the underlying raw pointer is garbled (for other thread is writting to head) + // And empty() doesn't guarantee the list is still empty after the function returned. + //std::lock_guard lockGuard(mutex); + + return ! head; + } + + operator bool() const { + return ! empty(); + } + + Handle append(const Callback & callback) + { + NodePtr node(doAllocateNode(callback)); + + std::lock_guard lockGuard(mutex); + + if(head) { + node->previous = tail; + tail->next = node; + tail = node; + } + else { + head = node; + tail = node; + } + + return Handle(node); + } + + Handle prepend(const Callback & callback) + { + NodePtr node(doAllocateNode(callback)); + + std::lock_guard lockGuard(mutex); + + if(head) { + node->next = head; + head->previous = node; + head = node; + } + else { + head = node; + tail = node; + } + + return Handle(node); + } + + Handle insert(const Callback & callback, const Handle & before) + { + // Disable this assertion because it's too slow in debug mode. + //assert(before.expired() || ownsHandle(before)); + + NodePtr beforeNode = before.lock(); + if(beforeNode) { + NodePtr node(doAllocateNode(callback)); + + std::lock_guard lockGuard(mutex); + + doInsert(node, beforeNode); + + return Handle(node); + } + + return append(callback); + } + + bool remove(const Handle & handle) + { + // Disable this assertion because it's too slow in debug mode. + //assert(handle.expired() || ownsHandle(handle)); + + // It looks like the lock can be put inside the `if` below, + // but that doesn't work in multi-threading and cause related unit tests fail. + std::lock_guard lockGuard(mutex); + + auto node = handle.lock(); + if(node) { + doFreeNode(node); + return true; + } + + return false; + } + + bool ownsHandle(const Handle & handle) const + { + std::lock_guard lockGuard(mutex); + + auto node = handle.lock(); + if(node) { + while(node->previous) { + node = node->previous; + } + return node == head; + } + + return false; + } + + template + void forEach(Func && func) const + { + doForEachIf([&func, this](NodePtr & node) -> bool { + doForEachInvoke(func, node); + return true; + }); + } + + template + bool forEachIf(Func && func) const + { + return doForEachIf([&func, this](NodePtr & node) -> bool { + return doForEachInvoke(func, node); + }); + } + +#if !defined(__GNUC__) || __GNUC__ >= 5 + void operator() (Args ...args) const + { + forEachIf([&args...](Callback & callback) -> bool { + // We can't use std::forward here, because if we use std::forward, + // for arg that is passed by value, and the callback prototype accepts it by value, + // std::forward will move it and may cause the original value invalid. + // That happens on any value-to-value passing, no matter the callback moves it or not. + + callback(args...); + return CanContinueInvoking::canContinueInvoking(args...); + }); + } +#else + // This is a patch version for GCC 4. It inlines the unrolled doForEachIf. + // GCC 4.8.3 doesn't supporting parameter pack catpure in lambda, see, + // https://github.com/wqking/eventpp/issues/19 + // This is a compromised patch for GCC 4, it may be not maintained or updated unless there are bugs. + // We don't use the patch as main code because the patch generates longer code, and duplicated with doForEachIf. + void operator() (Args ...args) const + { + NodePtr node; + + { + std::lock_guard lockGuard(mutex); + node = head; + } + + const Counter counter = currentCounter.load(std::memory_order_acquire); + + while(node) { + if(node->counter != removedCounter && counter >= node->counter) { + node->callback(args...); + if(! CanContinueInvoking::canContinueInvoking(args...)) { + break; + } + } + + { + std::lock_guard lockGuard(mutex); + node = node->next; + } + } + } +#endif + +private: + template + bool doForEachIf(F && f) const + { + NodePtr node; + + { + std::lock_guard lockGuard(mutex); + node = head; + } + + const Counter counter = currentCounter.load(std::memory_order_acquire); + + while(node) { + if(node->counter != removedCounter && counter >= node->counter) { + if(! f(node)) { + return false; + } + } + + { + std::lock_guard lockGuard(mutex); + node = node->next; + } + } + + return true; + } + + template + auto doForEachInvoke(Func && func, NodePtr & node) const + -> typename std::enable_if::value, RT>::type + { + return func(Handle(node), node->callback); + } + + template + auto doForEachInvoke(Func && func, NodePtr & node) const + -> typename std::enable_if::value, RT>::type + { + return func(node->callback); + } + + void doInsert(NodePtr & node, NodePtr & beforeNode) + { + node->previous = beforeNode->previous; + node->next = beforeNode; + if(beforeNode->previous) { + beforeNode->previous->next = node; + } + beforeNode->previous = node; + + if(beforeNode == head) { + head = node; + } + } + + NodePtr doAllocateNode(const Callback & callback) + { + return std::make_shared(callback, getNextCounter()); + } + + void doFreeNode(NodePtr & node) + { + if(node->next) { + node->next->previous = node->previous; + } + if(node->previous) { + node->previous->next = node->next; + } + + // Mark it as deleted, this must be before the assignment of head and tail below, + // because node can be a reference to head or tail, and after the assignment, node + // can be null pointer. + node->counter = removedCounter; + + if(head == node) { + head = node->next; + } + if(tail == node) { + tail = node->previous; + } + + // don't modify node->previous or node->next + // because node may be still used in a loop. + } + + void doFreeAllNodes() { + NodePtr node = head; + head.reset(); + while(node) { + NodePtr next = node->next; + node->previous.reset(); + node->next.reset(); + node = next; + } + node.reset(); + } + + Counter getNextCounter() + { + Counter result = ++currentCounter;; + if(result == 0) { // overflow, let's reset all nodes' counters. + { + std::lock_guard lockGuard(mutex); + NodePtr node = head; + while(node) { + node->counter = 1; + node = node->next; + } + } + result = ++currentCounter; + } + + return result; + } + + void cloneFrom(const NodePtr & fromHead) { + NodePtr fromNode(fromHead); + NodePtr node; + const Counter counter = getNextCounter(); + while(fromNode) { + const NodePtr nextNode(std::make_shared(fromNode->callback, counter)); + + nextNode->previous = node; + + if(node) { + node->next = nextNode; + } + else { + node = nextNode; + head = node; + } + + node = nextNode; + fromNode = fromNode->next; + } + + tail = node; + } + +private: + NodePtr head; + NodePtr tail; + mutable Mutex mutex; + typename Threading::template Atomic currentCounter; + +}; + + +} //namespace internal_ + + +template < + typename Prototype_, + typename Policies_ = DefaultPolicies +> +class CallbackList : public internal_::CallbackListBase, public TagCallbackList +{ +private: + using super = internal_::CallbackListBase; + +public: + using super::super; + + friend void swap(CallbackList & first, CallbackList & second) noexcept { + first.swap(second); + } +}; + + +} //namespace eventpp + + +#endif diff --git a/includes/eventpp/eventdispatcher.h b/includes/eventpp/eventdispatcher.h new file mode 100644 index 0000000..49c6712 --- /dev/null +++ b/includes/eventpp/eventdispatcher.h @@ -0,0 +1,328 @@ +// eventpp library +// Copyright (C) 2018 Wang Qi (wqking) +// Github: https://github.com/wqking/eventpp +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef EVENTDISPATCHER_H_319010983013 +#define EVENTDISPATCHER_H_319010983013 + +#include "callbacklist.h" + +namespace eventpp { + +namespace internal_ { + +template < + typename EventType_, + typename Prototype_, + typename Policies_, + typename MixinRoot_ +> +class EventDispatcherBase; + +template < + typename EventType_, + typename Policies_, + typename MixinRoot_, + typename ReturnType, typename ...Args +> +class EventDispatcherBase < + EventType_, + ReturnType (Args...), + Policies_, + MixinRoot_ +> +{ +protected: + using ThisType = EventDispatcherBase< + EventType_, + ReturnType (Args...), + Policies_, + MixinRoot_ + >; + using MixinRoot = typename std::conditional< + std::is_same::value, + ThisType, + MixinRoot_ + >::type; + using Policies = Policies_; + + using Threading = typename SelectThreading::value>::Type; + + using ArgumentPassingMode = typename SelectArgumentPassingMode< + Policies_, + HasTypeArgumentPassingMode::value, + ArgumentPassingAutoDetect + >::Type; + + using Callback_ = typename SelectCallback< + Policies_, + HasTypeCallback::value, + std::function + >::Type; + using CallbackList_ = CallbackList; + + using Prototype = ReturnType (Args...); + + using Map = typename SelectMap< + EventType_, + CallbackList_, + Policies_, + HasTemplateMap::value + >::Type; + + using Mixins = typename internal_::SelectMixins< + Policies_, + internal_::HasTypeMixins::value + >::Type; + +public: + using Handle = typename CallbackList_::Handle; + using Callback = Callback_; + using Event = EventType_; + using Mutex = typename Threading::Mutex; + +public: + EventDispatcherBase() + : + eventCallbackListMap(), + listenerMutex() + { + } + + EventDispatcherBase(const EventDispatcherBase & other) + : + eventCallbackListMap(other.eventCallbackListMap), + listenerMutex() + { + } + + EventDispatcherBase(EventDispatcherBase && other) noexcept + : + eventCallbackListMap(std::move(other.eventCallbackListMap)), + listenerMutex() + { + } + + EventDispatcherBase & operator = (const EventDispatcherBase & other) + { + eventCallbackListMap = other.eventCallbackListMap; + return *this; + } + + EventDispatcherBase & operator = (EventDispatcherBase && other) noexcept + { + eventCallbackListMap = std::move(other.eventCallbackListMap); + return *this; + } + + void swap(EventDispatcherBase & other) noexcept { + using std::swap; + + swap(eventCallbackListMap, other.eventCallbackListMap); + } + + Handle appendListener(const Event & event, const Callback & callback) + { + std::lock_guard lockGuard(listenerMutex); + + return eventCallbackListMap[event].append(callback); + } + + Handle prependListener(const Event & event, const Callback & callback) + { + std::lock_guard lockGuard(listenerMutex); + + return eventCallbackListMap[event].prepend(callback); + } + + Handle insertListener(const Event & event, const Callback & callback, const Handle & before) + { + std::lock_guard lockGuard(listenerMutex); + + return eventCallbackListMap[event].insert(callback, before); + } + + bool removeListener(const Event & event, const Handle handle) + { + CallbackList_ * callableList = doFindCallableList(event); + if(callableList) { + return callableList->remove(handle); + } + + return false; + } + + bool hasAnyListener(const Event & event) const + { + const CallbackList_ * callableList = doFindCallableList(event); + if(callableList) { + return ! callableList->empty(); + } + + return false; + } + + bool ownsHandle(const Event & event, const Handle & handle) const + { + const CallbackList_ * callableList = doFindCallableList(event); + if(callableList) { + return callableList->ownsHandle(handle); + } + + return false; + } + + template + void forEach(const Event & event, Func && func) const + { + const CallbackList_ * callableList = doFindCallableList(event); + if(callableList) { + callableList->forEach(std::forward(func)); + } + } + + template + bool forEachIf(const Event & event, Func && func) const + { + const CallbackList_ * callableList = doFindCallableList(event); + if (callableList) { + return callableList->forEachIf(std::forward(func)); + } + + return true; + } + + void dispatch(Args ...args) const + { + static_assert(ArgumentPassingMode::canIncludeEventType, "Dispatching arguments count doesn't match required (Event type should be included)."); + + using GetEvent = typename SelectGetEvent::value>::Type; + + // can't std::forward(args) in GetEvent::getEvent because the pass by value arguments will be moved to getEvent + // then the other std::forward(args) to directDispatch will get empty values. + directDispatch( + GetEvent::getEvent(args...), + std::forward(args)... + ); + } + + template + void dispatch(T && first, Args ...args) const + { + static_assert(ArgumentPassingMode::canExcludeEventType, "Dispatching arguments count doesn't match required (Event type should NOT be included)."); + + using GetEvent = typename SelectGetEvent::value>::Type; + + directDispatch( + GetEvent::getEvent(std::forward(first), args...), + std::forward(args)... + ); + } + + // Bypass any getEvent policy. The first argument is the event type. + // Most used for internal purpose. + void directDispatch(const Event & e, Args ...args) const + { + if(! internal_::ForEachMixins::forEach( + this, typename std::add_lvalue_reference::type(args)...)) { + return; + } + + const CallbackList_ * callableList = doFindCallableList(e); + if(callableList) { + (*callableList)(std::forward(args)...); + } + } + +protected: + const CallbackList_ * doFindCallableList(const Event & e) const + { + return doFindCallableListHelper(this, e); + } + + CallbackList_ * doFindCallableList(const Event & e) + { + return doFindCallableListHelper(this, e); + } + +private: + // template helper to avoid code duplication in doFindCallableList + template + static auto doFindCallableListHelper(T * self, const Event & e) + -> typename std::conditional::value, const CallbackList_ *, CallbackList_ *>::type + { + std::lock_guard lockGuard(self->listenerMutex); + + auto it = self->eventCallbackListMap.find(e); + if(it != self->eventCallbackListMap.end()) { + return &it->second; + } + else { + return nullptr; + } + } + +private: + // Mixin related + struct DoMixinBeforeDispatch + { + template + static auto forEach(const Self * self, A && ...args) + -> typename std::enable_if::value, bool>::type { + return static_cast(self)->mixinBeforeDispatch(std::forward(args)...); + } + + template + static auto forEach(const Self * /*self*/, A && ... /*args*/) + -> typename std::enable_if::value, bool>::type { + return true; + } + }; + +private: + Map eventCallbackListMap; + mutable Mutex listenerMutex; +}; + + +} //namespace internal_ + +template < + typename Event_, + typename Prototype_, + typename Policies_ = DefaultPolicies +> +class EventDispatcher : public internal_::InheritMixins< + internal_::EventDispatcherBase, + typename internal_::SelectMixins::value >::Type + >::Type, public TagEventDispatcher +{ +private: + using super = typename internal_::InheritMixins< + internal_::EventDispatcherBase, + typename internal_::SelectMixins::value >::Type + >::Type; + +public: + using super::super; + + friend void swap(EventDispatcher & first, EventDispatcher & second) noexcept { + first.swap(second); + } +}; + + +} //namespace eventpp + + +#endif + diff --git a/includes/eventpp/eventpolicies.h b/includes/eventpp/eventpolicies.h new file mode 100644 index 0000000..886ac10 --- /dev/null +++ b/includes/eventpp/eventpolicies.h @@ -0,0 +1,186 @@ +// eventpp library +// Copyright (C) 2018 Wang Qi (wqking) +// Github: https://github.com/wqking/eventpp +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef EVENTOPTIONS_H_730367862613 +#define EVENTOPTIONS_H_730367862613 + +#include "internal/typeutil_i.h" + +#include +#include +#include +#include +#include + +namespace eventpp { + +struct TagHomo {}; +struct TagCallbackList : public TagHomo {}; +struct TagEventDispatcher : public TagHomo {}; +struct TagEventQueue : public TagHomo {}; + +struct TagHeter {}; +struct TagHeterCallbackList : public TagHeter {}; +struct TagHeterEventDispatcher : public TagHeter {}; +struct TagHeterEventQueue : public TagHeter {}; + +struct SpinLock +{ +public: + void lock() { + while(locked.test_and_set(std::memory_order_acquire)) { + } + } + + void unlock() { + locked.clear(std::memory_order_release); + } + +private: + std::atomic_flag locked = ATOMIC_FLAG_INIT; +}; + +template < + typename Mutex_, + template class Atomic_ = std::atomic, + typename ConditionVariable_ = std::condition_variable +> +struct GeneralThreading +{ + using Mutex = Mutex_; + + template + using Atomic = Atomic_; + + using ConditionVariable = ConditionVariable_; +}; + +struct MultipleThreading +{ + using Mutex = std::mutex; + + template + using Atomic = std::atomic; + + using ConditionVariable = std::condition_variable; +}; + +struct SingleThreading +{ + struct Mutex + { + void lock() {} + void unlock() {} + }; + + template + struct Atomic + { + Atomic() noexcept = default; + constexpr Atomic(T desired) noexcept + : value(desired) + { + } + + void store(T desired, std::memory_order /*order*/ = std::memory_order_seq_cst) noexcept + { + value = desired; + } + + T load(std::memory_order /*order*/ = std::memory_order_seq_cst) const noexcept + { + return value; + } + + T exchange(T desired, std::memory_order /*order*/ = std::memory_order_seq_cst) noexcept + { + const T previous = value; + value = desired; + return previous; + } + + T operator ++ () noexcept + { + return ++value; + } + + T operator -- () noexcept + { + return --value; + } + + T value; + }; + + struct ConditionVariable + { + void notify_one() noexcept + { + } + + template + void wait(std::unique_lock & /*lock*/, Predicate /*pred*/) + { + } + + template + bool wait_for(std::unique_lock & /*lock*/, + const std::chrono::duration & /*rel_time*/, + Predicate /*pred*/ + ) + { + return true; + } + }; +}; + +struct ArgumentPassingAutoDetect +{ + enum { + canIncludeEventType = true, + canExcludeEventType = true + }; +}; + +struct ArgumentPassingIncludeEvent +{ + enum { + canIncludeEventType = true, + canExcludeEventType = false + }; +}; + +struct ArgumentPassingExcludeEvent +{ + enum { + canIncludeEventType = false, + canExcludeEventType = true + }; +}; + +struct DefaultPolicies +{ +}; + +template