Write-only mapping a O_WRONLY opened file supposed to work?

后端 未结 2 1038
孤独总比滥情好
孤独总比滥情好 2020-12-19 04:06

Is mmap() supposed to be able to create a write-only mapping of a O_WRONLY opened file?

I am asking because following fails on a Linux 4.0.

2条回答
  •  一个人的身影
    2020-12-19 04:40

    I don't think the x86 hardware supports write-only pages, so write access implies read. But it seems to be a more general requirement than just x86 - mm/mmap.c contains this code in do_mmap_pgoff():

        case MAP_SHARED:
            if ((prot&PROT_WRITE) && !(file->f_mode&FMODE_WRITE))
                return -EACCES;
            ....
            /* fall through */
        case MAP_PRIVATE:
            if (!(file->f_mode & FMODE_READ))
                return -EACCES;
    

    I think that explains what you're seeing.

提交回复
热议问题