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.

345 lines
14 KiB

  1. IISRTL - IIS Run Time Library
  2. George V. Reilly, <[email protected]>
  3. 6/9/1998
  4. Last Updated: 6/8/1999 by JasAndre
  5. This document describes the public interfaces to the code bundled in
  6. iisrtl.dll. The public header files can be found in iis\inc. The code can
  7. be found in iis\svcs\iisrtl.
  8. acache.hxx - ALLOC_CACHE_HANDLER - Allocation Cache
  9. ===================================================
  10. class ALLOC_CACHE_HANDLER is a memory allocator. An ACH maintains a
  11. free list of blocks of memory, each N bytes in size. Typically, you use
  12. this by overriding `operator new' and `operator delete' for your heavily
  13. used C++ class. You need to maintain a static member variable that
  14. points to your class's instance of an ACH. Examples of how to do this
  15. abound; look at lkrhash.{h,cpp} for one such. ACache can also be used
  16. for C-style structs or any fixed-size block of memory.
  17. Pros: ACache is considerably faster than the global `operator new'. (The
  18. difference isn't as marked in NT5, now that the NT heaps have been
  19. improved, but it's still a win.) In addition, you can use iisprobe to dump
  20. statistics on your class's use of ACache, and inetdbg has built-in support
  21. for ACache (!inetdbg.acache). ACache also offers additional debugging
  22. support by checking for double deletions and filling free'd blocks with a
  23. unique, identifiable pattern.
  24. Cons: May waste memory by keeping large lists that might be better
  25. returned to the system. ACache periodically prunes all free lists in
  26. the background, so this isn't too much of a problem.
  27. madel.hxx - MEMORY_ALLOC_DELETE - Memory Allocator
  28. manodel.hxx - MEMORY_ALLOC_NO_DELETE - Memory Allocator
  29. =======================================================
  30. Alternative memory allocators that are supposedly faster than ACache.
  31. They work by allocating large blocks of memory and then suballocating
  32. from those blocks. (ACache grabs an exact sized block from the system
  33. if its free list is empty.) Again, see lkrhash.{h,cpp} for an example of
  34. how to use these allocators.
  35. Madel will return memory to the system if its free list grows above a
  36. certain threshold. Manodel never returns memory to the system, which
  37. makes it faster but more wasteful.
  38. Pros: probably faster than ACache.
  39. Cons: ACache has much better debugging support. Don't really need three
  40. allocators. Should build one allocator class that combines the best
  41. features of all three allocators.
  42. pudebug.h - Debugging utilities
  43. ===============================
  44. Declares a number of useful debugging utilities, many of them encapsulated
  45. by macros which are available in both the free and checked builds.
  46. There are a number of macros which need to be used:
  47. DECLARE_DEBUG_PRINTS_OBJECT - declares the variables needed for tracing
  48. CREATE_INITIALIZE_DEBUG - called once per process this starts tracing
  49. DELETE_INITIALIZE_DEBUG - called once per process this stops tracing
  50. CREATE_DEBUG_PRINT_OBJECT - called once per module (ie DLL) this informs the
  51. tracing mechanism about the module
  52. DELETE_DEBUG_PRINT_OBJECT - called once per module this tells the mechanism
  53. that the module is no longer tracing
  54. VALID_DEBUG_PRINT_OBJECT - optional call to see if CREATE_DEBUG_PRINT_OBJECT
  55. was successful.
  56. See exe\main.cpp for an example of how to use them for a new process
  57. See svcs\iisrtl\dllmain.cpp for an example of how to use them for a new module
  58. The DEFAULT_TRACE_FLAGS macros control the debug settings, a DWORD variable
  59. per module that contains a collection of bit flags. These are typically used
  60. to conditionalize debug output with the IF_DEBUG macro, e.g.,
  61. IF_DEBUG(SCHED) { /* ... */ }
  62. IF_DEBUG(ACACHE) { DBGPRINTF((DBG_CONTEXT, "ACache blah blah\n")); }
  63. IF_DEBUG(arg), which is available in both the FRE and CHK builds, is defined as
  64. if (DEBUG_## arg & GET_DEBUG_FLAGS())
  65. A set of debug flags should be defined in a local header file,
  66. traditionally called "dbgutil.h", e.g.,
  67. #define DEBUG_SCHED 0x01000000
  68. The debug flags are automatically loaded from the registry at start up time. If
  69. none are found then the settings in the macro DEFAULT_TRACE_FLAGS are used. You
  70. can modify the settings are debug time using the trace extension,
  71. !inetdbg.trace
  72. Other useful macros include DBG_ASSERT and DBG_REQUIRE (simply evaluates its
  73. argument in a free build, but DBG_ASSERTs in a checked build).
  74. See <pudebug.h> for the full list.
  75. For a full explanation see the specs available at,
  76. http://iis/kevlar/webfarm/specs/Kevlar%20Tracing.htm
  77. http://iis/kevlar/webfarm/specs/Kevlar%20Supportability.htm
  78. The PLATFORM_TYPE code provides useful helpers for code that needs to know
  79. what platform it's executing on at runtime (NT Server, Win95, etc).
  80. The INITIALIZE_CRITICAL_SECTION macro should be used in place of
  81. ::InitializeCriticalSection, as it sets the spincount to a non-zero value
  82. (IIS_DEFAULT_CS_SPIN_COUNT) in a platform-independent manner. (Critical
  83. section spincounts were introduced in NT 4.0 sp3). For multiprocessor
  84. scalability, it's very important that busy critical sections have a
  85. non-zero spincount. If you want to set the spincount by hand, use the
  86. SET_CRITICAL_SECTION_SPIN_COUNT macro.
  87. Use the IIS_CREATE_EVENT, IIS_CREATE_SEMAPHORE, and IIS_CREATE_MUTEX macros
  88. to create events, semaphores, and mutexes. In debug builds, each of these
  89. objects will be given a debugger-friendly unique name. In free builds,
  90. they are nameless.
  91. irtldbg.h - More debugging utilities
  92. ====================================
  93. They don't do a lot that pudebug.h doesn't do. They mainly exist so that
  94. LKRhash can be redistributed without needing to provide large chunks of IIS
  95. support code. Many of the macros will look familiar to MFC users.
  96. Useful macros not included in pudebug.h include ASSERT_VALID,
  97. ASSERT[_NULL_OR]_POINTER, and ASSERT[_NULL_OR]_STRING.
  98. buffer.hxx - BUFFER - memory buffer
  99. buffer.hxx - BUFFER_CHAIN - chain of BUFFERs
  100. ============================================
  101. A BUFFER object caches a block of memory. If the block is no more than
  102. INLINED_BUFFER_LEN (16) bytes long, it's held inside the buffer object
  103. itself; otherwise it's dynamically allocated. You can either
  104. request an initial size upon construction or pass in a pointer to an
  105. already allocated block of memory. The size of the cached block can be
  106. adjusted by the Resize method, which takes an optional cbSlop
  107. parameter. QueryPtr returns a pointer to the storage; QuerySize returns
  108. the current size. BUFFER is used in the implementations of the STR,
  109. MULTISZ, STRAU, and MLSZAU classes, qv.
  110. A BUFFER_CHAIN is a linked list of BUFFERs.
  111. Pros: very useful when you need a dynamically sized memory buffer.
  112. If the size of the data is small enough, it'll be cached inline, which
  113. makes it very time- and space-efficient. (The 80-20 rule of memory
  114. allocation: if 80% of your requests can be satisfied by a modest,
  115. fixed-size buffer, inline it; else dynamically allocate.)
  116. Cons: INLINED_BUFFER_LEN is hardwired into BUFFER. If most of your
  117. buffers need to be larger than this, you're just buying yourself
  118. additional overhead (though you still save because you don't need to
  119. manage allocation of the memory block yourself).
  120. string.hxx - STR - lightweight string class
  121. ===========================================
  122. The STR class manages ANSI strings. It derives from the BUFFER class.
  123. It provides several additional methods (see header for complete list):
  124. * SetLen safely sets length
  125. * IsEmpty zero-length string?
  126. * Append (const char*); (const char*, int len); (const STR&)
  127. * Reset empties string but retains buffer
  128. * Copy same as Reset followed by Append (same variations)
  129. * LoadString reads string from a string resource table
  130. * FormatString reads string from a .mc resource table; inserts params
  131. * Escape ) Insert or remove any odd ranged Latin-1
  132. * EscapeSpaces ) characters with the escaped hexadecimal
  133. * Unescape ) equivalents (%xx)
  134. * QueryCB number of bytes in string
  135. * QueryCCH number of characters in string
  136. * CopyToBuffer copies stored string to buffer. Ansi and Unicode variations
  137. * QueryStr returns the string buffer
  138. * Append (char); (char, char) append 1 or 2 chars (unsafe)
  139. * AppendCRLF Append "\r\n" (unsafe; assumes buffer large enough)
  140. The STACK_STR(name, size) macro can be used to declare a string on the
  141. stack.
  142. stringau.hxx - STRAU - lightweight Ansi/Unicode string class
  143. ============================================================
  144. A class that looks a lot like STR but transparently converts between
  145. Ansi and Unicode. All members can take or return a string in either
  146. ANSI or Unicode. For members that take a parameter of bUnicode, the
  147. actual string type must match the flag, even though it gets passed in as
  148. the declared type.
  149. Strings are sync'd on an as needed basis. If a string is set in ANSI,
  150. then a UNICODE version will only be created if a get for UNICODE is
  151. done, or if a UNICODE string is appended.
  152. All conversions are done using Latin-1. This is because the intended use
  153. of this class is for converting HTML pages, which are defined to be
  154. Latin-1.
  155. multisz.hxx - MULTISZ - lightweight multi-string class
  156. ======================================================
  157. Another class that looks a lot like STR but contains a set of strings.
  158. The strings are stored consecutively in the buffer, separated by '\0'.
  159. mlszau.hxx - MLSZAU - lightweight Ansi/Unicode multi-string class
  160. =================================================================
  161. Stores and converts multisz's between unicode and ANSI. It does not allow
  162. much manipulation of them.
  163. lkrhash.h - CTypedHashTable - LKR Hash Tables
  164. =============================================
  165. LKRhash is a fast, growable, multiprocessor-friendly hashtable. The
  166. hashtable will automatically grow (shrink) as you add (delete) elements,
  167. keeping search times short. It is thread-safe and has been designed to
  168. scale extremely well on MP systems. It achieves this by carefully
  169. partitioning locks and holding them for a very short time to minimize lock
  170. contention and hence bottlenecks.
  171. The templatized wrapper class, CTypedHashTable, provides an easy-to-use
  172. front end for the underlying implementation. Several detailed examples
  173. exist in lkrhash.h and svcs\iisrtl\hashtest. If you need an unordered
  174. collection of data that needs to be searched quickly, you should strongly
  175. consider LKRhash.
  176. locks.h - Miscellaneous locks
  177. =============================
  178. In addition to providing an implementation of a user-mode spinlock for
  179. LKRhash, a number of other locks are provided (critical sections, NT
  180. resources, and other read/write locks). All provide the same interface, so
  181. they can be used interchangeably.
  182. irtlmisc.h - IISRTL Miscellanea
  183. ===============================
  184. Some macros used in IISRTL and some random declarations. The most useful
  185. functions are InitializeIISRTL and TerminateIISRTL, which should be used by
  186. clients who want to make use of the scheduler functionality. NumProcessors
  187. and stristr may also be of interest.
  188. tracelog.h - TRACE_LOG
  189. ===========================
  190. A trace log is a fast, in-memory, thread safe activity log useful for
  191. debugging certain classes of problems. They are especially useful when
  192. debugging reference count bugs.
  193. Note that the creator of the log has the option of adding "extra" bytes to
  194. the log header. This can be useful if the creator wants to create a set of
  195. global logs, each on a linked list.
  196. reftrace.h - RefTraceLog
  197. =========================
  198. Reftrace logs are built on top of trace logs. Typically, you write a
  199. reftrace entry whenever you modify a reference count. In addition to the
  200. value of the refcount and some custom context, the log entry includes a
  201. stack bactrace (top nine functions), so you have a chance of figuring out
  202. how the refcount was modified. Enormously useful for tracking down
  203. refcount leaks. Use !inetdbg.ref, !inetdbg.rref, and !inetdbg.resetref to
  204. manipulate the reftrace log.
  205. strlog.hxx - CStringTraceLog
  206. ============================
  207. String trace logs are useful for writing logs of free-form strings when
  208. trying to track down race conditions. DBG_PRINTF, which writes to the
  209. debugger and/or a log file, is relatively slow and involves context swaps,
  210. both of which can make reproducing race conditions much harder. A string
  211. trace log is synchronously written to main memory. The Puts method is
  212. little more than a strcpy; the Printf method is slower but much more
  213. versatile. Use !inetdbg.st, !inetdbg.rst, and !inetdbg.resetst to
  214. manipulate the string trace log.
  215. stktrace.h - IISCaptureStackBackTrace
  216. =====================================
  217. Used by reftrace and DBG_ASSERT to capture a stack backtrace.
  218. datetime.hxx - Date and time manipulation classes
  219. =================================================
  220. A number of classes and helper functions for converting between various
  221. time and date formats. Particularly used in generating HTTP headers and
  222. the IIS logs.
  223. timer.h - Timer routines
  224. ========================
  225. Wrap-proof timer routines (no worries about GetTickCount wrapping around to
  226. zero).
  227. issched.hxx - Scheduler
  228. =======================
  229. The scheduler is used to execute tasks (work items) in the background.
  230. These work items can be one-shot or periodic. Particularly useful for
  231. cleanup or periodic scavenging. Use !inetdbg.sched to debug.
  232. eventlog.hxx - EVENT_LOG
  233. =======================
  234. A useful wrapper for the system/security/application event logs.
  235. gip.h - Global Interface Pointer API support
  236. ============================================
  237. COM interface pointers are apartment-relative. The Global Interface Table
  238. makes passing interface pointers across apartment boundaries much easier
  239. than the traditional methods (CoMarshallInterfaceInStream...). gip.h
  240. further encapsulates the GIT.
  241. giplip.h - global and local interface pointers
  242. ==============================================
  243. An alternative to gip.h.
  244. perfutil.h - Performance Monitor helpers
  245. ========================================
  246. Some helper functions and macros for implementing PerfMon counters.
  247. trie.h - Trie templates
  248. =======================
  249. A trie is a multiway search tree, useful for doing string
  250. matches. Read the comments in <trie.h>