diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2021-10-26 16:57:30 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2021-12-01 12:45:59 -0800 |
commit | 157095b3a44d8b0130a532a0b7be3f5ac197111c (patch) | |
tree | 362d1b19c520ebf270b92921671dc5b312b2307c /misc | |
parent | 94ee88b38cf0a20666e3965f5c9c4d520cf02b22 (diff) |
Mark JIT code as writeable / executable depending on the situation
Some platforms don't want memory to be marked as writeable and
executable at the same time. When we write to the code block, we
calculate the OS page that the buffer position maps to. Then we call
`mprotect` to allow writes on that particular page. As an optimization,
we cache the "last written" aligned page which allows us to amortize the
cost of the `mprotect` call. In other words, sequential writes to the
same page will only call `mprotect` on the page once.
When we're done writing, we call `mprotect` on the entire JIT buffer.
This means we don't need to keep track of which pages were marked as
writeable, we let the OS take care of that.
Co-authored-by: John Hawthorn <john@hawthorn.email>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5032
Diffstat (limited to 'misc')
-rw-r--r-- | misc/yjit_asm_tests.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/misc/yjit_asm_tests.c b/misc/yjit_asm_tests.c index 5548af07f5..b37d483ecf 100644 --- a/misc/yjit_asm_tests.c +++ b/misc/yjit_asm_tests.c @@ -401,7 +401,7 @@ void run_runtime_tests(void) int (*function)(void); function = (int (*)(void))mem_block; - #define TEST(BODY) cb_set_pos(cb, 0); BODY ret(cb); assert_equal(7, function()); + #define TEST(BODY) cb_set_pos(cb, 0); BODY ret(cb); cb_mark_all_executable(cb); assert_equal(7, function()); // add TEST({ mov(cb, RAX, imm_opnd(0)); add(cb, RAX, imm_opnd(7)); }) |