Skip to content

Commit 5e987e3

Browse files
committed
fix: Windows implementations
1 parent 2fd4213 commit 5e987e3

11 files changed

Lines changed: 154 additions & 175 deletions

ext/opcache/tests/helpers/volatile_cache_zts_request_shared_graph_refs_001.c

Lines changed: 16 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -23,93 +23,27 @@
2323
#include <stdio.h>
2424
#include <string.h>
2525

26-
#include "Zend/zend_atomic.h"
2726
#include "Zend/zend_exceptions.h"
2827
#include "Zend/zend_execute.h"
2928
#include "Zend/zend_portability.h"
3029

3130
#include "sapi/embed/php_embed.h"
32-
#include "zend_static_cache_internal.h"
31+
#ifndef ZEND_WIN32
32+
# include "Zend/zend_atomic.h"
33+
# include "zend_static_cache_internal.h"
34+
#endif
3335

3436
#ifndef ZTS
3537
# error "This helper requires a ZTS build"
3638
#endif
3739

3840
#define REQUEST_COUNT 4
3941

40-
typedef struct _zend_opcache_test_accel_directives {
41-
zend_long memory_consumption;
42-
zend_long static_cache_volatile_size_mb;
43-
zend_long max_accelerated_files;
44-
double max_wasted_percentage;
45-
char *user_blacklist_filename;
46-
zend_long force_restart_timeout;
47-
bool use_cwd;
48-
bool ignore_dups;
49-
bool validate_timestamps;
50-
bool revalidate_path;
51-
bool save_comments;
52-
bool record_warnings;
53-
bool protect_memory;
54-
bool file_override_enabled;
55-
bool enable_cli;
56-
bool validate_permission;
57-
#ifndef ZEND_WIN32
58-
bool validate_root;
59-
#endif
60-
zend_ulong revalidate_freq;
61-
zend_ulong file_update_protection;
62-
char *error_log;
63-
#ifdef ZEND_WIN32
64-
char *mmap_base;
65-
#endif
66-
char *memory_model;
67-
zend_long log_verbosity_level;
68-
zend_long optimization_level;
69-
zend_long opt_debug_level;
70-
zend_long max_file_size;
71-
zend_long interned_strings_buffer;
72-
char *restrict_api;
73-
#ifndef ZEND_WIN32
74-
char *lockfile_path;
75-
#endif
76-
char *file_cache;
77-
bool file_cache_read_only;
78-
bool file_cache_only;
79-
bool file_cache_consistency_checks;
80-
#if ENABLE_FILE_CACHE_FALLBACK
81-
bool file_cache_fallback;
82-
#endif
83-
#ifdef HAVE_HUGE_CODE_PAGES
84-
bool huge_code_pages;
85-
#endif
86-
char *preload;
87-
#ifndef ZEND_WIN32
88-
char *preload_user;
89-
#endif
90-
#ifdef ZEND_WIN32
91-
char *cache_id;
92-
#endif
93-
} zend_opcache_test_accel_directives;
94-
95-
typedef struct _zend_opcache_test_globals {
96-
bool counted;
97-
bool enabled;
98-
bool locked;
99-
bool accelerator_enabled;
100-
bool pcre_reseted;
101-
zend_opcache_test_accel_directives accel_directives;
102-
} zend_opcache_test_globals;
103-
10442
typedef struct _zend_opcache_ref_thread_ctx {
10543
int result;
10644
char message[256];
10745
} zend_opcache_ref_thread_ctx;
10846

109-
extern size_t accel_globals_offset;
110-
111-
#define ZEND_OPCACHE_TEST_CG(v) ZEND_TSRMG_FAST(accel_globals_offset, zend_opcache_test_globals *, v)
112-
11347
static const char opcache_test_ini[] =
11448
"html_errors=0\n"
11549
"implicit_flush=1\n"
@@ -160,9 +94,7 @@ static const char worker_code[] =
16094
" return true;"
16195
"})()";
16296

163-
static zend_opcache_test_accel_directives zend_opcache_thread_accel_directives;
164-
static bool zend_opcache_thread_enabled;
165-
97+
#ifndef ZEND_WIN32
16698
static const zend_opcache_static_cache_shared_graph_header *zend_opcache_locate_shared_graph_header(uint32_t payload_offset)
16799
{
168100
const unsigned char *buffer;
@@ -193,6 +125,7 @@ static const zend_opcache_static_cache_shared_graph_header *zend_opcache_locate_
193125

194126
return header;
195127
}
128+
#endif
196129

