mm.h 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. mm.h
  5. Abstract:
  6. This header contains definitions for virtual memory management.
  7. Author:
  8. Evan Green 27-Jul-2012
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. //
  17. // Define the catch-all allocation tag used the the memory manager: Mm!!.
  18. //
  19. #define MM_ALLOCATION_TAG 0x21216D4D
  20. //
  21. // Define the allocation tag used for I/O buffers: MmIo
  22. //
  23. #define MM_IO_ALLOCATION_TAG 0x6F496D4D
  24. //
  25. // Define the allocation tag used for MM address space allocations: MmAd
  26. //
  27. #define MM_ADDRESS_SPACE_ALLOCATION_TAG 0x64416D4D
  28. //
  29. // Define the allocation tag used by image sections.
  30. //
  31. #define MM_IMAGE_SECTION_ALLOCATION_TAG 0x6D496D4D
  32. //
  33. // Define the pool magic values for non-paged pool (NonP) and paged-pool (PagP).
  34. //
  35. #define NON_PAGED_POOL_MAGIC 0x506E6F4E
  36. #define PAGED_POOL_MAGIC 0x50676150
  37. #define KERNEL_VA_START (PVOID)0x80000000
  38. #define KERNEL_VA_END 0x100000000ULL
  39. #define INVALID_PHYSICAL_ADDRESS 0
  40. //
  41. // Define the minimum size to reserve for user mode stack expansion. Calls to
  42. // map memory will not use this region.
  43. //
  44. #define USER_STACK_HEADROOM (128 * _1MB)
  45. #define USER_STACK_MAX (((UINTN)MAX_USER_ADDRESS + 1) * 3 / 4)
  46. #define MM_STATISTICS_VERSION 1
  47. #define MM_STATISTICS_MAX_VERSION 0x10000000
  48. //
  49. // Define flags for memory accounting systems.
  50. //
  51. #define MEMORY_ACCOUNTING_FLAG_INITIALIZED 0x00000001
  52. #define MEMORY_ACCOUNTING_FLAG_SYSTEM 0x00000002
  53. #define MEMORY_ACCOUNTING_FLAG_USER 0x00000004
  54. #define MEMORY_ACCOUNTING_FLAG_NO_MAP 0x00000008
  55. #define MEMORY_ACCOUNTING_FLAG_MASK 0x0000000E
  56. //
  57. // Define flags used for MDLs.
  58. //
  59. #define DESCRIPTOR_FLAG_USED 0x00000001
  60. #define DESCRIPTOR_FLAG_FREEABLE 0x00000002
  61. //
  62. // Define the number of bins MDLs keep for free descriptors.
  63. //
  64. #define MDL_BIN_COUNT 8
  65. //
  66. // Define the minimum amount of free system descriptors that need to be
  67. // available before a new system descriptor is added.
  68. //
  69. #define FREE_SYSTEM_DESCRIPTORS_MIN 2
  70. //
  71. // Define the number of free system descriptors that need to be available for
  72. // a descriptor refill to succeed.
  73. //
  74. #define FREE_SYSTEM_DESCRIPTORS_REQUIRED_FOR_REFILL 3
  75. //
  76. // Define flags used for image sections.
  77. //
  78. #define IMAGE_SECTION_READABLE 0x00000001
  79. #define IMAGE_SECTION_WRITABLE 0x00000002
  80. #define IMAGE_SECTION_EXECUTABLE 0x00000004
  81. #define IMAGE_SECTION_NON_PAGED 0x00000008
  82. #define IMAGE_SECTION_SHARED 0x00000010
  83. #define IMAGE_SECTION_MAP_SYSTEM_CALL 0x00000020
  84. #define IMAGE_SECTION_PAGE_CACHE_BACKED 0x00000040
  85. #define IMAGE_SECTION_NO_IMAGE_BACKING 0x00000080
  86. #define IMAGE_SECTION_DESTROYING 0x00000100
  87. #define IMAGE_SECTION_DESTROYED 0x00000200
  88. #define IMAGE_SECTION_WAS_WRITABLE 0x00000400
  89. //
  90. // Define a mask of image section flags that should be transfered when an image
  91. // section is copied. For internal use only.
  92. //
  93. #define IMAGE_SECTION_COPY_MASK \
  94. (IMAGE_SECTION_ACCESS_MASK | IMAGE_SECTION_NON_PAGED | \
  95. IMAGE_SECTION_SHARED | IMAGE_SECTION_MAP_SYSTEM_CALL | \
  96. IMAGE_SECTION_WAS_WRITABLE)
  97. //
  98. // Define a mask of image section access flags.
  99. //
  100. #define IMAGE_SECTION_ACCESS_MASK \
  101. (IMAGE_SECTION_READABLE | IMAGE_SECTION_WRITABLE | IMAGE_SECTION_EXECUTABLE)
  102. //
  103. // Define the mask of flags that is internal and should not be specified by
  104. // outside callers.
  105. //
  106. #define IMAGE_SECTION_INTERNAL_MASK \
  107. (IMAGE_SECTION_PAGE_CACHE_BACKED | IMAGE_SECTION_NO_IMAGE_BACKING)
  108. //
  109. // Define flags used for unmapping image sections.
  110. //
  111. #define IMAGE_SECTION_UNMAP_FLAG_TRUNCATE 0x00000001
  112. #define IMAGE_SECTION_UNMAP_FLAG_PAGE_CACHE_ONLY 0x00000002
  113. //
  114. // Define flags that describe properties of a fault.
  115. //
  116. #define FAULT_FLAG_PAGE_NOT_PRESENT 0x00000001
  117. #define FAULT_FLAG_WRITE 0x00000002
  118. #define FAULT_FLAG_PROTECTION_FAULT 0x00000004
  119. #define FAULT_FLAG_PERMISSION_ERROR 0x00000008
  120. #define FAULT_FLAG_OUT_OF_BOUNDS 0x00000010
  121. //
  122. // Define mapping flags.
  123. //
  124. #define MAP_FLAG_PRESENT 0x00000001
  125. #define MAP_FLAG_READ_ONLY 0x00000002
  126. #define MAP_FLAG_EXECUTE 0x00000004
  127. #define MAP_FLAG_USER_MODE 0x00000008
  128. #define MAP_FLAG_WRITE_THROUGH 0x00000010
  129. #define MAP_FLAG_CACHE_DISABLE 0x00000020
  130. #define MAP_FLAG_GLOBAL 0x00000040
  131. #define MAP_FLAG_LARGE_PAGE 0x00000080
  132. #define MAP_FLAG_PAGABLE 0x00000100
  133. #define MAP_FLAG_DIRTY 0x00000200
  134. #define MAP_FLAG_PROTECT_MASK 0xFFFF
  135. #define MAP_FLAG_PROTECT_SHIFT 16
  136. #define MAP_FLAG_ALL_MASK \
  137. (MAP_FLAG_PRESENT | \
  138. MAP_FLAG_READ_ONLY | \
  139. MAP_FLAG_EXECUTE | \
  140. MAP_FLAG_USER_MODE | \
  141. MAP_FLAG_WRITE_THROUGH | \
  142. MAP_FLAG_CACHE_DISABLE | \
  143. MAP_FLAG_GLOBAL | \
  144. MAP_FLAG_PAGABLE | \
  145. MAP_FLAG_DIRTY)
  146. //
  147. // Define flags used for creating block allocators.
  148. //
  149. #define BLOCK_ALLOCATOR_FLAG_NON_PAGED 0x00000001
  150. #define BLOCK_ALLOCATOR_FLAG_NON_CACHED 0x00000002
  151. #define BLOCK_ALLOCATOR_FLAG_PHYSICALLY_CONTIGUOUS 0x00000004
  152. #define BLOCK_ALLOCATOR_FLAG_TRIM 0x00000008
  153. #define BLOCK_ALLOCATOR_FLAG_NO_EXPANSION 0x00000010
  154. //
  155. // Define user mode virtual address for the user shared data page.
  156. //
  157. #define USER_SHARED_DATA_USER_ADDRESS ((PVOID)0x7FFFF000)
  158. //
  159. // Define the maximum number of I/O vector elements that will be tolerated from
  160. // user-mode.
  161. //
  162. #define MAX_IO_VECTOR_COUNT 1024
  163. //
  164. // Define the native sized user write function.
  165. // TODO: 64-bit.
  166. //
  167. #define MmUserWrite MmUserWrite32
  168. #define MmUserRead MmUserRead32
  169. //
  170. // Define the bitmask of flags used to initialize or allocate an I/O buffer.
  171. //
  172. #define IO_BUFFER_FLAG_PHYSICALLY_CONTIGUOUS 0x00000001
  173. #define IO_BUFFER_FLAG_MAP_NON_CACHED 0x00000002
  174. #define IO_BUFFER_FLAG_MAP_WRITE_THROUGH 0x00000004
  175. #define IO_BUFFER_FLAG_MEMORY_LOCKED 0x00000008
  176. #define IO_BUFFER_FLAG_KERNEL_MODE_DATA 0x00000010
  177. //
  178. // --------------------------------------------------------------------- Macros
  179. //
  180. #define IS_MEMORY_FREE_TYPE(_Type) ((_Type) == MemoryTypeFree)
  181. //
  182. // Define macros for pool allocations.
  183. //
  184. #define MmAllocateNonPagedPool(_Size, _Tag) \
  185. MmAllocatePool(PoolTypeNonPaged, _Size, _Tag)
  186. #define MmAllocatePagedPool(_Size, _Tag) \
  187. MmAllocatePool(PoolTypePaged, _Size, _Tag)
  188. #define MmFreeNonPagedPool(_Allocation) \
  189. MmFreePool(PoolTypeNonPaged, _Allocation)
  190. #define MmFreePagedPool(_Allocation) \
  191. MmFreePool(PoolTypePaged, _Allocation)
  192. #define MmFreePhysicalPage(_PhysicalAddress) \
  193. MmFreePhysicalPages((_PhysicalAddress), 1)
  194. //
  195. // These macros acquire the address space lock.
  196. //
  197. #define MmAcquireAddressSpaceLock(_AddressSpace) \
  198. KeAcquireQueuedLock((_AddressSpace)->Lock)
  199. #define MmReleaseAddressSpaceLock(_AddressSpace) \
  200. KeReleaseQueuedLock((_AddressSpace)->Lock)
  201. //
  202. // ------------------------------------------------------ Data Type Definitions
  203. //
  204. typedef LONGLONG IO_OFFSET, *PIO_OFFSET;
  205. typedef struct _IMAGE_SECTION_LIST IMAGE_SECTION_LIST, *PIMAGE_SECTION_LIST;
  206. typedef enum _POOL_CORRUPTION_DETAIL {
  207. PoolCorruptionNone,
  208. PoolCorruptionDoubleFree,
  209. PoolCorruptionBufferOverrun
  210. } POOL_CORRUPTION_DETAIL, *PPOOL_CORRUPTION_DETAIL;
  211. typedef enum _MEMORY_TYPE {
  212. MemoryTypeInvalid,
  213. MemoryTypeReserved,
  214. MemoryTypeFree,
  215. MemoryTypeFirmwareTemporary,
  216. MemoryTypeFirmwarePermanent,
  217. MemoryTypeAcpiTables,
  218. MemoryTypeAcpiNvStorage,
  219. MemoryTypeBad,
  220. MemoryTypeLoaderTemporary,
  221. MemoryTypeLoaderPermanent,
  222. MemoryTypePageTables,
  223. MemoryTypeBootPageTables,
  224. MemoryTypeMmStructures,
  225. MemoryTypeNonPagedPool,
  226. MemoryTypePagedPool,
  227. MemoryTypeHardware,
  228. MemoryTypeIoBuffer,
  229. MaxMemoryTypes
  230. } MEMORY_TYPE, *PMEMORY_TYPE;
  231. typedef enum _MDL_ALLOCATION_SOURCE {
  232. MdlAllocationSourceInvalid,
  233. MdlAllocationSourceNone,
  234. MdlAllocationSourceNonPagedPool,
  235. MdlAllocationSourcePagedPool
  236. } MDL_ALLOCATION_SOURCE, *PMDL_ALLOCATION_SOURCE;
  237. typedef enum _ALLOCATION_STRATEGY {
  238. AllocationStrategyInvalid,
  239. AllocationStrategyLowestAddress,
  240. AllocationStrategyAnyAddress,
  241. AllocationStrategyHighestAddress,
  242. AllocationStrategyFixedAddress,
  243. AllocationStrategyFixedAddressClobber,
  244. } ALLOCATION_STRATEGY, *PALLOCATION_STRATEGY;
  245. typedef enum _POOL_TYPE {
  246. PoolTypeInvalid,
  247. PoolTypeNonPaged,
  248. PoolTypePaged,
  249. PoolTypeCount
  250. } POOL_TYPE, *PPOOL_TYPE;
  251. typedef enum _MEMORY_WARNING_LEVEL {
  252. MemoryWarningLevelNone,
  253. MemoryWarningLevel1,
  254. MemoryWarningLevel2,
  255. MaxMemoryWarningLevels
  256. } MEMORY_WARNING_LEVEL, *PMEMORY_WARNING_LEVEL;
  257. typedef enum _MM_INFORMATION_TYPE {
  258. MmInformationInvalid,
  259. MmInformationSystemMemory,
  260. } MM_INFORMATION_TYPE, *PMM_INFORMATION_TYPE;
  261. /*++
  262. Structure Description:
  263. This structure defines a list of memory descriptors.
  264. Members:
  265. Tree - Stores the tree of the memory map.
  266. FreeLists - Stores the array of lists of free regions within the descriptor
  267. list.
  268. DescriptorCount - Stores the number of descriptors in the list.
  269. AllocationSource - Stores the policy on where the MDL should acquire new
  270. descriptors from.
  271. UnusedListHead - Stores the head of the list of descriptors that are
  272. currently not active in the MDL but are available for use.
  273. UnusedDescriptorCount - Stores the number of descriptors in the unused list
  274. that are immediately available.
  275. TotalSpace - Stores the total number of bytes described by this descriptor
  276. list.
  277. FreeSpace - Stores the total free descriptor bytes in this descriptor list.
  278. --*/
  279. typedef struct _MEMORY_DESCRIPTOR_LIST {
  280. RED_BLACK_TREE Tree;
  281. LIST_ENTRY FreeLists[MDL_BIN_COUNT];
  282. ULONG DescriptorCount;
  283. MDL_ALLOCATION_SOURCE AllocationSource;
  284. LIST_ENTRY UnusedListHead;
  285. ULONG UnusedDescriptorCount;
  286. ULONGLONG TotalSpace;
  287. ULONGLONG FreeSpace;
  288. } MEMORY_DESCRIPTOR_LIST, *PMEMORY_DESCRIPTOR_LIST;
  289. /*++
  290. Structure Description:
  291. This structure defines a contiguous piece of physical memory.
  292. Members:
  293. TreeNode - Stores the red-black tree membership information for this
  294. descriptor.
  295. FreeListEntry - Stores links to the next and previous memory descriptors if
  296. this descriptor represents a free area.
  297. BaseAddress - Stores the address of the beginning of the descriptor.
  298. Size - Stores the size of the region, in bytes.
  299. Type - Stores the type of memory that this descriptor represents.
  300. Flags - Stores various state of the descriptor. See DESCRIPTOR_FLAG_*
  301. definitions.
  302. --*/
  303. typedef struct _MEMORY_DESCRIPTOR {
  304. RED_BLACK_TREE_NODE TreeNode;
  305. LIST_ENTRY FreeListEntry;
  306. ULONGLONG BaseAddress;
  307. ULONGLONG Size;
  308. MEMORY_TYPE Type;
  309. ULONG Flags;
  310. } MEMORY_DESCRIPTOR, *PMEMORY_DESCRIPTOR;
  311. typedef
  312. VOID
  313. (*PMEMORY_DESCRIPTOR_LIST_ITERATION_ROUTINE) (
  314. PMEMORY_DESCRIPTOR_LIST DescriptorList,
  315. PMEMORY_DESCRIPTOR Descriptor,
  316. PVOID Context
  317. );
  318. /*++
  319. Routine Description:
  320. This routine is called once for each descriptor in the memory descriptor
  321. list.
  322. Arguments:
  323. DescriptorList - Supplies a pointer to the descriptor list being iterated
  324. over.
  325. Descriptor - Supplies a pointer to the current descriptor.
  326. Context - Supplies an optional opaque pointer of context that was provided
  327. when the iteration was requested.
  328. Return Value:
  329. None.
  330. --*/
  331. /*++
  332. Structure Description:
  333. This structure defines a memory accountant. This structure can be passed
  334. into support routines that keep track of which memory for a given region
  335. is in use.
  336. Members:
  337. Flags - Stores characteristics about the memory accounting. See the
  338. MEMORY_ACCOUNTING_FLAG_* flags.
  339. Lock - Stores a pointer to the shared/exclusive lock that synchronizes
  340. access to the accounting structures (type SHARED_EXCLUSIVE_LOCK).
  341. Mdl - Stores the memory descriptor list containing which areas are free
  342. and which are in use.
  343. --*/
  344. typedef struct _MEMORY_ACCOUNTING {
  345. ULONG Flags;
  346. PVOID Lock;
  347. MEMORY_DESCRIPTOR_LIST Mdl;
  348. } MEMORY_ACCOUNTING, *PMEMORY_ACCOUNTING;
  349. /*++
  350. Structure Description:
  351. This structure stores memory page backing information for a section of
  352. memory.
  353. Members:
  354. DeviceHandle - Stores a pointer to the device or file backing the
  355. allocation.
  356. Offset - Stores the offset from the beginning of the file where the backing
  357. starts, in bytes.
  358. --*/
  359. typedef struct _IMAGE_BACKING {
  360. HANDLE DeviceHandle;
  361. IO_OFFSET Offset;
  362. } IMAGE_BACKING, *PIMAGE_BACKING;
  363. /*++
  364. Structure Description:
  365. This structure defines a virtual address space reservation.
  366. Members:
  367. Process - Stores a pointer to the process owning the reservation.
  368. VirtualBase - Stores the base virtual address of the reservation.
  369. Size - Stores the size, in bytes, of the reservation.
  370. --*/
  371. typedef struct _MEMORY_RESERVATION {
  372. PVOID Process;
  373. PVOID VirtualBase;
  374. UINTN Size;
  375. } MEMORY_RESERVATION, *PMEMORY_RESERVATION;
  376. /*++
  377. Structure Description:
  378. This structure defines an I/O buffer fragment, a region of memory that is
  379. physically and virtually contiguous.
  380. Members:
  381. PhysicalAddress - Stores the physical address of the memory region.
  382. VirtualAddress - Stores the virtual address of the memory region.
  383. Size - Stores the size of the region, in bytes.
  384. --*/
  385. typedef struct _IO_BUFFER_FRAGMENT {
  386. PHYSICAL_ADDRESS PhysicalAddress;
  387. PVOID VirtualAddress;
  388. UINTN Size;
  389. } IO_BUFFER_FRAGMENT, *PIO_BUFFER_FRAGMENT;
  390. /*++
  391. Structure Description:
  392. This structure defines an I/O buffer.
  393. Members:
  394. Flags - Stores a bitfield of flags reserved for use interally by
  395. the memory management system.
  396. CurrentOffset - Stores the byte offset into the buffer at which all I/O
  397. or copies will begin.
  398. MaxFragmentCount - Stores the maximum number of fragments that this I/O
  399. buffer can hold.
  400. TotalSize - Stores the total size of the I/O buffer.
  401. PageCacheEntryCount - Store the maximum number of page cache entries that
  402. the I/O buffer can contain.
  403. PageCacheEntry - Stores a pointer to a page cache entry used for
  404. stack-allocated I/O buffers that only require one page.
  405. PageCacheEntries - Stores an array of page cache entries associated with
  406. this I/O buffer.
  407. Fragment - Stores an I/O buffer fragment structure used for stack-allocated
  408. I/O buffers that only require one fragment.
  409. --*/
  410. typedef struct _IO_BUFFER_INTERNAL {
  411. ULONG Flags;
  412. UINTN CurrentOffset;
  413. UINTN MaxFragmentCount;
  414. UINTN TotalSize;
  415. UINTN PageCacheEntryCount;
  416. PVOID PageCacheEntry;
  417. PVOID *PageCacheEntries;
  418. IO_BUFFER_FRAGMENT Fragment;
  419. } IO_BUFFER_INTERNAL, *PIO_BUFFER_INTERNAL;
  420. /*++
  421. Structure Description:
  422. This structure defines an I/O buffer.
  423. Members:
  424. Fragment - Stores an array of memory fragments that make up the I/O
  425. buffer, sorted by virtual address.
  426. FragmentCount - Stores the number of fragments in the fragment array.
  427. Internal - Stores I/O buffer information that is internal to the system.
  428. --*/
  429. typedef struct _IO_BUFFER {
  430. IO_BUFFER_FRAGMENT *Fragment;
  431. UINTN FragmentCount;
  432. IO_BUFFER_INTERNAL Internal;
  433. } IO_BUFFER, *PIO_BUFFER;
  434. typedef struct _BLOCK_ALLOCATOR BLOCK_ALLOCATOR, *PBLOCK_ALLOCATOR;
  435. /*++
  436. Structure Description:
  437. This structure defines an I/O buffer.
  438. Members:
  439. Version - Stores the structure version number. Set this to
  440. MM_STATISTICS_VERSION.
  441. PageSize - Stores the size of a page in the system.
  442. NonPagedPool - Stores memory heap statistics for non-paged pool.
  443. PagedPool - Stores memory heap statistics for paged pool.
  444. PhysicalPages - Stores the number of physical pages in the system.
  445. AllocatedPhysicalPages - Stores the number of physical pages currently in
  446. use by the system.
  447. NonPagedPhysicalPages - Stores the number of physical pages that are
  448. pinned in memory and cannot be paged out to disk.
  449. --*/
  450. typedef struct _MM_STATISTICS {
  451. ULONG Version;
  452. ULONG PageSize;
  453. MEMORY_HEAP_STATISTICS NonPagedPool;
  454. MEMORY_HEAP_STATISTICS PagedPool;
  455. ULONGLONG PhysicalPages;
  456. ULONGLONG AllocatedPhysicalPages;
  457. ULONGLONG NonPagedPhysicalPages;
  458. } MM_STATISTICS, *PMM_STATISTICS;
  459. /*++
  460. Structure Description:
  461. This structure defines an I/O vector, a structure used in kernel mode that
  462. lines up with struct iovec in the C library.
  463. Members:
  464. Data - Stores a pointer to the data.
  465. Length - Stores a the length of the data.
  466. --*/
  467. typedef struct _IO_VECTOR {
  468. PVOID Data;
  469. UINTN Length;
  470. } IO_VECTOR, *PIO_VECTOR;
  471. /*++
  472. Structure Description:
  473. This structure defines an address space context.
  474. Members:
  475. Lock - Stores a pointer to the queued lock serializing access to the
  476. image section list.
  477. SectionListHead - Stores the head of the list of image sections mapped
  478. into this process.
  479. Accountant - Stores a pointer to the address tracking information for this
  480. space.
  481. ResidentSet - Stores the number of pages currently mapped in the process.
  482. MaxResidentSet - Stores the maximum resident set ever mapped into the
  483. process.
  484. MaxMemoryMap - Stores the maximum address that map/unmap system calls
  485. should return.
  486. BreakStart - Stores the start address of the program break.
  487. BreakEnd - Stores the end address of the program break.
  488. --*/
  489. typedef struct _ADDRESS_SPACE {
  490. PVOID Lock;
  491. LIST_ENTRY SectionListHead;
  492. PMEMORY_ACCOUNTING Accountant;
  493. volatile UINTN ResidentSet;
  494. volatile UINTN MaxResidentSet;
  495. PVOID MaxMemoryMap;
  496. PVOID BreakStart;
  497. PVOID BreakEnd;
  498. } ADDRESS_SPACE, *PADDRESS_SPACE;
  499. /*++
  500. Structure Description:
  501. This structure defines the usual set of parameters for a virtual memory
  502. allocation request.
  503. Members:
  504. Address - Stores the preferred or demanded address on input, and the
  505. returned address on output.
  506. Size - Stores the size of the allocation.
  507. Alignment - Stores the required alignment of the allocation.
  508. Min - Stores the minimum address to allocate.
  509. Max - Stores the maximum address to allocate.
  510. MemoryType - Stores the requested memory type.
  511. Strategy - Stores the memory allocation strategy to use.
  512. --*/
  513. typedef struct _VM_ALLOCATION_PARAMETERS {
  514. PVOID Address;
  515. UINTN Size;
  516. ULONG Alignment;
  517. PVOID Min;
  518. PVOID Max;
  519. MEMORY_TYPE MemoryType;
  520. ALLOCATION_STRATEGY Strategy;
  521. } VM_ALLOCATION_PARAMETERS, *PVM_ALLOCATION_PARAMETERS;
  522. //
  523. // -------------------------------------------------------------------- Globals
  524. //
  525. //
  526. // -------------------------------------------------------- Function Prototypes
  527. //
  528. KERNEL_API
  529. PVOID
  530. MmAllocatePool (
  531. POOL_TYPE PoolType,
  532. UINTN Size,
  533. ULONG Tag
  534. );
  535. /*++
  536. Routine Description:
  537. This routine allocates memory from a kernel pool.
  538. Arguments:
  539. PoolType - Supplies the type of pool to allocate from. Valid choices are:
  540. PoolTypeNonPaged - This type of memory will never be paged out. It is a
  541. scarce resource, and should only be allocated if paged pool is not
  542. an option. This memory is marked no-execute.
  543. PoolTypePaged - This is normal memory that may be transparently paged if
  544. memory gets tight. The caller may not touch paged pool at run-levels at
  545. or above dispatch, and is not suitable for DMA (as its physical address
  546. may change unexpectedly.) This pool type should be used for most normal
  547. allocations. This memory is marked no-execute.
  548. Size - Supplies the size of the allocation, in bytes.
  549. Tag - Supplies an identifier to associate with the allocation, useful for
  550. debugging and leak detection.
  551. Return Value:
  552. Returns the allocated memory if successful, or NULL on failure.
  553. --*/
  554. KERNEL_API
  555. PVOID
  556. MmReallocatePool (
  557. POOL_TYPE PoolType,
  558. PVOID Memory,
  559. UINTN NewSize,
  560. UINTN AllocationTag
  561. );
  562. /*++
  563. Routine Description:
  564. This routine resizes the given allocation, potentially creating a new
  565. buffer and copying the old contents in.
  566. Arguments:
  567. PoolType - Supplies the type of pool the memory was allocated from. This
  568. must agree with the type of pool the allocation originated from, or
  569. the system will become unstable.
  570. Memory - Supplies the original active allocation. If this parameter is
  571. NULL, this routine will simply allocate memory.
  572. NewSize - Supplies the new required size of the allocation. If this is
  573. 0, then the original allocation will simply be freed.
  574. AllocationTag - Supplies an identifier for this allocation.
  575. Return Value:
  576. Returns a pointer to a buffer with the new size (and original contents) on
  577. success. This may be a new buffer or the same one.
  578. NULL on failure or if the new size supplied was zero.
  579. --*/
  580. KERNEL_API
  581. VOID
  582. MmFreePool (
  583. POOL_TYPE PoolType,
  584. PVOID Allocation
  585. );
  586. /*++
  587. Routine Description:
  588. This routine frees memory allocated from a kernel pool.
  589. Arguments:
  590. PoolType - Supplies the type of pool the memory was allocated from. This
  591. must agree with the type of pool the allocation originated from, or
  592. the system will become unstable.
  593. Allocation - Supplies a pointer to the allocation to free. This pointer
  594. may not be referenced after this function completes.
  595. Return Value:
  596. None.
  597. --*/
  598. KSTATUS
  599. MmGetPoolProfilerStatistics (
  600. PVOID *Buffer,
  601. PULONG BufferSize,
  602. ULONG Tag
  603. );
  604. /*++
  605. Routine Description:
  606. This routine allocates a buffer and fills it with the pool statistics.
  607. Arguments:
  608. Buffer - Supplies a pointer that receives a buffer full of pool statistics.
  609. BufferSize - Supplies a pointer that receives the size of the buffer, in
  610. bytes.
  611. Tag - Supplies an identifier to associate with the allocation, useful for
  612. debugging and leak detection.
  613. Return Value:
  614. Status code.
  615. --*/
  616. KERNEL_API
  617. VOID
  618. MmDebugPrintPoolStatistics (
  619. VOID
  620. );
  621. /*++
  622. Routine Description:
  623. This routine prints pool statistics to the debugger.
  624. Arguments:
  625. None.
  626. Return Value:
  627. None.
  628. --*/
  629. KERNEL_API
  630. PIO_BUFFER
  631. MmAllocateNonPagedIoBuffer (
  632. PHYSICAL_ADDRESS MinimumPhysicalAddress,
  633. PHYSICAL_ADDRESS MaximumPhysicalAddress,
  634. UINTN Alignment,
  635. UINTN Size,
  636. ULONG Flags
  637. );
  638. /*++
  639. Routine Description:
  640. This routine allocates memory for use as an I/O buffer. This memory will
  641. remain mapped in memory until the buffer is destroyed.
  642. Arguments:
  643. MinimumPhysicalAddress - Supplies the minimum physical address of the
  644. allocation.
  645. MaximumPhysicalAddress - Supplies the maximum physical address of the
  646. allocation.
  647. Alignment - Supplies the required physical alignment of the buffer.
  648. Size - Supplies the minimum size of the buffer, in bytes.
  649. Flags - Supplies a bitmask of flags used to allocate the I/O buffer. See
  650. IO_BUFFER_FLAG_* for definitions.
  651. Return Value:
  652. Returns a pointer to the I/O buffer on success, or NULL on failure.
  653. --*/
  654. KERNEL_API
  655. PIO_BUFFER
  656. MmAllocatePagedIoBuffer (
  657. UINTN Size,
  658. ULONG Flags
  659. );
  660. /*++
  661. Routine Description:
  662. This routine allocates memory for use as a pageable I/O buffer.
  663. Arguments:
  664. Size - Supplies the minimum size of the buffer, in bytes.
  665. Flags - Supplies a bitmask of flags used to allocate the I/O buffer. See
  666. IO_BUFFER_FLAG_* for definitions.
  667. Return Value:
  668. Returns a pointer to the I/O buffer on success, or NULL on failure.
  669. --*/
  670. KERNEL_API
  671. PIO_BUFFER
  672. MmAllocateUninitializedIoBuffer (
  673. UINTN Size,
  674. ULONG Flags
  675. );
  676. /*++
  677. Routine Description:
  678. This routine allocates an uninitialized I/O buffer that the caller will
  679. fill in with pages. It simply allocates the structures for the given
  680. size, assuming a buffer fragment may be required for each page.
  681. Arguments:
  682. Size - Supplies the minimum size of the buffer, in bytes. This size is
  683. rounded up (always) to a page, but does assume page alignment.
  684. Flags - Supplies a bitmask of flags used to allocate the I/O buffer. See
  685. IO_BUFFER_FLAG_* for definitions.
  686. Return Value:
  687. Returns a pointer to the I/O buffer on success, or NULL on failure.
  688. --*/
  689. KERNEL_API
  690. KSTATUS
  691. MmCreateIoBuffer (
  692. PVOID Buffer,
  693. UINTN SizeInBytes,
  694. ULONG Flags,
  695. PIO_BUFFER *NewIoBuffer
  696. );
  697. /*++
  698. Routine Description:
  699. This routine creates an I/O buffer from an existing memory buffer. This
  700. routine must be called at low level.
  701. Arguments:
  702. Buffer - Supplies a pointer to the memory buffer on which to base the I/O
  703. buffer.
  704. SizeInBytes - Supplies the size of the buffer, in bytes.
  705. Flags - Supplies a bitmask of flags used to allocate the I/O buffer. See
  706. IO_BUFFER_FLAG_* for definitions.
  707. NewIoBuffer - Supplies a pointer where a pointer to the new I/O buffer
  708. will be returned on success.
  709. Return Value:
  710. Status code.
  711. --*/
  712. KSTATUS
  713. MmCreateIoBufferFromVector (
  714. PIO_VECTOR Vector,
  715. BOOL VectorInKernelMode,
  716. UINTN VectorCount,
  717. PIO_BUFFER *NewIoBuffer
  718. );
  719. /*++
  720. Routine Description:
  721. This routine creates a paged usermode I/O buffer based on an I/O vector
  722. array. This is generally used to support vectored I/O functions in the C
  723. library.
  724. Arguments:
  725. Vector - Supplies a pointer to the I/O vector array.
  726. VectorInKernelMode - Supplies a boolean indicating if the given I/O vector
  727. array comes directly from kernel mode.
  728. VectorCount - Supplies the number of elements in the vector array.
  729. NewIoBuffer - Supplies a pointer where a pointer to the newly created I/O
  730. buffer will be returned on success. The caller is responsible for
  731. releasing this buffer.
  732. Return Value:
  733. STATUS_SUCCESS on success.
  734. STATUS_INVALID_PARAMETER if the vector count is invalid.
  735. STATUS_INSUFFICIENT_RESOURCES on allocation failure.
  736. STATUS_ACCESS_VIOLATION if the given vector array was from user-mode and
  737. was not valid.
  738. --*/
  739. KSTATUS
  740. MmInitializeIoBuffer (
  741. PIO_BUFFER IoBuffer,
  742. PVOID VirtualAddress,
  743. PHYSICAL_ADDRESS PhysicalAddress,
  744. UINTN SizeInBytes,
  745. ULONG Flags
  746. );
  747. /*++
  748. Routine Description:
  749. This routine initializes an I/O buffer based on the given virtual and
  750. phsyical address and the size. If a physical address is supplied, it is
  751. assumed that the range of bytes is both virtually and physically contiguous
  752. so that it can be contained in one fragment.
  753. Arguments:
  754. IoBuffer - Supplies a pointer to the I/O buffer to initialize.
  755. VirtualAddress - Supplies the starting virtual address of the I/O buffer.
  756. PhysicalAddress - Supplies the starting physical address of the I/O buffer.
  757. SizeInBytes - Supplies the size of the I/O buffer, in bytes.
  758. Flags - Supplies a bitmask of flags used to initialize the I/O buffer. See
  759. IO_BUFFER_FLAG_* for definitions.
  760. Return Value:
  761. Status code.
  762. --*/
  763. KERNEL_API
  764. VOID
  765. MmFreeIoBuffer (
  766. PIO_BUFFER IoBuffer
  767. );
  768. /*++
  769. Routine Description:
  770. This routine destroys an I/O buffer. If the memory was allocated when the
  771. I/O buffer was created, then the memory will be released at this time as
  772. well.
  773. Arguments:
  774. IoBuffer - Supplies a pointer to the I/O buffer to release.
  775. Return Value:
  776. None.
  777. --*/
  778. VOID
  779. MmResetIoBuffer (
  780. PIO_BUFFER IoBuffer
  781. );
  782. /*++
  783. Routine Description:
  784. This routine resets an I/O buffer for re-use, unmapping any memory and
  785. releasing any associated page cache entries.
  786. Arguments:
  787. IoBuffer - Supplies a pointer to an I/O buffer.
  788. Return Value:
  789. Status code.
  790. --*/
  791. KERNEL_API
  792. KSTATUS
  793. MmMapIoBuffer (
  794. PIO_BUFFER IoBuffer,
  795. BOOL WriteThrough,
  796. BOOL NonCached,
  797. BOOL VirtuallyContiguous
  798. );
  799. /*++
  800. Routine Description:
  801. This routine maps the given I/O buffer into memory. If the caller requests
  802. that the I/O buffer be mapped virtually contiguous, then all fragments will
  803. be updated with the virtually contiguous mappings. If the I/O buffer does
  804. not need to be virtually contiguous, then this routine just ensure that
  805. each fragment is mapped.
  806. Arguments:
  807. IoBuffer - Supplies a pointer to an I/O buffer.
  808. WriteThrough - Supplies a boolean indicating if the virtual addresses
  809. should be mapped write through (TRUE) or the default write back (FALSE).
  810. NonCached - Supplies a boolean indicating if the virtual addresses should
  811. be mapped non-cached (TRUE) or the default, which is to map is as
  812. normal cached memory (FALSE).
  813. VirtuallyContiguous - Supplies a boolean indicating whether or not the
  814. caller needs the I/O buffer to be mapped virtually contiguous (TRUE) or
  815. not (FALSE). In the latter case, each I/O buffer fragment will at least
  816. be virtually contiguous.
  817. Return Value:
  818. Status code.
  819. --*/
  820. KERNEL_API
  821. KSTATUS
  822. MmCopyIoBuffer (
  823. PIO_BUFFER Destination,
  824. UINTN DestinationOffset,
  825. PIO_BUFFER Source,
  826. UINTN SourceOffset,
  827. UINTN ByteCount
  828. );
  829. /*++
  830. Routine Description:
  831. This routine copies the contents of the source I/O buffer starting at the
  832. source offset to the destination I/O buffer starting at the destination
  833. offset. It assumes that the arguments are correct such that the copy can
  834. succeed.
  835. Arguments:
  836. Destination - Supplies a pointer to the destination I/O buffer that is to
  837. be copied into.
  838. DestinationOffset - Supplies the offset into the destination I/O buffer
  839. where the copy should begin.
  840. Source - Supplies a pointer to the source I/O buffer whose contents will be
  841. copied to the destination.
  842. SourceOffset - Supplies the offset into the source I/O buffer where the
  843. copy should begin.
  844. ByteCount - Supplies the size of the requested copy in bytes.
  845. Return Value:
  846. Status code.
  847. --*/
  848. KERNEL_API
  849. KSTATUS
  850. MmZeroIoBuffer (
  851. PIO_BUFFER IoBuffer,
  852. UINTN Offset,
  853. UINTN ByteCount
  854. );
  855. /*++
  856. Routine Description:
  857. This routine zeroes the contents of the I/O buffer starting at the offset
  858. for the given number of bytes.
  859. Arguments:
  860. IoBuffer - Supplies a pointer to the I/O buffer that is to be zeroed.
  861. Offset - Supplies the offset into the I/O buffer where the zeroing
  862. should begin.
  863. ByteCount - Supplies the number of bytes to zero.
  864. Return Value:
  865. Status code.
  866. --*/
  867. KERNEL_API
  868. KSTATUS
  869. MmCopyIoBufferData (
  870. PIO_BUFFER IoBuffer,
  871. PVOID Buffer,
  872. UINTN Offset,
  873. UINTN Size,
  874. BOOL ToIoBuffer
  875. );
  876. /*++
  877. Routine Description:
  878. This routine copies from a buffer into the given I/O buffer or out of the
  879. given I/O buffer.
  880. Arguments:
  881. IoBuffer - Supplies a pointer to the I/O buffer to copy in or out of.
  882. Buffer - Supplies a pointer to the regular linear buffer to copy to or from.
  883. This must be a kernel mode address.
  884. Offset - Supplies an offset in bytes from the beginning of the I/O buffer
  885. to copy to or from.
  886. Size - Supplies the number of bytes to copy.
  887. ToIoBuffer - Supplies a boolean indicating whether data is copied into the
  888. I/O buffer (TRUE) or out of the I/O buffer (FALSE).
  889. Return Value:
  890. STATUS_SUCCESS on success.
  891. STATUS_INCORRECT_BUFFER_SIZE if the copy goes outside the I/O buffer.
  892. Other error codes if the I/O buffer could not be mapped.
  893. --*/
  894. KERNEL_API
  895. ULONG
  896. MmGetIoBufferAlignment (
  897. VOID
  898. );
  899. /*++
  900. Routine Description:
  901. This routine returns the required alignment for all flush operations.
  902. Arguments:
  903. None.
  904. Return Value:
  905. Returns the size of a data cache line, in bytes.
  906. --*/
  907. KSTATUS
  908. MmValidateIoBuffer (
  909. PHYSICAL_ADDRESS MinimumPhysicalAddress,
  910. PHYSICAL_ADDRESS MaximumPhysicalAddress,
  911. UINTN Alignment,
  912. UINTN SizeInBytes,
  913. BOOL PhysicallyContiguous,
  914. PIO_BUFFER *IoBuffer,
  915. PBOOL LockedCopy
  916. );
  917. /*++
  918. Routine Description:
  919. This routine validates an I/O buffer for use by a device. If the I/O buffer
  920. does not meet the given requirements, then a new I/O buffer that meets the
  921. requirements will be returned. This new I/O buffer will not contain the
  922. same data as the originally supplied I/O buffer. It is up to the caller to
  923. decide which further actions need to be taken if a different buffer is
  924. returned. The exception is if the locked parameter is returned as true. In
  925. that case a new I/O buffer was created, but is backed by the same physical
  926. pages, now locked in memory.
  927. Arguments:
  928. MinimumPhysicalAddress - Supplies the minimum allowed physical address for
  929. the I/O buffer.
  930. MaximumPhysicalAddress - Supplies the maximum allowed physical address for
  931. the I/O buffer.
  932. Alignment - Supplies the required physical alignment of the I/O buffer.
  933. SizeInBytes - Supplies the minimum required size of the buffer, in bytes.
  934. PhysicallyContiguous - Supplies a boolean indicating whether or not the
  935. I/O buffer should be physically contiguous.
  936. IoBuffer - Supplies a pointer to a pointer to an I/O buffer. On entry, this
  937. contains a pointer to the I/O buffer to be validated. On exit, it may
  938. point to a newly allocated I/O buffer that the caller must free.
  939. LockedCopy - Supplies a pointer to a boolean that receives whether or not
  940. the validated I/O buffer is a locked copy of the original.
  941. Return Value:
  942. Status code.
  943. --*/
  944. KSTATUS
  945. MmValidateIoBufferForCachedIo (
  946. PIO_BUFFER *IoBuffer,
  947. UINTN SizeInBytes,
  948. UINTN Alignment
  949. );
  950. /*++
  951. Routine Description:
  952. This routine validates an I/O buffer for a cached I/O operation,
  953. potentially returning a new I/O buffer.
  954. Arguments:
  955. IoBuffer - Supplies a pointer to an I/O buffer pointer. On entry, it stores
  956. the pointer to the I/O buffer to evaluate. On exit, it stores a pointer
  957. to a valid I/O buffer, that may actually be a new I/O buffer.
  958. SizeInBytes - Supplies the required size of the I/O buffer.
  959. Alignment - Supplies the required alignment of the I/O buffer.
  960. Return Value:
  961. Status code.
  962. --*/
  963. VOID
  964. MmIoBufferAppendPage (
  965. PIO_BUFFER IoBuffer,
  966. PVOID PageCacheEntry,
  967. PVOID VirtualAddress,
  968. PHYSICAL_ADDRESS PhysicalAddress
  969. );
  970. /*++
  971. Routine Description:
  972. This routine appends a page, as described by its VA/PA or page cache entry,
  973. to the end of the given I/O buffer. The caller should either supply a page
  974. cache entry or a physical address (with an optional virtual address), but
  975. not both.
  976. Arguments:
  977. IoBuffer - Supplies a pointer to an I/O buffer.
  978. PageCacheEntry - Supplies an optional pointer to the page cache entry whose
  979. data will be appended to the I/O buffer.
  980. VirtualAddress - Supplies an optional virtual address for the range.
  981. PhysicalAddress - Supplies the optional physical address of the data that
  982. is to be set in the I/O buffer at the given offset. Use
  983. INVALID_PHYSICAL_ADDRESS when supplying a page cache entry.
  984. Return Value:
  985. None.
  986. --*/
  987. VOID
  988. MmSetIoBufferPageCacheEntry (
  989. PIO_BUFFER IoBuffer,
  990. UINTN IoBufferOffset,
  991. PVOID PageCacheEntry
  992. );
  993. /*++
  994. Routine Description:
  995. This routine sets the given page cache entry in the I/O buffer at the given
  996. offset. The physical address of the page cache entry should match that of
  997. the I/O buffer at the given offset.
  998. Arguments:
  999. IoBuffer - Supplies a pointer to an I/O buffer.
  1000. IoBufferOffset - Supplies an offset into the given I/O buffer.
  1001. PageCacheEntry - Supplies a pointer to the page cache entry to set.
  1002. Return Value:
  1003. None.
  1004. --*/
  1005. PVOID
  1006. MmGetIoBufferPageCacheEntry (
  1007. PIO_BUFFER IoBuffer,
  1008. UINTN IoBufferOffset
  1009. );
  1010. /*++
  1011. Routine Description:
  1012. This routine returns the page cache entry associated with the given I/O
  1013. buffer at the given offset into the buffer.
  1014. Arguments:
  1015. IoBuffer - Supplies a pointer to an I/O buffer.
  1016. IoBufferOffset - Supplies an offset into the I/O buffer, in bytes.
  1017. Return Value:
  1018. Returns a pointer to a page cache entry if the physical page at the given
  1019. offset has been cached, or NULL otherwise.
  1020. --*/
  1021. KERNEL_API
  1022. UINTN
  1023. MmGetIoBufferSize (
  1024. PIO_BUFFER IoBuffer
  1025. );
  1026. /*++
  1027. Routine Description:
  1028. This routine returns the size of the I/O buffer, in bytes.
  1029. Arguments:
  1030. IoBuffer - Supplies a pointer to an I/O buffer.
  1031. Return Value:
  1032. Returns the size of the I/O buffer, in bytes.
  1033. --*/
  1034. KERNEL_API
  1035. UINTN
  1036. MmGetIoBufferCurrentOffset (
  1037. PIO_BUFFER IoBuffer
  1038. );
  1039. /*++
  1040. Routine Description:
  1041. This routine returns the given I/O buffer's current offset. The offset is
  1042. the point at which all I/O should begin.
  1043. Arguments:
  1044. IoBuffer - Supplies a pointer to an I/O buffer.
  1045. Return Value:
  1046. Returns the I/O buffers current offset.
  1047. --*/
  1048. KERNEL_API
  1049. VOID
  1050. MmSetIoBufferCurrentOffset (
  1051. PIO_BUFFER IoBuffer,
  1052. UINTN Offset
  1053. );
  1054. /*++
  1055. Routine Description:
  1056. This routine sets the given I/O buffer's current offset. The offset is
  1057. the point at which all I/O should begin.
  1058. Arguments:
  1059. IoBuffer - Supplies a pointer to an I/O buffer.
  1060. Offset - Supplies the new offset for the I/O buffer.
  1061. Return Value:
  1062. None.
  1063. --*/
  1064. KERNEL_API
  1065. VOID
  1066. MmIoBufferIncrementOffset (
  1067. PIO_BUFFER IoBuffer,
  1068. UINTN OffsetIncrement
  1069. );
  1070. /*++
  1071. Routine Description:
  1072. This routine increments the I/O buffer's current offset by the given amount.
  1073. Arguments:
  1074. IoBuffer - Supplies a pointer to an I/O buffer.
  1075. OffsetIncrement - Supplies the number of bytes by which the offset will be
  1076. incremented.
  1077. Return Value:
  1078. None.
  1079. --*/
  1080. KERNEL_API
  1081. VOID
  1082. MmIoBufferDecrementOffset (
  1083. PIO_BUFFER IoBuffer,
  1084. UINTN OffsetDecrement
  1085. );
  1086. /*++
  1087. Routine Description:
  1088. This routine decrements the I/O buffer's current offset by the given amount.
  1089. Arguments:
  1090. IoBuffer - Supplies a pointer to an I/O buffer.
  1091. OffsetDecrement - Supplies the number of bytes by which the offset will be
  1092. incremented.
  1093. Return Value:
  1094. None.
  1095. --*/
  1096. PHYSICAL_ADDRESS
  1097. MmGetIoBufferPhysicalAddress (
  1098. PIO_BUFFER IoBuffer,
  1099. UINTN IoBufferOffset
  1100. );
  1101. /*++
  1102. Routine Description:
  1103. This routine returns the physical address at a given offset within an I/O
  1104. buffer.
  1105. Arguments:
  1106. IoBuffer - Supplies a pointer to an I/O buffer.
  1107. IoBufferOffset - Supplies a byte offset into the I/O buffer.
  1108. Return Value:
  1109. Returns the physical address of the memory at the given offset within the
  1110. I/O buffer.
  1111. --*/
  1112. KERNEL_API
  1113. PVOID
  1114. MmGetVirtualMemoryWarningEvent (
  1115. VOID
  1116. );
  1117. /*++
  1118. Routine Description:
  1119. This routine returns the memory manager's system virtual memory warning
  1120. event. This event is signaled whenever there is a change in system virtual
  1121. memory's warning level.
  1122. Arguments:
  1123. None.
  1124. Return Value:
  1125. Returns a pointer to the virutal memory warning event.
  1126. --*/
  1127. KERNEL_API
  1128. MEMORY_WARNING_LEVEL
  1129. MmGetVirtualMemoryWarningLevel (
  1130. VOID
  1131. );
  1132. /*++
  1133. Routine Description:
  1134. This routine returns the current system virtual memory warning level.
  1135. Arguments:
  1136. None.
  1137. Return Value:
  1138. Returns the current virtual memory warning level.
  1139. --*/
  1140. UINTN
  1141. MmGetTotalVirtualMemory (
  1142. VOID
  1143. );
  1144. /*++
  1145. Routine Description:
  1146. This routine returns the size of the kernel virtual address space, in bytes.
  1147. Arguments:
  1148. None.
  1149. Return Value:
  1150. Returns the total number of bytes in the kernel virtual address space.
  1151. --*/
  1152. UINTN
  1153. MmGetFreeVirtualMemory (
  1154. VOID
  1155. );
  1156. /*++
  1157. Routine Description:
  1158. This routine returns the number of unallocated bytes in the kernel virtual
  1159. address space.
  1160. Arguments:
  1161. None.
  1162. Return Value:
  1163. Returns the total amount of free kernel virtual memory, in bytes.
  1164. --*/
  1165. KERNEL_API
  1166. PVOID
  1167. MmMapPhysicalAddress (
  1168. PHYSICAL_ADDRESS PhysicalAddress,
  1169. UINTN SizeInBytes,
  1170. BOOL Writable,
  1171. BOOL WriteThrough,
  1172. BOOL CacheDisabled
  1173. );
  1174. /*++
  1175. Routine Description:
  1176. This routine maps a physical address into kernel VA space. It is meant so
  1177. that system components can access memory mapped hardware.
  1178. Arguments:
  1179. PhysicalAddress - Supplies a pointer to the physical address.
  1180. SizeInBytes - Supplies the size in bytes of the mapping. This will be
  1181. rounded up to the nearest page size.
  1182. Writable - Supplies a boolean indicating if the memory is to be marked
  1183. writable (TRUE) or read-only (FALSE).
  1184. WriteThrough - Supplies a boolean indicating if the memory is to be marked
  1185. write-through (TRUE) or write-back (FALSE).
  1186. CacheDisabled - Supplies a boolean indicating if the memory is to be mapped
  1187. uncached.
  1188. Return Value:
  1189. Returns a pointer to the virtual address of the mapping on success, or
  1190. NULL on failure.
  1191. --*/
  1192. KERNEL_API
  1193. VOID
  1194. MmUnmapAddress (
  1195. PVOID VirtualAddress,
  1196. UINTN SizeInBytes
  1197. );
  1198. /*++
  1199. Routine Description:
  1200. This routine unmaps memory mapped with MmMapPhysicalMemory.
  1201. Arguments:
  1202. VirtualAddress - Supplies the virtual address to unmap.
  1203. SizeInBytes - Supplies the number of bytes to unmap.
  1204. Return Value:
  1205. None.
  1206. --*/
  1207. KERNEL_API
  1208. ULONG
  1209. MmPageSize (
  1210. VOID
  1211. );
  1212. /*++
  1213. Routine Description:
  1214. This routine returns the size of a page of memory.
  1215. Arguments:
  1216. None.
  1217. Return Value:
  1218. Returns the size of one page of memory (ie the minimum mapping granularity).
  1219. --*/
  1220. KERNEL_API
  1221. ULONG
  1222. MmPageShift (
  1223. VOID
  1224. );
  1225. /*++
  1226. Routine Description:
  1227. This routine returns the amount to shift by to truncate an address to a
  1228. page number.
  1229. Arguments:
  1230. None.
  1231. Return Value:
  1232. Returns the amount to shift to reach page granularity.
  1233. --*/
  1234. KERNEL_API
  1235. PBLOCK_ALLOCATOR
  1236. MmCreateBlockAllocator (
  1237. ULONG BlockSize,
  1238. ULONG Alignment,
  1239. ULONG ExpansionCount,
  1240. ULONG Flags,
  1241. ULONG Tag
  1242. );
  1243. /*++
  1244. Routine Description:
  1245. This routine creates a memory block allocator. This routine must be called
  1246. at low level.
  1247. Arguments:
  1248. BlockSize - Supplies the size of allocations that this block allocator
  1249. doles out.
  1250. Alignment - Supplies the required address alignment, in bytes, for each
  1251. allocation. Valid values are powers of 2. Set to 1 or 0 to specify no
  1252. alignment requirement.
  1253. ExpansionCount - Supplies the number of blocks to expand the pool by when
  1254. out of free blocks.
  1255. Flags - Supplies a bitfield of flags governing the creation and behavior of
  1256. the block allocator. See BLOCK_ALLOCATOR_FLAG_* definitions.
  1257. Tag - Supplies an identifier to associate with the block allocations,
  1258. useful for debugging and leak detection.
  1259. Return Value:
  1260. Supplies an opaque pointer to the block allocator on success.
  1261. NULL on failure.
  1262. --*/
  1263. KERNEL_API
  1264. VOID
  1265. MmDestroyBlockAllocator (
  1266. PBLOCK_ALLOCATOR Allocator
  1267. );
  1268. /*++
  1269. Routine Description:
  1270. This routine destroys a block allocator, freeing all of its allocations
  1271. and releasing all memory associated with it.
  1272. Arguments:
  1273. Allocator - Supplies a pointer to the allocator to release.
  1274. Return Value:
  1275. None.
  1276. --*/
  1277. KERNEL_API
  1278. PVOID
  1279. MmAllocateBlock (
  1280. PBLOCK_ALLOCATOR Allocator,
  1281. PPHYSICAL_ADDRESS AllocationPhysicalAddress
  1282. );
  1283. /*++
  1284. Routine Description:
  1285. This routine attempts to allocate a block from the given block allocator.
  1286. Arguments:
  1287. Allocator - Supplies a pointer to the allocator to allocate the block of
  1288. memory from.
  1289. AllocationPhysicalAddress - Supplies an optional pointer where the physical
  1290. address of the allocation will be returned. If this parameter is
  1291. non-null, then the block allocator must have been created with the
  1292. physically contiguous flag. Otherwise blocks are not guaranteed to be
  1293. contiguous, making the starting physical address of a block meaningless.
  1294. Return Value:
  1295. Returns an allocation of fixed size (defined when the block allocator was
  1296. created) on success.
  1297. NULL on failure.
  1298. --*/
  1299. KERNEL_API
  1300. VOID
  1301. MmFreeBlock (
  1302. PBLOCK_ALLOCATOR Allocator,
  1303. PVOID Allocation
  1304. );
  1305. /*++
  1306. Routine Description:
  1307. This routine frees an allocated block back into the block allocator.
  1308. Arguments:
  1309. Allocator - Supplies a pointer to the allocator that originally doled out
  1310. the allocation.
  1311. Allocation - Supplies a pointer to the allocation to free.
  1312. Return Value:
  1313. None.
  1314. --*/
  1315. VOID
  1316. MmHandleFault (
  1317. ULONG FaultFlags,
  1318. PVOID FaultingAddress,
  1319. PTRAP_FRAME TrapFrame
  1320. );
  1321. /*++
  1322. Routine Description:
  1323. This routine handles access faults for the kernel.
  1324. Arguments:
  1325. FaultFlags - Supplies a bitfield of flags regarding the fault. See
  1326. FAULT_FLAG_* definitions.
  1327. FaultingAddress - Supplies the address that caused the page fault.
  1328. TrapFrame - Supplies a pointer to the state of the machine when the page
  1329. fault occurred.
  1330. Return Value:
  1331. None.
  1332. --*/
  1333. KSTATUS
  1334. MmGetMemoryStatistics (
  1335. PMM_STATISTICS Statistics
  1336. );
  1337. /*++
  1338. Routine Description:
  1339. This routine collects general memory statistics about the system as a whole.
  1340. This routine must be called at low level.
  1341. Arguments:
  1342. Statistics - Supplies a pointer where the statistics will be returned on
  1343. success. The caller should zero this buffer beforehand and set the
  1344. version member to MM_STATISTICS_VERSION. Failure to zero the structure
  1345. beforehand may result in uninitialized data when a driver built for a
  1346. newer OS is run on an older OS.
  1347. Return Value:
  1348. Status code.
  1349. --*/
  1350. PVOID
  1351. MmAllocateKernelStack (
  1352. UINTN Size
  1353. );
  1354. /*++
  1355. Routine Description:
  1356. This routine allocates memory to be used as a kernel stack.
  1357. Arguments:
  1358. Size - Supplies the size of the kernel stack to allocate, in bytes.
  1359. Return Value:
  1360. Returns a pointer to the base of the stack on success, or NULL on failure.
  1361. --*/
  1362. VOID
  1363. MmFreeKernelStack (
  1364. PVOID StackBase,
  1365. UINTN Size
  1366. );
  1367. /*++
  1368. Routine Description:
  1369. This routine frees a kernel stack.
  1370. Arguments:
  1371. StackBase - Supplies the base of the stack (the lowest address in the
  1372. allocation).
  1373. Size - Supplies the number of bytes allocated for the stack.
  1374. Return Value:
  1375. None.
  1376. --*/
  1377. VOID
  1378. MmMdInitDescriptorList (
  1379. PMEMORY_DESCRIPTOR_LIST Mdl,
  1380. MDL_ALLOCATION_SOURCE AllocationSource
  1381. );
  1382. /*++
  1383. Routine Description:
  1384. This routine initializes a memory descriptor list.
  1385. Arguments:
  1386. Mdl - Supplies a pointer to the MDL to initialize.
  1387. AllocationSource - Supplies the way that additional descriptors should be
  1388. allocated.
  1389. Return Value:
  1390. None.
  1391. --*/
  1392. VOID
  1393. MmMdDestroyDescriptorList (
  1394. PMEMORY_DESCRIPTOR_LIST Mdl
  1395. );
  1396. /*++
  1397. Routine Description:
  1398. This routine destroys a memory descriptor list. It frees all descriptors.
  1399. Arguments:
  1400. Mdl - Supplies a pointer to the MDL to destroy.
  1401. Return Value:
  1402. None.
  1403. --*/
  1404. VOID
  1405. MmMdInitDescriptor (
  1406. PMEMORY_DESCRIPTOR Descriptor,
  1407. ULONGLONG MinimumAddress,
  1408. ULONGLONG MaximumAddress,
  1409. MEMORY_TYPE Type
  1410. );
  1411. /*++
  1412. Routine Description:
  1413. This routine initializes a memory descriptor. Unaligned addresses are
  1414. expanded out to page boundaries.
  1415. Arguments:
  1416. Descriptor - Supplies a pointer to the uninitialized descriptor.
  1417. MinimumAddress - Supplies the base address of the descriptor.
  1418. MaximumAddress - Supplies the top address of the descriptor. This is the
  1419. first address NOT described by the descriptor.
  1420. Type - Supplies the memory type of the descriptor.
  1421. Return Value:
  1422. None.
  1423. --*/
  1424. KSTATUS
  1425. MmMdAddDescriptorToList (
  1426. PMEMORY_DESCRIPTOR_LIST Mdl,
  1427. PMEMORY_DESCRIPTOR NewDescriptor
  1428. );
  1429. /*++
  1430. Routine Description:
  1431. This routine adds the given descriptor to the descriptor list, regardless
  1432. of what other descriptors are currently describing that region. This
  1433. routine is useful for overriding regions described incorrectly by the
  1434. firmware.
  1435. Arguments:
  1436. Mdl - Supplies a pointer to the destination descriptor list the descriptor
  1437. should be added to.
  1438. NewDescriptor - Supplies a pointer to the descriptor to be added.
  1439. Return Value:
  1440. Status code.
  1441. --*/
  1442. PMEMORY_DESCRIPTOR
  1443. MmMdLookupDescriptor (
  1444. PMEMORY_DESCRIPTOR_LIST Mdl,
  1445. ULONGLONG StartAddress,
  1446. ULONGLONG EndAddress
  1447. );
  1448. /*++
  1449. Routine Description:
  1450. This routine finds the memory descriptor corresponding to the given address.
  1451. Arguments:
  1452. Mdl - Supplies a pointer to the descriptor list to search through.
  1453. StartAddress - Supplies the first valid address of the region being
  1454. queried for.
  1455. EndAddress - Supplies the first address beyond the region being queried.
  1456. In other words, the end address is not inclusive.
  1457. Return Value:
  1458. Returns a pointer to the descriptor that covers the given addres, or NULL
  1459. if the address is not described by the list.
  1460. --*/
  1461. PMEMORY_DESCRIPTOR
  1462. MmMdIsRangeFree (
  1463. PMEMORY_DESCRIPTOR_LIST Mdl,
  1464. ULONGLONG StartAddress,
  1465. ULONGLONG EndAddress
  1466. );
  1467. /*++
  1468. Routine Description:
  1469. This routine determines if the given memory range is marked as free.
  1470. Arguments:
  1471. Mdl - Supplies a pointer to the descriptor list to search through.
  1472. StartAddress - Supplies the first valid address of the region being
  1473. queried for.
  1474. EndAddress - Supplies the first address beyond the region being queried.
  1475. In other words, the end address is not inclusive.
  1476. Return Value:
  1477. Returns a pointer to the descriptor with the free memory type that covers
  1478. the given address range.
  1479. NULL if entire specified range is not free.
  1480. --*/
  1481. KSTATUS
  1482. MmMdRemoveRangeFromList (
  1483. PMEMORY_DESCRIPTOR_LIST Mdl,
  1484. ULONGLONG StartAddress,
  1485. ULONGLONG EndAddress
  1486. );
  1487. /*++
  1488. Routine Description:
  1489. This routine removes all descriptors from the given list that are within
  1490. the given memory range. Overlapping descriptors are truncated.
  1491. Arguments:
  1492. Mdl - Supplies a pointer to the descriptor list to remove from.
  1493. StartAddress - Supplies the first valid address of the region being removed.
  1494. EndAddress - Supplies the first address beyond the region being removed.
  1495. In other words, the end address is not inclusive.
  1496. Return Value:
  1497. Status code.
  1498. --*/
  1499. VOID
  1500. MmMdRemoveDescriptorFromList (
  1501. PMEMORY_DESCRIPTOR_LIST Mdl,
  1502. PMEMORY_DESCRIPTOR Descriptor
  1503. );
  1504. /*++
  1505. Routine Description:
  1506. This routine removes the given memory descriptor from the descriptor list.
  1507. Arguments:
  1508. Mdl - Supplies a pointer to the descriptor list to remove from.
  1509. Descriptor - Supplies a pointer to the descriptor to remove.
  1510. Return Value:
  1511. None.
  1512. --*/
  1513. VOID
  1514. MmMdPrintMdl (
  1515. PMEMORY_DESCRIPTOR_LIST Mdl
  1516. );
  1517. /*++
  1518. Routine Description:
  1519. This routine prints a memory descriptor list into a readable format.
  1520. Arguments:
  1521. Mdl - Supplies a pointer to the descriptor list to print.
  1522. Return Value:
  1523. None.
  1524. --*/
  1525. KSTATUS
  1526. MmMdAllocateFromMdl (
  1527. PMEMORY_DESCRIPTOR_LIST Mdl,
  1528. PULONGLONG Address,
  1529. ULONGLONG Size,
  1530. ULONG Alignment,
  1531. ULONGLONG Min,
  1532. ULONGLONG Max,
  1533. MEMORY_TYPE MemoryType,
  1534. ALLOCATION_STRATEGY Strategy
  1535. );
  1536. /*++
  1537. Routine Description:
  1538. This routine allocates a piece of free memory from the given descriptor
  1539. list, and marks it as the given type in the list.
  1540. Arguments:
  1541. Mdl - Supplies a pointer to the descriptor list to allocate memory from.
  1542. Address - Supplies a pointer to where the allocation will be returned.
  1543. Size - Supplies the size of the required space.
  1544. Alignment - Supplies the alignment requirement for the allocation, in bytes.
  1545. Valid values are powers of 2. Set to 1 or 0 to specify no alignment
  1546. requirement.
  1547. Min - Supplies the minimum address to allocate.
  1548. Max - Supplies the maximum address to allocate.
  1549. MemoryType - Supplies the type of memory to mark the allocation as.
  1550. Strategy - Supplies the memory allocation strategy for this allocation.
  1551. Return Value:
  1552. STATUS_SUCCESS if the allocation was successful.
  1553. STATUS_INVALID_PARAMETER if a page count of 0 was passed or the address
  1554. parameter was not filled out.
  1555. STATUS_NO_MEMORY if the allocation request could not be filled.
  1556. --*/
  1557. KSTATUS
  1558. MmMdAllocateMultiple (
  1559. PMEMORY_DESCRIPTOR_LIST Mdl,
  1560. ULONGLONG Size,
  1561. ULONGLONG Count,
  1562. MEMORY_TYPE MemoryType,
  1563. PUINTN Addresses
  1564. );
  1565. /*++
  1566. Routine Description:
  1567. This routine allocates multiple native sized addresses from an MDL in a
  1568. single pass.
  1569. Arguments:
  1570. Mdl - Supplies a pointer to the descriptor list to allocate memory from.
  1571. Size - Supplies the required size of each individual allocation. This must
  1572. be a power of two. This is also assumed to be the alignment requirement.
  1573. Count - Supplies the number of allocations required.
  1574. MemoryType - Supplies the type of memory to mark the allocation as.
  1575. Addresses - Supplies a pointer where the addresses will be returned on
  1576. success.
  1577. Return Value:
  1578. STATUS_SUCCESS if the allocation was successful.
  1579. STATUS_NO_MEMORY if the allocation request could not be filled.
  1580. --*/
  1581. VOID
  1582. MmMdAddFreeDescriptorsToMdl (
  1583. PMEMORY_DESCRIPTOR_LIST Mdl,
  1584. PMEMORY_DESCRIPTOR NewDescriptor,
  1585. ULONG Size
  1586. );
  1587. /*++
  1588. Routine Description:
  1589. This routine adds new free descriptors to the given memory descriptor list.
  1590. Arguments:
  1591. Mdl - Supplies a pointer to the descriptor list to add free descriptors to.
  1592. NewDescriptor - Supplies an array of new descriptors.
  1593. Size - Supplies the size of the descriptor array, in bytes.
  1594. Return Value:
  1595. None.
  1596. --*/
  1597. VOID
  1598. MmMdIterate (
  1599. PMEMORY_DESCRIPTOR_LIST DescriptorList,
  1600. PMEMORY_DESCRIPTOR_LIST_ITERATION_ROUTINE IterationRoutine,
  1601. PVOID Context
  1602. );
  1603. /*++
  1604. Routine Description:
  1605. This routine iterates over all the descriptors in the given list, calling
  1606. the iteration routine for each one.
  1607. Arguments:
  1608. DescriptorList - Supplies a pointer to the list to iterate over.
  1609. IterationRoutine - Supplies a pointer to the routine to call for each
  1610. descriptor in the list.
  1611. Context - Supplies an optional opaque context passed to the iteration
  1612. routine.
  1613. Return Value:
  1614. None.
  1615. --*/
  1616. INTN
  1617. MmSysMapOrUnmapMemory (
  1618. PVOID SystemCallParameter
  1619. );
  1620. /*++
  1621. Routine Description:
  1622. This routine responds to system calls from user mode requesting to map a
  1623. file object or unmap a region of the current process' address space.
  1624. Arguments:
  1625. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1626. the system call. This structure will be a stack-local copy of the
  1627. actual parameters passed from user-mode.
  1628. Return Value:
  1629. STATUS_SUCCESS or positive integer on success.
  1630. Error status code on failure.
  1631. --*/
  1632. INTN
  1633. MmSysSetMemoryProtection (
  1634. PVOID SystemCallParameter
  1635. );
  1636. /*++
  1637. Routine Description:
  1638. This routine responds to system calls from user mode requesting to change
  1639. memory region attributes.
  1640. Arguments:
  1641. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1642. the system call. This structure will be a stack-local copy of the
  1643. actual parameters passed from user-mode.
  1644. Return Value:
  1645. STATUS_SUCCESS or positive integer on success.
  1646. Error status code on failure.
  1647. --*/
  1648. INTN
  1649. MmSysFlushMemory (
  1650. PVOID SystemCallParameter
  1651. );
  1652. /*++
  1653. Routine Description:
  1654. This routine responds to system calls from user mode requesting to flush a
  1655. region of memory in the current process' to permanent storage.
  1656. Arguments:
  1657. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1658. the system call. This structure will be a stack-local copy of the
  1659. actual parameters passed from user-mode.
  1660. Return Value:
  1661. STATUS_SUCCESS or positive integer on success.
  1662. Error status code on failure.
  1663. --*/
  1664. INTN
  1665. MmSysSetBreak (
  1666. PVOID SystemCallParameter
  1667. );
  1668. /*++
  1669. Routine Description:
  1670. This routine implements the system call for getting or modifying the
  1671. program break.
  1672. Arguments:
  1673. SystemCallParameter - Supplies a pointer to the parameters supplied with
  1674. the system call. This structure will be a stack-local copy of the
  1675. actual parameters passed from user-mode.
  1676. Return Value:
  1677. STATUS_SUCCESS or positive integer on success.
  1678. Error status code on failure.
  1679. --*/
  1680. KSTATUS
  1681. MmCreateCopyOfUserModeString (
  1682. PSTR UserModeString,
  1683. ULONG UserModeStringBufferLength,
  1684. ULONG AllocationTag,
  1685. PSTR *CreatedCopy
  1686. );
  1687. /*++
  1688. Routine Description:
  1689. This routine is a convenience method that captures a string from user mode
  1690. and creates a paged-pool copy in kernel mode. The caller can be sure that
  1691. the string pointer was properly sanitized and the resulting buffer is null
  1692. terminated. The caller is responsible for freeing the memory returned by
  1693. this function on success.
  1694. Arguments:
  1695. UserModeString - Supplies the user mode pointer to the string.
  1696. UserModeStringBufferLength - Supplies the size of the buffer containing the
  1697. user mode string.
  1698. AllocationTag - Supplies the allocation tag that should be used when
  1699. creating the kernel buffer.
  1700. CreatedCopy - Supplies a pointer where the paged pool allocation will be
  1701. returned.
  1702. Return Value:
  1703. Status code.
  1704. --*/
  1705. KERNEL_API
  1706. KSTATUS
  1707. MmCopyFromUserMode (
  1708. PVOID KernelModePointer,
  1709. PVOID UserModePointer,
  1710. UINTN Size
  1711. );
  1712. /*++
  1713. Routine Description:
  1714. This routine copies memory from user mode to kernel mode.
  1715. Arguments:
  1716. KernelModePointer - Supplies the kernel mode pointer, the destination of
  1717. the copy.
  1718. UserModePointer - Supplies the untrusted user mode pointer, the source of
  1719. the copy.
  1720. Size - Supplies the number of bytes to copy.
  1721. Return Value:
  1722. STATUS_SUCCESS on success.
  1723. STATUS_ACCESS_VIOLATION if the user mode memory is invalid or corrupt.
  1724. --*/
  1725. KERNEL_API
  1726. KSTATUS
  1727. MmCopyToUserMode (
  1728. PVOID UserModePointer,
  1729. PVOID KernelModePointer,
  1730. UINTN Size
  1731. );
  1732. /*++
  1733. Routine Description:
  1734. This routine copies memory to user mode from kernel mode.
  1735. Arguments:
  1736. UserModePointer - Supplies the untrusted user mode pointer, the destination
  1737. of the copy.
  1738. KernelModePointer - Supplies the kernel mode pointer, the source of the
  1739. copy.
  1740. Size - Supplies the number of bytes to copy.
  1741. Return Value:
  1742. STATUS_SUCCESS on success.
  1743. STATUS_ACCESS_VIOLATION if the user mode memory is invalid or corrupt.
  1744. --*/
  1745. KERNEL_API
  1746. KSTATUS
  1747. MmTouchUserModeBuffer (
  1748. PVOID Buffer,
  1749. UINTN Size,
  1750. BOOL Write
  1751. );
  1752. /*++
  1753. Routine Description:
  1754. This routine touches a user mode buffer, validating it either for reading
  1755. or writing. Note that the caller must also have the process VA space
  1756. locked, or else this data is immediately stale.
  1757. Arguments:
  1758. Buffer - Supplies a pointer to the buffer to probe.
  1759. Size - Supplies the number of bytes to copy.
  1760. Write - Supplies a boolean indicating whether to probe the memory for
  1761. reading or writing.
  1762. Return Value:
  1763. STATUS_SUCCESS on success.
  1764. STATUS_ACCESS_VIOLATION if the user mode memory is invalid.
  1765. --*/
  1766. BOOL
  1767. MmUserRead16 (
  1768. PVOID Buffer,
  1769. PUSHORT Value
  1770. );
  1771. /*++
  1772. Routine Description:
  1773. This routine performs a 16-bit read from user mode. This is assumed to be
  1774. two-byte aligned.
  1775. Arguments:
  1776. Buffer - Supplies a pointer to the buffer to read.
  1777. Value - Supplies a pointer where the read value will be returned.
  1778. Return Value:
  1779. TRUE if the read succeeded.
  1780. FALSE if the read failed.
  1781. --*/
  1782. BOOL
  1783. MmUserWrite16 (
  1784. PVOID Buffer,
  1785. USHORT Value
  1786. );
  1787. /*++
  1788. Routine Description:
  1789. This routine performs a 16-bit write to user mode. This is assumed to be
  1790. two-byte aligned.
  1791. Arguments:
  1792. Buffer - Supplies a pointer to the buffer to write to.
  1793. Value - Supplies the value to write.
  1794. Return Value:
  1795. TRUE if the write succeeded.
  1796. FALSE if the write failed.
  1797. --*/
  1798. BOOL
  1799. MmUserRead32 (
  1800. PVOID Buffer,
  1801. PULONG Value
  1802. );
  1803. /*++
  1804. Routine Description:
  1805. This routine performs a 32-bit read from user mode. This is assumed to be
  1806. naturally aligned.
  1807. Arguments:
  1808. Buffer - Supplies a pointer to the buffer to read.
  1809. Value - Supplies a pointer where the read value will be returned.
  1810. Return Value:
  1811. TRUE if the read succeeded.
  1812. FALSE if the read failed.
  1813. --*/
  1814. BOOL
  1815. MmUserWrite32 (
  1816. PVOID Buffer,
  1817. ULONG Value
  1818. );
  1819. /*++
  1820. Routine Description:
  1821. This routine performs a 32-bit write to user mode. This is assumed to be
  1822. naturally aligned.
  1823. Arguments:
  1824. Buffer - Supplies a pointer to the buffer to write to.
  1825. Value - Supplies the value to write.
  1826. Return Value:
  1827. TRUE if the write succeeded.
  1828. FALSE if the write failed.
  1829. --*/
  1830. PMEMORY_RESERVATION
  1831. MmCreateMemoryReservation (
  1832. PVOID PreferredVirtualAddress,
  1833. UINTN Size,
  1834. PVOID Min,
  1835. PVOID Max,
  1836. ALLOCATION_STRATEGY FallbackStrategy,
  1837. BOOL KernelMode
  1838. );
  1839. /*++
  1840. Routine Description:
  1841. This routine creates a virtual address reservation for the current process.
  1842. Arguments:
  1843. PreferredVirtualAddress - Supplies the preferred virtual address of the
  1844. reservation. Supply NULL to indicate no preference.
  1845. Size - Supplies the size of the requested reservation, in bytes.
  1846. Min - Supplies the minimum virtual address to allocate.
  1847. Max - Supplies the maximum virtual address to allocate.
  1848. FallbackStrategy - Supplies the fallback memory allocation strategy in
  1849. case the preferred address isn't available (or wasn't supplied).
  1850. KernelMode - Supplies a boolean indicating whether the VA reservation must
  1851. be in kernel mode (TRUE) or user mode (FALSE).
  1852. Return Value:
  1853. Returns a pointer to the reservation structure on success.
  1854. NULL on failure.
  1855. --*/
  1856. VOID
  1857. MmFreeMemoryReservation (
  1858. PMEMORY_RESERVATION Reservation
  1859. );
  1860. /*++
  1861. Routine Description:
  1862. This routine destroys a memory reservation. All memory must be unmapped
  1863. and freed prior to this call.
  1864. Arguments:
  1865. Reservation - Supplies a pointer to the reservation structure returned when
  1866. the reservation was made.
  1867. Return Value:
  1868. None.
  1869. --*/
  1870. KSTATUS
  1871. MmInitializeMemoryAccounting (
  1872. PMEMORY_ACCOUNTING Accountant,
  1873. ULONG Flags
  1874. );
  1875. /*++
  1876. Routine Description:
  1877. This routine initializes a memory accounting structure.
  1878. Arguments:
  1879. Accountant - Supplies a pointer to the memory accounting structure to
  1880. initialize.
  1881. Flags - Supplies flags to control the behavior of the accounting. See the
  1882. MEMORY_ACCOUNTING_FLAG_* definitions for valid flags.
  1883. Return Value:
  1884. STATUS_SUCCESS on success.
  1885. STATUS_INVALID_PARAMETER if an invalid flag was passed.
  1886. --*/
  1887. KSTATUS
  1888. MmReinitializeUserAccounting (
  1889. PMEMORY_ACCOUNTING Accountant
  1890. );
  1891. /*++
  1892. Routine Description:
  1893. This routine resets the memory reservations on a user memory accounting
  1894. structure to those of a clean process.
  1895. Arguments:
  1896. Accountant - Supplies a pointer to the memory accounting structure to
  1897. initialize.
  1898. Return Value:
  1899. STATUS_SUCCESS on success.
  1900. STATUS_INVALID_PARAMETER if an invalid flag was passed.
  1901. --*/
  1902. VOID
  1903. MmDestroyMemoryAccounting (
  1904. PMEMORY_ACCOUNTING Accountant
  1905. );
  1906. /*++
  1907. Routine Description:
  1908. This routine destroys a memory accounting structure, freeing all memory
  1909. associated with it (except the MEMORY_ACCOUNTING structure itself, which
  1910. was provided to the initialize function separately).
  1911. Arguments:
  1912. Accountant - Supplies a pointer to the memory accounting structure to
  1913. destroy.
  1914. Return Value:
  1915. None.
  1916. --*/
  1917. KSTATUS
  1918. MmCloneAddressSpace (
  1919. PADDRESS_SPACE Source,
  1920. PADDRESS_SPACE Destination
  1921. );
  1922. /*++
  1923. Routine Description:
  1924. This routine makes a clone of one process' entire address space into
  1925. another process. The copy is not shared memory, the destination segments
  1926. are marked copy on write. This includes copying the mapping for the user
  1927. shared data page.
  1928. Arguments:
  1929. Source - Supplies a pointer to the source address space to copy.
  1930. Destination - Supplies a pointer to the newly created destination to copy
  1931. the sections to.
  1932. Return Value:
  1933. Status code.
  1934. --*/
  1935. VOID
  1936. MmIdentityMapStartupStub (
  1937. ULONG PageCount,
  1938. PVOID *Allocation,
  1939. PVOID *PageDirectory
  1940. );
  1941. /*++
  1942. Routine Description:
  1943. This routine allocates and identity maps pages for use by application
  1944. processor startup code.
  1945. Arguments:
  1946. PageCount - Supplies the number of pages to allocate and map.
  1947. Allocation - Supplies a pointer where the virtual/physical address will
  1948. be returned on success.
  1949. PageDirectory - Supplies a pointer where the current page directory will be
  1950. returned.
  1951. Return Value:
  1952. None.
  1953. --*/
  1954. VOID
  1955. MmUnmapStartupStub (
  1956. PVOID Allocation,
  1957. ULONG PageCount
  1958. );
  1959. /*++
  1960. Routine Description:
  1961. This routine unmaps memory allocated and identity mapped for use by the
  1962. AP startup stub.
  1963. Arguments:
  1964. Allocation - Supplies the allocation.
  1965. PageCount - Supplies the number of pages in the allocation.
  1966. Return Value:
  1967. None.
  1968. --*/
  1969. VOID
  1970. MmUpdatePageDirectory (
  1971. PADDRESS_SPACE AddressSpace,
  1972. PVOID VirtualAddress,
  1973. UINTN Size
  1974. );
  1975. /*++
  1976. Routine Description:
  1977. This routine updates the kernel mode entries in the given page directory
  1978. for the given virtual address range so that they're current.
  1979. Arguments:
  1980. AddressSpace - Supplies a pointer to the address space.
  1981. VirtualAddress - Supplies the base virtual address of the range to be
  1982. synchronized.
  1983. Size - Supplies the size of the virtual address range to synchronize.
  1984. Return Value:
  1985. None.
  1986. --*/
  1987. ULONG
  1988. MmValidateMemoryAccessForDebugger (
  1989. PVOID Address,
  1990. ULONG Length,
  1991. PBOOL Writable
  1992. );
  1993. /*++
  1994. Routine Description:
  1995. This routine validates that access to a specified location in memory will
  1996. not cause a page fault. It is intended to be called only by the debugger.
  1997. Arguments:
  1998. Address - Supplies the virtual address of the memory that will be read or
  1999. written.
  2000. Length - Supplies how many bytes at that location the caller would like to
  2001. read or write.
  2002. Writable - Supplies an optional pointer that receives a boolean indicating
  2003. whether or not the memory range is mapped writable.
  2004. Return Value:
  2005. Returns the number of bytes from the beginning of the address that are
  2006. accessible. If the memory is completely available, the return value will be
  2007. equal to the Length parameter. If the memory is completely paged out, 0
  2008. will be returned.
  2009. --*/
  2010. VOID
  2011. MmModifyAddressMappingForDebugger (
  2012. PVOID Address,
  2013. BOOL Writable,
  2014. PBOOL WasWritable
  2015. );
  2016. /*++
  2017. Routine Description:
  2018. This routine modifies the mapping properties for the page that contains the
  2019. given address.
  2020. Arguments:
  2021. Address - Supplies the virtual address of the memory whose mapping
  2022. properties are to be changed.
  2023. Writable - Supplies a boolean indicating whether or not to make the page
  2024. containing the address writable (TRUE) or read-only (FALSE).
  2025. WasWritable - Supplies a pointer that receives a boolean indicating whether
  2026. or not the page was writable (TRUE) or read-only (FALSE) before any
  2027. modifications.
  2028. Return Value:
  2029. None.
  2030. --*/
  2031. VOID
  2032. MmSwitchAddressSpace (
  2033. PVOID Processor,
  2034. PVOID CurrentStack,
  2035. PADDRESS_SPACE AddressSpace
  2036. );
  2037. /*++
  2038. Routine Description:
  2039. This routine switches to the given address space.
  2040. Arguments:
  2041. Processor - Supplies a pointer to the current processor block.
  2042. CurrentStack - Supplies the address of the current thread's kernel stack.
  2043. This routine will ensure this address is visible in the address space
  2044. being switched to. Stacks must not cross page directory boundaries.
  2045. AddressSpace - Supplies a pointer to the address space to switch to.
  2046. Return Value:
  2047. None.
  2048. --*/
  2049. VOID
  2050. MmVolumeArrival (
  2051. PSTR VolumeName,
  2052. ULONG VolumeNameLength,
  2053. BOOL SystemVolume
  2054. );
  2055. /*++
  2056. Routine Description:
  2057. This routine implements the memory manager's response to a new volume in
  2058. the system.
  2059. Arguments:
  2060. VolumeName - Supplies the full path to the new volume.
  2061. VolumeNameLength - Supplies the length of the volume name buffer, including
  2062. the null terminator, in bytes.
  2063. SystemVolume - Supplies a boolean indicating if this is the system volume
  2064. or not.
  2065. Return Value:
  2066. None.
  2067. --*/
  2068. BOOL
  2069. MmRequestPagingOut (
  2070. ULONGLONG FreePageTarget
  2071. );
  2072. /*++
  2073. Routine Description:
  2074. This routine schedules the backgroung paging thread to run, hopefully
  2075. freeing up some memory. This must be called at low level. This routine is
  2076. asynchronous, it will signal the paging thread and return immediately. The
  2077. request may be ignored or coalesced with other paging out requests.
  2078. Arguments:
  2079. FreePageTarget - Supplies the target number of free physical pages the
  2080. caller would like to see in the system.
  2081. Return Value:
  2082. Returns TRUE if a request was submitted or FALSE otherwise (e.g. paging is
  2083. not enabled).
  2084. --*/
  2085. KSTATUS
  2086. MmVolumeRemoval (
  2087. PVOID Device
  2088. );
  2089. /*++
  2090. Routine Description:
  2091. This routine implements the memory manager's response to a volume being
  2092. removed from the system.
  2093. Arguments:
  2094. Device - Supplies a pointer to the device (volume) being removed.
  2095. Return Value:
  2096. Status code.
  2097. --*/
  2098. KSTATUS
  2099. MmMapFileSection (
  2100. HANDLE FileHandle,
  2101. IO_OFFSET FileOffset,
  2102. PVM_ALLOCATION_PARAMETERS VaRequest,
  2103. ULONG Flags,
  2104. BOOL KernelSpace,
  2105. PMEMORY_RESERVATION Reservation
  2106. );
  2107. /*++
  2108. Routine Description:
  2109. This routine maps a file or a portion of a file into virtual memory space
  2110. of the current process. This routine must be called below dispatch level.
  2111. Arguments:
  2112. FileHandle - Supplies the open file handle.
  2113. FileOffset - Supplies the offset, in bytes, from the start of the file
  2114. where the mapping should begin.
  2115. VaRequest - Supplies a pointer to the virtual address allocation
  2116. parameters. If the supplied size is zero, then this routine will
  2117. attempt to map until the end of the file. The alignment will be set
  2118. to a page size, and the memory type will be set to reserved.
  2119. Flags - Supplies flags governing the mapping of the section. See
  2120. IMAGE_SECTION_* definitions.
  2121. KernelSpace - Supplies a boolean indicating whether to map the section in
  2122. kernel space or user space.
  2123. Reservation - Supplies an optional pointer to a memory reservation for the
  2124. desired mapping. A reservation is required only if several mappings
  2125. need to be allocated in the same range together for any one mapping to
  2126. be useful.
  2127. Return Value:
  2128. Status code.
  2129. --*/
  2130. KSTATUS
  2131. MmUnmapFileSection (
  2132. PVOID Process,
  2133. PVOID FileMapping,
  2134. UINTN Size,
  2135. PMEMORY_RESERVATION Reservation
  2136. );
  2137. /*++
  2138. Routine Description:
  2139. This routine unmaps a file section. This routine must be called at low
  2140. level. For kernel mode, this must specify a single whole image section.
  2141. Arguments:
  2142. Process - Supplies a pointer to the process containing the section to
  2143. unmap. Supply NULL to unmap from the current process.
  2144. FileMapping - Supplies a pointer to the file mapping.
  2145. Size - Supplies the size in bytes of the region to unmap.
  2146. Reservation - Supplies an optional pointer to the reservation that the
  2147. section was mapped under. If the mapping was not done under a
  2148. memory reservation, supply NULL. If the mapping was done under a
  2149. memory reservation, that reservation MUST be supplied here.
  2150. Return Value:
  2151. Status code.
  2152. --*/
  2153. VOID
  2154. MmCleanUpProcessMemory (
  2155. PVOID ExitedProcess
  2156. );
  2157. /*++
  2158. Routine Description:
  2159. This routine cleans up any leftover allocations made under the given
  2160. process.
  2161. Arguments:
  2162. ExitedProcess - Supplies a pointer to the process to clean up.
  2163. Return Value:
  2164. None.
  2165. --*/
  2166. KSTATUS
  2167. MmMapUserSharedData (
  2168. PADDRESS_SPACE AddressSpace
  2169. );
  2170. /*++
  2171. Routine Description:
  2172. This routine maps the user shared data at a fixed address in a new
  2173. process' address space.
  2174. Arguments:
  2175. AddressSpace - Supplies the address space to map the user shared data page
  2176. into.
  2177. Return Value:
  2178. Status code.
  2179. --*/
  2180. PVOID
  2181. MmGetUserSharedData (
  2182. VOID
  2183. );
  2184. /*++
  2185. Routine Description:
  2186. This routine returns the kernel virtual address of the user shared data
  2187. area.
  2188. Arguments:
  2189. None.
  2190. Return Value:
  2191. The kernel mode address of the user shared data page.
  2192. --*/
  2193. PADDRESS_SPACE
  2194. MmCreateAddressSpace (
  2195. VOID
  2196. );
  2197. /*++
  2198. Routine Description:
  2199. This routine creates a new address space context. This routine allocates
  2200. the structure, zeros at least the common portion, and initializes any
  2201. architecture specific members after the common potion.
  2202. Arguments:
  2203. None.
  2204. Return Value:
  2205. Returns a pointer to the new address space on success.
  2206. NULL on allocation failure.
  2207. --*/
  2208. VOID
  2209. MmDestroyAddressSpace (
  2210. PADDRESS_SPACE AddressSpace
  2211. );
  2212. /*++
  2213. Routine Description:
  2214. This routine destroys an address space, freeing this structure and all
  2215. architecture-specific content. The common portion of the structure will
  2216. already have been taken care of.
  2217. Arguments:
  2218. AddressSpace - Supplies a pointer to the address space to destroy.
  2219. Return Value:
  2220. None.
  2221. --*/
  2222. PIMAGE_SECTION_LIST
  2223. MmCreateImageSectionList (
  2224. VOID
  2225. );
  2226. /*++
  2227. Routine Description:
  2228. This routine creates an image section list.
  2229. Arguments:
  2230. None.
  2231. Return Value:
  2232. Returns a pointer to the new image section list.
  2233. --*/
  2234. VOID
  2235. MmDestroyImageSectionList (
  2236. PIMAGE_SECTION_LIST ImageSectionList
  2237. );
  2238. /*++
  2239. Routine Description:
  2240. This routine destroys an image section list.
  2241. Arguments:
  2242. ImageSectionList - Supplies a pointer to the image section list to destroy.
  2243. Return Value:
  2244. None.
  2245. --*/
  2246. KSTATUS
  2247. MmUnmapImageSectionList (
  2248. PIMAGE_SECTION_LIST ImageSectionList,
  2249. IO_OFFSET Offset,
  2250. ULONGLONG Size,
  2251. ULONG Flags,
  2252. PBOOL PageWasDirty
  2253. );
  2254. /*++
  2255. Routine Description:
  2256. This routine unmaps all pages in each image section in the given image
  2257. section list starting at the given offset and for the supplied size.
  2258. Arguments:
  2259. ImageSectionList - Supplies a pointer to an image section list.
  2260. Offset - Supplies the start offset beyond which all mappings in each image
  2261. section will be unmapped. The offset should be page aligned.
  2262. Size - Supplies the size of the region to unmap, in bytes. The size should
  2263. be page aligned.
  2264. Flags - Supplies a bitmask of flags for the unmap. See
  2265. IMAGE_SECTION_UNMAP_FLAG_* for definitions.
  2266. PageWasDirty - Supplies a pointer where a boolean will be returned
  2267. indicating if any page that was unmapped was dirty. This parameter is
  2268. optional.
  2269. Return Value:
  2270. Status code.
  2271. --*/
  2272. KSTATUS
  2273. MmChangeImageSectionRegionAccess (
  2274. PVOID Address,
  2275. UINTN Size,
  2276. ULONG NewAccess
  2277. );
  2278. /*++
  2279. Routine Description:
  2280. This routine sets the memory region protection for the given address range.
  2281. Arguments:
  2282. Address - Supplies the starting address of the region to change.
  2283. Size - Supplies the size of the region to change.
  2284. NewAccess - Supplies the new access permissions to set. See IMAGE_SECTION_*
  2285. definitions. Only the read, write, and execute flags can be changed.
  2286. Return Value:
  2287. Status code.
  2288. --*/
  2289. PVOID
  2290. MmGetObjectForAddress (
  2291. PVOID Address,
  2292. PUINTN Offset,
  2293. PBOOL Shared
  2294. );
  2295. /*++
  2296. Routine Description:
  2297. This routine returns a pointer to the object backing the memory at the
  2298. given user mode address. This is an opaque object with an increased
  2299. reference count on it.
  2300. Arguments:
  2301. Address - Supplies the user mode address to look up.
  2302. Offset - Supplies a pointer where the offset in bytes from the base of the
  2303. object's virtual region will be returned.
  2304. Shared - Supplies a pointer indicating whether the memory is a shared file
  2305. mapping (TRUE) or either a private file mapping or just general
  2306. memory (FALSE).
  2307. Return Value:
  2308. Returns a pointer to the object that owns this user mode address for the
  2309. current process. The caller must release the reference held on this object.
  2310. NULL if the address passed in is invalid or not mapped.
  2311. --*/
  2312. VOID
  2313. MmReleaseObjectReference (
  2314. PVOID Object,
  2315. BOOL Shared
  2316. );
  2317. /*++
  2318. Routine Description:
  2319. This routine releases the reference acquired by getting the object for a
  2320. user mode address.
  2321. Arguments:
  2322. Object - Supplies a pointer to the object returned when the address was
  2323. looked up.
  2324. Shared - Supplies the shared boolean that was returned when the address was
  2325. looked up. This is needed to know how to release the object.
  2326. Return Value:
  2327. None.
  2328. --*/
  2329. KSTATUS
  2330. MmUserModeDebuggerWrite (
  2331. PVOID KernelBuffer,
  2332. PVOID UserDestination,
  2333. UINTN Size
  2334. );
  2335. /*++
  2336. Routine Description:
  2337. This routine performs a user mode debugger write to the current
  2338. process memory. This routine may convert a read-only image section it
  2339. finds to a writable section.
  2340. Arguments:
  2341. KernelBuffer - Supplies a pointer to the kernel-mode buffer containing
  2342. the data to write.
  2343. UserDestination - Supplies the destination buffer where the contents
  2344. should be written.
  2345. Size - Supplies the number of bytes to write.
  2346. Return Value:
  2347. STATUS_SUCCESS on success.
  2348. STATUS_ACCESS_VIOLATION if the buffer is not valid.
  2349. STATUS_ACCESS_DENIED if an attempt was made to write to a read-only
  2350. shared section.
  2351. --*/
  2352. KERNEL_API
  2353. PVOID
  2354. MmGetPhysicalMemoryWarningEvent (
  2355. VOID
  2356. );
  2357. /*++
  2358. Routine Description:
  2359. This routine returns the memory manager's physical memory warning event.
  2360. This event is signaled whenever there is a change in physical memory's
  2361. warning level.
  2362. Arguments:
  2363. None.
  2364. Return Value:
  2365. Returns a pointer to the physical memory warning event.
  2366. --*/
  2367. KERNEL_API
  2368. MEMORY_WARNING_LEVEL
  2369. MmGetPhysicalMemoryWarningLevel (
  2370. VOID
  2371. );
  2372. /*++
  2373. Routine Description:
  2374. This routine returns the current physical memory warning level.
  2375. Arguments:
  2376. None.
  2377. Return Value:
  2378. Returns the current physical memory warning level.
  2379. --*/
  2380. UINTN
  2381. MmGetTotalPhysicalPages (
  2382. VOID
  2383. );
  2384. /*++
  2385. Routine Description:
  2386. This routine gets the total physical pages in the system.
  2387. Arguments:
  2388. None.
  2389. Return Value:
  2390. Returns the total number of physical pages present in the system.
  2391. --*/
  2392. UINTN
  2393. MmGetTotalFreePhysicalPages (
  2394. VOID
  2395. );
  2396. /*++
  2397. Routine Description:
  2398. This routine returns the total number of free physical pages in the system.
  2399. Arguments:
  2400. None.
  2401. Return Value:
  2402. Returns the total number of free physical pages in the system.
  2403. --*/
  2404. VOID
  2405. MmFreePhysicalPages (
  2406. PHYSICAL_ADDRESS PhysicalAddress,
  2407. ULONGLONG PageCount
  2408. );
  2409. /*++
  2410. Routine Description:
  2411. This routine frees a contiguous run of physical memory pages, making the
  2412. pages available to the system again.
  2413. Arguments:
  2414. PhysicalAddress - Supplies the base physical address of the pages to free.
  2415. PageCount - Supplies the number of contiguous physical pages to free.
  2416. Return Value:
  2417. None.
  2418. --*/
  2419. VOID
  2420. MmSetPageCacheEntryForPhysicalAddress (
  2421. PHYSICAL_ADDRESS PhysicalAddress,
  2422. PVOID PageCacheEntry
  2423. );
  2424. /*++
  2425. Routine Description:
  2426. This routine sets the page cache entry for the given physical address.
  2427. Arguments:
  2428. PhysicalAddress - Supplies the address of the physical page whose page
  2429. cache entry is to be set.
  2430. PageCacheEntry - Supplies a pointer to the page cache entry to be set for
  2431. the given physical page.
  2432. Return Value:
  2433. None.
  2434. --*/
  2435. KERNEL_API
  2436. KSTATUS
  2437. MmFlushBufferForDataIn (
  2438. PVOID Buffer,
  2439. UINTN SizeInBytes
  2440. );
  2441. /*++
  2442. Routine Description:
  2443. This routine flushes a buffer in preparation for incoming I/O from a device.
  2444. Arguments:
  2445. Buffer - Supplies the virtual address of the buffer to flush. This buffer
  2446. must be cache-line aligned.
  2447. SizeInBytes - Supplies the size of the buffer to flush, in bytes. This
  2448. size must also be cache-line aligned.
  2449. Return Value:
  2450. STATUS_SUCCESS on success.
  2451. STATUS_ACCESS_VIOLATION if the region was user mode and an address in the
  2452. region was not valid. Kernel mode addresses are always expected to be
  2453. valid.
  2454. --*/
  2455. KERNEL_API
  2456. KSTATUS
  2457. MmFlushBufferForDataOut (
  2458. PVOID Buffer,
  2459. UINTN SizeInBytes
  2460. );
  2461. /*++
  2462. Routine Description:
  2463. This routine flushes a buffer in preparation for outgoing I/O to a device.
  2464. Arguments:
  2465. Buffer - Supplies the virtual address of the buffer to flush. This buffer
  2466. must be cache-line aligned.
  2467. SizeInBytes - Supplies the size of the buffer to flush, in bytes. This
  2468. size must also be cache-line aligned.
  2469. Return Value:
  2470. STATUS_SUCCESS on success.
  2471. STATUS_ACCESS_VIOLATION if the region was user mode and an address in the
  2472. region was not valid. Kernel mode addresses are always expected to be
  2473. valid.
  2474. --*/
  2475. KERNEL_API
  2476. KSTATUS
  2477. MmFlushBufferForDataIo (
  2478. PVOID Buffer,
  2479. UINTN SizeInBytes
  2480. );
  2481. /*++
  2482. Routine Description:
  2483. This routine flushes a buffer in preparation for data that is both
  2484. incoming and outgoing (ie the buffer is read from and written to by an
  2485. external device).
  2486. Arguments:
  2487. Buffer - Supplies the virtual address of the buffer to flush. This buffer
  2488. must be cache-line aligned.
  2489. SizeInBytes - Supplies the size of the buffer to flush, in bytes. This
  2490. size must also be cache-line aligned.
  2491. Return Value:
  2492. STATUS_SUCCESS on success.
  2493. STATUS_ACCESS_VIOLATION if the region was user mode and an address in the
  2494. region was not valid. Kernel mode addresses are always expected to be
  2495. valid.
  2496. --*/
  2497. KERNEL_API
  2498. KSTATUS
  2499. MmSyncCacheRegion (
  2500. PVOID Address,
  2501. UINTN Size
  2502. );
  2503. /*++
  2504. Routine Description:
  2505. This routine unifies the instruction and data caches for the given region,
  2506. probably after a region of executable code was modified. This does not
  2507. necessarily flush data to the point where it's observable to device DMA
  2508. (called the point of coherency).
  2509. Arguments:
  2510. Address - Supplies the address to flush.
  2511. Size - Supplies the number of bytes in the region to flush.
  2512. Return Value:
  2513. STATUS_SUCCESS on success.
  2514. STATUS_ACCESS_VIOLATION if one of the addresses in the given range was not
  2515. valid.
  2516. --*/
  2517. INTN
  2518. MmSysFlushCache (
  2519. PVOID SystemCallParameter
  2520. );
  2521. /*++
  2522. Routine Description:
  2523. This routine responds to system calls from user mode requesting to
  2524. invalidate the instruction cache after changing a code region.
  2525. Arguments:
  2526. SystemCallParameter - Supplies a pointer to the parameters supplied with
  2527. the system call. This structure will be a stack-local copy of the
  2528. actual parameters passed from user-mode.
  2529. Return Value:
  2530. STATUS_SUCCESS or positive integer on success.
  2531. Error status code on failure.
  2532. --*/
  2533. KSTATUS
  2534. MmGetSetSystemInformation (
  2535. BOOL FromKernelMode,
  2536. MM_INFORMATION_TYPE InformationType,
  2537. PVOID Data,
  2538. PUINTN DataSize,
  2539. BOOL Set
  2540. );
  2541. /*++
  2542. Routine Description:
  2543. This routine gets or sets system information.
  2544. Arguments:
  2545. FromKernelMode - Supplies a boolean indicating whether or not this request
  2546. (and the buffer associated with it) originates from user mode (FALSE)
  2547. or kernel mode (TRUE).
  2548. InformationType - Supplies the information type.
  2549. Data - Supplies a pointer to the data buffer where the data is either
  2550. returned for a get operation or given for a set operation.
  2551. DataSize - Supplies a pointer that on input contains the size of the
  2552. data buffer. On output, contains the required size of the data buffer.
  2553. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  2554. a set operation (TRUE).
  2555. Return Value:
  2556. Status code.
  2557. --*/