summaryrefslogblamecommitdiffstats
path: root/private/os2/os2ses/util.c
blob: 47ce35dbef57d196a4eb61535639b5461897b67b (plain) (tree)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899


































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                           
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    util.c

Abstract:

    This module contains the common utilities used in OS2SES module

Author:

    Avi Nathan (avin) 17-Jul-1991

Environment:

    User Mode Only

Revision History:

--*/


#define WIN32_ONLY
#include "os2ses.h"
#include "os2win.h"

#include <stdio.h>
#include <stdlib.h>
#include <direct.h>
#include <string.h>
#include <ctype.h>

#if PMNT
#define INCL_32BIT
#include "pmnt.h"
#endif

/* ExitReason values (from os2v12.h/os2v20.h) */

#define TC_EXIT          0
#define TC_HARDERROR     1
#define TC_TRAP          2
#define TC_KILLPROCESS   3

typedef struct _UNICODE_STRING {
    USHORT Length;
    USHORT MaximumLength;
    PWSTR  Buffer;
} UNICODE_STRING, *PUNICODE_STRING;

typedef struct _STRING {
    USHORT Length;
    USHORT MaximumLength;
    PCHAR Buffer;
} STRING, *PSTRING;

BOOL
Or2CreateUnicodeStringFromMBz(
    OUT PUNICODE_STRING DestinationString,
    IN  PSZ SourceString
    );

DWORD
Or2MBStringToUnicodeString(
    PUNICODE_STRING DestinationString,
    PSTRING    SourceString,
    BOOL         AllocateDestinationString
    );

VOID
RtlFreeUnicodeString(
    PUNICODE_STRING UnicodeString
    );

DWORD
Ow2VioReadCurPos(
    );

DWORD
Ow2VioReadCurType();

DWORD
Ow2LvbUpdateLVBBuffer();

VOID
SetSessionParameters(
    IN  PVOID   SessionStartData,
    OUT PDWORD  pCreateFlags,
    IN  PSZ     ImageFileName,
#if PMNT
    IN  ULONG   IsPMApp,
#endif // PMNT
    OUT LPSTARTUPINFO pStartInfo
    );

int
Ow2DisplayHardErrorPopup(
    IN  int     Drive,
    IN  BOOLEAN WriteProtectError,
    IN  PUCHAR  AppName
    );

DWORD
Ow2HardErrorPopup(
    IN  int     Drive,
    IN  BOOLEAN WriteProtectError,
    OUT int *   ReturnedAction,
    IN  PUCHAR  AppName
    )
{
    int  RetVal;

    RetVal = Ow2DisplayHardErrorPopup(
                Drive,
                WriteProtectError,
                AppName
               );

    switch (RetVal) {
        case IDABORT:
            *ReturnedAction = OS2SS_IDABORT;
            break;

        case IDRETRY:
            *ReturnedAction = OS2SS_IDRETRY;
            break;

        default:
            *ReturnedAction = OS2SS_IDIGNORE;
            break;
    }
    return (0L);
}


HANDLE
Ow2GetNulDeviceHandle(
    VOID
    )
//
// NULL is returned if there is some system error
// and we can't open the nul device
//
{
    //
    // used to hold a handle to the win32 NUL device
    // this is needed to pass NUL redirections to win32 processes
    //
    static HANDLE Ow2NulDeviceHandle = NULL;
    HANDLE Hand;
    SECURITY_ATTRIBUTES Sa;

    if (Ow2NulDeviceHandle != NULL) {
        return(Ow2NulDeviceHandle);
    }

    Sa.nLength = sizeof(Sa);
    Sa.lpSecurityDescriptor = NULL;
    Sa.bInheritHandle = TRUE;

    Hand = CreateFileA("NUL",
                       GENERIC_READ|GENERIC_WRITE,
                       FILE_SHARE_READ|FILE_SHARE_WRITE,
                       &Sa,
                       OPEN_EXISTING,
                       0L,
                       NULL);

    if (Hand == INVALID_HANDLE_VALUE) {
#if DBG
        KdPrint(("OS2SES: Ow2GetNulDeviceHandle -- can't open NUL device, Error = %lx\n", GetLastError()));
#endif
        return(NULL);
    } else {
        Ow2NulDeviceHandle = Hand;
        return(Hand);
    }
}

    //
    // Interface for a direct call from client\conrqust.c
    //
