Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
bpo-26836: Add os.memfd_create()#13567
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
00ce42be25baa5457b9cbad92177c2a0d1500b221c997eba8ec58b01346e5d07a2c4ccFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add :func:`os.memfd_create`. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -389,6 +389,19 @@ extern char *ctermid_r(char *); | ||
| #define HAVE_STRUCT_STAT_ST_FSTYPE 1 | ||
| #endif | ||
| /* memfd_create is either defined in sys/mman.h or sys/memfd.h | ||
| * linux/memfd.h defines additional flags | ||
| */ | ||
| #ifdef HAVE_SYS_MMAN_H | ||
| #include <sys/mman.h> | ||
| #endif | ||
| #ifdef HAVE_SYS_MEMFD_H | ||
| #include <sys/memfd.h> | ||
| #endif | ||
| #ifdef HAVE_LINUX_MEMFD_H | ||
| #include <linux/memfd.h> | ||
| #endif | ||
| #ifdef _Py_MEMORY_SANITIZER | ||
| # include <sanitizer/msan_interface.h> | ||
| #endif | ||
| @@ -11897,6 +11910,31 @@ os_urandom_impl(PyObject *module, Py_ssize_t size) | ||
| return bytes; | ||
| } | ||
| #ifdef HAVE_MEMFD_CREATE | ||
| /*[clinic input] | ||
| os.memfd_create | ||
| name: FSConverter | ||
| flags: unsigned_int(bitwise=True, c_default="MFD_CLOEXEC") = MFD_CLOEXEC | ||
| [clinic start generated code]*/ | ||
| static PyObject * | ||
| os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags) | ||
| /*[clinic end generated code: output=6681ede983bdb9a6 input=a42cfc199bcd56e9]*/ | ||
| { | ||
| int fd; | ||
| const char *bytes = PyBytes_AS_STRING(name); | ||
| Py_BEGIN_ALLOW_THREADS | ||
| fd = memfd_create(bytes, flags); | ||
| Py_END_ALLOW_THREADS | ||
| if (fd == -1) { | ||
| return PyErr_SetFromErrno(PyExc_OSError); | ||
| } | ||
| return PyLong_FromLong(fd); | ||
| } | ||
| #endif | ||
| /* Terminal size querying */ | ||
| static PyTypeObject* TerminalSizeType; | ||
| @@ -13554,6 +13592,7 @@ static PyMethodDef posix_methods[] = { | ||
| OS_SCANDIR_METHODDEF | ||
| OS_FSPATH_METHODDEF | ||
| OS_GETRANDOM_METHODDEF | ||
| OS_MEMFD_CREATE_METHODDEF | ||
| #ifdef MS_WINDOWS | ||
| OS__ADD_DLL_DIRECTORY_METHODDEF | ||
| OS__REMOVE_DLL_DIRECTORY_METHODDEF | ||
| @@ -14003,6 +14042,27 @@ all_ins(PyObject *m) | ||
| if (PyModule_AddIntMacro(m, GRND_RANDOM)) return -1; | ||
| if (PyModule_AddIntMacro(m, GRND_NONBLOCK)) return -1; | ||
| #endif | ||
| #ifdef HAVE_MEMFD_CREATE | ||
| if (PyModule_AddIntMacro(m, MFD_CLOEXEC)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_ALLOW_SEALING)) return -1; | ||
| #ifdef MFD_HUGETLB | ||
| if (PyModule_AddIntMacro(m, MFD_HUGETLB)) return -1; | ||
ZackerySpytz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_SHIFT)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_MASK)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_64KB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_512KB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_1MB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_2MB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_8MB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_16MB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_32MB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_256MB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_512MB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_1GB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_2GB)) return -1; | ||
| if (PyModule_AddIntMacro(m, MFD_HUGE_16GB)) return -1; | ||
| #endif | ||
| #endif | ||
| #if defined(__APPLE__) | ||
| if (PyModule_AddIntConstant(m, "_COPYFILE_DATA", COPYFILE_DATA)) return -1; | ||
| @@ -14119,6 +14179,10 @@ static const char * const have_functions[] = { | ||
| "HAVE_LUTIMES", | ||
| #endif | ||
| #ifdef HAVE_MEMFD_CREATE | ||
| "HAVE_MEMFD_CREATE", | ||
| #endif | ||
| #ifdef HAVE_MKDIRAT | ||
| "HAVE_MKDIRAT", | ||
| #endif | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.