197130
static int zend_opcache_test_startup(int argc, char **argv)
198131
{
@@ -214,9 +147,6 @@ static int zend_opcache_test_startup(int argc, char **argv)
214147
return FAILURE;
215148
}
216149

217-
zend_opcache_thread_accel_directives = ZEND_OPCACHE_TEST_CG(accel_directives);
218-
zend_opcache_thread_enabled = ZEND_OPCACHE_TEST_CG(enabled);
219-
220150
SG(options) |= SAPI_OPTION_NO_CHDIR;
221151
return SUCCESS;
222152
}
@@ -232,8 +162,6 @@ static bool zend_opcache_thread_request_startup(void)
232162
{
233163
(void) ts_resource(0);
234164
ZEND_TSRMLS_CACHE_UPDATE();
235-
ZEND_OPCACHE_TEST_CG(accel_directives) = zend_opcache_thread_accel_directives;
236-
ZEND_OPCACHE_TEST_CG(enabled) = zend_opcache_thread_enabled;
237165

238166
SG(request_info).argc = 0;
239167
SG(request_info).argv = NULL;
@@ -299,6 +227,7 @@ static bool zend_opcache_run_request_code(const char *code, const char *label, b
299227
return false;
300228
}
301229

230+
#ifndef ZEND_WIN32
302231
if (expect_single_shared_graph_ref && zend_opcache_static_cache_shared_graph_ref_count != 1) {
303232
snprintf(
304233
message,
@@ -313,6 +242,9 @@ static bool zend_opcache_run_request_code(const char *code, const char *label, b
313242
php_request_shutdown(NULL);
314243
return false;
315244
}
245+
#else
246+
(void) expect_single_shared_graph_ref;
247+
#endif
316248

317249
if (!Z_ISUNDEF(retval)) {
318250
zval_ptr_dtor(&retval);
@@ -321,6 +253,7 @@ static bool zend_opcache_run_request_code(const char *code, const char *label, b
321253
return true;
322254
}
323255

256+
#ifndef ZEND_WIN32
324257
static bool zend_opcache_inspect_current_payload_state(
325258
uint32_t *value_offset_out,
326259
uint32_t *next_free_out,
@@ -395,13 +328,16 @@ static bool zend_opcache_inspect_current_payload_state(
395328
zend_opcache_static_cache_restore_context(previous_context);
396329
return ok;
397330
}
331+
#endif
398332

399333
static void *zend_opcache_ref_thread_main(void *arg)
400334
{
401335
zend_opcache_ref_thread_ctx *ctx = (zend_opcache_ref_thread_ctx *) arg;
336+
#ifndef ZEND_WIN32
402337
uint32_t expected_offset = 0;
403338
uint32_t value_offset, next_free;
404339
int refcount;
340+
#endif
405341
int iteration;
406342

407343
ctx->result = 0;
@@ -419,6 +355,7 @@ static void *zend_opcache_ref_thread_main(void *arg)
419355
break;
420356
}
421357

358+
#ifndef ZEND_WIN32
422359
if (!zend_opcache_inspect_current_payload_state(&value_offset, &next_free, &refcount, ctx->message, sizeof(ctx->message))) {
423360
ctx->result = 1;
424361
break;
@@ -452,6 +389,7 @@ static void *zend_opcache_ref_thread_main(void *arg)
452389
);
453390
break;
454391
}
392+
#endif
455393
}
456394

457395
ts_free_thread();

ext/opcache/tests/helpers/volatile_cache_zts_threads_003.c

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -32,70 +32,6 @@
3232
# error "This helper requires a ZTS build"
3333
#endif
3434

35-
typedef struct _zend_opcache_test_accel_directives {
36-
zend_long memory_consumption;
37-
zend_long static_cache_volatile_size_mb;
38-
zend_long max_accelerated_files;
39-
double max_wasted_percentage;
40-
char *user_blacklist_filename;
41-
zend_long force_restart_timeout;
42-
bool use_cwd;
43-
bool ignore_dups;
44-
bool validate_timestamps;
45-
bool revalidate_path;
46-
bool save_comments;
47-
bool record_warnings;
48-
bool protect_memory;
49-
bool file_override_enabled;
50-
bool enable_cli;
51-
bool validate_permission;
52-
#ifndef ZEND_WIN32
53-
bool validate_root;
54-
#endif
55-
zend_ulong revalidate_freq;
56-
zend_ulong file_update_protection;
57-
char *error_log;
58-
#ifdef ZEND_WIN32
59-
char *mmap_base;
60-
#endif
61-
char *memory_model;
62-
zend_long log_verbosity_level;
63-
zend_long optimization_level;
64-
zend_long opt_debug_level;
65-
zend_long max_file_size;
66-
zend_long interned_strings_buffer;
67-
char *restrict_api;
68-
#ifndef ZEND_WIN32
69-
char *lockfile_path;
70-
#endif
71-
char *file_cache;
72-
bool file_cache_read_only;
73-
bool file_cache_only;
74-
bool file_cache_consistency_checks;
75-
#if ENABLE_FILE_CACHE_FALLBACK
76-
bool file_cache_fallback;
77-
#endif
78-
#ifdef HAVE_HUGE_CODE_PAGES
79-
bool huge_code_pages;
80-
#endif
81-
char *preload;
82-
#ifndef ZEND_WIN32
83-
char *preload_user;
84-
#endif
85-
#ifdef ZEND_WIN32
86-
char *cache_id;
87-
#endif
88-
} zend_opcache_test_accel_directives;
89-
90-
typedef struct _zend_opcache_test_globals {
91-
bool counted;
92-
bool enabled;
93-
bool locked;
94-
bool accelerator_enabled;
95-
bool pcre_reseted;
96-
zend_opcache_test_accel_directives accel_directives;
97-
} zend_opcache_test_globals;
98-
9935
typedef struct _zend_opcache_thread_ctx {
10036
const char *mode;
10137
const char *scenario_path;
@@ -104,10 +40,6 @@ typedef struct _zend_opcache_thread_ctx {
10440
char message[256];
10541
} zend_opcache_thread_ctx;
10642

107-
extern size_t accel_globals_offset;
108-
109-
#define ZEND_OPCACHE_TEST_CG(v) ZEND_TSRMG_FAST(accel_globals_offset, zend_opcache_test_globals *, v)
110-
11143
static const char opcache_test_ini[] =
11244
"html_errors=0\n"
11345
"implicit_flush=1\n"
@@ -120,9 +52,6 @@ static const char opcache_test_ini[] =
12052
"opcache.max_accelerated_files=200\n"
12153
"opcache.static_cache.volatile_size_mb=32\n\0";
12254

123-
static zend_opcache_test_accel_directives zend_opcache_thread_accel_directives;
124-
static bool zend_opcache_thread_enabled;
125-
12655
static char *zend_opcache_build_scenario_code(const char *mode, const char *scenario_path);
12756

12857
static int zend_opcache_test_startup(int argc, char **argv)
@@ -145,9 +74,6 @@ static int zend_opcache_test_startup(int argc, char **argv)
14574
return FAILURE;
14675
}
14776

148-
zend_opcache_thread_accel_directives = ZEND_OPCACHE_TEST_CG(accel_directives);
149-
zend_opcache_thread_enabled = ZEND_OPCACHE_TEST_CG(enabled);
150-
15177
SG(options) |= SAPI_OPTION_NO_CHDIR;
15278
return SUCCESS;
15379
}
@@ -163,8 +89,6 @@ static bool zend_opcache_thread_request_startup(void)
16389
{
16490
(void) ts_resource(0);
16591
ZEND_TSRMLS_CACHE_UPDATE();
166-
ZEND_OPCACHE_TEST_CG(accel_directives) = zend_opcache_thread_accel_directives;
167-
ZEND_OPCACHE_TEST_CG(enabled) = zend_opcache_thread_enabled;
16892

16993
SG(request_info).argc = 0;
17094
SG(request_info).argv = NULL;

ext/opcache/tests/php_cli_server.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ function php_cli_server_start($ini = "", $doc_root = null) {
9797
for ($i = 0; $i < 60; $i++) {
9898
$status = proc_get_status($handle);
9999
if (!($status && $status['running'])) {
100-
if ($status && $status['exitcode'] !== -1 && $status['exitcode'] !== 0) {
100+
if ($status && $status['exitcode'] !== -1 && $status['exitcode'] !== 0
101+
&& !($status['exitcode'] === 255 && PHP_OS_FAMILY === 'Windows')) {
101102
printf("Server exited with non-zero status: %d\n", $status['exitcode']);
102103
printf("Server output:\n%s\n", file_get_contents($output_file));
103104
}

ext/opcache/tests/static_cache_persistent_static_store_failure_exception_001.phpt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ class PinnedStaticStoreFailureUnsupportedValueBox
5959
}
6060

6161
OPcache\pinned_clear();
62+
$nullDevice = PHP_OS_FAMILY === 'Windows' ? 'NUL' : '/dev/null';
6263

6364
dump_static_cache_exception('property-resource', function (): void {
64-
$resource = fopen('/dev/null', 'r');
65+
global $nullDevice;
66+
67+
$resource = fopen($nullDevice, 'r');
6568
try {
6669
PinnedStaticStoreFailureProperty::$value = $resource;
6770
} finally {
@@ -76,7 +79,9 @@ dump_static_cache_exception('property-closure', function (): void {
7679
});
7780

7881
dump_static_cache_exception('property-object-resource', function (): void {
79-
$resource = fopen('/dev/null', 'r');
82+
global $nullDevice;
83+
84+
$resource = fopen($nullDevice, 'r');
8085
try {
8186
PinnedStaticStoreFailureProperty::$value = new PinnedStaticStoreFailureUnsupportedValueBox($resource);
8287
} finally {

ext/opcache/tests/static_cache_persistent_static_zts_threads_001.phpt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,26 @@ function resolveBuildCommand(string $buildRoot, string $variable, array $fallbac
149149
}
150150

151151
$tokens = resolveBuildFlags($buildRoot, [$variable]);
152-
return $tokens !== [] ? $tokens : $fallback;
152+
return $tokens !== [] ? $tokens : $fallback;
153+
}
154+
155+
function resolveWindowsBuildFlags(): array
156+
{
157+
return [
158+
'/MD',
159+
'/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1',
160+
'/D_WINDOWS',
161+
'/DWINDOWS=1',
162+
'/DZEND_WIN32=1',
163+
'/DPHP_WIN32=1',
164+
'/DWIN32',
165+
'/D_MBCS',
166+
'/D_USE_MATH_DEFINES',
167+
'/DZTS=1',
168+
'/DZEND_DEBUG=0',
169+
'/DNDebug',
170+
'/DNDEBUG',
171+
];
153172
}
154173

155174
function resolveBuildRoot(string $root): string
@@ -223,19 +242,21 @@ if ($root === false) {
223242
}
224243

225244
$buildRoot = resolveBuildRoot($root);
245+
if (PHP_OS_FAMILY === 'Windows') {
246+
putenv('PATH=' . $buildRoot . PATH_SEPARATOR . (getenv('PATH') ?: ''));
247+
}
226248
$source = __DIR__ . '/helpers/pinned_static_zts_threads_001.c';
227249
$binary = __DIR__ . '/helpers/pinned_static_zts_threads_001' . (PHP_OS_FAMILY === 'Windows' ? '.exe' : '.out');
228250
$scenario = __DIR__ . '/helpers/pinned_static_zts_threads_001.inc';
229251
$compiler = resolveBuildCommand($buildRoot, 'CC', PHP_OS_FAMILY === 'Windows' ? ['cl'] : ['gcc']);
230-
$buildFlags = PHP_OS_FAMILY === 'Windows' ? [] : resolveBuildFlags($buildRoot, ['CPPFLAGS', 'CFLAGS_CLEAN']);
252+
$buildFlags = PHP_OS_FAMILY === 'Windows' ? resolveWindowsBuildFlags() : resolveBuildFlags($buildRoot, ['CPPFLAGS', 'CFLAGS_CLEAN']);
231253
$extraLibs = resolveExtraLibs($buildRoot);
232254

233255
if (PHP_OS_FAMILY === 'Windows') {
234256
$compileCommand = [
235257
...$compiler,
236258
'/nologo',
237-
'/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1',
238-
'/DHAVE_CONFIG_H',
259+
...$buildFlags,
239260
'/I' . $buildRoot,
240261
'/I' . $buildRoot . '/main',
241262
'/I' . $buildRoot . '/Zend',

0 commit comments

Comments
 (0)