linux/Documentation/nommu-mmap.txt
<<
>>
Prefs
   1                         =============================
   2                         NO-MMU MEMORY MAPPING SUPPORT
   3                         =============================
   4
   5The kernel has limited support for memory mapping under no-MMU conditions, such
   6as are used in uClinux environments. From the userspace point of view, memory
   7mapping is made use of in conjunction with the mmap() system call, the shmat()
   8call and the execve() system call. From the kernel's point of view, execve()
   9mapping is actually performed by the binfmt drivers, which call back into the
  10mmap() routines to do the actual work.
  11
  12Memory mapping behaviour also involves the way fork(), vfork(), clone() and
  13ptrace() work. Under uClinux there is no fork(), and clone() must be supplied
  14the CLONE_VM flag.
  15
  16The behaviour is similar between the MMU and no-MMU cases, but not identical;
  17and it's also much more restricted in the latter case:
  18
  19 (*) Anonymous mapping, MAP_PRIVATE
  20
  21        In the MMU case: VM regions backed by arbitrary pages; copy-on-write
  22        across fork.
  23
  24        In the no-MMU case: VM regions backed by arbitrary contiguous runs of
  25        pages.
  26
  27 (*) Anonymous mapping, MAP_SHARED
  28
  29        These behave very much like private mappings, except that they're
  30        shared across fork() or clone() without CLONE_VM in the MMU case. Since
  31        the no-MMU case doesn't support these, behaviour is identical to
  32        MAP_PRIVATE there.
  33
  34 (*) File, MAP_PRIVATE, PROT_READ / PROT_EXEC, !PROT_WRITE
  35
  36        In the MMU case: VM regions backed by pages read from file; changes to
  37        the underlying file are reflected in the mapping; copied across fork.
  38
  39        In the no-MMU case:
  40
  41         - If one exists, the kernel will re-use an existing mapping to the
  42           same segment of the same file if that has compatible permissions,
  43           even if this was created by another process.
  44
  45         - If possible, the file mapping will be directly on the backing device
  46           if the backing device has the BDI_CAP_MAP_DIRECT capability and
  47           appropriate mapping protection capabilities. Ramfs, romfs, cramfs
  48           and mtd might all permit this.
  49
  50         - If the backing device device can't or won't permit direct sharing,
  51           but does have the BDI_CAP_MAP_COPY capability, then a copy of the
  52           appropriate bit of the file will be read into a contiguous bit of
  53           memory and any extraneous space beyond the EOF will be cleared
  54
  55         - Writes to the file do not affect the mapping; writes to the mapping
  56           are visible in other processes (no MMU protection), but should not
  57           happen.
  58
  59 (*) File, MAP_PRIVATE, PROT_READ / PROT_EXEC, PROT_WRITE
  60
  61        In the MMU case: like the non-PROT_WRITE case, except that the pages in
  62        question get copied before the write actually happens. From that point
  63        on writes to the file underneath that page no longer get reflected into
  64        the mapping's backing pages. The page is then backed by swap instead.
  65
  66        In the no-MMU case: works much like the non-PROT_WRITE case, except
  67        that a copy is always taken and never shared.
  68
  69 (*) Regular file / blockdev, MAP_SHARED, PROT_READ / PROT_EXEC / PROT_WRITE
  70
  71        In the MMU case: VM regions backed by pages read from file; changes to
  72        pages written back to file; writes to file reflected into pages backing
  28

  v2.6.16.33  71     Regular 7ile / blockdev, MAP_SHA7ED, P7OT_READ / PROT_EXEC / PROT_WRITE
 Ay62.6t ddinumenr" name="L70"L50" class="line" name="L50">  50    8   In th8 MMU case: VM regions b8cked 8y pages read from file; changes to
 T  64mhrevide if ne" line"- pages 4re"t .txt#    red.
  28


  v2.6.16.33
  71    8mentatio8/nommu-mmap.txt#L70" id8"L70"8#39;t or won't permit direct sharing,
 Ay62.6t ddinumenr" name="L70"L50" class="line" name="L50">  50    9cumentat9on/nommu-mmap.txt#L72" 9d="L79ay fork(), vfork(), clone() and
 Ay62.6tmline"  pages r" name="L70restric read into a contiguous bit of

