summaryrefslogblamecommitdiffstats
path: root/private/os2/inc/os2srv.h
blob: 8b80171b2105844edb1e5c06d86e1f838d5f0b67 (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
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650

















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    os2srv.h

Abstract:

    Main include file for OS/2 Subsystem Server

Author:

    Steve Wood (stevewo) 22-Aug-1989

Revision History:

    Yaron Shamor 4-Apr-91 Add profile for ComputeValidDrives.
--*/

//
// Include OS/2 SubSystem Runtime Definitions.  Includes NT Definitions,
// OS/2 V2.0 Definitions and Debug definitions.
//

#include "os2ssrtl.h"

#if DBG
ULONG Os2Debug;
#endif

// Flag to let OS2SRV know whether or not to ignore LOGOFF (when started as a service)
extern BOOLEAN fService;

//
// Include NT Session Manager and Debug SubSystem Interfaces

#include <ntsm.h>
#include <ntdbg.h>
typedef BOOLEAN (*PSB_API_ROUTINE)( IN PSBAPIMSG SbApiMsg );


#include "os2file.h"
#include "os2ssmsg.h"

//
// OS/2 Subsystem Semaphore structures.
//

typedef enum _OS2_SEMAPHORE_TYPE {
    Os2EventSem = 1,
    Os2MutexSem,
    Os2MuxWaitSem
} OS2_SEMAPHORE_TYPE;

typedef struct _OS2_MUXWAIT_RECORD {
    ULONG SemHandleIndex;
    ULONG UserKey;
    struct _OS2_SEMAPHORE *Semaphore;
} OS2_MUXWAIT_RECORD, *POS2_MUXWAIT_RECORD;

typedef struct _OS2_MUXWAIT_SEMAPHORE {
    USHORT CountMuxWaitRecords;
    USHORT Type : 2;
    USHORT WaitAll : 1;
    USHORT Reserved : 13;
    OS2_MUXWAIT_RECORD MuxWaitRecords[ DCMW_MAX_SEMRECORDS ];
} OS2_MUXWAIT_SEMAPHORE, *POS2_MUXWAIT_SEMAPHORE;

typedef struct _OS2_SEMAPHORE {
    USHORT PointerCount : 14;
    USHORT Type : 2;
    USHORT OpenCount;
    STRING Name;
    union {
        PVOID Value;
        HANDLE EventHandle;
        HANDLE MutantHandle;
        POS2_MUXWAIT_SEMAPHORE MuxWait;
    } u;
} OS2_SEMAPHORE, *POS2_SEMAPHORE;


typedef struct _OS2_SESSION {
    LIST_ENTRY SessionLink;
    ULONG SessionId;
    ULONG ReferenceCount;
    ULONG TerminationQueueHandle;
    struct _OS2_QUEUE *TerminationQueue;
    struct _OS2_SESSION *RelatedSession;
    struct _OS2_SESSION *BindSession;
    HANDLE ConsolePort;
    ULONG  SessionUniqueId;
    ULONG  ProcessId;
    BOOLEAN Selectable;
    USHORT  FgBg;           // TRUE for background
    USHORT  InheritOpt;
    BOOLEAN ChildSession;
    BOOLEAN WinSession;
    PVOID   Thread;
    PVOID   Process;
    HANDLE  hWaitThread;
    HANDLE  hProcess;
    ULONG   dwProcessId;
    ULONG   dwParentProcessId;
    HANDLE  SesGrpHandle;
    PVOID   SesGrpAddress;
    BOOLEAN InTermination;
    HANDLE  Win32ForegroundWindow;
    struct _OS2_REGISTER_HANDLER_REC *RegisterCtrlHandler;
} OS2_SESSION, *POS2_SESSION;

typedef struct _OS2_NT_SESSION {
    LIST_ENTRY SessionLink;
    ULONG SessionId;
    ULONG ReferenceCount;
    STRING RootDirectory;
} OS2_NT_SESSION, *POS2_NT_SESSION;

typedef struct _OS2_THREAD {
    LIST_ENTRY Link;
    struct _OS2_PROCESS *Process;
    struct _OS2_WAIT_BLOCK *WaitBlock;
    POS2_SEMAPHORE WaitingForSemaphore;
    CLIENT_ID ClientId;
    TID ThreadId;
    HANDLE ThreadHandle;
    POS2_TIB ClientOs2Tib;
    ULONG Flags;
    KPRIORITY Priority;
    USHORT PendingSignals;
    USHORT CurrentSignals;
    USHORT MustComplete;
    USHORT DebugState;         // A flag for DosPtrace().
    BOOLEAN Dying;
    CHAR Os2Level;
    UCHAR Os2Class;
    ULONG InitialStack;
} OS2_THREAD, *POS2_THREAD;

//
// Flag definitions for OS2_THREAD.Flags
//

#define OS2_THREAD_THREAD1  0x00000001
#define OS2_THREAD_ATTACHED 0x00000002

#ifdef PMNT
#define PMNTFIRSTHIDDENTHREAD 40   // There is a check for Maximum thread in
                                   // pmwin\wintodos.inc     MAXTHRDID = 52
                                   // Maximum #threads per process handled by
                                   // AAB.ASM.  Assumes thread IDs range from
                                   // 0 to MAXTHRDID-1
#define PMNTMAXHIDDENTHREADS  10   // We allocated 10 PMNT hidden threads with
                                   // Tid 40-50. See process.c os2allocatetid
#endif

#define OS2_EXIT_IN_PROGRESS     0x00000001
#define OS2_EXIT_WAIT_FOR_SYNC   0x00000002

typedef struct _OS2_PROCESS {
    LIST_ENTRY ListLink;
    struct _OS2_PROCESS *Parent;
    LIST_ENTRY ChildrenList;
    LIST_ENTRY SiblingLink;
    LIST_ENTRY ThreadList;
    LIST_ENTRY SharedMemoryList;
    POS2_NT_SESSION NtSession;
    POS2_SESSION Session;
    PVOID ExitListDispatcher;
    PVOID InfiniteSleep;
    PVOID SignalDeliverer;
    PVOID FreezeThread;
    PVOID UnfreezeThread;
    PVOID VectorHandler;
    PVOID CritSectionAddr;
    PVOID TidBitMapHeader;
    PEB_OS2_DATA InitialPebOs2Data;
    RESULTCODES ResultCodes;
    ULONG ExpectedVersion;
    HANDLE ClientPort;
    PCH ClientViewBase;
    PCH ClientViewBounds;
    CLIENT_ID ClientId;
    PID ProcessId;
    PID CommandSubTreeId;
    HANDLE ProcessHandle;
    PPIB ClientPib;
//    ULONG LastThreadId; removed after TidBitMapHeader was added
#ifdef PMNT
    ULONG LastHiddenThreadId;
#endif
    ULONG Flags;
    USHORT ExceptionFocus;
    PFILE_HANDLE HandleTable;   // temporary copy of the file handle table during exec
    ULONG HandleTableLength;    // length of handle table
    ULONG ErrorAction;
    BOOLEAN CtrlHandlerFlag;
    ULONG   ExitStatus;         // 2 bits:
                                // Exit in progress
                                // Wait for sync during exit processing
    UCHAR   ApplName[OS2_PROCESS_MAX_APPL_NAME];
    ULONG   ApplNameLength;
    TID     DebugThreadId;
    PVOID   ProcessMTE;         // Pointer to process MTE structure
    BOOLEAN FirstPtrace;        // A flag for first DosPtrace(0xA)
    PVOID   FirstMTE;           // Pointer to the mte that has the INT 3 we inserted for DosPtrace()
    PVOID   LinkMte;            // Link list of mte's to transfer to a debugger process
    BOOLEAN ConfigSysUsageFlag; // TRUE if process used config.sys during its life
} OS2_PROCESS, *POS2_PROCESS;

typedef struct _OS2_REGISTER_HANDLER_REC {
    ULONG Signal;
    ULONG fAction;
    POS2_PROCESS Process;
    struct _OS2_REGISTER_HANDLER_REC *Link;
} OS2_REGISTER_HANDLER_REC, *POS2_REGISTER_HANDLER_REC;

//
// Flags field bit definitions
//

// When process terminates if no process is waiting for result, put the
// process in the zombie list so that DosWaitChild can find it and return
// the result.
//
#define OS2_PROCESS_SAVERESULT  0x00000001

// The process was invoked synchronously and the client is waiting for a
// response to their DosExecPgm request when this process terminates.
//
#define OS2_PROCESS_SYNCHRONOUS 0x00000002

// The process was invoked detached from the console and does not get any
// handles to the console device (keyboard, mouse and/or screen).
//
#define OS2_PROCESS_BACKGROUND  0x00000004

// The process was invoked in z suspended state.  It may be resumed with the
// DosSystemService API call.
//
#define OS2_PROCESS_FROZEN      0x00000008

// The process may be modified via the Debug Subsystem.  FIX, FIX - what does
// this really mean.
//
#define OS2_PROCESS_TRACE       0x00000010

// Any child process created by this process inherits the OS2_PROCESS_TRACE????
// flags.
//
#define OS2_PROCESS_TRACETREE   0x00000020

// The process is terminating after DosPtrace() with a TERMINATE command.
//
#define OS2_PROCESS_TERMINATE   0x00000040

// Process is doing ExitList processing
//
#define OS2_PROCESS_EXIT        0x00010000

// // Obsolete code below: OS/2 ss was keeping processes around as zombie so
// //  that DosCWait doesn't fail when father calls it after child termination.
// //  However, it turns out that OS/2 doesn't do this.
//
// // Process is linked into the zombie list.
// //
// #define OS2_PROCESS_ZOMBIE      0x00020000

// Process cannot run in the PM screen
//
#define OS2_PROCESS_NOTWINDOWCOMPAT 0x00040000

// Process can run in a PM screen
//
#define OS2_PROCESS_WINDOWCOMPAT 0x00080000

// Process is using PM APIs
//
#define OS2_PROCESS_WINDOWAPI   0x00100000

// Process is PMSHELL - special handling for GPs
//
#define OS2_PROCESS_IS_PMSHELL  0x00200000

#if PMNT
// Process is Forced PM process (PM but not marked as WINDOWAPI)
//
#define OS2_PROCESS_FORCEDPM  0x00400000

// Process calls WinCreateMsgQueue()
//
#define OS2_PROCESS_PMMSGQUE  0x00800000

#define Os2srvProcessIsPMProcess(Process) (Process->Flags & (OS2_PROCESS_WINDOWAPI \
 | OS2_PROCESS_PMMSGQUE | OS2_PROCESS_FORCEDPM))
