diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2021-12-01 14:15:23 -0500 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-12-03 20:02:25 -0500 |
commit | f41b4d44f95978dfa97af04af00055dc3fbf7978 (patch) | |
tree | 744a3d5e2d8f1ef0b3a4ab00a7cd99df0353f6b8 /misc | |
parent | 3be067234f156d75e6143cca5037df7eef1bd112 (diff) |
YJIT: Bounds check every byte in the assembler
Previously, YJIT assumed that basic blocks never consume more than
1 KiB of memory. This assumption does not hold for long Ruby methods
such as the one in the following:
```ruby
eval(<<RUBY)
def set_local_a_lot
#{'_=0;'*0x40000}
end
RUBY
set_local_a_lot
```
For low `--yjit-exec-mem-size` values, one basic block could exhaust the
entire buffer.
Introduce a new field `codeblock_t::dropped_bytes` that the assembler
sets whenever it runs out of space. Check this field in
gen_single_block() to respond to out of memory situations and other
error conditions. This design avoids making the control flow graph of
existing code generation functions more complex.
Use POSIX shell in misc/test_yjit_asm.sh since bash is expanding
`0%/*/*` differently.
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5209
Diffstat (limited to 'misc')
-rwxr-xr-x | misc/test_yjit_asm.sh | 4 | ||||
-rw-r--r-- | misc/yjit_asm_tests.c | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/misc/test_yjit_asm.sh b/misc/test_yjit_asm.sh index cf1ae7bee5..e09d83f0fb 100755 --- a/misc/test_yjit_asm.sh +++ b/misc/test_yjit_asm.sh @@ -1,9 +1,9 @@ -#!/bin/bash +#!/bin/sh set -e set -x -clang -std=gnu99 -Wall -Werror -Wno-error=unused-function -Wshorten-64-to-32 -I ${0%/*/*} ${0%/*}/yjit_asm_tests.c -o asm_test +clang -std=gnu99 -Wall -Werror -Wno-error=unused-function -Wshorten-64-to-32 -I "${0%/*/*}" "${0%/*}/yjit_asm_tests.c" -o asm_test ./asm_test diff --git a/misc/yjit_asm_tests.c b/misc/yjit_asm_tests.c index b37d483ecf..ccf8822bbe 100644 --- a/misc/yjit_asm_tests.c +++ b/misc/yjit_asm_tests.c @@ -26,7 +26,7 @@ void print_bytes(codeblock_t* cb) { for (uint32_t i = 0; i < cb->write_pos; ++i) { - printf("%02X", (int)cb->mem_block[i]); + printf("%02X", (int)*cb_get_ptr(cb, i)); } printf("\n"); @@ -59,7 +59,7 @@ void check_bytes(codeblock_t* cb, const char* bytes) char* endptr; long int byte = strtol(byte_str, &endptr, 16); - uint8_t cb_byte = cb->mem_block[i]; + uint8_t cb_byte = *cb_get_ptr(cb, i); if (cb_byte != byte) { |