| 1 | /* $Id: OS2KTK.h,v 1.5 2001-07-10 05:23:21 bird Exp $
 | 
|---|
| 2 |  *
 | 
|---|
| 3 |  * OS2KTK - OS/2 Kernel Task.
 | 
|---|
| 4 |  *
 | 
|---|
| 5 |  * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
 | 
|---|
| 6 |  *
 | 
|---|
| 7 |  * Project Odin Software License can be found in LICENSE.TXT
 | 
|---|
| 8 |  *
 | 
|---|
| 9 |  */
 | 
|---|
| 10 | #ifndef _OS2KTK_h_
 | 
|---|
| 11 | #define _OS2KTK_h_
 | 
|---|
| 12 | 
 | 
|---|
| 13 | #ifdef __cplusplus
 | 
|---|
| 14 | extern "C" {
 | 
|---|
| 15 | #endif
 | 
|---|
| 16 | 
 | 
|---|
| 17 | 
 | 
|---|
| 18 | /*******************************************************************************
 | 
|---|
| 19 | *   Defined Constants And Macros                                               *
 | 
|---|
| 20 | *******************************************************************************/
 | 
|---|
| 21 | #define TK_FUSU_FATAL       0x3         /* Traps the task on failure. */
 | 
|---|
| 22 | #define TK_FUSU_NONFATAL    0x0         /* Returns error code to caller on failure. */
 | 
|---|
| 23 | #define TK_FUSU_USER_SRC    0x10        /* Source buffer is in user memory. (TKSuFuBuff) */
 | 
|---|
| 24 | #define TK_FUSU_USER_DST    0x20        /* Target buffer is in user memory. (TKSuFuBuff) */
 | 
|---|
| 25 | 
 | 
|---|
| 26 | 
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #define TKFuChar(pch, pchUsr) \
 | 
|---|
| 29 |             TKFuBuff((PVOID)pch, (PVOID)pchUsr, sizeof(char), TK_FUSU_FATAL)
 | 
|---|
| 30 | #define TKSuChar(pchUsr, pch) \
 | 
|---|
| 31 |             TKSuBuff((PVOID)pchUsr, (PVOID)pch, sizeof(char), TK_FUSU_FATAL)
 | 
|---|
| 32 | 
 | 
|---|
| 33 | #define TKFuCharNF(pch, pchUsr) \
 | 
|---|
| 34 |             TKFuBuff((PVOID)pch, (PVOID)pchUsr, sizeof(char), TK_FUSU_NONFATAL)
 | 
|---|
| 35 | #define TKSuCharNF(pchUsr, pch) \
 | 
|---|
| 36 |             TKSuBuff((PVOID)pchUsr, (PVOID)pch, sizeof(char), TK_FUSU_NONFATAL)
 | 
|---|
| 37 | 
 | 
|---|
| 38 | 
 | 
|---|
| 39 | #define TKFuUShort(pus, pusUsr) \
 | 
|---|
| 40 |             TKFuBuff((PVOID)pus, (PVOID)pusUsr, sizeof(USHORT), TK_FUSU_FATAL)
 | 
|---|
| 41 | #define TKSuUShort(pusUsr, pus) \
 | 
|---|
| 42 |             TKSuBuff((PVOID)pusUsr, (PVOID)pus, sizeof(USHORT), TK_FUSU_FATAL)
 | 
|---|
| 43 | 
 | 
|---|
| 44 | #define TKFuUShortNF(pus, pusUsr) \
 | 
|---|
| 45 |             TKFuBuff((PVOID)pus, (PVOID)pusUsr, sizeof(USHORT), TK_FUSU_NONFATAL)
 | 
|---|
| 46 | #define TKSuUShortNF(pusUsr, pus) \
 | 
|---|
| 47 |             TKSuBuff((PVOID)pusUsr, (PVOID)pus, sizeof(USHORT), TK_FUSU_NONFATAL)
 | 
|---|
| 48 | 
 | 
|---|
| 49 | 
 | 
|---|
| 50 | #define TKFuULong(pul, pulUsr) \
 | 
|---|
| 51 |             TKFuBuff((PVOID)pul, (PVOID)pulUsr, sizeof(ULONG), TK_FUSU_FATAL)
 | 
|---|
| 52 | #define TKSuULong(pulUsr, pul) \
 | 
|---|
| 53 |             TKSuBuff((PVOID)pulUsr, (PVOID)pul, sizeof(ULONG), TK_FUSU_FATAL)
 | 
|---|
| 54 | 
 | 
|---|
| 55 | #define TKFuULongNF(pul, pulUsr) \
 | 
|---|
| 56 |             TKFuBuff((PVOID)pul, (PVOID)pulUsr, sizeof(ULONG), TK_FUSU_NONFATAL)
 | 
|---|
| 57 | #define TKSuULongNF(pulUsr, pul) \
 | 
|---|
| 58 |             TKSuBuff((PVOID)pulUsr, (PVOID)pul, sizeof(ULONG), TK_FUSU_NONFATAL)
 | 
|---|
| 59 | 
 | 
|---|
| 60 | 
 | 
|---|
| 61 | #define TKFuStrLen(pcch, pvUsr, cchMax) \
 | 
|---|
| 62 |             TKFuBufLen(pcch, pvUsr, cchMax, TK_FUSU_FATAL, FALSE)
 | 
|---|
| 63 | #define TKFuStrLenNZ(pcch, pvUsr, cchMax) \
 | 
|---|
| 64 |             TKFuBufLenNZ(pcch, pvUsr, cchMax, TK_FUSU_NONFATAL, FALSE)
 | 
|---|
| 65 | 
 | 
|---|
| 66 | #define TKFuStrLenZ(pcch, pvUsr, cchMax) \
 | 
|---|
| 67 |             TKFuBufLenZ(pcch, pvUsr, cchMax, TK_FUSU_FATAL, TRUE)
 | 
|---|
| 68 | #define TKFuStrLenZNZ(pcch, pvUsr, cchMax) \
 | 
|---|
| 69 |             TKFuBufLenZNZ(pcch, pvUsr, cchMax, TK_FUSU_NONFATAL, TRUE)
 | 
|---|
| 70 | 
 | 
|---|
| 71 | 
 | 
|---|
| 72 | 
 | 
|---|
| 73 | /*******************************************************************************
 | 
|---|
| 74 | *   External Functions                                                         *
 | 
|---|
| 75 | *******************************************************************************/
 | 
|---|
| 76 | 
 | 
|---|
| 77 | /**
 | 
|---|
| 78 |  * Copy user memory into system memory.
 | 
|---|
| 79 |  * @returns   OS/2 return code. (NO_ERROR is success)
 | 
|---|
| 80 |  * @param     pv     Pointer to target (system) data area.
 | 
|---|
| 81 |  * @param     pvUsr  Pointer to source (user) data area.
 | 
|---|
| 82 |  * @param     cb     Count of bytes to copy.
 | 
|---|
| 83 |  * @param     fl     Flags.
 | 
|---|
| 84 |  */
 | 
|---|
| 85 | extern ULONG KRNLCALL   TKFuBuff(PVOID pv, PVOID pvUsr, ULONG cb, ULONG fl);
 | 
|---|
| 86 | 
 | 
|---|
| 87 | 
 | 
|---|
| 88 | /**
 | 
|---|
| 89 |  * Copy system memory to user memory.
 | 
|---|
| 90 |  * @returns   OS/2 return code. (NO_ERROR is success)
 | 
|---|
| 91 |  * @param     pvUsr  Pointer to target (user) data area.
 | 
|---|
| 92 |  * @param     pv     Pointer to source (system) data area.
 | 
|---|
| 93 |  * @param     cb     Count of bytes to copy.
 | 
|---|
| 94 |  * @param     fl     Flags.
 | 
|---|
| 95 |  */
 | 
|---|
| 96 | extern ULONG KRNLCALL   TKSuBuff(PVOID pvUsr, PVOID pv, ULONG cb, ULONG fl);
 | 
|---|
| 97 | 
 | 
|---|
| 98 | 
 | 
|---|
| 99 | /**
 | 
|---|
| 100 |  * String length.
 | 
|---|
| 101 |  * @returns   OS/2 return code. (NO_ERROR is success)
 | 
|---|
| 102 |  * @param     pcch      Pointer to length variable.
 | 
|---|
| 103 |  * @param     pvUsr     Pointer to user data to preform string length on.
 | 
|---|
| 104 |  * @param     cchMax    Max string length.
 | 
|---|
| 105 |  * @param     fl        Flags.
 | 
|---|
| 106 |  * @param     fDblNULL  TRUE:  Double '\0' (ie. '\0\0') terminated. Usefull for scanning environments.
 | 
|---|
| 107 |  *                      FALSE: Single string. (ie. one '\0').
 | 
|---|
| 108 |  */
 | 
|---|
| 109 | extern ULONG KRNLCALL   TKFuBufLen(PLONG pcch, PVOID pvUsr, ULONG cchMax, ULONG fl, BOOL fDblNULL);
 | 
|---|
| 110 | 
 | 
|---|
| 111 | 
 | 
|---|
| 112 | /**
 | 
|---|
| 113 |  * Copy user memory to user memory.
 | 
|---|
| 114 |  * @returns   OS/2 return code. (NO_ERROR is success)
 | 
|---|
| 115 |  * @param     pvTarget  Pointer to target (user) data area.
 | 
|---|
| 116 |  * @param     pvSource  Pointer to source (user) data area.
 | 
|---|
| 117 |  * @param     cb        Count of bytes to copy.
 | 
|---|
| 118 |  * @param     fl        Flags.
 | 
|---|
| 119 |  */
 | 
|---|
| 120 | extern ULONG KRNLCALL   TKSuFuBuff(PVOID pvTarget, PVOID pvSource, ULONG cb, ULONG fl);
 | 
|---|
| 121 | 
 | 
|---|
| 122 | 
 | 
|---|
| 123 | #ifdef INCL_OS2KRNL_PTDA
 | 
|---|
| 124 | /**
 | 
|---|
| 125 |  * PID to PTDA pointer.
 | 
|---|
| 126 |  * @returns     OS/2 return code.
 | 
|---|
| 127 |  * @param       pid     Process Identifier.
 | 
|---|
| 128 |  * @param       ppPTDA  Pointer to the PTDA-pointer variabel which is to receive
 | 
|---|
| 129 |  *                      the PTDA pointer on successful return.
 | 
|---|
| 130 |  */
 | 
|---|
| 131 | extern ULONG KRNLCALL  TKPidToPTDA(PID pid, PPPTDA ppPTDA);
 | 
|---|
| 132 | #endif
 | 
|---|
| 133 | 
 | 
|---|
| 134 | 
 | 
|---|
| 135 | /**
 | 
|---|
| 136 |  * Post signal to one or more processes.
 | 
|---|
| 137 |  * @returns  NO_ERROR on success.
 | 
|---|
| 138 |  *           On error ERROR_NOT_DESCENDANT, ERROR_SIGNAL_REFUSED,
 | 
|---|
| 139 |  *           ERROR_INVALID_PROCID, ERROR_ZOMBIE_PROCESS, ERROR_SIGNAL_PENDING. (it seems)
 | 
|---|
| 140 |  * @param    usSignal       Signal number.
 | 
|---|
| 141 |  * @param    usAction       Action.
 | 
|---|
| 142 |  *                          0 - the process and all children.
 | 
|---|
| 143 |  *                          1 - only the process
 | 
|---|
| 144 |  *                          2 - the process and all it's decendants.
 | 
|---|
| 145 |  *                          3 - all processes in that screen group.
 | 
|---|
| 146 |  * @param    usSignalArg    Signal argument.
 | 
|---|
| 147 |  * @param    usPIDSGR       Process Id or Screen Group Id.
 | 
|---|
| 148 |  */
 | 
|---|
| 149 | extern ULONG _Optlink POST_SIGNAL32(USHORT usSignal, USHORT usAction, USHORT usSignalArg, USHORT usPIDSGR);
 | 
|---|
| 150 | 
 | 
|---|
| 151 | #ifdef __cplusplus
 | 
|---|
| 152 | }
 | 
