Skip to content

Commit 478237d

Browse files
committed
Fix nits
- Refactored Zend CMake files - Synced cache variable names
1 parent d2d082c commit 478237d

File tree

5 files changed

+116
-119
lines changed

5 files changed

+116
-119
lines changed

cmake/Zend/CMakeLists.txt

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@ include(PHP/AddCustomCommand)
6767
# Configuration.
6868
################################################################################
6969

70-
cmake_dependent_option(
71-
ZEND_FIBER_ASM
72-
"Enable the use of Boost fiber assembly files"
73-
ON
74-
[[NOT CMAKE_SYSTEM_NAME STREQUAL "Windows"]]
75-
ON
76-
)
77-
mark_as_advanced(ZEND_FIBER_ASM)
78-
7970
cmake_dependent_option(
8071
ZEND_SIGNALS
8172
"Enable Zend signal handling"
@@ -431,7 +422,10 @@ include(cmake/CheckFloatPrecision.cmake)
431422
include(cmake/CheckMMAlignment.cmake)
432423
include(cmake/CheckStackDirection.cmake)
433424
include(cmake/CheckStrerrorR.cmake)
425+
include(cmake/Fibers.cmake)
426+
include(cmake/GenerateGrammar.cmake)
434427
include(cmake/GlobalRegisterVariables.cmake)
428+
include(cmake/MaxExecutionTimers.cmake)
435429

436430
################################################################################
437431
# Zend signals.
@@ -455,27 +449,6 @@ add_feature_info(
455449
"signal handling for performance"
456450
)
457451

458-
################################################################################
459-
# Zend max execution timers.
460-
################################################################################
461-
462-
include(cmake/MaxExecutionTimers.cmake)
463-
464-
################################################################################
465-
# Generate parser and lexer files.
466-
################################################################################
467-
468-
include(cmake/GenerateGrammar.cmake)
469-
470-
################################################################################
471-
# Configure fibers.
472-
################################################################################
473-
474-
include(cmake/Fibers.cmake)
475-
if(TARGET Zend::Fibers)
476-
target_link_libraries(zend PRIVATE Zend::Fibers)
477-
endif()
478-
479452
################################################################################
480453
# Create files and set installation.
481454
################################################################################
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
#[=============================================================================[
22
Check whether the stack grows downwards. Assumes contiguous stack.
33
4-
Result/cache variables:
4+
Result variables:
55
6-
* ZEND_CHECK_STACK_LIMIT - Whether checking the stack limit is supported.
6+
* ZEND_CHECK_STACK_LIMIT
77
#]=============================================================================]
88

9-
# Skip in consecutive configuration phases.
10-
if(DEFINED ZEND_CHECK_STACK_LIMIT)
11-
return()
12-
endif()
9+
include(CheckSourceRuns)
10+
include(CMakePushCheckState)
1311

1412
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
1513
set(ZEND_CHECK_STACK_LIMIT TRUE)
1614
return()
1715
endif()
1816

19-
include(CheckSourceRuns)
20-
include(CMakePushCheckState)
21-
22-
message(CHECK_START "Checking whether the stack grows downwards")
23-
24-
cmake_push_check_state(RESET)
25-
set(CMAKE_REQUIRED_QUIET TRUE)
26-
27-
check_source_runs(C [[
28-
#include <stdint.h>
29-
30-
int (*volatile f)(uintptr_t);
31-
32-
int stack_grows_downwards(uintptr_t arg)
33-
{
34-
int local;
35-
return (uintptr_t)&local < arg;
36-
}
37-
38-
int main(void)
39-
{
40-
int local;
41-
42-
f = stack_grows_downwards;
43-
return f((uintptr_t)&local) ? 0 : 1;
44-
}
45-
]] ZEND_CHECK_STACK_LIMIT)
46-
cmake_pop_check_state()
47-
48-
if(ZEND_CHECK_STACK_LIMIT)
49-
message(CHECK_PASS "yes")
50-
else()
51-
message(CHECK_FAIL "no")
17+
# Skip in consecutive configuration phases.
18+
if(NOT DEFINED PHP_ZEND_CHECK_STACK_LIMIT)
19+
message(CHECK_START "Checking whether the stack grows downwards")
20+
21+
cmake_push_check_state(RESET)
22+
set(CMAKE_REQUIRED_QUIET TRUE)
23+
24+
check_source_runs(C [[
25+
#include <stdint.h>
26+
27+
int (*volatile f)(uintptr_t);
28+
29+
int stack_grows_downwards(uintptr_t arg)
30+
{
31+
int local;
32+
return (uintptr_t)&local < arg;
33+
}
34+
35+
int main(void)
36+
{
37+
int local;
38+
39+
f = stack_grows_downwards;
40+
return f((uintptr_t)&local) ? 0 : 1;
41+
}
42+
]] PHP_ZEND_CHECK_STACK_LIMIT)
43+
cmake_pop_check_state()
44+
45+
if(PHP_ZEND_CHECK_STACK_LIMIT)
46+
message(CHECK_PASS "yes")
47+
else()
48+
message(CHECK_FAIL "no")
49+
endif()
5250
endif()
51+
52+
set(ZEND_CHECK_STACK_LIMIT ${PHP_ZEND_CHECK_STACK_LIMIT})

cmake/Zend/cmake/Fibers.cmake

Lines changed: 69 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,85 @@ Determine whether Fibers can be used and add Boost fiber assembly files support
33
if available for the platform. As a Boost fallback alternative ucontext support
44
is checked if it can be used.
55
6-
Control variables:
6+
Configuration options:
77
8-
* ZEND_FIBER_ASM - Whether to use Boost fiber assembly files.
8+
* ZEND_FIBER_ASM
99
10-
Cache variables:
10+
Result variables:
1111
12-
* ZEND_FIBER_UCONTEXT - Whether <ucontext.h> header file is available and should
13-
be used.
14-
15-
Interface library:
16-
17-
* Zend::Fibers
18-
19-
Interface library using Boost fiber assembly files and compile options if
20-
available.
12+
* ZEND_FIBER_UCONTEXT
2113
#]=============================================================================]
2214

2315
include(CheckIncludeFiles)
2416
include(CheckSourceRuns)
17+
include(CMakeDependentOption)
2518
include(CMakePushCheckState)
2619

20+
cmake_dependent_option(
21+
ZEND_FIBER_ASM
22+
"Enable the use of Boost fiber assembly files"
23+
ON
24+
[[NOT CMAKE_SYSTEM_NAME STREQUAL "Windows"]]
25+
ON
26+
)
27+
mark_as_advanced(ZEND_FIBER_ASM)
28+
29+
# Create interface library for using Boost fiber assembly files and compile
30+
# options if available.
2731
add_library(zend_fibers INTERFACE)
2832
add_library(Zend::Fibers ALIAS zend_fibers)
33+
target_link_libraries(zend PRIVATE Zend::Fibers)
34+
35+
################################################################################
36+
# Check shadow stack.
37+
################################################################################
2938

30-
if(NOT DEFINED SHADOW_STACK_SYSCALL)
31-
message(CHECK_START "Whether syscall to create shadow stack exists")
32-
cmake_push_check_state(RESET)
33-
set(CMAKE_REQUIRED_QUIET TRUE)
34-
35-
check_source_runs(C [[
36-
#include <unistd.h>
37-
#include <sys/mman.h>
38-
int main(void)
39-
{
40-
void* base = (void *)syscall(451, 0, 0x20000, 0x1);
41-
if (base != (void*)-1) {
42-
munmap(base, 0x20000);
43-
return 0;
39+
function(_php_zend_fibers_shadow_stack_syscall)
40+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
41+
set(PHP_ZEND_SHADOW_STACK_SYSCALL FALSE)
42+
endif()
43+
44+
if(NOT DEFINED PHP_ZEND_SHADOW_STACK_SYSCALL)
45+
message(CHECK_START "Whether syscall to create shadow stack exists")
46+
cmake_push_check_state(RESET)
47+
set(CMAKE_REQUIRED_QUIET TRUE)
48+
49+
check_source_runs(C [[
50+
#include <unistd.h>
51+
#include <sys/mman.h>
52+
int main(void)
53+
{
54+
void* base = (void *)syscall(451, 0, 0x20000, 0x1);
55+
if (base != (void*)-1) {
56+
munmap(base, 0x20000);
57+
return 0;
58+
}
59+
return 1;
4460
}
45-
return 1;
46-
}
47-
]] SHADOW_STACK_SYSCALL)
48-
cmake_pop_check_state()
49-
if(SHADOW_STACK_SYSCALL)
50-
message(CHECK_PASS "yes")
51-
else()
52-
# If the syscall doesn't exist, we may block the final ELF from
53-
# __PROPERTY_SHSTK via redefine macro as "-D__CET__=1".
54-
message(CHECK_FAIL "no")
61+
]] PHP_ZEND_SHADOW_STACK_SYSCALL)
62+
cmake_pop_check_state()
63+
64+
if(PHP_ZEND_SHADOW_STACK_SYSCALL)
65+
message(CHECK_PASS "yes")
66+
else()
67+
# If the syscall doesn't exist, we may block the final ELF from
68+
# __PROPERTY_SHSTK via redefine macro as "-D__CET__=1".
69+
message(CHECK_FAIL "no")
70+
endif()
5571
endif()
56-
endif()
72+
73+
# Use compile definitions because ASM files can't see macro definitions from
74+
# the PHP configuration header (php_config.h/config.w32.h).
75+
target_compile_definitions(
76+
zend_fibers
77+
INTERFACE
78+
$<IF:$<BOOL:${PHP_ZEND_SHADOW_STACK_SYSCALL}>,SHADOW_STACK_SYSCALL=1,SHADOW_STACK_SYSCALL=0>
79+
)
80+
endfunction()
81+
82+
################################################################################
83+
# Configure fibers.
84+
################################################################################
5785

5886
block()
5987
set(cpu "")
@@ -146,13 +174,7 @@ block()
146174

147175
target_sources(zend_fibers INTERFACE ${asmSources})
148176

149-
# Use compile definitions because ASM files can't see macro definitions from
150-
# the PHP configuration header (php_config.h/config.w32.h).
151-
target_compile_definitions(
152-
zend_fibers
153-
INTERFACE
154-
$<IF:$<BOOL:${SHADOW_STACK_SYSCALL}>,SHADOW_STACK_SYSCALL=1,SHADOW_STACK_SYSCALL=0>
155-
)
177+
_php_zend_fibers_shadow_stack_syscall()
156178
else()
157179
cmake_push_check_state(RESET)
158180
# To use ucontext.h on macOS, the _XOPEN_SOURCE needs to be defined to any
@@ -173,16 +195,17 @@ block()
173195
)
174196
endif()
175197

176-
check_include_files(ucontext.h ZEND_FIBER_UCONTEXT)
198+
check_include_files(ucontext.h PHP_ZEND_FIBER_UCONTEXT)
177199
cmake_pop_check_state()
178200

179-
if(NOT ZEND_FIBER_UCONTEXT)
201+
if(NOT PHP_ZEND_FIBER_UCONTEXT)
180202
message(CHECK_FAIL "no")
181203
message(
182204
FATAL_ERROR
183205
"Fibers are not available on this platform, <ucontext.h> not found."
184206
)
185207
endif()
186208
message(CHECK_PASS "yes, ucontext")
209+
set(ZEND_FIBER_UCONTEXT TRUE PARENT_SCOPE)
187210
endif()
188211
endblock()

cmake/cmake/presets/windows.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"PHP_EXT_CALENDAR": true,
1313
"PHP_EXT_DL_TEST": true,
1414
"PHP_EXT_DOM": false,
15+
"PHP_EXT_EXIF": true,
1516
"PHP_EXT_FTP": true,
1617
"PHP_EXT_FTP_SSL": false,
1718
"PHP_EXT_ICONV": false,

cmake/cmake/toolchains/template.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ set(PHP_WRITE_STDOUT_EXITCODE 0)
3636
# Zend Engine
3737
################################################################################
3838

39-
# Set the exit code for the check if syscall to create shadow stack exists.
40-
set(SHADOW_STACK_SYSCALL_EXITCODE 1)
41-
4239
# Set the exit code of the stack limit check.
43-
set(ZEND_CHECK_STACK_LIMIT_EXITCODE 1)
40+
set(PHP_ZEND_CHECK_STACK_LIMIT_EXITCODE 0)
41+
42+
# Set the exit code of the check if syscall to create shadow stack exists.
43+
set(PHP_ZEND_SHADOW_STACK_SYSCALL_EXITCODE 1)
4444

4545
# Set the exit code and the output of the ZEND_MM check.
4646
# See CheckMMAlignment.cmake.

0 commit comments

Comments
 (0)