Skip to content

Simplify UFFDIO_WRITEPROTECT_MODE_WP Autoconf check #13564

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
Mar 2, 2024

Conversation

petk
Copy link
Member

@petk petk commented Mar 1, 2024

AC_CHECK_DECL can check whether preprocessor macro is defined in the given includes.

AC_CHECK_DECL can check whether preprocessor macro is defined in the
given includes.
#endif
]])], [ac_cv_phpdbg_userfaultfd_writefault=yes], [ac_cv_phpdbg_userfaultfd_writefault=no]))
if test "$ac_cv_phpdbg_userfaultfd_writefault" = "yes"; then
AC_CHECK_DECL([UFFDIO_WRITEPROTECT_MODE_WP], [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for macros? The manual for AC_CHECK_DECL talks about symbol (a function, variable, or constant).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah wait, I get it: This macro actually tests whether it is valid to use symbol as an r-value. So this should indeed be fine.

@petk
Copy link
Member Author

petk commented Mar 2, 2024

I was also confused about the docs and was hesitating whether to check these with the AC_CHECK_DECL or it would be better to compile and use the #error... :D

This:

AC_CHECK_DECL([UFFDIO_WRITEPROTECT_MODE_WP],,,[#include <linux/userfaultfd.h>]

Will try to compile a program similar to the one below, which works also for the preprocessor macros whether they are defined. A bit of a hack and the macro name abuse, but it works flawlessly and can simplify many things in the future probably. However, all these checking macros must be called after the AC_PROG_CC and AC_USE_SYSTEM_EXTENSIONS calls, so the compiler is determined.

/* confdefs.h */
#define PACKAGE_NAME "PHP"
#define PACKAGE_TARNAME "php"
#define PACKAGE_VERSION "8.4.0-dev"
#define PACKAGE_STRING "PHP 8.4.0-dev"
#define PACKAGE_BUGREPORT "https://github.com/php/php-src/issues"
#define PACKAGE_URL "https://www.php.net"
#define HAVE_STDIO_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRING_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_STRINGS_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_UNISTD_H 1
#define HAVE_WCHAR_H 1
#define STDC_HEADERS 1
#define _ALL_SOURCE 1
#define _DARWIN_C_SOURCE 1
#define _GNU_SOURCE 1
#define _HPUX_ALT_XOPEN_SOCKET_API 1
#define _NETBSD_SOURCE 1
#define _OPENBSD_SOURCE 1
#define _POSIX_PTHREAD_SEMANTICS 1
#define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1
#define __STDC_WANT_IEC_60559_BFP_EXT__ 1
#define __STDC_WANT_IEC_60559_DFP_EXT__ 1
#define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1
#define __STDC_WANT_IEC_60559_TYPES_EXT__ 1
#define __STDC_WANT_LIB_EXT2__ 1
#define __STDC_WANT_MATH_SPEC_FUNCS__ 1
#define _TANDEM_SOURCE 1
#define __EXTENSIONS__ 1
#define HAVE_GCC_GLOBAL_REGS 1
#define HAVE_CPUID_COUNT 1
#define GWINSZ_IN_SYS_IOCTL 1
#define HAVE_PHPDBG 1
#define PHPDBG_DEBUG 0
#define HAVE_USERFAULTFD_WRITEFAULT 1
#define PHP_WRITE_STDOUT 1
#define HAVE_SOCKET 1
#define HAVE_SOCKETPAIR 1
#define HAVE_HTONL 1
#define HAVE_GETHOSTNAME 1
#define HAVE_GETHOSTBYADDR 1
#define HAVE_LIBDL 1
/* end confdefs.h.  */
#include <linux/userfaultfd.h>

int
main (void)
{
#ifndef UFFDIO_WRITEPROTECT_MODE_WP
#ifdef __cplusplus
  (void) UFFDIO_WRITEPROTECT_MODE_WP;
#else
  (void) UFFDIO_WRITEPROTECT_MODE_WP;
#endif
#endif

  ;
  return 0;
}

@nielsdos
Copy link
Member

nielsdos commented Mar 2, 2024

Yeah that makes sense. Thanks for explaining it!
LGTM

@petk petk merged commit 734f686 into php:master Mar 2, 2024
@petk petk deleted the patch-phpdbg-UFFDIO_WRITEPROTECT_MODE_WP branch March 2, 2024 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants