Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions Include/internal/pycore_mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ extern "C" {

#include "pycore_pystate.h"

#if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that you should fix the detecting logic of HAVE_PR_SET_VMA_ANON_NAME not code itself.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See here:

cpython/configure.ac

Lines 5731 to 5740 in bfe6f9f

# musl libc redefines struct prctl_mm_map and conflicts with linux/prctl.h
AS_IF([test "$ac_cv_libc" != musl], [
AC_CHECK_DECLS([PR_SET_VMA_ANON_NAME],
[AC_DEFINE([HAVE_PR_SET_VMA_ANON_NAME], [1],
[Define if you have the 'PR_SET_VMA_ANON_NAME' constant.])],
[],
[@%:@include <linux/prctl.h>
@%:@include <sys/prctl.h>])
])
# check for openpty, login_tty, and forkpty

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Why would I fix the detection logic to address a compile-time error in the actual implementation?

When you think about what this configure step actually does, you may notice that what we are detecting there has no real connection to reality.
The set of macro definitions in the two header files is either whatever the libc has copied from a random kernel version (<sys/prctl.h>) or whatever the version of the system's linux-headers package contains (<linux/prctl.h>).

Both of which don't have to match the kernel which will then actually run the interpreter in the future.

Say, the interpreter is compiled as part of the build chain of some distro which is then used as the base image for a Linux container.
The kernel on which this container may be run does not have to have anything in common with the kernel the distro in the base image usually ships.
What does this configure check tell us?

Further, the mere presence of #define HAVE_PR_SET_VMA_ANON_NAME in <linux/prctl.h> says nothing about whether the kernel has CONFIG_ANON_VMA_NAME enabled.
So Python could call prctl() on a kernel which does not support this feature.

# include <linux/prctl.h>
# include <sys/prctl.h>
#if defined(__linux__)

#include <sys/prctl.h>

#ifndef PR_SET_VMA
# define PR_SET_VMA 0x53564d41
#endif
#ifndef PR_SET_VMA_ANON_NAME
# define PR_SET_VMA_ANON_NAME 0
#endif

#if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__)
static inline int
_PyAnnotateMemoryMap(void *addr, size_t size, const char *name)
{
Expand All @@ -33,12 +38,15 @@ _PyAnnotateMemoryMap(void *addr, size_t size, const char *name)
}
return 0;
}

#else

static inline int
_PyAnnotateMemoryMap(void *Py_UNUSED(addr), size_t Py_UNUSED(size), const char *Py_UNUSED(name))
{
return 0;
}

#endif

#ifdef __cplusplus
Expand Down
24 changes: 0 additions & 24 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5728,15 +5728,6 @@ AC_CHECK_DECLS([UT_NAMESIZE],
[Define if you have the 'HAVE_UT_NAMESIZE' constant.])],
[],
[@%:@include <utmp.h>])
# musl libc redefines struct prctl_mm_map and conflicts with linux/prctl.h
AS_IF([test "$ac_cv_libc" != musl], [
AC_CHECK_DECLS([PR_SET_VMA_ANON_NAME],
[AC_DEFINE([HAVE_PR_SET_VMA_ANON_NAME], [1],
[Define if you have the 'PR_SET_VMA_ANON_NAME' constant.])],
[],
[@%:@include <linux/prctl.h>
@%:@include <sys/prctl.h>])
])
# check for openpty, login_tty, and forkpty

AC_CHECK_FUNCS([openpty], [],
Expand Down
7 changes: 0 additions & 7 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,6 @@
/* Define to 1 if you have the <db.h> header file. */
#undef HAVE_DB_H

/* Define to 1 if you have the declaration of 'PR_SET_VMA_ANON_NAME', and to 0
if you don't. */
#undef HAVE_DECL_PR_SET_VMA_ANON_NAME

/* Define to 1 if you have the declaration of 'RTLD_DEEPBIND', and to 0 if you
don't. */
#undef HAVE_DECL_RTLD_DEEPBIND
Expand Down Expand Up @@ -1003,9 +999,6 @@
/* Define if your compiler supports function prototype */
#undef HAVE_PROTOTYPES

/* Define if you have the 'PR_SET_VMA_ANON_NAME' constant. */
#undef HAVE_PR_SET_VMA_ANON_NAME

/* Define to 1 if you have the 'pthread_condattr_setclock' function. */
#undef HAVE_PTHREAD_CONDATTR_SETCLOCK

Expand Down
Loading