From eef8f7895336af40b3b2701c36dd991c366deadc Mon Sep 17 00:00:00 2001 From: kobalicek Date: Wed, 17 Sep 2014 20:31:53 +0200 Subject: [PATCH] Removed contribs Added some misc methods to Compiler. Moved reset() from X86Var to Var. --- CMakeLists.txt | 11 ---- src/asmjit/base/compiler.h | 46 +++++++++++++- src/asmjit/contrib.h | 18 ------ src/asmjit/contrib/winremoteruntime.cpp | 79 ------------------------- src/asmjit/contrib/winremoteruntime.h | 74 ----------------------- src/asmjit/x86/x86compiler.h | 6 -- 6 files changed, 44 insertions(+), 190 deletions(-) delete mode 100644 src/asmjit/contrib.h delete mode 100644 src/asmjit/contrib/winremoteruntime.cpp delete mode 100644 src/asmjit/contrib/winremoteruntime.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 438b207..b5a6a23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,6 @@ CMake_Minimum_Required(VERSION 2.8.12) # Whether to build static library (default FALSE). # Set(ASMJIT_STATIC FALSE) -# Whether to build contribution together with AsmJit (default FALSE) -# Set(ASMJIT_BUILD_CONTRIB) - # Whether to build tests (default FALSE). # Set(ASMJIT_BUILD_TEST FALSE) @@ -227,7 +224,6 @@ AsmJit_AddSource(ASMJIT_SRC asmjit base.h build.h config.h - contrib.h host.h x86.h ) @@ -289,13 +285,6 @@ AsmJit_AddSource(ASMJIT_SRC asmjit/x86 x86scheduler_p.h ) -If(ASMJIT_BUILD_CONTRIB) -AsmJit_AddSource(ASMJIT_SRC asmjit/contrib - winremoteruntime.cpp - winremoteruntime.h -) -EndIf() - # ============================================================================= # [AsmJit - Headers] # ============================================================================= diff --git a/src/asmjit/base/compiler.h b/src/asmjit/base/compiler.h index 01b8aad..4db3af0 100644 --- a/src/asmjit/base/compiler.h +++ b/src/asmjit/base/compiler.h @@ -558,6 +558,12 @@ struct Var : public Operand { return Var(*this); } + //! Reset Var operand. + ASMJIT_INLINE void reset() { + _init_packed_op_sz_b0_b1_id(kOperandTypeVar, 0, kInvalidReg, kInvalidReg, kInvalidValue); + _init_packed_d2_d3(kInvalidValue, kInvalidValue); + } + //! Get whether the variable has been initialized by `Compiler`. ASMJIT_INLINE bool isInitialized() const { return _vreg.id != kInvalidValue; @@ -2954,15 +2960,51 @@ struct ASMJIT_VCLASS Compiler : public CodeGen { ASMJIT_API void alloc(Var& var); //! Alloc variable `var` using `regIndex` as a register index. ASMJIT_API void alloc(Var& var, uint32_t regIndex); - //! Alloc variable `var` using `reg` as a demanded register. + //! Alloc variable `var` using `reg` as a register operand. ASMJIT_API void alloc(Var& var, const Reg& reg); //! Spill variable `var`. ASMJIT_API void spill(Var& var); - //! Save variable `var` if modified. + //! Save variable `var` if the status is `modified` at this point. ASMJIT_API void save(Var& var); //! Unuse variable `var`. ASMJIT_API void unuse(Var& var); + //! Alloc variable `var` (if initialized), but only if it's initialized. + ASMJIT_INLINE void allocUnsafe(Var& var) { + if (var.isInitialized()) + alloc(var); + } + + //! Alloc variable `var` (if initialized) using `regIndex` as a register index + ASMJIT_INLINE void allocUnsafe(Var& var, uint32_t regIndex) { + if (var.isInitialized()) + alloc(var, regIndex); + } + + //! Alloc variable `var` (if initialized) using `reg` as a register operand. + ASMJIT_INLINE void allocUnsafe(Var& var, const Reg& reg) { + if (var.isInitialized()) + alloc(var, reg); + } + + //! Spill variable `var` (if initialized). + ASMJIT_INLINE void spillUnsafe(Var& var) { + if (var.isInitialized()) + spill(var); + } + + //! Save variable `var` (if initialized) if the status is `modified` at this point. + ASMJIT_INLINE void saveUnsafe(Var& var) { + if (var.isInitialized()) + save(var); + } + + //! Unuse variable `var` (if initialized). + ASMJIT_INLINE void unuseUnsafe(Var& var) { + if (var.isInitialized()) + unuse(var); + } + //! Get priority of variable `var`. ASMJIT_API uint32_t getPriority(Var& var) const; //! Set priority of variable `var` to `priority`. diff --git a/src/asmjit/contrib.h b/src/asmjit/contrib.h deleted file mode 100644 index dece8b3..0000000 --- a/src/asmjit/contrib.h +++ /dev/null @@ -1,18 +0,0 @@ -// [AsmJit] -// Complete x86/x64 JIT and Remote Assembler for C++. -// -// [License] -// Zlib - See LICENSE.md file in this package. - -// [Guard] -#ifndef _ASMJIT_CONTRIB_H -#define _ASMJIT_CONTRIB_H - -// [Dependencies - Core] -#include "base.h" - -// [Dependencies - Contrib] -#include "contrib/winremoteruntime.h" - -// [Guard] -#endif // _ASMJIT_CONTRIB_H diff --git a/src/asmjit/contrib/winremoteruntime.cpp b/src/asmjit/contrib/winremoteruntime.cpp deleted file mode 100644 index 3a2fe53..0000000 --- a/src/asmjit/contrib/winremoteruntime.cpp +++ /dev/null @@ -1,79 +0,0 @@ -// [AsmJit/WinRemoteRuntime] -// Contribution for remote process handling. -// -// [License] -// Zlib - See LICENSE.md file in the package. - -// [Export] -#define ASMJIT_EXPORTS - -// [Dependencies - AsmJit] -#include "../base.h" - -// [Guard - Windows] -#if defined(ASMJIT_OS_WINDOWS) -#include "winremoteruntime.h" - -namespace asmjit { -namespace contrib { - -// ============================================================================ -// [asmjit::contrib::WinRemoteRuntime - Construction / Destruction] -// ============================================================================ - -WinRemoteRuntime::WinRemoteRuntime(HANDLE hProcess) : - _memMgr(hProcess) { - - // We are patching another process so enable keep-virtual-memory option. - _memMgr.setKeepVirtualMemory(true); -} - -WinRemoteRuntime::~WinRemoteRuntime() {} - -// ============================================================================ -// [asmjit::contrib::WinRemoteRuntime - Interface] -// ============================================================================ - -uint32_t WinRemoteRuntime::add(void** dest, BaseAssembler* assembler) { - // Disallow generation of no code. - size_t codeSize = assembler->getCodeSize(); - if (codeSize == 0) { - *dest = NULL; - return kErrorInvalidState; - } - - // Allocate temporary memory where the code will be stored and relocated. - void* codeData = ASMJIT_ALLOC(codeSize); - if (codeData == NULL) { - *dest = NULL; - return kErrorNoHeapMemory; - } - - // Allocate a permanent remote process memory. - void* processMemPtr = _memMgr.alloc(codeSize, kVMemAllocPermanent); - if (processMemPtr == NULL) { - ASMJIT_FREE(codeData); - *dest = NULL; - return kErrorNoVirtualMemory; - } - - // Relocate and write the code to the process memory. - assembler->relocCode(codeData, (uintptr_t)processMemPtr); - - ::WriteProcessMemory(getProcessHandle(), processMemPtr, codeData, codeSize, NULL); - ASMJIT_FREE(codeData); - - *dest = processMemPtr; - return kErrorOk; -} - -// NOP. -Error WinRemoteRuntime::release(void* p) { - return kErrorOk; -} - -} // contrib namespace -} // asmjit namespace - -// [Guard - Windows] -#endif // ASMJIT_OS_WINDOWS diff --git a/src/asmjit/contrib/winremoteruntime.h b/src/asmjit/contrib/winremoteruntime.h deleted file mode 100644 index da39344..0000000 --- a/src/asmjit/contrib/winremoteruntime.h +++ /dev/null @@ -1,74 +0,0 @@ -// [AsmJit] -// Complete x86/x64 JIT and Remote Assembler for C++. -// -// [License] -// Zlib - See LICENSE.md file in the package. - -// [Guard] -#ifndef _ASMJIT_CONTRIB_WINREMOTERUNTIME_H -#define _ASMJIT_CONTRIB_WINREMOTERUNTIME_H - -#include "../base.h" -#if defined(ASMJIT_OS_WINDOWS) - -namespace asmjit { -namespace contrib { - -//! \addtogroup asmjit_contrib -//! \{ - -// ============================================================================ -// [asmjit::contrib::WinRemoteRuntime] -// ============================================================================ - -//! WinRemoteRuntime can be used to inject code to a remote process. -struct WinRemoteRuntime : public Runtime { - ASMJIT_NO_COPY(WinRemoteRuntime) - - // -------------------------------------------------------------------------- - // [Construction / Destruction] - // -------------------------------------------------------------------------- - - //! Create a `WinRemoteRuntime` instance for a given `hProcess`. - ASMJIT_API WinRemoteRuntime(HANDLE hProcess); - - //! Destroy the `WinRemoteRuntime` instance. - ASMJIT_API virtual ~WinRemoteRuntime(); - - // -------------------------------------------------------------------------- - // [Accessors] - // -------------------------------------------------------------------------- - - //! Get the remote process handle. - ASMJIT_INLINE HANDLE getProcessHandle() const { - return _memMgr.getProcessHandle(); - } - - //! Get the remote memory manager. - ASMJIT_INLINE VMemMgr* getMemMgr() const { - return const_cast(&_memMgr); - } - - // -------------------------------------------------------------------------- - // [Interface] - // -------------------------------------------------------------------------- - - ASMJIT_API virtual uint32_t add(void** dest, BaseAssembler* assembler); - ASMJIT_API virtual Error release(void* p); - - // -------------------------------------------------------------------------- - // [Members] - // -------------------------------------------------------------------------- - - //! Remove memory manager. - VMemMgr _memMgr; -}; - -//! \} - -} // contrib namespace -} // asmjit namespace - -// [Guard] -#endif // ASMJIT_OS_WINDOWS -#endif // _ASMJIT_CONTRIB_WINREMOTERUNTIME_H diff --git a/src/asmjit/x86/x86compiler.h b/src/asmjit/x86/x86compiler.h index 2a71bcd..465cc1d 100644 --- a/src/asmjit/x86/x86compiler.h +++ b/src/asmjit/x86/x86compiler.h @@ -526,12 +526,6 @@ struct X86Var : public Var { return X86Var(*this); } - //! Reset X86Var operand. - ASMJIT_INLINE void reset() { - _init_packed_op_sz_b0_b1_id(kOperandTypeVar, 0, kInvalidReg, kInvalidReg, kInvalidValue); - _init_packed_d2_d3(kInvalidValue, kInvalidValue); - } - // -------------------------------------------------------------------------- // [Type] // --------------------------------------------------------------------------