DWORD
Ow2ExecPgm(
    IN  ULONG   Flags,
    IN  PSZ     Arguments OPTIONAL,
    IN  PSZ     Variables OPTIONAL,
    IN  PSZ     ImageFileName,
#if PMNT
    IN  ULONG   IsPMApp,
#endif // PMNT
    IN  PVOID   SessionStartData OPTIONAL,
    IN  POS2_STDHANDLES StdStruc,
    OUT HANDLE  *pHandle,
    OUT HANDLE  *tHandle,
    OUT ULONG   *dwProcessId
    )
{
    STARTUPINFO     StartInfo;
    STARTUPINFOW     StartInfoW;
    PROCESS_INFORMATION ProcessInfo;
    BOOL    b;
    DWORD   dwCreateFlags, status = 0;
    UNICODE_STRING ImageString_U;
    UNICODE_STRING ArgString_U;
    UNICODE_STRING TitleString_U;

    RtlZeroMemory(&StartInfo, sizeof(STARTUPINFO));
    StartInfo.cb = sizeof(STARTUPINFO);
    StartInfo.dwFlags = STARTF_USESHOWWINDOW;
    StartInfo.wShowWindow = SW_SHOWDEFAULT;

    dwCreateFlags = CREATE_SUSPENDED;

    if (Flags & EXEC_WINDOW_PROGRAM) {

       // This is a window program, so create it with CREATE_NEW_PROCESS_GROUP
       // (it will enable us to send CTRL_EVENT to all the group)

       // dwCreateFlags |= CREATE_NEW_PROCESS_GROUP;

       //
       // redirect standard handles if we need to
       //

       if (StdStruc->Flags & STDFLAG_ALL) {

           if (StdStruc->Flags & STDFLAG_IN) {
               StartInfo.hStdInput = StdStruc->StdIn;
           } else {
               StartInfo.hStdInput = SesGrp->StdIn;
           }

           if (StdStruc->Flags & STDFLAG_OUT) {
               StartInfo.hStdOutput = StdStruc->StdOut;
           } else {
               StartInfo.hStdOutput = SesGrp->StdOut;
           }

           if (StdStruc->Flags & STDFLAG_ERR) {
               StartInfo.hStdError = StdStruc->StdErr;
           } else {
               StartInfo.hStdError = SesGrp->StdErr;
           }

           StartInfo.dwFlags |= STARTF_USESTDHANDLES;
       }

       Flags &= ~EXEC_WINDOW_PROGRAM;
    }

    if (Flags == 4) {
       // EXEC_BACKGROUND == 4
       dwCreateFlags |= DETACHED_PROCESS;
    }

    if (SessionStartData)
    {
        SetSessionParameters(
            SessionStartData,
            &dwCreateFlags,
            ImageFileName,
#if PMNT
            IsPMApp,
#endif // PMNT
            &StartInfo
            );
    }

#if DBG
    IF_OD2_DEBUG(TEMP)
    {
        KdPrint(("OS2SES(util-Ow2ExecPgm): CreateProcess %s\n     Arg %s\n",
             ImageFileName, Arguments));
    }
#endif

        //
        // Translate all the OEM parameters (MB) to Unicode
        //

        //
        // ImageFileName
        //

    if (!(Or2CreateUnicodeStringFromMBz(
                &ImageString_U,
                ImageFileName
                   ))) {
        status = GetLastError();
#if DBG
        KdPrint(("OS2SES(util-Ow2ExecPgm): Fail to translate ImageFileName %s OEM to Unicode\n",
                    ImageFileName));
#endif
        return(status);
    }

        //
        // Arguments
        //

    if (!(Or2CreateUnicodeStringFromMBz(
                &ArgString_U,
                Arguments
                   ))) {
        status = GetLastError();
#if DBG
        KdPrint(("OS2SES(util-Ow2ExecPgm): Fail to translate Arguments %s OEM to Unicode\n",
                    Arguments));
#endif
        if (ImageFileName)
            RtlFreeUnicodeString(&ImageString_U);
        return(status);
    }

        //
        // StartupInfo
        //

    RtlMoveMemory(&StartInfoW, &StartInfo, sizeof(StartInfo));

    TitleString_U.Buffer = NULL;
    if (!(Or2CreateUnicodeStringFromMBz(
                &TitleString_U,
                StartInfo.lpTitle
                   ))) {
        status = GetLastError();
#if DBG
        KdPrint(("OS2SES(util-Ow2ExecPgm): Fail to translate Title %s OEM to Unicode\n",
                    StartInfo.lpTitle ));
#endif
        if (ImageFileName)
            RtlFreeUnicodeString(&ImageString_U);
        if (Arguments)
            RtlFreeUnicodeString(&ArgString_U);
        return(status);
    }

    StartInfoW.lpTitle = TitleString_U.Buffer;


    b = CreateProcessW(ImageString_U.Buffer,
                      ArgString_U.Buffer,
                      NULL,
                      NULL,
                      TRUE, // inherit all handles
                      dwCreateFlags,
                      Variables,
                      NULL,
                      &StartInfoW,
                      &ProcessInfo
                     );

        //
        // Free Unicode Strings
        //
    if (ImageFileName)
        RtlFreeUnicodeString(&ImageString_U);
    if (Arguments)
        RtlFreeUnicodeString(&ArgString_U);
    if (TitleString_U.Buffer)
        RtlFreeUnicodeString(&TitleString_U);

        //
        // check for error
        //
    if (!b) {
        status = GetLastError();
#if DBG
        KdPrint(("OS2SES(util-Ow2ExecPgm): CreateProcess of %s failed status = %x \n",
             ImageFileName, status));
#endif

        return(status);
    }

    *pHandle = ProcessInfo.hProcess;
    *tHandle = ProcessInfo.hThread;
    *dwProcessId = ProcessInfo.dwProcessId;

    return(status);
}


