summaryrefslogtreecommitdiffstats
path: root/private/urtl/turtl.c
blob: 6d0fa7af5694b90cef54e82c41f742fb8e4a2efa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    turtl.c

Abstract:

    Test program for the NT OS User Mode Runtime Library (URTL)

Author:

    Steve Wood (stevewo) 18-Aug-1989

Revision History:

--*/

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>

NTSTATUS
main(
    int argc,
    char *argv[],
    char *envp[]
    )
{
    NTSTATUS Status;
    STRING ImagePathName;
    CHAR ImageNameBuffer[ 128 ];
    RTL_USER_PROCESS_INFORMATION ProcessInformation;
    PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
    ULONG i, CountBytes, envc, Bogus;
    PSTRING DstString;
    PCH Src, Dst;

#if DBG
    DbgPrint( "Entering URTL User Mode Test Program\n" );
    DbgPrint( "argc = %ld\n", argc );
    for (i=0; i<=argc; i++) {
        DbgPrint( "argv[ %ld ]: %s\n",
                  i,
                  argv[ i ] ? argv[ i ] : "<NULL>"
                );
        }
    DbgPrint( "\n" );
    for (i=0; envp[i]; i++) {
        DbgPrint( "envp[ %ld ]: %s\n", i, envp[ i ] );
        }
#endif
    envc = 0;
    for (i=0; envp[i]; i++) {
        envc++;
        }
    if (envc > argc) {
        envc = argc;
        }
    CountBytes = sizeof( *ProcessParameters ) +
                 argc * sizeof( STRING ) + envc * sizeof( STRING );
    for (i=0; i<argc; i++) {
        CountBytes += strlen( argv[ i ] );
        }
    for (i=0; i<envc; i++) {
        CountBytes += strlen( envp[ i ] );
        }
    ProcessParameters = (PRTL_USER_PROCESS_PARAMETERS)RtlAllocate( CountBytes );
    DstString = (PSTRING)((PCH)ProcessParameters +
                          sizeof( *ProcessParameters ));
    ProcessParameters->TotalLength = CountBytes;
    ProcessParameters->ArgumentCount = argc;
    ProcessParameters->Arguments = DstString;
    DstString += argc;
    ProcessParameters->VariableCount = envc;
    ProcessParameters->Variables = DstString;
    DstString += envc;
    Dst = (PCH)DstString;
    DstString = ProcessParameters->Arguments;
    for (i=0; i<argc; i++) {
        DstString->Buffer = Dst;
        Src = argv[ i ];
        while (*Dst++ = *Src++) {
            DstString->Length++;
            }
        DstString->MaximumLength = DstString->Length + 1;
        DstString++;
        }
    for (i=0; i<envc; i++) {
        DstString->Buffer = Dst;
        Src = envp[ i ];
        while (*Dst++ = *Src++) {
            DstString->Length++;
            }
        DstString->MaximumLength = DstString->Length + 1;
        DstString++;
        }
    RtlDeNormalizeProcessParameters( ProcessParameters );

    ImagePathName.Buffer = ImageNameBuffer;
    ImagePathName.Length = 0;
    ImagePathName.MaximumLength = sizeof( ImageNameBuffer );
    if (RtlResolveImageName( "TURTL1.SIM", &ImagePathName )) {
        Status = RtlCreateUserProcess( &ImagePathName,
                                       NULL,
                                       NULL,
                                       NULL,
                                       TRUE,
                                       ProcessParameters,
                                       &ProcessInformation,
                                       NULL
                                     );
        if (NT_SUCCESS( Status )) {
            Status = NtResumeThread( ProcessInformation.Thread, &Bogus );
            if (NT_SUCCESS( Status )) {
#if DBG
                DbgPrint( "URTL waiting for URTL1...\n" );
#endif
                Status = NtWaitForSingleObject( ProcessInformation.Process,
                                                TRUE,
                                                NULL
                                              );
                }
            }
        }

#if DBG
    DbgPrint( "Leaving URTL User Mode Test Program\n" );
#endif

    return( Status );
}