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.

666 lines
17 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. tex.c
  5. Abstract:
  6. Test program for the OB subcomponent of the NTOS project
  7. Author:
  8. Steve Wood (stevewo) 31-Mar-1989
  9. Revision History:
  10. --*/
  11. #include "obp.h"
  12. GENERIC_MAPPING MyGenericMapping = {
  13. STANDARD_RIGHTS_READ,
  14. STANDARD_RIGHTS_WRITE,
  15. STANDARD_RIGHTS_EXECUTE,
  16. STANDARD_RIGHTS_READ |
  17. STANDARD_RIGHTS_WRITE |
  18. STANDARD_RIGHTS_EXECUTE
  19. };
  20. typedef struct _OBJECTTYPEA {
  21. KEVENT Event;
  22. ULONG TypeALength;
  23. ULONG Stuff[ 4 ];
  24. } OBJECTTYPEA, *POBJECTTYPEA;
  25. typedef struct _OBJECTTYPEB {
  26. KSEMAPHORE Semaphore;
  27. ULONG TypeBLength;
  28. ULONG Stuff[ 16 ];
  29. } OBJECTTYPEB, *POBJECTTYPEB;
  30. OBJECT_ATTRIBUTES DirectoryObjA;
  31. OBJECT_ATTRIBUTES ObjectAObjA;
  32. OBJECT_ATTRIBUTES ObjectBObjA;
  33. STRING DirectoryName;
  34. STRING ObjectAName;
  35. STRING ObjectBName;
  36. STRING ObjectAPathName;
  37. STRING ObjectBPathName;
  38. STRING ObjectTypeAName;
  39. STRING ObjectTypeBName;
  40. POBJECT_TYPE ObjectTypeA;
  41. POBJECT_TYPE ObjectTypeB;
  42. PVOID ObjectBodyA;
  43. PVOID ObjectBodyB;
  44. PVOID ObjectBodyA1;
  45. PVOID ObjectBodyA2;
  46. POBJECTTYPEA ObjectA;
  47. POBJECTTYPEB ObjectB;
  48. HANDLE DirectoryHandle;
  49. HANDLE ObjectHandleA1;
  50. HANDLE ObjectHandleB1;
  51. HANDLE ObjectHandleA2;
  52. HANDLE ObjectHandleB2;
  53. VOID
  54. DumpAProc(
  55. IN PVOID Object,
  56. IN POB_DUMP_CONTROL Control OPTIONAL
  57. )
  58. {
  59. POBJECTTYPEA p = (POBJECTTYPEA)Object;
  60. ULONG i;
  61. DbgPrint( "DumpAProc: %lx\n", p );
  62. DbgPrint( " Length: %ld\n", p->TypeALength );
  63. for (i=0; i<4; i++) {
  64. DbgPrint( " Stuff[%ld]: %ld\n", i, p->Stuff[i] );
  65. }
  66. }
  67. char *OpenReasonStrings[] = {
  68. "ObCreateHandle",
  69. "ObOpenHandle",
  70. "ObDuplicateHandle",
  71. "ObInheritHandle"
  72. };
  73. VOID
  74. OpenAProc(
  75. IN OB_OPEN_REASON OpenReason,
  76. IN PEPROCESS Process OPTIONAL,
  77. IN PVOID Object,
  78. IN ACCESS_MASK GrantedAccess,
  79. IN ULONG HandleCount
  80. )
  81. {
  82. DbgPrint( "OpenAProc: OpenReason = %s Process: %lx \n",
  83. OpenReasonStrings[ OpenReason ], Process );
  84. DbgPrint( " Object: %lx Access: %lx Count: %lu\n",
  85. Object, GrantedAccess, HandleCount );
  86. }
  87. VOID
  88. CloseAProc(
  89. IN PEPROCESS Process OPTIONAL,
  90. IN PVOID Object,
  91. IN ACCESS_MASK GrantedAccess,
  92. IN ULONG ProcessHandleCount,
  93. IN ULONG SystemHandleCount
  94. )
  95. {
  96. DbgPrint( "CloseAProc: Process: %lx \n", Process );
  97. DbgPrint( " Object: %lx Access: %lx ProcessHandleCount: %lu SystemHandleCount: %lu\n",
  98. Object, GrantedAccess, ProcessHandleCount, SystemHandleCount );
  99. }
  100. VOID
  101. DeleteAProc(
  102. IN PVOID Object
  103. )
  104. {
  105. DbgPrint( "DeleteAProc: %lx\n", Object );
  106. }
  107. NTSTATUS
  108. ParseAProc(
  109. IN PVOID ParseObject,
  110. IN ULONG DesiredAccess,
  111. IN KPROCESSOR_MODE AccessMode,
  112. IN ULONG Attributes,
  113. IN OUT PSTRING CompleteName,
  114. IN OUT PSTRING RemainingName,
  115. IN OUT PVOID Context OPTIONAL,
  116. OUT PVOID *Object
  117. )
  118. {
  119. DbgPrint( "ParseAProc: %lx\n", ParseObject );
  120. DbgPrint( " CompleteName: %.*s\n", CompleteName->Length,
  121. CompleteName->Buffer );
  122. DbgPrint( " RemainingName: %.*s\n", RemainingName->Length,
  123. RemainingName->Buffer );
  124. ObReferenceObjectByPointer(
  125. ParseObject,
  126. DesiredAccess,
  127. ObjectTypeA,
  128. AccessMode
  129. );
  130. *Object = ParseObject;
  131. return( STATUS_SUCCESS );
  132. }
  133. VOID
  134. DumpBProc(
  135. IN PVOID Object,
  136. IN POB_DUMP_CONTROL Control OPTIONAL
  137. )
  138. {
  139. POBJECTTYPEB p = (POBJECTTYPEB)Object;
  140. ULONG i;
  141. DbgPrint( "DumpBProc: %lx\n", p );
  142. DbgPrint( " Length: %ld\n", p->TypeBLength );
  143. for (i=0; i<16; i++) {
  144. DbgPrint( " Stuff[%ld]: %ld\n", i, p->Stuff[i] );
  145. }
  146. }
  147. VOID
  148. DeleteBProc(
  149. IN PVOID Object
  150. )
  151. {
  152. DbgPrint( "DeleteBProc: %lx\n", Object );
  153. }
  154. BOOLEAN
  155. obtest( void )
  156. {
  157. ULONG i;
  158. HANDLE Handles[ 2 ];
  159. NTSTATUS Status;
  160. OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
  161. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  162. RtlInitString( &ObjectTypeAName, "ObjectTypeA" );
  163. RtlInitString( &ObjectTypeBName, "ObjectTypeB" );
  164. RtlZeroMemory( &ObjectTypeInitializer, sizeof( ObjectTypeInitializer ) );
  165. ObjectTypeInitializer.Length = sizeof( ObjectTypeInitializer );
  166. ObjectTypeInitializer.ValidAccessMask = -1;
  167. ObjectTypeInitializer.PoolType = NonPagedPool;
  168. ObjectTypeInitializer.MaintainHandleCount = TRUE;
  169. ObjectTypeInitializer.DumpProcedure = DumpAProc;
  170. ObjectTypeInitializer.OpenProcedure = OpenAProc;
  171. ObjectTypeInitializer.CloseProcedure = CloseAProc;
  172. ObjectTypeInitializer.DeleteProcedure = DeleteAProc;
  173. ObjectTypeInitializer.ParseProcedure = ParseAProc;
  174. ObCreateObjectType(
  175. &ObjectTypeAName,
  176. &ObjectTypeInitializer,
  177. (PSECURITY_DESCRIPTOR)NULL,
  178. &ObjectTypeA
  179. );
  180. ObjectTypeInitializer.PoolType = NonPagedPool;
  181. ObjectTypeInitializer.MaintainHandleCount = FALSE;
  182. ObjectTypeInitializer.GenericMapping = MyGenericMapping;
  183. ObjectTypeInitializer.DumpProcedure = DumpBProc;
  184. ObjectTypeInitializer.OpenProcedure = NULL;
  185. ObjectTypeInitializer.CloseProcedure = NULL;
  186. ObjectTypeInitializer.DeleteProcedure = DeleteBProc;
  187. ObjectTypeInitializer.ParseProcedure = NULL;
  188. ObCreateObjectType(
  189. &ObjectTypeBName,
  190. &ObjectTypeInitializer,
  191. (PSECURITY_DESCRIPTOR)NULL,
  192. &ObjectTypeB
  193. );
  194. ObpDumpTypes( NULL );
  195. RtlInitString( &DirectoryName, "\\MyObjects" );
  196. InitializeObjectAttributes( &DirectoryObjA,
  197. &DirectoryName,
  198. OBJ_PERMANENT |
  199. OBJ_CASE_INSENSITIVE,
  200. NULL,
  201. NULL
  202. );
  203. NtCreateDirectoryObject( &DirectoryHandle,
  204. 0,
  205. &DirectoryObjA
  206. );
  207. NtClose( DirectoryHandle );
  208. RtlInitString( &ObjectAName, "\\myobjects\\ObjectA" );
  209. InitializeObjectAttributes( &ObjectAObjA,
  210. &ObjectAName,
  211. OBJ_CASE_INSENSITIVE,
  212. NULL,
  213. NULL
  214. );
  215. RtlInitString( &ObjectBName, "\\myobjects\\ObjectB" );
  216. InitializeObjectAttributes( &ObjectBObjA,
  217. &ObjectBName,
  218. OBJ_CASE_INSENSITIVE,
  219. NULL,
  220. NULL
  221. );
  222. Status = ObCreateObject(
  223. KernelMode,
  224. ObjectTypeA,
  225. &ObjectAObjA,
  226. KernelMode,
  227. NULL,
  228. (ULONG)sizeof( OBJECTTYPEA ),
  229. 0L,
  230. 0L,
  231. (PVOID *)&ObjectBodyA
  232. );
  233. ObjectA = (POBJECTTYPEA)ObjectBodyA;
  234. ObjectA->TypeALength = sizeof( *ObjectA );
  235. for (i=0; i<4; i++) {
  236. ObjectA->Stuff[i] = i+1;
  237. }
  238. KeInitializeEvent( &ObjectA->Event, NotificationEvent, TRUE );
  239. Status = ObCreateObject(
  240. KernelMode,
  241. ObjectTypeB,
  242. &ObjectBObjA,
  243. KernelMode,
  244. NULL,
  245. (ULONG)sizeof( OBJECTTYPEB ),
  246. 0L,
  247. 0L,
  248. (PVOID *)&ObjectBodyB
  249. );
  250. ObjectB = (POBJECTTYPEB)ObjectBodyB;
  251. ObjectB->TypeBLength = sizeof( *ObjectB );
  252. for (i=0; i<16; i++) {
  253. ObjectB->Stuff[i] = i+1;
  254. }
  255. KeInitializeSemaphore ( &ObjectB->Semaphore, 2L, 2L );
  256. Status = ObInsertObject(
  257. ObjectBodyA,
  258. SYNCHRONIZE | 0x3,
  259. NULL,
  260. 1,
  261. &ObjectBodyA,
  262. &ObjectHandleA1
  263. );
  264. DbgPrint( "Status: %lx ObjectBodyA: %lx ObjectHandleA1: %lx\n",
  265. Status, ObjectBodyA, ObjectHandleA1
  266. );
  267. Status = ObInsertObject(
  268. ObjectBodyB,
  269. SYNCHRONIZE | 0x1,
  270. NULL,
  271. 1,
  272. &ObjectBodyB,
  273. &ObjectHandleB1
  274. );
  275. DbgPrint( "Status: %lx ObjectBodyB: %lx ObjectHandleB1: %lx\n",
  276. Status, ObjectBodyB, ObjectHandleB1
  277. );
  278. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  279. RtlInitString( &ObjectAName, "\\MyObjects\\ObjectA" );
  280. InitializeObjectAttributes( &ObjectAObjA,
  281. &ObjectAName,
  282. OBJ_OPENIF,
  283. NULL,
  284. NULL
  285. );
  286. Status = ObCreateObject(
  287. KernelMode,
  288. ObjectTypeA,
  289. &ObjectAObjA,
  290. KernelMode,
  291. NULL,
  292. (ULONG)sizeof( OBJECTTYPEA ),
  293. 0L,
  294. 0L,
  295. (PVOID *)&ObjectBodyA1
  296. );
  297. Status = ObInsertObject(
  298. ObjectBodyA1,
  299. SYNCHRONIZE | 0x3,
  300. NULL,
  301. 1,
  302. &ObjectBodyA2,
  303. &ObjectHandleA2
  304. );
  305. DbgPrint( "Status: %lx ObjectBodyA1: %lx ObjectBodyA2: %lx ObjectHandleA2: %lx\n",
  306. Status, ObjectBodyA1, ObjectBodyA2, ObjectHandleA2
  307. );
  308. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  309. NtClose( ObjectHandleA2 );
  310. ObDereferenceObject( ObjectBodyA2 ); // ObInsertObject,ObjectPointerBias
  311. NtWaitForSingleObject( ObjectHandleB1, TRUE, NULL );
  312. Handles[ 0 ] = ObjectHandleA1;
  313. Handles[ 1 ] = ObjectHandleB1;
  314. NtWaitForMultipleObjects( 2, Handles, WaitAny, TRUE, NULL );
  315. ObReferenceObjectByHandle(
  316. ObjectHandleA1,
  317. 0L,
  318. ObjectTypeA,
  319. KernelMode,
  320. &ObjectBodyA,
  321. NULL
  322. );
  323. ObReferenceObjectByHandle(
  324. ObjectHandleB1,
  325. 0L,
  326. ObjectTypeB,
  327. KernelMode,
  328. &ObjectBodyB,
  329. NULL
  330. );
  331. DbgPrint( "Reference Handle %lx = %lx\n", ObjectHandleA1, ObjectBodyA );
  332. DbgPrint( "Reference Handle %lx = %lx\n", ObjectHandleB1, ObjectBodyB );
  333. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  334. ObReferenceObjectByPointer(
  335. ObjectBodyA,
  336. 0L,
  337. ObjectTypeA,
  338. KernelMode
  339. );
  340. ObReferenceObjectByPointer(
  341. ObjectBodyB,
  342. 0L,
  343. ObjectTypeB,
  344. KernelMode
  345. );
  346. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  347. RtlInitString( &ObjectAPathName, "\\MyObjects\\ObjectA" );
  348. RtlInitString( &ObjectBPathName, "\\MyObjects\\ObjectB" );
  349. ObReferenceObjectByName(
  350. &ObjectAPathName,
  351. OBJ_CASE_INSENSITIVE,
  352. 0L,
  353. ObjectTypeA,
  354. KernelMode,
  355. NULL,
  356. &ObjectBodyA
  357. );
  358. ObReferenceObjectByName(
  359. &ObjectBPathName,
  360. OBJ_CASE_INSENSITIVE,
  361. 0L,
  362. ObjectTypeB,
  363. KernelMode,
  364. NULL,
  365. &ObjectBodyB
  366. );
  367. DbgPrint( "Reference Name %s = %lx\n", ObjectAPathName.Buffer,
  368. ObjectBodyA );
  369. DbgPrint( "Reference Name %s = %lx\n", ObjectBPathName.Buffer,
  370. ObjectBodyB );
  371. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  372. ObDereferenceObject( ObjectBodyA ); // ObInsertObject,ObjectPointerBias
  373. ObDereferenceObject( ObjectBodyB );
  374. ObDereferenceObject( ObjectBodyA ); // ObReferenceObjectByHandle
  375. ObDereferenceObject( ObjectBodyB );
  376. ObDereferenceObject( ObjectBodyA ); // ObReferenceObjectByPointer
  377. ObDereferenceObject( ObjectBodyB );
  378. ObDereferenceObject( ObjectBodyA ); // ObReferenceObjectByName
  379. ObDereferenceObject( ObjectBodyB );
  380. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  381. InitializeObjectAttributes( &ObjectAObjA,
  382. &ObjectAPathName,
  383. OBJ_CASE_INSENSITIVE,
  384. NULL,
  385. NULL
  386. );
  387. ObOpenObjectByName(
  388. &ObjectAObjA,
  389. 0L,
  390. NULL,
  391. ObjectTypeA,
  392. KernelMode,
  393. NULL,
  394. &ObjectHandleA2
  395. );
  396. InitializeObjectAttributes( &ObjectBObjA,
  397. &ObjectBPathName,
  398. OBJ_CASE_INSENSITIVE,
  399. NULL,
  400. NULL
  401. );
  402. ObOpenObjectByName(
  403. &ObjectBObjA,
  404. 0L,
  405. NULL,
  406. ObjectTypeB,
  407. KernelMode,
  408. NULL,
  409. &ObjectHandleB2
  410. );
  411. DbgPrint( "Open Object Name %s = %lx\n", ObjectAPathName.Buffer,
  412. ObjectHandleA2 );
  413. DbgPrint( "Open Object Name %s = %lx\n", ObjectBPathName.Buffer,
  414. ObjectHandleB2 );
  415. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  416. NtClose( ObjectHandleA1 );
  417. NtClose( ObjectHandleB1 );
  418. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  419. ObReferenceObjectByHandle(
  420. ObjectHandleA2,
  421. 0L,
  422. ObjectTypeA,
  423. KernelMode,
  424. &ObjectBodyA,
  425. NULL
  426. );
  427. ObReferenceObjectByHandle(
  428. ObjectHandleB2,
  429. 0L,
  430. ObjectTypeB,
  431. KernelMode,
  432. &ObjectBodyB,
  433. NULL
  434. );
  435. DbgPrint( "Reference Handle %lx = %lx\n", ObjectHandleA2, ObjectBodyA );
  436. DbgPrint( "Reference Handle %lx = %lx\n", ObjectHandleB2, ObjectBodyB );
  437. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  438. ObOpenObjectByPointer(
  439. ObjectBodyA,
  440. OBJ_CASE_INSENSITIVE,
  441. 0L,
  442. NULL,
  443. ObjectTypeA,
  444. KernelMode,
  445. &ObjectHandleA1
  446. );
  447. ObOpenObjectByPointer(
  448. ObjectBodyB,
  449. OBJ_CASE_INSENSITIVE,
  450. 0L,
  451. NULL,
  452. ObjectTypeB,
  453. KernelMode,
  454. &ObjectHandleB1
  455. );
  456. DbgPrint( "Open Object Pointer %lx = %lx\n", ObjectBodyA,
  457. ObjectHandleA1 );
  458. DbgPrint( "Open Object Pointer %lx = %lx\n", ObjectBodyB,
  459. ObjectHandleB1 );
  460. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  461. ObReferenceObjectByHandle(
  462. ObjectHandleA1,
  463. 0L,
  464. ObjectTypeA,
  465. KernelMode,
  466. &ObjectBodyA,
  467. NULL
  468. );
  469. ObReferenceObjectByHandle(
  470. ObjectHandleB1,
  471. 0L,
  472. ObjectTypeB,
  473. KernelMode,
  474. &ObjectBodyB,
  475. NULL
  476. );
  477. DbgPrint( "Reference Handle %lx = %lx\n", ObjectHandleA1, ObjectBodyA );
  478. DbgPrint( "Reference Handle %lx = %lx\n", ObjectHandleB1, ObjectBodyB );
  479. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  480. ObDereferenceObject( ObjectBodyA ); // ObReferenceObjectByHandle
  481. ObDereferenceObject( ObjectBodyB );
  482. ObDereferenceObject( ObjectBodyA ); // ObReferenceObjectByHandle
  483. ObDereferenceObject( ObjectBodyB );
  484. NtClose( ObjectHandleA1 );
  485. NtClose( ObjectHandleB1 );
  486. NtClose( ObjectHandleA2 );
  487. NtClose( ObjectHandleB2 );
  488. ObpDumpObjectTable( ObpGetObjectTable(), NULL );
  489. TestFunction = NULL;
  490. return( TRUE );
  491. }
  492. int
  493. _CDECL
  494. main(
  495. int argc,
  496. char *argv[]
  497. )
  498. {
  499. #ifdef SIMULATOR
  500. extern ULONG MmNumberOfPhysicalPages;
  501. char *s;
  502. while (--argc) {
  503. s = *++argv;
  504. if (*s == '-') {
  505. s++;
  506. if (*s >= '0' && *s <= '9') {
  507. MmNumberOfPhysicalPages = atol( s );
  508. DbgPrint( "INIT: Configured with %d pages of physical memory.\n",
  509. MmNumberOfPhysicalPages
  510. );
  511. }
  512. else
  513. if (!strcmp( s, "SCR" )) {
  514. IoInitIncludeDevices |= IOINIT_SCREEN;
  515. DbgPrint( "INIT: Configured with Screen device driver.\n" );
  516. }
  517. else
  518. if (!strcmp( s, "MOU" )) {
  519. IoInitIncludeDevices |= IOINIT_MOUSE;
  520. DbgPrint( "INIT: Configured with Mouse device driver.\n" );
  521. }
  522. else
  523. if (!strcmp( s, "KBD" )) {
  524. IoInitIncludeDevices |= IOINIT_KEYBOARD;
  525. DbgPrint( "INIT: Configured with Keyboard device driver.\n" );
  526. }
  527. else
  528. if (!strcmp( s, "RAW" )) {
  529. IoInitIncludeDevices |= IOINIT_RAWFS;
  530. DbgPrint( "INIT: Configured with RAW File System driver.\n" );
  531. }
  532. else
  533. if (!strcmp( s, "FAT" )) {
  534. IoInitIncludeDevices |= IOINIT_FATFS;
  535. DbgPrint( "INIT: Configured with FAT File System driver.\n" );
  536. }
  537. else
  538. if (!strcmp( s, "SVR" )) {
  539. IoInitIncludeDevices |= IOINIT_DDFS |
  540. IOINIT_FATFS |
  541. IOINIT_SERVER_FSD |
  542. IOINIT_SERVER_LOOPBACK |
  543. IOINIT_NBF;
  544. if ( MmNumberOfPhysicalPages < 512 ) {
  545. MmNumberOfPhysicalPages = 512;
  546. }
  547. DbgPrint( "INIT: Configured for LAN Manager server.\n" );
  548. }
  549. else {
  550. DbgPrint( "INIT: Invalid switch - %s\n", s );
  551. }
  552. }
  553. else {
  554. break;
  555. }
  556. }
  557. #endif // SIMULATOR
  558. TestFunction = NULL;
  559. KiSystemStartup();
  560. return( 0 );
  561. }