DWORD
CreateOS2SRV(
    OUT PHANDLE hProcess
    )
{
    STARTUPINFOW     StartInfo;
    PROCESS_INFORMATION ProcessInfo;
    BOOL    b;
    DWORD   status = 0;
    WCHAR   Path[MAX_PATH];
    UNICODE_STRING CdString_U;

    *hProcess = NULL;

    GetSystemDirectoryW((LPWSTR) &Path, MAX_PATH);

    if (!(Or2CreateUnicodeStringFromMBz(
                &CdString_U,
                getenv("SYSTEMROOT")
                   ))) {
        status = GetLastError();
#if DBG
        KdPrint(("OS2SES(util-CreateOS2SRV): Fail to translate curdir %s to Unicode, status %lx\n",
                    getenv("SYSTEMROOT"), status));
#endif
        return(status);
    }


    /*
    for ( i = 0 ; Path[i] ; i++ ) {
        Path[i] = toupper(Path[i]);
    }
    */

    wcscat(Path, L"\\OS2SRV.EXE");

    RtlZeroMemory(&StartInfo, sizeof(STARTUPINFOW));
    StartInfo.cb = sizeof(STARTUPINFOW);
    StartInfo.wShowWindow = SW_SHOWDEFAULT;

    if (fService)
        b = CreateProcessW(Path,
                      L"OS2SRV /S",
                      NULL,
                      NULL,
                      FALSE,
                      DETACHED_PROCESS,
                      NULL,
                      CdString_U.Buffer, //getenv("SYSTEMROOT"),
                      &StartInfo,
                      &ProcessInfo
                     );
    else
        b = CreateProcessW(Path,
                      L"",
                      NULL,
                      NULL,
                      FALSE,
                      DETACHED_PROCESS,
                      NULL,
                      CdString_U.Buffer, //getenv("SYSTEMROOT"),
                      &StartInfo,
                      &ProcessInfo
                     );
    if (!b) {
        status = GetLastError();
#if DBG
        KdPrint(("OS2SES(util-CreateOS2SRV): CreateProcess of OS2SRV failed status = %x \n",
             status));
#endif
        return(status);
    }

    *hProcess = ProcessInfo.hProcess;
    SetPriorityClass(*hProcess, REALTIME_PRIORITY_CLASS);
    RtlFreeUnicodeString(&CdString_U);

    return(status);

}


