Permalink
Browse files

Disable writing into JIT buffer during execution

  • Loading branch information...
dstogov committed Aug 18, 2016
1 parent f452c60 commit d5885945d2f64ab15f2c564dad42fd14b9abdcb6
Showing with 40 additions and 8 deletions.
  1. +30 −8 ext/opcache/jit/zend_jit.c
  2. +2 −0 ext/opcache/jit/zend_jit.h
  3. +8 −0 ext/opcache/zend_persist.c
View
@@ -105,22 +105,22 @@ static void *jit_alloc(size_t size, int shared)
# ifdef MAP_HUGETLB
p = mmap(NULL, size,
//???# ifdef HAVE_MPROTECT
//??? PROT_NONE,
//???# else
# ifdef HAVE_MPROTECT
PROT_NONE,
# else
PROT_EXEC | PROT_READ | PROT_WRITE,
//???# endif
# endif
(shared ? MAP_SHARED : MAP_PRIVATE) | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
if (p != MAP_FAILED) {
return (void*)p;
}
# endif
p = mmap(NULL, size,
//???# ifdef HAVE_MPROTECT
//??? PROT_NONE,
//???# else
# ifdef HAVE_MPROTECT
PROT_NONE,
# else
PROT_EXEC | PROT_READ | PROT_WRITE,
//???# endif
# endif
(shared ? MAP_SHARED : MAP_PRIVATE) | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) {
return NULL;
@@ -353,6 +353,20 @@ ZEND_API int zend_jit(zend_op_array *op_array, zend_persistent_script* main_pers
return FAILURE;
}
ZEND_API void zend_jit_unprotect(void)
{
#ifdef HAVE_MPROTECT
mprotect(dasm_buf, ((char*)dasm_end) - ((char*)dasm_buf), PROT_READ | PROT_WRITE);
#endif
}
ZEND_API void zend_jit_protect(void)
{
#ifdef HAVE_MPROTECT
mprotect(dasm_buf, ((char*)dasm_end) - ((char*)dasm_buf), PROT_READ | PROT_EXEC);
#endif
}
ZEND_API int zend_jit_startup(size_t size)
{
size_t page_size = jit_page_size();
@@ -392,6 +406,14 @@ ZEND_API int zend_jit(zend_op_array *op_array, zend_persistent_script* main_pers
return FAILURE;
}
ZEND_API void zend_jit_unprotect(void)
{
}
ZEND_API void zend_jit_protect(void)
{
}
ZEND_API int zend_jit_startup(size_t size)
{
return FAILURE;
@@ -22,6 +22,8 @@
#define HAVE_JIT_H
ZEND_API int zend_jit(zend_op_array *op_array, zend_persistent_script* main_persistent_script);
ZEND_API void zend_jit_unprotect(void);
ZEND_API void zend_jit_protect(void);
ZEND_API int zend_jit_startup(size_t size);
ZEND_API void zend_jit_shutdown(void);
@@ -856,10 +856,18 @@ zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script
script->arena_mem = ZCG(arena_mem) = ZCG(mem);
ZCG(mem) = (void*)((char*)ZCG(mem) + script->arena_size);
#ifdef HAVE_JIT
zend_jit_unprotect();
#endif
zend_accel_persist_class_table(&script->script.class_table);
zend_hash_persist(&script->script.function_table, zend_persist_op_array);
zend_persist_op_array_ex(&script->script.main_op_array, script);
#ifdef HAVE_JIT
zend_jit_protect();
#endif
return script;
}

0 comments on commit d588594

Please sign in to comment.