1
0
Fork 0
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:
k0kubun 2018-10-23 00:09:10 +00:00
parent e38a0b4606
commit 5984aa84db
2 changed files with 12 additions and 1 deletions

10
mjit.c
View file

@ -24,7 +24,15 @@
static void
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) {
memcpy(job->cc_entries, job->body->cc_entries, sizeof(struct rb_call_cache) * (job->body->ci_size + job->body->ci_kw_size));
}

View file

@ -1182,6 +1182,9 @@ copy_cache_from_main_thread(struct mjit_copy_job *job)
return FALSE;
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) {
rb_native_cond_wait(&mjit_worker_wakeup, &mjit_engine_mutex);
verbose(3, "Getting wakeup from client");