BOOL
ServeWinCreateProcess(PWINEXECPGM_MSG PReq, PVOID PStatus)
{
        DWORD       Rc = 0;

#if DBG
    IF_OD2_DEBUG( TASKING )
    {
        KdPrint(("OS2SES: ServeWinCreateProcess: Request: %u\n",
        PReq->Request));
    }
#endif

    switch (PReq->Request)
    {
        case RemoveConsoleThread:
            if ( SesGrp->WinSyncProcessNumberInSession == 0 )
            {
                Rc = RemoveConForWinProcess();
            }
            if (!Rc)
            {
                SesGrp->WinSyncProcessNumberInSession++ ;
                SesGrp->WinProcessNumberInSession++ ;
            }
            break;

        case RestartConsoleThread:

            // force CurPos, CurType and LVB to get updated

            Ow2VioReadCurPos();
            Ow2VioReadCurType();
            Ow2LvbUpdateLVBBuffer();

            if(SesGrp->WinSyncProcessNumberInSession == 1)
            {
                Rc = AddConAfterWinProcess();
            }

            SesGrp->WinSyncProcessNumberInSession--;
            SesGrp->WinProcessNumberInSession--;
            break;

        case AddWin32ChildProcess:
            SesGrp->WinProcessNumberInSession++;
            break;

        case RemWin32ChildProcess:

            // force CurPos, CurType and LVB to get updated

            Ow2VioReadCurPos();
            Ow2VioReadCurType();
            Ow2LvbUpdateLVBBuffer();

            SesGrp->WinProcessNumberInSession--;
            break;

        default:
            Rc = (DWORD) -1; //STATUS_INVALID_PARAMETER;
#if DBG
            KdPrint(("OS2SES(util-ServeWinCreateProcess): Unknown WinExec request = %X\n",
                      PReq->Request));
#endif
    }

    if ( Rc == 1 )
    {
/* BUGBUG=> BUGBUG! error code and returned Status are wrong */
        if (!(Rc = GetLastError()))
        {
#if DBG
            KdPrint(("OS2SES(util-ServeWinCreateProcess): Unknown LastError\n"));
#endif
            Rc = (DWORD) -1;
        }
    }

    *(PDWORD) PStatus = Rc;

    return(TRUE);  // Continue
}


VOID
Ow2WinExitCode2ResultCode(
                IN  DWORD  Status,
                OUT PDWORD pReturnCode,
                OUT PDWORD pExitReason)

