diff options
author | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-06 07:22:25 +0000 |
---|---|---|
committer | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-06 07:22:25 +0000 |
commit | 7a2263fb389cbd0fb9cc8d86ed909b7e080ef1e7 (patch) | |
tree | 092c35f03dbbdcf557855e27c79254577d615c5a /mjit.c | |
parent | 9f17712d2c8af72e211467d09eb920ab320be307 (diff) |
mjit_worker.c: strictly control MJIT copy job
-available region. reducing risk of SEGV in mjit_copy_job_handler() like
http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1446117
I'm not sure which exact part is causing "[BUG] Segmentation fault at 0x0000000000000008"
on `(mjit_copy_job_handler+0x12) [0x564a6c4ce632] /home/ko1/ruby/src/trunk-mjit/mjit.c:26`...
mjit.c: ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'mjit.c')
-rw-r--r-- | mjit.c | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -24,15 +24,20 @@ static void mjit_copy_job_handler(void *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. */ + struct mjit_copy_job *job = data; + int finish_p; + CRITICAL_SECTION_START(3, "in mjit_copy_job_handler"); + finish_p = job->finish_p; + CRITICAL_SECTION_FINISH(3, "in mjit_copy_job_handler"); + + if (stop_worker_p || finish_p) { + /* `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. + `finish_p`: make sure that this job is never executed while job is being modified. */ 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)); } @@ -40,10 +45,10 @@ mjit_copy_job_handler(void *data) memcpy(job->is_entries, job->body->is_entries, sizeof(union iseq_inline_storage_entry) * job->body->is_size); } - CRITICAL_SECTION_START(3, "in MJIT copy job wait"); + CRITICAL_SECTION_START(3, "in mjit_copy_job_handler"); job->finish_p = TRUE; rb_native_cond_broadcast(&mjit_worker_wakeup); - CRITICAL_SECTION_FINISH(3, "in MJIT copy job wait"); + CRITICAL_SECTION_FINISH(3, "in mjit_copy_job_handler"); } extern int rb_thread_create_mjit_thread(void (*worker_func)(void)); |