#endif
//
// ProcessId limits
//

#define PID_MIN         0x00000001      // Lowest process id
#define PID_MAX         0x0000FFFF      // Highest process id

//
// ProcessStatus field flag bits.  All but the first are private to OS/2
//

#define PS_XITLST       PS_EXITLIST     // Doing ExitList Processing
#define PS_XITTH1       0x00000002      // Exiting thread 1
#define PS_XITALL       0x00000004      // The whole process is exiting
#define PS_SYNCPARENT   0x00000010      // Parent cares about termination
#define PS_WAITPARENT   0x00000020      // Parent did an exec-and-wait
#define PS_DYING        0x00000040      // Process is dying
#define PS_EMBRYO       0x00000080      // Process in embryonic state

#define AcquireLocalObjectLock(AssociatedHandleTable) RtlEnterCriticalSection( &(AssociatedHandleTable)->Lock );
#define ReleaseLocalObjectLock(AssociatedHandleTable) RtlLeaveCriticalSection( &(AssociatedHandleTable)->Lock );
//
// All exported API calls define the same interface to the OS/2 Server Request
// loop.  The return value indicates to the request loop whether or not to
// generate a reply to the client.
//

typedef BOOLEAN (*POS2_API_ROUTINE)( IN POS2_THREAD t, IN POS2_API_MSG m );

BOOLEAN Os2InternalNullApiCall( IN POS2_THREAD t, IN POS2_API_MSG m );


