Skip to content

Commit 0e3933d

Browse files
committed
gh-141770: Annotate anonymous mmap only for debug build
1 parent 5ec03cf commit 0e3933d

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

Include/internal/pycore_pymem.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ extern "C" {
1111
# error "this header requires Py_BUILD_CORE define"
1212
#endif
1313

14+
#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME)
15+
#include <sys/prctl.h>
16+
#endif
17+
1418
// Try to get the allocators name set by _PyMem_SetupAllocators().
1519
// Return NULL if unknown.
1620
// Export for '_testinternalcapi' shared extension.
@@ -91,6 +95,16 @@ static inline int _PyMem_IsULongFreed(unsigned long value)
9195
#endif
9296
}
9397

98+
static inline int _PyMem_Annotate_Mmap(void *addr, size_t size, const char *name)
99+
{
100+
#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME)
101+
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name);
102+
return 0;
103+
#else
104+
return 0;
105+
#endif
106+
}
107+
94108
extern int _PyMem_GetAllocatorName(
95109
const char *name,
96110
PyMemAllocatorName *allocator);

configure

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5578,6 +5578,12 @@ AC_CHECK_DECLS([UT_NAMESIZE],
55785578
[],
55795579
[@%:@include <utmp.h>])
55805580

5581+
AC_CHECK_DECLS([PR_SET_VMA_ANON_NAME],
5582+
[AC_DEFINE([HAVE_PR_SET_VMA_ANON_NAME], [1],
5583+
[Define if you have the 'PR_SET_VMA_ANON_NAME' constant.])],
5584+
[],
5585+
[@%:@include <linux/prctl.h>])
5586+
55815587
# check for openpty, login_tty, and forkpty
55825588

55835589
AC_CHECK_FUNCS([openpty], [],

pyconfig.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@
228228
/* Define to 1 if you have the <db.h> header file. */
229229
#undef HAVE_DB_H
230230

231+
/* Define to 1 if you have the declaration of 'PR_SET_VMA_ANON_NAME', and to 0
232+
if you don't. */
233+
#undef HAVE_DECL_PR_SET_VMA_ANON_NAME
234+
231235
/* Define to 1 if you have the declaration of 'RTLD_DEEPBIND', and to 0 if you
232236
don't. */
233237
#undef HAVE_DECL_RTLD_DEEPBIND
@@ -996,6 +1000,9 @@
9961000
/* Define if your compiler supports function prototype */
9971001
#undef HAVE_PROTOTYPES
9981002

1003+
/* Define if you have the 'PR_SET_VMA_ANON_NAME' constant. */
1004+
#undef HAVE_PR_SET_VMA_ANON_NAME
1005+
9991006
/* Define to 1 if you have the 'pthread_condattr_setclock' function. */
10001007
#undef HAVE_PTHREAD_CONDATTR_SETCLOCK
10011008

0 commit comments

Comments
 (0)