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.

126 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. #include "d:\ntroot\base\ntos\inc\intrlk.h"
  24. #pragma intrinsic(__readgsdword)
  25. //
  26. // Define structure that will be used in SLIST.
  27. //
  28. typedef struct _PROGRAM_ITEM {
  29. //
  30. // Normally a SINGLE_LIST_ENTRY is the first member of the program
  31. // item structure, but it can be any member as long as the address
  32. // of the containing structure is computed correctly.
  33. //
  34. SINGLE_LIST_ENTRY ItemEntry;
  35. //
  36. // Additional members in the structure would be used for data
  37. // associated with whatever the program item represents. Here
  38. // the only use is for a signature that will be used for the
  39. // test.
  40. //
  41. ULONG Signature;
  42. } PROGRAM_ITEM, *PPROGRAM_ITEM;
  43. void
  44. foo (
  45. IN UCHAR *pjSrc,
  46. IN UCHAR *pjDst
  47. )
  48. {
  49. *(ULONG64 UNALIGNED *)pjDst = *(volatile ULONG64 *)pjSrc;
  50. }
  51. //
  52. // Main program.
  53. //
  54. int
  55. __cdecl
  56. main(
  57. int argc,
  58. char *argv[],
  59. char *envp[]
  60. )
  61. {
  62. ULONG Count;
  63. PSINGLE_LIST_ENTRY FirstEntry;
  64. PSINGLE_LIST_ENTRY LastEntry;
  65. SINGLE_LIST_ENTRY ListHead;
  66. PPROGRAM_ITEM ProgramItem;
  67. ListHead.Next = NULL;
  68. LastEntry = NULL;
  69. for (Count = 1; Count < 100; Count += 1) {
  70. ProgramItem = (PPROGRAM_ITEM)malloc(sizeof(*ProgramItem));
  71. ProgramItem->Signature = Count;
  72. FirstEntry = InterlockedPushEntrySingleList(&ListHead,
  73. &ProgramItem->ItemEntry);
  74. if (FirstEntry != LastEntry) {
  75. printf("wrong old first entry\n");
  76. }
  77. LastEntry = &ProgramItem->ItemEntry;
  78. // Count = _byteswap_ulong(Count);
  79. Count = __readgsdword(Count);
  80. }
  81. for (Count = 99; Count > 0; Count -= 1) {
  82. FirstEntry = InterlockedPopEntrySingleList(&ListHead);
  83. ProgramItem = CONTAINING_RECORD(FirstEntry, PROGRAM_ITEM, ItemEntry);
  84. if (ProgramItem->Signature != Count) {
  85. printf("wring entry removed\n");
  86. }
  87. }
  88. if (ListHead.Next != NULL) {
  89. printf("list not empty\n");
  90. }
  91. printf("program ran successfully\n");
  92. return 0;
  93. }