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.

134 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. turtl.c
  5. Abstract:
  6. Test program for the NT OS User Mode Runtime Library (URTL)
  7. Author:
  8. Steve Wood (stevewo) 18-Aug-1989
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. NTSTATUS
  15. main(
  16. int argc,
  17. char *argv[],
  18. char *envp[]
  19. )
  20. {
  21. NTSTATUS Status;
  22. STRING ImagePathName;
  23. CHAR ImageNameBuffer[ 128 ];
  24. RTL_USER_PROCESS_INFORMATION ProcessInformation;
  25. PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
  26. ULONG i, CountBytes, envc, Bogus;
  27. PSTRING DstString;
  28. PCH Src, Dst;
  29. #if DBG
  30. DbgPrint( "Entering URTL User Mode Test Program\n" );
  31. DbgPrint( "argc = %ld\n", argc );
  32. for (i=0; i<=argc; i++) {
  33. DbgPrint( "argv[ %ld ]: %s\n",
  34. i,
  35. argv[ i ] ? argv[ i ] : "<NULL>"
  36. );
  37. }
  38. DbgPrint( "\n" );
  39. for (i=0; envp[i]; i++) {
  40. DbgPrint( "envp[ %ld ]: %s\n", i, envp[ i ] );
  41. }
  42. #endif
  43. envc = 0;
  44. for (i=0; envp[i]; i++) {
  45. envc++;
  46. }
  47. if (envc > argc) {
  48. envc = argc;
  49. }
  50. CountBytes = sizeof( *ProcessParameters ) +
  51. argc * sizeof( STRING ) + envc * sizeof( STRING );
  52. for (i=0; i<argc; i++) {
  53. CountBytes += strlen( argv[ i ] );
  54. }
  55. for (i=0; i<envc; i++) {
  56. CountBytes += strlen( envp[ i ] );
  57. }
  58. ProcessParameters = (PRTL_USER_PROCESS_PARAMETERS)RtlAllocate( CountBytes );
  59. DstString = (PSTRING)((PCH)ProcessParameters +
  60. sizeof( *ProcessParameters ));
  61. ProcessParameters->TotalLength = CountBytes;
  62. ProcessParameters->ArgumentCount = argc;
  63. ProcessParameters->Arguments = DstString;
  64. DstString += argc;
  65. ProcessParameters->VariableCount = envc;
  66. ProcessParameters->Variables = DstString;
  67. DstString += envc;
  68. Dst = (PCH)DstString;
  69. DstString = ProcessParameters->Arguments;
  70. for (i=0; i<argc; i++) {
  71. DstString->Buffer = Dst;
  72. Src = argv[ i ];
  73. while (*Dst++ = *Src++) {
  74. DstString->Length++;
  75. }
  76. DstString->MaximumLength = DstString->Length + 1;
  77. DstString++;
  78. }
  79. for (i=0; i<envc; i++) {
  80. DstString->Buffer = Dst;
  81. Src = envp[ i ];
  82. while (*Dst++ = *Src++) {
  83. DstString->Length++;
  84. }
  85. DstString->MaximumLength = DstString->Length + 1;
  86. DstString++;
  87. }
  88. RtlDeNormalizeProcessParameters( ProcessParameters );
  89. ImagePathName.Buffer = ImageNameBuffer;
  90. ImagePathName.Length = 0;
  91. ImagePathName.MaximumLength = sizeof( ImageNameBuffer );
  92. if (RtlResolveImageName( "TURTL1.SIM", &ImagePathName )) {
  93. Status = RtlCreateUserProcess( &ImagePathName,
  94. NULL,
  95. NULL,
  96. NULL,
  97. TRUE,
  98. ProcessParameters,
  99. &ProcessInformation,
  100. NULL
  101. );
  102. if (NT_SUCCESS( Status )) {
  103. Status = NtResumeThread( ProcessInformation.Thread, &Bogus );
  104. if (NT_SUCCESS( Status )) {
  105. #if DBG
  106. DbgPrint( "URTL waiting for URTL1...\n" );
  107. #endif
  108. Status = NtWaitForSingleObject( ProcessInformation.Process,
  109. TRUE,
  110. NULL
  111. );
  112. }
  113. }
  114. }
  115. #if DBG
  116. DbgPrint( "Leaving URTL User Mode Test Program\n" );
  117. #endif
  118. return( Status );
  119. }