Leaked source code of windows server 2003
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.

149 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. slisttest.c
  5. Abstract:
  6. This module implements a program which tests the interlocked SLIST
  7. functions exported from kernel32.dll. Since these functions are
  8. implemented in Win2000 and are just being exposed to windows programs
  9. this program is not an exhaustive test. Rather it just tests whether
  10. the interfaces exposed correctly.
  11. Author:
  12. David N. Cutler (davec) 10-Jan-2000
  13. Environment:
  14. User mode.
  15. Revision History:
  16. None.
  17. --*/
  18. #include <windows.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <malloc.h>
  23. //
  24. // Define structure that will be used in SLIST.
  25. //
  26. typedef struct _PROGRAM_ITEM {
  27. //
  28. // Normally a SINGLE_LIST_ENTRY is the first member of the program
  29. // item structure, but it can be any member as long as the address
  30. // of the containing structure is computed correctly.
  31. //
  32. SINGLE_LIST_ENTRY ItemEntry;
  33. //
  34. // Additional members in the structure would be used for data
  35. // associated with whatever the program item represents. Here
  36. // the only use is for a signature that will be used for the
  37. // test.
  38. //
  39. ULONG Signature;
  40. } PROGRAM_ITEM, *PPROGRAM_ITEM;
  41. VOID
  42. FrameNoCode (
  43. VOID
  44. );
  45. VOID
  46. FrameWithCode (
  47. VOID
  48. );
  49. int
  50. Bar (
  51. PULONG Switch
  52. )
  53. {
  54. *Switch /= 3;
  55. return (*Switch & 1);
  56. }
  57. int
  58. Foo (
  59. PULONG Switch
  60. )
  61. {
  62. *Switch += 1;
  63. return (*Switch & 1);
  64. }
  65. //
  66. // Main program.
  67. //
  68. int __cdecl
  69. main(
  70. ULONG *Buffer1,
  71. ULONG *Buffer2,
  72. ULONG Length
  73. )
  74. {
  75. ULONG Count = 1;
  76. PSINGLE_LIST_ENTRY FirstEntry;
  77. PSINGLE_LIST_ENTRY ListEntry;
  78. SLIST_HEADER ListHead;
  79. PPROGRAM_ITEM ProgramItem;
  80. memmove(Buffer1, Buffer2, Length);
  81. memcpy(Buffer1, Buffer2, Length);
  82. memset(Buffer1, 0, Length);
  83. InitializeSListHead(&ListHead);
  84. Foo(&Count);
  85. try {
  86. ProgramItem = (PPROGRAM_ITEM)malloc(sizeof(*ProgramItem));
  87. ProgramItem->Signature = Count;
  88. FirstEntry = InterlockedPushEntrySList(&ListHead,
  89. &ProgramItem->ItemEntry);
  90. if (FirstEntry != NULL) {
  91. leave;
  92. }
  93. try {
  94. ListEntry = InterlockedPopEntrySList(&ListHead);
  95. ProgramItem = CONTAINING_RECORD(ListEntry, PROGRAM_ITEM, ItemEntry);
  96. if (ProgramItem->Signature != Count) {
  97. leave;
  98. }
  99. free((PCHAR)ProgramItem);
  100. } finally {
  101. if (AbnormalTermination()) {
  102. Foo(&Count);
  103. }
  104. }
  105. Bar(&Count);
  106. } except (Bar(&Count)) {
  107. Foo(&Count);
  108. }
  109. FrameNoCode();
  110. FrameWithCode();
  111. return 0;
  112. }