mmap

MMAP(2)                    Linux Programmer's Manual                   MMAP(2)



åå
       mmap, munmap - ãã¡ã¤ã«/ããã¤ã¹ãã¡ã¢ãªã«ããã/ã¢ã³ããããã

æ¸å¼
       #include <unistd.h>
       #include <sys/mman.h>

       caddr_t mmap(void *start, size_t length, int prot , int flags, int fd,
       off_t offset);

       int munmap(void *start, size_t length);

説æ
       mmap é¢æ°ã¯ fd ã§æå®ããããã¡ã¤ã«(ãããã¯ãã®ä»ã®ãªãã¸ã§ã¯ã)ã®ãªãã»ãã offset
       ãã length ãã¤ãã®é·ããã¡ã¢ãªã«ããããã(ã¡ã¢ãªã«å¼µãä»ãã)ããã®ã¨ãããªãã¹ã
       ã¡ã¢ãªä¸ã® start ã¢ãã¬ã¹ããã¯ãããããã«ãããããããã®ã¢ãã¬ã¹ã¯å®éã¯é¢æ°ã«å¯¾ãã¦
       ã®ãã³ãã§ããç¡ããé常㯠0 ãæå®ãããå®éã«ãªãã¸ã§ã¯ã(ãã¡ã¤ã«ã
       ã®ä»)ãããããããã¢ãã¬ã¹ã¯ mmap ãè¿ãã

       å¼æ° prot ã«ã¯ã¡ã¢ãªä¿è·ãã©ã®ããã«è¡ãªãã(ãã®ã¡ã¢ãªãã©ã®ããã«ä½¿ãããã)ã
       æå®ãããããããã¼ã¿ã¨ãã¦ä»¥ä¸ã®é ç®ãæã¤ã

       PROT_EXEC
              ãã¼ã¸ã¯å®è¡å¯è½ã§ããã

       PROT_READ
              ãã¼ã¸ã¯èªã¿è¾¼ã¿å¯è½ã§ããã

       PROT_WRITE
              ãã¼ã¸ã«æ¸ãè¾¼ã¿å¯è½ã§ããã

       PROT_NONE
              ãã¼ã¸ã¯ã¢ã¯ã»ã¹ããã¦ããªãã

       å¼æ° flags ã«ã¯ããããããããªãã¸ã§ã¯ãã®ã¿ã¤ãããããæã®ãªãã·ã§ã³ããããã
       ãããã¼ã¸ã³ãã¼ã¸ã®å¤æ´ã¯ãã®ããã»ã¹åºæ(ãã®ããã»ã¹ã ããå¤æ´å¯è½)
       ã§ããã®ãããã¨ãä»(ã®ããã»ã¹)ãããåç§ããã¦ããã®ã(å±æããã¦ã
       ãã®ã)ããæå®ãããããããã¼ã¿ã¨ãã¦ä»¥ä¸ã®é ç®ãæã¤ã

       MAP_FIXED
              ãããã³ã°ãæå®ãããã¢ãã¬ã¹ä»¥å¤ã®ã¢ãã¬ã¹ã«è¡ãªããªããããæå®ãã
              ãã¢ãã¬ã¹ã使ç¨ã§ããªãã®ã§ããã° mmap ã¯å¤±æããããã MAP_FIXED
              ãæå®ããã¦ããã®ãªã start
              ã¯ãã¼ã¸ãµã¤ãºã®åæ°ã§ãªãã¦ã¯ãããªãããã®ãªãã·ã§ã³ã¯ä½¿ç¨ããªãæ¹ã è¯ãã

       MAP_SHARED
              ãã®ãªãã¸ã§ã¯ããããã®ãªãã¸ã§ã¯ãããããããå¨ã¦ã®ããã»ã¹ããå±æ ããã

       MAP_PRIVATE
              åºæã® copy-on-write (æ¸ãè¾¼ã¿æã³ãã¼) ããããçæããã

       以ä¸3ã¤ã®ãã©ã°ã¯ POSIX.1b (以å㯠POSIX.4) ã«ã¦è¦å®ããã¦ãããLinux
       ã«ã¯ãã®ä»ã« MAP_DENYWRITEãMAP_EXECUTABLEãMAP_ANON(YMOUS) ãããã

       ã·ã¹ãã ã³ã¼ã« munmap
       ã¯æå®ãããã¢ãã¬ã¹ç¯å²ã®ããããæ¶å»ãããã®å¾ã®ãã®ç¯å²åã¸ã®åç§ã
       ç¡å¹ãªã¡ã¢ãªã¸ã®åç§ã¨ããã


è¿ãå¤
       mmap ã¯æåããã¨ããããããå ´æã®ãã¤ã³ã¿ãè¿ãã 失æãã㨠-1 ãè¿ãã errno
       ã«ã¨ã©ã¼ã«ãã£ãå¤ãã»ãããããã

       munmap ã¯æåãã㨠0 ãè¿ãã失æãã㨠-1 ãè¿ãã errno ãã»ããããã(ãããã EINVAL
       ã«ã»ãããããã ãã)ã

ã¨ã©ã¼
       EBADF  fd ãæå¹ãªãã¡ã¤ã«è¨è¿°åã§ã¯ãªã (MAP_ANONYMOUS ã¯ã»ãããããªã)ã

       EACCES MAP_PRIVATE ãè¦æ±ããã¦ããã fd ãèªã¿åºãã§éããã¨ãã§ããªããã¾ãã¯
              MAP_SHARED ãè¦æ±ãã PROT_WRITE ãã»ããããã¦ããã fd
              ãæ¸ãè¾¼ã¿ã§éããã¨ãã§ããªãã

       EINVAL start ã length ã offset ãåãä»ããããªãã (ä¾ãã°å¤§ãããããPAGESIZE
              å¢çã«è¨å®ããã¦ããªã)

       ETXTBUSY
              MAP_DENYWRITE ãã»ããããã¦ããã fd
              ã§æå®ããã¦ãããªãã¸ã§ã¯ãã¯æ¸ãè¾¼ã¿ç¨ã«éããã¦ããã

       EAGAIN ãã¡ã¤ã«ãããã¯ããã¦ãããã¾ãã¯ããã¯ããã¦ããã¡ã¢ãªãå¤ãããã

       ENOMEM ã¡ã¢ãªã«ç©ºãããªãã

æºæ
       SVr4, POSIX.1b (以å㯠POSIX.4), 4.4BSDãSVr4 ã«ã¯ä»ã« ENXIO 㨠ENODEV
       ã®ã¨ã©ã¼ã³ã¼ãã«ã¤ãã¦ã®è¨è¿°ãããã

é¢é£é ç®
       getpagesize(2), msync(2), shm_open(2), B.O. Gallmeister, POSIX.4,
       O'Reilly, pp. 128-129 and 389-391.



Linux 1.3.86                     12 April 1996                         MMAP(2)