//
// Global data accessed by OS/2 Subsystem Server
//

#if DBG
ULONG Os2DebugFlag;
#endif // DBG

PVOID Os2Heap;

ULONG Os2BootDrive;
ULONG Os2DefaultDrive;
ULONG Os2ValidDrives;
PSZ   *environ;
PSZ   SystemRootValuePtr;

HANDLE Os2RootDirectory;
HANDLE Os2DrivesDirectory;
HANDLE Os2DevicesDirectory;

STRING Os2DebugPortName;
UNICODE_STRING Os2DebugPortName_U;
HANDLE Os2DebugPort;

STRING Os2ExceptionPortName;
UNICODE_STRING Os2ExceptionPortName_U;
HANDLE Os2ExceptionPort;

UNICODE_STRING Os2SbApiPortName_U;
HANDLE Os2SbApiPort;
HANDLE Os2SmApiPort;

/*
 * Port and threads for Console Session globals.
 */
HANDLE Os2SessionPort;

HANDLE Os2SessionRequestThreadHandle;


#define OS2_SS_SBAPI_PORT_NAME L"\\OS2SS\\SbApiPort"

#define OS2_SS_API_LISTEN_THREAD 0
#define OS2_SS_SBAPI_REQUEST_THREAD 1
#define OS2_SS_FIRST_API_REQUEST_THREAD 2

#define OS2_SS_MAX_THREADS 64

HANDLE Os2ServerThreadHandles[ OS2_SS_MAX_THREADS ];
HANDLE Os2DebugThreadHandle;
CLIENT_ID Os2ServerThreadClientIds[ OS2_SS_MAX_THREADS ];
CLIENT_ID Os2DebugThreadClientId;

POR2_HANDLE_TABLE Os2SharedSemaphoreTable;

CLIENT_ID Os2DebugUserClientId;


//
// Routines defined in srvinit.c
//

NTSTATUS
Os2Initialize( VOID );

BOOLEAN
Os2SrvHandleCtrlEvent(
    IN int CtrlType
    );

ULONG
NtGetIntegerFromUnicodeString(
    IN WCHAR *WString
    );

//
// Routines defined in srvnls.c
//
// Note: srvnls.c doesn't include this file. It includes <windows.h> instead
// of <nt.h>.
// All callers to Win32 APIs (like SetConsoleCtrlHandler) should be put there.
//

ULONG    Os2ssCountryCode;
ULONG    Os2ssCodePage[2];
UCHAR    Os2ssKeyboardLayout[2];
#if PMNT
UCHAR    Os2ssKeyboardName[4];  // Allow space for keyboard sub-code (103,
                                // 189, 150G etc.)
#endif
ULONG    Os2ssKeysOnFlag;
ULONG    Os2SrvExitNow;

VOID
Os2SrvExitProcess(IN ULONG  uExitCode);

APIRET
Os2InitializeNLS( VOID );

VOID
SetEventHandlersAndErrorMode(
    IN BOOLEAN fSet
    );

//
// Routines defined in srvobjmn.c
//

typedef enum _OS2_LOCAL_OBJECT_TYPE {
    LocalObjectAnyType,
    LocalObjectQueue,
    MaxLocalObject
} OS2_LOCAL_OBJECT_TYPE;

typedef struct _OS2_LOCAL_OBJECT_DIRENT {
    STRING ObjectName;
    OS2_LOCAL_OBJECT_TYPE ObjectType;
    ULONG ObjectHandle;
} OS2_LOCAL_OBJECT_DIRENT, *POS2_LOCAL_OBJECT_DIRENT;

NTSTATUS
Os2InitializeLocalObjectManager( VOID );

RTL_GENERIC_TABLE Os2LocalObjectNames;

RTL_GENERIC_COMPARE_RESULTS
Os2LocalObjectCompare(
    IN struct _RTL_GENERIC_TABLE *Table,
    IN PVOID FirstStruct,
    IN PVOID SecondStruct
    );

PVOID
Os2LocalObjectDirentAllocate(
    IN struct _RTL_GENERIC_TABLE *Table,
    IN CLONG ByteSize
    );

VOID
Os2LocalObjectDirentDeallocate(
    IN struct _RTL_GENERIC_TABLE *Table,
    IN PVOID Buffer
    );

POS2_LOCAL_OBJECT_DIRENT
Os2LookupLocalObjectByName(
    IN PSTRING ObjectName,
    IN OS2_LOCAL_OBJECT_TYPE ObjectType
    );

POS2_LOCAL_OBJECT_DIRENT
Os2InsertLocalObjectName(
    IN PSTRING ObjectName,
    IN OS2_LOCAL_OBJECT_TYPE ObjectType,
    IN ULONG ObjectHandle
    );

VOID
Os2DeleteLocalObject(
    IN POS2_LOCAL_OBJECT_DIRENT Dirent
    );

//
// Routines defined in srvname.c
//

NTSTATUS
Os2InitializeNameSpace( VOID );

NTSTATUS
Os2InitializeDriveLetters( VOID );

NTSTATUS
Os2InitLocalObjectDirectory( VOID );

ULONG
Os2ComputeValidDrives( VOID );

NTSTATUS
Os2GetClientId(void);

NTSTATUS
Os2DebugProcess(
    IN PCLIENT_ID DebugUserInterface,
    IN POS2_THREAD Thread,
    IN HANDLE ReplyEvent
    );

NTSTATUS
Os2DebugThread(
    IN HANDLE hThread,
    IN HANDLE ReplyEvent
    );

//
// Routines defined in srvcnfg.c
//

NTSTATUS
Os2InitializeRegistry(
    VOID
    );

BOOLEAN
Os2ConfigSysCreator(
    IN POS2_THREAD t,
    IN POS2_API_MSG m
    );

VOID
Os2UpdateRegistryFromConfigSys(
    VOID
    );

//
// Routines defined in srvnet.c
//

BOOLEAN
Os2Netbios2Request(
    IN POS2_THREAD t,
    IN POS2_API_MSG m
    );

