Open
Description
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 withctypesjust to do something like this (which "feels like" it should be part of themmapmodule).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.

