|
31 | 31 |
|
32 | 32 | #define ACCEL_FILEMAP_NAME "ZendOPcache.SharedMemoryArea"
|
33 | 33 | #define ACCEL_MUTEX_NAME "ZendOPcache.SharedMemoryMutex"
|
34 |
| -#define ACCEL_FILEMAP_BASE_DEFAULT 0x01000000 |
35 |
| -#define ACCEL_FILEMAP_BASE "ZendOPcache.MemoryBase" |
36 | 34 | #define ACCEL_EVENT_SOURCE "Zend OPcache"
|
37 | 35 |
|
| 36 | +/* address of mapping base and address of execute_ex */ |
| 37 | +#define ACCEL_BASE_POINTER_SIZE (2 * sizeof(void*)) |
| 38 | + |
38 | 39 | static HANDLE memfile = NULL, memory_mutex = NULL;
|
39 | 40 | static void *mapping_base;
|
40 | 41 |
|
@@ -93,28 +94,6 @@ static char *create_name_with_username(char *name)
|
93 | 94 | return newname;
|
94 | 95 | }
|
95 | 96 |
|
96 |
| -static char *get_mmap_base_file(void) |
97 |
| -{ |
98 |
| - static char windir[MAXPATHLEN+UNLEN + 3 + sizeof("\\\\@") + 1 + 32 + 21]; |
99 |
| - char *uname; |
100 |
| - int l; |
101 |
| - |
102 |
| - uname = php_win32_get_username(); |
103 |
| - if (!uname) { |
104 |
| - return NULL; |
105 |
| - } |
106 |
| - GetTempPath(MAXPATHLEN, windir); |
107 |
| - l = strlen(windir); |
108 |
| - if ('\\' == windir[l-1]) { |
109 |
| - l--; |
110 |
| - } |
111 |
| - snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%s@%.20s@%.32s", ACCEL_FILEMAP_BASE, uname, sapi_module.name, ZCG(system_id)); |
112 |
| - |
113 |
| - free(uname); |
114 |
| - |
115 |
| - return windir; |
116 |
| -} |
117 |
| - |
118 | 97 | void zend_shared_alloc_create_lock(void)
|
119 | 98 | {
|
120 | 99 | memory_mutex = CreateMutex(NULL, FALSE, create_name_with_username(ACCEL_MUTEX_NAME));
|
@@ -143,39 +122,20 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in)
|
143 | 122 | {
|
144 | 123 | int err;
|
145 | 124 | void *wanted_mapping_base;
|
146 |
| - char *mmap_base_file = get_mmap_base_file(); |
147 |
| - FILE *fp = fopen(mmap_base_file, "r"); |
148 | 125 | MEMORY_BASIC_INFORMATION info;
|
149 | 126 | void *execute_ex_base;
|
150 | 127 | int execute_ex_moved;
|
151 | 128 |
|
152 |
| - if (!fp) { |
153 |
| - err = GetLastError(); |
154 |
| - zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err); |
155 |
| - zend_win_error_message(ACCEL_LOG_FATAL, "Unable to open base address file", err); |
156 |
| - *error_in="fopen"; |
157 |
| - return ALLOC_FAILURE; |
158 |
| - } |
159 |
| - if (!fscanf(fp, "%p", &wanted_mapping_base)) { |
| 129 | + mapping_base = MapViewOfFileEx(memfile, FILE_MAP_ALL_ACCESS, 0, 0, ACCEL_BASE_POINTER_SIZE, NULL); |
| 130 | + if (mapping_base == NULL) { |
160 | 131 | err = GetLastError();
|
161 | 132 | zend_win_error_message(ACCEL_LOG_FATAL, "Unable to read base address", err);
|
162 | 133 | *error_in="read mapping base";
|
163 |
| - fclose(fp); |
164 |
| - return ALLOC_FAILURE; |
165 |
| - } |
166 |
| - if (!fscanf(fp, "%p", &execute_ex_base)) { |
167 |
| - err = GetLastError(); |
168 |
| - zend_win_error_message(ACCEL_LOG_FATAL, "Unable to read execute_ex base address", err); |
169 |
| - *error_in="read execute_ex base"; |
170 |
| - fclose(fp); |
171 | 134 | return ALLOC_FAILURE;
|
172 | 135 | }
|
173 |
| - fclose(fp); |
174 |
| - |
175 |
| - if (0 > win32_utime(mmap_base_file, NULL)) { |
176 |
| - err = GetLastError(); |
177 |
| - zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err); |
178 |
| - } |
| 136 | + wanted_mapping_base = ((void**)mapping_base)[0]; |
| 137 | + execute_ex_base = ((void**)mapping_base)[1]; |
| 138 | + UnmapViewOfFile(mapping_base); |
179 | 139 |
|
180 | 140 | execute_ex_moved = (void *)execute_ex != execute_ex_base;
|
181 | 141 |
|
@@ -231,7 +191,7 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in)
|
231 | 191 | }
|
232 | 192 | return ALLOC_FAIL_MAPPING;
|
233 | 193 | }
|
234 |
| - smm_shared_globals = (zend_smm_shared_globals *) mapping_base; |
| 194 | + smm_shared_globals = (zend_smm_shared_globals *) ((char*)mapping_base + ACCEL_BASE_POINTER_SIZE); |
235 | 195 |
|
236 | 196 | return SUCCESSFULLY_REATTACHED;
|
237 | 197 | }
|
@@ -349,19 +309,9 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
|
349 | 309 | *error_in = "MapViewOfFile";
|
350 | 310 | return ALLOC_FAILURE;
|
351 | 311 | } else {
|
352 |
| - char *mmap_base_file = get_mmap_base_file(); |
353 |
| - void *execute_ex_base = (void *)execute_ex; |
354 |
| - FILE *fp = fopen(mmap_base_file, "w"); |
355 |
| - if (!fp) { |
356 |
| - err = GetLastError(); |
357 |
| - zend_shared_alloc_unlock_win32(); |
358 |
| - zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err); |
359 |
| - zend_win_error_message(ACCEL_LOG_FATAL, "Unable to write base address", err); |
360 |
| - return ALLOC_FAILURE; |
361 |
| - } |
362 |
| - fprintf(fp, "%p\n", mapping_base); |
363 |
| - fprintf(fp, "%p\n", execute_ex_base); |
364 |
| - fclose(fp); |
| 312 | + ((void**)mapping_base)[0] = mapping_base; |
| 313 | + ((void**)mapping_base)[1] = (void*)execute_ex; |
| 314 | + ((char*)shared_segment->p) += ACCEL_BASE_POINTER_SIZE; |
365 | 315 | }
|
366 | 316 |
|
367 | 317 | shared_segment->pos = 0;
|
|
0 commit comments