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.

941 lines
22 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. prefetch.h
  5. Abstract:
  6. This module contains the prefetcher definitions that are shared
  7. between the kernel mode component and the user mode service.
  8. Author:
  9. Stuart Sechrest (stuartse)
  10. Cenk Ergan (cenke)
  11. Chuck Leinzmeier (chuckl)
  12. Revision History:
  13. */
  14. #ifndef _PREFETCH_H
  15. #define _PREFETCH_H
  16. //
  17. // Prefetcher version. Be sure to update this after making any changes
  18. // to any defines or structures in this file. When in doubt, update
  19. // the version.
  20. //
  21. #define PF_CURRENT_VERSION 17
  22. //
  23. // Magic numbers to identify scenario dump files.
  24. //
  25. #define PF_SCENARIO_MAGIC_NUMBER 0x41434353
  26. #define PF_TRACE_MAGIC_NUMBER 0x43435341
  27. #define PF_SYSINFO_MAGIC_NUMBER 0x6B756843
  28. //
  29. // Define various limits used in sanity checking a prefetch scenario.
  30. // Do not use these limits except for sanity checking. Most of these are
  31. // very large values that are overkills.
  32. //
  33. #define PF_MAXIMUM_PAGES (128*1024)
  34. #define PF_MAXIMUM_LOG_ENTRIES PF_MAXIMUM_PAGES
  35. #define PF_MAXIMUM_SECTION_PAGES 8192
  36. #define PF_MAXIMUM_SECTION_FILE_NAME_LENGTH 1024
  37. #define PF_MAXIMUM_FILE_NAME_DATA_SIZE (4*1024*1024)
  38. #define PF_MAXIMUM_TIMER_PERIOD (-1i64 * 10 * 60 * 1000 * 1000 * 10)
  39. #define PF_MAXIMUM_ACTIVE_TRACES 4096
  40. #define PF_MAXIMUM_SAVED_TRACES 4096
  41. //
  42. // This is the maximum size a scenario can grow to.
  43. //
  44. #define PF_MAXIMUM_SCENARIO_SIZE (16*1024*1024)
  45. //
  46. // This is the maximum size a trace file can grow to. It is a function
  47. // of the limits above.
  48. //
  49. #define PF_MAXIMUM_TRACE_SIZE PF_MAXIMUM_SCENARIO_SIZE
  50. //
  51. // Maximum allowed sections in a scenario should fit into a USHORT,
  52. // sizeof the SectionId field in log entries.
  53. //
  54. #define PF_MAXIMUM_SECTIONS 16384
  55. //
  56. // Maximum number of unique directories the files for a scenario can
  57. // be in. This is a sanity check constant.
  58. //
  59. #define PF_MAXIMUM_DIRECTORIES (PF_MAXIMUM_SECTIONS * 32)
  60. //
  61. // Minimum size in pages for new scenarios. Smaller traces will be discarded.
  62. //
  63. #define PF_MIN_SCENARIO_PAGES 32
  64. //
  65. // Define various types of prefetch scenarios (starting from 0).
  66. //
  67. typedef enum _PF_SCENARIO_TYPE {
  68. PfApplicationLaunchScenarioType,
  69. PfSystemBootScenarioType,
  70. PfMaxScenarioType,
  71. } PF_SCENARIO_TYPE;
  72. //
  73. // Define structure used to identify traces and prefetch instructions
  74. // for a scenario. For application launch scenarios, it consists of
  75. // the first characters in the executable image's name (NUL
  76. // terminated) and a hash of its full path including the image
  77. // name. Both path and image name are uppercased. On a file system
  78. // with case sensitive names executables at the same path with the
  79. // same name except for case will get the same id.
  80. //
  81. #define PF_SCEN_ID_MAX_CHARS 29
  82. typedef struct _PF_SCENARIO_ID {
  83. WCHAR ScenName[PF_SCEN_ID_MAX_CHARS + 1];
  84. ULONG HashId;
  85. } PF_SCENARIO_ID, *PPF_SCENARIO_ID;
  86. //
  87. // This is the scenario name and hash code value for the boot scenario.
  88. //
  89. #define PF_BOOT_SCENARIO_NAME L"NTOSBOOT"
  90. #define PF_BOOT_SCENARIO_HASHID 0xB00DFAAD
  91. //
  92. // Extension for the prefetch files.
  93. //
  94. #define PF_PREFETCH_FILE_EXTENSION L"pf"
  95. //
  96. // A scenario id can be converted to a file name using the following
  97. // sprintf format, using ScenName, HashId and prefetch file extension.
  98. //
  99. #define PF_SCEN_FILE_NAME_FORMAT L"%ws-%08X.%ws"
  100. //
  101. // This is the maximum number of characters in a scenario file name
  102. // (not path) given the format and definitions above with some head
  103. // room.
  104. //
  105. #define PF_MAX_SCENARIO_FILE_NAME 50
  106. //
  107. // Define the number of periods over which we track page faults for a
  108. // scenario. The duration of the periods depend on the scenario type.
  109. //
  110. #define PF_MAX_NUM_TRACE_PERIODS 10
  111. //
  112. // Define maximum number of characters for the relative path from
  113. // system root to where prefetch files can be found.
  114. //
  115. #define PF_MAX_PREFETCH_ROOT_PATH 32
  116. //
  117. // Define maximum number of characters for the list of known hosting
  118. // applications.
  119. //
  120. #define PF_HOSTING_APP_LIST_MAX_CHARS 128
  121. //
  122. // Define invalid page index used to terminate a section's page record
  123. // lists in scenarios.
  124. //
  125. #define PF_INVALID_PAGE_IDX (-1)
  126. //
  127. // Define the number of launches of the scenario we keep track of for
  128. // usage history of pages. In every page record there is a bit field
  129. // of this size. Do not grow this over 32, size of (ULONG).
  130. //
  131. #define PF_PAGE_HISTORY_SIZE 8
  132. //
  133. // Define the maximum and minimum scenario sensitivity. A page has to be
  134. // used in this many of the launches in the history for it to be prefetch.
  135. //
  136. #define PF_MAX_SENSITIVITY PF_PAGE_HISTORY_SIZE
  137. #define PF_MIN_SENSITIVITY 1
  138. //
  139. // Define structure for kernel trace dumps. The dump is all in a
  140. // single contiguous buffer at the top of which is the trace header
  141. // structure. The trace header contains offsets to an array of log
  142. // entries in the buffer and to a list of section info
  143. // structures. Section info structures come one after the other
  144. // containing file names. There is a log entry for every page
  145. // fault. Every log entry has a SectionId that is the number of the
  146. // section info structure that contains the name of the file the fault
  147. // was to. These are followed by variable sized volumeinfo entries
  148. // that describe the volumes on which the sections in the trace are
  149. // located.
  150. //
  151. //
  152. // NOTE: Do not forget about alignment issues on 64 bit platforms as
  153. // you modify these structures or add new ones.
  154. //
  155. //
  156. // One of these is logged for every page fault.
  157. //
  158. typedef struct _PF_LOG_ENTRY {
  159. //
  160. // File offset of the page that was faulted.
  161. //
  162. ULONG FileOffset;
  163. //
  164. // Index into the section info table in the trace header that helps
  165. // us identify the file.
  166. //
  167. USHORT SectionId;
  168. //
  169. // Whether this page was faulted as an image page or data page.
  170. //
  171. BOOLEAN IsImage;
  172. //
  173. // Whether this is a fault that happened in the process in which
  174. // the scenario is active. We may log faults in special system
  175. // process as a part of this scenario.
  176. //
  177. BOOLEAN InProcess;
  178. } PF_LOG_ENTRY, *PPF_LOG_ENTRY;
  179. //
  180. // This structure associates a page fault with a file name.
  181. // Note that because we lay these structures right after each other in
  182. // the trace buffer, if you add a new field which has an alignment
  183. // greater than 2 bytes, we'll hit alignment problems.
  184. //
  185. typedef struct _PF_SECTION_INFO {
  186. //
  187. // Number of characters in the file name, excluding terminating NUL.
  188. //
  189. USHORT FileNameLength;
  190. //
  191. // Whether this section is for filesystem metafile (e.g. directory.)
  192. //
  193. USHORT Metafile:1;
  194. USHORT Unused:15;
  195. //
  196. // Variable length file name buffer including terminating NUL.
  197. //
  198. WCHAR FileName[1];
  199. } PF_SECTION_INFO, *PPF_SECTION_INFO;
  200. //
  201. // This structure describes a volume on which the sections in the
  202. // trace are on.
  203. //
  204. typedef struct _PF_VOLUME_INFO {
  205. //
  206. // Volume creation time and serial number used to identify the
  207. // volume in case its NT/device path e.g. \Device\HarddiskVolume1
  208. // changes.
  209. //
  210. LARGE_INTEGER CreationTime;
  211. ULONG SerialNumber;
  212. //
  213. // Current NT/device path for the volume and its length in
  214. // characters excluding terminating NUL.
  215. //
  216. ULONG VolumePathLength;
  217. WCHAR VolumePath[1];
  218. } PF_VOLUME_INFO, *PPF_VOLUME_INFO;
  219. //
  220. // This is the trace header.
  221. //
  222. typedef struct _PF_TRACE_HEADER {
  223. //
  224. // Prefetcher version.
  225. //
  226. ULONG Version;
  227. //
  228. // Magic number identifying this as a trace.
  229. //
  230. ULONG MagicNumber;
  231. //
  232. // Total size of the trace buffer in bytes.
  233. //
  234. ULONG Size;
  235. //
  236. // Scenario id for which this trace was acquired.
  237. //
  238. PF_SCENARIO_ID ScenarioId;
  239. //
  240. // Type of this scenario.
  241. //
  242. PF_SCENARIO_TYPE ScenarioType;
  243. //
  244. // Offset from the start of the trace buffer where logged
  245. // entries can be found and the number of them.
  246. //
  247. ULONG TraceBufferOffset;
  248. ULONG NumEntries;
  249. //
  250. // Offset from the start of the trace buffer where the section and
  251. // file name information is located.
  252. //
  253. ULONG SectionInfoOffset;
  254. ULONG NumSections;
  255. //
  256. // Offset from the start of the trace buffer where the volume
  257. // information is located, the number of volumes and the total
  258. // size of the volume information block.
  259. //
  260. ULONG VolumeInfoOffset;
  261. ULONG NumVolumes;
  262. ULONG VolumeInfoSize;
  263. //
  264. // Distribution of the pagefaults over the duration of the trace.
  265. // PeriodLength is in 100ns.
  266. //
  267. LONGLONG PeriodLength;
  268. ULONG FaultsPerPeriod[PF_MAX_NUM_TRACE_PERIODS];
  269. //
  270. // System time when we started tracing this scenario as
  271. // returned by KeQuerySystemTime.
  272. //
  273. LARGE_INTEGER LaunchTime;
  274. } PF_TRACE_HEADER, *PPF_TRACE_HEADER;
  275. //
  276. // Define structure for prefetch scenario instructions. The
  277. // instructions are all in a single contiguous buffer at the top of
  278. // which is the scenario header structure. The header contains offsets
  279. // to arrays of section and page records as well as a file name data
  280. // buffer. Every section contains an offset into the file name data
  281. // buffer where the file name for that section is located. It also has
  282. // an index into the page record table where the first page for that
  283. // section is located. Subsequent pages of the section are linked
  284. // through indices embedded in the page records.
  285. //
  286. // This data is followed by the file system metadata prefetch
  287. // instructions so opening the files will not be as expensive. These
  288. // instructions consist of metadata records that describe the metadata
  289. // that needs to be prefetched on the volumes containing the files to
  290. // be prefetched.
  291. //
  292. //
  293. // NOTE: Do not forget about alignment issues on 64 bit platforms as
  294. // you modify these structures or add new ones.
  295. //
  296. //
  297. // Define structure used for describing pages to be prefetched.
  298. //
  299. typedef struct _PF_PAGE_RECORD {
  300. //
  301. // Index of the next page for this section in the page record
  302. // table or PF_INVALID_PAGE_IDX to terminate the list.
  303. //
  304. LONG NextPageIdx;
  305. //
  306. // File offset of the page that was faulted.
  307. //
  308. ULONG FileOffset;
  309. //
  310. // Whether we should just ignore this page record.
  311. //
  312. ULONG IsIgnore:1;
  313. //
  314. // Whether this page was faulted as an image page.
  315. //
  316. ULONG IsImage:1;
  317. //
  318. // Whether this page was faulted as a data page.
  319. //
  320. ULONG IsData:1;
  321. //
  322. // The following fields are only used by the service:
  323. //
  324. //
  325. // Whether this page was used in the last PF_PAGE_HISTORY_SIZE
  326. // launches of the scenario. The least significant bit stands for
  327. // the most recent launch. If a bit is on, it means the page was
  328. // used in that launch.
  329. //
  330. ULONG UsageHistory:PF_PAGE_HISTORY_SIZE;
  331. //
  332. // Whether this page was prefetched in the last PF_PAGE_HISTORY_SIZE
  333. // launches of the scenario. The least significant bit stands for
  334. // the most recent launch. If a bit is on, it means the page was
  335. // prefetched in that launch.
  336. //
  337. ULONG PrefetchHistory:PF_PAGE_HISTORY_SIZE;
  338. } PF_PAGE_RECORD, *PPF_PAGE_RECORD;
  339. //
  340. // Define structure used for describing sections to prefetch from.
  341. //
  342. typedef struct _PF_SECTION_RECORD {
  343. //
  344. // Index of the first page for this section in the page record
  345. // table or PF_INVALID_PAGE_IDX to terminate the list. That page
  346. // will contain the index for the next page etc.
  347. //
  348. LONG FirstPageIdx;
  349. //
  350. // Total number of page records for this section.
  351. //
  352. ULONG NumPages;
  353. //
  354. // Byte offset relative to the beginning of the file name data
  355. // block where the file path for this section can be found, and
  356. // the number of characters in the file path excluding NUL.
  357. //
  358. ULONG FileNameOffset;
  359. ULONG FileNameLength;
  360. //
  361. // Do we just ignore this section record.
  362. //
  363. ULONG IsIgnore:1;
  364. //
  365. // Was this section accessed through an image mapping.
  366. //
  367. ULONG IsImage:1;
  368. //
  369. // Was this section accessed through a data mapping.
  370. //
  371. ULONG IsData:1;
  372. } PF_SECTION_RECORD, *PPF_SECTION_RECORD;
  373. //
  374. // Define a counted string structure. It can be used to put paths one
  375. // after the other in the scenario/trace file. Its count coming before
  376. // the string would help us verify that the strings are terminated and
  377. // within bounds. The string is still NUL terminated.
  378. //
  379. typedef struct _PF_COUNTED_STRING {
  380. //
  381. // Number of characters excluding the terminating NUL. Making this
  382. // a USHORT helps alignment when stacking counted strings one
  383. // after the other.
  384. //
  385. USHORT Length;
  386. //
  387. // The NUL terminated string.
  388. //
  389. WCHAR String[1];
  390. } PF_COUNTED_STRING, *PPF_COUNTED_STRING;
  391. //
  392. // Define structure used for describing the filesystem metadata that
  393. // should be prefetched before prefetching the scenario.
  394. //
  395. typedef struct _PF_METADATA_RECORD {
  396. //
  397. // Byte offset relative to the beginning of metadata prefetch info
  398. // for the NUL terminated volume name on which the metadata to
  399. // prefetch resides. VolumeNameLength is in characters excluding
  400. // the terminating NUL.
  401. //
  402. ULONG VolumeNameOffset;
  403. ULONG VolumeNameLength;
  404. //
  405. // In case volume's NT/device path changes, these magics are used
  406. // to identify the volume.
  407. //
  408. LARGE_INTEGER CreationTime;
  409. ULONG SerialNumber;
  410. //
  411. // Byte offset relative to the beginning of metadata prefetch info
  412. // for the input buffer to FSCTL to prefetch the metadata and its size.
  413. //
  414. ULONG FilePrefetchInfoOffset;
  415. ULONG FilePrefetchInfoSize;
  416. //
  417. // Byte offset relative to the beginning of metadata prefetch info
  418. // for the full paths of directories (PF_COUNTED_STRING's) that
  419. // need to be prefetched on this volume. The paths come one after
  420. // the other in the buffer.
  421. //
  422. ULONG DirectoryPathsOffset;
  423. ULONG NumDirectories;
  424. } PF_METADATA_RECORD, *PPF_METADATA_RECORD;
  425. //
  426. // This is the scenario header.
  427. //
  428. typedef struct _PF_SCENARIO_HEADER {
  429. //
  430. // Prefetcher version.
  431. //
  432. ULONG Version;
  433. //
  434. // Magic number identifying this as a scenario.
  435. //
  436. ULONG MagicNumber;
  437. //
  438. // This is the version of the prefetcher maintenance service that
  439. // generated this file.
  440. //
  441. ULONG ServiceVersion;
  442. //
  443. // Total size of the scenario.
  444. //
  445. ULONG Size;
  446. //
  447. // Scenario id identifying the scenario.
  448. //
  449. PF_SCENARIO_ID ScenarioId;
  450. //
  451. // Type of this scenario.
  452. //
  453. PF_SCENARIO_TYPE ScenarioType;
  454. //
  455. // Offset from the start of the scenario buffer where the section
  456. // info table is located.
  457. //
  458. ULONG SectionInfoOffset;
  459. ULONG NumSections;
  460. //
  461. // Offset from the start of the scenario buffer where the page
  462. // records are located.
  463. //
  464. ULONG PageInfoOffset;
  465. ULONG NumPages;
  466. //
  467. // Offset from the start of the scenario buffer where file names
  468. // are located.
  469. //
  470. ULONG FileNameInfoOffset;
  471. ULONG FileNameInfoSize;
  472. //
  473. // Offset from the start of the scenario buffer where file system
  474. // metadata prefetch record table is located, number of these
  475. // structures and the size of the whole metadata prefetch
  476. // information.
  477. //
  478. ULONG MetadataInfoOffset;
  479. ULONG NumMetadataRecords;
  480. ULONG MetadataInfoSize;
  481. //
  482. // The following three fields are used to determine if a scenario
  483. // is getting launched too frequently (e.g. multiple times a
  484. // second/minute) for prefetching to be useful.
  485. //
  486. //
  487. // This is the KeQuerySystemTime time of the last launch of this
  488. // scenario for which these scenario instructions were updated.
  489. //
  490. LARGE_INTEGER LastLaunchTime;
  491. //
  492. // If this much time (in 100ns) has not passed since last launch
  493. // time, we should not prefetch this scenario.
  494. //
  495. LARGE_INTEGER MinRePrefetchTime;
  496. //
  497. // If this much time (in 100ns) has not passed since last launch
  498. // time, we should not trace this scenario.
  499. //
  500. LARGE_INTEGER MinReTraceTime;
  501. //
  502. // The following fields are used only by the service:
  503. //
  504. //
  505. // Number of times this scenario has been launched.
  506. //
  507. ULONG NumLaunches;
  508. //
  509. // A page should be used at least this many times in the last
  510. // PF_PAGE_HISTORY_SIZE launches to be prefetched. Otherwise the
  511. // ignore bit on the page is set. The kernel does not have look at
  512. // this variable. The sensitivity is adjusted dynamically by the
  513. // service according to the hit rate of the prefetched pages.
  514. //
  515. ULONG Sensitivity;
  516. } PF_SCENARIO_HEADER, *PPF_SCENARIO_HEADER;
  517. //
  518. // Definitions for the interface between the kernel and the service.
  519. //
  520. //
  521. // This is the name of the event that will be signaled by the kernel
  522. // when there are new scenario traces for the service.
  523. //
  524. #define PF_COMPLETED_TRACES_EVENT_NAME L"\\BaseNamedObjects\\PrefetchTracesReady"
  525. #define PF_COMPLETED_TRACES_EVENT_WIN32_NAME L"PrefetchTracesReady"
  526. //
  527. // This is the name of the event that gets signaled by the kernel when
  528. // parameters have changed.
  529. //
  530. #define PF_PARAMETERS_CHANGED_EVENT_NAME L"\\BaseNamedObjects\\PrefetchParametersChanged"
  531. #define PF_PARAMETERS_CHANGED_EVENT_WIN32_NAME L"PrefetchParametersChanged"
  532. //
  533. // Define sub information classes for SystemPrefetcherInformation.
  534. //
  535. typedef enum _PREFETCHER_INFORMATION_CLASS {
  536. PrefetcherRetrieveTrace = 1,
  537. PrefetcherSystemParameters,
  538. PrefetcherBootPhase,
  539. } PREFETCHER_INFORMATION_CLASS;
  540. //
  541. // This is the input structure to NtQuerySystemInformation /
  542. // NtSetSystemInformation for the SystemPrefetcherInformation
  543. // information class.
  544. //
  545. typedef struct _PREFETCHER_INFORMATION {
  546. //
  547. // These two fields help make sure caller does not make bogus
  548. // requests and keep track of version for this kernel interface.
  549. //
  550. ULONG Version;
  551. ULONG Magic;
  552. //
  553. // Sub information class.
  554. //
  555. PREFETCHER_INFORMATION_CLASS PrefetcherInformationClass;
  556. //
  557. // Input / Output buffer and its length.
  558. //
  559. PVOID PrefetcherInformation;
  560. ULONG PrefetcherInformationLength;
  561. } PREFETCHER_INFORMATION, *PPREFETCHER_INFORMATION;
  562. //
  563. // Define boot phase id's for use with PrefetcherBootPhase information
  564. // subclass.
  565. //
  566. typedef enum _PF_BOOT_PHASE_ID {
  567. PfKernelInitPhase = 0,
  568. PfBootDriverInitPhase = 90,
  569. PfSystemDriverInitPhase = 120,
  570. PfSessionManagerInitPhase = 150,
  571. PfSMRegistryInitPhase = 180,
  572. PfVideoInitPhase = 210,
  573. PfPostVideoInitPhase = 240,
  574. PfBootAcceptedRegistryInitPhase = 270,
  575. PfUserShellReadyPhase = 300,
  576. PfMaxBootPhaseId = 900,
  577. } PF_BOOT_PHASE_ID, *PPF_BOOT_PHASE_ID;
  578. //
  579. // Define system wide prefetch parameters structure.
  580. //
  581. //
  582. // Whether a particular type of prefetching is enabled, disabled or
  583. // just not specified.
  584. //
  585. typedef enum _PF_ENABLE_STATUS {
  586. PfSvNotSpecified,
  587. PfSvEnabled,
  588. PfSvDisabled,
  589. PfSvMaxEnableStatus
  590. } PF_ENABLE_STATUS, *PPF_ENABLE_STATUS;
  591. //
  592. // Define limits structure for different prefetch types.
  593. //
  594. typedef struct _PF_TRACE_LIMITS {
  595. //
  596. // Maximum number of pages that can be logged.
  597. //
  598. ULONG MaxNumPages;
  599. //
  600. // Maximum number of sections that can be logged.
  601. //
  602. ULONG MaxNumSections;
  603. //
  604. // Period for the trace timer. The trace times out after
  605. // PF_MAX_NUM_TRACE_PERIODS. This is in 100ns. It should be
  606. // negative denoting to the system that periods are relative.
  607. //
  608. LONGLONG TimerPeriod;
  609. } PF_TRACE_LIMITS, *PPF_TRACE_LIMITS;
  610. //
  611. // System wide prefetch parameters structure.
  612. //
  613. typedef struct _PF_SYSTEM_PREFETCH_PARAMETERS {
  614. //
  615. // Whether different types of prefetching are enabled or not.
  616. //
  617. PF_ENABLE_STATUS EnableStatus[PfMaxScenarioType];
  618. //
  619. // Limits for different prefetch types.
  620. //
  621. PF_TRACE_LIMITS TraceLimits[PfMaxScenarioType];
  622. //
  623. // Maximum number of active prefetch traces.
  624. //
  625. ULONG MaxNumActiveTraces;
  626. //
  627. // Maximum number of saved completed prefetch traces.
  628. // Note that this should be greater than the number of boot phases,
  629. // since the service won't be started until later in boot.
  630. //
  631. ULONG MaxNumSavedTraces;
  632. //
  633. // Path to directory relative to system root where prefetch
  634. // instructions can be found.
  635. //
  636. WCHAR RootDirPath[PF_MAX_PREFETCH_ROOT_PATH];
  637. //
  638. // Comma seperated list of hosting applications (e.g. dllhost.exe, mmc.exe,
  639. // rundll32.exe ...) for which we create scenario ID's based on command line
  640. // as well.
  641. //
  642. WCHAR HostingApplicationList[PF_HOSTING_APP_LIST_MAX_CHARS];
  643. } PF_SYSTEM_PREFETCH_PARAMETERS, *PPF_SYSTEM_PREFETCH_PARAMETERS;
  644. //
  645. // Useful macros.
  646. //
  647. //
  648. // Macros for alignment. Assumptions are that alignments are a power
  649. // of 2 and allocators (malloc, heap, pool etc) allocate chunks with
  650. // bigger alignment than what you need. You should verify these by
  651. // using asserts and the "power of two" macro below.
  652. //
  653. //
  654. // Determines whether the value is a power of two. Zero is not a power
  655. // of 2. The value should be of an unsigned type that supports bit
  656. // operations, e.g. not a pointer.
  657. //
  658. #define PF_IS_POWER_OF_TWO(Value) \
  659. ((Value) && !((Value) & (Value - 1)))
  660. //
  661. // Return value is the Pointer increased to be aligned with
  662. // Alignment. Alignment must be a power of 2.
  663. //
  664. #define PF_ALIGN_UP(Pointer, Alignment) \
  665. ((PVOID)(((ULONG_PTR)(Pointer) + (Alignment) - 1) & (~((ULONG_PTR)(Alignment) - 1))))
  666. //
  667. // Verification code shared with the kernel mode component. This code
  668. // has to be kept in sync copy & paste.
  669. //
  670. BOOLEAN
  671. PfWithinBounds(
  672. PVOID Pointer,
  673. PVOID Base,
  674. ULONG Length
  675. );
  676. BOOLEAN
  677. PfVerifyScenarioId (
  678. PPF_SCENARIO_ID ScenarioId
  679. );
  680. BOOLEAN
  681. PfVerifyScenarioBuffer(
  682. PPF_SCENARIO_HEADER Scenario,
  683. ULONG BufferSize,
  684. PULONG FailedCheck
  685. );
  686. BOOLEAN
  687. PfVerifyTraceBuffer(
  688. PPF_TRACE_HEADER Trace,
  689. ULONG BufferSize,
  690. PULONG FailedCheck
  691. );
  692. #endif // _PREFETCH_H