Skip to content

Commit 8b7023e

Browse files
committed
Apply annotation feature to modules
1 parent 0e3933d commit 8b7023e

File tree

6 files changed

+12
-0
lines changed

6 files changed

+12
-0
lines changed

Modules/_ctypes/malloc_closure.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# endif
1515
#endif
1616
#include "ctypes.h"
17+
#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap()
1718

1819
/* BLOCKSIZE can be adjusted. Larger blocksize will take a larger memory
1920
overhead, but allocate less blocks from the system. It may be that some
@@ -82,6 +83,7 @@ static void more_core(void)
8283
0);
8384
if (item == (void *)MAP_FAILED)
8485
return;
86+
_PyMem_Annotate_Mmap(item, count * sizeof(ITEM), "Python:more_core");
8587
#endif
8688

8789
#ifdef MALLOC_CLOSURE_DEBUG

Modules/mmapmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
2727
#include "pycore_bytesobject.h" // _PyBytes_Find()
2828
#include "pycore_fileutils.h" // _Py_stat_struct
29+
#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap()
2930
#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
3031

3132
#include <stddef.h> // offsetof()
@@ -1951,6 +1952,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
19511952
PyErr_SetFromErrno(PyExc_OSError);
19521953
return NULL;
19531954
}
1955+
_PyMem_Annotate_Mmap(m_obj->data, map_size, "Python:new_mmap_object");
19541956
m_obj->access = (access_mode)access;
19551957
return (PyObject *)m_obj;
19561958
}

Objects/obmalloc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ _PyMem_ArenaAlloc(void *Py_UNUSED(ctx), size_t size)
467467
if (ptr == MAP_FAILED)
468468
return NULL;
469469
assert(ptr != NULL);
470+
_PyMem_Annotate_Mmap(ptr, size, "Python:PyMem_ArenaAlloc");
470471
return ptr;
471472
#else
472473
return malloc(size);

Python/jit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ jit_alloc(size_t size)
7171
int prot = PROT_READ | PROT_WRITE;
7272
unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0);
7373
int failed = memory == MAP_FAILED;
74+
if (!failed) {
75+
_PyMem_Annotate_Mmap(memory, size, "Python:jit_alloc");
76+
}
7477
#endif
7578
if (failed) {
7679
jit_error("unable to allocate memory");

Python/perf_jit_trampoline.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "pycore_ceval.h" // _PyPerf_Callbacks
6262
#include "pycore_frame.h"
6363
#include "pycore_interp.h"
64+
#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap()
6465
#include "pycore_runtime.h" // _PyRuntime
6566

6667
#ifdef PY_HAVE_PERF_TRAMPOLINE
@@ -1085,6 +1086,7 @@ static void* perf_map_jit_init(void) {
10851086
close(fd);
10861087
return NULL; // Memory mapping failed
10871088
}
1089+
_PyMem_Annotate_Mmap(perf_jit_map_state.mapped_buffer, page_size, "Python:perf_map_jit_init");
10881090
#endif
10891091

10901092
perf_jit_map_state.mapped_size = page_size;

Python/perf_trampoline.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ any DWARF information available for them).
132132
#include "Python.h"
133133
#include "pycore_ceval.h" // _PyPerf_Callbacks
134134
#include "pycore_interpframe.h" // _PyFrame_GetCode()
135+
#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap()
135136
#include "pycore_runtime.h" // _PyRuntime
136137

137138

@@ -290,6 +291,7 @@ new_code_arena(void)
290291
perf_status = PERF_STATUS_FAILED;
291292
return -1;
292293
}
294+
_PyMem_Annotate_Mmap(memory, mem_size, "Python:new_code_arena");
293295
void *start = &_Py_trampoline_func_start;
294296
void *end = &_Py_trampoline_func_end;
295297
size_t code_size = end - start;

0 commit comments

Comments
 (0)