//
// Routines defined in sbinit.c
//

NTSTATUS
Os2SbApiPortInitialize( VOID );


VOID
Os2SbApiPortTerminate(
    NTSTATUS Status
    );

//
// Routines defined in sbreqst.c
//

NTSTATUS
Os2SbApiRequestThread(
    IN PVOID Parameter
    );

//
// Routines defined in sbapi.c
//

BOOLEAN
Os2SbCreateSession(
    IN PSBAPIMSG Msg
    );

BOOLEAN
Os2SbTerminateSession(
    IN PSBAPIMSG Msg
    );

BOOLEAN
Os2SbForeignSessionComplete(
    IN PSBAPIMSG Msg
    );

//
// Routines defined in apiinit.c
//

NTSTATUS
Os2DebugPortInitialize(void);


//
// Routines defined in apireqst.c
//

NTSTATUS
Os2ApiRequestThread(
    IN PVOID Parameter
    );


BOOLEAN
Os2CaptureArguments(
    IN POS2_THREAD t,
    IN POS2_API_MSG m
    );

VOID
Os2ReleaseCapturedArguments(
    IN POS2_API_MSG m
    );

NTSTATUS
Os2DebugRequestThread(
    IN PVOID Parameter
    );

NTSTATUS
Os2ExceptionRequestThread(
    IN PVOID Parameter
    );

//
// Routines defined in coninit.c
//

NTSTATUS
Os2InitializeConsolePort( VOID );


//
// Routines defined in conthrds.c
//

VOID
Os2SessionHandleConnectionRequest(
    struct _OS2SESREQUESTMSG *Message
    );

VOID
HandleOs2ConRequest(IN  PVOID    pApiReceiveMsg,
                    OUT PVOID    *PReplyMsg
                   );

//
// Routines defined in concreat.c
//

NTSTATUS
Os2CreateConSession(
                     IN OUT PVOID RequestMsg
                   );

//
// Routines defined in consignl.c
//

NTSTATUS
Os2CtrlSignalHandler(
                     IN OUT PVOID RequestMsg,
                     IN POS2_PROCESS RecievingProcess
                   );

NTSTATUS
Os2TerminateConSession(
                        IN POS2_SESSION Session,
            IN POS2_TERMINATEPROCESS_MSG a
                      );

//
// Routines and data defined in process.c
//

//
// The Os2StructureLock critical section protects against races with various
// threads accessing internal structures.
//

RTL_CRITICAL_SECTION Os2StructureLock;
#define Os2AcquireStructureLock() RtlEnterCriticalSection( &Os2StructureLock )
#define Os2ReleaseStructureLock() RtlLeaveCriticalSection( &Os2StructureLock )

//
// The following is a dummy process that acts as the root of the OS/2 Process
// Structure.  It has a ClientId of -1.-1 so it does not conflict with actual
// OS/2 Processes.  All processes created via the session manager are children
// of this process, as are all orphaned processes.  The ListLink field of this
// process is the head of a list of all OS/2 Processes.
//
POS2_PROCESS Os2RootProcess;

// // Obsolete code below: OS/2 ss was keeping processes around as zombie so
// //  that DosCWait doesn't fail when father calls it after child termination.
// //  However, it turns out that OS/2 doesn't do this.
//
// The Os2ZombieList is a list of all zombie processes that contain result
// codes that have not been retrieved yet.  Processes in the Zombie List
// are NOT in the process tree rooted at Os2RootProcess.  The ListLink
// field of each zombie process is used for the zombie list pointers, since
// they are not used to link them into the process structure.
//
//
// LIST_ENTRY Os2ZombieList;

//
// OS/2 Process Id values are assigned from this variable.  They are handed
// out sequentially.
//

PID Os2LastProcessId;
PID Os2NextHigherProcessId;

#define MINIMUM_PROCESS_ID (PID)0x00000001
#define MAXIMUM_PROCESS_ID (PID)0x0000FFFF


NTSTATUS
Os2InitializeProcessStructure( VOID );

POS2_PROCESS
Os2AllocateProcess( VOID );

VOID
Os2DeallocateProcess(
    IN POS2_PROCESS Process
    );

VOID
Os2InsertProcess(
    IN POS2_PROCESS ParentProcess,
    IN POS2_PROCESS Process
    );

VOID
Os2RemoveProcess(
    IN POS2_PROCESS Process
    );

VOID
Os2SuspendProcess(
    IN POS2_PROCESS Process
    );

NTSTATUS
Os2SetProcessContext(
    IN POS2_PROCESS Process,
    IN POS2_THREAD Thread,
    IN BOOLEAN StartedBySm,
    IN ULONG HandleTableLength,
    IN ULONG CurrentDrive,
    IN ULONG CodePage
    );

POS2_THREAD
Os2AllocateThread(
#ifdef PMNT
    IN ULONG Flags,
#endif
    IN POS2_PROCESS Process
    );

VOID
Os2DeallocateThread(
    IN POS2_THREAD Thread
    );

VOID
Os2InsertThread(
    IN POS2_PROCESS Process,
    IN POS2_THREAD Thread
    );

VOID
Os2RemoveThread(
    IN POS2_PROCESS Process,
    IN POS2_THREAD Thread
    );

VOID
Os2SetThreadPriority(
    IN POS2_THREAD Thread,
    IN ULONG NewClass,
    IN ULONG Delta
    );

VOID
Os2SetProcessPriority(
    IN POS2_PROCESS Process,
    IN ULONG NewClass,
    IN ULONG Delta
    );

VOID
Os2SetProcessTreePriority(
    IN POS2_PROCESS RootProcess,
    IN ULONG NewClass,
    IN ULONG Delta
    );

POS2_PROCESS
Os2LocateProcessByProcessId(
    IN POS2_API_MSG m OPTIONAL,
    IN POS2_PROCESS CurrentProcess,
    IN PID ProcessId,
    IN BOOLEAN MustBeChild
    );

POS2_PROCESS
Os2LocateProcessByClientId(
    IN PCLIENT_ID ClientId
    );

