Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/generate_diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function formatDiff(?int $baseInstructions, int $headInstructions): string {
}

function find_benchmarked_commit_hash(string $repo, string $commitHash): ?string {
$repeat = 10;
$repeat = 100;

while (true) {
if ($repeat-- <= 0) {
Expand Down
27 changes: 12 additions & 15 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -3968,24 +3968,18 @@ PHP_FUNCTION(date_diff)
}
/* }}} */

static bool timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t tz_len, char **warning_message) /* {{{ */
static bool timezone_initialize(php_timezone_obj *tzobj, const zend_string *tz_zstr, char **warning_message) /* {{{ */
{
timelib_time *dummy_t = ecalloc(1, sizeof(timelib_time));
int dst, not_found;
const char *orig_tz = tz;
const char *tz = ZSTR_VAL(tz_zstr);

if (strlen(tz) != tz_len) {
if (warning_message) {
spprintf(warning_message, 0, "Timezone must not contain null bytes");
}
efree(dummy_t);
return false;
}
ZEND_ASSERT(!zend_str_has_nul_byte(tz_zstr) && "timezone should have been checked to not have null bytes");

dummy_t->z = timelib_parse_zone(&tz, &dst, dummy_t, &not_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
if ((dummy_t->z >= (100 * 60 * 60)) || (dummy_t->z <= (-100 * 60 * 60))) {
if (warning_message) {
spprintf(warning_message, 0, "Timezone offset is out of range (%s)", orig_tz);
spprintf(warning_message, 0, "Timezone offset is out of range (%s)", ZSTR_VAL(tz_zstr));
}
timelib_free(dummy_t->tz_abbr);
efree(dummy_t);
Expand All @@ -3994,15 +3988,15 @@ static bool timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t
dummy_t->dst = dst;
if (!not_found && (*tz != '\0')) {
if (warning_message) {
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", orig_tz);
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
}
timelib_free(dummy_t->tz_abbr);
efree(dummy_t);
return false;
}
if (not_found) {
if (warning_message) {
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", orig_tz);
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
}
efree(dummy_t);
return false;
Expand All @@ -4026,7 +4020,7 @@ PHP_FUNCTION(timezone_open)
ZEND_PARSE_PARAMETERS_END();

tzobj = Z_PHPTIMEZONE_P(php_date_instantiate(date_ce_timezone, return_value));
if (!timezone_initialize(tzobj, ZSTR_VAL(tz), ZSTR_LEN(tz), &warning_message)) {
if (!timezone_initialize(tzobj, tz, &warning_message)) {
php_error_docref(NULL, E_WARNING, "%s", warning_message);
efree(warning_message);
zval_ptr_dtor(return_value);
Expand All @@ -4047,7 +4041,7 @@ PHP_METHOD(DateTimeZone, __construct)
ZEND_PARSE_PARAMETERS_END();

tzobj = Z_PHPTIMEZONE_P(ZEND_THIS);
if (!timezone_initialize(tzobj, ZSTR_VAL(tz), ZSTR_LEN(tz), &exception_message)) {
if (!timezone_initialize(tzobj, tz, &exception_message)) {
zend_throw_exception_ex(date_ce_date_invalid_timezone_exception, 0, "DateTimeZone::__construct(): %s", exception_message);
efree(exception_message);
RETURN_THROWS();
Expand Down Expand Up @@ -4078,7 +4072,10 @@ static bool php_date_timezone_initialize_from_hash(zval **return_value, php_time
if (Z_TYPE_P(z_timezone) != IS_STRING) {
return false;
}
return timezone_initialize(*tzobj, Z_STRVAL_P(z_timezone), Z_STRLEN_P(z_timezone), NULL);
if (UNEXPECTED(zend_str_has_nul_byte(Z_STR_P(z_timezone)))) {
return false;
}
return timezone_initialize(*tzobj, Z_STR_P(z_timezone), NULL);
} /* }}} */

/* {{{ */
Expand Down
19 changes: 0 additions & 19 deletions ext/intl/tests/dateformat_invalid_timezone.phpt

This file was deleted.

4 changes: 4 additions & 0 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -4845,6 +4845,8 @@ static zend_result accel_finish_startup_preload(bool in_child)
bool old_reset_signals = SIGG(reset);
#endif

ZCG(preloading) = true;

sapi_module.activate = NULL;
sapi_module.deactivate = NULL;
sapi_module.register_server_variables = NULL;
Expand Down Expand Up @@ -4926,6 +4928,8 @@ static zend_result accel_finish_startup_preload(bool in_child)
sapi_module.ub_write = orig_ub_write;
sapi_module.flush = orig_flush;

ZCG(preloading) = false;

sapi_activate();

return ret;
Expand Down
1 change: 1 addition & 0 deletions ext/opcache/ZendAccelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ typedef struct _zend_accel_globals {
#endif
void *preloaded_internal_run_time_cache;
size_t preloaded_internal_run_time_cache_size;
bool preloading;
/* preallocated shared-memory block to save current script */
void *mem;
zend_persistent_script *current_persistent_script;
Expand Down
3 changes: 3 additions & 0 deletions ext/opcache/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ PHP_NEW_EXTENSION([opcache], m4_normalize([
shared_alloc_mmap.c
shared_alloc_posix.c
shared_alloc_shm.c
zend_accelerator_api.c
zend_accelerator_blacklist.c
zend_accelerator_debug.c
zend_accelerator_hash.c
Expand Down Expand Up @@ -361,3 +362,5 @@ AS_VAR_IF([PHP_OPCACHE_JIT], [yes], [
])
PHP_ADD_MAKEFILE_FRAGMENT([$ext_srcdir/jit/Makefile.frag])
])

PHP_INSTALL_HEADERS([ext/opcache], [zend_accelerator_api.h])
3 changes: 3 additions & 0 deletions ext/opcache/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PHP_OPCACHE="yes";

ZEND_EXTENSION('opcache', "\
ZendAccelerator.c \
zend_accelerator_api.c \
zend_accelerator_blacklist.c \
zend_accelerator_debug.c \
zend_accelerator_hash.c \
Expand Down Expand Up @@ -68,3 +69,5 @@ if (PHP_OPCACHE_JIT == "yes") {
}

ADD_FLAG('CFLAGS_OPCACHE', "/I " + configure_module_dirname);

PHP_INSTALL_HEADERS("ext/opcache", "zend_accelerator_api.h");
3 changes: 3 additions & 0 deletions ext/opcache/tests/api/opcache_preloading.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
printf("%s: %d\n", __FILE__, zend_test_opcache_preloading());
?>
21 changes: 21 additions & 0 deletions ext/opcache/tests/api/opcache_preloading_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
opcache_preloading() api 001
--EXTENSIONS--
zend_test
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.preload={PWD}/opcache_preloading.inc
--SKIPIF--
<?php
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php

printf("%s: %d\n", __FILE__, zend_test_opcache_preloading());

?>
--EXPECTF--
%sopcache_preloading.inc: 1
%sopcache_preloading_001.php: 0
24 changes: 24 additions & 0 deletions ext/opcache/tests/api/opcache_preloading_002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
opcache_preloading() api 002
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.preload={PWD}/opcache_preloading.inc
opcache.preload_user={ENV:TEST_NON_ROOT_USER}
--EXTENSIONS--
posix
zend_test
--SKIPIF--
<?php
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
if (posix_geteuid() !== 0) die('skip Test needs root user');
?>
--FILE--
<?php

printf("%s: %d\n", __FILE__, zend_test_opcache_preloading());

?>
--EXPECTF--
%sopcache_preloading.inc: 1
%sopcache_preloading_002.php: 0
23 changes: 23 additions & 0 deletions ext/opcache/zend_accelerator_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
+----------------------------------------------------------------------+
| Zend OPcache |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/

#include "zend_accelerator_api.h"
#include "ZendAccelerator.h"

ZEND_API bool opcache_preloading(void)
{
return ZCG(preloading);
}
29 changes: 29 additions & 0 deletions ext/opcache/zend_accelerator_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
+----------------------------------------------------------------------+
| Zend OPcache |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/

#ifndef ZEND_ACCELERATOR_API_H
#define ZEND_ACCELERATOR_API_H

#include "Zend/zend_portability.h"

BEGIN_EXTERN_C()

/* Returns true during preloading */
ZEND_API bool opcache_preloading(void);

END_EXTERN_C()

#endif /* ZEND_ACCELERATOR_API_H */
9 changes: 9 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
+----------------------------------------------------------------------+
*/

#include "ext/opcache/zend_accelerator_api.h"
#include "zend_API.h"
#include "zend_modules.h"
#include "zend_types.h"
#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -1645,3 +1647,10 @@ static PHP_FUNCTION(zend_test_gh18756)
zend_mm_gc(heap);
zend_mm_shutdown(heap, true, false);
}

static PHP_FUNCTION(zend_test_opcache_preloading)
{
ZEND_PARSE_PARAMETERS_NONE();

RETURN_BOOL(opcache_preloading());
}
2 changes: 2 additions & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ function zend_test_log_err_debug(string $str): void {}
function zend_test_compile_to_ast(string $str): string {}

function zend_test_gh18756(): void {}

function zend_test_opcache_preloading(): bool {}
}

namespace ZendTestNS {
Expand Down
6 changes: 5 additions & 1 deletion ext/zend_test/test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
#include "ext/random/php_random_csprng.h"
#include "ext/random/php_random_zend_utils.h"
#include "ext/opcache/ZendAccelerator.h"
#include "ext/opcache/jit/zend_jit.h"
#ifdef HAVE_JIT
# include "ext/opcache/jit/zend_jit.h"
#endif
#include "php_variables.h"
#include "ext/standard/credits.h"
#ifdef PHP_WIN32
Expand Down Expand Up @@ -2807,7 +2809,10 @@ PHPAPI void php_reserve_tsrm_memory(void)
TSRM_ALIGNED_SIZE(sizeof(php_core_globals)) +
TSRM_ALIGNED_SIZE(sizeof(sapi_globals_struct)) +
TSRM_ALIGNED_SIZE(sizeof(zend_accel_globals)) +
TSRM_ALIGNED_SIZE(sizeof(zend_jit_globals))
#ifdef HAVE_JIT
TSRM_ALIGNED_SIZE(sizeof(zend_jit_globals)) +
#endif
0
);
}
/* }}} */
Expand Down