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

Copyright (c) 1991  Microsoft Corporation

Module Name:

    dlltsk16.c

Abstract:

    This module implements 32 equivalents of OS/2 V1.21 Thread/Task
    API Calls. These are called from 16->32 thunks (i386\doscalls.asm).
    Other related calls are in dllldr16.c.


Author:

    Yaron Shamir (YaronS) 30-May-1991

Revision History:

--*/

#define INCL_OS2V20_MEMORY
#define INCL_OS2V20_FILESYS
#define INCL_OS2V20_TASKING
#define INCL_OS2V20_ERRORS
#include "os2dll.h"
#include "os2dll16.h"

typedef struct _RESULTCODES16 {
    USHORT ExitReason;
    USHORT ExitResult;
} RESULTCODES16, *PRESULTCODES16;

APIRET
DosGetPID(
        PPIDINFO16 pidi
        )
{

    pidi->pid = (USHORT)Od2Process->Pib.ProcessId;
    pidi->tid = (USHORT)(Od2CurrentThreadId());
    pidi->pidParent = (USHORT)Od2Process->Pib.ParentProcessId;
    return (NO_ERROR);
}

APIRET
DosGetPPID(
        ULONG pidChild,
        PUSHORT ppidParent
        )
{
    OS2_API_MSG m;
    POS2_DOSGETPPID_MSG a = &m.u.DosGetPPID;
    APIRET rc;

    try
    {
        Od2ProbeForWrite(ppidParent, sizeof(USHORT), 1);
    }
    except (EXCEPTION_EXECUTE_HANDLER) {
       Od2ExitGP();
    }

    a->ChildPid = (PID)pidChild;

    rc = Od2CallSubsystem( &m, NULL, Os2GetPPID, sizeof( *a ) );

    if (rc == NO_ERROR) {
        *ppidParent = (USHORT)a->ParentPid;
    }
    return(rc);
}

APIRET
Dos16ExitList(
    ULONG OrderCode,
    PFNEXITLIST ExitRoutine
    )
{
    return( Od2ExitList( OrderCode,
                         (PFNEXITLIST) (FLATTOFARPTR((ULONG)(ExitRoutine))),
                         FALSE ) );
}

APIRET
Dos16ExecPgm(
    OUT PSZ ErrorText OPTIONAL,
    IN LONG MaximumErrorTextLength,
    IN ULONG Flags,
    IN PSZ Arguments OPTIONAL,
    IN PSZ Variables OPTIONAL,
    OUT PRESULTCODES16 pResultCodes16,
    IN PSZ ImageFileName)
{
    RESULTCODES ResultCodes;
    APIRET rc;

    try
    {
        Od2ProbeForWrite(pResultCodes16, sizeof(PRESULTCODES16), 1);
    } except( EXCEPTION_EXECUTE_HANDLER )
    {
       Od2ExitGP();
    }

    ResultCodes.ExitReason = (ULONG)pResultCodes16->ExitReason;
    ResultCodes.ExitResult = (ULONG)pResultCodes16->ExitResult;

    rc = DosExecPgm(ErrorText,
                    MaximumErrorTextLength,
                    Flags,
                    Arguments,
                    Variables,
                    &ResultCodes,
                    ImageFileName);

    pResultCodes16->ExitReason = (USHORT)ResultCodes.ExitReason;
    pResultCodes16->ExitResult = (USHORT)ResultCodes.ExitResult;

    return(rc);
}

APIRET
Dos16WaitChild(
    IN  ULONG          WaitTarget,
    IN  ULONG          WaitOption,
    OUT PRESULTCODES16 pResultCodes16,
    OUT PPID16         pResultProcessId16,
    IN  PID            ProcessId
    )
{
    RESULTCODES ResultCodes;
    PID         ResultProcessId;
    APIRET      rc;

    try
    {
        Od2ProbeForWrite(pResultCodes16, sizeof(PRESULTCODES16), 1);
        Od2ProbeForWrite(pResultProcessId16, sizeof(PPID16), 1);
    } except( EXCEPTION_EXECUTE_HANDLER )
    {
       Od2ExitGP();
    }

    ResultProcessId = (PID) *pResultProcessId16;
    ResultCodes.ExitReason = (ULONG)pResultCodes16->ExitReason;
    ResultCodes.ExitResult = (ULONG)pResultCodes16->ExitResult;

    rc = DosWaitChild(  WaitTarget,
                        WaitOption,
                        &ResultCodes,
                        &ResultProcessId,
                        ProcessId);

    pResultCodes16->ExitReason = (USHORT)ResultCodes.ExitReason;
    pResultCodes16->ExitResult = (USHORT)ResultCodes.ExitResult;
    *pResultProcessId16 = (PID16)ResultProcessId;

    return(rc);
}