[9748] | 1 | /* $Id: kobjects.cpp,v 1.16 2003-02-04 11:29:01 sandervl Exp $ */
|
---|
[114] | 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 | *****************************************************************************/
|
---|
[1460] | 16 |
|
---|
| 17 | #include <odin.h>
|
---|
| 18 | #include <odinwrap.h>
|
---|
| 19 | #include <os2sel.h>
|
---|
| 20 |
|
---|
[114] | 21 | #include <os2win.h>
|
---|
[5481] | 22 | #include <misc.h>
|
---|
| 23 | #include <unicode.h>
|
---|
| 24 | #include <handlemanager.h>
|
---|
[114] | 25 |
|
---|
[2802] | 26 | #define DBG_LOCALLOG DBG_kobjects
|
---|
| 27 | #include "dbglocal.h"
|
---|
[114] | 28 |
|
---|
[2802] | 29 |
|
---|
[1460] | 30 | ODINDEBUGCHANNEL(KERNEL32-KOBJECTS)
|
---|
[114] | 31 |
|
---|
[1460] | 32 |
|
---|
[114] | 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 | /*****************************************************************************
|
---|
[1460] | 47 | * Name : BOOL CreateMutexW
|
---|
[114] | 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 |
|
---|
[7854] | 58 | HANDLE WIN32API CreateMutexW(LPSECURITY_ATTRIBUTES arg1, BOOL arg2,
|
---|
| 59 | LPCWSTR arg3)
|
---|
[114] | 60 | {
|
---|
| 61 | HANDLE rc;
|
---|
| 62 | char *astring;
|
---|
| 63 |
|
---|
[1602] | 64 | if (arg3 != NULL) // support for unnamed mutexes
|
---|
| 65 | astring = UnicodeToAsciiString((LPWSTR)arg3);
|
---|
| 66 | else
|
---|
| 67 | astring = NULL;
|
---|
[114] | 68 |
|
---|
[21302] | 69 | rc = CreateMutexA(arg1,
|
---|
[114] | 70 | arg2,
|
---|
| 71 | astring);
|
---|
| 72 |
|
---|
[1602] | 73 | if (astring != NULL)
|
---|
| 74 | FreeAsciiString(astring);
|
---|
| 75 |
|
---|
[114] | 76 | return(rc);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | /*****************************************************************************
|
---|
[1460] | 81 | * Name : BOOL WaitForSingleObject
|
---|
[114] | 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 |
|
---|
[7854] | 92 | DWORD WIN32API WaitForSingleObject(HANDLE hObject, DWORD timeout)
|
---|
[114] | 93 | {
|
---|
| 94 | return(HMWaitForSingleObject(hObject,
|
---|
| 95 | timeout));
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | /*****************************************************************************
|
---|
[5332] | 100 | * Name : DWORD WaitForSingleObjectEx
|
---|
[114] | 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 |
|
---|
[7854] | 118 | DWORD WIN32API WaitForSingleObjectEx(HANDLE hObject, DWORD dwTimeout, BOOL fAlertable)
|
---|
[114] | 119 | {
|
---|
| 120 | dprintf(("Kernel32: WaitForSingleObjectEx(%08xh,%08xh,%08xh) not implemented correctly.\n",
|
---|
| 121 | hObject,
|
---|
| 122 | dwTimeout,
|
---|
| 123 | fAlertable));
|
---|
| 124 |
|
---|
[278] | 125 | return(HMWaitForSingleObjectEx(hObject,
|
---|
| 126 | dwTimeout,
|
---|
| 127 | fAlertable));
|
---|
[114] | 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 | /*****************************************************************************
|
---|
[1460] | 133 | * Name : UINT SetHandleCount
|
---|
[114] | 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 |
|
---|
[7854] | 144 | UINT WIN32API SetHandleCount(UINT cHandles)
|
---|
[114] | 145 | {
|
---|
[3259] | 146 | //SvL: Has no effect in NT; also ignore it
|
---|
| 147 | return cHandles;
|
---|
[114] | 148 | }
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 | /*****************************************************************************
|
---|
[1460] | 152 | * Name : BOOL DuplicateHandle
|
---|
[114] | 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 |
|
---|
[7854] | 163 | BOOL WIN32API DuplicateHandle(HANDLE srcprocess, HANDLE srchandle,
|
---|
| 164 | HANDLE destprocess, PHANDLE desthandle,
|
---|
| 165 | DWORD arg5, BOOL arg6, DWORD arg7)
|
---|
[114] | 166 | {
|
---|
| 167 | BOOL rc;
|
---|
| 168 |
|
---|
| 169 | rc = HMDuplicateHandle(srcprocess,
|
---|
| 170 | srchandle,
|
---|
| 171 | destprocess,
|
---|
| 172 | desthandle,
|
---|
| 173 | arg5,
|
---|
| 174 | arg6,
|
---|
| 175 | arg7);
|
---|
[765] | 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 |
|
---|
[114] | 186 | return(rc);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | /*****************************************************************************
|
---|
[1460] | 192 | * Name : BOOL CreateSemaphoreW
|
---|
[114] | 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 |
|
---|
[7854] | 203 | HANDLE WIN32API CreateSemaphoreW(LPSECURITY_ATTRIBUTES arg1, LONG arg2,
|
---|
| 204 | LONG arg3, LPCWSTR arg4)
|
---|
[114] | 205 | {
|
---|
| 206 | HANDLE rc;
|
---|
| 207 | char *astring;
|
---|
| 208 |
|
---|
[1602] | 209 | if (arg4 != NULL) // support for unnamed semaphores
|
---|
| 210 | astring = UnicodeToAsciiString((LPWSTR)arg4);
|
---|
| 211 | else
|
---|
| 212 | astring = NULL;
|
---|
[114] | 213 |
|
---|
[21302] | 214 | rc = CreateSemaphoreA(arg1,
|
---|
[114] | 215 | arg2,
|
---|
| 216 | arg3,
|
---|
| 217 | astring);
|
---|
[1602] | 218 |
|
---|
| 219 | if (astring != NULL)
|
---|
| 220 | FreeAsciiString(astring);
|
---|
[114] | 221 | return(rc);
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 |
|
---|
| 225 | /*****************************************************************************
|
---|
[1602] | 226 | * Name : BOOL
|
---|
[114] | 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 |
|
---|
[7854] | 237 | HANDLE WIN32API OpenEventW(DWORD dwDesiredAccess, BOOL bInheritHandle,
|
---|
| 238 | LPCWSTR lpName)
|
---|
[114] | 239 | {
|
---|
| 240 | char *asciiname;
|
---|
| 241 | HANDLE rc;
|
---|
| 242 |
|
---|
[1460] | 243 | asciiname = UnicodeToAsciiString((LPWSTR)lpName);
|
---|
[114] | 244 |
|
---|
[21302] | 245 | rc = OpenEventA(dwDesiredAccess,
|
---|
[114] | 246 | bInheritHandle,
|
---|
| 247 | asciiname);
|
---|
| 248 | FreeAsciiString(asciiname);
|
---|
| 249 | return(rc);
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 |
|
---|
| 253 | /*****************************************************************************
|
---|
[1460] | 254 | * Name : BOOL OpenMutexW
|
---|
[114] | 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 |
|
---|
[7854] | 265 | HANDLE WIN32API OpenMutexW(DWORD dwDesiredAccess, BOOL bInheritHandle,
|
---|
| 266 | LPCWSTR lpName)
|
---|
[114] | 267 | {
|
---|
| 268 | char *asciiname;
|
---|
| 269 | HANDLE rc;
|
---|
| 270 |
|
---|
[1460] | 271 | asciiname = UnicodeToAsciiString((LPWSTR)lpName);
|
---|
[114] | 272 |
|
---|
[21302] | 273 | rc = OpenMutexA(dwDesiredAccess,
|
---|
[114] | 274 | bInheritHandle,
|
---|
| 275 | asciiname);
|
---|
| 276 | FreeAsciiString(asciiname);
|
---|
| 277 | return(rc);
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 |
|
---|
| 281 | /*****************************************************************************
|
---|
[1460] | 282 | * Name : BOOL OpenSemaphoreW
|
---|
[114] | 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 |
|
---|
[7854] | 293 | HANDLE WIN32API OpenSemaphoreW(DWORD dwDesiredAccess, BOOL bInheritHandle,
|
---|
| 294 | LPCWSTR lpName)
|
---|
[114] | 295 | {
|
---|
| 296 | char *asciiname;
|
---|
| 297 | HANDLE rc;
|
---|
| 298 |
|
---|
[1460] | 299 | asciiname = UnicodeToAsciiString((LPWSTR)lpName);
|
---|
[114] | 300 |
|
---|
[21302] | 301 | rc = OpenSemaphoreA(dwDesiredAccess,
|
---|
[114] | 302 | bInheritHandle,
|
---|
| 303 | asciiname);
|
---|
| 304 | FreeAsciiString(asciiname);
|
---|
| 305 | return(rc);
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 |
|
---|
| 309 |
|
---|
| 310 | /*****************************************************************************
|
---|
[1460] | 311 | * Name : BOOL WaitForMultipleObjects
|
---|
[114] | 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 |
|
---|
[7854] | 322 | DWORD WIN32API WaitForMultipleObjects(DWORD arg1, const HANDLE * arg2,
|
---|
| 323 | BOOL arg3, DWORD arg4)
|
---|
[114] | 324 | {
|
---|
| 325 | return HMWaitForMultipleObjects(arg1,
|
---|
[278] | 326 | (PHANDLE)arg2,
|
---|
[114] | 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 |
|
---|
[7854] | 354 | DWORD WIN32API WaitForMultipleObjectsEx(DWORD cObjects, CONST HANDLE *lphObjects,
|
---|
| 355 | BOOL fWaitAll, DWORD dwTimeout,
|
---|
| 356 | BOOL fAlertable)
|
---|
[114] | 357 | {
|
---|
[278] | 358 | return(HMWaitForMultipleObjectsEx(cObjects,
|
---|
| 359 | (PHANDLE)lphObjects,
|
---|
| 360 | fWaitAll,
|
---|
| 361 | dwTimeout,
|
---|
| 362 | fAlertable));
|
---|
[114] | 363 | }
|
---|
| 364 |
|
---|
| 365 |
|
---|
| 366 | /*****************************************************************************
|
---|
[1460] | 367 | * Name : HANDLE ConvertToGlobalHandle
|
---|
[114] | 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 |
|
---|
[7854] | 378 | HANDLE WIN32API ConvertToGlobalHandle(HANDLE hHandle)
|
---|
[1460] | 379 |
|
---|
[7854] | 380 | //ODINFUNCTION2(HANDLE ConvertToGlobalHandle,
|
---|
| 381 | // HANDLE hHandle,
|
---|
| 382 | // BOOL fInherit)
|
---|
[114] | 383 | {
|
---|
| 384 | return (hHandle);
|
---|
| 385 | }
|
---|
| 386 |
|
---|
[3128] | 387 | //******************************************************************************
|
---|
| 388 | //******************************************************************************
|
---|