Closed Bug 1525803 Opened 9 months ago Closed 8 months ago

Use MAP_SHARED for read-only file mappings on MacOS and Android


(NSPR :: NSPR, defect, P1)



(Not tracked)



(Reporter: jld, Assigned: jld)




(1 file)

Both MacOS and Android have shared memory implementations that need to be mapped with MAP_SHARED even for read-only use: POSIX shared memory on MacOS will return an error if mapped MAP_PRIVATE, and Android's ashmem will map zeroed memory instead of the memory object's contents in that case.

NSPR's PR_CreateFileMap could be used with these forms of shared memory by importing the fd, except that it tries to use MAP_PRIVATE for read-only mappings. There's already an #ifdefed workaround to use MAP_SHARED in that case, for an old version of OSF/1, which could be extended to other OSes. That shouldn't affect regular file mappings, because the difference between MAP_SHARED and MAP_PRIVATE is the result of writes to the mapping, which aren't allowed in the read-only case.

Comment on attachment 9042329 [details] [diff] [review]

Review of attachment 9042329 [details] [diff] [review]:

::: pr/src/md/unix/unix.c
@@ +3586,2 @@
>           */
>          fmap->md.flags = MAP_SHARED;

Considering the POSIX definition of MAP_SHARED vs. MAP_PRIVATE say they only make a difference for modifications to the mapped data by the calling process, and considering PROT_READ is never going to allow modifications, I'm almost tempted to say we could make it MAP_SHARED everywhere.

Anyways, I think it's fine like this.
Attachment #9042329 - Flags: review?(mh+mozilla) → review+

I don't seem to have permission to push to NSPR.

Keywords: checkin-needed
Closed: 8 months ago
Keywords: checkin-needed
Resolution: --- → FIXED
Blocks: 1526010
Target Milestone: --- → 4.21
You need to log in before you can comment on or make changes to this bug.