com php-src: Support VirtualProtect for opcache.protect_mem ory: ext/opcache/ZendAccelerator.c ext/opcache/zend_s hared_alloc.c
| From: | Nikita Popov | Date: | Wed, 10 Apr 2019 13:31:18 +0000 |
| Subject: | com php-src: Support VirtualProtect for opcache.protect_mem ory: ext/opcache/ZendAccelerator.c ext/opcache/zend_s hared_alloc.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-105627@lists.php.net to get a copy of this message | ||
Commit: eb8c07fe2f081a5e270f19c329180469d66142bb
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 25 Mar 2019 15:23:11 +0100
Parents: db7aba538d2813fca7c69fdb8c004e8df06173ed
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=eb8c07fe2f081a5e270f19c329180469d66142bb
Log:
Support VirtualProtect for opcache.protect_memory
Don't enable this on AppVeyor yet, as there is still an open
issue in phar.
Changed paths:
M ext/opcache/ZendAccelerator.c
M ext/opcache/zend_shared_alloc.c
Diff:
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 0bdee2b..56651f2 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -305,7 +305,9 @@ static inline int accel_restart_is_active(void)
static inline int accel_activate_add(void)
{
#ifdef ZEND_WIN32
+ SHM_UNPROTECT();
INCREMENT(mem_usage);
+ SHM_PROTECT();
#else
struct flock mem_usage_lock;
@@ -327,8 +329,10 @@ static inline void accel_deactivate_sub(void)
{
#ifdef ZEND_WIN32
if (ZCG(counted)) {
+ SHM_UNPROTECT();
DECREMENT(mem_usage);
ZCG(counted) = 0;
+ SHM_PROTECT();
}
#else
struct flock mem_usage_unlock;
diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c
index 177cbcc..e4e44c3 100644
--- a/ext/opcache/zend_shared_alloc.c
+++ b/ext/opcache/zend_shared_alloc.c
@@ -594,6 +594,25 @@ void zend_accel_shared_protect(int mode)
for (i = 0; i < ZSMMG(shared_segments_count); i++) {
mprotect(ZSMMG(shared_segments)[i]->p, ZSMMG(shared_segments)[i]->size, mode);
}
+#elif defined(ZEND_WIN32)
+ int i;
+
+ if (!smm_shared_globals) {
+ return;
+ }
+
+ if (mode) {
+ mode = PAGE_READONLY;
+ } else {
+ mode = PAGE_READWRITE;
+ }
+
+ for (i = 0; i < ZSMMG(shared_segments_count); i++) {
+ DWORD oldProtect;
+ if (!VirtualProtect(ZSMMG(shared_segments)[i]->p, ZSMMG(shared_segments)[i]->size, mode,
&oldProtect)) {
+ zend_accel_error(ACCEL_LOG_ERROR, "Failed to protect memory");
+ }
+ }
#endif
}