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.

252 lines
11 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. tbase.c
  5. Abstract:
  6. Skeleton for a Win32 Base API Test Program
  7. Author:
  8. Steve Wood (stevewo) 26-Oct-1990
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <string.h>
  16. #include <stdarg.h>
  17. #include <assert.h>
  18. #include <stdio.h>
  19. #ifndef DBG
  20. #define DBG 0
  21. #endif
  22. #if DBG
  23. #define IF_DEBUG if (TRUE)
  24. #else
  25. #define IF_DEBUG if (FALSE)
  26. #endif
  27. #include "basertl.h"
  28. DWORD
  29. main(
  30. int argc,
  31. char *argv[],
  32. char *envp[]
  33. )
  34. {
  35. NTSTATUS Status;
  36. LPVOID p1, p2, p3, p4, p5, p6;
  37. HANDLE h1, h2, h3, h4, h5, h6;
  38. BOOL result;
  39. LPDWORD p;
  40. printf( "TMEM: Entering Test Program\n" );
  41. p1 = LocalAlloc( LMEM_ZEROINIT, 0 );
  42. printf( "LocalAlloc( 0 ) == %lX\n", p1 );
  43. printf( "LocalSize( %lX ) == %ld\n", p1, LocalSize( p1 ) );
  44. p2 = LocalReAlloc( p1, 23, 0 );
  45. printf( "LocalReAlloc( %lX, 23 ) == %lX\n", p1, p2 );
  46. printf( "LocalSize( %lX ) == %ld\n", p2, LocalSize( p2 ) );
  47. printf( "LocalFree( %lX ) == %ld\n", p2, LocalFree( p2 ) );
  48. p1 = LocalAlloc( LMEM_ZEROINIT, 123 );
  49. printf( "LocalAlloc( 123 ) == %lX\n", p1 );
  50. printf( "LocalSize( %lX ) == %ld\n", p1, LocalSize( p1 ) );
  51. p2 = LocalReAlloc( p1, 23, 0 );
  52. printf( "LocalReAlloc( %lX, 23 ) == %lX\n", p1, p2 );
  53. printf( "LocalSize( %lX ) == %ld\n", p2, LocalSize( p2 ) );
  54. p3 = LocalReAlloc( p2, 223, LMEM_ZEROINIT );
  55. printf( "LocalReAlloc( %lX, 223 ) == %lX\n", p2, p3 );
  56. printf( "LocalSize( %lX ) == %ld\n", p3, LocalSize( p3 ) );
  57. p4 = LocalReAlloc( p3, 22, 0 );
  58. printf( "LocalReAlloc( %lX, 22 ) == %lX\n", p3, p4 );
  59. printf( "LocalSize( %lX ) == %ld\n", p4, LocalSize( p4 ) );
  60. printf( "LocalFree( %lX ) == %ld\n", p4, LocalFree( p4 ) );
  61. h1 = LocalAlloc( LMEM_MOVEABLE | LMEM_ZEROINIT, 123 );
  62. printf( "LocalAlloc( MOVEABLE, 123 ) == %lX (-> %lX)\n", h1, LocalLock( h1 ) );
  63. printf( "LocalSize( %lX ) == %ld\n", h1, LocalSize( h1 ) );
  64. h2 = LocalReAlloc( h1, 23, 0 );
  65. printf( "LocalReAlloc( %lX, 23 ) == %lX\n", h1, h2, LocalLock( h2 ) );
  66. printf( "LocalSize( %lX ) == %ld\n", h2, LocalSize( h2 ) );
  67. h3 = LocalReAlloc( h2, 223, LMEM_ZEROINIT );
  68. printf( "LocalReAlloc( %lX, 223 ) == %lX\n", h2, h3, LocalLock( h3 ) );
  69. printf( "LocalSize( %lX ) == %ld\n", h3, LocalSize( h3 ) );
  70. h4 = LocalReAlloc( h3, 22, 0 );
  71. printf( "LocalReAlloc( %lX, 22 ) == %lX\n", h3, h4, LocalLock( h4 ) );
  72. printf( "LocalSize( %lX ) == %ld\n", h4, LocalSize( h4 ) );
  73. printf( "LocalFree( %lX ) == %ld\n", h4, LocalFree( h4 ) );
  74. h1 = GlobalAlloc( GMEM_ZEROINIT, 123 );
  75. printf( "GlobalAlloc( 123 ) == %lX\n", h1 );
  76. printf( "GlobalFlags( %lX ) == %ld\n", h1, GlobalFlags( h1 ) );
  77. printf( "GlobalSize( %lX ) == %ld\n", h1, GlobalSize( h1 ) );
  78. h2 = GlobalReAlloc( h1, 23, 0 );
  79. printf( "GlobalReAlloc( %lX, 23 ) == %lX\n", h1, h2 );
  80. printf( "GlobalSize( %lX ) == %ld\n", h2, GlobalSize( h2 ) );
  81. h3 = GlobalReAlloc( h2, 223, GMEM_ZEROINIT );
  82. printf( "GlobalReAlloc( %lX, 223 ) == %lX\n", h2, h3 );
  83. printf( "GlobalSize( %lX ) == %ld\n", h3, GlobalSize( h3 ) );
  84. h4 = GlobalReAlloc( h3, 22, 0 );
  85. printf( "GlobalReAlloc( %lX, 22 ) == %lX\n", h3, h4 );
  86. printf( "GlobalSize( %lX ) == %ld\n", h4, GlobalSize( h4 ) );
  87. printf( "GlobalFree( %lX ) == %ld\n", h4, GlobalFree( h4 ) );
  88. h1 = GlobalAlloc( GMEM_ZEROINIT, 12003 );
  89. printf( "GlobalAlloc( 123 ) == %lX\n", h1 );
  90. printf( "GlobalFlags( %lX ) == %ld\n", h1, GlobalFlags( h1 ) );
  91. printf( "GlobalSize( %lX ) == %ld\n", h1, GlobalSize( h1 ) );
  92. h2 = GlobalReAlloc( h1, 4000, 0 );
  93. printf( "GlobalReAlloc( %lX, 23 ) == %lX\n", h1, h2 );
  94. printf( "GlobalSize( %lX ) == %ld\n", h2, GlobalSize( h2 ) );
  95. h3 = GlobalReAlloc( h2, 8000, GMEM_ZEROINIT );
  96. printf( "GlobalReAlloc( %lX, 223 ) == %lX\n", h2, h3 );
  97. printf( "GlobalSize( %lX ) == %ld\n", h3, GlobalSize( h3 ) );
  98. h4 = GlobalReAlloc( h3, 22, 0 );
  99. printf( "GlobalReAlloc( %lX, 22 ) == %lX\n", h3, h4 );
  100. printf( "GlobalSize( %lX ) == %ld\n", h4, GlobalSize( h4 ) );
  101. printf( "GlobalFree( %lX ) == %ld\n", h4, GlobalFree( h4 ) );
  102. DbgBreakPoint();
  103. h1 = GlobalAlloc( GMEM_DDESHARE, 123 );
  104. printf( "GlobalAlloc( 123 ) == %lX\n", h1 );
  105. printf( "GlobalFlags( %lX ) == %ld\n", h1, GlobalFlags( h1 ) );
  106. printf( "GlobalSize( %lX ) == %ld\n", h1, GlobalSize( h1 ) );
  107. p = GlobalLock( h1 );
  108. if (*p != 0xABCDEF01) {
  109. DbgBreakPoint();
  110. }
  111. h2 = GlobalReAlloc( h1, 23, 0 );
  112. printf( "GlobalReAlloc( %lX, 23 ) == %lX\n", h1, h2 );
  113. printf( "GlobalSize( %lX ) == %ld\n", h2, GlobalSize( h2 ) );
  114. h3 = GlobalReAlloc( h2, 223, GMEM_ZEROINIT );
  115. printf( "GlobalReAlloc( %lX, 223 ) == %lX\n", h2, h3 );
  116. printf( "GlobalSize( %lX ) == %ld\n", h3, GlobalSize( h3 ) );
  117. h4 = GlobalReAlloc( h3, 22, 0 );
  118. printf( "GlobalReAlloc( %lX, 22 ) == %lX\n", h3, h4 );
  119. printf( "GlobalSize( %lX ) == %ld\n", h4, GlobalSize( h4 ) );
  120. printf( "GlobalFree( %lX ) == %ld\n", h4, GlobalFree( h4 ) );
  121. printf( "TMEM: Exiting Test Program\n" );
  122. return 0;
  123. }
  124. #if 0
  125. MEMORY_BASIC_INFORMATION MemoryInformation;
  126. DWORD cb;
  127. DWORD oldProtect;
  128. p1 = VirtualAlloc( NULL, 8192, MEM_RESERVE, PAGE_READONLY );
  129. p2 = VirtualAlloc( (LPVOID)((LPSTR)p1 + 4096), 4096, MEM_COMMIT, PAGE_READWRITE );
  130. try {
  131. *(LPDWORD)p1 = -1;
  132. *(LPDWORD)p2 = -2;
  133. }
  134. except( 1 ) {
  135. }
  136. cb = VirtualQuery( (LPVOID)p1, &MemoryInformation, sizeof( MemoryInformation ) );
  137. printf( "VirtualQuery( %X ) = %u (%d)\n", p1, cb, GetLastError() );
  138. printf( " BaseAddress: %x\n", MemoryInformation.BaseAddress );
  139. printf( " AllocationBase: %x\n", MemoryInformation.AllocationBase );
  140. printf( " AllocationProtect: %x\n", MemoryInformation.AllocationProtect );
  141. printf( " RegionSize: %u\n", MemoryInformation.RegionSize );
  142. printf( " State: %x\n", MemoryInformation.State );
  143. printf( " Protect: %x\n", MemoryInformation.Protect );
  144. printf( " Type: %x\n", MemoryInformation.Type );
  145. cb = VirtualQuery( (LPVOID)p2, &MemoryInformation, sizeof( MemoryInformation ) );
  146. printf( "VirtualQuery( %X ) = %u (%d)\n", p2, cb, GetLastError() );
  147. printf( " BaseAddress: %x\n", MemoryInformation.BaseAddress );
  148. printf( " AllocationBase: %x\n", MemoryInformation.AllocationBase );
  149. printf( " AllocationProtect: %x\n", MemoryInformation.AllocationProtect );
  150. printf( " RegionSize: %u\n", MemoryInformation.RegionSize );
  151. printf( " State: %x\n", MemoryInformation.State );
  152. printf( " Protect: %x\n", MemoryInformation.Protect );
  153. printf( " Type: %x\n", MemoryInformation.Type );
  154. result = VirtualProtect( (LPVOID)p2, 4096, PAGE_READONLY, &oldProtect );
  155. printf( "VirtualProtect( %X, 4096, PAGE_READONLY, oldProtect == %x ) = %d (%d)\n", p2, oldProtect, result, GetLastError() );
  156. cb = VirtualQuery( (LPVOID)p2, &MemoryInformation, sizeof( MemoryInformation ) );
  157. printf( "VirtualQuery( %X ) = %u (%d)\n", p2, cb, GetLastError() );
  158. printf( " BaseAddress: %x\n", MemoryInformation.BaseAddress );
  159. printf( " AllocationBase: %x\n", MemoryInformation.AllocationBase );
  160. printf( " AllocationProtect: %x\n", MemoryInformation.AllocationProtect );
  161. printf( " RegionSize: %u\n", MemoryInformation.RegionSize );
  162. printf( " State: %x\n", MemoryInformation.State );
  163. printf( " Protect: %x\n", MemoryInformation.Protect );
  164. printf( " Type: %x\n", MemoryInformation.Type );
  165. result = VirtualFree( (LPVOID)p2, 4096, MEM_DECOMMIT );
  166. printf( "VirtualFree( %X, 4096, MEM_DECOMMIT ) = %d\n", p2, result, GetLastError() );
  167. cb = VirtualQuery( (LPVOID)p2, &MemoryInformation, sizeof( MemoryInformation ) );
  168. printf( "VirtualQuery( %X ) = %u (%d)\n", p2, cb, GetLastError() );
  169. printf( " BaseAddress: %x\n", MemoryInformation.BaseAddress );
  170. printf( " AllocationBase: %x\n", MemoryInformation.AllocationBase );
  171. printf( " AllocationProtect: %x\n", MemoryInformation.AllocationProtect );
  172. printf( " RegionSize: %u\n", MemoryInformation.RegionSize );
  173. printf( " State: %x\n", MemoryInformation.State );
  174. printf( " Protect: %x\n", MemoryInformation.Protect );
  175. printf( " Type: %x\n", MemoryInformation.Type );
  176. result = VirtualFree( (LPVOID)p2, 4096, MEM_RELEASE );
  177. printf( "VirtualFree( %X, 4096, MEM_RELEASE ) = %d\n", p2, result, GetLastError() );
  178. cb = VirtualQuery( (LPVOID)p2, &MemoryInformation, sizeof( MemoryInformation ) );
  179. printf( "VirtualQuery( %X ) = %u (%d)\n", p2, cb, GetLastError() );
  180. printf( " BaseAddress: %x\n", MemoryInformation.BaseAddress );
  181. printf( " AllocationBase: %x\n", MemoryInformation.AllocationBase );
  182. printf( " AllocationProtect: %x\n", MemoryInformation.AllocationProtect );
  183. printf( " RegionSize: %u\n", MemoryInformation.RegionSize );
  184. printf( " State: %x\n", MemoryInformation.State );
  185. printf( " Protect: %x\n", MemoryInformation.Protect );
  186. printf( " Type: %x\n", MemoryInformation.Type );
  187. result = VirtualFree( (LPVOID)p1, 4096, MEM_RELEASE );
  188. printf( "VirtualFree( %X, 4096, MEM_RELEASE ) = %d\n", p1, result, GetLastError() );
  189. cb = VirtualQuery( (LPVOID)p1, &MemoryInformation, sizeof( MemoryInformation ) );
  190. printf( "VirtualQuery( %X ) = %u (%d)\n", p1, cb, GetLastError() );
  191. printf( " BaseAddress: %x\n", MemoryInformation.BaseAddress );
  192. printf( " AllocationBase: %x\n", MemoryInformation.AllocationBase );
  193. printf( " AllocationProtect: %x\n", MemoryInformation.AllocationProtect );
  194. printf( " RegionSize: %u\n", MemoryInformation.RegionSize );
  195. printf( " State: %x\n", MemoryInformation.State );
  196. printf( " Protect: %x\n", MemoryInformation.Protect );
  197. printf( " Type: %x\n", MemoryInformation.Type );
  198. #endif