POS2_THREAD
Os2LocateThreadByThreadId(
    IN POS2_API_MSG m OPTIONAL,
    IN POS2_THREAD CurrentThread,
    IN TID ThreadId
    );

POS2_THREAD
Os2LocateThreadByClientId(
    IN POS2_PROCESS Process,
    IN PCLIENT_ID ClientId
    );

//
// Routines and data defined in wait.c
//

typedef enum _OS2_WAIT_REASON {
    WaitProcess,
    WaitThread,
    WaitQueue,
    WaitInterrupt,
    WaitSession,
    WaitWinProcess,
    MaxWaitReason
} OS2_WAIT_REASON;

typedef
BOOLEAN
(*OS2_WAIT_ROUTINE)(
    IN OS2_WAIT_REASON WaitReason,
    IN POS2_THREAD WaitingThread,
    IN POS2_API_MSG WaitReplyMessage,
    IN PVOID WaitParameter,
    IN PVOID SatisfyParameter1,
    IN PVOID SatisfyParameter2
    );

typedef struct _OS2_WAIT_BLOCK {
    ULONG Length;
    LIST_ENTRY Link;
    LIST_ENTRY UserLink;
    PVOID WaitParameter;
    POS2_THREAD WaitingThread;
    OS2_WAIT_ROUTINE WaitRoutine;
    OS2_API_MSG WaitReplyMessage;
} OS2_WAIT_BLOCK, *POS2_WAIT_BLOCK;

LIST_ENTRY Os2WaitLists[ MaxWaitReason ];

BOOLEAN
Os2InitializeWait(
    IN OS2_WAIT_ROUTINE WaitRoutine,
    IN POS2_THREAD WaitingThread,
    IN OUT POS2_API_MSG WaitReplyMessage,
    IN PVOID WaitParameter,
    OUT POS2_WAIT_BLOCK *WaitBlockPtr
    );

BOOLEAN
Os2CreateWait(
    IN OS2_WAIT_REASON WaitReason,
    IN OS2_WAIT_ROUTINE WaitRoutine,
    IN POS2_THREAD WaitingThread,
    IN OUT POS2_API_MSG WaitReplyMessage,
    IN PVOID WaitParameter,
    IN PLIST_ENTRY UserLinkListHead OPTIONAL
    );


BOOLEAN
Os2NotifyWaitBlock(
    IN POS2_WAIT_BLOCK WaitBlock,
    IN OS2_WAIT_REASON WaitReason,
    IN PVOID SatisfyParameter1,
    IN PVOID SatisfyParameter2
    );

BOOLEAN
Os2NotifyWait(
    IN OS2_WAIT_REASON WaitReason,
    IN PVOID SatisfyParameter1,
    IN PVOID SatisfyParameter2
    );

VOID
Os2DestroyWait(
    IN POS2_WAIT_BLOCK WaitBlock
    );

//
// srvque.c
//

NTSTATUS
Os2InitializeQueues( VOID );

typedef struct _OS2_QUEUE_ENTRY {
    LIST_ENTRY Links;
    REQUESTDATA RequestData;
    ULONG EntryId;
    PVOID ElementAddress;
    ULONG ElementLength;
    ULONG Priority;
} OS2_QUEUE_ENTRY, *POS2_QUEUE_ENTRY;

typedef struct _OS2_QUEUE_SEM_BLOCK {
    LIST_ENTRY Links;
    HANDLE NtEvent;
} OS2_QUEUE_SEM_BLOCK, *POS2_QUEUE_SEM_BLOCK;

typedef struct _OS2_QUEUE {
    PID CreatorPid;
    POS2_LOCAL_OBJECT_DIRENT Dirent;
    LONG OpenCount;
    ULONG QueueType;
    ULONG EntryIdCounter;
    LIST_ENTRY Entries;
    LIST_ENTRY Waiters;
    LIST_ENTRY SemBlocks;
} OS2_QUEUE, *POS2_QUEUE;

POR2_QHANDLE_TABLE Os2QueueTable;

VOID
Os2PurgeQueueEntries(
    IN POS2_QUEUE Queue
    );

POS2_QUEUE_ENTRY
Os2LocateQueueEntry(
    IN POS2_QUEUE Queue,
    IN ULONG ReadPosition
    );

BOOLEAN
Os2WaitQueueEntries(
    IN OS2_WAIT_REASON WaitReason,
    IN POS2_THREAD WaitingThread,
    IN POS2_API_MSG WaitReplyMessage,
    IN PVOID WaitParameter,
    IN PVOID SatisfyParameter1,
    IN PVOID SatisfyParameter2
    );

POS2_QUEUE
Os2OpenQueueByHandle(
    IN HQUEUE QueueHandle
    );

APIRET
Os2CloseQueueByHandle(
    IN HQUEUE QueueHandle,
    IN ULONG CloseCount,
    IN PID OwnerPid,
    IN POS2_PROCESS Process
    );

APIRET
Os2WriteQueueByHandle(
    POS2_DOSWRITEQUEUE_MSG a,
    PID ProcessId
    );

VOID
Os2ReadQueueEntry(
    IN POS2_QUEUE_ENTRY QueueEntry,
    OUT POS2_DOSREADQUEUE_MSG ReadMsg
    );

VOID
Os2PeekQueueEntry(
    IN POS2_QUEUE Queue,
    IN POS2_QUEUE_ENTRY QueueEntry,
    OUT POS2_DOSPEEKQUEUE_MSG PeekMsg
    );

VOID
DumpQueueEntry(
    IN PSZ Str,
    IN POS2_QUEUE_ENTRY QueueEntry
    );
VOID
Os2QueueWaitCheck(
    POS2_QUEUE Queue
    );

VOID
Os2ProcessSemBlocks(
    IN POS2_QUEUE Queue
    );


