mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
mjit.c: prevent from accessing expired job
Given that `copy_cache_from_main_thread()` breaks the loop when `stop_worker_p` is TRUE, memory of `job` allocated by `alloca` may be invalid if `stop_worker_p` is already TRUE. mjit_worker.c: explain why `copy_cache_from_main_thread()` should not stop checking `stop_worker_p`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e38a0b4606
commit
5984aa84db
2 changed files with 12 additions and 1 deletions
10
mjit.c
10
mjit.c
|
@ -24,7 +24,15 @@
|
||||||
static void
|
static void
|
||||||
mjit_copy_job_handler(void *data)
|
mjit_copy_job_handler(void *data)
|
||||||
{
|
{
|
||||||
struct mjit_copy_job *job = (struct mjit_copy_job *)data;
|
struct mjit_copy_job *job;
|
||||||
|
if (stop_worker_p) {
|
||||||
|
/* `copy_cache_from_main_thread()` stops to wait for this job. Then job
|
||||||
|
data which is allocated by `alloca()` could be expired and we might
|
||||||
|
not be able to access that. */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
job = (struct mjit_copy_job *)data;
|
||||||
if (job->cc_entries) {
|
if (job->cc_entries) {
|
||||||
memcpy(job->cc_entries, job->body->cc_entries, sizeof(struct rb_call_cache) * (job->body->ci_size + job->body->ci_kw_size));
|
memcpy(job->cc_entries, job->body->cc_entries, sizeof(struct rb_call_cache) * (job->body->ci_size + job->body->ci_kw_size));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1182,6 +1182,9 @@ copy_cache_from_main_thread(struct mjit_copy_job *job)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
CRITICAL_SECTION_START(3, "in MJIT copy job wait");
|
CRITICAL_SECTION_START(3, "in MJIT copy job wait");
|
||||||
|
/* checking `stop_worker_p` too because `RUBY_VM_CHECK_INTS(ec)` may not
|
||||||
|
lush mjit_copy_job_handler when EC_EXEC_TAG() is not TAG_NONE, and then
|
||||||
|
`stop_worker()` could dead lock with this function. */
|
||||||
while (!job->finish_p && !stop_worker_p) {
|
while (!job->finish_p && !stop_worker_p) {
|
||||||
rb_native_cond_wait(&mjit_worker_wakeup, &mjit_engine_mutex);
|
rb_native_cond_wait(&mjit_worker_wakeup, &mjit_engine_mutex);
|
||||||
verbose(3, "Getting wakeup from client");
|
verbose(3, "Getting wakeup from client");
|
||||||
|
|
Loading…
Add table
Reference in a new issue