Skip to content

Commit 8032d70

Browse files
committed
Change ini settings modifiability to INI_SYSTEM
1 parent da14c4a commit 8032d70

File tree

5 files changed

+51
-42
lines changed

5 files changed

+51
-42
lines changed

Zend/zend.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ static ZEND_INI_MH(OnUpdateMaxAllowedStackSize) /* {{{ */
179179
{
180180
zend_long size = zend_ini_parse_quantity_warn(new_value, entry->name);
181181

182-
if (size < ZEND_MAX_ALLOWED_STACK_USAGE_UNCHECKED) {
182+
if (size < ZEND_MAX_ALLOWED_STACK_SIZE_UNCHECKED) {
183183
zend_error(E_WARNING, "Invalid \"%s\" setting. Value must be >= %d, but got " ZEND_LONG_FMT,
184-
ZSTR_VAL(entry->name), ZEND_MAX_ALLOWED_STACK_USAGE_UNCHECKED, size);
184+
ZSTR_VAL(entry->name), ZEND_MAX_ALLOWED_STACK_SIZE_UNCHECKED, size);
185185
return FAILURE;
186186
}
187187

@@ -252,9 +252,9 @@ ZEND_INI_BEGIN()
252252
STD_ZEND_INI_ENTRY("fiber.stack_size", NULL, ZEND_INI_ALL, OnUpdateFiberStackSize, fiber_stack_size, zend_executor_globals, executor_globals)
253253
#ifdef ZEND_CHECK_STACK_LIMIT
254254
/* The maximum allowed call stack size. 0: auto detect, -1: no limit. For fibers, this is fiber.stack_size. */
255-
STD_ZEND_INI_ENTRY("zend.max_allowed_stack_size", "0", ZEND_INI_PERDIR, OnUpdateMaxAllowedStackSize, max_allowed_stack_size, zend_executor_globals, executor_globals)
255+
STD_ZEND_INI_ENTRY("zend.max_allowed_stack_size", "0", ZEND_INI_SYSTEM, OnUpdateMaxAllowedStackSize, max_allowed_stack_size, zend_executor_globals, executor_globals)
256256
/* Substracted from the max allowed stack size, as a buffer, when checking for overflow. 0: auto detect. */
257-
STD_ZEND_INI_ENTRY("zend.reserved_stack_size", "0", ZEND_INI_PERDIR, OnUpdateReservedStackSize, reserved_stack_size, zend_executor_globals, executor_globals)
257+
STD_ZEND_INI_ENTRY("zend.reserved_stack_size", "0", ZEND_INI_SYSTEM, OnUpdateReservedStackSize, reserved_stack_size, zend_executor_globals, executor_globals)
258258
#endif
259259

260260
ZEND_INI_END()
@@ -851,10 +851,8 @@ static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{
851851
executor_globals->errors = NULL;
852852

853853
# ifdef ZEND_CHECK_STACK_LIMIT
854-
if (!zend_call_stack_get(&executor_globals->call_stack)) {
855-
executor_globals->call_stack = (zend_call_stack){0};
856-
}
857-
# endif /* ZEND_CHECK_STACK_LIMIT */
854+
zend_call_stack_init();
855+
# endif
858856
}
859857
/* }}} */
860858

@@ -1041,12 +1039,6 @@ void zend_startup(zend_utility_functions *utility_functions) /* {{{ */
10411039
CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(NULL);
10421040
CG(map_ptr_size) = 0;
10431041
CG(map_ptr_last) = 0;
1044-
1045-
# ifdef ZEND_CHECK_STACK_LIMIT
1046-
if (!zend_call_stack_get(&EG(call_stack))) {
1047-
EG(call_stack) = (zend_call_stack){0};
1048-
}
1049-
# endif /* ZEND_CHECK_STACK_LIMIT */
10501042
#endif /* ZTS */
10511043
EG(error_reporting) = E_ALL & ~E_NOTICE;
10521044

@@ -1140,6 +1132,9 @@ zend_result zend_post_startup(void) /* {{{ */
11401132
zend_copy_ini_directives();
11411133
#else
11421134
global_map_ptr_last = CG(map_ptr_last);
1135+
# ifdef ZEND_CHECK_STACK_LIMIT
1136+
zend_call_stack_init();
1137+
# endif
11431138
#endif
11441139

11451140
return SUCCESS;

Zend/zend_call_stack.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/* Inspired from Chromium's stack_util.cc */
2020

2121
#include "zend.h"
22+
#include "zend_globals.h"
2223
#include "zend_portability.h"
2324
#include "zend_call_stack.h"
2425
#include <stdint.h>
@@ -47,6 +48,43 @@
4748
#include <sys/syscall.h>
4849
#endif
4950

51+
/* Called once per process or thread */
52+
ZEND_API void zend_call_stack_init(void) {
53+
if (!zend_call_stack_get(&EG(call_stack))) {
54+
EG(call_stack) = (zend_call_stack){0};
55+
}
56+
57+
switch (EG(max_allowed_stack_size)) {
58+
case ZEND_MAX_ALLOWED_STACK_SIZE_DETECT: {
59+
void *base = EG(call_stack).base;
60+
size_t size = EG(call_stack).max_size;
61+
if (UNEXPECTED(base == (void*)0)) {
62+
base = zend_call_stack_position();
63+
size = zend_call_stack_default_size();
64+
/* base is not the actual stack base */
65+
size -= 32 * 1024;
66+
}
67+
EG(stack_base) = base;
68+
EG(stack_limit) = zend_call_stack_limit(base, size, EG(reserved_stack_size));
69+
break;
70+
}
71+
case ZEND_MAX_ALLOWED_STACK_SIZE_UNCHECKED: {
72+
EG(stack_base) = (void*)0;
73+
EG(stack_limit) = (void*)0;
74+
break;
75+
}
76+
default: {
77+
ZEND_ASSERT(EG(max_allowed_stack_size) > 0);
78+
void *base = EG(call_stack).base;
79+
if (UNEXPECTED(base == (void*)0)) {
80+
base = zend_call_stack_position();
81+
}
82+
EG(stack_base) = base;
83+
EG(stack_limit) = zend_call_stack_limit(base, EG(max_allowed_stack_size), EG(reserved_stack_size));
84+
break;
85+
}
86+
}
87+
}
5088

5189
#ifdef __linux__
5290
static bool zend_call_stack_is_main_thread(void) {

Zend/zend_call_stack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ typedef struct _zend_call_stack {
3030
size_t max_size;
3131
} zend_call_stack;
3232

33+
ZEND_API void zend_call_stack_init(void);
34+
3335
ZEND_API bool zend_call_stack_get(zend_call_stack *stack);
3436

3537
/** Returns an approximation of the current stack position */

Zend/zend_execute_API.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -172,32 +172,6 @@ void init_executor(void) /* {{{ */
172172
ZEND_ATOMIC_BOOL_INIT(&EG(vm_interrupt), false);
173173
ZEND_ATOMIC_BOOL_INIT(&EG(timed_out), false);
174174

175-
#ifdef ZEND_CHECK_STACK_LIMIT
176-
if (EXPECTED(EG(max_allowed_stack_size) == ZEND_MAX_ALLOWED_STACK_USAGE_DETECT)) {
177-
void *base = EG(call_stack).base;
178-
size_t size = EG(call_stack).max_size;
179-
if (UNEXPECTED(base == (void*)0)) {
180-
base = zend_call_stack_position();
181-
size = zend_call_stack_default_size();
182-
/* base is not the actual stack base */
183-
size -= 32 * 1024;
184-
}
185-
EG(stack_base) = base;
186-
EG(stack_limit) = zend_call_stack_limit(base, size, EG(reserved_stack_size));
187-
} else if (EG(max_allowed_stack_size) == ZEND_MAX_ALLOWED_STACK_USAGE_UNCHECKED) {
188-
EG(stack_base) = (void*)0;
189-
EG(stack_limit) = (void*)0;
190-
} else {
191-
ZEND_ASSERT(EG(max_allowed_stack_size) > 0);
192-
void *base = EG(call_stack).base;
193-
if (UNEXPECTED(base == (void*)0)) {
194-
base = zend_call_stack_position();
195-
}
196-
EG(stack_base) = base;
197-
EG(stack_limit) = zend_call_stack_limit(base, EG(max_allowed_stack_size), EG(reserved_stack_size));
198-
}
199-
#endif /* ZEND_CHECK_STACK_LIMIT */
200-
201175
EG(exception) = NULL;
202176
EG(prev_exception) = NULL;
203177

Zend/zend_globals.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ END_EXTERN_C()
5656
#define SYMTABLE_CACHE_SIZE 32
5757

5858
#ifdef ZEND_CHECK_STACK_LIMIT
59-
# define ZEND_MAX_ALLOWED_STACK_USAGE_UNCHECKED -1
60-
# define ZEND_MAX_ALLOWED_STACK_USAGE_DETECT 0
59+
# define ZEND_MAX_ALLOWED_STACK_SIZE_UNCHECKED -1
60+
# define ZEND_MAX_ALLOWED_STACK_SIZE_DETECT 0
6161
#endif
6262

6363
#include "zend_compile.h"

0 commit comments

Comments
 (0)