-
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?
Changes from all commits
0f5fbaa
44261bc
990ddda
59d4761
d504800
1e7f230
f70ec3c
2c232bc
5df374a
878887a
f629122
34f4520
149d543
2766030
604b177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* ********************************************************** | ||
* Copyright (c) 2011-2023 Google, Inc. All rights reserved. | ||
* Copyright (c) 2000-2010 VMware, Inc. All rights reserved. | ||
* Copyright (c) 2025 Foundation of Research and Technology, Hellas. | ||
* **********************************************************/ | ||
|
||
/* | ||
|
@@ -569,7 +570,17 @@ enter_fcache(dcontext_t *dcontext, fcache_enter_func_t entry, cache_pc pc) | |
* paths were missed? | ||
*/ | ||
PTHREAD_JIT_READ(); | ||
|
||
/* | ||
* XXX arithmetic with void pointers does not work on windows. | ||
* Since RISCV is the only architecture that has CONTEXT_REBASE_OFFT != 0 | ||
* and it does not run windows, we can work around that with conditional compilation. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, we could convert it to |
||
#if (CONTEXT_REBASE_OFFT != 0) | ||
(*entry)(((void *)dcontext) + CONTEXT_REBASE_OFFT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conversion between |
||
#else | ||
(*entry)(dcontext); | ||
#endif | ||
IF_WINDOWS(ASSERT_NOT_REACHED()); /* returns for signals on unix */ | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* Copyright (c) 2010-2025 Google, Inc. All rights reserved. | ||
* Copyright (c) 2011 Massachusetts Institute of Technology All rights reserved. | ||
* Copyright (c) 2000-2010 VMware, Inc. All rights reserved. | ||
* Copyright (c) 2025 Foundation of Research and Technology, Hellas. | ||
* *******************************************************************************/ | ||
|
||
/* | ||
|
@@ -2378,6 +2379,9 @@ os_tls_init(void) | |
if (last_thread_tls_exited) /* re-attach */ | ||
last_thread_tls_exited = false; | ||
} | ||
#if (CONTEXT_REBASE_OFFT != 0) | ||
set_thread_private_dcontext(NULL); | ||
#endif | ||
Comment on lines
+2382
to
+2384
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
ASSERT(is_thread_tls_initialized()); | ||
} | ||
|
||
|
@@ -3134,7 +3138,7 @@ get_thread_private_dcontext(void) | |
pid_cached != get_process_id()); | ||
}); | ||
READ_TLS_SLOT_IMM(TLS_DCONTEXT_OFFSET, dcontext); | ||
return dcontext; | ||
return (dcontext_t *)(((void *)dcontext) - CONTEXT_REBASE_OFFT); | ||
#else | ||
/* Assumption: no lock needed on a read => no race conditions between | ||
* reading and writing same tid! Since both get and set are only for | ||
|
@@ -3146,7 +3150,8 @@ get_thread_private_dcontext(void) | |
if (tls_table != NULL) { | ||
for (i = 0; i < MAX_THREADS; i++) { | ||
if (tls_table[i].tid == tid) { | ||
return tls_table[i].dcontext; | ||
return (dcontext_t *)(((void *)tls_table[i].dcontext - | ||
CONTEXT_REBASE_OFFT); | ||
} | ||
} | ||
} | ||
|
@@ -3158,6 +3163,7 @@ get_thread_private_dcontext(void) | |
void | ||
set_thread_private_dcontext(dcontext_t *dcontext) | ||
{ | ||
dcontext = (dcontext_t *)(((void *)dcontext) + CONTEXT_REBASE_OFFT); | ||
#ifdef HAVE_TLS | ||
ASSERT(is_thread_tls_allocated()); | ||
WRITE_TLS_SLOT_IMM(TLS_DCONTEXT_OFFSET, dcontext); | ||
|
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).
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.
(I prefer to keep the offset positive, as it is a positive offset.)
Maybe define some macros to avoid raw arithmetic operations all over the place?