summaryrefslogtreecommitdiff
path: root/yjit_core.c
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2021-12-06 19:14:34 -0500
committerAlan Wu <XrXr@users.noreply.github.com>2021-12-06 20:27:15 -0500
commit794b9a28b562121426b3b1a19d2e465616af3ac0 (patch)
tree7199b80cfde3f65684c3af592fed795b06e42af2 /yjit_core.c
parentb7ea66bc3228635a87125bea69f01779f75c39de (diff)
YJIT: Add integrity checks for blockid
Verify that the iseq idx pair for the block is valid in invalidate_block_version(). While we are at it, bound loop iterating over instructions to `iseq_body->iseq_size`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5222
Diffstat (limited to 'yjit_core.c')
-rw-r--r--yjit_core.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/yjit_core.c b/yjit_core.c
index 00905e7f24..d420f0fcab 100644
--- a/yjit_core.c
+++ b/yjit_core.c
@@ -1205,6 +1205,15 @@ block_array_remove(rb_yjit_block_array_t block_array, block_t *block)
RUBY_ASSERT(false);
}
+// Some runtime checks for integrity of a program location
+static void
+verify_blockid(const blockid_t blockid)
+{
+ const rb_iseq_t *const iseq = blockid.iseq;
+ RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
+ RUBY_ASSERT_ALWAYS(blockid.idx < iseq->body->iseq_size);
+}
+
// Invalidate one specific block version
static void
invalidate_block_version(block_t *block)
@@ -1214,6 +1223,8 @@ invalidate_block_version(block_t *block)
// TODO: want to assert that all other ractors are stopped here. Can't patch
// machine code that some other thread is running.
+ verify_blockid(block->blockid);
+
const rb_iseq_t *iseq = block->blockid.iseq;
//fprintf(stderr, "invalidating block (%p, %d)\n", block->blockid.iseq, block->blockid.idx);