mentationa>  58" crevide/antation/nommu-ma   class=e no-MMad into a contiguous bit of
  55    9xt#L42" 9d="nation/nommu-mmap.tx9#L73"9id="L>   12oma thits"L54">  5s/antation/nommarriyiupo fntL50" class="line" name="L50">  50    96.28"
ef9"Documentation/nommu-mm9p.txt9Documentation/nommu-mmap.txt#L28" id="L28" cl9mentatio9n/nommu-mmap.txt#L8" id9="L689Documentat"line"  pages tesra>
  71    9cumentat9ion/nommu-mmap.txt#L9" 9ED, P9OT_READ / PROT_EXEC / PROT_WRITE
 Ay62.6t ddinumenr" name="L70"L50" class="line" name="L50">  50    10 class="liine" name="L11">  11
cked>
cDocumentation/nommu-mmap.txt#L20" id="L20" cl0y mapping0 behaviour also involves01ked>
" class="line" name= name="L28"> T  6tesrac19" ">  51  6e="L38">  3">  51
-mmap.txt#L6"crevides"L54">  .6tquasi-L54">  href=c>  150
  51st I      /o do n52">  28mentation/nommu-mmap.txt#L20" id="L20" cl0ehaviour 0is similar between the M05ked>
5mmap.txt#L6"crevide/a>


  v2.6.16.33
Documentation/nommu-mmap.txt#L28" id="L28" cl10ap.txt#L108" id="L18" class="line"07ked>
7 pages read from file; changes to
   5The kernel10ass="line0" name="L20">  20

tatioFURTHER NOTES ON   ====== hr12" class="line" name="L12">  12Memory class="lline" name="L11">  11>
   5The kernel1ry mapping  behaviour also involves 1ked>way fork(), vfork(), clone() and
     enr"put ty buffer href=i>  28mentation/nommu-mmap.txt#L20" id="L20" clcumentatioon/nommu-mmap.txt#L14" idd="L111-mmap.txt#clas-alignhre  T ="Doshe camentXIP   enmmu- place,line" namdata   en 28  155
  34 (*)1behaviour  is similar between the MMMU a1d no-MMU cases, but not identical;
  68
e="L46">>     ize>       r"" nam on/nommiona
e=wer     wo/a>   wientsomDocumentation/nommu-mmap.txt#L11" id="L11""Anonymouss mapping, MAP_PRIVATE
  20
  5lentatfon/ back"mentation/nommu-mmap.txt#L20" id="L20" cl    In th1e MMU case: VM regions b1acked120ation/nomp.="D   a of   are on  r gu-mmap.txL34" class="line" name="L34">  34 (*)1umentatio1n/nommu-mmap.txt#L22" id1="L2212ay fork(), vfork(), clone() and
  15on/nommu-mmap.txt#L25" i1d="L21" class="liLtmammclass=(do n2.22 .6tl  5r)L34" class="line" name="L34">  34 (*)1uehaviour >
  28
  68
>       ar   pages wrivirL12" class,e execve()s="line"honly ioe="nmmap-mmap.txt#L15" id="L15" class="line" name="    These1 behave very much like p1rivat12 href="Doc64"" id="Lmphysntaticlass=ee file writefile unevice ef=specificiclasmap.txt#L15" id="L15" class="line" name=" ass="lineon/nommu-mmap.txt#L30" i1d="L31" class="li(3">.6t#oe actu,he write acar     are dolynmmap-mL64">  6globatizeroiclasmap.txt#L15" id="L15" class="line" name="Documenta1tion/nommu-mmap.txt#L31"1 id="131" class="o fil actuaack "Dc>  33
  34 (*)13umentationn/nommu-mmap.txt#L14" id= bac1EC, !PROT_WRITE
 aually happens. From that point
 a" liset62.6t#39;umenr acroL34" class="line" name="L34">  34 (*)13   These1e no-MMU case:
  40
 have thr"" ir-mL64"bocure" id="Lm- ersp a bamaared.
  6       heef=im on/nom have thba>    " id=e if ne" line" >     e reflected into pages backing
 put ine" te  No 5n6eef=CONFIG_= hr_ALLOWeUNINITIALIZED entationenaed mmap.txt#L15" id="L15" class="line" name="Lumentatio id="L44" class="line" n1ame="144">  44  69 (*)14L15">  15<
     L69" class="line" name="L69">  69 (*)14umentati1n/nommu-mmap.txt#L48" id1="L48147 pages read from file; changes to
  491
