-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tiny amounts of cleanup (lots)
- Loading branch information
Showing
41 changed files
with
545 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "../Platform.hpp" | ||
|
||
#if defined(TULIP_HOOK_MACOS) && defined(TULIP_HOOK_X64) | ||
|
||
#include "../CallingConvention.hpp" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace tulip::hook { | ||
class AbstractFunction; | ||
|
||
class TULIP_HOOK_DLL SystemVConvention : public CallingConvention { | ||
public: | ||
~SystemVConvention() override; | ||
|
||
void generateDefaultCleanup(BaseAssembler& a, AbstractFunction const& function) override; | ||
void generateIntoDefault(BaseAssembler& a, AbstractFunction const& function) override; | ||
void generateIntoOriginal(BaseAssembler& a, AbstractFunction const& function) override; | ||
void generateOriginalCleanup(BaseAssembler& a, AbstractFunction const& function) override; | ||
bool needsWrapper(AbstractFunction const& function) const override; | ||
|
||
static std::shared_ptr<SystemVConvention> create(); | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <Platform.hpp> | ||
|
||
#if defined(TULIP_HOOK_MACOS) && defined(TULIP_HOOK_X64) | ||
|
||
#include <AbstractFunction.hpp> | ||
#include <platform/MacosIntelConvention.hpp> | ||
#include "../assembler/X64Assembler.hpp" | ||
|
||
using namespace tulip::hook; | ||
|
||
namespace { | ||
size_t getStackParamSize(AbstractFunction const& function) { | ||
size_t stackParamSize = 0; | ||
int xmmCount = 0; | ||
int gprCount = 0; | ||
if (function.m_return.m_kind == AbstractTypeKind::Other && function.m_return.m_size > 16) { | ||
gprCount += 1; | ||
} | ||
for (auto& param : function.m_parameters) { | ||
if (param.m_kind == AbstractTypeKind::FloatingPoint) { | ||
if (xmmCount < 8) { | ||
xmmCount++; | ||
} else { | ||
stackParamSize += 8; | ||
} | ||
} else { | ||
if (gprCount < 6) { | ||
gprCount++; | ||
} else { | ||
stackParamSize += 8; | ||
} | ||
} | ||
} | ||
return stackParamSize; | ||
} | ||
} | ||
|
||
SystemVConvention::~SystemVConvention() {} | ||
|
||
void SystemVConvention::generateDefaultCleanup(BaseAssembler& a_, AbstractFunction const& function) { | ||
size_t stackParamSize = getStackParamSize(function); | ||
if (stackParamSize > 0) { | ||
auto& a = static_cast<X64Assembler&>(a_); | ||
using enum X64Register; | ||
auto const paddedSize = (stackParamSize % 16) ? stackParamSize + 8 : stackParamSize; | ||
a.add(RSP, paddedSize); | ||
} | ||
} | ||
|
||
// used to move the stack values to the correct places | ||
|
||
void SystemVConvention::generateIntoDefault(BaseAssembler& a_, AbstractFunction const& function) { | ||
size_t stackParamSize = getStackParamSize(function); | ||
if (stackParamSize > 0) { | ||
auto& a = static_cast<X64Assembler&>(a_); | ||
using enum X64Register; | ||
RegMem64 m; | ||
auto const paddedSize = (stackParamSize % 16) ? stackParamSize + 8 : stackParamSize; | ||
a.sub(RSP, paddedSize); | ||
int stackOffset = 0; | ||
|
||
for (auto i = 0; i < stackParamSize; i += 8) { | ||
a.mov(RAX, m[RBP + (16 + i)]); | ||
a.mov(m[RSP + i], RAX); | ||
} | ||
} | ||
} | ||
|
||
void SystemVConvention::generateIntoOriginal(BaseAssembler& a_, AbstractFunction const& function) { | ||
} | ||
|
||
void SystemVConvention::generateOriginalCleanup(BaseAssembler& a_, AbstractFunction const& function) { | ||
} | ||
|
||
bool SystemVConvention::needsWrapper(AbstractFunction const& function) const { | ||
return false; | ||
} | ||
|
||
std::shared_ptr<SystemVConvention> SystemVConvention::create() { | ||
return std::make_shared<SystemVConvention>(); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.