From 687ff827cb41cfa743d2a837c3815c19a26b4b6d Mon Sep 17 00:00:00 2001 From: jmpews Date: Tue, 28 Mar 2023 19:57:29 +0800 Subject: [PATCH] Fixup logging, remove stl container, cleanup code --- CMakeLists.txt | 97 +-- builtin-plugin/SymbolResolver/CMakeLists.txt | 4 +- .../macho/dobby_symbol_resolver.cc | 13 +- cmake/compiler_and_linker.cmake | 2 + cmake/platform/platform-darwin.cmake | 2 +- docs/compile.md | 4 +- examples/CMakeLists.txt | 1 + external/TINYSTL/algorithm.h | 1 + external/TINYSTL/vector.h | 613 +++++++++--------- .../deprecated/misc-helper/CMakeLists.txt | 2 +- external/logging/CMakeLists.txt | 2 +- external/logging/logging.cc | 5 + external/logging/logging/logging.h | 25 +- .../Darwin/ProcessRuntimeUtility.cc | 10 +- .../PlatformUtil/ProcessRuntimeUtility.h | 4 +- .../MultiThreadSupport/ThreadSupport.h | 2 +- .../Darwin/ProcessRuntimeUtility.cc | 15 +- .../Linux/ProcessRuntimeUtility.cc | 18 +- .../PlatformUtil/ProcessRuntimeUtility.h | 4 +- .../Windows/ProcessRuntimeUtility.cc | 10 +- .../arm/InstructionRelocationARM.h | 2 +- .../RoutingPlugin/RoutingPlugin.cc | 2 +- .../RoutingPlugin/RoutingPlugin.h | 2 +- .../MemoryAllocator.h | 6 +- .../ClosureTrampoline.h | 2 +- source/core/arch/x86/cpu-x86.cc | 88 --- source/core/assembler/AssemblerPseudoLabel.h | 2 +- source/core/assembler/assembler.h | 2 +- source/dobby.cpp | 8 +- source/dobby/platform_features.h | 5 +- 30 files changed, 461 insertions(+), 492 deletions(-) create mode 100644 external/TINYSTL/algorithm.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d504457f..2e6cbd4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ set(CMAKE_C_STANDARD 11) auto_source_group("." "auto-source-group" "\\.(cc|cpp|c|h)$") -# ===== handle option ===== +# --- options option(DOBBY_DEBUG "Enable debug logging" OFF) @@ -28,38 +28,35 @@ option(Plugin.ImportTableReplace "Enable import table replace " OFF) option(Plugin.Android.BionicLinkerUtil "Enable android bionic linker util" OFF) -option(BUILD_EXAMPLE "Build example" OFF) +option(DOBBY_BUILD_EXAMPLE "Build example" OFF) -option(BUILD_TEST "Build test" OFF) +option(DOBBY_BUILD_TEST "Build test" OFF) -# private -option(Obfuscation "Enable llvm obfuscation" OFF) +# --- private +option(DOBBY_BUILD_KERNEL_MODE "Build xnu kernel mode" OFF) -# private -option(BUILD_KERNEL_MODE "Build xnu kernel mode" OFF) +option(Private.Obfuscation "Enable llvm obfuscation" OFF) -# Enable debug will log more information if ((NOT DEFINED CMAKE_BUILD_TYPE) OR (CMAKE_BUILD_TYPE STREQUAL "Debug")) set(DOBBY_DEBUG ON) endif () -if (DOBBY_DEBUG) - add_definitions(-DDOBBY_DEBUG) - add_definitions(-DLOGGING_DEBUG) - message(STATUS "[Dobby] Enable debug logging") -endif () -# Enable full floating point register pack +set(compile_definitions "") + # for arm64, allow access q8 - q31 if (FullFloatingPointRegisterPack) - add_definitions(-DFULL_FLOATING_POINT_REGISTER_PACK) - message(STATUS "[Dobby] Save and pack all floating-point registers") + set(compile_definitions "${compile_definitions} -DFULL_FLOATING_POINT_REGISTER_PACK") endif () -if (BUILD_KERNEL_MODE) - set(BUILDING_KERNEL ON) - add_definitions(-DBUILDING_KERNEL) - message(STATUS "[Dobby] Build xnu kernel mode") +if (DOBBY_BUILD_KERNEL_MODE) + set(compile_definitions "${compile_definitions} -DBUILDING_KERNEL") +endif () + +if (DOBBY_DEBUG) + set(compile_definitions "${compile_definitions} -DDOBBY_DEBUG") +else () + set(compile_definitions "${compile_definitions} -DDOBBY_LOGGING_DISABLE") endif () if (CMAKE_GENERATOR STREQUAL Xcode) @@ -67,6 +64,18 @@ endif () include(cmake/compiler_and_linker.cmake) +message(STATUS "[Dobby] CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +message(STATUS "[Dobby] DOBBY_DEBUG: ${DOBBY_DEBUG}") +message(STATUS "[Dobby] NearBranch: ${NearBranch}") +message(STATUS "[Dobby] FullFloatingPointRegisterPack: ${FullFloatingPointRegisterPack}") +message(STATUS "[Dobby] Plugin.SymbolResolver: ${Plugin.SymbolResolver}") +message(STATUS "[Dobby] Plugin.ImportTableReplace: ${Plugin.ImportTableReplace}") +message(STATUS "[Dobby] Plugin.Android.BionicLinkerUtil: ${Plugin.Android.BionicLinkerUtil}") +message(STATUS "[Dobby] DOBBY_BUILD_EXAMPLE: ${DOBBY_BUILD_EXAMPLE}") +message(STATUS "[Dobby] DOBBY_BUILD_TEST: ${DOBBY_BUILD_TEST}") +message(STATUS "[Dobby] DOBBY_BUILD_KERNEL_MODE: ${DOBBY_BUILD_KERNEL_MODE}") +message(STATUS "[Dobby] Private.Obfuscation: ${Private.Obfuscation}") + # --- include_directories( @@ -81,7 +90,7 @@ include_directories( ./builtin-plugin ) -if (SYSTEM.Darwin AND BUILDING_KERNEL) +if (SYSTEM.Darwin AND DOBBY_BUILD_KERNEL_MODE) include_directories( source/Backend/KernelMode ) @@ -168,7 +177,7 @@ set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST} source/InterceptEntry.cpp ) -if (SYSTEM.Darwin AND BUILDING_KERNEL) +if (SYSTEM.Darwin AND DOBBY_BUILD_KERNEL_MODE) set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST} # platform util source/Backend/KernelMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc @@ -226,11 +235,11 @@ endif () # --- -if (0 AND SYSTEM.iOS AND (NOT BUILDING_KERNEL)) +if (0 AND SYSTEM.iOS AND (NOT DOBBY_BUILD_KERNEL_MODE)) include_directories( source/Backend/UserMode/ExecMemory/substrated ) - add_definitions(-DCODE_PATCH_WITH_SUBSTRATED) + set(compile_definitions "${compile_definitions} -DCODE_PATCH_WITH_SUBSTRATED") set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST} source/Backend/UserMode/ExecMemory/substrated/mach_interface_support ) @@ -251,7 +260,6 @@ endif () # --- if (NearBranch) - message(STATUS "[Dobby] Enable near branch trampoline") set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST} source/InterceptRouting/RoutingPlugin/NearBranchTrampoline/near_trampoline_arm64.cc source/InterceptRouting/RoutingPlugin/NearBranchTrampoline/NearBranchTrampoline.cc @@ -266,10 +274,10 @@ get_target_property(logging.SOURCE_FILE_LIST logging SOURCES) # add osbase library add_subdirectory(external/osbase) + # --- if (Plugin.SymbolResolver) - message(STATUS "[Dobby] Enable symbol resolver") include_directories(builtin-plugin/SymbolResolver) add_subdirectory(builtin-plugin/SymbolResolver) get_target_property(symbol_resolver.SOURCE_FILE_LIST dobby_symbol_resolver SOURCES) @@ -301,7 +309,7 @@ if (EXISTS "${CMAKE_SOURCE_DIR}/.git") endif () endif () set(DOBBY_BUILD_VERSION "Dobby${VERSION_REVISION}") -add_definitions(-D__DOBBY_BUILD_VERSION__="${DOBBY_BUILD_VERSION}") +set(compile_definitions "${compile_definitions} -D__DOBBY_BUILD_VERSION__=\"${DOBBY_BUILD_VERSION}\"") message(STATUS "[Dobby] ${DOBBY_BUILD_VERSION}") # --- @@ -314,7 +322,9 @@ add_library(dobby SHARED ${dobby.plugin.SOURCE_FILE_LIST} ) -target_include_directories(dobby PUBLIC include) +target_include_directories(dobby PUBLIC + include + ) # --- @@ -326,16 +336,16 @@ add_library(dobby_static STATIC ${dobby.plugin.SOURCE_FILE_LIST} ) -target_include_directories(dobby_static PUBLIC include) +target_include_directories(dobby_static PUBLIC + include + ) -set_target_properties(dobby_static PROPERTIES OUTPUT_NAME "dobby") +set_target_properties(dobby_static + PROPERTIES OUTPUT_NAME "dobby" + ) # --- -if (Obfuscation) - set(linker_flags "${linker_flags} -Wl,-mllvm -Wl,-obfuscator-conf=all") -endif () - set_target_properties(dobby PROPERTIES LINK_FLAGS "${linker_flags}" @@ -347,6 +357,19 @@ set_target_properties(dobby_static COMPILE_FLAGS "${compiler_flags}" ) +target_compile_definitions(dobby PRIVATE + "COMPILE_DEFINITIONS ${compile_definitions}" + ) +target_compile_definitions(dobby_static PRIVATE + "COMPILE_DEFINITIONS ${compile_definitions}" + ) + +# --- + +if (Private.Obfuscation) + set(linker_flags "${linker_flags} -Wl,-mllvm -Wl,-obfuscator-conf=all") +endif () + # --- if (SYSTEM.Android) @@ -369,16 +392,16 @@ endif () # --- -if (BUILD_EXAMPLE AND (NOT BUILDING_KERNEL)) +if (DOBBY_BUILD_EXAMPLE AND (NOT DOBBY_BUILD_KERNEL_MODE)) add_subdirectory(examples) endif () -if (BUILD_TEST AND (NOT BUILDING_KERNEL)) +if (DOBBY_BUILD_TEST AND (NOT DOBBY_BUILD_KERNEL_MODE)) add_subdirectory(tests) endif () # --- -if (SYSTEM.Darwin AND (NOT BUILDING_KERNEL)) +if (SYSTEM.Darwin AND (NOT DOBBY_BUILD_KERNEL_MODE)) include(cmake/platform/platform-darwin.cmake) endif () \ No newline at end of file diff --git a/builtin-plugin/SymbolResolver/CMakeLists.txt b/builtin-plugin/SymbolResolver/CMakeLists.txt index eb32a8c7..2bf6a6ac 100644 --- a/builtin-plugin/SymbolResolver/CMakeLists.txt +++ b/builtin-plugin/SymbolResolver/CMakeLists.txt @@ -4,7 +4,7 @@ if (NOT DEFINED DOBBY_DIR) message(FATAL_ERROR "DOBBY_DIR must be set!") endif () -if (SYSTEM.Darwin AND (NOT BUILDING_KERNEL)) +if (SYSTEM.Darwin AND (NOT DOBBY_BUILD_KERNEL_MODE)) set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST} ${CMAKE_CURRENT_SOURCE_DIR}/macho/macho_ctx.cc ${CMAKE_CURRENT_SOURCE_DIR}/macho/shared_cache_ctx.cpp @@ -14,7 +14,7 @@ if (SYSTEM.Darwin AND (NOT BUILDING_KERNEL)) ${DOBBY_DIR}/source/Backend/UserMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc ) endif () -if (SYSTEM.Darwin AND BUILDING_KERNEL) +if (SYSTEM.Darwin AND DOBBY_BUILD_KERNEL_MODE) set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST} ${CMAKE_CURRENT_SOURCE_DIR}/macho/dobby_symbol_resolver.cc diff --git a/builtin-plugin/SymbolResolver/macho/dobby_symbol_resolver.cc b/builtin-plugin/SymbolResolver/macho/dobby_symbol_resolver.cc index f0fef65d..5fe236c7 100644 --- a/builtin-plugin/SymbolResolver/macho/dobby_symbol_resolver.cc +++ b/builtin-plugin/SymbolResolver/macho/dobby_symbol_resolver.cc @@ -24,11 +24,18 @@ PUBLIC void *DobbySymbolResolver(const char *image_name, const char *symbol_name_pattern) { uintptr_t result = 0; - const std::vector modules = ProcessRuntimeUtility::GetProcessModuleMap(); + auto modules = ProcessRuntimeUtility::GetProcessModuleMap(); for (auto iter = modules.begin(); iter != modules.end(); iter++) { auto module = *iter; - if (image_name != NULL && strnstr(module.path, image_name, strlen(module.path)) == NULL) + + // image filter + if (image_name && !strstr(module.path, image_name)) + continue; + + // dyld in shared cached at new os version + // ignore dyld, as some functions as own implementation in dyld + if (!image_name && strstr(module.path, "dyld")) continue; auto header = (mach_header_t *)module.load_address; @@ -102,7 +109,7 @@ PUBLIC void *DobbySymbolResolver(const char *image_name, const char *symbol_name #endif if (result == 0) { - LOG(LOG_LEVEL_DEBUG, "symbol resolver failed: %s", symbol_name_pattern); + DEBUG_LOG("symbol resolver failed: %s", symbol_name_pattern); } return (void *)result; diff --git a/cmake/compiler_and_linker.cmake b/cmake/compiler_and_linker.cmake index 9f7d1c98..9fc17545 100644 --- a/cmake/compiler_and_linker.cmake +++ b/cmake/compiler_and_linker.cmake @@ -8,6 +8,8 @@ if (NOT DOBBY_DEBUG) set(linker_flags "${linker_flags} -Wl,-x -Wl,-S") endif () +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions") + if (SYSTEM.Darwin) # set(compiler_flags "${compiler_flags} -nostdinc++") elseif (SYSTEM.Android) diff --git a/cmake/platform/platform-darwin.cmake b/cmake/platform/platform-darwin.cmake index 4ea0af66..826c4183 100644 --- a/cmake/platform/platform-darwin.cmake +++ b/cmake/platform/platform-darwin.cmake @@ -21,7 +21,7 @@ set_target_properties(DobbyX PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development" ) -if ((SYSTEM.Darwin AND BUILDING_PLUGIN) AND (NOT BUILDING_KERNEL)) +if ((SYSTEM.Darwin AND BUILDING_PLUGIN) AND (NOT DOBBY_BUILD_KERNEL_MODE)) add_subdirectory(builtin-plugin/Dyld2HideLibrary) add_subdirectory(builtin-plugin/ObjcRuntimeHook) if (PROCESSOR.AARCH64) diff --git a/docs/compile.md b/docs/compile.md index aa7af74d..002dba46 100644 --- a/docs/compile.md +++ b/docs/compile.md @@ -17,9 +17,9 @@ option(Plugin.ImportTableReplace "Enable import table replace " OFF) option(Plugin.Android.BionicLinkerUtil "Enable android bionic linker util" OFF) -option(BUILD_EXAMPLE "Build example" OFF) +option(DOBBY_BUILD_EXAMPLE "Build example" OFF) -option(BUILD_TEST "Build test" OFF) +option(DOBBY_BUILD_TEST "Build test" OFF) ``` ## Build with `scripts/platform_builder.py` diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index dc976191..b461a1c6 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,6 +5,7 @@ add_executable(socket_example target_link_libraries(socket_example dobby + logging ) diff --git a/external/TINYSTL/algorithm.h b/external/TINYSTL/algorithm.h new file mode 100644 index 00000000..7b9637ef --- /dev/null +++ b/external/TINYSTL/algorithm.h @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/external/TINYSTL/vector.h b/external/TINYSTL/vector.h index 32eae1f1..6e3b0e15 100644 --- a/external/TINYSTL/vector.h +++ b/external/TINYSTL/vector.h @@ -33,304 +33,321 @@ #include namespace tinystl { - template - class vector { - public: - vector(); - vector(const vector& other); - vector(vector&& other); - vector(size_t size); - vector(size_t size, const T& value); - vector(const T* first, const T* last); - ~vector(); - - vector& operator=(const vector& other); - vector& operator=(vector&& other); - - void assign(const T* first, const T* last); - - const T* data() const; - T* data(); - size_t size() const; - size_t capacity() const; - bool empty() const; - - T& operator[](size_t idx); - const T& operator[](size_t idx) const; - - const T& front() const; - T& front(); - const T& back() const; - T& back(); - - void resize(size_t size); - void resize(size_t size, const T& value); - void clear(); - void reserve(size_t capacity); - - void push_back(const T& t); - void pop_back(); - - void emplace_back(); - template - void emplace_back(const Param& param); - - void shrink_to_fit(); - - void swap(vector& other); - - typedef T value_type; - - typedef T* iterator; - iterator begin(); - iterator end(); - - typedef const T* const_iterator; - const_iterator begin() const; - const_iterator end() const; - - void insert(iterator where); - void insert(iterator where, const T& value); - void insert(iterator where, const T* first, const T* last); - - template - void emplace(iterator where, const Param& param); - - iterator erase(iterator where); - iterator erase(iterator first, iterator last); - - iterator erase_unordered(iterator where); - iterator erase_unordered(iterator first, iterator last); - - private: - buffer m_buffer; - }; - - template - inline vector::vector() { - buffer_init(&m_buffer); - } - - template - inline vector::vector(const vector& other) { - buffer_init(&m_buffer); - buffer_reserve(&m_buffer, other.size()); - buffer_insert(&m_buffer, m_buffer.last, other.m_buffer.first, other.m_buffer.last); - } - - template - inline vector::vector(vector&& other) { - buffer_move(&m_buffer, &other.m_buffer); - } - - template - inline vector::vector(size_t size) { - buffer_init(&m_buffer); - buffer_resize(&m_buffer, size); - } - - template - inline vector::vector(size_t size, const T& value) { - buffer_init(&m_buffer); - buffer_resize(&m_buffer, size, value); - } - - template - inline vector::vector(const T* first, const T* last) { - buffer_init(&m_buffer); - buffer_insert(&m_buffer, m_buffer.last, first, last); - } - - template - inline vector::~vector() { - buffer_destroy(&m_buffer); - } - - template - inline vector& vector::operator=(const vector& other) { - vector(other).swap(*this); - return *this; - } - - template - vector& vector::operator=(vector&& other) { - buffer_destroy(&m_buffer); - buffer_move(&m_buffer, &other.m_buffer); - return *this; - } - - template - inline void vector::assign(const T* first, const T* last) { - buffer_clear(&m_buffer); - buffer_insert(&m_buffer, m_buffer.last, first, last); - } - - template - inline const T* vector::data() const { - return m_buffer.first; - } - - template - inline T* vector::data() { - return m_buffer.first; - } - - template - inline size_t vector::size() const { - return (size_t)(m_buffer.last - m_buffer.first); - } - - template - inline size_t vector::capacity() const { - return (size_t)(m_buffer.capacity - m_buffer.first); - } - - template - inline bool vector::empty() const { - return m_buffer.last == m_buffer.first; - } - - template - inline T& vector::operator[](size_t idx) { - return m_buffer.first[idx]; - } - - template - inline const T& vector::operator[](size_t idx) const { - return m_buffer.first[idx]; - } - - template - inline const T& vector::front() const { - return m_buffer.first[0]; - } - - template - inline T& vector::front() { - return m_buffer.first[0]; - } - - template - inline const T& vector::back() const { - return m_buffer.last[-1]; - } - - template - inline T& vector::back() { - return m_buffer.last[-1]; - } - - template - inline void vector::resize(size_t size) { - buffer_resize(&m_buffer, size); - } - - template - inline void vector::resize(size_t size, const T& value) { - buffer_resize(&m_buffer, size, value); - } - - template - inline void vector::clear() { - buffer_clear(&m_buffer); - } - - template - inline void vector::reserve(size_t capacity) { - buffer_reserve(&m_buffer, capacity); - } - - template - inline void vector::push_back(const T& t) { - buffer_append(&m_buffer, &t); - } - - template - inline void vector::emplace_back() { - buffer_append(&m_buffer); - } - - template - template - inline void vector::emplace_back(const Param& param) { - buffer_append(&m_buffer, ¶m); - } - - template - inline void vector::pop_back() { - buffer_erase(&m_buffer, m_buffer.last - 1, m_buffer.last); - } - - template - inline void vector::shrink_to_fit() { - buffer_shrink_to_fit(&m_buffer); - } - - template - inline void vector::swap(vector& other) { - buffer_swap(&m_buffer, &other.m_buffer); - } - - template - inline typename vector::iterator vector::begin() { - return m_buffer.first; - } - - template - inline typename vector::iterator vector::end() { - return m_buffer.last; - } - - template - inline typename vector::const_iterator vector::begin() const { - return m_buffer.first; - } - - template - inline typename vector::const_iterator vector::end() const { - return m_buffer.last; - } - - template - inline void vector::insert(typename vector::iterator where) { - buffer_insert(&m_buffer, where, 1); - } - - template - inline void vector::insert(iterator where, const T& value) { - buffer_insert(&m_buffer, where, &value, &value + 1); - } - - template - inline void vector::insert(iterator where, const T* first, const T* last) { - buffer_insert(&m_buffer, where, first, last); - } - - template - inline typename vector::iterator vector::erase(iterator where) { - return buffer_erase(&m_buffer, where, where + 1); - } - - template - inline typename vector::iterator vector::erase(iterator first, iterator last) { - return buffer_erase(&m_buffer, first, last); - } - - template - inline typename vector::iterator vector::erase_unordered(iterator where) { - return buffer_erase_unordered(&m_buffer, where, where + 1); - } - - template - inline typename vector::iterator vector::erase_unordered(iterator first, iterator last) { - return buffer_erase_unordered(&m_buffer, first, last); - } - - template - template - void vector::emplace(typename vector::iterator where, const Param& param) { - buffer_insert(&m_buffer, where, ¶m, ¶m + 1); - } +template class vector { + using iterator = T *; + +public: + vector(); + vector(const vector &other); + vector(vector &&other); + vector(size_t size); + vector(size_t size, const T &value); + vector(const T *first, const T *last); + ~vector(); + + vector &operator=(const vector &other); + vector &operator=(vector &&other); + + void assign(const T *first, const T *last); + + const T *data() const; + T *data(); + size_t size() const; + size_t capacity() const; + bool empty() const; + + T &operator[](size_t idx); + const T &operator[](size_t idx) const; + + const T &front() const; + T &front(); + const T &back() const; + T &back(); + + void resize(size_t size); + void resize(size_t size, const T &value); + void clear(); + void reserve(size_t capacity); + + void push_back(const T &t); + void pop_back(); + + void emplace_back(); + template void emplace_back(const Param ¶m); + + void shrink_to_fit(); + + void swap(vector &other); + + typedef T value_type; + + iterator begin(); + iterator end(); + + typedef const T *const_iterator; + const_iterator begin() const; + const_iterator end() const; + + void insert(iterator where); + void insert(iterator where, const T &value); + void insert(iterator where, const T *first, const T *last); + + template void emplace(iterator where, const Param ¶m); + + iterator erase(iterator where); + iterator erase(iterator first, iterator last); + + iterator erase_unordered(iterator where); + iterator erase_unordered(iterator first, iterator last); + + iterator find(const T &other) const; + void sort(int (*compare)(const T &elem0, const T &elem1)); + void sort(unsigned begin, unsigned end, int (*compare)(const T &elem0, const T &elem1)); + +private: + int partition(int (*compare)(const T &elem0, const T &elem1), int p, int r); + void quick_sort(int (*compare)(const T &elem0, const T &elem1), int p, int r); + +private: + buffer m_buffer; +}; + +template inline vector::vector() { + buffer_init(&m_buffer); +} + +template inline vector::vector(const vector &other) { + buffer_init(&m_buffer); + buffer_reserve(&m_buffer, other.size()); + buffer_insert(&m_buffer, m_buffer.last, other.m_buffer.first, other.m_buffer.last); +} + +template inline vector::vector(vector &&other) { + buffer_move(&m_buffer, &other.m_buffer); +} + +template inline vector::vector(size_t size) { + buffer_init(&m_buffer); + buffer_resize(&m_buffer, size); +} + +template inline vector::vector(size_t size, const T &value) { + buffer_init(&m_buffer); + buffer_resize(&m_buffer, size, value); +} + +template inline vector::vector(const T *first, const T *last) { + buffer_init(&m_buffer); + buffer_insert(&m_buffer, m_buffer.last, first, last); +} + +template inline vector::~vector() { + buffer_destroy(&m_buffer); +} + +template inline vector &vector::operator=(const vector &other) { + vector(other).swap(*this); + return *this; +} + +template vector &vector::operator=(vector &&other) { + buffer_destroy(&m_buffer); + buffer_move(&m_buffer, &other.m_buffer); + return *this; +} + +template inline void vector::assign(const T *first, const T *last) { + buffer_clear(&m_buffer); + buffer_insert(&m_buffer, m_buffer.last, first, last); +} + +template inline const T *vector::data() const { + return m_buffer.first; +} + +template inline T *vector::data() { + return m_buffer.first; +} + +template inline size_t vector::size() const { + return (size_t)(m_buffer.last - m_buffer.first); +} + +template inline size_t vector::capacity() const { + return (size_t)(m_buffer.capacity - m_buffer.first); +} + +template inline bool vector::empty() const { + return m_buffer.last == m_buffer.first; +} + +template inline T &vector::operator[](size_t idx) { + return m_buffer.first[idx]; +} + +template inline const T &vector::operator[](size_t idx) const { + return m_buffer.first[idx]; +} + +template inline const T &vector::front() const { + return m_buffer.first[0]; +} + +template inline T &vector::front() { + return m_buffer.first[0]; +} + +template inline const T &vector::back() const { + return m_buffer.last[-1]; +} + +template inline T &vector::back() { + return m_buffer.last[-1]; +} + +template inline void vector::resize(size_t size) { + buffer_resize(&m_buffer, size); +} + +template inline void vector::resize(size_t size, const T &value) { + buffer_resize(&m_buffer, size, value); +} + +template inline void vector::clear() { + buffer_clear(&m_buffer); +} + +template inline void vector::reserve(size_t capacity) { + buffer_reserve(&m_buffer, capacity); +} + +template inline void vector::push_back(const T &t) { + buffer_append(&m_buffer, &t); +} + +template inline void vector::emplace_back() { + buffer_append(&m_buffer); +} + +template +template +inline void vector::emplace_back(const Param ¶m) { + buffer_append(&m_buffer, ¶m); +} + +template inline void vector::pop_back() { + buffer_erase(&m_buffer, m_buffer.last - 1, m_buffer.last); +} + +template inline void vector::shrink_to_fit() { + buffer_shrink_to_fit(&m_buffer); +} + +template inline void vector::swap(vector &other) { + buffer_swap(&m_buffer, &other.m_buffer); +} + +template inline typename vector::iterator vector::begin() { + return m_buffer.first; +} + +template inline typename vector::iterator vector::end() { + return m_buffer.last; +} + +template inline typename vector::const_iterator vector::begin() const { + return m_buffer.first; +} + +template inline typename vector::const_iterator vector::end() const { + return m_buffer.last; +} + +template inline void vector::insert(typename vector::iterator where) { + buffer_insert(&m_buffer, where, 1); +} + +template inline void vector::insert(iterator where, const T &value) { + buffer_insert(&m_buffer, where, &value, &value + 1); +} + +template +inline void vector::insert(iterator where, const T *first, const T *last) { + buffer_insert(&m_buffer, where, first, last); +} + +template +inline typename vector::iterator vector::erase(iterator where) { + return buffer_erase(&m_buffer, where, where + 1); +} + +template +inline typename vector::iterator vector::erase(iterator first, iterator last) { + return buffer_erase(&m_buffer, first, last); +} + +template +inline typename vector::iterator vector::erase_unordered(iterator where) { + return buffer_erase_unordered(&m_buffer, where, where + 1); +} + +template +inline typename vector::iterator vector::erase_unordered(iterator first, iterator last) { + return buffer_erase_unordered(&m_buffer, first, last); +} + +template +template +void vector::emplace(typename vector::iterator where, const Param ¶m) { + buffer_insert(&m_buffer, where, ¶m, ¶m + 1); +} + +template +inline typename vector::iterator vector::find(const T &other) const { + for (unsigned i = 0; i < size(); ++i) + if (m_buffer.first[i] == other) + return &m_buffer.first[i]; + + return m_buffer.last; +} + +template +inline int vector::partition(int (*compare)(const T &elem0, const T &elem1), int p, int r) { + T tmp, pivot = m_buffer.first[p]; + int left = p; + + for (int i = p + 1; i <= r; i++) { + if (compare(m_buffer.first[i], pivot) < 0) { + left++; + tmp = m_buffer.first[i]; + m_buffer.first[i] = m_buffer.first[left]; + m_buffer.first[left] = tmp; + } + } + tmp = m_buffer.first[p]; + m_buffer.first[p] = m_buffer.first[left]; + m_buffer.first[left] = tmp; + return left; +} + +template +inline void vector::quick_sort(int (*compare)(const T &elem0, const T &elem1), int p, int r) { + if (p < r) { + int q = partition(compare, p, r); + quick_sort(compare, p, q - 1); + quick_sort(compare, q + 1, r); + } +} + +template +inline void vector::sort(int (*compare)(const T &elem0, const T &elem1)) { + quick_sort(compare, 0, (int)size() - 1); +} + +template +inline void vector::sort(unsigned begin, unsigned end, int (*compare)(const T &elem0, const T &elem1)) { + quick_sort(compare, (int)begin, (int)end); } +} // namespace tinystl #endif // TINYSTL_VECTOR_H diff --git a/external/deprecated/misc-helper/CMakeLists.txt b/external/deprecated/misc-helper/CMakeLists.txt index 115c9fdb..fca13b62 100644 --- a/external/deprecated/misc-helper/CMakeLists.txt +++ b/external/deprecated/misc-helper/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(.) -if(NOT BUILDING_KERNEL) +if(NOT DOBBY_BUILD_KERNEL_MODE) set(SOURCE_FILE_LIST ${CMAKE_CURRENT_SOURCE_DIR}/variable_cache.c ${CMAKE_CURRENT_SOURCE_DIR}/async_logger.cc diff --git a/external/logging/CMakeLists.txt b/external/logging/CMakeLists.txt index a227246d..a11dfa97 100644 --- a/external/logging/CMakeLists.txt +++ b/external/logging/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(.) -if(NOT BUILDING_KERNEL) +if(NOT DOBBY_BUILD_KERNEL_MODE) set(SOURCE_FILE_LIST ${CMAKE_CURRENT_SOURCE_DIR}/logging.cc ) diff --git a/external/logging/logging.cc b/external/logging/logging.cc index de163fb8..fb57c0ed 100644 --- a/external/logging/logging.cc +++ b/external/logging/logging.cc @@ -93,8 +93,13 @@ void Logger::logv(LogLevel level, const char *_fmt, va_list ap) { if (log_file_ != nullptr) { char buffer[0x4000] = {0}; vsnprintf(buffer, sizeof(buffer) - 1, fmt_buffer, ap); +#if defined(USER_CXX_FILESTREAM) log_file_stream_->write(buffer, strlen(buffer)); log_file_stream_->flush(); +#else + fwrite(buffer, strlen(buffer), 1, log_file_stream_); + fflush(log_file_stream_); +#endif } if (1 || !enable_syslog_ && log_file_ == nullptr) { diff --git a/external/logging/logging/logging.h b/external/logging/logging/logging.h index f4a8cf1d..99ec360a 100644 --- a/external/logging/logging/logging.h +++ b/external/logging/logging/logging.h @@ -1,14 +1,12 @@ #pragma once +#include #include #include #include #define LOG_TAG NULL -#ifdef __cplusplus -extern "C" { -#endif typedef enum { LOG_LEVEL_DEBUG = 0, LOG_LEVEL_INFO = 1, @@ -16,20 +14,23 @@ typedef enum { LOG_LEVEL_ERROR = 3, LOG_LEVEL_FATAL = 4 } LogLevel; -#ifdef __cplusplus -} -#endif #ifdef __cplusplus +#if defined(USE_CXX_FILESTREAM) #include +#endif class Logger { public: const char *log_tag_; const char *log_file_; +#if defined(USE_CXX_FILESTREAM) std::fstream *log_file_stream_; +#else + FILE *log_file_stream_; +#endif LogLevel log_level_; @@ -77,8 +78,12 @@ class Logger { void setLogFile(const char *file) { log_file_ = file; +#if defined(USE_CXX_FILESTREAM) log_file_stream_ = new std::fstream(); log_file_stream_->open(log_file_, std::ios::out | std::ios::app); +#else + log_file_stream_ = fopen(log_file_, "a"); +#endif } void setLogLevel(LogLevel level) { @@ -144,19 +149,19 @@ class Logger { extern "C" { #endif +#if defined(DOBBY_LOGGING_DISABLE) +#define LOG_FUNCTION_IMPL(...) +#else #if !defined(LOG_FUNCTION_IMPL) #define LOG_FUNCTION_IMPL logger_log_impl #endif +#endif void *logger_create(const char *tag, const char *file, LogLevel level, bool enable_time_tag, bool enable_syslog); void logger_set_options(void *logger, const char *tag, const char *file, LogLevel level, bool enable_time_tag, bool enable_syslog); void logger_log_impl(void *logger, LogLevel level, const char *fmt, ...); -#if defined(LOGGING_DISABLE) -#define LOG_FUNCTION_IMPL(...) -#endif - #ifdef __cplusplus } #endif diff --git a/source/Backend/KernelMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc b/source/Backend/KernelMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc index 8ffff99d..3635c7b6 100644 --- a/source/Backend/KernelMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc +++ b/source/Backend/KernelMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc @@ -72,8 +72,8 @@ static inline vm_map_entry_t vm_map_first_entry(vm_map_t map) { // --- -static std::vector regions; -const std::vector &ProcessRuntimeUtility::GetProcessMemoryLayout() { +static tinystl::vector regions; +const tinystl::vector &ProcessRuntimeUtility::GetProcessMemoryLayout() { return regions; } @@ -84,8 +84,8 @@ const std::vector &ProcessRuntimeUtility::GetProcessMemoryLayout() { extern "C" void *kernel_info_load_base(); ; -std::vector modules; -const std::vector *ProcessRuntimeUtility::GetProcessModuleMap() { +tinystl::vector modules; +const tinystl::vector *ProcessRuntimeUtility::GetProcessModuleMap() { modules.clear(); // brute force kernel base ? so rude :) @@ -128,6 +128,6 @@ const std::vector *ProcessRuntimeUtility::GetProcessModuleMap() { } RuntimeModule ProcessRuntimeUtility::GetProcessModule(const char *name) { - const std::vector *modules = GetProcessModuleMap(); + const tinystl::vector *modules = GetProcessModuleMap(); return RuntimeModule{0}; } diff --git a/source/Backend/KernelMode/PlatformUtil/ProcessRuntimeUtility.h b/source/Backend/KernelMode/PlatformUtil/ProcessRuntimeUtility.h index e51a494c..af2df8ef 100644 --- a/source/Backend/KernelMode/PlatformUtil/ProcessRuntimeUtility.h +++ b/source/Backend/KernelMode/PlatformUtil/ProcessRuntimeUtility.h @@ -17,9 +17,9 @@ struct MemRegion : MemRange { class ProcessRuntimeUtility { public: - static const std::vector &GetProcessMemoryLayout(); + static const tinystl::vector &GetProcessMemoryLayout(); - static const std::vector *GetProcessModuleMap(); + static const tinystl::vector *GetProcessModuleMap(); static RuntimeModule GetProcessModule(const char *name); }; \ No newline at end of file diff --git a/source/Backend/UserMode/MultiThreadSupport/ThreadSupport.h b/source/Backend/UserMode/MultiThreadSupport/ThreadSupport.h index fa67a0cf..ed02a794 100644 --- a/source/Backend/UserMode/MultiThreadSupport/ThreadSupport.h +++ b/source/Backend/UserMode/MultiThreadSupport/ThreadSupport.h @@ -18,7 +18,7 @@ typedef struct _StackFrame { // (thead) CallStack base in thread typedef struct _CallStack { - std::vector stackframes; + tinystl::vector stackframes; } CallStack; // ThreadSupport base on vm_core, support mutipl platforms. diff --git a/source/Backend/UserMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc b/source/Backend/UserMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc index c11bfd4a..1046221f 100644 --- a/source/Backend/UserMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc +++ b/source/Backend/UserMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc @@ -35,9 +35,9 @@ static bool memory_region_comparator(MemRegion a, MemRegion b) { return (a.start < b.start); } -std::vector regions; +tinystl::vector regions; -const std::vector &ProcessRuntimeUtility::GetProcessMemoryLayout() { +const tinystl::vector &ProcessRuntimeUtility::GetProcessMemoryLayout() { regions.clear(); vm_region_submap_info_64 region_submap_info; @@ -84,11 +84,11 @@ const std::vector &ProcessRuntimeUtility::GetProcessMemoryLayout() { return regions; } -static std::vector *modules; +static tinystl::vector *modules; -const std::vector &ProcessRuntimeUtility::GetProcessModuleMap() { +const tinystl::vector &ProcessRuntimeUtility::GetProcessModuleMap() { if (modules == nullptr) { - modules = new std::vector(); + modules = new tinystl::vector(); } modules->clear(); @@ -123,10 +123,7 @@ const std::vector &ProcessRuntimeUtility::GetProcessModuleMap() { } } - std::sort(modules->begin(), modules->end(), [](RuntimeModule a, RuntimeModule b) { - ; - return a.load_address < b.load_address; - }); + modules->sort([](const RuntimeModule &a, const RuntimeModule &b) -> int { return a.load_address < b.load_address; }); return *modules; } diff --git a/source/Backend/UserMode/PlatformUtil/Linux/ProcessRuntimeUtility.cc b/source/Backend/UserMode/PlatformUtil/Linux/ProcessRuntimeUtility.cc index 60cfd0ac..862c29fb 100644 --- a/source/Backend/UserMode/PlatformUtil/Linux/ProcessRuntimeUtility.cc +++ b/source/Backend/UserMode/PlatformUtil/Linux/ProcessRuntimeUtility.cc @@ -20,8 +20,8 @@ static bool memory_region_comparator(MemRange a, MemRange b) { return (a.start < b.start); } -std::vector regions; -const std::vector &ProcessRuntimeUtility::GetProcessMemoryLayout() { +tinystl::vector regions; +const tinystl::vector &ProcessRuntimeUtility::GetProcessMemoryLayout() { regions.clear(); FILE *fp = fopen("/proc/self/maps", "r"); @@ -97,10 +97,10 @@ const std::vector &ProcessRuntimeUtility::GetProcessMemoryLayout() { // ================================================================ // GetProcessModuleMap -static std::vector *modules; -static std::vector &get_process_map_with_proc_maps() { +static tinystl::vector *modules; +static tinystl::vector &get_process_map_with_proc_maps() { if (modules == nullptr) { - modules = new std::vector(); + modules = new tinystl::vector(); } FILE *fp = fopen("/proc/self/maps", "r"); @@ -182,8 +182,8 @@ static std::vector &get_process_map_with_proc_maps() { } #if defined(__LP64__) -static std::vector get_process_map_with_linker_iterator() { - std::vector ProcessModuleMap; +static tinystl::vector get_process_map_with_linker_iterator() { + tinystl::vector ProcessModuleMap; static int (*dl_iterate_phdr_ptr)(int (*)(struct dl_phdr_info *, size_t, void *), void *); dl_iterate_phdr_ptr = (__typeof(dl_iterate_phdr_ptr))dlsym(RTLD_DEFAULT, "dl_iterate_phdr"); @@ -207,7 +207,7 @@ static std::vector get_process_map_with_linker_iterator() { } // push to vector - auto ProcessModuleMap = reinterpret_cast *>(data); + auto ProcessModuleMap = reinterpret_cast *>(data); ProcessModuleMap->push_back(module); return 0; }, @@ -217,7 +217,7 @@ static std::vector get_process_map_with_linker_iterator() { } #endif -const std::vector &ProcessRuntimeUtility::GetProcessModuleMap() { +const tinystl::vector &ProcessRuntimeUtility::GetProcessModuleMap() { #if defined(__LP64__) && 0 // TODO: won't resolve main binary return get_process_map_with_linker_iterator(); diff --git a/source/Backend/UserMode/PlatformUtil/ProcessRuntimeUtility.h b/source/Backend/UserMode/PlatformUtil/ProcessRuntimeUtility.h index 190c6b1c..f861d7a1 100644 --- a/source/Backend/UserMode/PlatformUtil/ProcessRuntimeUtility.h +++ b/source/Backend/UserMode/PlatformUtil/ProcessRuntimeUtility.h @@ -18,9 +18,9 @@ struct MemRegion : MemRange { class ProcessRuntimeUtility { public: - static const std::vector &GetProcessMemoryLayout(); + static const tinystl::vector &GetProcessMemoryLayout(); - static const std::vector &GetProcessModuleMap(); + static const tinystl::vector &GetProcessModuleMap(); static RuntimeModule GetProcessModule(const char *name); }; \ No newline at end of file diff --git a/source/Backend/UserMode/PlatformUtil/Windows/ProcessRuntimeUtility.cc b/source/Backend/UserMode/PlatformUtil/Windows/ProcessRuntimeUtility.cc index 96235b87..632bfc55 100755 --- a/source/Backend/UserMode/PlatformUtil/Windows/ProcessRuntimeUtility.cc +++ b/source/Backend/UserMode/PlatformUtil/Windows/ProcessRuntimeUtility.cc @@ -15,8 +15,8 @@ static bool memory_region_comparator(MemRange a, MemRange b) { // https://gist.github.com/jedwardsol/9d4fe1fd806043a5767affbd200088ca -std::vector ProcessMemoryLayout; -std::vector ProcessRuntimeUtility::GetProcessMemoryLayout() { +tinystl::vector ProcessMemoryLayout; +tinystl::vector ProcessRuntimeUtility::GetProcessMemoryLayout() { if (!ProcessMemoryLayout.empty()) { ProcessMemoryLayout.clear(); } @@ -61,9 +61,9 @@ std::vector ProcessRuntimeUtility::GetProcessMemoryLayout() { // ================================================================ // GetProcessModuleMap -std::vector ProcessModuleMap; +tinystl::vector ProcessModuleMap; -std::vector ProcessRuntimeUtility::GetProcessModuleMap() { +tinystl::vector ProcessRuntimeUtility::GetProcessModuleMap() { if (!ProcessMemoryLayout.empty()) { ProcessMemoryLayout.clear(); } @@ -71,7 +71,7 @@ std::vector ProcessRuntimeUtility::GetProcessModuleMap() { } RuntimeModule ProcessRuntimeUtility::GetProcessModule(const char *name) { - std::vector ProcessModuleMap = GetProcessModuleMap(); + tinystl::vector ProcessModuleMap = GetProcessModuleMap(); for (auto module : ProcessModuleMap) { if (strstr(module.path, name) != 0) { return module; diff --git a/source/InstructionRelocation/arm/InstructionRelocationARM.h b/source/InstructionRelocation/arm/InstructionRelocationARM.h index 45fadabd..ed289aa8 100644 --- a/source/InstructionRelocation/arm/InstructionRelocationARM.h +++ b/source/InstructionRelocation/arm/InstructionRelocationARM.h @@ -296,7 +296,7 @@ class ThumbTurboAssembler : public ThumbAssembler { } private: - std::vector data_labels_; + tinystl::vector data_labels_; }; #if 0 diff --git a/source/InterceptRouting/RoutingPlugin/RoutingPlugin.cc b/source/InterceptRouting/RoutingPlugin/RoutingPlugin.cc index c3657648..e6e8ffd8 100644 --- a/source/InterceptRouting/RoutingPlugin/RoutingPlugin.cc +++ b/source/InterceptRouting/RoutingPlugin/RoutingPlugin.cc @@ -1,6 +1,6 @@ #include "InterceptRouting/RoutingPlugin/RoutingPlugin.h" -std::vector RoutingPluginManager::plugins; +tinystl::vector RoutingPluginManager::plugins; RoutingPluginInterface *RoutingPluginManager::near_branch_trampoline = NULL; diff --git a/source/InterceptRouting/RoutingPlugin/RoutingPlugin.h b/source/InterceptRouting/RoutingPlugin/RoutingPlugin.h index 816577e9..17ac97e4 100644 --- a/source/InterceptRouting/RoutingPlugin/RoutingPlugin.h +++ b/source/InterceptRouting/RoutingPlugin/RoutingPlugin.h @@ -24,7 +24,7 @@ class RoutingPluginManager { static void registerPlugin(const char *name, RoutingPluginInterface *plugin); public: - static std::vector plugins; + static tinystl::vector plugins; static RoutingPluginInterface *near_branch_trampoline; }; diff --git a/source/PlatformUnifiedInterface/MemoryAllocator.h b/source/PlatformUnifiedInterface/MemoryAllocator.h index 9b536bba..56da2e5d 100644 --- a/source/PlatformUnifiedInterface/MemoryAllocator.h +++ b/source/PlatformUnifiedInterface/MemoryAllocator.h @@ -37,7 +37,7 @@ struct MemoryArena : MemRange { addr_t addr; addr_t cursor_addr; - std::vector memory_blocks; + tinystl::vector memory_blocks; MemoryArena(addr_t addr, size_t size) : MemRange(addr, size), addr(addr), cursor_addr(addr) { } @@ -79,8 +79,8 @@ class MemoryAllocator { friend class NearMemoryAllocator; private: - std::vector code_arenas; - std::vector data_arenas; + tinystl::vector code_arenas; + tinystl::vector data_arenas; private: static MemoryAllocator *shared_allocator; diff --git a/source/TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h b/source/TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h index 2555d284..160ba0ab 100644 --- a/source/TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h +++ b/source/TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h @@ -32,7 +32,7 @@ asm_func_t get_closure_bridge(); class ClosureTrampoline { private: - static std::vector *trampolines_; + static tinystl::vector *trampolines_; public: static ClosureTrampolineEntry *CreateClosureTrampoline(void *carry_data, void *carry_handler); diff --git a/source/core/arch/x86/cpu-x86.cc b/source/core/arch/x86/cpu-x86.cc index 47ac89c3..d7005819 100644 --- a/source/core/arch/x86/cpu-x86.cc +++ b/source/core/arch/x86/cpu-x86.cc @@ -4,95 +4,7 @@ #include "cpu-x86.h" X86CpuInfo::X86CpuInfo() { - icache_line_size_ = 0; - dcache_line_size_ = 0; - has_fpu_ = false; - has_cmov_ = false; - has_sahf_ = false; - has_mmx_ = false; - has_sse_ = false; - has_sse2_ = false; - has_sse3_ = false; - has_ssse3_ = false; - has_sse41_ = false; - has_sse42_ = false; - has_osxsave_ = false; - has_avx_ = false; - has_fma3_ = false; - has_bmi1_ = false; - has_bmi2_ = false; - has_lzcnt_ = false; - has_popcnt_ = false; - is_atom_ = false; - - memcpy(vendor_, (void *)"Unknown", 8); -#if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 - int cpu_info[4]; - __cpuid(cpu_info, 0); - unsigned num_ids = cpu_info[0]; - std::swap(cpu_info[2], cpu_info[3]); - _memcpy(vendor_, cpu_info + 1, 12); - vendor_[12] = '\0'; - - // Interpret CPU feature information. - if (num_ids > 0) { - __cpuid(cpu_info, 1); - stepping_ = cpu_info[0] & 0xF; - model_ = ((cpu_info[0] >> 4) & 0xF) + ((cpu_info[0] >> 12) & 0xF0); - family_ = (cpu_info[0] >> 8) & 0xF; - type_ = (cpu_info[0] >> 12) & 0x3; - ext_model_ = (cpu_info[0] >> 16) & 0xF; - ext_family_ = (cpu_info[0] >> 20) & 0xFF; - has_fpu_ = (cpu_info[3] & 0x00000001) != 0; - has_cmov_ = (cpu_info[3] & 0x00008000) != 0; - has_mmx_ = (cpu_info[3] & 0x00800000) != 0; - has_sse_ = (cpu_info[3] & 0x02000000) != 0; - has_sse2_ = (cpu_info[3] & 0x04000000) != 0; - has_sse3_ = (cpu_info[2] & 0x00000001) != 0; - has_ssse3_ = (cpu_info[2] & 0x00000200) != 0; - has_sse41_ = (cpu_info[2] & 0x00080000) != 0; - has_sse42_ = (cpu_info[2] & 0x00100000) != 0; - has_popcnt_ = (cpu_info[2] & 0x00800000) != 0; - has_osxsave_ = (cpu_info[2] & 0x08000000) != 0; - has_avx_ = (cpu_info[2] & 0x10000000) != 0; - has_fma3_ = (cpu_info[2] & 0x00001000) != 0; - if (family_ == 0x6) { - switch (model_) { - case 0x1C: // SLT - case 0x26: - case 0x36: - case 0x27: - case 0x35: - case 0x37: // SLM - case 0x4A: - case 0x4D: - case 0x4C: // AMT - case 0x6E: - is_atom_ = true; - } - } - } - - // There are separate feature flags for VEX-encoded GPR instructions. - if (num_ids >= 7) { - __cpuid(cpu_info, 7); - has_bmi1_ = (cpu_info[1] & 0x00000008) != 0; - has_bmi2_ = (cpu_info[1] & 0x00000100) != 0; - } - - // Query extended IDs. - __cpuid(cpu_info, 0x80000000); - unsigned num_ext_ids = cpu_info[0]; - - // Interpret extended CPU feature information. - if (num_ext_ids > 0x80000000) { - __cpuid(cpu_info, 0x80000001); - has_lzcnt_ = (cpu_info[2] & 0x00000020) != 0; - // SAHF must be probed in long mode. - has_sahf_ = (cpu_info[2] & 0x00000001) != 0; - } -#endif } #endif \ No newline at end of file diff --git a/source/core/assembler/AssemblerPseudoLabel.h b/source/core/assembler/AssemblerPseudoLabel.h index f00be583..8774774d 100644 --- a/source/core/assembler/AssemblerPseudoLabel.h +++ b/source/core/assembler/AssemblerPseudoLabel.h @@ -57,7 +57,7 @@ class AssemblerPseudoLabel : public Label { struct RelocLabel : public AssemblerPseudoLabel { public: RelocLabel() : AssemblerPseudoLabel(0) { - memset(&data_, 0, sizeof(data_)); + memset(data_, 0, sizeof(data_)); data_size_ = 0; } diff --git a/source/core/assembler/assembler.h b/source/core/assembler/assembler.h index 23002ffa..e3e22dfb 100644 --- a/source/core/assembler/assembler.h +++ b/source/core/assembler/assembler.h @@ -41,7 +41,7 @@ class AssemblerBase { void AppendRelocLabel(RelocLabel *label); protected: - std::vector data_labels_; + tinystl::vector data_labels_; public: virtual void *GetRealizedAddress(); diff --git a/source/dobby.cpp b/source/dobby.cpp index f1f426d3..c843796a 100644 --- a/source/dobby.cpp +++ b/source/dobby.cpp @@ -2,10 +2,10 @@ #include "Interceptor.h" __attribute__((constructor)) static void ctor() { - INFO_LOG("================================"); - INFO_LOG("Dobby"); - INFO_LOG("dobby in debug log mode, disable with cmake flag \"-DDOBBY_DEBUG=OFF\""); - INFO_LOG("================================"); + DEBUG_LOG("================================"); + DEBUG_LOG("Dobby"); + DEBUG_LOG("dobby in debug log mode, disable with cmake flag \"-DDOBBY_DEBUG=OFF\""); + DEBUG_LOG("================================"); } PUBLIC const char *DobbyGetVersion() { diff --git a/source/dobby/platform_features.h b/source/dobby/platform_features.h index c9b8d7f8..94d8abe3 100644 --- a/source/dobby/platform_features.h +++ b/source/dobby/platform_features.h @@ -43,9 +43,8 @@ #endif #else #ifdef __cplusplus -#include -#include -#include +// #include "TINYSTL/vector.h" +// #include "TINYSTL/unordered_map.h" #include "TINYSTL/vector.h" #include "TINYSTL/unordered_map.h" #endif