summaryrefslogblamecommitdiffstats
path: root/private/os2/inc/os2dll.h
blob: b290f13fa81bb8d0ac4fd652013d7f231a0c4200 (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

















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                            
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    os2dll.h

Abstract:

    Main include file for OS/2 Subsystem Client DLL

Author:

    Steve Wood (stevewo) 22-Aug-1989

Revision History:

--*/

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

#include "os2ssrtl.h"

#if DBG
extern ULONG Os2Debug;
#endif

//
// Include definitions of API Calls exported by the OS/2 Subsystem Server
// (i.e. the stub procedure definitions).
//
#include "dllfile.h"
#include "os2ssmsg.h"


//
// Common Types and Definitions
//

//
// OD2_HEAP_MEMORY_SIZE defines how much address space should be
// reserved for the OS/2 Client heap.  This heap is used to store all
// data structures maintained by the OS/2 Client DLL.
//

#define OD2_HEAP_MEMORY_SIZE (64*1024)


//
// OD2_PORT_MEMORY_SIZE defines how much address space should be
// reserved for passing data to the OS/2 Server.  The memory is visible
// to both the client and server processes.
//

#define OD2_PORT_MEMORY_SIZE 0x10000


//
// OD2_SEMAPHORE and its related types are the client represenation of OS/2
// shared semaphores and the entire representation of private OS/2 semaphores.
//

typedef enum _OD2_SEMAPHORE_TYPE {
    Od2EventSem = 1,
    Od2MutexSem,
    Od2MuxWaitSem
} OD2_SEMAPHORE_TYPE;

typedef struct _OD2_MUTEX_SEMAPHORE {
    HANDLE MutantHandle;
    ULONG OwnerRequestLevel;
    TID OwnerTid;
} OD2_MUTEX_SEMAPHORE, *POD2_MUTEX_SEMAPHORE;

typedef struct _OD2_MUXWAIT_RECORD {
    HSEM SemHandle;
    ULONG UserKey;
    struct _OD2_SEMAPHORE *Semaphore;
} OD2_MUXWAIT_RECORD, *POD2_MUXWAIT_RECORD;

typedef struct _OD2_MUXWAIT_SEMAPHORE {
    USHORT CountMuxWaitRecords;
    USHORT Type : 2;
    USHORT WaitAll : 1;
    USHORT Reserved : 13;
    OD2_MUXWAIT_RECORD MuxWaitRecords[ DCMW_MAX_SEMRECORDS ];
} OD2_MUXWAIT_SEMAPHORE, *POD2_MUXWAIT_SEMAPHORE;

typedef struct _OD2_SEMAPHORE {
    USHORT PointerCount : 13;
    USHORT Type : 2;
    USHORT Shared : 1;
    USHORT OpenCount;
    union {
        PVOID Value;
        HANDLE EventHandle;
        POD2_MUTEX_SEMAPHORE Mutex;
        POD2_MUXWAIT_SEMAPHORE MuxWait;
    } u;
} OD2_SEMAPHORE, *POD2_SEMAPHORE;

typedef struct _OD2_QUEUE {
    ULONG OpenCount;
    PID OwnerProcessId;
} OD2_QUEUE, *POD2_QUEUE;

//
// The OD2_PROCESS and OD2_THREAD data structures describe the OS/2 Client
// process.  Both data structures are allocated from the Od2Heap.
//

typedef struct _OD2_PROCESS {
    HANDLE TaskLock;
    RTL_RESOURCE FileLock;
    LIST_ENTRY ThreadList;
    LIST_ENTRY ExitList;
    RESULTCODES ResultCodes;    // Valid if PS_EXITLIST is set in Pib.Status
    ULONG ErrorAction;
    ULONG VerifyFlag;
    ULONG MaximumFileHandles;
    ULONG DefaultDisk;
    BOOLEAN BoundApp;
    POR2_HANDLE_TABLE PrivateSemaphoreTable;
    POR2_HANDLE_TABLE SharedSemaphoreTable;
    POR2_QHANDLE_TABLE QueueTable;
    LIST_ENTRY MsgFileList;
    UCHAR   ApplName[OS2_PROCESS_MAX_APPL_NAME];
    PIB Pib;                    // Make this the last field in the
                                // the structure so client cant inadvertantly
                                // muck with the other fields in OD2_PROCESS
} OD2_PROCESS, *POD2_PROCESS;




#define OD2_ENABLE_HARD_ERROR_POPUP    0x1
#define OD2_ENABLE_ACCESS_VIO_POPUP    0x2

typedef struct _OD2_THREAD {
    LIST_ENTRY Link;
    PFNTHREAD StartAddress;     // Used to pass startup information
    ULONG Parameter;            // ... to Od2UserThreadStartup
    POD2_SEMAPHORE WaitingForSemaphore;
    ULONG  Saved32Esp;
    ULONG  ApiIndex;
    HANDLE ThreadHandle;
    HANDLE Event;               // DosCreateThread use this event to get
                                // notification from the thread that it has
                                // be created and initialized
                                // DosSuspendThread use it to suspend thread in
                                // 32 bit
    ULONG Flags;                // Parameter of DosCreateThread
    APIRET rc;                  // Return code of the thread during startup
                                // to DosCreateThread
    OS2_TIB Os2Tib;             // OS2 specific part of the TIB
                                // (subsystem portable part is in TEB)
                                // Make this the last field in the
                                // the structure so client can't inadvertantly
                                // muck with the other fields in OD2_THREAD
} OD2_THREAD, *POD2_THREAD;


typedef struct _OS2_EXITLISTENTRY {
    LIST_ENTRY Link;
    ULONG Order;
    PFNEXITLIST ExitRoutine;
    ULONG flag;
} OD2_EXITLISTENTRY, *POS2_EXITLISTENTRY;

typedef struct _OD2_CONTEXT_SAVE_AREA {
    LOCALINFOSEG TebBlock;
    ULONG Saved16Stack;
    BOOLEAN SignalHandlingInProgress;
    USHORT SegEs;
    USHORT SegDs;
} OD2_CONTEXT_SAVE_AREA, *POD2_CONTEXT_SAVE_AREA;

#define Od2CurrentThreadId() \
    (                                                       \
     ((POD2_THREAD)(NtCurrentTeb()->EnvironmentPointer)) ?   \
        (((POD2_THREAD)(NtCurrentTeb()->EnvironmentPointer))->Os2Tib.ThreadId) : \
        0 \
    )


//
// The Lock field in an OS/2 Process object protects the fields of the process
// data structure.  This includes the list of thread objects attached
// to the process object and the list of exit procedures.
//
//
// If the process is dieing, and there is only thread 1, there is no
// need for the lock, and we should not try it incase we terminated
// a thread inside (Acquire .. Release) block.
//
/*
#define AcquireTaskLock()                                                 \
        if ((!Od2SigHandlingInProgress) || ((Od2CurrentThreadId()) != 1)) \
            RtlEnterCriticalSection( &Od2Process->TaskLock )
#define ReleaseTaskLock()                                                 \
        if ((!Od2SigHandlingInProgress) || ((Od2CurrentThreadId()) != 1)) \
            RtlLeaveCriticalSection( &Od2Process->TaskLock )
*/

NTSTATUS AcquireTaskLock(VOID);
NTSTATUS ReleaseTaskLock(VOID);

#if DBG
//
// dllutil.c
//

VOID
AcquireFileLockShared(
    IN PSZ CallingRoutine
    );

VOID
ReleaseFileLockShared(
    IN PSZ CallingRoutine
    );

VOID
PromoteFileLocktoExclusive(
    IN PSZ CallingRoutine
    );

VOID
AcquireFileLockExclusive(
    IN PSZ CallingRoutine
    );

VOID
ReleaseFileLockExclusive(
    IN PSZ CallingRoutine
    );

#else
#define PromoteFileLocktoExclusive(x) RtlConvertSharedToExclusive( &Od2Process->FileLock )

VOID
AcquireFileLockShared( VOID );

VOID
ReleaseFileLockShared( VOID );

VOID
AcquireFileLockExclusive( VOID );

VOID
ReleaseFileLockExclusive( VOID );

#endif

//
// Global data accessed by Client DLL
//

//
//  dllnls.c
//

#define Od2ProcessCodePage              Or2ProcessCodePage
#define Od2CurrentCodePageIsOem         Or2CurrentCodePageIsOem

#define Od2InitMBString                 Or2InitMBString
#define Od2MBStringToUnicodeString      Or2MBStringToUnicodeString
#define Od2CreateUnicodeStringFromMBz   Or2CreateUnicodeStringFromMBz
#define Od2UnicodeStringToMBString      Or2UnicodeStringToMBString
#define Od2FreeMBString                 Or2FreeMBString

//
// The Od2NtSysInfo global variable contains NT specific constants of
// interest, such as page size, allocation granularity, etc.  It is filled
// in once during process initialization.
//

extern SYSTEM_BASIC_INFORMATION Od2NtSysInfo;

#define ROUND_UP_TO_PAGES(SIZE) (((ULONG)(SIZE) + Od2NtSysInfo.PageSize - 1) & ~(Od2NtSysInfo.PageSize - 1))
#define ROUND_DOWN_TO_PAGES(SIZE) (((ULONG)(SIZE)) & ~(Od2NtSysInfo.PageSize - 1))

//
// The Od2DebugFlag is non-zero if the OS/2 Client Application was invoked
// with the Debug option.
//

extern ULONG Od2DebugFlag;


//
// The Od2Heap global variable describes a single heap used by the Client DLL
// for process wide storage management.  The process data structure, thread
// data structures, file handle table, current directory structures, etc. are
// all allocated out of this heap.
//

extern PVOID Od2Heap;


//
// The Od2Environment variable points to a block of memory that contains the
// OS/2 Environment block.  Od2EnvSize describes how much virtual address space
// is reserved at this location.
//

extern PVOID Od2Environment;
extern ULONG Od2EnvSize;


//
// The Od2BootDrive and Od2SystemDrive define the meaning of \BootDevice and
// \SystemDisk respectively.
//

extern ULONG Od2BootDrive;
extern ULONG Od2SystemDrive;


//
// The connection to the OS/2 Emulation Subsystem is described by the
// Od2PortHandle global variable.  The connection is established during
// process initialization by Od2ProcessStartup.
//

extern HANDLE Od2PortHandle;


//
// In order to pass large arguments to the OS/2 Emulation Subsystem (e.g.
// path name arguments) the Od2PortHeap global variable describes a
// heap that is visible to both the OS/2 Client process and the OS/2
// Emulation Subsystem.
//

extern PVOID Od2PortHeap;
extern ULONG Od2PortMemoryRemoteDelta;

//
// The Od2Process global variable points to the OD2_PROCESS structure for
// the client process.  It is allocated out of Od2Heap.
//

extern POD2_PROCESS Od2Process;


//
// The Od2Thread1 global variable points to the first thread structure for
// the client process.  It is allocated out of Od2Heap.
//

extern POD2_THREAD Od2Thread1;


//
// The Od2DllHandle global variable contains the DLL handle for the OS2DLL
// client stubs executable.
//

extern HMODULE Od2DllHandle;


//
// The Od2DeviceDirecotory global variable contains the handle to the
// \OS2SS\DEVICES directory in the object name space.
//

extern HANDLE Od2DeviceDirectory;

//
// Od2NtLibPath replaces what in Os2 1.X is kept in the kernel
// The DLl get's it from the subsystem
//
extern PSZ Od2NtLibPath;
extern USHORT Od2NtLibPathLength;

//
// Od2LibPath holds the search path for the loader to load
// the OS/2 specific DLLs. This search path may be different than the
// NT LibPath since some OS/2 thunk DLLs conflict in name with NT DLLs
// (like netapi.dll)
//
extern PSZ Od2LibPath;
extern USHORT Od2LibPathLength;

//
//
// Od2DllInitialize does the OS/2 Client DLL initialization of all of
// the above global variables.  It is a DLL Initialization routine.
//

BOOLEAN
Od2DllInitialize(
    IN PVOID DllHandle,
    IN ULONG Reason,
    IN PCONTEXT Context OPTIONAL
    );


//
//
// Od2ProcessStartup is the modified start address for OS/2 applications.
// The DLL Initialization procedure makes this the new start address if
// it successfully initializes the client process.  This function in turns
// calls the application entry point with the OS/2 defined process startup
// parameters.
//

VOID
Od2ProcessStartup(
    IN PPEB Peb
    );


//
// The Od2InitializeTask procedure is called by the Od2ProcessStartup code
// to initialize the tasking component of the OS/2 Client DLL.
//

NTSTATUS
Od2InitializeTask( VOID );


NTSTATUS
Od2InitializeThread(
    IN POD2_THREAD Thread
    );


VOID
Od2UserThreadStartup(
    IN POD2_THREAD Thread
    );

//
// Common Exec Message formatter used by DosExecPgm and DosStartSession
//

APIRET
Od2FormatExecPgmMessage(
    OUT POS2_DOSEXECPGM_MSG a,
    OUT POS2_CAPTURE_HEADER *CaptureBuffer,
    OUT PNTSTATUS   Od2IsConsoleTypeReturnStatus,
#if PMNT
    OUT PULONG      IsPMApp,
#endif // PMNT
    IN  PSZ     ErrorText,
    IN  LONG    MaximumErrorTextLength,
    IN  ULONG   Flags,
    IN OUT PSZ  *VariablesBuffer,
    IN OUT PSZ  *ArgumentBuffer,
    IN  PSZ     *ImageFileName
    );

NTSTATUS
Od2IsFileConsoleType(
    PSTRING NtImagePathName
#if PMNT
    ,
    PULONG  IsPMApp
#endif // PMNT
    );

//
// routines defined in dllinit.c
//

extern PUCHAR Od2SystemRoot;

ULONG
Od2ProcessException(
    IN PEXCEPTION_POINTERS ExceptionInfo,
    OUT PEXCEPTION_RECORD ExceptionRecord
    );

VOID
Od2ExceptionHandler(
    IN PEXCEPTION_RECORD ExceptionRecord
    );

//
// Routines defined in dllsem.c
//

//
// The following bit masks define the fields within a 32 bit semaphore
// handle.
//

#define SEM_SHARED      0x80000000
#define SEM_HANDLESIG   0x00010000      // 32-bit handle signature
#define SEM_SIGBITS     0x7FFF0000      // Isolates 32-bit signature bits
#define SEM_INDEX       0x0000FFFF

APIRET
Od2CaptureSemaphoreName(
    IN PSZ ObjectName,
    IN ULONG ExtraCaptureBufferLength OPTIONAL,
    OUT POS2_CAPTURE_HEADER *CaptureBuffer,
    OUT PSTRING CapturedObjectName
    );


POR2_HANDLE_TABLE
Od2GetSemaphoreTable(
    BOOLEAN SharedSem,
    BOOLEAN CreateOkay
    );


HSEM
Od2ConstructSemaphoreHandle(
    IN BOOLEAN SharedSem,
    IN ULONG Index
    );


APIRET
Od2ValidateSemaphoreHandle(
    IN HSEM SemaphoreHandle,
    OUT PBOOLEAN SharedSem,
    OUT PULONG Index
    );

POD2_SEMAPHORE
Od2ReferenceSemaphore(
    IN POD2_SEMAPHORE Semaphore
    );

VOID
Od2DereferenceSemaphore(
    IN POD2_SEMAPHORE Semaphore
    );

VOID
Od2ThreadWaitingOnSemaphore(
    IN POR2_HANDLE_TABLE SemaphoreTable,
    IN POD2_SEMAPHORE Semaphore,
    IN BOOLEAN AboutToWait
    );

POD2_THREAD
Od2SearchForWaitingThread(
    IN POD2_SEMAPHORE Semaphore
    );

VOID
Od2SemaphoreDestroyProcedure(
    IN POD2_SEMAPHORE Semaphore,
    IN ULONG HandleIndex
    );

VOID
Od2CloseAllSemaphores( VOID );


#if DBG

VOID
Od2SemaphoreDumpProcedure(
    IN POD2_SEMAPHORE Semaphore,
    IN ULONG HandleIndex,
    IN PVOID DumpParameter
    );

VOID
Od2DumpAllSemaphores(
    IN PCHAR Title
    );

#endif // DBG


//
// Routines defined in dllmuxwt.c
//

APIRET
Od2AddMuxWait(
    IN POD2_MUXWAIT_SEMAPHORE MuxWait,
    IN PSEMRECORD MuxWaitEntry
    );


APIRET
Od2DeleteMuxWait(
    IN POD2_MUXWAIT_SEMAPHORE MuxWait,
    IN ULONG MuxWaitEntryIndex,
    IN HSEM MuxWaitEntrySem OPTIONAL
    );


//
// Routines defined in dlltimer.c
//

NTSTATUS
Od2InitializeTimers(VOID);

VOID
Od2CloseAllTimers(VOID);


//
// Definitions for dllflopy.c
//

VOID
Od2DiskIOInitialize(
    VOID
    );

VOID
Od2DiskIOTerminate(
    VOID
    );


//
// Routines defined in dllname.c
//

APIRET
Od2Canonicalize(
    IN PSZ Path,
    IN ULONG ExpectedType,
    OUT PSTRING OutputString,
    OUT PHANDLE OutputDirectory OPTIONAL,
    OUT PULONG ParseFlags OPTIONAL,
    OUT PULONG FileType OPTIONAL
    );

//
// Valid values for ExpectedType parameter
//

#define CANONICALIZE_FILE_DEV_OR_PIPE   0x00000000
#define CANONICALIZE_FILE_OR_DEV        0x00000001
#define CANONICALIZE_SHARED_MEMORY      0x00000002
#define CANONICALIZE_SEMAPHORE          0x00000003
#define CANONICALIZE_QUEUE              0x00000004
#define CANONICALIZE_MAILSLOT           0x00000005

//
// Flag definitions returned via the ParseFlags parameter
//

#define CANONICALIZE_META_CHARS_FOUND   0x00000001
#define CANONICALIZE_IS_ROOT_DIRECTORY  0x00000002

//
// Maximum length of NT specific prefix that is placed at the beginning
// of the canonical output string.
//

#define CANONICALIZE_MAX_PREFIX_LENGTH  32
#define IS_OBJ_NAME_PATH_SEPARATOR(ch) ((ch == '\\') || (ch == '\0'))

BOOLEAN
Od2IsAbsolutePath(
    IN PSZ Path
    );


//
// Routines defined in dllque.c
//

POR2_QHANDLE_TABLE
Od2GetQueueTable(
    BOOLEAN CreateOkay
    );

APIRET
Od2ValidateQueueSemaphore(
    IN HSEM EventHandle,
    IN PULONG HandleIndex
    );

VOID
Od2CloseAllQueues( VOID );

VOID
Od2QueueDestroyProcedure(
    IN POD2_QUEUE Semaphore,
    IN ULONG HandleIndex
    );

//
// Routines defined in dllutil.c
//

APIRET
Od2CallSubsystem(
    IN OUT POS2_API_MSG m,
    IN OUT POS2_CAPTURE_HEADER CaptureBuffer OPTIONAL,
    IN OS2_API_NUMBER ApiNumber,
    IN ULONG ArgLength
    );

POS2_CAPTURE_HEADER
Od2AllocateCaptureBuffer(
    IN ULONG CountMessagePointers,
    IN ULONG CountCapturePointers,
    IN ULONG Size
    );

VOID
Od2FreeCaptureBuffer(
    IN POS2_CAPTURE_HEADER CaptureBuffer
    );

ULONG
Od2AllocateMessagePointer(
    IN OUT POS2_CAPTURE_HEADER CaptureBuffer,
    IN ULONG Length,
    OUT PVOID *Pointer
    );

ULONG
Od2AllocateCapturePointer(
    IN OUT POS2_CAPTURE_HEADER CaptureBuffer,
    IN ULONG Length,
    OUT PVOID *Pointer
    );

VOID
Od2CaptureMessageString(
    IN OUT POS2_CAPTURE_HEADER CaptureBuffer,
    IN PCHAR String,
    IN ULONG Length,
    IN ULONG MaximumLength,
    OUT PSTRING CapturedString
    );

void
Od2StartTimeout(
    PLARGE_INTEGER StartTimeStamp
    );

NTSTATUS
Od2ContinueTimeout(
    PLARGE_INTEGER StartTimeStamp,
    PLARGE_INTEGER Timeout
    );

PLARGE_INTEGER
Od2CaptureTimeout(
    IN ULONG Milliseconds,
    OUT PLARGE_INTEGER Timeout
    );

VOID
Od2ProbeForWrite(
    IN PVOID Address,
    IN ULONG Length,
    IN ULONG Alignment
    );

VOID
Od2ProbeForRead(
    IN PVOID Address,
    IN ULONG Length,
    IN ULONG Alignment
    );

APIRET
Od2CaptureObjectName(
    IN PSZ ObjectName,
    IN ULONG ObjectType,
    IN ULONG ExtraCaptureBufferLength OPTIONAL,
    OUT POS2_CAPTURE_HEADER *CaptureBuffer,
    OUT PSTRING CapturedObjectName
    );

PWSTR
Od2CopyStrToWstr(
    IN OUT PWSTR wstr OPTIONAL,
    IN PSZ str
    );

int
Od2WstrSize(
    IN PWSTR pwstr
    );

PSZ
Od2CopyWstrToStr(
    IN OUT PSZ str OPTIONAL,
    IN PWSTR wstr
    );

PSZ Od2nCopyWstrToStr(
    IN OUT PSZ str OPTIONAL,
    IN PWSTR wstr,
    IN int n
    );

APIRET Od2FixFEA2List(
    IN  FEA2LIST *fpFEA2List);

VOID
Od2ExitGP();

BOOLEAN
RetryIO(
    IN NTSTATUS Status,
    IN HANDLE Handle
    );

BOOLEAN
RetryCreateOpen(
    IN NTSTATUS Status,
    IN POBJECT_ATTRIBUTES pObja
    );

//
// Routines defined in dlltask.c
//

VOID
Od2ProcessCleanup( VOID );


VOID
Od2DosExit(
    ULONG ExitAction,
    ULONG ExitResult,
    ULONG ExitReason);

//
// Routines defined in dllxcpt.c
//

APIRET
Od2AcknowledgeSignalException(
    IN ULONG SignalNumber
    );

VOID
_Od2VectorHander( VOID );

//
// Routines defined in dllthunk.s
//

VOID
_Od2ExitListDispatcher( VOID );

VOID
Od2JumpToExitRoutine(
    IN PFNEXITLIST ExitRoutine,
    IN ULONG ExitReason
    );

VOID
_Od2SignalDeliverer(
    IN PCONTEXT pContext,
    IN int Signal
    );

VOID
_Od2ProcessSignal16(
    IN POS2_REGISTER16_SIGNAL pa
    );

VOID
_Od2FreezeThread(
    IN PCONTEXT pContext
    );

VOID
_Od2UnfreezeThread(
    IN PCONTEXT pContext
    );

//
// Routines defined in dllhandl.c
//

APIRET
OpenCreatePath(
    OUT PHANDLE FileHandle,
    IN ULONG DesiredAccess,
    IN POBJECT_ATTRIBUTES ObjectAttributes,
    IN PIO_STATUS_BLOCK IoStatus,
    IN ULONG CreateSize,
    IN ULONG FileAttributes,
    IN ULONG ShareAccess,
    IN ULONG CreateDisposition,
    IN ULONG CreateOptions,
    IN OUT PEAOP2 ExtendedFileAttr OPTIONAL,
    OUT PUSHORT FileType,
    OUT PUSHORT DeviceAttributes,
    IN BOOLEAN OpenDirectory
    );

APIRET
MapFileType(
    IN HANDLE FileHandle,
    OUT PBOOLEAN Directory OPTIONAL,
    OUT PUSHORT FileType,
    OUT PUSHORT DeviceAttribute
    );

BOOLEAN
CheckFileType(
    IN HANDLE FileHandle,
    IN USHORT FileTypes
    );

APIRET
AllocateHandle(
    OUT PHFILE FileHandle
    );

APIRET
FreeHandle(
    IN HFILE FileHandle
    );

APIRET
DereferenceFileHandle(
    IN HFILE FileHandle,
    OUT PFILE_HANDLE *hFileRecord
    );

PFILE_HANDLE
DereferenceFileHandleNoCheck(
    IN HFILE FileHandle
    );

VOID
InvalidateHandle(
    IN PFILE_HANDLE hFileRecord
    );

VOID
ValidateHandle(
    IN PFILE_HANDLE hFileRecord
    );


//
// Routines defined in fileinit.c
//

APIRET
Od2InitializeFileSystemForExec(
    IN ULONG ParentTableLength,     // number of entries in handle table
    IN ULONG CurrentDrive           // current drive in parent process
    );

APIRET
Od2InitializeFileSystemForSM(
    IN ULONG DefaultDrive,          // default drive for this session
    IN HANDLE StandardInput,
    IN HANDLE StandardOutput,
    IN HANDLE StandardError
    );

APIRET
Od2InitializeFileSystemForChildSM(
    IN ULONG ParentTableLength,     // number of entries in handle table
    IN ULONG CurrentDrive           // current drive in parent process
    );

APIRET
Od2InitCurrentDir(
    IN ULONG CurrentDisk
    );

//
// Routines defined in name.c
//

APIRET
Canonicalize(
    IN PSZ Name,
    IN ULONG Flags,
    OUT PHANDLE Handle,
    OUT PSTRING CanonicalString,
    OUT PUSHORT FileType,
    OUT PBOOLEAN MetaCharacters,
    OUT PBOOLEAN RootDirectory
    );

PSZ
FindLastComponent(
    IN PSZ String
    );

//
// Routines defined in dllea.c
//

BOOLEAN
NtTimeToFatTimeAndDate (
    OUT PFTIME FatTime,
    OUT PFDATE FatDate,
    IN LARGE_INTEGER NtTime
    );

APIRET
GetEaListLength(
    IN HANDLE NtHandle,
    OUT PULONG EaListSize
);

APIRET
GetGEAList(
    IN HANDLE NtHandle,
    OUT PBYTE UserBuffer,
    IN ULONG Length
);

//
// Routines defined in dllea.c
//

VOID
MapAttributesToOs2(
    IN ULONG NtAttributes,
    OUT PUSHORT Os2Attributes
    );

APIRET
MapEaListToNt(
    IN OUT PBYTE UserBuffer,
    IN ULONG Length,
    OUT PVOID *Buffer,
    OUT PULONG ListLength,
    OUT PULONG BufferLength
);


//
// Routines defined in dlldir.c
//

APIRET
Od2GetCurrentDirectory(
    IN ULONG DiskNumber,
    OUT PSTRING *CurrentDirectoryString,
    OUT PHANDLE CurrentDirectoryHandle,
    IN OUT PULONG DirectoryNameLength,
    IN BOOLEAN Verify
    );

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

NTSTATUS Od2InitializeSessionPort(OUT PBOOLEAN RootProcessInSession);

//
// Routines defined in dllmsg.c
//


#define COMP_ID_LEN         3               // length of component ID


//
// header for a 16 bit (OS/2 1.X) message segment
//

typedef struct _MSGSEGMENT_HEADER16 {
    BYTE Signature[10];                     // "\xffMKMSGSEG"
    USHORT Version;                         // should be 1
    USHORT Reserved;
    USHORT FileTableOffset;
} MSGSEGMENT_HEADER16, *PMSGSEGMENT_HEADER16;


typedef struct _OD2_MSGFILE {
    LIST_ENTRY Link;
    HANDLE SectionHandle;
    PVOID BaseAddress;
    ULONG Size;
    ULONG Type;
    STRING FileName;
} OD2_MSGFILE, *POD2_MSGFILE;

#define MSG_FILE_TYPE_OS2_20 0
#define MSG_FILE_TYPE_OS2_1x 1

typedef struct _OD2_MSGFILE_HEADER {
    ULONG HeaderLength;
    CHAR Signature[ 8 ];
    CHAR Component[ COMP_ID_LEN ];
    CHAR Reserved[ 5 ];
    ULONG CountOfMessages;
    ULONG BaseMessageId;
    ULONG MessageOffsets[ 1 ];
} OD2_MSGFILE_HEADER, *POD2_MSGFILE_HEADER;

APIRET
Od2FindMessageFile(
    IN PSZ MessageFileName,
    OUT POD2_MSGFILE *ReturnedMsgFile
    );

//
// OD2_MESSAGE_RESOURCE_FILENAME defines the file
// string, that if specified as the MessageFileName parameter to DosGetMessage
// or DosQueryMessageCP, will cause the function to access the data in
// the OS/2 system message file.
//

#define OD2_MESSAGE_RESOURCE_FILENAME   "OSO001.MSG"


//
// Od2MsgFile variable points to an OD2_MSGFILE structure that represents the
// OSO001.MSG resource contained in the OS/2 DLL image file.
//

extern POD2_MSGFILE Od2MsgFile;

//
// This function will initialize the Od2MsgFile variable.
//

NTSTATUS
Od2InitializeMessageFile( VOID );

//   Signal numbers
//      these are also defined in os2srv.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

/* Vector exception handlers */

#define VECTOR_DIVIDE_BY_ZERO   0x0000
#define VECTOR_OVERFLOW     0x0004
#define VECTOR_OUTOFBOUNDS  0x0005
#define VECTOR_INVALIDOPCODE    0x0006
#define VECTOR_NO_EXTENSION 0x0007
#define VECTOR_EXTENSION_ERROR  0x0010

typedef struct _OD2_VEC_HANDLER_REC {
    ULONG       VecHandler[6];
    ULONG       doscallssel;
} OD2_VEC_HANDLER_REC, *POD2_VEC_HANDLER_REC;

#define FIELD_SIZE(type, field)     (sizeof( ((type *)0)->field ))

//
// Support for mapping c:\config.sys
// to the OS/2 SS directory
//

BOOLEAN
Od2FileIsConfigSys(
    IN OUT PANSI_STRING FileName_A,
    IN ULONG AccessMode,
    OUT PNTSTATUS ResultStatus
    );

//
// routines in dllnb.c
//


VOID
Od2NetbiosInitialize(
    VOID
    );

VOID
Od2NetbiosDelete(
    VOID
    );


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

#undef FALSE
#define FALSE (BOOLEAN)0

#ifndef MAX
#define MAX(a,b) (((a)>(b))? (a):(b))
#endif