|---|
| 153 | #endif
 | 
|---|
| 154 | 
 | 
|---|
| 155 | 
 | 
|---|
| 156 | #ifdef INCL_OS2KRNL_TCB
 | 
|---|
| 157 | /**
 | 
|---|
| 158 |  * Force a thread to be made ready.
 | 
|---|
| 159 |  * @param   flFlag  Which flag(s?) to set.
 | 
|---|
| 160 |  * @param   pTCB    Pointer to the thread control block of the thread to be forced.
 | 
|---|
| 161 |  */
 | 
|---|
| 162 | extern void KRNLCALL TKForceThread(ULONG flFlag, PTCB pTCB);
 | 
|---|
| 163 | #endif
 | 
|---|
| 164 | 
 | 
|---|
| 165 | #ifdef INCL_OS2KRNL_PTDA
 | 
|---|
| 166 | /**
 | 
|---|
| 167 |  * Set force flag on a task.
 | 
|---|
| 168 |  * @param   flFlag  Which flag(s?) to set.
 | 
|---|
| 169 |  * @param   pPTDA   Pointer to the PTDA of the task to be processed.
 | 
|---|
| 170 |  * @param   fForce  FALSE   Just set the flag on all threads.
 | 
|---|
| 171 |  *                  TRUE    Force all threads ready by calling TKForceThread.
 | 
|---|
| 172 |  */
 | 
