-
Notifications
You must be signed in to change notification settings - Fork 571
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
i#3544 RV64: Rebase the dcontext pointer. #7235
base: master
Are you sure you want to change the base?
Conversation
The dcontext_t struct is larger than the biggest valid displacement of the load and store instructions. By rebasing the pointer by 0x800, we van access the entire struct, because the dispacement can be in the renge of -0x800 to 0x7ff.
Also worked around build failure on windows
I know that these patches are quite "hacky". However, I could not find a better way to work around some issues. |
* substracting 0x800 from the offset in the struct. | ||
*/ | ||
#ifdef RISCV64 | ||
# define CONTEXT_REBASE_OFFT 0x800 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest a better name such as CONTEXT_HEAD_OFFSET
.
I wonder whether a negative offset will be more descriptive than using subtraction everywhere, which gives a hint about the memory layout (REG_DCTX points to the middle of dcontext_t, yielding a negative offset).
* and it does not run windows, we can work around that with conditional compilation. | ||
*/ | ||
#if (CONTEXT_REBASE_OFFT != 0) | ||
(*entry)(((void *)dcontext) + CONTEXT_REBASE_OFFT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conversion between REG_DCTX
and the real head of dcontext_t occurs several times. Suggest wrap these into macros. (CONTEXT_PTR_TO_HEAD()
and CONTEXT_HEAD_TO_PTR
).
#if (CONTEXT_REBASE_OFFT != 0) | ||
set_thread_private_dcontext(NULL); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Existing code compares thread private dcontext with NULL for validation check, thus this is required or they will get NULL - CONTEXT_REBASE_OFFSET and wrongly assumes thread private dcontext is ready.
Do I understand it correcly? If so, some comments to explain this call seem helpful.
The dcontext_t struct is larger than the biggest valid displacement of the load and store instructions.
By rebasing the pointer by 0x800, we can access the entire struct, because the displacement can be in the range of -0x800 to 0x7ff.