148clasentatinlisa>   a the wrihared aocume54n/nommu-mmap.tx  vice ha 9m="directly on the backing device
  5through /    /  34 (*)1href="Doc1umentation/nommu-mmap.tx1t#L5115cDocumentation/nommu-mmap.txt#L20" id="L20" clumentatio1n/nommu-mmap.txt#L52" id1="L521 class=ntatinlisa>   a the wrmmap.tx  "L7"se-mmapn       DoshL57">  5throughmentation/nommu-mmap.txt#L20" id="L20" clu" name="1n/nommu-mmap.txt#L53" id1="L531 class="lin/    /<pidt ty/  34 (*)1humentatioommu-mmap.txt#L54" id="L154" c15C, !PROT_WRITE
  35Snomm">  3 hr_FIXED .6ta r"" name ifanparticname=mmap.tx iddr   Dif tROT_WRITE
  34 (*)1hAnonymou1on/nommu-mmap.txt#L57" i1d="L515Documentation/nommu-mmap.txt#L28" id="L28" cl1"L58">  518
  28<  1a hne" name="L51">  51  55    1Documenta1tion/nommu-mmap.txt#L62"1 id="162" class=" exectesrac19" ">  51<"L70respip0resfifosmap.tsoaget"L50" class="line" name="L50">  50    1ocumentat1ion/nommu-mmap.txt#L63" 1id="L13" cla50" class="line" name="L50">  50    1oumentatiotion/nommu-mmap.txt#L64"1 id="16C, !PROT_WRITE
   5The kernel1    In th1e no-MMU case: works muc1h lik1 the nINTERPROCESS f="Doc=======lass="line" name="L5">   5The kernel1 umentationn/nommu-mmap.txt#L17" id=="L51class=mmu-mmap.txt#L5" id="L5" class="line" name="L5">   5The kernel1 L58">  51d="L68" class="line" nam1e="L6167 pages read from file; changes to
  54  ="Dsa>
r5through se of 12" metes ism,ap.txt#L19" through "L70ron/nommues read from file; changes to
  50    1ocumentat1ion/nommu-mmap.txt#L72" 1id="L17ay fork(), vfork(), clone() and
  50    1lue="v2.61.16.28"
ef="Documentatio1n/nom1u-mmap="L5" class="line" name="L5">   5The kernel1appingĿs backing pages. The t1xt#Lp1txtes FUTEXESlass="line" name="L5">   5The kernel1a   In th1id="nation/nommu-mmap.tx1t#L731 id="L="L5" class="line" name="L5">   5The kernel1aumentatio="Documentation/nommu-mm1ap.tx17Documentation/nommu-mmap.txt#L28" id="L28" cl17ap.txt#L188" id="L18" class="line" ="L617DocumFutex acar  sa>
 d154 sa>
  64utex  9mappi>a e"Doriside/) rentation/nommu-mmap.txt#L28" id="L28" cl17mentatio17/nommu-mmap.txt#L70" id17"L7017 class="lineame="L8mmapn       Dor "L47"> mmap.tx men actua7"> dddr   Da e"D52">  28mentation/nommu-mmap.txt#L20" id="L20" cl8   In th18 MMU case: VM regions b18cked18y pagas arutex ac(ersp a bammI/O tesra>
 mmap.tx)L34" class="line" name="L34">  34 (*)18cumentat18on/nommu-mmap.txt#L72" 18d="L18ay fork(), vfork(), clone() and
  50    18ue="v2.61816.28"
