8000 x64 linux sourcehook hookmangen by rtldg · Pull Request #212 · alliedmodders/metamod-source · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

x64 linux sourcehook hookmangen #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

rtldg
Copy link
Contributor
@rtldg rtldg commented Mar 2, 2025

Following up on @Kenzzer's epic work on the x64 Windows hookmangen #175 stuff: WIP x64 Linux hookmangen stuff!

TODO:

  • More testing....
  • Even more testing.....

@Kenzzer
Copy link
Member
Kenzzer commented Mar 2, 2025

May I recommend that you mark this PR as a draft until it is ready ? Anyways, thanks for seeing this through I've a few remarks that aren't noted in your todo.

@rtldg rtldg marked this pull request as draft March 2, 2025 11:39
Copy link
Member
@Kenzzer Kenzzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of stack alignment for Linux are missing. Specifically in

  • x64GenContext::GeneratePubFunc
  • x64GenContext::CallEndContext
  • x64GenContext::DoReturn
  • x64GenContext::PrepareReturn
  • x64GenContext::GenerateCallHooks
  • retInfo.pAssignOperator
  • retInfo.pDtor
  • x64GenContext::CallSetupHookLoop (You also need to handle parameter 7, 8, 9 & 10)

Comment on lines 407 to 417
8000
const x86_64_Reg params_reg[] = { rdi, rsi, rdx, rcx, r8, r9 };

int reg_index = 0;

m_HookFunc.mov(rbp(v_this), rdi);
reg_index++;

if ((retInfo.flags & PassInfo::PassFlag_RetMem) == PassInfo::PassFlag_RetMem) {
m_HookFunc.mov(rbp(v_memret_ptr), params_reg[reg_index]);
reg_index++;
}
Copy link
Member
@Kenzzer Kenzzer Mar 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that System V callconv is very annoying because sourcehook doesn't provide nearly enough information to tell whether an object goes in memory or registers. I'm fine with the idea of just saving all the registers and restoring them when its time to call the original. Only the return value will therefore need special attention.

It's very important all the registers are saved, because in the rest of the stub generator I make the promise that all general purpose registers are available for usage. Which I did make use of (see when r8 or r9 get used) and they're not restored, this will create issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that System V callconv is very annoying because sourcehook doesn't provide nearly enough information to tell whether an object goes in memory or registers

This is nice in a way though because it means all the type classification logic from the ABI can be excluded.

Which does mean Linux64 Sourcepawn DHooks users will have to manually fill out registers, where on Windows64 you can just HookParamType_Object/HookParamType_ObjectPtr and call it a day...

@rtldg
Copy link
Contributor Author
rtldg commented Mar 2, 2025

Lots of stack alignment for Linux are missing. Specifically in

* [ ]  `x64GenContext::GeneratePubFunc`

* [ ]  `x64GenContext::CallEndContext`

* [ ]  `x64GenContext::DoReturn`

* [ ]  `x64GenContext::PrepareReturn`

* [ ]  `x64GenContext::GenerateCallHooks`

* [ ]  `retInfo.pAssignOperator`

* [ ]  `retInfo.pDtor`

* [ ]  `x64GenContext::CallSetupHookLoop` (You also need to handle parameter 7, 8, 9 & 10)

Alignment for these were added with the latest commit:

  • CallEndContext
  • DoReturn
  • PrepareReturn
  • GenerateCallHooks
  • pAssignOperator
  • pDtor

TODO still because they're a bit more than just copy & pasting.

  • TODO GeneratePubFunc
  • TODO CallSetupHookLoop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0