|
@@ -0,0 +1,159 @@
|
|
1
|
+From dc8bb6a53bfdfe42d9ae81d4e78c6155ad4bfd6e Mon Sep 17 00:00:00 2001
|
|
2
|
+From: Michael Heimpold <mhei@heimpold.de>
|
|
3
|
+Date: Sun, 17 May 2015 16:50:50 +0200
|
|
4
|
+Subject: [PATCH] ext/opcache: fix detection of shm/mmap
|
|
5
|
+
|
|
6
|
+The detection of sysvipc and mmap doesn't work well when cross-compiling,
|
|
7
|
+so I decided to only check for the availability of the functions involved.
|
|
8
|
+This is not a clean solution, but works for now(tm) :-)
|
|
9
|
+
|
|
10
|
+It should be discussed with upstream to find a better solution.
|
|
11
|
+
|
|
12
|
+This solves the issue reported at
|
|
13
|
+https://github.com/openwrt/packages/issues/1010
|
|
14
|
+and makes opcache usable on OpenWrt.
|
|
15
|
+
|
|
16
|
+Signed-off-by: Michael Heimpold <mhei@heimpold.de>
|
|
17
|
+---
|
|
18
|
+ ext/opcache/config.m4 | 122 ++-----------------------------------------------
|
|
19
|
+ 1 file changed, 4 insertions(+), 118 deletions(-)
|
|
20
|
+
|
|
21
|
+diff --git a/ext/opcache/config.m4 b/ext/opcache/config.m4
|
|
22
|
+index b7e4835..7b6c0aa 100644
|
|
23
|
+--- a/ext/opcache/config.m4
|
|
24
|
++++ b/ext/opcache/config.m4
|
|
25
|
+@@ -11,127 +11,13 @@ if test "$PHP_OPCACHE" != "no"; then
|
|
26
|
+ AC_DEFINE(HAVE_MPROTECT, 1, [Define if you have mprotect() function])
|
|
27
|
+ ])
|
|
28
|
+
|
|
29
|
+- AC_MSG_CHECKING(for sysvipc shared memory support)
|
|
30
|
+- AC_TRY_RUN([
|
|
31
|
+-#include <sys/types.h>
|
|
32
|
+-#include <sys/wait.h>
|
|
33
|
+-#include <sys/ipc.h>
|
|
34
|
+-#include <sys/shm.h>
|
|
35
|
+-#include <unistd.h>
|
|
36
|
+-#include <string.h>
|
|
37
|
+-
|
|
38
|
+-int main() {
|
|
39
|
+- pid_t pid;
|
|
40
|
+- int status;
|
|
41
|
+- int ipc_id;
|
|
42
|
+- char *shm;
|
|
43
|
+- struct shmid_ds shmbuf;
|
|
44
|
+-
|
|
45
|
+- ipc_id = shmget(IPC_PRIVATE, 4096, (IPC_CREAT | SHM_R | SHM_W));
|
|
46
|
+- if (ipc_id == -1) {
|
|
47
|
+- return 1;
|
|
48
|
+- }
|
|
49
|
+-
|
|
50
|
+- shm = shmat(ipc_id, NULL, 0);
|
|
51
|
+- if (shm == (void *)-1) {
|
|
52
|
+- shmctl(ipc_id, IPC_RMID, NULL);
|
|
53
|
+- return 2;
|
|
54
|
+- }
|
|
55
|
+-
|
|
56
|
+- if (shmctl(ipc_id, IPC_STAT, &shmbuf) != 0) {
|
|
57
|
+- shmdt(shm);
|
|
58
|
+- shmctl(ipc_id, IPC_RMID, NULL);
|
|
59
|
+- return 3;
|
|
60
|
+- }
|
|
61
|
+-
|
|
62
|
+- shmbuf.shm_perm.uid = getuid();
|
|
63
|
+- shmbuf.shm_perm.gid = getgid();
|
|
64
|
+- shmbuf.shm_perm.mode = 0600;
|
|
65
|
+-
|
|
66
|
+- if (shmctl(ipc_id, IPC_SET, &shmbuf) != 0) {
|
|
67
|
+- shmdt(shm);
|
|
68
|
+- shmctl(ipc_id, IPC_RMID, NULL);
|
|
69
|
+- return 4;
|
|
70
|
+- }
|
|
71
|
+-
|
|
72
|
+- shmctl(ipc_id, IPC_RMID, NULL);
|
|
73
|
+-
|
|
74
|
+- strcpy(shm, "hello");
|
|
75
|
+-
|
|
76
|
+- pid = fork();
|
|
77
|
+- if (pid < 0) {
|
|
78
|
+- return 5;
|
|
79
|
+- } else if (pid == 0) {
|
|
80
|
+- strcpy(shm, "bye");
|
|
81
|
+- return 6;
|
|
82
|
+- }
|
|
83
|
+- if (wait(&status) != pid) {
|
|
84
|
+- return 7;
|
|
85
|
+- }
|
|
86
|
+- if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
|
|
87
|
+- return 8;
|
|
88
|
+- }
|
|
89
|
+- if (strcmp(shm, "bye") != 0) {
|
|
90
|
+- return 9;
|
|
91
|
+- }
|
|
92
|
+- return 0;
|
|
93
|
+-}
|
|
94
|
+-],dnl
|
|
95
|
++ AC_CHECK_FUNC(shmget,[
|
|
96
|
+ AC_DEFINE(HAVE_SHM_IPC, 1, [Define if you have SysV IPC SHM support])
|
|
97
|
+- msg=yes,msg=no,msg=no)
|
|
98
|
+- AC_MSG_RESULT([$msg])
|
|
99
|
+-
|
|
100
|
+- AC_MSG_CHECKING(for mmap() using MAP_ANON shared memory support)
|
|
101
|
+- AC_TRY_RUN([
|
|
102
|
+-#include <sys/types.h>
|
|
103
|
+-#include <sys/wait.h>
|
|
104
|
+-#include <sys/mman.h>
|
|
105
|
+-#include <unistd.h>
|
|
106
|
+-#include <string.h>
|
|
107
|
+-
|
|
108
|
+-#ifndef MAP_ANON
|
|
109
|
+-# ifdef MAP_ANONYMOUS
|
|
110
|
+-# define MAP_ANON MAP_ANONYMOUS
|
|
111
|
+-# endif
|
|
112
|
+-#endif
|
|
113
|
+-#ifndef MAP_FAILED
|
|
114
|
+-# define MAP_FAILED ((void*)-1)
|
|
115
|
+-#endif
|
|
116
|
+-
|
|
117
|
+-int main() {
|
|
118
|
+- pid_t pid;
|
|
119
|
+- int status;
|
|
120
|
+- char *shm;
|
|
121
|
+-
|
|
122
|
+- shm = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
|
|
123
|
+- if (shm == MAP_FAILED) {
|
|
124
|
+- return 1;
|
|
125
|
+- }
|
|
126
|
+-
|
|
127
|
+- strcpy(shm, "hello");
|
|
128
|
++ ])
|
|
129
|
+
|
|
130
|
+- pid = fork();
|
|
131
|
+- if (pid < 0) {
|
|
132
|
+- return 5;
|
|
133
|
+- } else if (pid == 0) {
|
|
134
|
+- strcpy(shm, "bye");
|
|
135
|
+- return 6;
|
|
136
|
+- }
|
|
137
|
+- if (wait(&status) != pid) {
|
|
138
|
+- return 7;
|
|
139
|
+- }
|
|
140
|
+- if (!WIFEXITED(status) || WEXITSTATUS(status) != 6) {
|
|
141
|
+- return 8;
|
|
142
|
+- }
|
|
143
|
+- if (strcmp(shm, "bye") != 0) {
|
|
144
|
+- return 9;
|
|
145
|
+- }
|
|
146
|
+- return 0;
|
|
147
|
+-}
|
|
148
|
+-],dnl
|
|
149
|
++ AC_CHECK_FUNC(mmap,[
|
|
150
|
+ AC_DEFINE(HAVE_SHM_MMAP_ANON, 1, [Define if you have mmap(MAP_ANON) SHM support])
|
|
151
|
+- msg=yes,msg=no,msg=no)
|
|
152
|
+- AC_MSG_RESULT([$msg])
|
|
153
|
++ ])
|
|
154
|
+
|
|
155
|
+ AC_MSG_CHECKING(for mmap() using /dev/zero shared memory support)
|
|
156
|
+ AC_TRY_RUN([
|
|
157
|
+--
|
|
158
|
+1.7.10.4
|
|
159
|
+
|