diff options
author | Sergey Bugaev <bugaevc@gmail.com> | 2021-08-11 18:31:51 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-08-11 18:39:51 +0200 |
commit | 08fc6df294ab7e10e14492094a99b7861ad7d77e (patch) | |
tree | 3f5b65d6e735c89336a2b787cdc97d1e81b222b3 /sysdeps/mach | |
parent | 43d06ed218fc8be58987bdfd00e21e5720f0b862 (diff) | |
download | glibc-08fc6df294ab7e10e14492094a99b7861ad7d77e.tar glibc-08fc6df294ab7e10e14492094a99b7861ad7d77e.tar.gz glibc-08fc6df294ab7e10e14492094a99b7861ad7d77e.tar.bz2 glibc-08fc6df294ab7e10e14492094a99b7861ad7d77e.zip |
hurd mmap: Factorize MAP_SHARED flag check
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'sysdeps/mach')
-rw-r--r-- | sysdeps/mach/hurd/mmap.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c index ea0e61d571..9fa265f752 100644 --- a/sysdeps/mach/hurd/mmap.c +++ b/sysdeps/mach/hurd/mmap.c @@ -37,6 +37,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) vm_prot_t vmprot; memory_object_t memobj; vm_address_t mapaddr; + boolean_t copy; mapaddr = (vm_address_t) addr; @@ -52,6 +53,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) if (prot & PROT_EXEC) vmprot |= VM_PROT_EXECUTE; + copy = ! (flags & MAP_SHARED); + switch (flags & MAP_TYPE) { default: @@ -98,7 +101,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) __mach_port_deallocate (__mach_task_self (), memobj); } else if (wobj == MACH_PORT_NULL /* Not writable by mapping. */ - && !(flags & MAP_SHARED)) + && copy) /* The file can only be mapped for reading. Since we are making a private mapping, we will never try to write the object anyway, so we don't care. */ @@ -123,9 +126,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) &mapaddr, (vm_size_t) len, (vm_address_t) 0, mapaddr == 0, memobj, (vm_offset_t) offset, - ! (flags & MAP_SHARED), - vmprot, VM_PROT_ALL, - (flags & MAP_SHARED) ? VM_INHERIT_SHARE : VM_INHERIT_COPY); + copy, vmprot, VM_PROT_ALL, + copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE); if (flags & MAP_FIXED) { @@ -138,10 +140,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) err = __vm_map (__mach_task_self (), &mapaddr, (vm_size_t) len, (vm_address_t) 0, 0, memobj, (vm_offset_t) offset, - ! (flags & MAP_SHARED), - vmprot, VM_PROT_ALL, - (flags & MAP_SHARED) ? VM_INHERIT_SHARE - : VM_INHERIT_COPY); + copy, vmprot, VM_PROT_ALL, + copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE); } } else @@ -150,10 +150,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) err = __vm_map (__mach_task_self (), &mapaddr, (vm_size_t) len, (vm_address_t) 0, 1, memobj, (vm_offset_t) offset, - ! (flags & MAP_SHARED), - vmprot, VM_PROT_ALL, - (flags & MAP_SHARED) ? VM_INHERIT_SHARE - : VM_INHERIT_COPY); + copy, vmprot, VM_PROT_ALL, + copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE); } if (memobj != MACH_PORT_NULL) |