Skip to content

Commit 59c3dda

Browse files
committed
Remove support for preloading on Windows
Due to ASLR restrictions, preloading on Windows does not work with any code that has preloading dependencies on internal classes. This effectively makes it unusable for any non-trivial codebase. Instead of pretending like preloading is going to work, only to make people realize that it really doesn't once they get beyond a dummy example, we disable support for preloading on Windows entirely. Closes GH-4999.
1 parent 846b647 commit 59c3dda

37 files changed

+147
-141
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44
?? ??? ????, PHP 7.4.2
55

66
- Core:
7+
. Preloading support on Windows has been disabled. (Nikita)
78
. Fixed bug #79022 (class_exists returns True for classes that are not ready
89
to be used). (Laruence)
910
. Fixed bug #78929 (plus signs in cookie values are converted to spaces).

ext/ffi/tests/300-win32.phpt

Lines changed: 0 additions & 24 deletions
This file was deleted.

ext/ffi/tests/bug78761.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
--TEST--
22
Bug #78761 (Zend memory heap corruption with preload and casting)
33
--SKIPIF--
4-
<?php require_once('skipif.inc'); ?>
4+
<?php
5+
require_once('skipif.inc');
6+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
7+
?>
58
--INI--
69
opcache.enable_cli=1
710
opcache.preload={PWD}/bug78761_preload.php

