1
0

mm.h 89 KB

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