Skip to content

Instantly share code, notes, and snippets.

@KalleZ
Created March 25, 2019 22:18
Show Gist options
  • Save KalleZ/c5b8302139bf60dc98a45ea503581a9c to your computer and use it in GitHub Desktop.
Save KalleZ/c5b8302139bf60dc98a45ea503581a9c to your computer and use it in GitHub Desktop.
ext/opcache/ZendAccelerator.c | 10 ++++++++--
ext/opcache/zend_shared_alloc.c | 18 ++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 7879de866f..802e7ed23b 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -133,8 +133,14 @@ static void preload_activate(void);
static void preload_restart(void);
#ifdef ZEND_WIN32
-# define INCREMENT(v) InterlockedIncrement64(&ZCSG(v))
-# define DECREMENT(v) InterlockedDecrement64(&ZCSG(v))
+# define INCREMENT(v) \
+ SHM_UNPROTECT(); \
+ InterlockedIncrement64(&ZCSG(v)); \
+ SHM_PROTECT()
+# define DECREMENT(v) \
+ SHM_UNPROTECT(); \
+ InterlockedDecrement64(&ZCSG(v)); \
+ SHM_PROTECT()
# define LOCKVAL(v) (ZCSG(v))
#endif
diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c
index 177cbcc46f..72ff6fa033 100644
--- a/ext/opcache/zend_shared_alloc.c
+++ b/ext/opcache/zend_shared_alloc.c
@@ -594,6 +594,24 @@ 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;
+
+ VirtualProtect((LPVOID)ZSMMG(shared_segments)[i]->p, ZSMMG(shared_segments)[i]->size, mode, &oldProtect);
+ }
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment