#ifndef jit_x86_shared_Patching_x86_shared_h
#define jit_x86_shared_Patching_x86_shared_h
namespace js {
namespace jit {
namespace X86Encoding {
inline void* GetPointer(const void* where) {
void* res;
memcpy(&res, (const char*)where - sizeof(void*), sizeof(void*));
return res;
}
inline void SetPointer(void* where, const void* value) {
memcpy((char*)where - sizeof(void*), &value, sizeof(void*));
}
inline int32_t GetInt32(const void* where) {
int32_t res;
memcpy(&res, (const char*)where - sizeof(int32_t), sizeof(int32_t));
return res;
}
inline void SetInt32(void* where, int32_t value) {
memcpy((char*)where - sizeof(int32_t), &value, sizeof(int32_t));
}
inline void SetRel32(void* from, void* to) {
intptr_t offset =
reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(from);
MOZ_ASSERT(offset == static_cast<int32_t>(offset),
"offset is too great for a 32-bit relocation");
if (offset != static_cast<int32_t>(offset)) {
MOZ_CRASH("offset is too great for a 32-bit relocation");
}
SetInt32(from, offset);
}
inline void* GetRel32Target(void* where) {
int32_t rel = GetInt32(where);
return (char*)where + rel;
}
class JmpSrc {
public:
JmpSrc() : offset_(-1) {}
explicit JmpSrc(int32_t offset) : offset_(offset) {}
int32_t offset() const { return offset_; }
private:
int32_t offset_;
};
class JmpDst {
public:
explicit JmpDst(int32_t offset) : offset_(offset) {}
int32_t offset() const { return offset_; }
private:
int32_t offset_;
};
inline bool CanRelinkJump(void* from, void* to) {
intptr_t offset = static_cast<char*>(to) - static_cast<char*>(from);
return (offset == static_cast<int32_t>(offset));
}
}
} }
#endif