|---|
| 173 | extern void KRNLCALL  TKForceTask(ULONG flFlag, PPTDA pPTDA, BOOL fForce);
 | 
|---|
| 174 | #endif
 | 
|---|
| 175 | 
 | 
|---|
| 176 | #ifdef INCL_OS2KRNL_TCB
 | 
|---|
| 177 | /**
 | 
|---|
| 178 |  * Get priotity of a thread.
 | 
|---|
| 179 |  * @returns Thread priority.
 | 
|---|
| 180 |  * @param   pTCB    pointer to the TCB of the thread in question.
 | 
|---|
| 181 |  */
 | 
|---|
| 182 | extern ULONG KRNLCALL TKGetPriority(PTCB pTCB);
 | 
|---|
| 183 | #endif
 | 
|---|
| 184 | 
 | 
|---|
| 185 | /**
 | 
|---|
| 186 |  * Make current thread sleep.
 | 
|---|
| 187 |  * @returns NO_ERROR on success.
 | 
|---|
| 188 |  *          ERROR_INTERRUPT if a signal is forced on the thread.
 | 
|---|
| 189 |  *          ERROR_TIMEOUT if we timeout.
 | 
|---|
| 190 |  * @param   ulSleepId   32-bit sleep id which TKWakeup will be called with.
 | 
|---|
| 191 |  * @param   ulTimeout   Number of milliseconds to sleep. (0 is not yield)
 | 
|---|
| 192 |  *                      -1 means forever or till wakeup.
 | 
|---|
| 193 |  * @param   fUnint      TRUE:  may not interrupt sleep.
 | 
|---|
| 194 |  *                      FALSE: may interrupt sleep.
 | 
|---|
| 195 |  * @param   flSleepType ???
 | 
|---|
| 196 |  */
 | 
