Skip to content
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

Enable public usage of SLJIT_LOCALS_OFFSET #264

Merged
merged 1 commit into from
Aug 18, 2024

Conversation

invertego
Copy link
Contributor

Remove dependency on internal macro SSIZE_OF.

Remove dependency on internal macro SSIZE_OF.
Copy link
Owner

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

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

LGTM

@zherczeg zherczeg merged commit 3b9c0c8 into zherczeg:master Aug 18, 2024
11 checks passed
@zherczeg
Copy link
Owner

Just out of curiosity, how can you use this relative size? I am not aware of any operation where it is needed.

@invertego
Copy link
Contributor Author

I am using it to calculate the unadjusted stack pointer. I wanted a cheap way to determine where in generated code the last callout to C code occurred without needing to walk the stack or pay an additional cost for each call. On entry to generated code, I can do something like the following:
sljit_get_local_base(compiler, SLJIT_MEM1(SLJIT_S0), offsetof(JitState, stackPointer), -SLJIT_LOCALS_OFFSET);

Later, after calling out to C code, from an arbitrarily deep call stack I can retrieve the stored stack pointer and use it to determine where the call originated. On x86-64, the next 8 bytes below the stored pointer will hold the return address. I understand this trick can't be generalized to all architectures/ABIs (notably ARM64).

@invertego invertego deleted the locals_offset_macro branch August 18, 2024 23:16
@zherczeg
Copy link
Owner

This operation can also be used to get the return address:
https://github.com/zherczeg/sljit/blob/master/sljit_src/sljitLir.h#L1478

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