Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
9.5 KiB

  1. <html xmlns:v="urn:schemas-microsoft-com:vml"
  2. xmlns:o="urn:schemas-microsoft-com:office:office"
  3. xmlns:w="urn:schemas-microsoft-com:office:word"
  4. xmlns="http://www.w3.org/TR/REC-html40">
  5. <head>
  6. <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
  7. <meta name=ProgId content=Word.Document>
  8. <meta name=Generator content="Microsoft Word 9">
  9. <meta name=Originator content="Microsoft Word 9">
  10. <link rel=File-List href="./registry%20leak_files/filelist.xml">
  11. <link rel=Edit-Time-Data href="./registry%20leak_files/editdata.mso">
  12. <link rel=OLE-Object-Data href="./registry%20leak_files/oledata.mso">
  13. <!--[if !mso]>
  14. <style>
  15. v\:* {behavior:url(#default#VML);}
  16. o\:* {behavior:url(#default#VML);}
  17. w\:* {behavior:url(#default#VML);}
  18. .shape {behavior:url(#default#VML);}
  19. </style>
  20. <![endif]-->
  21. <title>Profile Registry Leak</title>
  22. <!--[if gte mso 9]><xml>
  23. <o:DocumentProperties>
  24. <o:Author>Alex Armanasu</o:Author>
  25. <o:Template>Normal</o:Template>
  26. <o:LastAuthor>Alex Armanasu</o:LastAuthor>
  27. <o:Revision>4</o:Revision>
  28. <o:TotalTime>31</o:TotalTime>
  29. <o:Created>2000-02-04T02:52:00Z</o:Created>
  30. <o:LastSaved>2000-02-04T03:23:00Z</o:LastSaved>
  31. <o:Pages>1</o:Pages>
  32. <o:Company>Sarut</o:Company>
  33. <o:Lines>1</o:Lines>
  34. <o:Paragraphs>1</o:Paragraphs>
  35. <o:Version>9.2720</o:Version>
  36. </o:DocumentProperties>
  37. </xml><![endif]-->
  38. <style>
  39. <!--
  40. /* Font Definitions */
  41. @font-face
  42. {font-family:Courier;
  43. panose-1:0 0 0 0 0 0 0 0 0 0;
  44. mso-font-charset:0;
  45. mso-generic-font-family:modern;
  46. mso-font-format:other;
  47. mso-font-pitch:fixed;
  48. mso-font-signature:3 0 0 0 1 0;}
  49. /* Style Definitions */
  50. p.MsoNormal, li.MsoNormal, div.MsoNormal
  51. {mso-style-parent:"";
  52. margin:0in;
  53. margin-bottom:.0001pt;
  54. mso-pagination:widow-orphan;
  55. font-size:12.0pt;
  56. font-family:"Times New Roman";
  57. mso-fareast-font-family:"Times New Roman";}
  58. p.Paragraph, li.Paragraph, div.Paragraph
  59. {mso-style-name:Paragraph;
  60. margin-top:3.0pt;
  61. margin-right:0in;
  62. margin-bottom:3.0pt;
  63. margin-left:0in;
  64. text-indent:.5in;
  65. mso-pagination:widow-orphan;
  66. font-size:12.0pt;
  67. font-family:"Times New Roman";
  68. mso-fareast-font-family:"Times New Roman";}
  69. p.Code, li.Code, div.Code
  70. {mso-style-name:Code;
  71. margin-top:0in;
  72. margin-right:0in;
  73. margin-bottom:0in;
  74. margin-left:1.0in;
  75. margin-bottom:.0001pt;
  76. mso-pagination:widow-orphan;
  77. mso-layout-grid-align:none;
  78. text-autospace:none;
  79. font-size:10.0pt;
  80. font-family:Courier;
  81. mso-fareast-font-family:"Times New Roman";
  82. mso-bidi-font-family:Arial;}
  83. @page Section1
  84. {size:8.5in 11.0in;
  85. margin:1.0in 1.25in 1.0in 1.25in;
  86. mso-header-margin:.5in;
  87. mso-footer-margin:.5in;
  88. mso-paper-source:0;}
  89. div.Section1
  90. {page:Section1;}
  91. -->
  92. </style>
  93. </head>
  94. <body lang=EN-US style='tab-interval:.5in'>
  95. <div class=Section1>
  96. <p class=MsoNormal align=center style='text-align:center'>Profile Registry Leak</p>
  97. <p class=Paragraph>This document describes a proposed solution to the registry
  98. leak problem that we could not fix for Windows 2000.<span style="mso-spacerun:
  99. yes">� </span>Bugs 173929 and 435236 are partly caused by the registry
  100. leak.<span style="mso-spacerun: yes"></span>Here is one example of the
  101. problem.<span style="mso-spacerun: yes"></span>When a user logs off, userenv
  102. tries to unload the user's profile.<span style="mso-spacerun: yes">
  103. </span>Sometimes some process has a key open in the registry.<span
  104. style="mso-spacerun: yes">� </span>This prevents userenv from unloading the
  105. hive.<span style="mso-spacerun: yes"></span>The spreadsheet below lists most
  106. of the known causes of the bug.</p>
  107. <p class=Paragraph><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
  108. <p class=Paragraph><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
  109. o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
  110. stroked="f">
  111. <v:stroke joinstyle="miter"/>
  112. <v:formulas>
  113. <v:f eqn="if lineDrawn pixelLineWidth 0"/>
  114. <v:f eqn="sum @0 1 0"/>
  115. <v:f eqn="sum 0 0 @1"/>
  116. <v:f eqn="prod @2 1 2"/>
  117. <v:f eqn="prod @3 21600 pixelWidth"/>
  118. <v:f eqn="prod @3 21600 pixelHeight"/>
  119. <v:f eqn="sum @0 0 1"/>
  120. <v:f eqn="prod @6 1 2"/>
  121. <v:f eqn="prod @7 21600 pixelWidth"/>
  122. <v:f eqn="sum @8 21600 0"/>
  123. <v:f eqn="prod @7 21600 pixelHeight"/>
  124. <v:f eqn="sum @10 21600 0"/>
  125. </v:formulas>
  126. <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
  127. <o:lock v:ext="edit" aspectratio="t"/>
  128. </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:1in;
  129. height:56.25pt' o:ole="">
  130. <v:imagedata src="./registry%20leak_files/image001.wmz" o:title=""/>
  131. </v:shape><![endif]--><![if !vml]><img width=96 height=75
  132. src="./registry%20leak_files/image002.gif" v:shapes="_x0000_i1025"><![endif]><!--[if gte mso 9]><xml>
  133. <o:OLEObject Type="Embed" ProgID="Outlook.FileAttach" ShapeID="_x0000_i1025"
  134. DrawAspect="Content" ObjectID="_1011110951">
  135. </o:OLEObject>
  136. </xml><![endif]--></p>
  137. <p class=Paragraph>This bug has three symptoms that affect users.<span
  138. style="mso-spacerun: yes">� </span>First, if userenv cannot unload the profile
  139. when the user logs off, userenv does not save the user's profile to the
  140. server.<span style="mso-spacerun: yes"></span>Second, since such profiles
  141. never get unloaded, they end up using a lot of memory on a terminal server that
  142. has lots of users logging in.<span style="mso-spacerun: yes"></span>Third, if
  143. the profile is still loaded the next time the user logs in, any changes stored
  144. on the server are not loaded and are lost.</p>
  145. <p class=Paragraph>I have a separate solution for each symptom.<span
  146. style="mso-spacerun: yes">� </span>Currently when a user logs off, if the profile
  147. is locked we poll the profile for 60 seconds before giving up.<span
  148. style="mso-spacerun: yes">� </span>I would change the code to use RegSaveKey to
  149. save the hive at the end of the 60 second delay rather then giving up.</p>
  150. <p class=Paragraph>To solve the second symptom, the memory leak, I propose
  151. using a new API that will soon be checked in.<span style="mso-spacerun: yes">
  152. </span>With this API we can tell the registry to set an event when no one is
  153. using the specified hive.<span style="mso-spacerun: yes"></span>At that point
  154. we can unload the hive.<span style="mso-spacerun: yes"></span>Our code would
  155. change so that after waiting 60 seconds for a hive to be unlocked, we would use
  156. the new API to receive notice when the hive was finally free.<span
  157. style="mso-spacerun: yes">� </span>We would have to add a thread to wait for each
  158. group of 64 hives (WaitForMultipleObjects can only wait for 64 events).<span
  159. style="mso-spacerun: yes">� </span>We would have to add code to tell the helper
  160. thread which hives to wait for.<span style="mso-spacerun: yes"></span>We
  161. would have to add code to synchronize the helper thread and LoadUserProfile in
  162. the case where the user logs back in before the hive gets unloaded.<span
  163. style="mso-spacerun: yes">� </span>This does not completely solve the problem
  164. because wininet never releases some of the keys that it uses.<span
  165. style="mso-spacerun: yes">� </span>However it makes sure that we behave
  166. correctly should wininet ever get fixed.<span style="mso-spacerun: yes">
  167. </span>We can show the terminal server team what dlls are leaking registry keys
  168. and they can spend the time getting the dlls fixed.</p>
  169. <p class=Code>NtUnloadKeyEx(<o:p></o:p></p>
  170. <p class=Code><span style="mso-spacerun: yes">��� </span>IN POBJECT_ATTRIBUTES
  171. TargetKey,<o:p></o:p></p>
  172. <p class=Code><span style="mso-spacerun: yes">��� </span>IN HANDLE Event
  173. OPTIONAL<o:p></o:p></p>
  174. <p class=Code><span style="mso-spacerun: yes">��� </span>)<o:p></o:p></p>
  175. <p class=Paragraph>It is unclear if we should solve the last symptom.<span
  176. style="mso-spacerun: yes">� </span>Currently userenv does not handle overlapped
  177. logon sessions well.<span style="mso-spacerun: yes"></span>Userenv will lose
  178. one set of changes.<span style="mso-spacerun: yes"></span>A solution to that
  179. problem would probably solve this problem.<span style="mso-spacerun: yes">
  180. </span>We could solve this problem by using another new API.<span
  181. style="mso-spacerun: yes">� </span>This API will let us rename a key even when
  182. it is in use.<span style="mso-spacerun: yes"></span>If a user logs on and his
  183. hive is loaded because the user has another logon session on the machine, we will
  184. use the loaded hive and lose any changes on the server.<span
  185. style="mso-spacerun: yes">� </span>If a user logs on and his hive is loaded
  186. because some program still has a key open from the last logon session (or some
  187. program has loaded the hive for its own use), then we will rename the key and
  188. load the profile from the server.<span style="mso-spacerun: yes"></span>This
  189. requires that we change our code as described above.<span style="mso-spacerun:
  190. yes">� </span>Unfortunately, since the name ntuser.dat is already taken, we
  191. need to use a new name for the hive from the server and remember that when the
  192. user logs out.<span style="mso-spacerun: yes"></span>At that time we need to
  193. make sure we copy the new hive and attempt to delete the old hive.<span
  194. style="mso-spacerun: yes">� </span>We need to handle the case where the user
  195. has multiple hives leaked simultaneously.</p>
  196. <p class=Code>NTSTATUS<o:p></o:p></p>
  197. <p class=Code>NtRenameKey(<o:p></o:p></p>
  198. <p class=Code><span style="mso-spacerun: yes">��� </span>IN HANDLE<span
  199. style="mso-spacerun: yes">���������� </span>KeyHandle,<o:p></o:p></p>
  200. <p class=Code><span style="mso-spacerun: yes">��� </span>IN
  201. PUNICODE_STRING<span style="mso-spacerun: yes"></span>NewName<o:p></o:p></p>
  202. <p class=Code><span style="mso-spacerun: yes">��� </span>)<o:p></o:p></p>
  203. <p class=Paragraph><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
  204. </div>
  205. </body>
  206. </html>