X Tutup
The Wayback Machine - https://web.archive.org/web/20250609135916/https://github.com/python/cpython/issues/114233
Skip to content

Expose mprotect in mmap #114233

Open
Open
@ronaldoussoren

Description

@ronaldoussoren

In #113868 I noted that we currently don't expose mprotect functionality in mmap and that this might be useful to have for use cases like generating native code in Python. @brandtbucher confirmed that this would be useful to have

       > * There is no way to change the memory protection (`PROT_READ` etc.) after creating the mapping, exposing such functionality could be useful for using `mmap` to write executable code in Python.

Sorry I'm late, but +1 for exposing mprotect. I was prototyping JITs in pure-Python a while back, and it was unfortunate to have to hack around the edges with ctypes just to do something like this (which "feels like" it should be part of the mmap module).

Originally posted by @brandtbucher in #113868 (comment)

Adding this should be fairly easy, given that the mmap code assumes that the entire buffer has the same protections. One thing to consider is the impact on sharing memory through the buffer interface.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup