When using mremap() with MREMAP_FIXED and bad parameters, mremap() returns EINVAL, which is expected; but it also unmaps existing regions at 'new_address', which surprised me. I had expected that on EINVAL, mappings at 'new_address' would remain unmodified. The current behavior is reasonable, but it was surprising to me, so it might be surprising to others. The man page DESCRIPTION currently says: "Any previous mapping at the address range specified by new_address and new_size is unmapped." It would be clearer to me if it also said something like: "Previous mappings may be unmapped even if mremap() returns an error." And/or if ERRORS said something about this behavior. A sample patch for man2/mremap.2 is attached.
Attachment:
mremap.2.patch
Description: mremap.2.patch