mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-17 04:24:37 +03:00
Removed contribs
Added some misc methods to Compiler. Moved reset() from X86Var to Var.
This commit is contained in:
@@ -14,9 +14,6 @@ CMake_Minimum_Required(VERSION 2.8.12)
|
|||||||
# Whether to build static library (default FALSE).
|
# Whether to build static library (default FALSE).
|
||||||
# Set(ASMJIT_STATIC FALSE)
|
# Set(ASMJIT_STATIC FALSE)
|
||||||
|
|
||||||
# Whether to build contribution together with AsmJit (default FALSE)
|
|
||||||
# Set(ASMJIT_BUILD_CONTRIB)
|
|
||||||
|
|
||||||
# Whether to build tests (default FALSE).
|
# Whether to build tests (default FALSE).
|
||||||
# Set(ASMJIT_BUILD_TEST FALSE)
|
# Set(ASMJIT_BUILD_TEST FALSE)
|
||||||
|
|
||||||
@@ -227,7 +224,6 @@ AsmJit_AddSource(ASMJIT_SRC asmjit
|
|||||||
base.h
|
base.h
|
||||||
build.h
|
build.h
|
||||||
config.h
|
config.h
|
||||||
contrib.h
|
|
||||||
host.h
|
host.h
|
||||||
x86.h
|
x86.h
|
||||||
)
|
)
|
||||||
@@ -289,13 +285,6 @@ AsmJit_AddSource(ASMJIT_SRC asmjit/x86
|
|||||||
x86scheduler_p.h
|
x86scheduler_p.h
|
||||||
)
|
)
|
||||||
|
|
||||||
If(ASMJIT_BUILD_CONTRIB)
|
|
||||||
AsmJit_AddSource(ASMJIT_SRC asmjit/contrib
|
|
||||||
winremoteruntime.cpp
|
|
||||||
winremoteruntime.h
|
|
||||||
)
|
|
||||||
EndIf()
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# [AsmJit - Headers]
|
# [AsmJit - Headers]
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|||||||
@@ -558,6 +558,12 @@ struct Var : public Operand {
|
|||||||
return Var(*this);
|
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`.
|
//! Get whether the variable has been initialized by `Compiler`.
|
||||||
ASMJIT_INLINE bool isInitialized() const {
|
ASMJIT_INLINE bool isInitialized() const {
|
||||||
return _vreg.id != kInvalidValue;
|
return _vreg.id != kInvalidValue;
|
||||||
@@ -2954,15 +2960,51 @@ struct ASMJIT_VCLASS Compiler : public CodeGen {
|
|||||||
ASMJIT_API void alloc(Var& var);
|
ASMJIT_API void alloc(Var& var);
|
||||||
//! Alloc variable `var` using `regIndex` as a register index.
|
//! Alloc variable `var` using `regIndex` as a register index.
|
||||||
ASMJIT_API void alloc(Var& var, uint32_t regIndex);
|
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);
|
ASMJIT_API void alloc(Var& var, const Reg& reg);
|
||||||
//! Spill variable `var`.
|
//! Spill variable `var`.
|
||||||
ASMJIT_API void spill(Var& 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);
|
ASMJIT_API void save(Var& var);
|
||||||
//! Unuse variable `var`.
|
//! Unuse variable `var`.
|
||||||
ASMJIT_API void unuse(Var& 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`.
|
//! Get priority of variable `var`.
|
||||||
ASMJIT_API uint32_t getPriority(Var& var) const;
|
ASMJIT_API uint32_t getPriority(Var& var) const;
|
||||||
//! Set priority of variable `var` to `priority`.
|
//! Set priority of variable `var` to `priority`.
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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<VMemMgr*>(&_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
|
|
||||||
@@ -526,12 +526,6 @@ struct X86Var : public Var {
|
|||||||
return X86Var(*this);
|
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]
|
// [Type]
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user