| 1 | /* $Id: kobjects.cpp,v 1.16 2003-02-04 11:29:01 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 5 | * Win32 compatibility file functions for OS/2 | 
|---|
| 6 | * Copyright 1998 Sander van Leeuven | 
|---|
| 7 | * Copyright 1998 Patrick Haller | 
|---|
| 8 | * Copyright 1998 Peter Fitzsimmons | 
|---|
| 9 | * Copyright 1998 Knut St. Osmundsen | 
|---|
| 10 | */ | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 | /***************************************************************************** | 
|---|
| 14 | * Includes                                                                  * | 
|---|
| 15 | *****************************************************************************/ | 
|---|
| 16 |  | 
|---|
| 17 | #include <odin.h> | 
|---|
| 18 | #include <odinwrap.h> | 
|---|
| 19 | #include <os2sel.h> | 
|---|
| 20 |  | 
|---|
| 21 | #include <os2win.h> | 
|---|
| 22 | #include <misc.h> | 
|---|
| 23 | #include <unicode.h> | 
|---|
| 24 | #include <handlemanager.h> | 
|---|
| 25 |  | 
|---|
| 26 | #define DBG_LOCALLOG    DBG_kobjects | 
|---|
| 27 | #include "dbglocal.h" | 
|---|
| 28 |  | 
|---|
| 29 |  | 
|---|
| 30 | ODINDEBUGCHANNEL(KERNEL32-KOBJECTS) | 
|---|
| 31 |  | 
|---|
| 32 |  | 
|---|
| 33 | /***************************************************************************** | 
|---|
| 34 | * Defines                                                                   * | 
|---|
| 35 | *****************************************************************************/ | 
|---|
| 36 |  | 
|---|
| 37 | /* this define enables certain less important debug messages */ | 
|---|
| 38 | //#define DEBUG_LOCAL 1 | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 |  | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 |  | 
|---|
| 45 |  | 
|---|
| 46 | /***************************************************************************** | 
|---|
| 47 | * Name      : BOOL CreateMutexW | 
|---|
| 48 | * Purpose   : forward call to Open32 | 
|---|
| 49 | * Parameters: | 
|---|
| 50 | * Variables : | 
|---|
| 51 | * Result    : | 
|---|
| 52 | * Remark    : handle translation is done in CreateMutexW | 
|---|
| 53 | * Status    : | 
|---|
| 54 | * | 
|---|
| 55 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 56 | *****************************************************************************/ | 
|---|
| 57 |  | 
|---|
| 58 | HANDLE WIN32API CreateMutexW(LPSECURITY_ATTRIBUTES arg1, BOOL arg2, | 
|---|
| 59 | LPCWSTR arg3) | 
|---|
| 60 | { | 
|---|
| 61 | HANDLE rc; | 
|---|
| 62 | char  *astring; | 
|---|
| 63 |  | 
|---|
| 64 | if (arg3 != NULL) // support for unnamed mutexes | 
|---|
| 65 | astring = UnicodeToAsciiString((LPWSTR)arg3); | 
|---|
| 66 | else | 
|---|
| 67 | astring = NULL; | 
|---|
| 68 |  | 
|---|
| 69 | rc = CreateMutexA(arg1, | 
|---|
| 70 | arg2, | 
|---|
| 71 | astring); | 
|---|
| 72 |  | 
|---|
| 73 | if (astring != NULL) | 
|---|
| 74 | FreeAsciiString(astring); | 
|---|
| 75 |  | 
|---|
| 76 | return(rc); | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 |  | 
|---|
| 80 | /***************************************************************************** | 
|---|
| 81 | * Name      : BOOL WaitForSingleObject | 
|---|
| 82 | * Purpose   : forward call to Open32 | 
|---|
| 83 | * Parameters: | 
|---|
| 84 | * Variables : | 
|---|
| 85 | * Result    : | 
|---|
| 86 | * Remark    : handle translation is done in WaitForSingleObject | 
|---|
| 87 | * Status    : | 
|---|
| 88 | * | 
|---|
| 89 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 90 | *****************************************************************************/ | 
|---|
| 91 |  | 
|---|
| 92 | DWORD WIN32API WaitForSingleObject(HANDLE hObject, DWORD timeout) | 
|---|
| 93 | { | 
|---|
| 94 | return(HMWaitForSingleObject(hObject, | 
|---|
| 95 | timeout)); | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 |  | 
|---|
| 99 | /***************************************************************************** | 
|---|
| 100 | * Name      : DWORD WaitForSingleObjectEx | 
|---|
| 101 | * Purpose   : The WaitForSingleObjectEx function is an extended wait function | 
|---|
| 102 | *             that can be used to perform an alertable wait. This enables the | 
|---|
| 103 | *             function to return when the system queues an I/O completion | 
|---|
| 104 | *             routine to be executed by the calling thread. The function also | 
|---|
| 105 | *             returns when the specified object is in the signaled state or | 
|---|
| 106 | *             when the time-out interval elapses. | 
|---|
| 107 | * Parameters: HANDLE hObject     handle of object to wait for | 
|---|
| 108 | *             DWORD  dwTimeout   time-out interval in milliseconds | 
|---|
| 109 | *             BOOL   fAlertable  alertable wait flag | 
|---|
| 110 | * Variables : | 
|---|
| 111 | * Result    : 0xFFFFFFFF in case of error | 
|---|
| 112 | * Remark    : only really required for async I/O | 
|---|
| 113 | * Status    : UNTESTED STUB | 
|---|
| 114 | * | 
|---|
| 115 | * Author    : Patrick Haller [Mon, 1998/06/15 08:00] | 
|---|
| 116 | *****************************************************************************/ | 
|---|
| 117 |  | 
|---|
| 118 | DWORD WIN32API WaitForSingleObjectEx(HANDLE hObject, DWORD dwTimeout, BOOL fAlertable) | 
|---|
| 119 | { | 
|---|
| 120 | dprintf(("Kernel32: WaitForSingleObjectEx(%08xh,%08xh,%08xh) not implemented correctly.\n", | 
|---|
| 121 | hObject, | 
|---|
| 122 | dwTimeout, | 
|---|
| 123 | fAlertable)); | 
|---|
| 124 |  | 
|---|
| 125 | return(HMWaitForSingleObjectEx(hObject, | 
|---|
| 126 | dwTimeout, | 
|---|
| 127 | fAlertable)); | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 |  | 
|---|
| 132 | /***************************************************************************** | 
|---|
| 133 | * Name      : UINT SetHandleCount | 
|---|
| 134 | * Purpose   : forward call to Open32 | 
|---|
| 135 | * Parameters: | 
|---|
| 136 | * Variables : | 
|---|
| 137 | * Result    : | 
|---|
| 138 | * Remark    : handle translation is done in SetHandleCount | 
|---|
| 139 | * Status    : | 
|---|
| 140 | * | 
|---|
| 141 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 142 | *****************************************************************************/ | 
|---|
| 143 |  | 
|---|
| 144 | UINT WIN32API SetHandleCount(UINT cHandles) | 
|---|
| 145 | { | 
|---|
| 146 | //SvL: Has no effect in NT; also ignore it | 
|---|
| 147 | return cHandles; | 
|---|
| 148 | } | 
|---|
| 149 |  | 
|---|
| 150 |  | 
|---|
| 151 | /***************************************************************************** | 
|---|
| 152 | * Name      : BOOL DuplicateHandle | 
|---|
| 153 | * Purpose   : forward call to Open32 | 
|---|
| 154 | * Parameters: | 
|---|
| 155 | * Variables : | 
|---|
| 156 | * Result    : | 
|---|
| 157 | * Remark    : handle translation is done in DuplicateHandle | 
|---|
| 158 | * Status    : | 
|---|
| 159 | * | 
|---|
| 160 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 161 | *****************************************************************************/ | 
|---|
| 162 |  | 
|---|
| 163 | BOOL WIN32API DuplicateHandle(HANDLE srcprocess, HANDLE srchandle, | 
|---|
| 164 | HANDLE destprocess, PHANDLE desthandle, | 
|---|
| 165 | DWORD arg5, BOOL arg6, DWORD arg7) | 
|---|
| 166 | { | 
|---|
| 167 | BOOL rc; | 
|---|
| 168 |  | 
|---|
| 169 | rc = HMDuplicateHandle(srcprocess, | 
|---|
| 170 | srchandle, | 
|---|
| 171 | destprocess, | 
|---|
| 172 | desthandle, | 
|---|
| 173 | arg5, | 
|---|
| 174 | arg6, | 
|---|
| 175 | arg7); | 
|---|
| 176 | //@@@PH: (temporary) fix for non-HandleManager handles | 
|---|
| 177 | if (rc == FALSE) | 
|---|
| 178 | rc = O32_DuplicateHandle(srcprocess, | 
|---|
| 179 | srchandle, | 
|---|
| 180 | destprocess, | 
|---|
| 181 | desthandle, | 
|---|
| 182 | arg5, | 
|---|
| 183 | arg6, | 
|---|
| 184 | arg7); | 
|---|
| 185 |  | 
|---|
| 186 | return(rc); | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 |  | 
|---|
| 190 |  | 
|---|
| 191 | /***************************************************************************** | 
|---|
| 192 | * Name      : BOOL CreateSemaphoreW | 
|---|
| 193 | * Purpose   : forward call to Open32 | 
|---|
| 194 | * Parameters: | 
|---|
| 195 | * Variables : | 
|---|
| 196 | * Result    : | 
|---|
| 197 | * Remark    : handle translation is done in CreateSemaphoreW | 
|---|
| 198 | * Status    : | 
|---|
| 199 | * | 
|---|
| 200 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 201 | *****************************************************************************/ | 
|---|
| 202 |  | 
|---|
| 203 | HANDLE WIN32API CreateSemaphoreW(LPSECURITY_ATTRIBUTES arg1, LONG arg2, | 
|---|
| 204 | LONG arg3, LPCWSTR arg4) | 
|---|
| 205 | { | 
|---|
| 206 | HANDLE rc; | 
|---|
| 207 | char   *astring; | 
|---|
| 208 |  | 
|---|
| 209 | if (arg4 != NULL) // support for unnamed semaphores | 
|---|
| 210 | astring = UnicodeToAsciiString((LPWSTR)arg4); | 
|---|
| 211 | else | 
|---|
| 212 | astring = NULL; | 
|---|
| 213 |  | 
|---|
| 214 | rc = CreateSemaphoreA(arg1, | 
|---|
| 215 | arg2, | 
|---|
| 216 | arg3, | 
|---|
| 217 | astring); | 
|---|
| 218 |  | 
|---|
| 219 | if (astring != NULL) | 
|---|
| 220 | FreeAsciiString(astring); | 
|---|
| 221 | return(rc); | 
|---|
| 222 | } | 
|---|
| 223 |  | 
|---|
| 224 |  | 
|---|
| 225 | /***************************************************************************** | 
|---|
| 226 | * Name      : BOOL | 
|---|
| 227 | * Purpose   : forward call to Open32 | 
|---|
| 228 | * Parameters: | 
|---|
| 229 | * Variables : | 
|---|
| 230 | * Result    : | 
|---|
| 231 | * Remark    : handle translation is done in OpenEventW | 
|---|
| 232 | * Status    : | 
|---|
| 233 | * | 
|---|
| 234 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 235 | *****************************************************************************/ | 
|---|
| 236 |  | 
|---|
| 237 | HANDLE WIN32API  OpenEventW(DWORD dwDesiredAccess, BOOL bInheritHandle, | 
|---|
| 238 | LPCWSTR lpName) | 
|---|
| 239 | { | 
|---|
| 240 | char  *asciiname; | 
|---|
| 241 | HANDLE rc; | 
|---|
| 242 |  | 
|---|
| 243 | asciiname = UnicodeToAsciiString((LPWSTR)lpName); | 
|---|
| 244 |  | 
|---|
| 245 | rc = OpenEventA(dwDesiredAccess, | 
|---|
| 246 | bInheritHandle, | 
|---|
| 247 | asciiname); | 
|---|
| 248 | FreeAsciiString(asciiname); | 
|---|
| 249 | return(rc); | 
|---|
| 250 | } | 
|---|
| 251 |  | 
|---|
| 252 |  | 
|---|
| 253 | /***************************************************************************** | 
|---|
| 254 | * Name      : BOOL OpenMutexW | 
|---|
| 255 | * Purpose   : forward call to Open32 | 
|---|
| 256 | * Parameters: | 
|---|
| 257 | * Variables : | 
|---|
| 258 | * Result    : | 
|---|
| 259 | * Remark    : handle translation is done in OpenMutexW | 
|---|
| 260 | * Status    : | 
|---|
| 261 | * | 
|---|
| 262 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 263 | *****************************************************************************/ | 
|---|
| 264 |  | 
|---|
| 265 | HANDLE WIN32API OpenMutexW(DWORD dwDesiredAccess, BOOL bInheritHandle, | 
|---|
| 266 | LPCWSTR lpName) | 
|---|
| 267 | { | 
|---|
| 268 | char  *asciiname; | 
|---|
| 269 | HANDLE rc; | 
|---|
| 270 |  | 
|---|
| 271 | asciiname = UnicodeToAsciiString((LPWSTR)lpName); | 
|---|
| 272 |  | 
|---|
| 273 | rc = OpenMutexA(dwDesiredAccess, | 
|---|
| 274 | bInheritHandle, | 
|---|
| 275 | asciiname); | 
|---|
| 276 | FreeAsciiString(asciiname); | 
|---|
| 277 | return(rc); | 
|---|
| 278 | } | 
|---|
| 279 |  | 
|---|
| 280 |  | 
|---|
| 281 | /***************************************************************************** | 
|---|
| 282 | * Name      : BOOL OpenSemaphoreW | 
|---|
| 283 | * Purpose   : forward call to Open32 | 
|---|
| 284 | * Parameters: | 
|---|
| 285 | * Variables : | 
|---|
| 286 | * Result    : | 
|---|
| 287 | * Remark    : handle translation is done in OpenSemaphoreW | 
|---|
| 288 | * Status    : | 
|---|
| 289 | * | 
|---|
| 290 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 291 | *****************************************************************************/ | 
|---|
| 292 |  | 
|---|
| 293 | HANDLE WIN32API OpenSemaphoreW(DWORD dwDesiredAccess, BOOL bInheritHandle, | 
|---|
| 294 | LPCWSTR lpName) | 
|---|
| 295 | { | 
|---|
| 296 | char  *asciiname; | 
|---|
| 297 | HANDLE rc; | 
|---|
| 298 |  | 
|---|
| 299 | asciiname = UnicodeToAsciiString((LPWSTR)lpName); | 
|---|
| 300 |  | 
|---|
| 301 | rc = OpenSemaphoreA(dwDesiredAccess, | 
|---|
| 302 | bInheritHandle, | 
|---|
| 303 | asciiname); | 
|---|
| 304 | FreeAsciiString(asciiname); | 
|---|
| 305 | return(rc); | 
|---|
| 306 | } | 
|---|
| 307 |  | 
|---|
| 308 |  | 
|---|
| 309 |  | 
|---|
| 310 | /***************************************************************************** | 
|---|
| 311 | * Name      : BOOL WaitForMultipleObjects | 
|---|
| 312 | * Purpose   : forward call to Open32 | 
|---|
| 313 | * Parameters: | 
|---|
| 314 | * Variables : | 
|---|
| 315 | * Result    : | 
|---|
| 316 | * Remark    : handle translation is done in WaitForMultipleObjects | 
|---|
| 317 | * Status    : | 
|---|
| 318 | * | 
|---|
| 319 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 320 | *****************************************************************************/ | 
|---|
| 321 |  | 
|---|
| 322 | DWORD WIN32API WaitForMultipleObjects(DWORD arg1, const HANDLE * arg2, | 
|---|
| 323 | BOOL arg3, DWORD arg4) | 
|---|
| 324 | { | 
|---|
| 325 | return HMWaitForMultipleObjects(arg1, | 
|---|
| 326 | (PHANDLE)arg2, | 
|---|
| 327 | arg3, | 
|---|
| 328 | arg4); | 
|---|
| 329 | } | 
|---|
| 330 |  | 
|---|
| 331 |  | 
|---|
| 332 | /***************************************************************************** | 
|---|
| 333 | * Name      : DWORD OS2WaitForMultipleObjectsEx | 
|---|
| 334 | * Purpose   : The WaitForMultipleObjectsEx function is an extended wait | 
|---|
| 335 | *             function that can be used to perform an alertable wait. This | 
|---|
| 336 | *             enables the function to return when the system queues an I/O | 
|---|
| 337 | *             completion routine to be executed by the calling thread. The | 
|---|
| 338 | *             function also returns either when any one or when all of the | 
|---|
| 339 | *             specified objects are in the signaled state, or when the | 
|---|
| 340 | *             time-out interval elapses. | 
|---|
| 341 | * Parameters: DWORD  cObjects    number of handles in handle array | 
|---|
| 342 | *             HANDLE *lphObjects address of object-handle array | 
|---|
| 343 | *             BOOL   fWaitAll    wait flag | 
|---|
| 344 | *             DWORD  dwTimeout   time-out interval in milliseconds | 
|---|
| 345 | *             BOOL   fAlertable  alertable wait flag | 
|---|
| 346 | * Variables : | 
|---|
| 347 | * Result    : 0xFFFFFFFF in case of error | 
|---|
| 348 | * Remark    : only really required for async I/O | 
|---|
| 349 | * Status    : UNTESTED STUB | 
|---|
| 350 | * | 
|---|
| 351 | * Author    : Patrick Haller [Mon, 1998/06/15 08:00] | 
|---|
| 352 | *****************************************************************************/ | 
|---|
| 353 |  | 
|---|
| 354 | DWORD WIN32API WaitForMultipleObjectsEx(DWORD cObjects, CONST HANDLE *lphObjects, | 
|---|
| 355 | BOOL fWaitAll, DWORD dwTimeout, | 
|---|
| 356 | BOOL fAlertable) | 
|---|
| 357 | { | 
|---|
| 358 | return(HMWaitForMultipleObjectsEx(cObjects, | 
|---|
| 359 | (PHANDLE)lphObjects, | 
|---|
| 360 | fWaitAll, | 
|---|
| 361 | dwTimeout, | 
|---|
| 362 | fAlertable)); | 
|---|
| 363 | } | 
|---|
| 364 |  | 
|---|
| 365 |  | 
|---|
| 366 | /***************************************************************************** | 
|---|
| 367 | * Name      : HANDLE ConvertToGlobalHandle | 
|---|
| 368 | * Purpose   : forward call to Open32 | 
|---|
| 369 | * Parameters: | 
|---|
| 370 | * Variables : | 
|---|
| 371 | * Result    : | 
|---|
| 372 | * Remark    : handle translation is done in ConvertToGlobalHandle | 
|---|
| 373 | * Status    : | 
|---|
| 374 | * | 
|---|
| 375 | * Author    : Patrick Haller [Fri, 1999/06/18 03:44] | 
|---|
| 376 | *****************************************************************************/ | 
|---|
| 377 |  | 
|---|
| 378 | HANDLE WIN32API ConvertToGlobalHandle(HANDLE hHandle) | 
|---|
| 379 |  | 
|---|
| 380 | //ODINFUNCTION2(HANDLE ConvertToGlobalHandle, | 
|---|
| 381 | //              HANDLE hHandle, | 
|---|
| 382 | //              BOOL   fInherit) | 
|---|
| 383 | { | 
|---|
| 384 | return (hHandle); | 
|---|
| 385 | } | 
|---|
| 386 |  | 
|---|
| 387 | //****************************************************************************** | 
|---|
| 388 | //****************************************************************************** | 
|---|