|
33 | 33 |
|
34 | 34 | #define ACCEL_FILEMAP_NAME "ZendOPcache.SharedMemoryArea"
|
35 | 35 | #define ACCEL_MUTEX_NAME "ZendOPcache.SharedMemoryMutex"
|
| 36 | +#define ACCEL_FILEMAP_BASE_DEFAULT 0x01000000 |
| 37 | +#define ACCEL_FILEMAP_BASE "ZendOPcache.MemoryBase" |
36 | 38 | #define ACCEL_EVENT_SOURCE "Zend OPcache"
|
37 | 39 |
|
38 |
| -/* address of mapping base and address of execute_ex */ |
39 |
| -#define ACCEL_BASE_POINTER_SIZE (2 * sizeof(void*)) |
40 |
| - |
41 | 40 | static HANDLE memfile = NULL, memory_mutex = NULL;
|
42 | 41 | static void *mapping_base;
|
43 | 42 |
|
@@ -76,6 +75,22 @@ static char *create_name_with_username(char *name)
|
76 | 75 | return newname;
|
77 | 76 | }
|
78 | 77 |
|
| 78 | +static char *get_mmap_base_file(void) |
| 79 | +{ |
| 80 | + static char windir[MAXPATHLEN+ 32 + 3 + sizeof("\\\\@") + 1 + 32 + 21]; |
| 81 | + int l; |
| 82 | + |
| 83 | + GetTempPath(MAXPATHLEN, windir); |
| 84 | + l = strlen(windir); |
| 85 | + if ('\\' == windir[l-1]) { |
| 86 | + l--; |
| 87 | + } |
| 88 | + |
| 89 | + snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%.32s@%.20s@%.32s", ACCEL_FILEMAP_BASE, accel_uname_id, sapi_module.name, accel_system_id); |
| 90 | + |
| 91 | + return windir; |
| 92 | +} |
| 93 | + |
79 | 94 | void zend_shared_alloc_create_lock(void)
|
80 | 95 | {
|
81 | 96 | memory_mutex = CreateMutex(NULL, FALSE, create_name_with_username(ACCEL_MUTEX_NAME));
|
@@ -104,20 +119,39 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in)
|
104 | 119 | {
|
105 | 120 | int err;
|
106 | 121 | void *wanted_mapping_base;
|
| 122 | + char *mmap_base_file = get_mmap_base_file(); |
| 123 | + FILE *fp = fopen(mmap_base_file, "r"); |
107 | 124 | MEMORY_BASIC_INFORMATION info;
|
108 | 125 | void *execute_ex_base;
|
109 | 126 | int execute_ex_moved;
|
110 | 127 |
|
111 |
| - mapping_base = MapViewOfFileEx(memfile, FILE_MAP_ALL_ACCESS, 0, 0, ACCEL_BASE_POINTER_SIZE, NULL); |
112 |
| - if (mapping_base == NULL) { |
| 128 | + if (!fp) { |
| 129 | + err = GetLastError(); |
| 130 | + zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err); |
| 131 | + zend_win_error_message(ACCEL_LOG_FATAL, "Unable to open base address file", err); |
| 132 | + *error_in="fopen"; |
| 133 | + return ALLOC_FAILURE; |
| 134 | + } |
| 135 | + if (!fscanf(fp, "%p", &wanted_mapping_base)) { |
113 | 136 | err = GetLastError();
|
114 | 137 | zend_win_error_message(ACCEL_LOG_FATAL, "Unable to read base address", err);
|
115 | 138 | *error_in="read mapping base";
|
| 139 | + fclose(fp); |
| 140 | + return ALLOC_FAILURE; |
| 141 | + } |
| 142 | + if (!fscanf(fp, "%p", &execute_ex_base)) { |
| 143 | + err = GetLastError(); |
| 144 | + zend_win_error_message(ACCEL_LOG_FATAL, "Unable to read execute_ex base address", err); |
| 145 | + *error_in="read execute_ex base"; |
| 146 | + fclose(fp); |
116 | 147 | return ALLOC_FAILURE;
|
117 | 148 | }
|
118 |
| - wanted_mapping_base = ((void**)mapping_base)[0]; |
119 |
| - execute_ex_base = ((void**)mapping_base)[1]; |
120 |
| - UnmapViewOfFile(mapping_base); |
| 149 | + fclose(fp); |
| 150 | + |
| 151 | + if (0 > win32_utime(mmap_base_file, NULL)) { |
| 152 | + err = GetLastError(); |
| 153 | + zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err); |
| 154 | + } |
121 | 155 |
|
122 | 156 | execute_ex_moved = (void *)execute_ex != execute_ex_base;
|
123 | 157 |
|
@@ -173,7 +207,7 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in)
|
173 | 207 | }
|
174 | 208 | return ALLOC_FAIL_MAPPING;
|
175 | 209 | }
|
176 |
| - smm_shared_globals = (zend_smm_shared_globals *) ((char*)mapping_base + ACCEL_BASE_POINTER_SIZE); |
| 210 | + smm_shared_globals = (zend_smm_shared_globals *) mapping_base; |
177 | 211 |
|
178 | 212 | return SUCCESSFULLY_REATTACHED;
|
179 | 213 | }
|
@@ -291,9 +325,19 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
|
291 | 325 | *error_in = "MapViewOfFile";
|
292 | 326 | return ALLOC_FAILURE;
|
293 | 327 | } else {
|
294 |
| - ((void**)mapping_base)[0] = mapping_base; |
295 |
| - ((void**)mapping_base)[1] = (void*)execute_ex; |
296 |
| - ((char*)shared_segment->p) += ACCEL_BASE_POINTER_SIZE; |
| 328 | + char *mmap_base_file = get_mmap_base_file(); |
| 329 | + void *execute_ex_base = (void *)execute_ex; |
| 330 | + FILE *fp = fopen(mmap_base_file, "w"); |
| 331 | + if (!fp) { |
| 332 | + err = GetLastError(); |
| 333 | + zend_shared_alloc_unlock_win32(); |
| 334 | + zend_win_error_message(ACCEL_LOG_WARNING, mmap_base_file, err); |
| 335 | + zend_win_error_message(ACCEL_LOG_FATAL, "Unable to write base address", err); |
| 336 | + return ALLOC_FAILURE; |
| 337 | + } |
| 338 | + fprintf(fp, "%p\n", mapping_base); |
| 339 | + fprintf(fp, "%p\n", execute_ex_base); |
| 340 | + fclose(fp); |
297 | 341 | }
|
298 | 342 |
|
299 | 343 | shared_segment->pos = 0;
|
|
0 commit comments