|---|
| 197 | extern ULONG KRNLCALL TKSleep(ULONG ulSleepId, ULONG ulTimeout, ULONG fUnInterruptable, ULONG flWakeupType);
 | 
|---|
| 198 | 
 | 
|---|
| 199 | /**
 | 
|---|
| 200 |  * Wakeup sleeping thread(s).
 | 
|---|
| 201 |  * @returns NO_ERROR on succes.
 | 
|---|
| 202 |  *          Appropriate error code on failure.
 | 
|---|
| 203 |  * @param   ulSleepId       32-bit sleep id which threads are sleeping on.
 | 
|---|
| 204 |  * @param   flWakeUpType    How/what to wakeup.
 | 
|---|
| 205 |  * @param   pcWakedUp       Pointer to variable which is to hold the count of
 | 
|---|
| 206 |  *                          thread waked up.
 | 
|---|
| 207 |  */
 | 
|---|
| 208 | extern ULONG KRNLCALL TKWakeup(ULONG ulSleepId, ULONG flWakeupType, PULONG cWakedUp);
 | 
|---|
| 209 | 
 | 
|---|
| 210 | #ifdef INCL_OS2KRNL_TCB
 | 
|---|
| 211 | /**
 | 
|---|
| 212 |  * Wake up a single thread.
 | 
|---|
| 213 |  * @returns NO_ERROR on succes.
 | 
|---|
| 214 |  *          Appropriate error code on failure.
 | 
|---|
| 215 |  * @param   pTCB    Pointer to the TCB of the thread to be waken.
 | 
|---|
| 216 |  */
 | 
|---|
| 217 | extern ULONG KRNLCALL TKWakeThread(PTCB pTCB);
 | 
|---|
| 218 | #endif
 | 
|---|
| 219 | 
 | 
|---|
| 220 | #ifdef INCL_OS2KRNL_TCB
 | 
|---|
| 221 | /**
 | 
|---|
| 222 |  * See which thread will be Wakeup.
 | 
|---|
| 223 |  * @returns Pointer to TCB of the thread on success.
 | 
|---|
| 224 |  *          NULL on failure or no threads.
 | 
|---|
| 225 |  * @param   ulSleepId       32-bit sleep id which threads are sleeping on.
 | 
|---|
| 226 |  * @param   flWakeUpType    How/what to wakeup.
 | 
|---|
| 227 |  */
 | 
|---|
| 228 | extern PTCB  KRNLCALL TKQueryWakeup(ULONG ulSleepId, ULONG flWakeupType);
 | 
|---|
| 229 | #endif
 | 
|---|
| 230 | 
 | 
|---|
| 231 | #endif
 | 
|---|