ext/opcache/ZendAccelerator.c

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,13 +3397,6 @@ static void get_unlinked_dependency(zend_class_entry *ce, const char **kind, con
33973397
*name = ZSTR_VAL(ce->parent_name);
33983398
return;
33993399
}
3400-
#ifdef ZEND_WIN32
3401-
if (p->type == ZEND_INTERNAL_CLASS) {
3402-
*kind = "Windows can't link to internal parent ";
3403-
*name = ZSTR_VAL(ce->parent_name);
3404-
return;
3405-
}
3406-
#endif
34073400
if (!(p->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
34083401
*kind = "Parent with unresolved initializers ";
34093402
*name = ZSTR_VAL(ce->parent_name);
@@ -3523,13 +3516,6 @@ static zend_bool preload_try_resolve_property_types(zend_class_entry *ce)
35233516
continue;
35243517
}
35253518
if (p != ce) {
3526-
#ifdef ZEND_WIN32
3527-
/* On Windows we can't link with internal class, because of ASLR */
3528-
if (p->type == ZEND_INTERNAL_CLASS) {
3529-
ok = 0;
3530-
continue;
3531-
}
3532-
#endif
35333519
if (!(p->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
35343520
ok = 0;
35353521
continue;
@@ -3666,10 +3652,6 @@ static void preload_link(void)
36663652
parent = zend_hash_find_ptr(EG(class_table), key);
36673653
zend_string_release(key);
36683654
if (!parent) continue;
3669-
#ifdef ZEND_WIN32
3670-
/* On Windows we can't link with internal class, because of ASLR */
3671-
if (parent->type == ZEND_INTERNAL_CLASS) continue;
3672-
#endif
36733655
if (!(parent->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
36743656
continue;
36753657
}
@@ -3686,13 +3668,6 @@ static void preload_link(void)
36863668
found = 0;
36873669
break;
36883670
}
3689-
#ifdef ZEND_WIN32
3690-
/* On Windows we can't link with internal class, because of ASLR */
3691-
if (p->type == ZEND_INTERNAL_CLASS) {
3692-
found = 0;
3693-
break;
3694-
}
3695-
#endif
36963671
if (!(p->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
36973672
found = 0;
36983673
break;
@@ -3709,13 +3684,6 @@ static void preload_link(void)
37093684
found = 0;
37103685
break;
37113686
}
3712-
#ifdef ZEND_WIN32
3713-
/* On Windows we can't link with internal class, because of ASLR */
3714-
if (p->type == ZEND_INTERNAL_CLASS) {
3715-
found = 0;
3716-
break;
3717-
}
3718-
#endif
37193687
}
37203688
if (!found) continue;
37213689
}
@@ -3859,26 +3827,6 @@ static void preload_link(void)
38593827
} ZEND_HASH_FOREACH_END();
38603828
}
38613829

3862-
#ifdef ZEND_WIN32
3863-
static void preload_check_windows_restriction(zend_class_entry *scope, zend_class_entry *ce) {
3864-
if (ce && ce->type == ZEND_INTERNAL_CLASS) {
3865-
zend_error_noreturn(E_ERROR,
3866-
"Class %s uses internal class %s during preloading, which is not supported on Windows",
3867-
ZSTR_VAL(scope->name), ZSTR_VAL(ce->name));
3868-
}
3869-
}
3870-
3871-
static void preload_check_windows_restrictions(zend_class_entry *scope) {
3872-
uint32_t i;
3873-
3874-
preload_check_windows_restriction(scope, scope->parent);
3875-
3876-
for (i = 0; i < scope->num_interfaces; i++) {
3877-
preload_check_windows_restriction(scope, scope->interfaces[i]);
3878-
}
3879-
}
3880-
#endif
3881-
38823830
static inline int preload_update_class_constants(zend_class_entry *ce) {
38833831
/* This is a separate function to work around what appears to be a bug in GCC
38843832
* maybe-uninitialized analysis. */
@@ -3931,10 +3879,6 @@ static void preload_ensure_classes_loadable() {
39313879
continue;
39323880
}
39333881

3934-
#ifdef ZEND_WIN32
3935-
preload_check_windows_restrictions(ce);
3936-
#endif
3937-
39383882
if (!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
39393883
if (preload_update_class_constants(ce) == FAILURE) {
39403884
zend_error_noreturn(E_ERROR,
@@ -4601,9 +4545,11 @@ static int accel_finish_startup(void)
46014545
}
46024546

46034547
if (ZCG(accel_directives).preload && *ZCG(accel_directives).preload) {
4604-
#ifndef ZEND_WIN32
4548+
#ifdef ZEND_WIN32
4549+
zend_accel_error(ACCEL_LOG_ERROR, "Preloading is not supported on Windows");
4550+
return FAILURE;
4551+
#else
46054552
int in_child = 0;
4606-
#endif
46074553
int ret = SUCCESS;
46084554
int rc;
46094555
int orig_error_reporting;
@@ -4637,7 +4583,6 @@ static int accel_finish_startup(void)
46374583
return SUCCESS;
46384584
}
46394585

4640-
#ifndef ZEND_WIN32
46414586
if (geteuid() == 0) {
46424587
pid_t pid;
46434588
struct passwd *pw;
@@ -4701,7 +4646,6 @@ static int accel_finish_startup(void)
47014646
zend_accel_error(ACCEL_LOG_WARNING, "\"opcache.preload_user\" is ignored");
47024647
}
47034648
}
4704-
#endif
47054649

47064650
sapi_module.activate = NULL;
47074651
sapi_module.deactivate = NULL;
@@ -4713,11 +4657,9 @@ static int accel_finish_startup(void)
47134657
sapi_module.ub_write = preload_ub_write;
47144658
sapi_module.flush = preload_flush;
47154659

4716-
#ifndef ZEND_WIN32
47174660
if (in_child) {
47184661
CG(compiler_options) |= ZEND_COMPILE_PRELOAD_IN_CHILD;
47194662
}
4720-
#endif
47214663
CG(compiler_options) |= ZEND_COMPILE_PRELOAD;
47224664
CG(compiler_options) |= ZEND_COMPILE_HANDLE_OP_ARRAY;
47234665
CG(compiler_options) |= ZEND_COMPILE_IGNORE_INTERNAL_CLASSES;
@@ -4792,17 +4734,16 @@ static int accel_finish_startup(void)
47924734

47934735
sapi_activate();
47944736

4795-
#ifndef ZEND_WIN32
47964737
if (in_child) {
47974738
if (ret == SUCCESS) {
47984739
exit(0);
47994740
} else {
48004741
exit(2);
48014742
}
48024743
}
4803-
#endif
48044744

48054745
return ret;
4746+
#endif
48064747
}
48074748

48084749
return SUCCESS;

ext/opcache/tests/bug78014.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78014.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
class B extends A {

ext/opcache/tests/bug78175.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78175.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
OK
1215
--EXPECT--

ext/opcache/tests/bug78175_2.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78175_2.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
var_dump(get_class(Loader::getLoader()));

ext/opcache/tests/bug78376.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78376.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
var_dump(\A::$a);
1316
?>
1417
--EXPECT--
15-
string(4) "aaaa"
18+
string(4) "aaaa"

ext/opcache/tests/bug78937_1.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78937.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
class Bar {

ext/opcache/tests/bug78937_2.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78937.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
include(__DIR__ . "/preload_bug78937.inc");
@@ -19,4 +22,4 @@ Warning: Can't preload unlinked class Foo: Unknown parent Bar in %spreload_bug78
1922

2023
Warning: Can't preload unlinked class class@anonymous: Unknown parent Bar in %spreload_bug78937.inc on line 3
2124
object(class@anonymous)#%d (0) {
22-
}
25+
}

ext/opcache/tests/bug78937_3.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78937.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
include(__DIR__ . "/preload_bug78937.inc");

ext/opcache/tests/bug78937_4.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78937.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
class Bar {
@@ -19,4 +22,4 @@ Warning: Can't preload unlinked class Foo: Unknown parent Bar in %spreload_bug78
1922

2023
Warning: Can't preload unlinked class class@anonymous: Unknown parent Bar in %spreload_bug78937.inc on line 3
2124

22-
Fatal error: Class foo wasn't preloaded in %spreload_bug78937.inc on line 6
25+
Fatal error: Class foo wasn't preloaded in %spreload_bug78937.inc on line 6

ext/opcache/tests/bug78937_5.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78937.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
include(__DIR__ . "/preload_bug78937.inc");
@@ -20,4 +23,4 @@ Warning: Can't preload unlinked class Foo: Unknown parent Bar in %spreload_bug78
2023

2124
Warning: Can't preload unlinked class class@anonymous: Unknown parent Bar in %spreload_bug78937.inc on line 3
2225
object(Foo)#%d (0) {
23-
}
26+
}

ext/opcache/tests/bug78937_6.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload_bug78937.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
include(__DIR__ . "/preload_bug78937.inc");

ext/opcache/tests/preload_001.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
var_dump(function_exists("f1"));

ext/opcache/tests/preload_002.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
var_dump((new ReflectionMethod('x', 'foo'))->getPrototype()->class);

ext/opcache/tests/preload_003.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ opcache.enable_cli=1
66
opcache.optimization_level=-1
77
opcache.preload={PWD}/preload.inc
88
--SKIPIF--
9-
<?php require_once('skipif.inc'); ?>
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
1013
--FILE--
1114
<?php
1215
Y::foo();

0 commit comments

Comments
 (0)