-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-142419: Add mmap.set_name method for user custom annotation #142480
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
base: main
Are you sure you want to change the base?
Changes from all commits
f19909e
c65e691
d354eba
91d4aea
5919851
6c13efc
5586acd
73ac4b9
a931201
831bd7e
c7185f0
3a2654d
cc3cf8a
bd02cc5
fa52b0e
73bf762
94d0268
a9df12f
2d6d632
ca4bcec
987cf09
2a5d9a4
9adcf8e
522ef49
13138d9
2ece41b
cf96361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| :meth:`mmap.mmap.set_name` method added to annotate an anonymous memory map | ||
| if Linux kernel supports ``PR_SET_VMA_ANON_NAME`` (Linux 5.17 or newer). | ||
| Patch by Donghee Na. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1117,6 +1117,44 @@ mmap_mmap_seek_impl(mmap_object *self, Py_ssize_t dist, int how) | |
| return NULL; | ||
| } | ||
|
|
||
| /*[clinic input] | ||
| mmap.mmap.set_name | ||
|
|
||
| name: str | ||
| / | ||
|
|
||
| [clinic start generated code]*/ | ||
|
|
||
| static PyObject * | ||
| mmap_mmap_set_name_impl(mmap_object *self, const char *name) | ||
| /*[clinic end generated code: output=1edaf4fd51277760 input=6c7dd91cad205f07]*/ | ||
| { | ||
| #if defined(MAP_ANONYMOUS) && defined(__linux__) | ||
| const char *prefix = "cpython:mmap:"; | ||
corona10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (strlen(name) + strlen(prefix) > 79) { | ||
| PyErr_SetString(PyExc_ValueError, "name is too long"); | ||
| return NULL; | ||
| } | ||
| if (self->flags & MAP_ANONYMOUS) { | ||
| char buf[80]; | ||
| sprintf(buf, "%s%s", prefix, name); | ||
| _PyAnnotateMemoryMap(self->data, self->size, buf); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that this function suppresses
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @picnixz Do you want emit warn log? |
||
| Py_RETURN_NONE; | ||
| } | ||
| else { | ||
| /* cannot name non-anonymous mappings */ | ||
| PyErr_SetString(PyExc_ValueError, | ||
| "Cannot set annotation on non-anonymous mappings"); | ||
| return NULL; | ||
| } | ||
| #else | ||
| /* naming not supported on this platform */ | ||
| PyErr_SetString(PyExc_NotImplementedError, | ||
| "Annotation of mmap is not supported on this platform"); | ||
| return NULL; | ||
| #endif | ||
| } | ||
|
|
||
| /*[clinic input] | ||
| mmap.mmap.seekable | ||
|
|
||
|
|
@@ -1397,6 +1435,7 @@ static struct PyMethodDef mmap_object_methods[] = { | |
| MMAP_MMAP_RESIZE_METHODDEF | ||
| MMAP_MMAP_SEEK_METHODDEF | ||
| MMAP_MMAP_SEEKABLE_METHODDEF | ||
| MMAP_MMAP_SET_NAME_METHODDEF | ||
| MMAP_MMAP_SIZE_METHODDEF | ||
| MMAP_MMAP_TELL_METHODDEF | ||
| MMAP_MMAP_WRITE_METHODDEF | ||
|
|
@@ -1952,7 +1991,11 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) | |
| PyErr_SetFromErrno(PyExc_OSError); | ||
| return NULL; | ||
| } | ||
| _PyAnnotateMemoryMap(m_obj->data, map_size, "cpython:mmap"); | ||
| #ifdef MAP_ANONYMOUS | ||
| if (m_obj->flags & MAP_ANONYMOUS) { | ||
| _PyAnnotateMemoryMap(m_obj->data, map_size, "cpython:mmap"); | ||
| } | ||
| #endif | ||
| m_obj->access = (access_mode)access; | ||
| return (PyObject *)m_obj; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.