/*++

Routine Description:

    This routine translate the ExitCode from Win32's GetExitCodeProcess
    to the OS/2 structure RESULTCODES fields: ExitReason and ExitResult.

Arguments:

    Status - the ExitCode from Win32 process.

    pReturnCode - where to put the translated ExitResult

    pExitReason - where to put the translated ExitReason

Return Value:


Note:


--*/
{
    *pReturnCode = Status;
    *pExitReason = TC_EXIT;

    if (*pReturnCode == STATUS_WAIT_0)
    {
        /*
        Success:

        STATUS_WAIT_O                    0x00000000L)   0
        */

    } else if (*pReturnCode == STATUS_CONTROL_C_EXIT)
    {
        /*
        STATUS_CONTROL_C_EXIT            0xC000013AL)   0
        */

        *pExitReason = TC_TRAP;
        *pReturnCode = 0;
    } else if (((ULONG)*pReturnCode >= (ULONG)STATUS_ARRAY_BOUNDS_EXCEEDED) &&
               ((ULONG)*pReturnCode <= (ULONG)STATUS_PRIVILEGED_INSTRUCTION))
    {
        /*
        STATUS_ARRAY_BOUNDS_EXCEEDED     0xC000008CL)    5
        STATUS_FLOAT_DENORMAL_OPERAND    0xC000008DL)   16
        STATUS_FLOAT_DIVIDE_BY_ZERO      0xC000008EL)   16
        STATUS_FLOAT_INEXACT_RESULT      0xC000008FL)   16
        STATUS_FLOAT_INVALID_OPERATION   0xC0000090L)   16
        STATUS_FLOAT_OVERFLOW            0xC0000091L)   16
        STATUS_FLOAT_STACK_CHECK         0xC0000092L)   16
        STATUS_FLOAT_UNDERFLOW           0xC0000093L)   16
        STATUS_INTEGER_DIVIDE_BY_ZERO    0xC0000094L)    0
        STATUS_INTEGER_OVERFLOW          0xC0000095L)    4
        STATUS_PRIVILEGED_INSTRUCTION    0xC0000096L)   13
        */

        if (*pReturnCode == STATUS_INTEGER_DIVIDE_BY_ZERO)
        {
            *pReturnCode = 0;
        } else if (*pReturnCode == STATUS_INTEGER_OVERFLOW)
        {
            *pReturnCode = 4;
        } else if (*pReturnCode == STATUS_PRIVILEGED_INSTRUCTION)
        {
            *pReturnCode = 13;
        } else if (*pReturnCode == STATUS_ARRAY_BOUNDS_EXCEEDED)
        {
            *pReturnCode = 5;
        } else
        {
            *pReturnCode = 16;
        }
        *pExitReason = TC_TRAP;
    } else if (*pReturnCode == STATUS_STACK_OVERFLOW)
    {
        /*
        STATUS_STACK_OVERFLOW            0xC00000FDL)   12
        */

        *pExitReason = TC_TRAP;
        *pReturnCode = 12;
    } else if (*pReturnCode == STATUS_DATATYPE_MISALIGNMENT)
    {
        /*
        STATUS_DATATYPE_MISALIGNMENT     0x80000002L)   17
        */

        *pExitReason = TC_TRAP;
        *pReturnCode = 17;
    } else if (*pReturnCode == STATUS_BREAKPOINT)
    {
        /*
        STATUS_BREAKPOINT                0x80000003L)    3
        */

        *pExitReason = TC_TRAP;
        *pReturnCode = 3;
    } else if (*pReturnCode == STATUS_SINGLE_STEP)
    {
        /*
        STATUS_SINGLE_STEP               0x80000004L)    1
        */

        *pExitReason = TC_TRAP;
        *pReturnCode = 1;
    } else if (*pReturnCode == STATUS_ACCESS_VIOLATION)
    {
        /*
        STATUS_ACCESS_VIOLATION          0xC0000005L)   13
        */

        *pExitReason = TC_TRAP;
        *pReturnCode = 13;
    } else if (*pReturnCode == STATUS_ILLEGAL_INSTRUCTION)
    {
        /*
        STATUS_ILLEGAL_INSTRUCTION       0xC000001DL)    6
        */

        *pExitReason = TC_TRAP;
        *pReturnCode = 6;
    } else if ((*pReturnCode == STATUS_ABANDONED_WAIT_0) ||
               (*pReturnCode == STATUS_USER_APC) ||
               (*pReturnCode == STATUS_TIMEOUT) ||
               (*pReturnCode == STATUS_PENDING) ||
               (*pReturnCode == STATUS_NONCONTINUABLE_EXCEPTION) ||
               (*pReturnCode == STATUS_INVALID_DISPOSITION))
    {
        /*
        STATUS_WAIT_0                    0x00000000L)  ??
        STATUS_ABANDONED_WAIT_0          0x00000080L)  255
        STATUS_USER_APC                  0x000000C0L)  255
        STATUS_TIMEOUT                   0x00000102L)  255
        STATUS_PENDING                   0x00000103L)  255
        STATUS_NONCONTINUABLE_EXCEPTION  0xC0000025L)  255
        STATUS_INVALID_DISPOSITION       0xC0000026L)  255
        */

        *pExitReason = TC_TRAP;
        *pReturnCode = 255;
    }
#if DBG
    IF_OD2_DEBUG3( OS2_EXE, TASKING, WIN )
    {
        KdPrint(("Ow2WinExitCode2ResultCode: Status %lu => Result %lu, Reason %lu\n",
                Status, *pReturnCode, *pExitReason));
    }
#endif

    return;
}


typedef struct _STARTDATA {
    USHORT  Length;
    USHORT  Related;
    USHORT  FgBg;
    USHORT  TraceOpt;
    PSZ     PgmTitle;
    PSZ     PgmName;
    PBYTE   PgmInputs;
    PBYTE   TermQ;
    PBYTE   Environment;
    USHORT  InheritOpt;
    USHORT  SessionType;
    PSZ     IconFile;
    ULONG   PgmHandle;
    USHORT  PgmControl;
    USHORT  InitXPos;
    USHORT  InitYPos;
    USHORT  InitXSize;
    USHORT  InitYSize;
    USHORT  Reserved;
    PSZ     ObjectBuffer;
    ULONG   ObjectBuffLen;
} STARTDATA, *PSTARTDATA;


