Skip to content

Refactor SHADOW_STACK_SYSCALL check #14575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2024
Merged
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
29 changes: 15 additions & 14 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1322,9 +1322,9 @@ else
fiber_asm="no"
fi

dnl Check whether syscall to create shadow stack exists, should be a better way, but...
AC_CACHE_CHECK([whether syscall to create shadow stack exists], ac_cv_syscall_shadow_stack_exists,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
AC_CACHE_CHECK([whether syscall to create shadow stack exists],
[php_cv_have_shadow_stack_syscall],
[AC_RUN_IFELSE([AC_LANG_SOURCE([
#include <unistd.h>
#include <sys/mman.h>
int main(void) {
Expand All @@ -1334,18 +1334,19 @@ int main(void) {
munmap(base, 0x20000);
return 0;
}
else
return 1;
return 1;
}
]])], [ac_cv_syscall_shadow_stack_exists=yes], [ac_cv_syscall_shadow_stack_exists=no], [ac_cv_syscall_shadow_stack_exists=no])
])],
[php_cv_have_shadow_stack_syscall=yes],
[php_cv_have_shadow_stack_syscall=no],
[php_cv_have_shadow_stack_syscall=no])
])
if test "$ac_cv_syscall_shadow_stack_exists" = yes; then
AC_DEFINE([SHADOW_STACK_SYSCALL], 1, [ ])
# asm file can't see macro from AC_DEFINE, workaround this via cflag
fiber_asm_cflag="-DSHADOW_STACK_SYSCALL=1"
# if the syscall doesn't exist, we may block the final ELF from __PROPERTY_SHSTK
# via redefine macro as "-D__CET__=1"
fi
dnl The asm files can't see macro from AC_DEFINE, workaround this via cflag. If
dnl the syscall doesn't exist, we may block the final ELF from __PROPERTY_SHSTK
dnl via redefine macro as "-D__CET__=1".
AS_VAR_IF([php_cv_have_shadow_stack_syscall], [yes],
[fiber_asm_cflag="-DSHADOW_STACK_SYSCALL=1"],
[fiber_asm_cflag="-DSHADOW_STACK_SYSCALL=0"])

if test "$fiber_asm" = 'yes'; then
AC_MSG_CHECKING([for fiber switching context])
Expand Down Expand Up @@ -1776,7 +1777,7 @@ PHP_ADD_SOURCES(Zend, \
Optimizer/escape_analysis.c \
Optimizer/compact_vars.c \
Optimizer/zend_dump.c \
, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
, [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 $fiber_asm_cflag])

PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/scripts/Makefile.frag,$abs_srcdir/scripts,scripts)
PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/Zend/Makefile.frag,$abs_srcdir/Zend,Zend)
Expand Down
Loading