Windows NT 4.0 source code leak
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.

129 lines
4.3 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1993 Digital Equipment Corporation
  3. Module Name:
  4. tmovmem.c
  5. Abstract:
  6. This module implements a test of the operation of the RtlMoveMemory
  7. function by running an exhaustive test of every case of string offset,
  8. move length, and relative overlap of the two strings up to and a little
  9. beyond one 32-byte cache line. This represents several hundred thousand
  10. test cases. It is assumed any bugs that exist will be found within this
  11. range. If only the error count summary is desired, type "tmovmem > nul"
  12. instead.
  13. Author:
  14. Thomas Van Baak (tvb) 13-Jan-1993
  15. Environment:
  16. User mode.
  17. Revision History:
  18. --*/
  19. #include <nt.h>
  20. #include <ntrtl.h>
  21. #include <stdio.h>
  22. #include "localrtl.h"
  23. //
  24. // Two strings are defined within a large buffer. The target string is
  25. // initially below the source string with a small gap between the two
  26. // strings. A margin around the strings ensures any bytes accidentally
  27. // changed outside the strings are detectable. As the length of the strings
  28. // and the offset of the source string are varied, the target string wanders
  29. // from well below, through, and well above the source string.
  30. //
  31. #define MIN_OVERLAP (-(MAX_LENGTH + MAX_MARGIN))
  32. #define MAX_OVERLAP (MAX_LENGTH + MAX_MARGIN - 1)
  33. #define BUFFER_SIZE (MAX_MARGIN + MAX_LENGTH + MAX_MARGIN + MAX_OFFSET + MAX_LENGTH + MAX_MARGIN + MAX_LENGTH + MAX_MARGIN)
  34. UCHAR Buffer0[BUFFER_SIZE];
  35. UCHAR Buffer1[BUFFER_SIZE];
  36. UCHAR Buffer2[BUFFER_SIZE];
  37. void
  38. _CRTAPI1
  39. main()
  40. {
  41. ULONG ErrorCount;
  42. ULONG Length;
  43. ULONG Offset;
  44. LONG Overlap;
  45. ULONG Result;
  46. ULONG Source;
  47. ULONG Target;
  48. ULONG TestCases;
  49. fprintf(stderr, "Testing RtlMoveMemory\n");
  50. ErrorCount = 0;
  51. TestCases = 0;
  52. //
  53. // Make a call to RtlMoveMemory for all possible source string offsets
  54. // within a cache line, for a large set of string lengths, and a wide
  55. // range of positions of the target string relative to the source string,
  56. // including all possible overlapping string configurations.
  57. //
  58. for (Offset = 0; Offset <= MAX_OFFSET; Offset += 1) {
  59. for (Length = 0; Length <= MAX_LENGTH; Length += 1) {
  60. for (Overlap = MIN_OVERLAP; Overlap <= MAX_OVERLAP; Overlap += 1) {
  61. //
  62. // The same string configuration is made in two different
  63. // buffers. RtlMoveMemory is used on the two strings in one
  64. // buffer and the trusted LocalMoveMemory on the two strings
  65. // in the other buffer. The entire buffers are compared to
  66. // determine if the two move functions agree.
  67. //
  68. FillPattern(Buffer1, BUFFER_SIZE);
  69. FillPattern(Buffer2, BUFFER_SIZE);
  70. Source = MAX_MARGIN + MAX_LENGTH + MAX_MARGIN + Offset;
  71. Target = Source + Overlap;
  72. LocalMoveMemory(&Buffer1[Target], &Buffer1[Source], Length);
  73. RtlMoveMemory(&Buffer2[Target], &Buffer2[Source], Length);
  74. Result = LocalCompareMemory(Buffer1, Buffer2, BUFFER_SIZE);
  75. TestCases += 1;
  76. if (Result != BUFFER_SIZE) {
  77. ErrorCount += 1;
  78. printf("ERROR: Offset = %d, Length = %d, Overlap = %d\n",
  79. Offset, Length, Overlap);
  80. printf("RtlMoveMemory( &Buffer[ %d ], &Buffer[ %d ], %d )\n",
  81. Target, Source, Length);
  82. FillPattern(Buffer0, BUFFER_SIZE);
  83. printf(" Original Source = %lx: <%.*s>\n",
  84. &Buffer0[Source], Length, &Buffer0[Source]);
  85. printf(" Expected Target = %lx: <%.*s>\n",
  86. &Buffer1[Target], Length, &Buffer1[Target]);
  87. printf(" Actual Target = %lx: <%.*s>\n",
  88. &Buffer2[Target], Length, &Buffer2[Target]);
  89. printf("\n");
  90. printf("Buffers differ starting at byte %d:\n", Result);
  91. printf("Buffer1 = <%*s>\n", BUFFER_SIZE, Buffer1);
  92. printf("Buffer2 = <%*s>\n", BUFFER_SIZE, Buffer2);
  93. printf("\n");
  94. }
  95. }
  96. }
  97. }
  98. fprintf(stderr, "Test of RtlMoveMemory completed: ");
  99. fprintf(stderr, "%d test cases, %d errors found.\n", TestCases, ErrorCount);
  100. }