VOID
SetSessionParameters(
    IN  PVOID   SessionStartData,
    OUT PDWORD  pCreateFlags,
    IN  PSZ     ImageFileName,
#if PMNT
    IN  ULONG   IsPMApp,
#endif // PMNT
    OUT LPSTARTUPINFO pStartInfo
    )
{
    PSTARTDATA  pStartData = (PSTARTDATA)SessionStartData;
    ULONG       Length = pStartData->Length, i;
    PUCHAR      Title;

#if PMNT
    //
    // Don't create console for PM process that is the child session of other PM
    // process.
    //
    if (!ProcessIsPMApp() || (!IsPMApp) || (!pStartData->Related)) {
#endif
        *pCreateFlags |= CREATE_NEW_CONSOLE;
#if PMNT
    }
#endif

    Title = (pStartData->PgmTitle) ? pStartData->PgmTitle : ImageFileName;
    i = strlen(Title);
    if (i > 32)
    {
        Title += ( i - 32 );
        i = 32;
    }

    if (!pStartData->PgmTitle)
        //
        // we give the pathname, strip out the last component
        //
    {
#ifdef DBCS
// MSKK Jun.16.1993 V-AkihiS
        {
            ULONG LastComponentPos = 0;
            ULONG j;

            for (j = 0; j < i; )
            {
                if (Ow2NlsIsDBCSLeadByte(Title[j], SesGrp->DosCP)) {
                    j++;
                    if (j < i) {
                        j++;
                    }
                } else {
                    if ((Title[j] == '\\' ) ||
                        (Title[j] == '/' ) ||
                        (Title[j] == ':' )) {
                        LastComponentPos = j;
                    }
                    j++;
                }
            }
            Title += j + 1;
        }
#else
        for ( ; i ; i-- )
        {
            if ((Title[i - 1] == '\\' ) ||
                (Title[i - 1] == '/' ) ||
                (Title[i - 1] == ':' ))
            {
                Title += i;
                break;
            }
        }
#endif
    }

    pStartInfo->lpTitle = Title;
    pStartInfo->dwXSize = (DWORD)SesGrp->ScreenColNum;
    pStartInfo->dwYSize = (DWORD)SesGrp->ScreenRowNum;

    if (Length > 40)
    {
        if (pStartData->PgmControl & 0x8000)          // window position & size
        {
            if (Length > 42)
            {
                pStartInfo->dwX = (DWORD)(pStartData->InitXPos / SesGrp->CellHSize);
            }
            if (Length > 44)
            {
                pStartInfo->dwY = (DWORD)(pStartData->InitYPos / SesGrp->CellVSize);
            }
            if (Length > 46)
            {
                pStartInfo->dwXSize = (DWORD)(pStartData->InitXSize / SesGrp->CellHSize);
            }
            if (Length > 48)
            {
                pStartInfo->dwYSize = (DWORD)(pStartData->InitYSize / SesGrp->CellVSize);
            }
            pStartInfo->dwFlags |= (STARTF_USESIZE | STARTF_USEPOSITION);
        }

        if (!pStartData->FgBg)                    // window ForeGround
        {
            if (pStartData->PgmControl == 0)                  // invisible
            {
                //pStartInfo->dwFlags |= (STARTF_USESIZE | STARTF_USEPOSITION);
            } else
            {
                if (pStartData->PgmControl & 2)               // maximize
                {
                    pStartInfo->wShowWindow = SW_SHOWMAXIMIZED;
                }

                if (pStartData->PgmControl & 4)               // minimize
                {
                    pStartInfo->wShowWindow = SW_SHOWMINIMIZED;
                }
            }
        } else                                  // window BackGround
        {
            if (pStartData->PgmControl == 0)                  // invisible
            {
                //pStartInfo->dwFlags |= (STARTF_USESIZE | STARTF_USEPOSITION);
            } else
            {
                if (pStartData->PgmControl & 2)               // maximize
                {
                    pStartInfo->wShowWindow = SW_MAXIMIZE;
                }

                if (pStartData->PgmControl & 4)               // minimize
                {
                    pStartInfo->wShowWindow = SW_MINIMIZE;
                }
            }
        }
    } else
    {
        if (!pStartData->FgBg)                    // window ForeGround
        {
            //pStartInfo->wShowWindow |= STARTF_USESIZE;
        }

    }

    if (pStartInfo->wShowWindow)
    {
        pStartInfo->dwFlags |= STARTF_USESHOWWINDOW;
    }

    // ((Length > 30 ) ? pStartData->SessionType : 0);
    // TmpInheritOpt;
}