Changeset 21302 for trunk/src/kernel32/HandleManager.cpp
- Timestamp:
- Jun 18, 2009, 11:53:26 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r10132 r21302 45 45 #include <string.h> 46 46 47 #include "unicode.h"48 #include "misc.h"49 50 #include "HandleManager.H"47 #include <unicode.h> 48 #include <dbglog.h> 49 50 #include <HandleManager.H> 51 51 #include "handlenames.h" 52 52 #include "HMDevice.h" … … 67 67 #include "HMMailslot.h" 68 68 69 #include "hmhandle.h" 70 69 71 #include <vmutex.h> 70 72 #include <win\thread.h> 71 73 74 #include <odinapi.h> 75 76 #include <_ras.h> 77 72 78 #define DBG_LOCALLOG DBG_handlemanager 73 79 #include "dbglocal.h" … … 77 83 *****************************************************************************/ 78 84 79 /* this is the size of our currently static handle table */ 80 #define MAX_OS2_HMHANDLES 409685 // this is the size of our currently static handle table 86 #define MAX_OS2_HMHANDLES (4*1024) 81 87 82 88 … … 84 90 * Structures * 85 91 *****************************************************************************/ 86 87 typedef struct _HMHANDLE88 {89 HMDeviceHandler *pDeviceHandler; /* handler for this pseudo-device */90 HMHANDLEDATA hmHandleData; /* attributes of the handle */91 } HMHANDLE, *PHMHANDLE;92 92 93 93 … … 120 120 /* the device name is repeated here to enable device alias names */ 121 121 static PHMDEVICE TabWin32Devices = NULL; 122 122 static int lastIndex = 1; 123 123 static HMHANDLE *TabWin32Handles = NULL; /* static handle table */ 124 124 VMutex handleMutex; … … 154 154 155 155 156 #ifdef RAS 157 158 RAS_TRACK_HANDLE rthHandles = 0; 159 160 ULONG WIN32API LogObjectContent_Handle (ULONG objident, ULONG objhandle, void *objdata, ULONG cbobjdata, FNRASLOG_EXTERNAL *pRasLog) 161 { 162 pRasLog (" %8.8x: data=%p, type=%x, internal type=%x", objhandle, TabWin32Handles[objhandle].hmHandleData.hHMHandle, GetFileType(objhandle), TabWin32Handles[objhandle].hmHandleData.dwInternalType); 163 return 0; 164 } 165 166 #endif 167 168 #define FREEHANDLE(a) do { \ 169 TabWin32Handles[a].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; \ 170 RasRemoveObject(rthHandles, a); \ 171 } while (0) 172 156 173 /***************************************************************************** 157 174 * Local Prototypes * … … 254 271 handleMutex.enter(); 255 272 256 for (ulLoop = 1; // @@@PH Note, this is an experimental change 257 // 0L as hHandle is sometimes considered invalid! 258 // this will never return 0l as free handle now. 259 ulLoop < MAX_OS2_HMHANDLES; 260 ulLoop++) 273 //find next free handle; do not reuse handles until we have no choice 274 if(lastIndex >= MAX_OS2_HMHANDLES) { 275 lastIndex = 1; 276 } 277 278 for (ulLoop = lastIndex;ulLoop < MAX_OS2_HMHANDLES; ulLoop++) 261 279 { 262 280 /* free handle found ? */ 263 if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) { 264 //SvL: Mark handle as allocated here. Doing it outside of this function 265 // isn't thread safe. (and not very smart) 281 if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) 282 { 283 //Mark handle as allocated here. 284 memset(&TabWin32Handles[ulLoop].hmHandleData, 0, sizeof(TabWin32Handles[ulLoop].hmHandleData)); 266 285 TabWin32Handles[ulLoop].hmHandleData.hHMHandle = ulLoop; 267 TabWin32Handles[ulLoop].hmHandleData.dwUserData = 0;268 286 TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN; 269 287 TabWin32Handles[ulLoop].hmHandleData.hWin32Handle = (HANDLE)ulLoop; 270 TabWin32Handles[ulLoop].hmHandleData.lpDeviceData = NULL; 271 TabWin32Handles[ulLoop].hmHandleData.dwHandleInformation = 0; 288 lastIndex = ulLoop+1; 272 289 handleMutex.leave(); 290 RasAddObject (rthHandles, ulLoop, NULL, 0); 273 291 return (ulLoop); /* OK, then return it to the caller */ 274 292 } … … 276 294 277 295 handleMutex.leave(); 296 dprintf(("KERNEL32:HandleManager:_HMHandleGetFree() no free handle (%d already allocated)\n", ulLoop)); 297 #ifdef RAS 298 RasLog ("KERNEL32:HandleManager:_HMHandleGetFree() no free handle"); 299 RasLogObjects (rthHandles, RAS_FLAG_LOG_OBJECTS); 300 #endif 278 301 return (INVALID_HANDLE_VALUE); /* haven't found any free handle */ 279 302 } 280 303 304 /***************************************************************************** 305 * Name : static int _HMHandleGetFree 306 * Purpose : get pointer to first free handle in the handle table 307 * Parameters: 308 * Variables : 309 * Result : pointer to the table or NULL in case of error 310 * Remark : 311 * Status : 312 * 313 * Author : SvL 314 *****************************************************************************/ 315 PHMHANDLE HMHandleGetFreePtr(ULONG dwType) 316 { 317 ULONG handle; 318 PHMHANDLE pHandle; 319 320 handle = _HMHandleGetFree(); 321 if(handle == INVALID_HANDLE_VALUE) { 322 return NULL; 323 } 324 pHandle = &TabWin32Handles[handle]; 325 switch(dwType) { 326 case HMTYPE_MEMMAP: 327 pHandle->pDeviceHandler = HMGlobals.pHMFileMapping; 328 break; 329 case HMTYPE_DEVICE: 330 pHandle->pDeviceHandler = HMGlobals.pHMFile; 331 break; 332 case HMTYPE_PROCESSTOKEN: 333 case HMTYPE_THREADTOKEN: 334 pHandle->pDeviceHandler = HMGlobals.pHMToken; 335 break; 336 case HMTYPE_THREAD: 337 pHandle->pDeviceHandler = HMGlobals.pHMThread; 338 break; 339 case HMTYPE_PIPE: 340 pHandle->pDeviceHandler = HMGlobals.pHMNamedPipe; 341 break; 342 case HMTYPE_EVENTSEM: 343 pHandle->pDeviceHandler = HMGlobals.pHMEvent; 344 break; 345 case HMTYPE_MUTEXSEM: 346 pHandle->pDeviceHandler = HMGlobals.pHMMutex; 347 break; 348 case HMTYPE_SEMAPHORE: 349 pHandle->pDeviceHandler = HMGlobals.pHMSemaphore; 350 break; 351 case HMTYPE_COMPORT: 352 pHandle->pDeviceHandler = HMGlobals.pHMComm; 353 break; 354 case HMTYPE_PARPORT: 355 pHandle->pDeviceHandler = HMGlobals.pHMParPort; 356 break; 357 case HMTYPE_MAILSLOT: 358 pHandle->pDeviceHandler = HMGlobals.pHMMailslot; 359 break; 360 361 case HMTYPE_UNKNOWN: 362 default: 363 DebugInt3(); 364 HMHandleFree(handle); 365 return NULL; 366 } 367 368 pHandle->hmHandleData.dwInternalType = dwType; 369 return pHandle; 370 } 281 371 282 372 /***************************************************************************** … … 293 383 DWORD HMHandleGetUserData(ULONG hHandle) 294 384 { 295 if (hHandle > MAX_OS2_HMHANDLES) /* check the table range */ 296 return (-1); 385 if (hHandle >= MAX_OS2_HMHANDLES) /* check the table range */ 386 { 387 /* Standard handle? */ 388 switch (hHandle) 389 { 390 case STD_INPUT_HANDLE: hHandle = HMGlobals.hStandardIn; break; 391 case STD_OUTPUT_HANDLE: hHandle = HMGlobals.hStandardOut; break; 392 case STD_ERROR_HANDLE: hHandle = HMGlobals.hStandardError; break; 393 default: 394 return(-1); 395 } 396 if (hHandle >= MAX_OS2_HMHANDLES) 397 return(-1); 398 } 297 399 /* Oops, invalid handle ! */ 298 400 if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle) 299 return(-1); /* nope, ERROR_INVALID_HANDLE */401 return(-1); /* nope, ERROR_INVALID_HANDLE */ 300 402 301 403 return TabWin32Handles[hHandle].hmHandleData.dwUserData; … … 315 417 DWORD HMHandleSetUserData(ULONG hHandle, ULONG dwUserData) 316 418 { 317 if (hHandle > MAX_OS2_HMHANDLES) /* check the table range */ 318 return (-1); 419 if (hHandle >= MAX_OS2_HMHANDLES) /* check the table range */ 420 { 421 /* Standard handle? */ 422 switch (hHandle) 423 { 424 case STD_INPUT_HANDLE: hHandle = HMGlobals.hStandardIn; break; 425 case STD_OUTPUT_HANDLE: hHandle = HMGlobals.hStandardOut; break; 426 case STD_ERROR_HANDLE: hHandle = HMGlobals.hStandardError; break; 427 default: 428 return(-1); 429 } 430 if (hHandle >= MAX_OS2_HMHANDLES) 431 return(-1); 432 } 433 319 434 /* Oops, invalid handle ! */ 320 435 if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle) 321 return(-1); /* nope, ERROR_INVALID_HANDLE */436 return(-1); /* nope, ERROR_INVALID_HANDLE */ 322 437 323 438 TabWin32Handles[hHandle].hmHandleData.dwUserData = dwUserData; … … 341 456 static ULONG INLINE _HMHandleQuery(HANDLE hHandle) 342 457 { 343 if (hHandle > MAX_OS2_HMHANDLES) /* check the table range */ 344 return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */ 458 if (hHandle >= MAX_OS2_HMHANDLES) /* check the table range */ 459 { 460 /* Standard handle? */ 461 switch (hHandle) 462 { 463 case STD_INPUT_HANDLE: hHandle = HMGlobals.hStandardIn; break; 464 case STD_OUTPUT_HANDLE: hHandle = HMGlobals.hStandardOut; break; 465 case STD_ERROR_HANDLE: hHandle = HMGlobals.hStandardError; break; 466 default: 467 return(INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */ 468 } 469 if (hHandle >= MAX_OS2_HMHANDLES) /* check the table range */ 470 return(INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */ 471 } 345 472 346 473 /* Oops, invalid handle ! */ 347 474 if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle) 348 return (INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */ 349 350 return ( hHandle); /* OK, we've got our handle index */ 475 return(INVALID_HANDLE_VALUE); /* nope, ERROR_INVALID_HANDLE */ 476 477 return( hHandle); /* OK, we've got our handle index */ 478 } 479 480 /***************************************************************************** 481 * Name : HMHandleQueryPtr 482 * Purpose : gets the pointer of handle table entry as fast as possible from 483 * the specified handle 484 * Parameters: HANDLE hHandle 485 * Variables : 486 * Result : pointer or NULL in case of error 487 * Remark : 488 * Status : 489 * 490 * Author : SvL 491 *****************************************************************************/ 492 493 PHMHANDLE HMHandleQueryPtr(HANDLE hHandle) 494 { 495 if (hHandle >= MAX_OS2_HMHANDLES) 496 { 497 /* Standard handle? */ 498 switch (hHandle) 499 { 500 case STD_INPUT_HANDLE: hHandle = HMGlobals.hStandardIn; break; 501 case STD_OUTPUT_HANDLE: hHandle = HMGlobals.hStandardOut; break; 502 case STD_ERROR_HANDLE: hHandle = HMGlobals.hStandardError; break; 503 default: 504 SetLastError(ERROR_INVALID_HANDLE); 505 return(NULL); 506 } 507 if (hHandle >= MAX_OS2_HMHANDLES) 508 { 509 SetLastError(ERROR_INVALID_HANDLE); 510 return(NULL); 511 } 512 } 513 if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle) 514 { 515 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 516 return(NULL); /* nope, ERROR_INVALID_HANDLE */ 517 } 518 return( &TabWin32Handles[hHandle]); /* OK, we've got our handle index */ 351 519 } 352 520 … … 421 589 if (HMGlobals.fIsInitialized != TRUE) 422 590 { 591 592 #ifdef RAS 593 RasRegisterObjectTracking(&rthHandles, "KERNEL32 handles", 594 0, RAS_TRACK_FLAG_LOGOBJECTCONTENT, 595 LogObjectContent_Handle, NULL); 596 #endif 597 423 598 handleMutex.enter(); 424 599 425 TabWin32Handles = (HMHANDLE *) malloc(MAX_OS2_HMHANDLES*sizeof(HMHANDLE));600 TabWin32Handles = (HMHANDLE *)VirtualAlloc(NULL, MAX_OS2_HMHANDLES*sizeof(HMHANDLE), MEM_COMMIT, PAGE_READWRITE); 426 601 if(TabWin32Handles == NULL) { 427 602 DebugInt3(); 428 603 return ERROR_NOT_ENOUGH_MEMORY; 429 604 } 430 memset(TabWin32Handles, 0, MAX_OS2_HMHANDLES*sizeof(HMHANDLE));431 605 432 606 // fill handle table … … 523 697 { 524 698 /* @@@PH we could deallocate the device list here */ 699 #ifdef DEBUG 700 dprintf(("List of leaked handles")); 701 for(int i = 0; i < MAX_OS2_HMHANDLES; i++) 702 { 703 /* check if handle is free */ 704 if (TabWin32Handles[i].hmHandleData.hHMHandle != INVALID_HANDLE_VALUE) 705 { 706 dprintf(("Handle %x(%p) type %x internal type %x", i, TabWin32Handles[i].hmHandleData.hHMHandle, GetFileType(i), TabWin32Handles[i].hmHandleData.dwInternalType)); 707 } 708 } 709 #endif 710 RasLogObjects (rthHandles, RAS_FLAG_LOG_OBJECTS); 525 711 526 712 if(HMGlobals.pHMOpen32) … … 617 803 618 804 handleMutex.leave(); 805 RasAddObject (rthHandles, ulHandle, NULL, 0); 619 806 return (NO_ERROR); /* OK */ 620 807 } … … 629 816 handleMutex.leave(); 630 817 818 #ifdef DEBUG 819 dprintf(("ERROR: Out of handles!!!!")); 820 for (int i = 0; i < MAX_OS2_HMHANDLES; i++) 821 { 822 /* check if handle is free */ 823 if (TabWin32Handles[i].hmHandleData.hHMHandle != INVALID_HANDLE_VALUE) 824 { 825 dprintf(("Handle %d type %d internal type %d", i, GetFileType(i), TabWin32Handles[i].hmHandleData.dwInternalType)); 826 } 827 } 828 #endif 829 #ifdef RAS 830 RasLog ("KERNEL32:HandleManager:HMHandleAllocate() no free handle"); 831 RasLogObjects (rthHandles, RAS_FLAG_LOG_OBJECTS); 832 #endif 631 833 return (ERROR_TOO_MANY_OPEN_FILES); /* OK, we're done */ 632 834 } … … 659 861 return (rc); /* raise error condition */ 660 862 661 TabWin32Handles[hHandle16].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 863 FREEHANDLE(hHandle16); 864 // TabWin32Handles[hHandle16].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 865 // RasRemoveObjects(rthHandles, hHandle16); 662 866 /* OK, done */ 663 867 … … 669 873 * Name : DWORD HMHandleValidate 670 874 * Purpose : validate a handle through the translation table 671 * Parameters: ULONG hHandle 16- the handle to be verified875 * Parameters: ULONG hHandle - the handle to be verified 672 876 * Variables : 673 877 * Result : API returncode … … 678 882 *****************************************************************************/ 679 883 680 DWORD HMHandleValidate (ULONG hHandle 16)884 DWORD HMHandleValidate (ULONG hHandle) 681 885 { 682 886 #ifdef DEBUG_LOCAL 683 dprintf(("KERNEL32: HMHandleValidate (%08xh)\n", 684 hHandle16)); 887 dprintf(("KERNEL32: HMHandleValidate (%08xh)\n", hHandle)); 685 888 #endif 686 889 687 if (hHandle16 >= MAX_OS2_HMHANDLES) /* check boundary */ 688 return (ERROR_INVALID_HANDLE); /* raise error condition */ 689 690 if (TabWin32Handles[hHandle16].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE) 890 if (hHandle >= MAX_OS2_HMHANDLES) /* check boundary */ 891 { 892 /* Standard handle? */ 893 switch (hHandle) 894 { 895 case STD_INPUT_HANDLE: hHandle = HMGlobals.hStandardIn; break; 896 case STD_OUTPUT_HANDLE: hHandle = HMGlobals.hStandardOut; break; 897 case STD_ERROR_HANDLE: hHandle = HMGlobals.hStandardError; break; 898 default: 899 return(ERROR_INVALID_HANDLE); 900 } 901 if (hHandle >= MAX_OS2_HMHANDLES) 902 return(ERROR_INVALID_HANDLE); 903 } 904 905 if (TabWin32Handles[hHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE) 691 906 /* valid ? */ 692 return(ERROR_INVALID_HANDLE); /* raise error condition */693 694 return(NO_ERROR);907 return(ERROR_INVALID_HANDLE); /* raise error condition */ 908 909 return(NO_ERROR); 695 910 } 696 911 //***************************************************************************** … … 966 1181 pHMHandleData->dwFlags = TabWin32Handles[srchandle].hmHandleData.dwFlags; 967 1182 pHMHandleData->lpHandlerData = TabWin32Handles[srchandle].hmHandleData.lpHandlerData; 1183 pHMHandleData->dwInternalType = TabWin32Handles[srchandle].hmHandleData.dwInternalType; 968 1184 969 1185 … … 980 1196 &TabWin32Handles[srchandle].hmHandleData, 981 1197 destprocess, 982 desthandle,983 1198 fdwAccess, 984 1199 fInherit, … … 991 1206 if(rc == FALSE) /* oops, creation failed within the device handler */ 992 1207 { 993 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1208 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1209 FREEHANDLE(iIndexNew); 994 1210 return FALSE; /* signal error */ 995 1211 } … … 1073 1289 1074 1290 if(pDeviceHandler == HMGlobals.pHMOpen32) { 1075 if(dwDesiredAccess == 0) { 1291 /* PF When create flag is set we do not care about zero in desired access 1292 verified in Win2k */ 1293 if(dwDesiredAccess == 0 && dwCreationDisposition != CREATE_NEW) { 1294 dprintf(("File information access!")); 1076 1295 pDeviceHandler = HMGlobals.pHMInfoFile; 1077 1296 } … … 1096 1315 else 1097 1316 { 1317 memset(&HMHandleTemp, 0, sizeof(HMHandleTemp)); 1098 1318 HMHandleTemp.dwAccess = dwDesiredAccess; 1099 1319 HMHandleTemp.dwShare = dwShareMode; 1100 1320 HMHandleTemp.dwCreation = dwCreationDisposition; 1101 1321 HMHandleTemp.dwFlags = dwFlagsAndAttributes; 1102 HMHandleTemp.lpHandlerData = NULL;1103 1322 HMHandleTemp.hWin32Handle = iIndexNew; 1104 1323 HMHandleTemp.lpDeviceData = pDevData; 1105 HMHandleTemp.dwHandleInformation = 0;1106 1324 } 1107 1325 … … 1130 1348 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 1131 1349 { 1132 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1350 FREEHANDLE(iIndexNew); 1351 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1133 1352 1134 1353 // Note: … … 1196 1415 } 1197 1416 1198 HANDLE HMOpenFile(LPCSTR lpFileName, 1199 OFSTRUCT* pOFStruct, 1417 HFILE WIN32API OpenFile(LPCSTR lpFileName, OFSTRUCT* pOFStruct, 1200 1418 UINT fuMode) 1201 1419 { … … 1207 1425 DWORD rc; /* API return code */ 1208 1426 1427 1428 dprintf(("KERNEL32: OpenFile(%s, %08xh, %08xh)\n", 1429 lpFileName, pOFStruct, fuMode)); 1430 1209 1431 // name resolving 1210 1432 CHAR szFilename[260]; … … 1286 1508 */ 1287 1509 if (fuMode & OF_PARSE) { 1288 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1510 FREEHANDLE(iIndexNew); 1511 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1289 1512 return 0; 1290 1513 } … … 1292 1515 if(rc != NO_ERROR) /* oops, creation failed within the device handler */ 1293 1516 { 1294 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1517 FREEHANDLE(iIndexNew); 1518 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1295 1519 SetLastError(pOFStruct->nErrCode); 1296 1520 return (INVALID_HANDLE_VALUE); /* signal error */ … … 1299 1523 if(fuMode & (OF_DELETE|OF_EXIST)) { 1300 1524 //file handle already closed 1301 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1525 FREEHANDLE(iIndexNew); 1526 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1302 1527 return TRUE; //TODO: correct? 1303 1528 } 1304 1529 1305 1530 if(fuMode & OF_VERIFY) { 1306 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1531 FREEHANDLE(iIndexNew); 1532 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1307 1533 return 1; //TODO: correct? 1308 1534 } … … 1493 1719 1494 1720 if(pHMHandle->hmHandleData.dwHandleInformation & HANDLE_FLAG_PROTECT_FROM_CLOSE) { 1495 dprintf(("Handle not close because of HANDLE_FLAG_PROTECT_FROM_CLOSE"));1721 dprintf(("Handle not closed because of HANDLE_FLAG_PROTECT_FROM_CLOSE")); 1496 1722 SetLastError(ERROR_SUCCESS); 1497 1723 return TRUE; … … 1511 1737 if (fResult == TRUE) /* remove handle if close succeeded */ 1512 1738 { 1513 pHMHandle->hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; /* mark handle as free */ 1739 FREEHANDLE(iIndex); 1740 // pHMHandle->hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; /* mark handle as free */ 1514 1741 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 1515 1742 } … … 1591 1818 } 1592 1819 1820 /* watcom hack: 1821 * watcom may write -1 bytes to a device during flushall(), we should return 1822 * ERROR_NOT_ENOUGH_MEMORY or ERROR_NO_ACCESS 1823 */ 1824 if (nNumberOfBytesToWrite == 0xffffffff) 1825 { 1826 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 1827 return FALSE; 1828 } 1829 1593 1830 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1594 1831 fResult = pHMHandle->pDeviceHandler->WriteFile(&pHMHandle->hmHandleData, … … 1614 1851 *****************************************************************************/ 1615 1852 1616 DWORD HMGetFileType(HANDLE hFile)1853 DWORD WIN32API GetFileType(HANDLE hFile) 1617 1854 { 1618 1855 int iIndex; /* index into the handle table */ … … 1692 1929 *****************************************************************************/ 1693 1930 1694 BOOL HMGetFileInformationByHandle (HANDLE hFile,1931 BOOL WIN32API GetFileInformationByHandle (HANDLE hFile, 1695 1932 BY_HANDLE_FILE_INFORMATION *pHFI) 1696 1933 { … … 1727 1964 *****************************************************************************/ 1728 1965 1729 BOOL HMSetEndOfFile (HANDLE hFile)1966 BOOL WIN32API SetEndOfFile (HANDLE hFile) 1730 1967 { 1731 1968 int iIndex; /* index into the handle table */ … … 1760 1997 *****************************************************************************/ 1761 1998 1762 BOOL HMSetFileTime (HANDLE hFile,1999 BOOL WIN32API SetFileTime (HANDLE hFile, 1763 2000 const FILETIME *pFT1, 1764 2001 const FILETIME *pFT2, … … 1798 2035 *****************************************************************************/ 1799 2036 1800 BOOL HMGetFileTime (HANDLE hFile, 1801 const FILETIME *pFT1, 1802 const FILETIME *pFT2, 1803 const FILETIME *pFT3) 2037 BOOL WIN32API GetFileTime (HANDLE hFile, FILETIME *pFT1, 2038 FILETIME *pFT2, FILETIME *pFT3) 1804 2039 { 1805 2040 int iIndex; /* index into the handle table */ … … 1837 2072 *****************************************************************************/ 1838 2073 1839 DWORD HMGetFileSize (HANDLE hFile, 1840 PDWORD pSize) 2074 DWORD WIN32API GetFileSize (HANDLE hFile, PDWORD pSize) 1841 2075 { 1842 2076 int iIndex; /* index into the handle table */ … … 1872 2106 *****************************************************************************/ 1873 2107 1874 DWORD HMSetFilePointer (HANDLE hFile,2108 DWORD WIN32API SetFilePointer (HANDLE hFile, 1875 2109 LONG lDistanceToMove, 1876 2110 PLONG lpDistanceToMoveHigh, … … 1911 2145 *****************************************************************************/ 1912 2146 1913 BOOL HMLockFile (HFILEhFile,2147 BOOL WIN32API LockFile (HANDLE hFile, 1914 2148 DWORD arg2, 1915 2149 DWORD arg3, … … 1941 2175 1942 2176 /***************************************************************************** 1943 * Name : HMDeviceHandler::LockFileEx 1944 * Purpose : router function for LockFileEx 1945 * Parameters: 1946 * Variables : 1947 * Result : 1948 * Remark : 1949 * Status : 1950 * 1951 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1952 *****************************************************************************/ 1953 1954 BOOL HMLockFileEx(HANDLE hFile, 2177 * Name : BOOL LockFileEx 2178 * Purpose : The LockFileEx function locks a byte range within an open file for shared or exclusive access. 2179 * Parameters: HANDLE hFile handle of file to lock 2180 * DWORD dwFlags functional behavior modification flags 2181 * DWORD dwReserved reserved, must be set to zero 2182 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock 2183 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock 2184 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset 2185 * Variables : 2186 * Result : TRUE / FALSE 2187 * Remark : 2188 * Status : UNTESTED STUB 2189 * 2190 * Author : Patrick Haller [Mon, 1998/06/15 08:00] 2191 *****************************************************************************/ 2192 2193 BOOL WIN32API LockFileEx(HANDLE hFile, 1955 2194 DWORD dwFlags, 1956 2195 DWORD dwReserved, … … 1996 2235 *****************************************************************************/ 1997 2236 1998 BOOL HMUnlockFile (HANDLE hFile,2237 BOOL WIN32API UnlockFile (HANDLE hFile, 1999 2238 DWORD arg2, 2000 2239 DWORD arg3, … … 2026 2265 2027 2266 /***************************************************************************** 2028 * Name : HMDeviceHandler::UnlockFileEx 2029 * Purpose : router function for UnlockFileEx 2030 * Parameters: 2031 * Variables : 2032 * Result : 2033 * Remark : 2034 * Status : 2035 * 2036 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 2037 *****************************************************************************/ 2038 2039 BOOL HMUnlockFileEx(HANDLE hFile, 2267 * Name : BOOL UnlockFileEx 2268 * Purpose : The UnlockFileEx function unlocks a previously locked byte range in an open file. 2269 * Parameters: HANDLE hFile handle of file to lock 2270 * DWORD dwReserved reserved, must be set to zero 2271 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock 2272 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock 2273 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset 2274 * Variables : 2275 * Result : TRUE / FALSE 2276 * Remark : 2277 * Status : UNTESTED STUB 2278 * 2279 * Author : Patrick Haller [Mon, 1998/06/15 08:00] 2280 *****************************************************************************/ 2281 2282 BOOL WIN32API UnlockFileEx(HANDLE hFile, 2040 2283 DWORD dwReserved, 2041 2284 DWORD nNumberOfBytesToLockLow, … … 2155 2398 } 2156 2399 } 2157 2158 //If the timeout is less than 20 milliseconds (and not zero), then we are likely to2159 //return too late if the thread priority isn't time critical (time slices2160 //of 32 ms)2161 //To avoid this problem, we temporarily switch to time critical priority.2162 HANDLE hThread = GetCurrentThread();2163 BOOL fChangePriority = FALSE;2164 DWORD dwThreadPriority;2165 2166 if(dwTimeout && dwTimeout < 20) {2167 dwThreadPriority = GetThreadPriority(hThread);2168 if(dwThreadPriority != THREAD_PRIORITY_TIME_CRITICAL)2169 {2170 dprintf(("Temporarily change priority to THREAD_PRIORITY_TIME_CRITICAL for better timing"));2171 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);2172 //round to 8 ms units to get more precise timeouts2173 if(dwTimeout > 8)2174 dwTimeout = (dwTimeout/8)*8;2175 fChangePriority = TRUE;2176 }2177 }2178 2179 2400 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 2180 2401 dwResult = pHMHandle->pDeviceHandler->WaitForSingleObject(&pHMHandle->hmHandleData, 2181 2402 dwTimeout); 2182 2403 2183 //Restore thread priority if we previously changed it2184 if(fChangePriority) {2185 SetThreadPriority(hThread, dwThreadPriority);2186 }2187 2404 return (dwResult); /* deliver return code */ 2188 2405 } … … 2238 2455 *****************************************************************************/ 2239 2456 2240 BOOL HMFlushFileBuffers(HANDLE hFile)2457 BOOL WIN32API FlushFileBuffers(HANDLE hFile) 2241 2458 { 2242 2459 int iIndex; /* index into the handle table */ … … 2310 2527 *****************************************************************************/ 2311 2528 2312 BOOL HMReleaseMutex(HANDLE hObject)2529 BOOL WIN32API ReleaseMutex(HANDLE hObject) 2313 2530 { 2314 2531 int iIndex; /* index into the handle table */ … … 2331 2548 2332 2549 2333 /***************************************************************************** 2334 * Name : HMSetEvent 2335 * Purpose : router function for SetEvent 2550 2551 2552 /***************************************************************************** 2553 * Name : HANDLE HMCreateMutex 2554 * Purpose : Wrapper for the CreateMutex() API 2336 2555 * Parameters: 2337 2556 * Variables : … … 2340 2559 * Status : 2341 2560 * 2342 * Author : Patrick Haller [Wed, 1999/06/17 20:44]2343 *****************************************************************************/2344 2345 BOOL HMSetEvent(HANDLE hEvent)2346 {2347 int iIndex; /* index into the handle table */2348 DWORD dwResult; /* result from the device handler's API */2349 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */2350 2351 /* validate handle */2352 iIndex = _HMHandleQuery(hEvent); /* get the index */2353 if (-1 == iIndex) /* error ? */2354 {2355 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */2356 return FALSE; /* signal failure */2357 }2358 2359 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */2360 dwResult = pHMHandle->pDeviceHandler->SetEvent(&pHMHandle->hmHandleData);2361 2362 return (dwResult); /* deliver return code */2363 }2364 2365 2366 /*****************************************************************************2367 * Name : HMPulseEvent2368 * Purpose : router function for PulseEvent2369 * Parameters:2370 * Variables :2371 * Result :2372 * Remark :2373 * Status :2374 *2375 * Author : Patrick Haller [Wed, 1999/06/17 20:44]2376 *****************************************************************************/2377 2378 BOOL HMPulseEvent(HANDLE hEvent)2379 {2380 int iIndex; /* index into the handle table */2381 DWORD dwResult; /* result from the device handler's API */2382 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */2383 2384 /* validate handle */2385 iIndex = _HMHandleQuery(hEvent); /* get the index */2386 if (-1 == iIndex) /* error ? */2387 {2388 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */2389 return FALSE; /* signal failure */2390 }2391 2392 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */2393 dwResult = pHMHandle->pDeviceHandler->PulseEvent(&pHMHandle->hmHandleData);2394 2395 return (dwResult); /* deliver return code */2396 }2397 2398 2399 /*****************************************************************************2400 * Name : HMResetEvent2401 * Purpose : router function for ResetEvent2402 * Parameters:2403 * Variables :2404 * Result :2405 * Remark :2406 * Status :2407 *2408 * Author : Patrick Haller [Wed, 1999/06/17 20:44]2409 *****************************************************************************/2410 2411 BOOL HMResetEvent(HANDLE hEvent)2412 {2413 int iIndex; /* index into the handle table */2414 DWORD dwResult; /* result from the device handler's API */2415 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */2416 2417 /* validate handle */2418 iIndex = _HMHandleQuery(hEvent); /* get the index */2419 if (-1 == iIndex) /* error ? */2420 {2421 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */2422 return FALSE; /* signal failure */2423 }2424 2425 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */2426 dwResult = pHMHandle->pDeviceHandler->ResetEvent(&pHMHandle->hmHandleData);2427 2428 return (dwResult); /* deliver return code */2429 }2430 2431 2432 /*****************************************************************************2433 * Name : HANDLE HMCreateEvent2434 * Purpose : Wrapper for the CreateEvent() API2435 * Parameters:2436 * Variables :2437 * Result :2438 * Remark :2439 * Status :2440 *2441 2561 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 2442 2562 *****************************************************************************/ 2443 2563 2444 HANDLE HMCreateEvent(LPSECURITY_ATTRIBUTES lpsa, 2445 BOOL bManualReset, 2446 BOOL bInitialState, 2564 HANDLE WIN32API CreateMutexA(LPSECURITY_ATTRIBUTES lpsa, 2565 BOOL bInitialOwner, 2447 2566 LPCTSTR lpName) 2448 2567 { … … 2454 2573 2455 2574 2456 if(lpName) { //check if shared event semaphore already exists 2575 if(lpName) { //check if shared mutex semaphore already exists 2576 dprintf(("Event semaphore name %s", lpName)); 2577 2457 2578 //TODO: No inheritance?? 2458 HANDLE handle = HMOpenEvent(EVENT_ALL_ACCESS, FALSE, lpName); 2459 if(handle) { 2460 dprintf(("CreateEvent: return handle of existing event semaphore %x", handle)); 2461 SetLastError(ERROR_ALREADY_EXISTS); 2462 return handle; 2463 } 2464 } 2465 2466 pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */ 2467 2468 iIndexNew = _HMHandleGetFree(); /* get free handle */ 2469 if (-1 == iIndexNew) /* oops, no free handles ! */ 2470 { 2471 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 2472 return 0; /* signal error */ 2473 } 2474 2475 /* Initialize the complete HMHANDLEDATA structure */ 2476 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 2477 pHMHandleData->dwAccess = 0; 2478 pHMHandleData->dwShare = 0; 2479 pHMHandleData->dwCreation = 0; 2480 pHMHandleData->dwFlags = 0; 2481 pHMHandleData->lpHandlerData = NULL; 2482 2483 /* we've got to mark the handle as occupied here, since another device */ 2484 /* could be created within the device handler -> deadlock */ 2485 2486 /* write appropriate entry into the handle table if open succeeded */ 2487 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2488 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 2489 2490 /* call the device handler */ 2491 rc = pDeviceHandler->CreateEvent(&TabWin32Handles[iIndexNew].hmHandleData, 2492 lpsa, 2493 bManualReset, 2494 bInitialState, 2495 lpName); 2496 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2497 { 2498 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2499 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2500 return 0; /* signal error */ 2501 } 2502 else 2503 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 2504 2505 return iIndexNew; /* return valid handle */ 2506 } 2507 2508 2509 /***************************************************************************** 2510 * Name : HANDLE HMCreateMutex 2511 * Purpose : Wrapper for the CreateMutex() API 2512 * Parameters: 2513 * Variables : 2514 * Result : 2515 * Remark : 2516 * Status : 2517 * 2518 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 2519 *****************************************************************************/ 2520 2521 HANDLE HMCreateMutex(LPSECURITY_ATTRIBUTES lpsa, 2522 BOOL bInitialOwner, 2523 LPCTSTR lpName) 2524 { 2525 int iIndex; /* index into the handle table */ 2526 int iIndexNew; /* index into the handle table */ 2527 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 2528 PHMHANDLEDATA pHMHandleData; 2529 DWORD rc; /* API return code */ 2530 2531 2532 if(lpName) { //check if shared mutex semaphore already exists 2533 //TODO: No inheritance?? 2534 HANDLE handle = HMOpenMutex(MUTEX_ALL_ACCESS, FALSE, lpName); 2579 HANDLE handle = OpenMutexA(MUTEX_ALL_ACCESS, FALSE, lpName); 2535 2580 if(handle) { 2536 2581 dprintf(("CreateMutex: return handle of existing mutex semaphore %x", handle)); … … 2557 2602 pHMHandleData->dwFlags = 0; 2558 2603 pHMHandleData->lpHandlerData = NULL; 2559 2560 2561 /* we've got to mark the handle as occupied here, since another device */ 2562 /* could be created within the device handler -> deadlock */ 2563 2564 /* write appropriate entry into the handle table if open succeeded */ 2604 pHMHandleData->dwInternalType = HMTYPE_MUTEXSEM; 2605 2606 2607 /* we've got to mark the handle as occupied here, since another device */ 2608 /* could be created within the device handler -> deadlock */ 2609 2610 /* write appropriate entry into the handle table if open succeeded */ 2565 2611 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2566 2612 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 2567 2613 2568 2614 /* call the device handler */ 2569 2615 rc = pDeviceHandler->CreateMutex(&TabWin32Handles[iIndexNew].hmHandleData, 2570 2616 lpsa, … … 2573 2619 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2574 2620 { 2575 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2621 FREEHANDLE(iIndexNew); 2622 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2576 2623 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2577 2624 return 0; /* signal error */ … … 2584 2631 2585 2632 2586 /***************************************************************************** 2587 * Name : HANDLE HMOpenEvent 2588 * Purpose : Wrapper for the OpenEvent() API 2633 2634 /***************************************************************************** 2635 * Name : HANDLE HMOpenMutex 2636 * Purpose : Wrapper for the OpenMutex() API 2589 2637 * Parameters: 2590 2638 * Variables : … … 2596 2644 *****************************************************************************/ 2597 2645 2598 HANDLE HMOpenEvent(DWORD fdwAccess,2599 BOOL fInherit,2600 LPCTSTRlpName)2646 HANDLE WIN32API OpenMutexA(DWORD fdwAccess, 2647 BOOL fInherit, 2648 LPCTSTR lpName) 2601 2649 { 2602 2650 int iIndex; /* index into the handle table */ … … 2607 2655 2608 2656 2609 pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */ 2657 if(lpName) { 2658 dprintf(("Mutex semaphore name %s", lpName)); 2659 } 2660 2661 pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */ 2610 2662 2611 2663 iIndexNew = _HMHandleGetFree(); /* get free handle */ … … 2624 2676 pHMHandleData->dwFlags = 0; 2625 2677 pHMHandleData->lpHandlerData = NULL; 2678 pHMHandleData->dwInternalType = HMTYPE_MUTEXSEM; 2626 2679 2627 2680 … … 2634 2687 2635 2688 /* call the device handler */ 2636 rc = pDeviceHandler->Open Event(&TabWin32Handles[iIndexNew].hmHandleData,2689 rc = pDeviceHandler->OpenMutex(&TabWin32Handles[iIndexNew].hmHandleData, 2637 2690 fInherit, 2638 2691 lpName); 2639 2692 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2640 2693 { 2641 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2694 FREEHANDLE(iIndexNew); 2695 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2642 2696 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2643 2697 return 0; /* signal error */ … … 2651 2705 2652 2706 /***************************************************************************** 2653 * Name : HANDLE HM OpenMutex2654 * Purpose : Wrapper for the OpenMutex() API2707 * Name : HANDLE HMCreateSemaphore 2708 * Purpose : Wrapper for the CreateSemaphore() API 2655 2709 * Parameters: 2656 2710 * Variables : … … 2662 2716 *****************************************************************************/ 2663 2717 2664 HANDLE HMOpenMutex(DWORD fdwAccess, 2665 BOOL fInherit, 2666 LPCTSTR lpName) 2718 HANDLE WIN32API CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpsa, 2719 LONG lInitialCount, 2720 LONG lMaximumCount, 2721 LPCTSTR lpName) 2667 2722 { 2668 2723 int iIndex; /* index into the handle table */ … … 2672 2727 DWORD rc; /* API return code */ 2673 2728 2674 2675 pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */ 2729 if(lpName) { //check if shared event semaphore already exists 2730 //TODO: No inheritance?? 2731 dprintf(("Semaphore name %s", lpName)); 2732 2733 HANDLE handle = OpenSemaphoreA(SEMAPHORE_ALL_ACCESS, FALSE, lpName); 2734 if(handle) { 2735 dprintf(("CreateSemaphore: return handle of existing semaphore %x", handle)); 2736 SetLastError(ERROR_ALREADY_EXISTS); 2737 return handle; 2738 } 2739 } 2740 2741 pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */ 2742 2743 iIndexNew = _HMHandleGetFree(); /* get free handle */ 2744 if (-1 == iIndexNew) /* oops, no free handles ! */ 2745 { 2746 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 2747 return 0; /* signal error */ 2748 } 2749 2750 2751 /* initialize the complete HMHANDLEDATA structure */ 2752 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 2753 pHMHandleData->dwAccess = 0; 2754 pHMHandleData->dwShare = 0; 2755 pHMHandleData->dwCreation = 0; 2756 pHMHandleData->dwFlags = 0; 2757 pHMHandleData->lpHandlerData = NULL; 2758 pHMHandleData->dwInternalType = HMTYPE_SEMAPHORE; 2759 2760 2761 /* we've got to mark the handle as occupied here, since another device */ 2762 /* could be created within the device handler -> deadlock */ 2763 2764 /* write appropriate entry into the handle table if open succeeded */ 2765 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2766 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 2767 2768 /* call the device handler */ 2769 rc = pDeviceHandler->CreateSemaphore(&TabWin32Handles[iIndexNew].hmHandleData, 2770 lpsa, 2771 lInitialCount, 2772 lMaximumCount, 2773 lpName); 2774 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2775 { 2776 FREEHANDLE(iIndexNew); 2777 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2778 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2779 return 0; /* signal failure */ 2780 } 2781 else 2782 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 2783 2784 return iIndexNew; /* return valid handle */ 2785 } 2786 2787 2788 /***************************************************************************** 2789 * Name : HANDLE HMOpenSemaphore 2790 * Purpose : Wrapper for the OpenSemaphore() API 2791 * Parameters: 2792 * Variables : 2793 * Result : 2794 * Remark : 2795 * Status : 2796 * 2797 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 2798 *****************************************************************************/ 2799 2800 HANDLE WIN32API OpenSemaphoreA(DWORD fdwAccess, 2801 BOOL fInherit, 2802 LPCTSTR lpName) 2803 { 2804 int iIndex; /* index into the handle table */ 2805 int iIndexNew; /* index into the handle table */ 2806 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 2807 PHMHANDLEDATA pHMHandleData; 2808 DWORD rc; /* API return code */ 2809 2810 2811 if(lpName) { 2812 dprintf(("Semaphore name %s", lpName)); 2813 } 2814 2815 pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */ 2676 2816 2677 2817 iIndexNew = _HMHandleGetFree(); /* get free handle */ … … 2690 2830 pHMHandleData->dwFlags = 0; 2691 2831 pHMHandleData->lpHandlerData = NULL; 2832 pHMHandleData->dwInternalType = HMTYPE_SEMAPHORE; 2692 2833 2693 2834 … … 2700 2841 2701 2842 /* call the device handler */ 2702 rc = pDeviceHandler->Open Mutex(&TabWin32Handles[iIndexNew].hmHandleData,2703 fInherit,2704 lpName);2843 rc = pDeviceHandler->OpenSemaphore(&TabWin32Handles[iIndexNew].hmHandleData, 2844 fInherit, 2845 lpName); 2705 2846 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2706 2847 { 2707 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2848 FREEHANDLE(iIndexNew); 2849 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2708 2850 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2709 return 0; /* signal error*/2851 return 0; /* signal failure */ 2710 2852 } 2711 2853 else … … 2717 2859 2718 2860 /***************************************************************************** 2719 * Name : H ANDLE HMCreateSemaphore2720 * Purpose : Wrapper for the CreateSemaphore() API2861 * Name : HMReleaseSemaphore 2862 * Purpose : router function for ReleaseSemaphore 2721 2863 * Parameters: 2722 2864 * Variables : … … 2725 2867 * Status : 2726 2868 * 2869 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 2870 *****************************************************************************/ 2871 2872 BOOL WIN32API ReleaseSemaphore(HANDLE hEvent, 2873 LONG cReleaseCount, 2874 LPLONG lpPreviousCount) 2875 { 2876 int iIndex; /* index into the handle table */ 2877 DWORD dwResult; /* result from the device handler's API */ 2878 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 2879 2880 /* validate handle */ 2881 iIndex = _HMHandleQuery(hEvent); /* get the index */ 2882 if (-1 == iIndex) /* error ? */ 2883 { 2884 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 2885 return 0; /* signal failure */ 2886 } 2887 else 2888 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 2889 2890 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 2891 dwResult = pHMHandle->pDeviceHandler->ReleaseSemaphore(&pHMHandle->hmHandleData, 2892 cReleaseCount, 2893 lpPreviousCount); 2894 2895 return (dwResult); /* deliver return code */ 2896 } 2897 2898 2899 /***************************************************************************** 2900 * Name : HANDLE HMCreateFileMapping 2901 * Purpose : Wrapper for the CreateFileMapping() API 2902 * Parameters: 2903 * Variables : 2904 * Result : 2905 * Remark : 2906 * Status : 2907 * 2727 2908 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 2728 2909 *****************************************************************************/ 2729 2910 2730 HANDLE HMCreateSemaphore(LPSECURITY_ATTRIBUTES lpsa, 2731 LONG lInitialCount, 2732 LONG lMaximumCount, 2733 LPCTSTR lpName) 2911 HANDLE HMCreateFileMapping(HANDLE hFile, 2912 LPSECURITY_ATTRIBUTES lpFileMappingAttributes, 2913 DWORD flProtect, 2914 DWORD dwMaximumSizeHigh, 2915 DWORD dwMaximumSizeLow, 2916 LPCTSTR lpName) 2734 2917 { 2735 2918 int iIndex; /* index into the handle table */ … … 2739 2922 DWORD rc; /* API return code */ 2740 2923 2741 if(lpName) { //check if shared event semaphore already exists 2742 //TODO: No inheritance?? 2743 HANDLE handle = HMOpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, lpName); 2744 if(handle) { 2745 dprintf(("CreateSemaphore: return handle of existing semaphore %x", handle)); 2746 SetLastError(ERROR_ALREADY_EXISTS); 2747 return handle; 2748 } 2749 } 2750 2751 pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */ 2924 pDeviceHandler = HMGlobals.pHMFileMapping; /* device is predefined */ 2752 2925 2753 2926 iIndexNew = _HMHandleGetFree(); /* get free handle */ … … 2757 2930 return 0; /* signal error */ 2758 2931 } 2759 2760 2932 2761 2933 /* initialize the complete HMHANDLEDATA structure */ … … 2766 2938 pHMHandleData->dwFlags = 0; 2767 2939 pHMHandleData->lpHandlerData = NULL; 2768 2769 2770 /* we've got to mark the handle as occupied here, since another device */ 2771 /* could be created within the device handler -> deadlock */ 2772 2773 /* write appropriate entry into the handle table if open succeeded */ 2774 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2775 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 2776 2777 /* call the device handler */ 2778 rc = pDeviceHandler->CreateSemaphore(&TabWin32Handles[iIndexNew].hmHandleData, 2779 lpsa, 2780 lInitialCount, 2781 lMaximumCount, 2782 lpName); 2783 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2784 { 2785 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2786 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2787 return 0; /* signal failure */ 2788 } 2789 else 2790 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 2791 2792 return iIndexNew; /* return valid handle */ 2793 } 2794 2795 2796 /***************************************************************************** 2797 * Name : HANDLE HMOpenSemaphore 2798 * Purpose : Wrapper for the OpenSemaphore() API 2799 * Parameters: 2800 * Variables : 2801 * Result : 2802 * Remark : 2803 * Status : 2804 * 2805 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 2806 *****************************************************************************/ 2807 2808 HANDLE HMOpenSemaphore(DWORD fdwAccess, 2809 BOOL fInherit, 2810 LPCTSTR lpName) 2811 { 2812 int iIndex; /* index into the handle table */ 2813 int iIndexNew; /* index into the handle table */ 2814 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 2815 PHMHANDLEDATA pHMHandleData; 2816 DWORD rc; /* API return code */ 2817 2818 2819 pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */ 2820 2821 iIndexNew = _HMHandleGetFree(); /* get free handle */ 2822 if (-1 == iIndexNew) /* oops, no free handles ! */ 2823 { 2824 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 2825 return 0; /* signal error */ 2826 } 2827 2828 2829 /* initialize the complete HMHANDLEDATA structure */ 2830 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 2831 pHMHandleData->dwAccess = fdwAccess; 2832 pHMHandleData->dwShare = 0; 2833 pHMHandleData->dwCreation = 0; 2834 pHMHandleData->dwFlags = 0; 2835 pHMHandleData->lpHandlerData = NULL; 2836 2837 2838 /* we've got to mark the handle as occupied here, since another device */ 2839 /* could be created within the device handler -> deadlock */ 2840 2841 /* write appropriate entry into the handle table if open succeeded */ 2842 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2843 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 2844 2845 /* call the device handler */ 2846 rc = pDeviceHandler->OpenSemaphore(&TabWin32Handles[iIndexNew].hmHandleData, 2847 fInherit, 2848 lpName); 2849 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2850 { 2851 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2852 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2853 return 0; /* signal failure */ 2854 } 2855 else 2856 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 2857 2858 return iIndexNew; /* return valid handle */ 2859 } 2860 2861 2862 /***************************************************************************** 2863 * Name : HMReleaseSemaphore 2864 * Purpose : router function for ReleaseSemaphore 2865 * Parameters: 2866 * Variables : 2867 * Result : 2868 * Remark : 2869 * Status : 2870 * 2871 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 2872 *****************************************************************************/ 2873 2874 BOOL HMReleaseSemaphore(HANDLE hEvent, 2875 LONG cReleaseCount, 2876 LPLONG lpPreviousCount) 2877 { 2878 int iIndex; /* index into the handle table */ 2879 DWORD dwResult; /* result from the device handler's API */ 2880 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 2881 2882 /* validate handle */ 2883 iIndex = _HMHandleQuery(hEvent); /* get the index */ 2884 if (-1 == iIndex) /* error ? */ 2885 { 2886 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 2887 return 0; /* signal failure */ 2888 } 2889 else 2890 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 2891 2892 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 2893 dwResult = pHMHandle->pDeviceHandler->ReleaseSemaphore(&pHMHandle->hmHandleData, 2894 cReleaseCount, 2895 lpPreviousCount); 2896 2897 return (dwResult); /* deliver return code */ 2898 } 2899 2900 2901 /***************************************************************************** 2902 * Name : HANDLE HMCreateFileMapping 2903 * Purpose : Wrapper for the CreateFileMapping() API 2904 * Parameters: 2905 * Variables : 2906 * Result : 2907 * Remark : 2908 * Status : 2909 * 2910 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 2911 *****************************************************************************/ 2912 2913 HANDLE HMCreateFileMapping(HANDLE hFile, 2914 LPSECURITY_ATTRIBUTES lpFileMappingAttributes, 2915 DWORD flProtect, 2916 DWORD dwMaximumSizeHigh, 2917 DWORD dwMaximumSizeLow, 2918 LPCTSTR lpName) 2919 { 2920 int iIndex; /* index into the handle table */ 2921 int iIndexNew; /* index into the handle table */ 2922 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 2923 PHMHANDLEDATA pHMHandleData; 2924 DWORD rc; /* API return code */ 2925 2926 pDeviceHandler = HMGlobals.pHMFileMapping; /* device is predefined */ 2927 2928 iIndexNew = _HMHandleGetFree(); /* get free handle */ 2929 if (-1 == iIndexNew) /* oops, no free handles ! */ 2930 { 2931 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 2932 return 0; /* signal error */ 2933 } 2934 2935 /* initialize the complete HMHANDLEDATA structure */ 2936 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 2937 pHMHandleData->dwAccess = 0; 2938 pHMHandleData->dwShare = 0; 2939 pHMHandleData->dwCreation = 0; 2940 pHMHandleData->dwFlags = 0; 2941 pHMHandleData->lpHandlerData = NULL; 2940 pHMHandleData->dwInternalType = HMTYPE_MEMMAP; 2942 2941 2943 2942 /* we've got to mark the handle as occupied here, since another device */ … … 2963 2962 { 2964 2963 if(rc != ERROR_ALREADY_EXISTS) { 2965 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2964 FREEHANDLE(iIndexNew); 2965 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2966 2966 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2967 2967 return (NULL); /* signal error */ … … 3033 3033 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 3034 3034 { 3035 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3035 FREEHANDLE(iIndexNew); 3036 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3036 3037 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 3037 3038 return (NULL); /* signal error */ … … 3150 3151 } 3151 3152 3152 //If the timeout is less than 20 milliseconds (and not zero), then we are likely to3153 //return too late if the thread priority isn't time critical (time slices3154 //of 32 ms)3155 //To avoid this problem, we temporarily switch to time critical priority.3156 HANDLE hThread = GetCurrentThread();3157 BOOL fChangePriority = FALSE;3158 DWORD dwThreadPriority;3159 3160 if(dwTimeout && dwTimeout < 20) {3161 dwThreadPriority = GetThreadPriority(hThread);3162 if(dwThreadPriority != THREAD_PRIORITY_TIME_CRITICAL)3163 {3164 dprintf(("Temporarily change priority to THREAD_PRIORITY_TIME_CRITICAL for better timing"));3165 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);3166 //round to 8 ms units to get more precise timeouts3167 if(dwTimeout > 8)3168 dwTimeout = (dwTimeout/8)*8;3169 fChangePriority = TRUE;3170 }3171 }3172 3173 3153 // OK, now forward to Open32. 3174 3154 // @@@PH: Note this will fail on handles that do NOT belong to Open32 … … 3179 3159 dwTimeout); 3180 3160 3181 //Restore old thread priority if we changed it before3182 if(fChangePriority) {3183 SetThreadPriority(hThread, dwThreadPriority);3184 }3185 3186 3161 return (rc); // OK, done 3187 3162 } … … 3271 3246 //// return (WAIT_FAILED); 3272 3247 } 3273 }3274 3275 //If the timeout is less than 20 milliseconds (and not zero), then we are likely to3276 //return too late if the thread priority isn't time critical (time slices3277 //of 32 ms)3278 //To avoid this problem, we temporarily switch to time critical priority.3279 HANDLE hThread = GetCurrentThread();3280 BOOL fChangePriority = FALSE;3281 DWORD dwThreadPriority;3282 3283 if(dwTimeout && dwTimeout < 20) {3284 dwThreadPriority = GetThreadPriority(hThread);3285 if(dwThreadPriority != THREAD_PRIORITY_TIME_CRITICAL)3286 {3287 dprintf(("Temporarily change priority to THREAD_PRIORITY_TIME_CRITICAL for better timing"));3288 SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);3289 //round to 8 ms units to get more precise timeouts3290 if(dwTimeout > 8)3291 dwTimeout = (dwTimeout/8)*8;3292 fChangePriority = TRUE;3293 }3294 3248 } 3295 3249 … … 3302 3256 dwWakeMask); 3303 3257 3304 //Restore old thread priority if we changed it before3305 if(fChangePriority) {3306 SetThreadPriority(hThread, dwThreadPriority);3307 }3308 3309 3258 dprintf2(("MsgWaitForMultipleObjects returned %d", rc)); 3310 3259 return (rc); // OK, done … … 3322 3271 *****************************************************************************/ 3323 3272 3324 BOOL HMDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,3273 BOOL WIN32API DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, 3325 3274 LPVOID lpInBuffer, DWORD nInBufferSize, 3326 3275 LPVOID lpOutBuffer, DWORD nOutBufferSize, … … 3349 3298 } 3350 3299 /***************************************************************************** 3351 * Name : HMCancelIo 3352 * Purpose : router function for CancelIo 3353 * Parameters: 3354 * Variables : 3355 * Result : 3356 * Remark : 3300 * Name : BOOL WIN32API CancelIo 3301 * Purpose : The CancelIO function cancels all pending input and output 3302 * (I/O) operations that were issued by the calling thread for 3303 * the specified file handle. The function does not cancel 3304 * I/O operations issued for the file handle by other threads. 3305 * Parameters: HANDLE hFile file handle for which to cancel I/O 3306 * Variables : 3307 * Result : If the function succeeds, the return value is nonzero All pending 3308 * I/O operations issued by the calling thread for the file handle 3309 * were successfully canceled. 3310 * If the function fails, the return value is zero. 3311 * To get extended error information, call GetLastError. 3312 * Remark : If there are any I/O operations in progress for the specified 3313 * file HANDLE and they were issued by the calling thread, the 3314 * CancelIO function cancels them. 3315 * Note that the I/O operations must have been issued as 3316 * overlapped I/O. If they were not, the I/O operations would not 3317 * have returned to allow the thread to call the CancelIO function. 3318 * Calling the CancelIO function with a file handle that was not 3319 * opened with FILE_FLAG_OVERLAPPED does nothing. 3320 * All I/O operations that are canceled will complete with the 3321 * error ERROR_OPERATION_ABORTED. All completion notifications 3322 * for the I/O operations will occur normally. 3357 3323 * Status : 3358 3324 * 3359 3325 * Author : Sander van Leeuwen 3360 3326 *****************************************************************************/ 3361 BOOL HMCancelIo(HANDLE hDevice)3327 BOOL WIN32API CancelIo(HANDLE hDevice) 3362 3328 { 3363 3329 int iIndex; /* index into the handle table */ … … 3377 3343 3378 3344 return (fResult); /* deliver return code */ 3379 }3380 /*****************************************************************************3381 * Name : HMCOMGetCommState3382 * Purpose : router function for GetCommState3383 * Parameters:3384 * Variables :3385 * Result :3386 * Remark :3387 * Status :3388 *3389 * Author : Achim Hasenmueller [Sat, 1999/11/27 13:40]3390 *****************************************************************************/3391 3392 BOOL HMCommGetCommState(HANDLE hCommDev, LPDCB lpdcb)3393 {3394 int iIndex; /* index into the handle table */3395 BOOL bResult; /* result from the device handler's API */3396 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3397 3398 /* validate handle */3399 iIndex = _HMHandleQuery(hCommDev); /* get the index */3400 if (-1 == iIndex) /* error ? */3401 {3402 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3403 return (NULL); /* signal failure */3404 }3405 3406 if(IsBadWritePtr(lpdcb,sizeof(DCB)))3407 {3408 SetLastError(ERROR_INVALID_PARAMETER);3409 return FALSE;3410 }3411 3412 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3413 bResult = pHMHandle->pDeviceHandler->GetCommState(&pHMHandle->hmHandleData,3414 lpdcb);3415 3416 return (bResult); /* deliver return code */3417 }3418 3419 BOOL HMCommWaitCommEvent( HANDLE hCommDev,3420 LPDWORD lpfdwEvtMask,3421 LPOVERLAPPED lpo)3422 {3423 int iIndex; /* index into the handle table */3424 BOOL bResult; /* result from the device handler's API */3425 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3426 3427 /* validate handle */3428 iIndex = _HMHandleQuery(hCommDev); /* get the index */3429 if (-1 == iIndex) /* error ? */3430 {3431 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3432 return FALSE; /* signal failure */3433 }3434 3435 if(NULL!=lpo && IsBadReadPtr(lpo,sizeof(OVERLAPPED)) )3436 {3437 SetLastError(ERROR_INVALID_PARAMETER);3438 return FALSE;3439 }3440 3441 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3442 bResult = pHMHandle->pDeviceHandler->WaitCommEvent( &pHMHandle->hmHandleData,3443 lpfdwEvtMask,3444 lpo);3445 3446 return (bResult); /* deliver return code */3447 }3448 3449 BOOL HMCommGetCommProperties( HANDLE hCommDev,3450 LPCOMMPROP lpcmmp)3451 {3452 int iIndex; /* index into the handle table */3453 BOOL bResult; /* result from the device handler's API */3454 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3455 3456 /* validate handle */3457 iIndex = _HMHandleQuery(hCommDev); /* get the index */3458 if (-1 == iIndex) /* error ? */3459 {3460 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3461 return (NULL); /* signal failure */3462 }3463 3464 if(IsBadWritePtr(lpcmmp,sizeof(COMMPROP)) )3465 {3466 SetLastError(ERROR_INVALID_PARAMETER);3467 return FALSE;3468 }3469 3470 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3471 bResult = pHMHandle->pDeviceHandler->GetCommProperties( &pHMHandle->hmHandleData,3472 lpcmmp);3473 3474 return (bResult); /* deliver return code */3475 }3476 3477 BOOL HMCommGetCommMask( HANDLE hCommDev,3478 LPDWORD lpfdwEvtMask)3479 {3480 int iIndex; /* index into the handle table */3481 BOOL bResult; /* result from the device handler's API */3482 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3483 3484 /* validate handle */3485 iIndex = _HMHandleQuery(hCommDev); /* get the index */3486 if (-1 == iIndex) /* error ? */3487 {3488 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3489 return (NULL); /* signal failure */3490 }3491 3492 if(IsBadWritePtr(lpfdwEvtMask,sizeof(DWORD)) )3493 {3494 SetLastError(ERROR_INVALID_PARAMETER);3495 return FALSE;3496 }3497 3498 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3499 bResult = pHMHandle->pDeviceHandler->GetCommMask( &pHMHandle->hmHandleData,3500 lpfdwEvtMask);3501 3502 return (bResult); /* deliver return code */3503 }3504 3505 BOOL HMCommSetCommMask( HANDLE hCommDev,3506 DWORD fdwEvtMask)3507 {3508 int iIndex; /* index into the handle table */3509 BOOL bResult; /* result from the device handler's API */3510 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3511 3512 /* validate handle */3513 iIndex = _HMHandleQuery(hCommDev); /* get the index */3514 if (-1 == iIndex) /* error ? */3515 {3516 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3517 return (NULL); /* signal failure */3518 }3519 3520 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3521 bResult = pHMHandle->pDeviceHandler->SetCommMask( &pHMHandle->hmHandleData,3522 fdwEvtMask);3523 3524 return (bResult); /* deliver return code */3525 }3526 3527 BOOL HMCommPurgeComm( HANDLE hCommDev,3528 DWORD fdwAction)3529 {3530 int iIndex; /* index into the handle table */3531 BOOL bResult; /* result from the device handler's API */3532 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3533 3534 /* validate handle */3535 iIndex = _HMHandleQuery(hCommDev); /* get the index */3536 if (-1 == iIndex) /* error ? */3537 {3538 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3539 return (NULL); /* signal failure */3540 }3541 3542 3543 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3544 bResult = pHMHandle->pDeviceHandler->PurgeComm( &pHMHandle->hmHandleData,3545 fdwAction);3546 3547 return (bResult); /* deliver return code */3548 }3549 3550 BOOL HMCommClearCommError( HANDLE hCommDev,3551 LPDWORD lpdwErrors,3552 LPCOMSTAT lpcst)3553 {3554 int iIndex; /* index into the handle table */3555 BOOL bResult; /* result from the device handler's API */3556 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3557 3558 /* validate handle */3559 iIndex = _HMHandleQuery(hCommDev); /* get the index */3560 if (-1 == iIndex) /* error ? */3561 {3562 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3563 return (NULL); /* signal failure */3564 }3565 3566 if((lpdwErrors != NULL && IsBadWritePtr(lpdwErrors,sizeof(DWORD))) ||3567 (NULL!=lpcst && IsBadWritePtr(lpcst,sizeof(COMSTAT)) ) )3568 {3569 SetLastError(ERROR_INVALID_PARAMETER);3570 return FALSE;3571 }3572 3573 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3574 bResult = pHMHandle->pDeviceHandler->ClearCommError(&pHMHandle->hmHandleData,3575 lpdwErrors,3576 lpcst);3577 3578 return (bResult); /* deliver return code */3579 }3580 3581 BOOL HMCommSetCommState( HANDLE hCommDev,3582 LPDCB lpdcb)3583 {3584 int iIndex; /* index into the handle table */3585 BOOL bResult; /* result from the device handler's API */3586 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3587 3588 /* validate handle */3589 iIndex = _HMHandleQuery(hCommDev); /* get the index */3590 if (-1 == iIndex) /* error ? */3591 {3592 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3593 return (NULL); /* signal failure */3594 }3595 3596 if(IsBadReadPtr(lpdcb,sizeof(DCB)) )3597 {3598 SetLastError(ERROR_INVALID_PARAMETER);3599 return FALSE;3600 }3601 3602 3603 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3604 bResult = pHMHandle->pDeviceHandler->SetCommState(&pHMHandle->hmHandleData,3605 lpdcb);3606 3607 return (bResult); /* deliver return code */3608 }3609 3610 3611 BOOL HMCommGetCommTimeouts( HANDLE hCommDev,3612 LPCOMMTIMEOUTS lpctmo)3613 {3614 int iIndex; /* index into the handle table */3615 BOOL bResult; /* result from the device handler's API */3616 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3617 3618 /* validate handle */3619 iIndex = _HMHandleQuery(hCommDev); /* get the index */3620 if (-1 == iIndex) /* error ? */3621 {3622 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3623 return (NULL); /* signal failure */3624 }3625 3626 if(IsBadWritePtr(lpctmo,sizeof(COMMTIMEOUTS)) )3627 {3628 SetLastError(ERROR_INVALID_PARAMETER);3629 return FALSE;3630 }3631 3632 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3633 bResult = pHMHandle->pDeviceHandler->GetCommTimeouts( &pHMHandle->hmHandleData,3634 lpctmo);3635 3636 return (bResult); /* deliver return code */3637 }3638 BOOL HMCommGetCommModemStatus( HANDLE hCommDev,3639 LPDWORD lpModemStat )3640 {3641 int iIndex; /* index into the handle table */3642 BOOL bResult; /* result from the device handler's API */3643 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3644 3645 /* validate handle */3646 iIndex = _HMHandleQuery(hCommDev); /* get the index */3647 if (-1 == iIndex) /* error ? */3648 {3649 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3650 return (NULL); /* signal failure */3651 }3652 3653 if(IsBadWritePtr(lpModemStat,sizeof(DWORD)) )3654 {3655 SetLastError(ERROR_INVALID_PARAMETER);3656 return FALSE;3657 }3658 3659 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3660 bResult = pHMHandle->pDeviceHandler->GetCommModemStatus( &pHMHandle->hmHandleData,3661 lpModemStat);3662 3663 return (bResult); /* deliver return code */3664 }3665 3666 BOOL HMCommSetCommTimeouts( HANDLE hCommDev,3667 LPCOMMTIMEOUTS lpctmo)3668 {3669 int iIndex; /* index into the handle table */3670 BOOL bResult; /* result from the device handler's API */3671 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3672 3673 /* validate handle */3674 iIndex = _HMHandleQuery(hCommDev); /* get the index */3675 if (-1 == iIndex) /* error ? */3676 {3677 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3678 return (NULL); /* signal failure */3679 }3680 3681 if(IsBadReadPtr(lpctmo,sizeof(COMMTIMEOUTS)) )3682 {3683 SetLastError(ERROR_INVALID_PARAMETER);3684 return FALSE;3685 }3686 3687 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3688 bResult = pHMHandle->pDeviceHandler->SetCommTimeouts( &pHMHandle->hmHandleData,3689 lpctmo);3690 3691 return (bResult); /* deliver return code */3692 }3693 3694 BOOL HMCommTransmitCommChar( HANDLE hCommDev,3695 CHAR cChar )3696 {3697 int iIndex; /* index into the handle table */3698 BOOL bResult; /* result from the device handler's API */3699 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3700 3701 /* validate handle */3702 iIndex = _HMHandleQuery(hCommDev); /* get the index */3703 if (-1 == iIndex) /* error ? */3704 {3705 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3706 return (NULL); /* signal failure */3707 }3708 3709 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3710 bResult = pHMHandle->pDeviceHandler->TransmitCommChar( &pHMHandle->hmHandleData,3711 cChar);3712 3713 return (bResult); /* deliver return code */3714 }3715 3716 BOOL HMCommSetCommConfig( HANDLE hCommDev,3717 LPCOMMCONFIG lpCC,3718 DWORD dwSize )3719 {3720 int iIndex; /* index into the handle table */3721 BOOL bResult; /* result from the device handler's API */3722 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3723 3724 /* validate handle */3725 iIndex = _HMHandleQuery(hCommDev); /* get the index */3726 if (-1 == iIndex) /* error ? */3727 {3728 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3729 return (NULL); /* signal failure */3730 }3731 3732 if( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) ||3733 dwSize < sizeof(COMMCONFIG) )3734 {3735 SetLastError(ERROR_INVALID_PARAMETER);3736 return FALSE;3737 }3738 3739 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3740 bResult = pHMHandle->pDeviceHandler->SetCommConfig( &pHMHandle->hmHandleData,3741 lpCC,3742 dwSize);3743 3744 return (bResult); /* deliver return code */3745 }3746 3747 BOOL HMCommSetCommBreak( HANDLE hCommDev )3748 {3749 int iIndex; /* index into the handle table */3750 BOOL bResult; /* result from the device handler's API */3751 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3752 3753 /* validate handle */3754 iIndex = _HMHandleQuery(hCommDev); /* get the index */3755 if (-1 == iIndex) /* error ? */3756 {3757 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3758 return (NULL); /* signal failure */3759 }3760 3761 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3762 bResult = pHMHandle->pDeviceHandler->SetCommBreak( &pHMHandle->hmHandleData);3763 3764 return (bResult); /* deliver return code */3765 }3766 3767 BOOL HMCommGetCommConfig( HANDLE hCommDev,3768 LPCOMMCONFIG lpCC,3769 LPDWORD lpdwSize )3770 {3771 int iIndex; /* index into the handle table */3772 BOOL bResult; /* result from the device handler's API */3773 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3774 3775 /* validate handle */3776 iIndex = _HMHandleQuery(hCommDev); /* get the index */3777 if (-1 == iIndex) /* error ? */3778 {3779 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3780 return (NULL); /* signal failure */3781 }3782 3783 if(IsBadWritePtr(lpdwSize,sizeof(DWORD)) )3784 {3785 SetLastError(ERROR_INVALID_PARAMETER);3786 return FALSE;3787 }3788 3789 if( IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) ||3790 *lpdwSize< sizeof(COMMCONFIG) )3791 {3792 SetLastError(ERROR_INSUFFICIENT_BUFFER);3793 *lpdwSize= sizeof(COMMCONFIG);3794 return FALSE;3795 }3796 3797 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3798 bResult = pHMHandle->pDeviceHandler->GetCommConfig( &pHMHandle->hmHandleData,3799 lpCC,3800 lpdwSize);3801 3802 return (bResult); /* deliver return code */3803 }3804 3805 BOOL HMCommEscapeCommFunction( HANDLE hCommDev,3806 UINT dwFunc )3807 {3808 int iIndex; /* index into the handle table */3809 BOOL bResult; /* result from the device handler's API */3810 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3811 3812 /* validate handle */3813 iIndex = _HMHandleQuery(hCommDev); /* get the index */3814 if (-1 == iIndex) /* error ? */3815 {3816 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3817 return (NULL); /* signal failure */3818 }3819 3820 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3821 3822 switch(dwFunc)3823 {3824 case CLRDTR:3825 case CLRRTS:3826 case SETDTR:3827 case SETRTS:3828 case SETXOFF:3829 case SETXON:3830 bResult = pHMHandle->pDeviceHandler->EscapeCommFunction( &pHMHandle->hmHandleData,3831 dwFunc);3832 break;3833 case SETBREAK:3834 bResult = pHMHandle->pDeviceHandler->SetCommBreak(&pHMHandle->hmHandleData);3835 break;3836 case CLRBREAK:3837 bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData);3838 break;3839 default:3840 SetLastError(ERROR_INVALID_PARAMETER);3841 bResult = FALSE;3842 }3843 3844 3845 return (bResult); /* deliver return code */3846 }3847 3848 BOOL HMCommSetupComm( HANDLE hCommDev,3849 DWORD dwInQueue,3850 DWORD dwOutQueue)3851 {3852 int iIndex; /* index into the handle table */3853 BOOL bResult; /* result from the device handler's API */3854 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3855 3856 /* validate handle */3857 iIndex = _HMHandleQuery(hCommDev); /* get the index */3858 if (-1 == iIndex) /* error ? */3859 {3860 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3861 return (NULL); /* signal failure */3862 }3863 3864 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3865 bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData,3866 dwInQueue,3867 dwOutQueue);3868 3869 return (bResult); /* deliver return code */3870 }3871 3872 BOOL HMCommClearCommBreak(HANDLE hCommDev)3873 {3874 int iIndex; /* index into the handle table */3875 BOOL bResult; /* result from the device handler's API */3876 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3877 3878 /* validate handle */3879 iIndex = _HMHandleQuery(hCommDev); /* get the index */3880 if (-1 == iIndex) /* error ? */3881 {3882 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3883 return (NULL); /* signal failure */3884 }3885 3886 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3887 bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData);3888 3889 return (bResult); /* deliver return code */3890 }3891 3892 BOOL HMCommSetDefaultCommConfig( HANDLE hCommDev,3893 LPCOMMCONFIG lpCC,3894 DWORD dwSize)3895 {3896 int iIndex; /* index into the handle table */3897 BOOL bResult; /* result from the device handler's API */3898 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3899 3900 /* validate handle */3901 iIndex = _HMHandleQuery(hCommDev); /* get the index */3902 if (-1 == iIndex) /* error ? */3903 {3904 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3905 return (NULL); /* signal failure */3906 }3907 3908 if( (lpCC!=NULL) &&3909 ( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) ||3910 dwSize != sizeof(COMMCONFIG) ) )3911 {3912 SetLastError(ERROR_INVALID_PARAMETER);3913 return FALSE;3914 }3915 3916 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3917 bResult = pHMHandle->pDeviceHandler->SetDefaultCommConfig(&pHMHandle->hmHandleData,3918 lpCC,3919 dwSize);3920 3921 return (bResult); /* deliver return code */3922 }3923 3924 BOOL HMCommGetDefaultCommConfig( HANDLE hCommDev,3925 LPCOMMCONFIG lpCC,3926 LPDWORD lpdwSize)3927 {3928 int iIndex; /* index into the handle table */3929 BOOL bResult; /* result from the device handler's API */3930 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */3931 3932 /* validate handle */3933 iIndex = _HMHandleQuery(hCommDev); /* get the index */3934 if (-1 == iIndex) /* error ? */3935 {3936 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */3937 return (NULL); /* signal failure */3938 }3939 3940 if(IsBadWritePtr(lpdwSize,sizeof(DWORD)))3941 {3942 SetLastError(ERROR_INVALID_PARAMETER);3943 return FALSE;3944 }3945 3946 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */3947 bResult = pHMHandle->pDeviceHandler->GetDefaultCommConfig( &pHMHandle->hmHandleData,3948 lpCC,3949 lpdwSize);3950 3951 return (bResult); /* deliver return code */3952 3345 } 3953 3346 … … 3969 3362 HANDLE *TokenHandle) 3970 3363 { 3971 int iIndex;/* index into the handle table */3364 int iIndex; /* index into the handle table */ 3972 3365 int iIndexNew; /* index into the handle table */ 3973 3366 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ … … 3991 3384 pHMHandleData->dwFlags = 0; 3992 3385 pHMHandleData->lpHandlerData = NULL; 3386 pHMHandleData->dwInternalType = HMTYPE_THREADTOKEN; 3993 3387 3994 3388 … … 4010 3404 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 4011 3405 { 4012 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3406 FREEHANDLE(iIndexNew); 3407 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 4013 3408 return (rc); /* signal error */ 4014 3409 } … … 4036 3431 HANDLE *TokenHandle) 4037 3432 { 4038 int iIndex;/* index into the handle table */3433 int iIndex; /* index into the handle table */ 4039 3434 int iIndexNew; /* index into the handle table */ 4040 3435 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ … … 4058 3453 pHMHandleData->dwFlags = 0; 4059 3454 pHMHandleData->lpHandlerData = NULL; 3455 pHMHandleData->dwInternalType = HMTYPE_PROCESSTOKEN; 4060 3456 4061 3457 … … 4067 3463 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 4068 3464 4069 3465 /* call the device handler */ 4070 3466 4071 3467 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to … … 4077 3473 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 4078 3474 { 4079 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3475 FREEHANDLE(iIndexNew); 3476 // TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 4080 3477 return (rc); /* signal error */ 4081 3478 } … … 4086 3483 return STATUS_SUCCESS; 4087 3484 } 4088 /***************************************************************************** 4089 * Name : HMCreateThread 4090 * Purpose : router function for CreateThread 4091 * Parameters: 4092 * Variables : 4093 * Result : 4094 * Remark : 4095 * Status : 4096 * 4097 * Author : SvL 4098 *****************************************************************************/ 4099 HANDLE HMCreateThread(LPSECURITY_ATTRIBUTES lpsa, 4100 DWORD cbStack, 4101 LPTHREAD_START_ROUTINE lpStartAddr, 4102 LPVOID lpvThreadParm, 4103 DWORD fdwCreate, 4104 LPDWORD lpIDThread, 4105 BOOL fFirstThread) 4106 { 4107 int iIndex; /* index into the handle table */ 4108 int iIndexNew; /* index into the handle table */ 4109 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 4110 PHMHANDLEDATA pHMHandleData; 4111 HANDLE rc; /* API return code */ 4112 4113 SetLastError(ERROR_SUCCESS); 4114 4115 pDeviceHandler = HMGlobals.pHMThread; /* device is predefined */ 4116 4117 iIndexNew = _HMHandleGetFree(); /* get free handle */ 4118 if (-1 == iIndexNew) /* oops, no free handles ! */ 4119 { 4120 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 4121 return 0; 4122 } 4123 4124 /* initialize the complete HMHANDLEDATA structure */ 4125 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 4126 pHMHandleData->dwAccess = 0; 4127 pHMHandleData->dwShare = 0; 4128 pHMHandleData->dwCreation = 0; 4129 pHMHandleData->dwFlags = 0; 4130 pHMHandleData->lpHandlerData = NULL; 4131 4132 4133 /* we've got to mark the handle as occupied here, since another device */ 4134 /* could be created within the device handler -> deadlock */ 4135 4136 /* write appropriate entry into the handle table if open succeeded */ 4137 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 4138 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 4139 4140 /* call the device handler */ 4141 4142 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to 4143 // a valid HandleManager-internal handle! 4144 rc = pDeviceHandler->CreateThread(&TabWin32Handles[iIndexNew].hmHandleData, 4145 lpsa, cbStack, lpStartAddr, 4146 lpvThreadParm, fdwCreate, lpIDThread, fFirstThread); 4147 4148 if (rc == 0) /* oops, creation failed within the device handler */ 4149 { 4150 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 4151 return 0; /* signal error */ 4152 } 4153 4154 return iIndexNew; 4155 } 4156 /***************************************************************************** 4157 * Name : HMGetThreadPriority 4158 * Purpose : router function for GetThreadPriority 4159 * Parameters: 4160 * Variables : 4161 * Result : 4162 * Remark : 4163 * Status : 4164 * 4165 * Author : SvL 4166 *****************************************************************************/ 4167 INT HMGetThreadPriority(HANDLE hThread) 4168 { 4169 int iIndex; /* index into the handle table */ 4170 INT lpResult; /* result from the device handler's API */ 4171 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4172 4173 SetLastError(ERROR_SUCCESS); 4174 /* validate handle */ 4175 iIndex = _HMHandleQuery(hThread); /* get the index */ 4176 if (-1 == iIndex) /* error ? */ 4177 { 4178 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4179 return (-1); /* signal failure */ 4180 } 4181 4182 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4183 lpResult = pHMHandle->pDeviceHandler->GetThreadPriority(hThread, &TabWin32Handles[iIndex].hmHandleData); 4184 4185 return (lpResult); /* deliver return code */ 4186 } 4187 /***************************************************************************** 4188 * Name : HMSuspendThread 4189 * Purpose : router function for SuspendThread 4190 * Parameters: 4191 * Variables : 4192 * Result : 4193 * Remark : 4194 * Status : 4195 * 4196 * Author : SvL 4197 *****************************************************************************/ 4198 DWORD HMSuspendThread(HANDLE hThread) 4199 { 4200 int iIndex; /* index into the handle table */ 4201 HANDLE lpResult; /* result from the device handler's API */ 4202 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4203 4204 SetLastError(ERROR_SUCCESS); 4205 /* validate handle */ 4206 iIndex = _HMHandleQuery(hThread); /* get the index */ 4207 if (-1 == iIndex) /* error ? */ 4208 { 4209 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4210 return -1; /* signal failure */ 4211 } 4212 4213 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4214 lpResult = pHMHandle->pDeviceHandler->SuspendThread(hThread, &TabWin32Handles[iIndex].hmHandleData); 4215 4216 return (lpResult); /* deliver return code */ 4217 } 4218 /***************************************************************************** 4219 * Name : HMSetThreadPriority 4220 * Purpose : router function for SetThreadPriority 4221 * Parameters: 4222 * Variables : 4223 * Result : 4224 * Remark : 4225 * Status : 4226 * 4227 * Author : SvL 4228 *****************************************************************************/ 4229 BOOL HMSetThreadPriority(HANDLE hThread, int priority) 4230 { 4231 int iIndex; /* index into the handle table */ 4232 BOOL lpResult; /* result from the device handler's API */ 4233 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4234 4235 SetLastError(ERROR_SUCCESS); 4236 /* validate handle */ 4237 iIndex = _HMHandleQuery(hThread); /* get the index */ 4238 if (-1 == iIndex) /* error ? */ 4239 { 4240 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4241 return FALSE; /* signal failure */ 4242 } 4243 4244 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4245 lpResult = pHMHandle->pDeviceHandler->SetThreadPriority(hThread, &TabWin32Handles[iIndex].hmHandleData, priority); 4246 4247 return (lpResult); /* deliver return code */ 4248 } 4249 /***************************************************************************** 4250 * Name : HMGetThreadContext 4251 * Purpose : router function for GetThreadContext 4252 * Parameters: 4253 * Variables : 4254 * Result : 4255 * Remark : 4256 * Status : 4257 * 4258 * Author : SvL 4259 *****************************************************************************/ 4260 BOOL HMGetThreadContext(HANDLE hThread, CONTEXT *lpContext) 4261 { 4262 int iIndex; /* index into the handle table */ 4263 BOOL lpResult; /* result from the device handler's API */ 4264 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4265 4266 SetLastError(ERROR_SUCCESS); 4267 /* validate handle */ 4268 iIndex = _HMHandleQuery(hThread); /* get the index */ 4269 if (-1 == iIndex) /* error ? */ 4270 { 4271 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4272 return FALSE; /* signal failure */ 4273 } 4274 4275 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4276 lpResult = pHMHandle->pDeviceHandler->GetThreadContext(hThread, &TabWin32Handles[iIndex].hmHandleData, lpContext); 4277 4278 return (lpResult); /* deliver return code */ 4279 } 4280 /***************************************************************************** 4281 * Name : HMSetThreadContext 4282 * Purpose : router function for SetThreadContext 4283 * Parameters: 4284 * Variables : 4285 * Result : 4286 * Remark : 4287 * Status : 4288 * 4289 * Author : SvL 4290 *****************************************************************************/ 4291 BOOL HMSetThreadContext(HANDLE hThread, const CONTEXT *lpContext) 4292 { 4293 int iIndex; /* index into the handle table */ 4294 BOOL lpResult; /* result from the device handler's API */ 4295 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4296 4297 SetLastError(ERROR_SUCCESS); 4298 /* validate handle */ 4299 iIndex = _HMHandleQuery(hThread); /* get the index */ 4300 if (-1 == iIndex) /* error ? */ 4301 { 4302 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4303 return FALSE; /* signal failure */ 4304 } 4305 4306 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4307 lpResult = pHMHandle->pDeviceHandler->SetThreadContext(hThread, &TabWin32Handles[iIndex].hmHandleData, lpContext); 4308 4309 return (lpResult); /* deliver return code */ 4310 } 4311 /***************************************************************************** 4312 * Name : HMGetThreadTimes 4313 * Purpose : router function for HMGetThreadTimes 4314 * Parameters: 4315 * Variables : 4316 * Result : 4317 * Remark : 4318 * Status : 4319 * 4320 * Author : SvL 4321 *****************************************************************************/ 4322 BOOL HMGetThreadTimes(HANDLE hThread, LPFILETIME lpCreationTime, 4323 LPFILETIME lpExitTime, LPFILETIME lpKernelTime, 4324 LPFILETIME lpUserTime) 4325 { 4326 int iIndex; /* index into the handle table */ 4327 BOOL lpResult; /* result from the device handler's API */ 4328 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4329 4330 SetLastError(ERROR_SUCCESS); 4331 /* validate handle */ 4332 iIndex = _HMHandleQuery(hThread); /* get the index */ 4333 if (-1 == iIndex) /* error ? */ 4334 { 4335 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4336 return FALSE; /* signal failure */ 4337 } 4338 4339 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4340 lpResult = pHMHandle->pDeviceHandler->GetThreadTimes(hThread, &TabWin32Handles[iIndex].hmHandleData, 4341 lpCreationTime, lpExitTime, 4342 lpKernelTime, lpUserTime); 4343 4344 return (lpResult); /* deliver return code */ 4345 } 4346 /***************************************************************************** 4347 * Name : HMTerminateThread 4348 * Purpose : router function for TerminateThread 4349 * Parameters: 4350 * Variables : 4351 * Result : 4352 * Remark : 4353 * Status : 4354 * 4355 * Author : SvL 4356 *****************************************************************************/ 4357 BOOL HMTerminateThread(HANDLE hThread, DWORD exitcode) 4358 { 4359 int iIndex; /* index into the handle table */ 4360 BOOL lpResult; /* result from the device handler's API */ 4361 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4362 4363 SetLastError(ERROR_SUCCESS); 4364 /* validate handle */ 4365 iIndex = _HMHandleQuery(hThread); /* get the index */ 4366 if (-1 == iIndex) /* error ? */ 4367 { 4368 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4369 return FALSE; /* signal failure */ 4370 } 4371 4372 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4373 lpResult = pHMHandle->pDeviceHandler->TerminateThread(hThread, &TabWin32Handles[iIndex].hmHandleData, exitcode); 4374 4375 return (lpResult); /* deliver return code */ 4376 } 4377 /***************************************************************************** 4378 * Name : HMResumeThread 4379 * Purpose : router function for ResumeThread 4380 * Parameters: 4381 * Variables : 4382 * Result : 4383 * Remark : 4384 * Status : 4385 * 4386 * Author : SvL 4387 *****************************************************************************/ 4388 DWORD HMResumeThread(HANDLE hThread) 4389 { 4390 int iIndex; /* index into the handle table */ 4391 DWORD lpResult; /* result from the device handler's API */ 4392 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4393 4394 SetLastError(ERROR_SUCCESS); 4395 /* validate handle */ 4396 iIndex = _HMHandleQuery(hThread); /* get the index */ 4397 if (-1 == iIndex) /* error ? */ 4398 { 4399 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4400 return -1; /* signal failure */ 4401 } 4402 4403 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4404 lpResult = pHMHandle->pDeviceHandler->ResumeThread(hThread, &TabWin32Handles[iIndex].hmHandleData); 4405 4406 return (lpResult); /* deliver return code */ 4407 } 4408 4409 /***************************************************************************** 4410 * Name : HMGetExitCodeThread 4411 * Purpose : router function for GetExitCodeThread 4412 * Parameters: 4413 * Variables : 4414 * Result : 4415 * Remark : 4416 * Status : 4417 * 4418 * Author : SvL 4419 *****************************************************************************/ 4420 BOOL HMGetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode) 4421 { 4422 int iIndex; /* index into the handle table */ 4423 BOOL lpResult; /* result from the device handler's API */ 4424 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4425 4426 SetLastError(ERROR_SUCCESS); 4427 /* validate handle */ 4428 iIndex = _HMHandleQuery(hThread); /* get the index */ 4429 if (-1 == iIndex) /* error ? */ 4430 { 4431 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4432 return FALSE; /* signal failure */ 4433 } 4434 4435 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4436 lpResult = pHMHandle->pDeviceHandler->GetExitCodeThread(hThread, &TabWin32Handles[iIndex].hmHandleData, lpExitCode); 4437 4438 return (lpResult); /* deliver return code */ 4439 } 4440 /***************************************************************************** 4441 * Name : HMSetThreadTerminated 4442 * Purpose : 4443 * Parameters: 4444 * Variables : 4445 * Result : 4446 * Remark : 4447 * Status : 4448 * 4449 * Author : SvL 4450 *****************************************************************************/ 4451 BOOL HMSetThreadTerminated(HANDLE hThread) 4452 { 4453 int iIndex; /* index into the handle table */ 4454 BOOL lpResult; /* result from the device handler's API */ 4455 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4456 4457 SetLastError(ERROR_SUCCESS); 4458 /* validate handle */ 4459 iIndex = _HMHandleQuery(hThread); /* get the index */ 4460 if (-1 == iIndex) /* error ? */ 4461 { 4462 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4463 return FALSE; /* signal failure */ 4464 } 4465 4466 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4467 lpResult = pHMHandle->pDeviceHandler->SetThreadTerminated(hThread, &TabWin32Handles[iIndex].hmHandleData); 4468 4469 return (lpResult); /* deliver return code */ 4470 } 4471 4472 /***************************************************************************** 4473 * Name : HMPeekNamedPipe 4474 * Purpose : 4475 * Parameters: 4476 * Variables : 4477 * Result : 4478 * Remark : 4479 * Status : 4480 * 4481 * Author : Przemyslaw Dobrowolski 4482 *****************************************************************************/ 4483 BOOL HMPeekNamedPipe(HANDLE hPipe, 4484 LPVOID lpvBuffer, 4485 DWORD cbBuffer, 4486 LPDWORD lpcbRead, 4487 LPDWORD lpcbAvail, 4488 LPDWORD lpcbMessage) 4489 { 4490 int iIndex; /* index into the handle table */ 4491 BOOL lpResult; /* result from the device handler's API */ 4492 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4493 4494 SetLastError(ERROR_SUCCESS); 4495 /* validate handle */ 4496 iIndex = _HMHandleQuery(hPipe); /* get the index */ 4497 if (-1 == iIndex) /* error ? */ 4498 { 4499 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4500 return FALSE; /* signal failure */ 4501 } 4502 4503 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4504 lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 4505 lpvBuffer, 4506 cbBuffer, 4507 lpcbRead, 4508 lpcbAvail, 4509 lpcbMessage); 4510 4511 return (lpResult); /* deliver return code */ 4512 } 4513 4514 /***************************************************************************** 4515 * Name : HMCreateNamedPipe 4516 * Purpose : 4517 * Parameters: 4518 * Variables : 4519 * Result : 4520 * Remark : 4521 * Status : 4522 * 4523 * Author : Przemyslaw Dobrowolski 4524 *****************************************************************************/ 4525 HANDLE HMCreateNamedPipe(LPCTSTR lpName, 4526 DWORD dwOpenMode, 4527 DWORD dwPipeMode, 4528 DWORD nMaxInstances, 4529 DWORD nOutBufferSize, 4530 DWORD nInBufferSize, 4531 DWORD nDefaultTimeOut, 4532 LPSECURITY_ATTRIBUTES lpSecurityAttributes) 4533 { 4534 int iIndex; /* index into the handle table */ 4535 int iIndexNew; /* index into the handle table */ 4536 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 4537 PHMHANDLEDATA pHMHandleData; 4538 HANDLE rc; /* API return code */ 4539 4540 SetLastError(ERROR_SUCCESS); 4541 4542 pDeviceHandler = HMGlobals.pHMNamedPipe; /* device is predefined */ 4543 4544 iIndexNew = _HMHandleGetFree(); /* get free handle */ 4545 if (-1 == iIndexNew) /* oops, no free handles ! */ 4546 { 4547 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 4548 return INVALID_HANDLE_VALUE; 4549 } 4550 4551 /* initialize the complete HMHANDLEDATA structure */ 4552 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 4553 pHMHandleData->dwAccess = 0; 4554 pHMHandleData->dwShare = 0; 4555 pHMHandleData->dwCreation = 0; 4556 pHMHandleData->dwFlags = 0; 4557 pHMHandleData->lpHandlerData = NULL; 4558 4559 /* we've got to mark the handle as occupied here, since another device */ 4560 /* could be created within the device handler -> deadlock */ 4561 4562 /* write appropriate entry into the handle table if open succeeded */ 4563 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 4564 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 4565 4566 /* call the device handler */ 4567 4568 rc = pDeviceHandler->CreateNamedPipe(&TabWin32Handles[iIndexNew].hmHandleData, 4569 lpName,dwOpenMode, 4570 dwPipeMode,nMaxInstances, 4571 nOutBufferSize,nInBufferSize, 4572 nDefaultTimeOut,lpSecurityAttributes); 4573 4574 if (rc == -1) /* oops, creation failed within the device handler */ 4575 { 4576 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 4577 return INVALID_HANDLE_VALUE; /* signal error */ 4578 } 4579 4580 dprintf(("Named pipe %x", iIndexNew)); 4581 if(lpSecurityAttributes && lpSecurityAttributes->bInheritHandle) { 4582 dprintf(("Set inheritance for child processes")); 4583 HMSetHandleInformation(iIndexNew, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); 4584 } 4585 4586 return iIndexNew; 4587 } 4588 4589 /***************************************************************************** 4590 * Name : HMConnectNamedPipe 4591 * Purpose : 4592 * Parameters: 4593 * Variables : 4594 * Result : 4595 * Remark : 4596 * Status : 4597 * 4598 * Author : Przemyslaw Dobrowolski 4599 *****************************************************************************/ 4600 BOOL HMConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED lpOverlapped) 4601 { 4602 int iIndex; /* index into the handle table */ 4603 BOOL lpResult; /* result from the device handler's API */ 4604 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4605 4606 SetLastError(ERROR_SUCCESS); 4607 /* validate handle */ 4608 iIndex = _HMHandleQuery(hPipe); /* get the index */ 4609 if (-1 == iIndex) /* error ? */ 4610 { 4611 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4612 return FALSE; /* signal failure */ 4613 } 4614 4615 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4616 lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 4617 lpOverlapped); 4618 4619 return (lpResult); /* deliver return code */ 4620 } 4621 4622 /***************************************************************************** 4623 * Name : HMDisconnectNamedPipe 4624 * Purpose : 4625 * Parameters: 4626 * Variables : 4627 * Result : 4628 * Remark : 4629 * Status : 4630 * 4631 * Author : Przemyslaw Dobrowolski 4632 *****************************************************************************/ 4633 BOOL HMDisconnectNamedPipe(HANDLE hPipe) 4634 { 4635 int iIndex; /* index into the handle table */ 4636 BOOL lpResult; /* result from the device handler's API */ 4637 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4638 4639 SetLastError(ERROR_SUCCESS); 4640 /* validate handle */ 4641 iIndex = _HMHandleQuery(hPipe); /* get the index */ 4642 if (-1 == iIndex) /* error ? */ 4643 { 4644 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4645 return FALSE; /* signal failure */ 4646 } 4647 4648 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4649 lpResult = pHMHandle->pDeviceHandler->DisconnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData); 4650 4651 return (lpResult); /* deliver return code */ 4652 } 4653 4654 /***************************************************************************** 4655 * Name : HMGetNamedPipeHandleState 4656 * Purpose : 4657 * Parameters: 4658 * Variables : 4659 * Result : 4660 * Remark : 4661 * Status : 4662 * 4663 * Author : Przemyslaw Dobrowolski 4664 *****************************************************************************/ 4665 BOOL HMGetNamedPipeHandleState(HANDLE hPipe, 4666 LPDWORD lpState, 4667 LPDWORD lpCurInstances, 4668 LPDWORD lpMaxCollectionCount, 4669 LPDWORD lpCollectDataTimeout, 4670 LPTSTR lpUserName, 4671 DWORD nMaxUserNameSize) 4672 { 4673 int iIndex; /* index into the handle table */ 4674 BOOL lpResult; /* result from the device handler's API */ 4675 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4676 4677 SetLastError(ERROR_SUCCESS); 4678 /* validate handle */ 4679 iIndex = _HMHandleQuery(hPipe); /* get the index */ 4680 if (-1 == iIndex) /* error ? */ 4681 { 4682 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4683 return FALSE; /* signal failure */ 4684 } 4685 4686 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4687 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData, 4688 lpState, 4689 lpCurInstances, 4690 lpMaxCollectionCount, 4691 lpCollectDataTimeout, 4692 lpUserName, 4693 nMaxUserNameSize); 4694 4695 4696 return (lpResult); /* deliver return code */ 4697 } 4698 4699 /***************************************************************************** 4700 * Name : HMGetNamedPipeInfo 4701 * Purpose : 4702 * Parameters: 4703 * Variables : 4704 * Result : 4705 * Remark : 4706 * Status : 4707 * 4708 * Author : Przemyslaw Dobrowolski 4709 *****************************************************************************/ 4710 BOOL HMGetNamedPipeInfo(HANDLE hPipe, 4711 LPDWORD lpFlags, 4712 LPDWORD lpOutBufferSize, 4713 LPDWORD lpInBufferSize, 4714 LPDWORD lpMaxInstances) 4715 { 4716 int iIndex; /* index into the handle table */ 4717 BOOL lpResult; /* result from the device handler's API */ 4718 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4719 4720 SetLastError(ERROR_SUCCESS); 4721 /* validate handle */ 4722 iIndex = _HMHandleQuery(hPipe); /* get the index */ 4723 if (-1 == iIndex) /* error ? */ 4724 { 4725 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4726 return FALSE; /* signal failure */ 4727 } 4728 4729 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4730 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeInfo(&TabWin32Handles[iIndex].hmHandleData, 4731 lpFlags, 4732 lpOutBufferSize, 4733 lpInBufferSize, 4734 lpMaxInstances); 4735 4736 return (lpResult); /* deliver return code */ 4737 } 4738 4739 /***************************************************************************** 4740 * Name : HMTransactNamedPipe 4741 * Purpose : 4742 * Parameters: 4743 * Variables : 4744 * Result : 4745 * Remark : 4746 * Status : 4747 * 4748 * Author : Przemyslaw Dobrowolski 4749 *****************************************************************************/ 4750 BOOL HMTransactNamedPipe(HANDLE hPipe, 4751 LPVOID lpvWriteBuf, 4752 DWORD cbWriteBuf, 4753 LPVOID lpvReadBuf, 4754 DWORD cbReadBuf, 4755 LPDWORD lpcbRead, 4756 LPOVERLAPPED lpo) 4757 { 4758 int iIndex; /* index into the handle table */ 4759 BOOL lpResult; /* result from the device handler's API */ 4760 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4761 4762 SetLastError(ERROR_SUCCESS); 4763 /* validate handle */ 4764 iIndex = _HMHandleQuery(hPipe); /* get the index */ 4765 if (-1 == iIndex) /* error ? */ 4766 { 4767 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4768 return FALSE; /* signal failure */ 4769 } 4770 4771 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4772 lpResult = pHMHandle->pDeviceHandler->TransactNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 4773 lpvWriteBuf, 4774 cbWriteBuf, 4775 lpvReadBuf, 4776 cbReadBuf, 4777 lpcbRead, 4778 lpo); 4779 4780 return (lpResult); /* deliver return code */ 4781 } 4782 4783 /***************************************************************************** 4784 * Name : HMSetNamedPipeHandleState 4785 * Purpose : 4786 * Parameters: 4787 * Variables : 4788 * Result : 4789 * Remark : 4790 * Status : 4791 * 4792 * Author : Przemyslaw Dobrowolski 4793 *****************************************************************************/ 4794 BOOL HMSetNamedPipeHandleState(HANDLE hPipe, 4795 LPDWORD lpdwMode, 4796 LPDWORD lpcbMaxCollect, 4797 LPDWORD lpdwCollectDataTimeout) 4798 { 4799 int iIndex; /* index into the handle table */ 4800 BOOL lpResult; /* result from the device handler's API */ 4801 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4802 4803 SetLastError(ERROR_SUCCESS); 4804 /* validate handle */ 4805 iIndex = _HMHandleQuery(hPipe); /* get the index */ 4806 if (-1 == iIndex) /* error ? */ 4807 { 4808 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4809 return FALSE; /* signal failure */ 4810 } 4811 4812 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4813 lpResult = pHMHandle->pDeviceHandler->SetNamedPipeHandleState(&TabWin32Handles[iIndex].hmHandleData, 4814 lpdwMode, 4815 lpcbMaxCollect, 4816 lpdwCollectDataTimeout); 4817 4818 return (lpResult); /* deliver return code */ 4819 } 4820 4821 /***************************************************************************** 4822 * Name : HMCreateMailslotA 4823 * Purpose : 4824 * Parameters: 4825 * Variables : 4826 * Result : 4827 * Remark : 4828 * Status : 4829 * 4830 * Author : SvL 4831 *****************************************************************************/ 4832 HANDLE HMCreateMailslotA(LPCSTR lpName, DWORD nMaxMessageSize, 4833 DWORD lReadTimeout, 4834 LPSECURITY_ATTRIBUTES lpSecurityAttributes) 4835 { 4836 int iIndex; /* index into the handle table */ 4837 int iIndexNew; /* index into the handle table */ 4838 HMMailslotClass *pDeviceHandler; /* device handler for this handle */ 4839 PHMHANDLEDATA pHMHandleData; 4840 BOOL rc; /* API return code */ 4841 4842 SetLastError(ERROR_SUCCESS); 4843 4844 pDeviceHandler = (HMMailslotClass *)HMGlobals.pHMMailslot; /* device is predefined */ 4845 4846 iIndexNew = _HMHandleGetFree(); /* get free handle */ 4847 if (-1 == iIndexNew) /* oops, no free handles ! */ 4848 { 4849 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 4850 return 0; 4851 } 4852 4853 /* initialize the complete HMHANDLEDATA structure */ 4854 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 4855 pHMHandleData->dwAccess = 0; 4856 pHMHandleData->dwShare = 0; 4857 pHMHandleData->dwCreation = 0; 4858 pHMHandleData->dwFlags = 0; 4859 pHMHandleData->lpHandlerData = NULL; 4860 4861 /* we've got to mark the handle as occupied here, since another device */ 4862 /* could be created within the device handler -> deadlock */ 4863 4864 /* write appropriate entry into the handle table if open succeeded */ 4865 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 4866 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 4867 4868 /* call the device handler */ 4869 4870 rc = pDeviceHandler->CreateMailslotA(&TabWin32Handles[iIndexNew].hmHandleData, 4871 lpName, nMaxMessageSize, 4872 lReadTimeout, lpSecurityAttributes); 4873 4874 if (rc == FALSE) /* oops, creation failed within the device handler */ 4875 { 4876 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 4877 return 0; /* signal error */ 4878 } 4879 4880 return iIndexNew; 4881 } 4882 /***************************************************************************** 4883 * Name : HMGetMailslotInfo 4884 * Purpose : 4885 * Parameters: 4886 * Variables : 4887 * Result : 4888 * Remark : 4889 * Status : 4890 * 4891 * Author : SvL 4892 *****************************************************************************/ 4893 BOOL HMGetMailslotInfo(HANDLE hMailslot, 4894 LPDWORD lpMaxMessageSize, 4895 LPDWORD lpNextSize, 4896 LPDWORD lpMessageCount, 4897 LPDWORD lpReadTimeout) 4898 { 4899 int iIndex; /* index into the handle table */ 4900 BOOL lpResult; /* result from the device handler's API */ 4901 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4902 4903 SetLastError(ERROR_SUCCESS); 4904 /* validate handle */ 4905 iIndex = _HMHandleQuery(hMailslot); /* get the index */ 4906 if (-1 == iIndex) /* error ? */ 4907 { 4908 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4909 return FALSE; /* signal failure */ 4910 } 4911 4912 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4913 lpResult = pHMHandle->pDeviceHandler->GetMailslotInfo(&TabWin32Handles[iIndex].hmHandleData, 4914 lpMaxMessageSize, 4915 lpNextSize, 4916 lpMessageCount, 4917 lpReadTimeout); 4918 return (lpResult); /* deliver return code */ 4919 } 4920 /***************************************************************************** 4921 * Name : HMSetMailslotInfo 4922 * Purpose : 4923 * Parameters: 4924 * Variables : 4925 * Result : 4926 * Remark : 4927 * Status : 4928 * 4929 * Author : SvL 4930 *****************************************************************************/ 4931 BOOL HMSetMailslotInfo(HANDLE hMailslot, 4932 DWORD dwReadTimeout) 4933 { 4934 int iIndex; /* index into the handle table */ 4935 BOOL lpResult; /* result from the device handler's API */ 4936 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 4937 4938 SetLastError(ERROR_SUCCESS); 4939 /* validate handle */ 4940 iIndex = _HMHandleQuery(hMailslot); /* get the index */ 4941 if (-1 == iIndex) /* error ? */ 4942 { 4943 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 4944 return FALSE; /* signal failure */ 4945 } 4946 4947 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 4948 lpResult = pHMHandle->pDeviceHandler->SetMailslotInfo(&TabWin32Handles[iIndex].hmHandleData, 4949 dwReadTimeout); 4950 4951 return (lpResult); /* deliver return code */ 4952 } 3485 3486 3487 /** 3488 * Gets the type of an object. 3489 * 3490 * @returns the value of one of the HMMTYPE_ defines. 3491 * @returns HMTYPE_BAD_HANDLE if hObject isn't a valid handle. 3492 * @param hObject Handle to object. 3493 */ 3494 unsigned WIN32API HMQueryObjectType(HANDLE hObject) 3495 { 3496 PHMHANDLEDATA pData = HMQueryHandleData(hObject); 3497 if (pData) 3498 return (unsigned)pData->dwInternalType; 3499 return HMTYPE_BAD_HANDLE; 3500 } 3501
Note:
See TracChangeset
for help on using the changeset viewer.