From 157095b3a44d8b0130a532a0b7be3f5ac197111c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Oct 2021 16:57:30 -0700 Subject: 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 --- misc/yjit_asm_tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc') 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)); }) -- cgit v1.2.3