diff options
author | Aaron Patterson <[email protected]> | 2021-10-26 16:57:30 -0700 |
---|---|---|
committer | Aaron Patterson <[email protected]> | 2021-12-01 12:45:59 -0800 |
commit | 157095b3a44d8b0130a532a0b7be3f5ac197111c (patch) | |
tree | 362d1b19c520ebf270b92921671dc5b312b2307c /yjit_codegen.c | |
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 <[email protected]>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5032
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r-- | yjit_codegen.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c index 7b44874af8..96f895b934 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -4876,6 +4876,8 @@ rb_yjit_tracing_invalidate_all(void) RUBY_ASSERT_ALWAYS(yjit_codepage_frozen_bytes <= old_pos && "frozen bytes should increase monotonically"); yjit_codepage_frozen_bytes = old_pos; + cb_mark_all_executable(ocb); + cb_mark_all_executable(cb); RB_VM_LOCK_LEAVE(); } @@ -4957,6 +4959,7 @@ yjit_init_codegen(void) // Generate full exit code for C func gen_full_cfunc_return(); + cb_mark_all_executable(cb); // Map YARV opcodes to the corresponding codegen functions yjit_reg_op(BIN(nop), gen_nop); |