@@ -3,57 +3,85 @@ Determine whether Fibers can be used and add Boost fiber assembly files support
33if available for the platform. As a Boost fallback alternative ucontext support
44is 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
2315include (CheckIncludeFiles)
2416include (CheckSourceRuns)
17+ include (CMakeDependentOption)
2518include (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.
2731add_library (zend_fibers INTERFACE )
2832add_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
5886block()
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 ()
188211endblock()
0 commit comments