Proposed mmap module modifications

Jay T Miller jmiller at
Tue Oct 30 22:37:08 CET 2001


I am proposing a set of modifications to the mmap module which serve two


1. The modifications expose read-only and copy-on-write access on the
Win32 platform. Read-write access is already in place.   I need
copy-on-write. I have no real use for read-only.

2. The modifications provide unified access to the "core" features of
memory mapping on both UNIX and Win32.  By this I mean that it would be
possible to create the 3 principle varieties of mmaps on both using the
same platform independent "access" parameter.

I propose adding a new optional keyword parameter, "access", which takes

on 3 possible values:  ACCESS_READ,  ACCESS_WRITE, ACCESS_COPY.

ACCESS_READ implies that the mapped memory may *only* be read.  Any
attempt to write to the mapped memory will generate a signal.  This
signal will be handled in the platform specified manner.

ACCESS_WRITE implies that the mapped memory may be read and written.
Attempts to write to the mapped memory will be passed through to the
underlying file.

ACCESS_COPY implies that the mapped memory may be read and written.
Attempts to write to the mapped memory result in disassociating the
written memory page from the underlying file.  A newly associated page
in memory is modified to record the effect of the write.  The underlying

file is not altered.

The access values map onto UNIX platform specific parameters as follows:

ACCESS_READ:                flags=SHARED,   prot=PROT_READ
ACCESS_WRITE:              flags=SHARED,   prot=PROT_READ | PROT_WRITE
ACCESS_COPY:               flags=PRIVATE,  prot=PROT_READ | PROT_WRITE

I propose making it an error to specify both "access" and "flags" or
"prot".  In the absence of "access",  "prot" and "flags" work like they
always did.

The access values map onto Win32 mmap internal parameters as follows:

ACCESS_READ:                CreateFileMapping(...PAGE_READONLY...),

ACCESS_WRITE:              CreateFileMapping(...PAGE_READWRITE...),

ACCESS_COPY:                CreateFileMapping(...PAGE_WRITECOPY...),


In the absence of "access", the map is effectively ACCESS_WRITE, as it
always was.

The last issue I want to address is the incompatible naming between
existing UNIX and Win32 parameters of mmap, file vs. fileno, and length
vs. size.  Since the Win32 mmap does not currently use keyword
parameters, I propose renaming the Win32 parameters to match the UNIX
parameters and changing the documentation.  Since these can be specified

positionally (as they are now!), this is not really that important, but
I'd be happy to clean them up.

I have already implemented the modifications against 2.2b1.  If they
sound OK, I'll submit a patch.



More information about the Python-list mailing list