ef="Documentatio18/nom183ass=mmu-mmap.txt#50" class="line" name="L50">  50    18ppingľs backing pages. The t18t#Lp18L65"   ======RE hr12" class="line" name="L12">  12Memor8xt#L42" 18d="nation/nommu-mmap.tx18#L73185ass=mmu-mmap.txt#50" class="line" name="L50">  50    18umentatio8"Documentation/nommu-mm18p.tx18Documentation/nommu-mmap.txt#L28" id="L28" cl18mentatio18n/nommu-mmap.txt#L8" id18="L6187 pagTne" resystemf and theisnparti the /a>
     ize>   aentation/nommu-mmap.txt#L28" id="L28" cl18Anonymous  mapping, MAP_PRIVATE
 new  izeentation/nommu-mmap.txt#L28" id="L28" cl18mentatio18/nommu-mmap.txt#L70" id18"L7018#39;toL47"> mmap.tx e=  eds>     ize>       slab objare currmma devccu63p() rentation/nommu-mmap.txt#L28" id="L28" cl19   In th19 MMU case: VM regions b19cked190atiomline" hon actua7">  name="nr"fo theor "L4a smp.tL69"lab objare c/nommionnameL34" class="line" name="L34">  34 (*)19cumentat19on/nommu-mmap.txt#L72" 19d="L19ay fork(), vfork(), clone() and
reL65">  noites to>nd the EOF will be cleared
  28  34 (*)19ppingĿs backing pages. The t19t#Lp19l be directly on the backing device
rpability, then a copy of the
  69 (*)19mentatio19n/nommu-mmap.txt#L8" id19="L6197 pages read from file; changes to
  es read from file; changes to
  20
  11part"ho   file i e e"t  ntaes read from file; changes to
  27 (*) 0entation20nommu-mmap.txt#L13" id=202ked20" cla50" class="line" name="L50">  50    20umentati20n/nommu-mmap.txt#L14" i203ked2
-mmap[*] N28

  v2.6.16.33  120
   5The kernel20ap.txt#L208" id="L18" class="line207ked2
7 pagPROVID======"DoABLE C="DACTER DEVICE==========
   5The kernel20umentatio0" name="L20">  20
<209ked20#39;t or won't permit direct sharing,
  11
  5tesrac19" ">  51
perap.txLtTne" mumentation/nomsame ca the ="directly on the backing device
  name="ne cament8
  125

a3"
	  >
  v2.6.16.33  51  68tonindic  5n6h by anot hru   51st s="l/efa/0"um"directly on the backing device
  5ine"nomma>  ,i 28  ,iine"only sns ba>  directly on the backing device
  20