BOOLEAN Os2DosCreateQueue( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosOpenQueue( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosCloseQueue( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosPurgeQueue( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosQueryQueue( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosPeekQueue( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosReadQueue( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosWriteQueue( IN POS2_THREAD t, IN POS2_API_MSG m );

//
// srvsm.c
//

LIST_ENTRY Os2SessionList;

#define OS2_MAX_SESSION   30

typedef struct
{
    LIST_ENTRY      Waiters;
    POS2_SESSION    Session;
} SessionTableEntry;

SessionTableEntry SessionTable[OS2_MAX_SESSION];

POS2_SESSION
Os2AllocateSession(
    POS2_DOSSTARTSESSION_INFO SessionInfo OPTIONAL,
    ULONG   UniqueId,
    PAPIRET ApiRet
    );

VOID
Os2ReferenceSession(
    POS2_SESSION Session
    );

POS2_SESSION
Os2DereferenceSession(
    POS2_SESSION Session,
    POS2_TERMINATEPROCESS_MSG msg,
    BOOLEAN Bailout
    );

VOID
Os2DereferenceSessionByUniqueId(
    ULONG       UniqueId,
    POS2_TERMINATEPROCESS_MSG msg,
    BOOLEAN     Bailout
    );

POS2_SESSION
Os2GetSessionByUniqueId(
    ULONG       UniqueId
    );

VOID
Os2CreateConSessionFail( IN  ULONG   SessionUniqueId);

VOID
Os2CreateConSessionAccept(IN POS2_SESSION  Session);

NTSTATUS
Os2SessionFocusSet(IN OUT PVOID RequestMsg);

BOOLEAN Os2DosStartSession( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosSelectSession( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosSetSession( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosStopSession( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosSmSetTitle( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosGetCtrlPortForSessionID( IN POS2_THREAD t, IN POS2_API_MSG m);

//
// srvtask.c
//

VOID
Os2HandleException(
    IN POS2_PROCESS Process,
    IN PDBGKM_APIMSG ReceiveMsg
    );

VOID
Os2HandleDebugEvent(
    IN POS2_PROCESS Process,
    IN PDBGKM_APIMSG ReceiveMsg
    );

BOOLEAN Os2DosCreateThread( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosSuspendThread( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosResumeThread( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosExit( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosExitGP(IN POS2_THREAD t, IN POS2_API_MSG m);
BOOLEAN Os2DosWaitChild( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosWaitThread( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosEnterCritSec( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosExitCritSec( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosExecPgm( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosKillProcess( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosSetPriority( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosGetPriority( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosGetPPID( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosError( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2InternalTerminateProcess( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2InternalTerminateThread( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosPTrace( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosCloseHandle(IN POS2_THREAD t, IN POS2_API_MSG m);
#if PMNT
BOOLEAN PMSetPMshellFlag(IN POS2_THREAD t, IN POS2_API_MSG m);
#endif

BOOLEAN
Os2WaitDeadThreadSatisfy(
    IN OS2_WAIT_REASON WaitReason,
    IN POS2_THREAD t,
    IN POS2_API_MSG m,
    IN PVOID WaitParameter,
    IN PVOID SatisfyParameter1,
    IN PVOID SatisfyParameter2
    );

BOOLEAN
Os2WaitChildSatisfy(
    IN OS2_WAIT_REASON WaitReason,
    IN POS2_THREAD t,
    IN POS2_API_MSG m,
    IN PVOID WaitParameter,
    IN POS2_PROCESS TerminatingProcess,
    IN PVOID SatisfyParameter2
    );

BOOLEAN
Os2WaitThreadSatisfy(
    IN OS2_WAIT_REASON WaitReason,
    IN POS2_THREAD t,
    IN POS2_API_MSG m,
    IN PVOID WaitParameter,
    IN POS2_THREAD TerminatingThread,
    IN PVOID SatisfyParameter2
    );

BOOLEAN
Os2WaitWinExec(
    IN OS2_WAIT_REASON WaitReason,
    IN POS2_THREAD t,
    IN POS2_API_MSG m,
    IN PVOID WaitParameter,
    IN PID TerminatingProcess,
    IN PVOID SatisfyParameter2
    );

APIRET
Os2CreateProcess(
    IN PVOID RequestMsg OPTIONAL,
    IN POS2_THREAD  t,
    POS2_DOSEXECPGM_MSG a,
    POS2_SESSION    Session OPTIONAL,
    POS2_THREAD     *NewThread
    );

//
// srvxcpt.c
//

BOOLEAN Os2DosSetSignalExceptionFocus( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosEnterMustComplete( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosExitMustComplete( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosSendSignalException( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosAcknowledgeSignalException( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosDispatch16Signal( IN POS2_THREAD t, IN POS2_API_MSG m);

BOOLEAN
Os2DispatchVector(
    IN PDBGKM_APIMSG ReceiveMsg,
    POS2_THREAD Thread,
    CONTEXT Context
    );

VOID
SendSyncPterm(
    IN POS2_THREAD Thread
    );

VOID
SendAsyncPterm(
    IN POS2_THREAD Thread
    );

APIRET
Os2IssueSignal(
    IN POS2_PROCESS Process,
    IN int          Signal
    );

VOID
Os2IssueSignalTree(
    IN POS2_PROCESS RootProcess,
    IN int          Signal
    );

BOOLEAN Os2DosRegisterCtrlHandler( IN POS2_THREAD t, IN POS2_API_MSG m );

VOID Os2DeRegisterCtrlHandler(IN POS2_PROCESS Process);

//
// srvvm.c
//

typedef struct _OS2_SHARED_MEMORY_OBJECT {
    LIST_ENTRY Link;
    ULONG RefCount;
    PVOID BaseAddress;
    ULONG Index;
    ULONG RegionSize;
    HANDLE SectionHandle;
    ULONG AllocationFlags;
    STRING SectionName;
    BOOLEAN IsHuge;
    ULONG MaxSegments;
    ULONG NumOfSegments;
    ULONG SizeOfPartialSeg;
    BOOLEAN Sizeable;
} OS2_SHARED_MEMORY_OBJECT, *POS2_SHARED_MEMORY_OBJECT;

LIST_ENTRY Os2SharedMemoryList;

//
// A linked list of all the shared memory objects that a process currently
// has open.
//

typedef struct _OS2_SHARED_MEMORY_PROCESS_REF {
    LIST_ENTRY Link;
    ULONG RefCount;
    ULONG AllocationFlags;
    POS2_SHARED_MEMORY_OBJECT SharedMemoryObject;
} OS2_SHARED_MEMORY_PROCESS_REF, *POS2_SHARED_MEMORY_PROCESS_REF;


NTSTATUS
Os2InitializeMemory( VOID );


POS2_SHARED_MEMORY_OBJECT
Os2CreateSharedMemoryObject(
    IN POS2_API_MSG m,
    IN PVOID BaseAddress,
    IN ULONG Index,
    IN ULONG RegionSize,
    IN HANDLE SectionHandle OPTIONAL,
    IN ULONG AllocationFlags,
    IN PSTRING SectionName
    );


VOID
Os2FreeSharedMemoryObject(
    POS2_SHARED_MEMORY_OBJECT MemoryObject
    );


POS2_SHARED_MEMORY_PROCESS_REF
Os2CreateProcessRefToSharedMemory(
    IN POS2_PROCESS Process,
    IN POS2_SHARED_MEMORY_OBJECT MemoryObject
    );


BOOLEAN
Os2FreeProcessRefToSharedMemory(
    IN POS2_PROCESS Process,
    IN POS2_SHARED_MEMORY_PROCESS_REF MemoryProcessRef
    );


VOID
Os2FreeAllSharedMemoryForProcess(
    IN POS2_PROCESS Process
    );


POS2_SHARED_MEMORY_OBJECT
Os2FindSharedMemoryObject(
    IN PVOID BaseAddress,
    IN POS2_PROCESS Process
    );


APIRET
Os2MapViewOfSharedMemoryObject(
    POS2_SHARED_MEMORY_OBJECT MemoryObject,
    POS2_PROCESS Process,
    BOOLEAN ProcessIsSelf,
    ULONG RequiredAccess,
    ULONG PageProtection
    );

BOOLEAN Os2DosFreeMem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosSetMem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosGiveSharedMem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosGetSharedMem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosGetNamedSharedMem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosAllocSharedMem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2InternalQueryVirtualMemory( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2InternalMarkSharedMemAsHuge( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosReallocSharedMem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2InternalReallocSharedHuge( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosGetSeg( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosGiveSeg( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosGetShrSeg( IN POS2_THREAD t, IN POS2_API_MSG m );

//
// srvfile.c
//

BOOLEAN Os2InternalCopyHandleTable( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2InternalDeviceShare( IN POS2_THREAD t, IN POS2_API_MSG m );

APIRET
InitializeFileSystemForExec(
    IN POS2_FILE_SYSTEM_PARAMETERS FileSystemParameters,
    IN HANDLE ParentProcessHandle,  // NT process handle
    IN HANDLE ChildProcessHandle,   // NT process handle
    POS2_PROCESS ParentProcess,     // OS/2 parent process
    POS2_PROCESS ChildProcess,      // OS/2 child process
    IN POS2_DOSEXECPGM_MSG pExecPgmMsg
    );

VOID
InitializeFileSystemForSesMgr(
    IN POS2_PROCESS Process         // OS/2 process
    );

APIRET
InitializeFileSystemForChildSesMgr(
    IN POS2_FILE_SYSTEM_PARAMETERS FileSystemParameters,
    IN HANDLE ParentProcessHandle,  // NT process handle
    IN HANDLE ChildProcessHandle,   // NT process handle
    POS2_PROCESS ParentProcess,     // OS/2 parent process
    POS2_PROCESS ChildProcess,      // OS/2 child process
    IN POS2_DOSEXECPGM_MSG pExecPgmMsg
    );

//
// srvwin.c
//

ULONG
Os2AccessGPPopup(
    IN  ULONG   CS,
    IN  ULONG   IP,
    IN  ULONG   AX,
    IN  ULONG   BX,
    IN  ULONG   CX,
    IN  ULONG   DX,
    IN  ULONG   SI,
    IN  ULONG   DI,
    IN  ULONG   BP,
    IN  ULONG   SP,
    IN  ULONG   SS,
    IN  ULONG   DS,
    IN  ULONG   ES,
    IN  PUCHAR  AppName
    );

ULONG
Os2ApiGPPopup(
    IN  PUCHAR  AppName,
    IN  PUCHAR  Text
    );

extern HANDLE  Os2hOs2SrvInstance;      // for resouces

//
// srvsem.c
//

NTSTATUS
Os2InitializeSemaphores( VOID );

BOOLEAN
Os2SemaphoreCreateProcedure(
    IN POS2_SEMAPHORE Semaphore,
    IN POS2_SEMAPHORE CreateSemaphore
    );

BOOLEAN
Os2SemaphoreOpenProcedure(
    IN POS2_SEMAPHORE Semaphore,
    IN POS2_SEMAPHORE OpenSemaphore
    );

APIRET
Os2ProcessSemaphoreName(
    IN PSTRING ObjectName,
    IN POS2_SEMAPHORE Semaphore OPTIONAL,
    OUT PULONG ExistingHandleIndex OPTIONAL
    );

PVOID
Os2DestroySemaphore(
    IN POS2_SEMAPHORE Semaphore,
    IN ULONG HandleIndex
    );

POS2_SEMAPHORE
Os2ReferenceSemaphore(
    IN POS2_SEMAPHORE Semaphore
    );

VOID
Os2DereferenceSemaphore(
    IN POS2_SEMAPHORE Semaphore
    );

VOID
Os2ThreadWaitingOnSemaphore(
    IN POS2_THREAD t,
    IN POS2_SEMAPHORE Semaphore,
    IN BOOLEAN AboutToWait
    );


#if DBG

VOID
Os2SemaphoreDumpProcedure(
    IN POS2_SEMAPHORE Semaphore,
    IN ULONG HandleIndex,
    IN PVOID DumpParameter
    );

VOID
Os2DumpSemaphoreTable(
    IN PCHAR Title
    );

#endif // DBG


//
// srvevent.c
//

BOOLEAN Os2DosCreateEventSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosOpenEventSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosCloseEventSem( IN POS2_THREAD t, IN POS2_API_MSG m );


//
// srvmutex.c
//

BOOLEAN Os2DosCreateMutexSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosOpenMutexSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosCloseMutexSem( IN POS2_THREAD t, IN POS2_API_MSG m );


//
// srvmuxwt.c
//

APIRET
Os2AddMuxWait(
    IN POS2_MUXWAIT_SEMAPHORE MuxWait,
    IN PSEMRECORD MuxWaitEntry
    );

APIRET
Os2DeleteMuxWait(
    IN POS2_MUXWAIT_SEMAPHORE MuxWait,
    IN ULONG MuxWaitEntryIndex,
    IN ULONG SemHandleIndex OPTIONAL
    );

BOOLEAN Os2DosCreateMuxWaitSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosOpenMuxWaitSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosCloseMuxWaitSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosWaitMuxWaitSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosAddMuxWaitSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosDeleteMuxWaitSem( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2InternalAlertMuxWaiter( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN Os2DosQueryMuxWaitSem( IN POS2_THREAD t, IN POS2_API_MSG m );

//
// loader routines
//

BOOLEAN LDRNewExe( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRUnloadExe( IN POS2_PROCESS Process );
BOOLEAN LDRDosLoadModule( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRDosFreeModule( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRDosGetModName( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRDosGetModHandle( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRDosGetProcAddr( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRDosQAppType( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRDosGetResource( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRDosGetResource2( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRDosFreeResource( IN POS2_THREAD t, IN POS2_API_MSG m );
#if PMNT
BOOLEAN LDRIdentifyCodeSelector( IN POS2_THREAD t, IN POS2_API_MSG m );
BOOLEAN LDRDumpSegments( IN POS2_THREAD t, IN POS2_API_MSG m );
#endif

BOOLEAN LDRModifySizeOfSharedSegment( IN POS2_THREAD t, IN ULONG Sel, IN ULONG NewLimit );

//
// LinkMTE is used for saving all the mte's of a process
// in a linked list.
//

typedef struct _LinkMTE {
    USHORT              MTE;
    struct _LinkMTE     *NextMTE;
    USHORT              NeedToTransfer;     // used as counter for mtes
                                            // and for flag for DosPtrace
} LinkMTE;


//
// xtlexec.c
//

NTSTATUS
XtlCreateUserProcess(
    IN PSTRING NtImagePathName,
    IN PRTL_USER_PROCESS_PARAMETERS ProcessParameters,
    IN PSECURITY_DESCRIPTOR ProcessSecurityDescriptor OPTIONAL,
    IN PSECURITY_DESCRIPTOR ThreadSecurityDescriptor OPTIONAL,
    IN HANDLE ParentProcess OPTIONAL,
    IN BOOLEAN InheritHandles,
    IN HANDLE DebugPort OPTIONAL,
    IN HANDLE ExceptionPort OPTIONAL,
    OUT PRTL_USER_PROCESS_INFORMATION ProcessInformation
    );

NTSTATUS
Os2WinCreateProcess (POS2_DOSEXECPGM_MSG a,
                     POS2_PROCESS        ParentProcess,
                     POS2_SESSION        Session,
                     PHANDLE             pHandle
                    );

NTSTATUS
Os2WinRunProcess (IN  HANDLE          tHandle,
                  IN  POS2_SESSION    Session
                 );

//
// srvdebug.c
//

NTSTATUS
Os2UiLookup(PCLIENT_ID AppClientId,
        PCLIENT_ID DebugUiClientId);

NTSTATUS
Os2CheckStopDebugThread(
    IN PVOID Parameter
    );

//
// exception handling structures and equates
//

#define MAXIMUM_MUST_COMPLETE 0xFFFF        // maximum must complete nesting

#define SIG_MAXSF             0xFFFF        // maximum signal focus nesting


//   Signal numbers
//      these are also defined in os2dll.h, so if the values change be sure
//      to change them there

#define SIGNAL_TO_FLAG(Signal)  (1 << (Signal - 1))

#define SIGAPTERM       8                       // Asynchronous PTERM
#define SIGPTERM        9                       // Synchronous PTERM

//      Signal flags

#define SIGINTRF        (1 << (XCPT_SIG_INTR - 1))      // Ctrl-C
#define SIGTERMF        (1 << (XCPT_SIG_KILLPROC - 1))  // program termination
#define SIGBREAKF       (1 << (XCPT_SIG_BREAK - 1))     // Ctrl-Break
#define SIGAPTERMF      (1 << (SIGAPTERM - 1))          // Asyncronous PTERM

//      Error flags
// Similar flags are defined in os2dll.h as OD2_ENABLE_ ...

#define OS2_ENABLE_HARD_ERROR_POPUP    0x1
#define OS2_ENABLE_ACCESS_VIO_POPUP    0x2

/* Fix for a C8 compilation warning */
#undef TRUE
#define TRUE (BOOLEAN)1

#undef FALSE
#define FALSE (BOOLEAN)0

/* Global Information Segment */

typedef struct _GINFOSEG {      /* gis */
    ULONG   time;
    ULONG   msecs;
    UCHAR   hour;
    UCHAR   minutes;
    UCHAR   seconds;
    UCHAR   hundredths;
    USHORT  timezone;
    USHORT  cusecTimerInterval;
    UCHAR   day;
    UCHAR   month;
    USHORT  year;
    UCHAR   weekday;
    UCHAR   uchMajorVersion;
    UCHAR   uchMinorVersion;
    UCHAR   chRevisionLetter;
    UCHAR   sgCurrent;
    UCHAR   sgMax;
    UCHAR   cHugeShift;
    UCHAR   fProtectModeOnly;
    USHORT  pidForeground;
    UCHAR   fDynamicSched;
    UCHAR   csecMaxWait;
    USHORT  cmsecMinSlice;
    USHORT  cmsecMaxSlice;
    USHORT  bootdrive;
    UCHAR   amecRAS[32];
    UCHAR   csgWindowableVioMax;
    UCHAR   csgPMMax;
} GINFOSEG;