<2a hre21tatioacking de(       butbe>  63  34 (*)2    In thee MMU case: VM regions baacked2by arbitrary pages; copy-on-write
perap.txp.txt#L55" wohr"xtra to the in ugur  5n6h itrary pages; copy-on-write
  223
  name="n64"boc  63  34 (*)2 L15">  12on/nommu-mmap.txt#L25" idd="L222l be directly on the backing device
  26>

directly on the backing device
directly on the backing device
  28
  68e no-MMU 28ifyine" nam/o do L34" class="line" name="L34">  34 (*)2 Anonymou2 behave very much like prrivat2 mappings, except that they're
 y anot hruhref=2.6t#39;"L70-t tyf_op-t tyget_unmmap-m_s baperap.txfile reflected into pages backing
perap.txfjntat/a>        e reflected into pages backing
  33
  51-specifici/o do L"L14"> ersp cirint iannt/a>   e reflected into pages backing
   wienL24" class="line" name="L24">  24      ap.txt#L2on/nommu-mmap.txt#L38" i2d="L3237 pages read from file; changes to
  41    2ne" name=2"L40">  40
  51<  enpr  -mm"an5cffer-mm"aap-aranntaetranyon e reflected into pages backing
certa/a>mod"nderlcregr  me i or
er28"mmod", yoummu-mmase5n6h itrary pages; copy-on-write
  44
< iatommuref="Documentation/nomm,a6" id="        dataL24" class="line" name="L24">  24     4L15">  12<
   12ommu-ersp a"L28", car  entationmmu-mmlnam f in conjuse5naions ba .6tadirectly on the backing device
  51. R membo ne/peci the:ashared adrivuma>  entation/nommu-mmap.txt#L28" id="L28" cl24   These2s="line" name="L49">  492
2a href="Documes="lineame=ene s the bmmap-mLacking devff" nam/>  51 envirosomDentation/nommu-mmap.txt#L28" id="L28" cl24e" name=2 the backing device devi2ce ca24tation/nommu-cirint iannt/!entation/nommu-mmap.txt#L28" id="L28" cl2href="Doc2umentation/nommu-mmap.tx2t#L5125cDocumentation/nommu-mmap.txt#L20" id="L20" c2umentatio2n/nommu-mmap.txt#L52" id2="L5225ay fork(), vfork(), clone() and
   5The kernel2humentati2ommu-mmap.txt#L54" id="L254" c25C, !PPROVID======"DoABLE ======-BACKED FILE==========
   5The kernel2hocumenta2ion/nommu-mmap.txt#L56" 2id="L25 no-MMU cases, but not identical;
  17
  51st s="lma/a>5cffer-mcntationaic read into a contiguous bit of
mhrevide if ne" in  51 if thhreba> ytp.toc  5na
tation/nommcoll="Docuad into a contiguous bit of
  27 (*) Aref="Doc2e MMU case: like the non2-PROT2WRITE case, except that the pages in
 kines endeLmhref="Dirunc  5t>perap.txf="llihr"xtrersp a"a>   amaared.
 ize,en if thi  evens 9mpty,tionmmu-mm5s/anr"" nam 64"na>   red.
 ki" ir-mL64"era>as aPOSIXions bared.
  27 (*) Aocumenta2e no-MMU case: works muc2h lik2 the non-PROT_WRITE case, except
  51scar  indic  5Lmap() romname="L65">  65
<">  51  52d="L68" class="line" nam2e="L6267 pag ne" line"_ pages "d="fsefL27" class="line" name="L27">  27 (*) A49" clas2file / blockdev, MAP_SHA2RED, 2ROT_READ / PROT_EXEC / PROT_WRITE
   5The kernel2ocumentat2ion/nommu-mmap.txt#L72" 2id="L27ay foPROVID======"DoABLE BLOCK DEVICE==========
  51<"L70rens 9tactlp() ro     ay62.6ROT_WRITE
  51st IL47">re=i> have thabacklm/>  51 envir   th the fiine"5o do ROT_WRITE

  27 (*) 7ap.txt#L288" id="L18" class="line2 ="L6277 pages read from file; changes to
  50    28ue="v2.62816.28"
ef="Documentatio28/nom283ass=NOme="m0  50    28ppingňs backing pages. The t28t#Lp28L65"  e fiy a0  50    28ocumenta28d="nation/nommu-mmap.tx28#L73285ass= r gu-mmap.tx,iine"asrersp,ens leftntatfon/ a6">re s="l/efa/0"ubehivs3
rhe bacsaed mas crled lyheor bumphruupuetranhig     te e reflected into pages backing
  50    29   In th29 MMU case: VM regions b29cked29RITE case, except that the pages in
 viace ha 9  50    29ocumenta29ion/nommu-mmap.txt#L73"29id="292 cla


s="loriginklmLXR softwar p() ro0" class=http://s3LXR nes unity cla,ie =".no">lxr@l.no cla.
lxr.l.no /a>dhe fos 5Lmap(0" class=http://www. bapill-lRbapilliLttat3/0".tx ine">perap.txs" in 51L17"mcnt1995.