Changeset 278 for trunk/src/kernel32/HandleManager.cpp
- Timestamp:
- Jul 6, 1999, 5:48:48 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r271 r278 1 /* $Id: HandleManager.cpp,v 1. 5 1999-07-05 09:58:14phaller Exp $ */1 /* $Id: HandleManager.cpp,v 1.6 1999-07-06 15:48:45 phaller Exp $ */ 2 2 3 3 /* … … 52 52 #include "HMDevice.h" 53 53 #include "HMOpen32.h" 54 #include "HMEvent.h" 55 #include "HMMutex.h" 56 #include "HMSemaphore.h" 54 57 55 58 … … 59 62 60 63 /* this is the size of our currently static handle table */ 61 #define MAX_OS2_HMHANDLES 102464 #define MAX_OS2_HMHANDLES 2048 62 65 63 66 … … 83 86 84 87 85 typedef struct _HMTRANSHANDLE86 {87 /* @@@PH88 UCHAR ucSubsystemID; to determine "lost" handles89 */90 /* the index position in the array is the 16bit windows part of the handle */91 ULONG hHandle32; /* 32-bit OS/2 part of the handle */92 } HMTRANSHANDLE, *PHMTRANSHANDLE;93 94 95 88 /***************************************************************************** 96 89 * This pseudo-device logs all device requests to the logfile and returns * … … 123 116 /* this MUST !!! be false initially */ 124 117 125 HMDeviceHandler *pHMOpen32; /* default handle manager instance */ 118 HMDeviceHandler *pHMOpen32; /* default handle manager instance */ 119 HMDeviceHandler *pHMEvent; /* static instances of subsystems */ 120 HMDeviceHandler *pHMMutex; 121 HMDeviceHandler *pHMSemaphore; 126 122 127 123 ULONG ulHandleLast; /* index of last used handle */ … … 312 308 313 309 /* create handle manager instance for Open32 handles */ 314 HMGlobals.pHMOpen32 = new HMDeviceOpen32Class("\\\\.\\"); 310 HMGlobals.pHMOpen32 = new HMDeviceOpen32Class("\\\\.\\"); 311 HMGlobals.pHMEvent = new HMDeviceEventClass("\\\\EVENT\\"); 312 HMGlobals.pHMMutex = new HMDeviceMutexClass("\\\\MUTEX\\"); 313 HMGlobals.pHMSemaphore = new HMDeviceSemaphoreClass("\\\\SEM\\"); 315 314 } 316 315 return (NO_ERROR); … … 333 332 { 334 333 /* @@@PH we could deallocate the device list here */ 334 335 delete HMGlobals.pHMOpen32; 336 delete HMGlobals.pHMEvent; 337 delete HMGlobals.pHMMutex; 338 delete HMGlobals.pHMSemaphore; 335 339 336 340 return (NO_ERROR); … … 357 361 * Remark : no parameter checking is done, phHandle may not be invalid 358 362 * hHandle32 shouldn't be 0 363 * Should be protected with a HM-Mutex ! 359 364 * Status : 360 365 * … … 546 551 *****************************************************************************/ 547 552 548 DWORD 553 DWORD HMHandleTranslateToOS2i (ULONG hHandle16) 549 554 { 550 555 #ifdef DEBUG_LOCAL … … 922 927 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 923 928 *****************************************************************************/ 929 924 930 BOOL HMReadFile(HANDLE hFile, 925 931 LPVOID lpBuffer, … … 1038 1044 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 1039 1045 *****************************************************************************/ 1046 1040 1047 DWORD HMDeviceRequest (HANDLE hFile, 1041 1048 ULONG ulRequestCode, … … 1080 1087 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1081 1088 *****************************************************************************/ 1082 DWORD HMGetFileInformationByHandle (HANDLE hFile, 1083 BY_HANDLE_FILE_INFORMATION *pHFI) 1089 1090 BOOL HMGetFileInformationByHandle (HANDLE hFile, 1091 BY_HANDLE_FILE_INFORMATION *pHFI) 1084 1092 { 1085 1093 int iIndex; /* index into the handle table */ … … 1103 1111 1104 1112 1105 1106 1113 /***************************************************************************** 1107 1114 * Name : HMDeviceHandler::SetEndOfFile … … 1115 1122 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1116 1123 *****************************************************************************/ 1124 1117 1125 BOOL HMSetEndOfFile (HANDLE hFile) 1118 1126 { … … 1147 1155 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1148 1156 *****************************************************************************/ 1157 1149 1158 BOOL HMSetFileTime (HANDLE hFile, 1150 1159 const FILETIME *pFT1, … … 1185 1194 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1186 1195 *****************************************************************************/ 1196 1187 1197 DWORD HMGetFileSize (HANDLE hFile, 1188 1198 PDWORD pSize) … … 1219 1229 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1220 1230 *****************************************************************************/ 1231 1221 1232 DWORD HMSetFilePointer (HANDLE hFile, 1222 1233 LONG lDistanceToMove, … … 1257 1268 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1258 1269 *****************************************************************************/ 1270 1259 1271 BOOL HMLockFile (HFILE hFile, 1260 1272 DWORD arg2, … … 1297 1309 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1298 1310 *****************************************************************************/ 1299 DWORD HMLockFileEx(HANDLE hFile, 1300 DWORD dwFlags, 1301 DWORD dwReserved, 1302 DWORD nNumberOfBytesToLockLow, 1303 DWORD nNumberOfBytesToLockHigh, 1304 LPOVERLAPPED lpOverlapped) 1311 1312 BOOL HMLockFileEx(HANDLE hFile, 1313 DWORD dwFlags, 1314 DWORD dwReserved, 1315 DWORD nNumberOfBytesToLockLow, 1316 DWORD nNumberOfBytesToLockHigh, 1317 LPOVERLAPPED lpOverlapped) 1305 1318 { 1306 1319 int iIndex; /* index into the handle table */ … … 1340 1353 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1341 1354 *****************************************************************************/ 1355 1342 1356 BOOL HMUnlockFile (HFILE hFile, 1343 1357 DWORD arg2, … … 1368 1382 } 1369 1383 1384 1370 1385 /***************************************************************************** 1371 1386 * Name : HMDeviceHandler::UnlockFileEx … … 1379 1394 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1380 1395 *****************************************************************************/ 1396 1381 1397 BOOL HMUnlockFileEx(HANDLE hFile, 1382 1398 DWORD dwFlags, … … 1409 1425 } 1410 1426 1427 1428 /***************************************************************************** 1429 * Name : HMDeviceHandler::WaitForSingleObject 1430 * Purpose : router function for WaitForSingleObject 1431 * Parameters: 1432 * Variables : 1433 * Result : 1434 * Remark : 1435 * Status : 1436 * 1437 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1438 *****************************************************************************/ 1439 1440 DWORD HMWaitForSingleObject(HANDLE hObject, 1441 DWORD dwTimeout) 1442 { 1443 int iIndex; /* index into the handle table */ 1444 DWORD dwResult; /* result from the device handler's API */ 1445 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1446 1447 /* validate handle */ 1448 iIndex = _HMHandleQuery(hObject); /* get the index */ 1449 if (-1 == iIndex) /* error ? */ 1450 { 1451 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 1452 return (INVALID_HANDLE_ERROR); /* signal failure */ 1453 } 1454 1455 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1456 dwResult = pHMHandle->pDeviceHandler->WaitForSingleObject(&pHMHandle->hmHandleData, 1457 dwTimeout); 1458 1459 return (dwResult); /* deliver return code */ 1460 } 1461 1462 1463 /***************************************************************************** 1464 * Name : HMDeviceHandler::WaitForSingleObjectEx 1465 * Purpose : router function for WaitForSingleObjectEx 1466 * Parameters: 1467 * Variables : 1468 * Result : 1469 * Remark : 1470 * Status : 1471 * 1472 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1473 *****************************************************************************/ 1474 1475 DWORD HMWaitForSingleObjectEx(HANDLE hObject, 1476 DWORD dwTimeout, 1477 BOOL fAlertable) 1478 { 1479 int iIndex; /* index into the handle table */ 1480 DWORD dwResult; /* result from the device handler's API */ 1481 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1482 1483 /* validate handle */ 1484 iIndex = _HMHandleQuery(hObject); /* get the index */ 1485 if (-1 == iIndex) /* error ? */ 1486 { 1487 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 1488 return (INVALID_HANDLE_ERROR); /* signal failure */ 1489 } 1490 1491 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1492 dwResult = pHMHandle->pDeviceHandler->WaitForSingleObjectEx(&pHMHandle->hmHandleData, 1493 dwTimeout, 1494 fAlertable); 1495 1496 return (dwResult); /* deliver return code */ 1497 } 1498 1499 1500 /***************************************************************************** 1501 * Name : HMDeviceHandler::FlushFileBuffers 1502 * Purpose : router function for FlushFileBuffers 1503 * Parameters: 1504 * Variables : 1505 * Result : 1506 * Remark : 1507 * Status : 1508 * 1509 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1510 *****************************************************************************/ 1511 1512 BOOL HMFlushFileBuffers(HANDLE hFile) 1513 { 1514 int iIndex; /* index into the handle table */ 1515 DWORD dwResult; /* result from the device handler's API */ 1516 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1517 1518 /* validate handle */ 1519 iIndex = _HMHandleQuery(hFile); /* get the index */ 1520 if (-1 == iIndex) /* error ? */ 1521 { 1522 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 1523 return (INVALID_HANDLE_ERROR); /* signal failure */ 1524 } 1525 1526 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1527 dwResult = pHMHandle->pDeviceHandler->FlushFileBuffers(&pHMHandle->hmHandleData); 1528 1529 return (dwResult); /* deliver return code */ 1530 } 1531 1532 1533 /***************************************************************************** 1534 * Name : HMDeviceHandler::GetOverlappedResult 1535 * Purpose : router function for GetOverlappedResult 1536 * Parameters: 1537 * Variables : 1538 * Result : 1539 * Remark : 1540 * Status : 1541 * 1542 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1543 *****************************************************************************/ 1544 1545 BOOL HMGetOverlappedResult(HANDLE hObject, 1546 LPOVERLAPPED lpOverlapped, 1547 LPDWORD arg3, 1548 BOOL arg4) 1549 { 1550 int iIndex; /* index into the handle table */ 1551 DWORD dwResult; /* result from the device handler's API */ 1552 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1553 1554 /* validate handle */ 1555 iIndex = _HMHandleQuery(hObject); /* get the index */ 1556 if (-1 == iIndex) /* error ? */ 1557 { 1558 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 1559 return (INVALID_HANDLE_ERROR); /* signal failure */ 1560 } 1561 1562 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1563 dwResult = pHMHandle->pDeviceHandler->GetOverlappedResult(&pHMHandle->hmHandleData, 1564 lpOverlapped, 1565 arg3, 1566 arg4); 1567 1568 return (dwResult); /* deliver return code */ 1569 } 1570 1571 1572 /***************************************************************************** 1573 * Name : HMReleaseMutex 1574 * Purpose : router function for ReleaseMutex 1575 * Parameters: 1576 * Variables : 1577 * Result : 1578 * Remark : 1579 * Status : 1580 * 1581 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1582 *****************************************************************************/ 1583 1584 BOOL HMReleaseMutex(HANDLE hObject) 1585 { 1586 int iIndex; /* index into the handle table */ 1587 DWORD dwResult; /* result from the device handler's API */ 1588 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1589 1590 /* validate handle */ 1591 iIndex = _HMHandleQuery(hObject); /* get the index */ 1592 if (-1 == iIndex) /* error ? */ 1593 { 1594 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 1595 return (INVALID_HANDLE_ERROR); /* signal failure */ 1596 } 1597 1598 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1599 dwResult = pHMHandle->pDeviceHandler->ReleaseMutex(&pHMHandle->hmHandleData); 1600 1601 return (dwResult); /* deliver return code */ 1602 } 1603 1604 1605 /***************************************************************************** 1606 * Name : HMSetEvent 1607 * Purpose : router function for SetEvent 1608 * Parameters: 1609 * Variables : 1610 * Result : 1611 * Remark : 1612 * Status : 1613 * 1614 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1615 *****************************************************************************/ 1616 1617 BOOL HMSetEvent(HANDLE hEvent) 1618 { 1619 int iIndex; /* index into the handle table */ 1620 DWORD dwResult; /* result from the device handler's API */ 1621 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1622 1623 /* validate handle */ 1624 iIndex = _HMHandleQuery(hEvent); /* get the index */ 1625 if (-1 == iIndex) /* error ? */ 1626 { 1627 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 1628 return (INVALID_HANDLE_ERROR); /* signal failure */ 1629 } 1630 1631 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1632 dwResult = pHMHandle->pDeviceHandler->SetEvent(&pHMHandle->hmHandleData); 1633 1634 return (dwResult); /* deliver return code */ 1635 } 1636 1637 1638 /***************************************************************************** 1639 * Name : HMPulseEvent 1640 * Purpose : router function for PulseEvent 1641 * Parameters: 1642 * Variables : 1643 * Result : 1644 * Remark : 1645 * Status : 1646 * 1647 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1648 *****************************************************************************/ 1649 1650 BOOL HMPulseEvent(HANDLE hEvent) 1651 { 1652 int iIndex; /* index into the handle table */ 1653 DWORD dwResult; /* result from the device handler's API */ 1654 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1655 1656 /* validate handle */ 1657 iIndex = _HMHandleQuery(hEvent); /* get the index */ 1658 if (-1 == iIndex) /* error ? */ 1659 { 1660 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 1661 return (INVALID_HANDLE_ERROR); /* signal failure */ 1662 } 1663 1664 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1665 dwResult = pHMHandle->pDeviceHandler->PulseEvent(&pHMHandle->hmHandleData); 1666 1667 return (dwResult); /* deliver return code */ 1668 } 1669 1670 1671 /***************************************************************************** 1672 * Name : HMResetEvent 1673 * Purpose : router function for ResetEvent 1674 * Parameters: 1675 * Variables : 1676 * Result : 1677 * Remark : 1678 * Status : 1679 * 1680 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 1681 *****************************************************************************/ 1682 1683 BOOL HMResetEvent(HANDLE hEvent) 1684 { 1685 int iIndex; /* index into the handle table */ 1686 DWORD dwResult; /* result from the device handler's API */ 1687 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1688 1689 /* validate handle */ 1690 iIndex = _HMHandleQuery(hEvent); /* get the index */ 1691 if (-1 == iIndex) /* error ? */ 1692 { 1693 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 1694 return (INVALID_HANDLE_ERROR); /* signal failure */ 1695 } 1696 1697 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 1698 dwResult = pHMHandle->pDeviceHandler->ResetEvent(&pHMHandle->hmHandleData); 1699 1700 return (dwResult); /* deliver return code */ 1701 } 1702 1703 1704 /***************************************************************************** 1705 * Name : HANDLE HMCreateEvent 1706 * Purpose : Wrapper for the CreateEvent() API 1707 * Parameters: 1708 * Variables : 1709 * Result : 1710 * Remark : 1711 * Status : 1712 * 1713 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 1714 *****************************************************************************/ 1715 1716 HANDLE HMCreateEvent(LPSECURITY_ATTRIBUTES lpsa, 1717 BOOL bManualReset, 1718 BOOL bInitialState, 1719 LPCTSTR lpName) 1720 { 1721 int iIndex; /* index into the handle table */ 1722 int iIndexNew; /* index into the handle table */ 1723 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 1724 PHMHANDLEDATA pHMHandleData; 1725 DWORD rc; /* API return code */ 1726 1727 1728 pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */ 1729 1730 iIndexNew = _HMHandleGetFree(); /* get free handle */ 1731 if (-1 == iIndexNew) /* oops, no free handles ! */ 1732 { 1733 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 1734 return (INVALID_HANDLE_VALUE); /* signal error */ 1735 } 1736 1737 1738 /* initialize the complete HMHANDLEDATA structure */ 1739 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 1740 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */ 1741 pHMHandleData->dwAccess = 0; 1742 pHMHandleData->dwShare = 0; 1743 pHMHandleData->dwCreation = 0; 1744 pHMHandleData->dwFlags = 0; 1745 pHMHandleData->lpHandlerData = NULL; 1746 1747 1748 /* we've got to mark the handle as occupied here, since another device */ 1749 /* could be created within the device handler -> deadlock */ 1750 1751 /* write appropriate entry into the handle table if open succeeded */ 1752 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 1753 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 1754 1755 /* call the device handler */ 1756 rc = pDeviceHandler->CreateEvent(&TabWin32Handles[iIndexNew].hmHandleData, 1757 lpsa, 1758 bManualReset, 1759 bInitialState, 1760 lpName); 1761 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 1762 { 1763 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1764 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 1765 return (INVALID_HANDLE_VALUE); /* signal error */ 1766 } 1767 1768 return iIndexNew; /* return valid handle */ 1769 } 1770 1771 1772 /***************************************************************************** 1773 * Name : HANDLE HMCreateMutex 1774 * Purpose : Wrapper for the CreateMutex() API 1775 * Parameters: 1776 * Variables : 1777 * Result : 1778 * Remark : 1779 * Status : 1780 * 1781 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 1782 *****************************************************************************/ 1783 1784 HANDLE HMCreateMutex(LPSECURITY_ATTRIBUTES lpsa, 1785 BOOL bInitialOwner, 1786 LPCTSTR lpName) 1787 { 1788 int iIndex; /* index into the handle table */ 1789 int iIndexNew; /* index into the handle table */ 1790 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 1791 PHMHANDLEDATA pHMHandleData; 1792 DWORD rc; /* API return code */ 1793 1794 1795 pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */ 1796 1797 iIndexNew = _HMHandleGetFree(); /* get free handle */ 1798 if (-1 == iIndexNew) /* oops, no free handles ! */ 1799 { 1800 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 1801 return (INVALID_HANDLE_VALUE); /* signal error */ 1802 } 1803 1804 1805 /* initialize the complete HMHANDLEDATA structure */ 1806 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 1807 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */ 1808 pHMHandleData->dwAccess = 0; 1809 pHMHandleData->dwShare = 0; 1810 pHMHandleData->dwCreation = 0; 1811 pHMHandleData->dwFlags = 0; 1812 pHMHandleData->lpHandlerData = NULL; 1813 1814 1815 /* we've got to mark the handle as occupied here, since another device */ 1816 /* could be created within the device handler -> deadlock */ 1817 1818 /* write appropriate entry into the handle table if open succeeded */ 1819 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 1820 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 1821 1822 /* call the device handler */ 1823 rc = pDeviceHandler->CreateMutex(&TabWin32Handles[iIndexNew].hmHandleData, 1824 lpsa, 1825 bInitialOwner, 1826 lpName); 1827 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 1828 { 1829 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1830 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 1831 return (INVALID_HANDLE_VALUE); /* signal error */ 1832 } 1833 1834 return iIndexNew; /* return valid handle */ 1835 } 1836 1837 1838 /***************************************************************************** 1839 * Name : HANDLE HMOpenEvent 1840 * Purpose : Wrapper for the OpenEvent() API 1841 * Parameters: 1842 * Variables : 1843 * Result : 1844 * Remark : 1845 * Status : 1846 * 1847 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 1848 *****************************************************************************/ 1849 1850 HANDLE HMOpenEvent(DWORD fdwAccess, 1851 BOOL fInherit, 1852 LPCTSTR lpName) 1853 { 1854 int iIndex; /* index into the handle table */ 1855 int iIndexNew; /* index into the handle table */ 1856 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 1857 PHMHANDLEDATA pHMHandleData; 1858 DWORD rc; /* API return code */ 1859 1860 1861 pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */ 1862 1863 iIndexNew = _HMHandleGetFree(); /* get free handle */ 1864 if (-1 == iIndexNew) /* oops, no free handles ! */ 1865 { 1866 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 1867 return (INVALID_HANDLE_VALUE); /* signal error */ 1868 } 1869 1870 1871 /* initialize the complete HMHANDLEDATA structure */ 1872 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 1873 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */ 1874 pHMHandleData->dwAccess = fdwAccess; 1875 pHMHandleData->dwShare = 0; 1876 pHMHandleData->dwCreation = 0; 1877 pHMHandleData->dwFlags = 0; 1878 pHMHandleData->lpHandlerData = NULL; 1879 1880 1881 /* we've got to mark the handle as occupied here, since another device */ 1882 /* could be created within the device handler -> deadlock */ 1883 1884 /* write appropriate entry into the handle table if open succeeded */ 1885 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 1886 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 1887 1888 /* call the device handler */ 1889 rc = pDeviceHandler->OpenEvent(&TabWin32Handles[iIndexNew].hmHandleData, 1890 fInherit, 1891 lpName); 1892 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 1893 { 1894 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1895 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 1896 return (INVALID_HANDLE_VALUE); /* signal error */ 1897 } 1898 1899 return iIndexNew; /* return valid handle */ 1900 } 1901 1902 1903 /***************************************************************************** 1904 * Name : HANDLE HMOpenMutex 1905 * Purpose : Wrapper for the OpenMutex() API 1906 * Parameters: 1907 * Variables : 1908 * Result : 1909 * Remark : 1910 * Status : 1911 * 1912 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 1913 *****************************************************************************/ 1914 1915 HANDLE HMOpenMutex(DWORD fdwAccess, 1916 BOOL fInherit, 1917 LPCTSTR lpName) 1918 { 1919 int iIndex; /* index into the handle table */ 1920 int iIndexNew; /* index into the handle table */ 1921 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 1922 PHMHANDLEDATA pHMHandleData; 1923 DWORD rc; /* API return code */ 1924 1925 1926 pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */ 1927 1928 iIndexNew = _HMHandleGetFree(); /* get free handle */ 1929 if (-1 == iIndexNew) /* oops, no free handles ! */ 1930 { 1931 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 1932 return (INVALID_HANDLE_VALUE); /* signal error */ 1933 } 1934 1935 1936 /* initialize the complete HMHANDLEDATA structure */ 1937 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 1938 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */ 1939 pHMHandleData->dwAccess = fdwAccess; 1940 pHMHandleData->dwShare = 0; 1941 pHMHandleData->dwCreation = 0; 1942 pHMHandleData->dwFlags = 0; 1943 pHMHandleData->lpHandlerData = NULL; 1944 1945 1946 /* we've got to mark the handle as occupied here, since another device */ 1947 /* could be created within the device handler -> deadlock */ 1948 1949 /* write appropriate entry into the handle table if open succeeded */ 1950 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 1951 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 1952 1953 /* call the device handler */ 1954 rc = pDeviceHandler->OpenMutex(&TabWin32Handles[iIndexNew].hmHandleData, 1955 fInherit, 1956 lpName); 1957 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 1958 { 1959 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1960 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 1961 return (INVALID_HANDLE_VALUE); /* signal error */ 1962 } 1963 1964 return iIndexNew; /* return valid handle */ 1965 } 1966 1967 1968 /***************************************************************************** 1969 * Name : HANDLE HMCreateSemaphore 1970 * Purpose : Wrapper for the CreateSemaphore() API 1971 * Parameters: 1972 * Variables : 1973 * Result : 1974 * Remark : 1975 * Status : 1976 * 1977 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 1978 *****************************************************************************/ 1979 1980 HANDLE HMCreateSemaphore(LPSECURITY_ATTRIBUTES lpsa, 1981 LONG lInitialCount, 1982 LONG lMaximumCount, 1983 LPCTSTR lpName) 1984 { 1985 int iIndex; /* index into the handle table */ 1986 int iIndexNew; /* index into the handle table */ 1987 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 1988 PHMHANDLEDATA pHMHandleData; 1989 DWORD rc; /* API return code */ 1990 1991 1992 pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */ 1993 1994 iIndexNew = _HMHandleGetFree(); /* get free handle */ 1995 if (-1 == iIndexNew) /* oops, no free handles ! */ 1996 { 1997 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 1998 return (INVALID_HANDLE_VALUE); /* signal error */ 1999 } 2000 2001 2002 /* initialize the complete HMHANDLEDATA structure */ 2003 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 2004 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */ 2005 pHMHandleData->dwAccess = 0; 2006 pHMHandleData->dwShare = 0; 2007 pHMHandleData->dwCreation = 0; 2008 pHMHandleData->dwFlags = 0; 2009 pHMHandleData->lpHandlerData = NULL; 2010 2011 2012 /* we've got to mark the handle as occupied here, since another device */ 2013 /* could be created within the device handler -> deadlock */ 2014 2015 /* write appropriate entry into the handle table if open succeeded */ 2016 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2017 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 2018 2019 /* call the device handler */ 2020 rc = pDeviceHandler->CreateSemaphore(&TabWin32Handles[iIndexNew].hmHandleData, 2021 lpsa, 2022 lInitialCount, 2023 lMaximumCount, 2024 lpName); 2025 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2026 { 2027 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2028 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2029 return (INVALID_HANDLE_VALUE); /* signal error */ 2030 } 2031 2032 return iIndexNew; /* return valid handle */ 2033 } 2034 2035 2036 /***************************************************************************** 2037 * Name : HANDLE HMOpenSemaphore 2038 * Purpose : Wrapper for the OpenSemaphore() API 2039 * Parameters: 2040 * Variables : 2041 * Result : 2042 * Remark : 2043 * Status : 2044 * 2045 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 2046 *****************************************************************************/ 2047 2048 HANDLE HMOpenSemaphore(DWORD fdwAccess, 2049 BOOL fInherit, 2050 LPCTSTR lpName) 2051 { 2052 int iIndex; /* index into the handle table */ 2053 int iIndexNew; /* index into the handle table */ 2054 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 2055 PHMHANDLEDATA pHMHandleData; 2056 DWORD rc; /* API return code */ 2057 2058 2059 pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */ 2060 2061 iIndexNew = _HMHandleGetFree(); /* get free handle */ 2062 if (-1 == iIndexNew) /* oops, no free handles ! */ 2063 { 2064 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 2065 return (INVALID_HANDLE_VALUE); /* signal error */ 2066 } 2067 2068 2069 /* initialize the complete HMHANDLEDATA structure */ 2070 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 2071 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */ 2072 pHMHandleData->dwAccess = fdwAccess; 2073 pHMHandleData->dwShare = 0; 2074 pHMHandleData->dwCreation = 0; 2075 pHMHandleData->dwFlags = 0; 2076 pHMHandleData->lpHandlerData = NULL; 2077 2078 2079 /* we've got to mark the handle as occupied here, since another device */ 2080 /* could be created within the device handler -> deadlock */ 2081 2082 /* write appropriate entry into the handle table if open succeeded */ 2083 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2084 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 2085 2086 /* call the device handler */ 2087 rc = pDeviceHandler->OpenSemaphore(&TabWin32Handles[iIndexNew].hmHandleData, 2088 fInherit, 2089 lpName); 2090 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2091 { 2092 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2093 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2094 return (INVALID_HANDLE_VALUE); /* signal error */ 2095 } 2096 2097 return iIndexNew; /* return valid handle */ 2098 } 2099 2100 2101 /***************************************************************************** 2102 * Name : HMReleaseSemaphore 2103 * Purpose : router function for ReleaseSemaphore 2104 * Parameters: 2105 * Variables : 2106 * Result : 2107 * Remark : 2108 * Status : 2109 * 2110 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 2111 *****************************************************************************/ 2112 2113 BOOL HMReleaseSemaphore(HANDLE hEvent, 2114 LONG cReleaseCount, 2115 LPLONG lpPreviousCount) 2116 { 2117 int iIndex; /* index into the handle table */ 2118 DWORD dwResult; /* result from the device handler's API */ 2119 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 2120 2121 /* validate handle */ 2122 iIndex = _HMHandleQuery(hEvent); /* get the index */ 2123 if (-1 == iIndex) /* error ? */ 2124 { 2125 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 2126 return (INVALID_HANDLE_ERROR); /* signal failure */ 2127 } 2128 2129 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 2130 dwResult = pHMHandle->pDeviceHandler->ReleaseSemaphore(&pHMHandle->hmHandleData, 2131 cReleaseCount, 2132 lpPreviousCount); 2133 2134 return (dwResult); /* deliver return code */ 2135 } 2136 2137 2138 /***************************************************************************** 2139 * Name : HMWaitForMultipleObjects 2140 * Purpose : router function for WaitForMultipleObjects 2141 * Parameters: 2142 * Variables : 2143 * Result : 2144 * Remark : 2145 * Status : 2146 * 2147 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 2148 *****************************************************************************/ 2149 2150 DWORD HMWaitForMultipleObjects (DWORD cObjects, 2151 PHANDLE lphObjects, 2152 BOOL fWaitAll, 2153 DWORD dwTimeout) 2154 { 2155 ULONG ulIndex; 2156 PHANDLE pArrayOfHandles; 2157 PHANDLE pLoop1 = lphObjects; 2158 PHANDLE pLoop2; 2159 DWORD rc; 2160 2161 // allocate array for handle table 2162 pArrayOfHandles = (PHANDLE)malloc(cObjects * sizeof(HANDLE)); 2163 if (pArrayOfHandles == NULL) 2164 { 2165 O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY); 2166 return WAIT_FAILED; 2167 } 2168 else 2169 pLoop2 = pArrayOfHandles; 2170 2171 // convert array to odin handles 2172 for (ulIndex = 0; 2173 2174 ulIndex < cObjects; 2175 2176 ulIndex++, 2177 pLoop1++, 2178 pLoop2++) 2179 { 2180 rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle 2181 pLoop2); 2182 2183 if (rc != NO_ERROR) 2184 { 2185 free (pArrayOfHandles); // free memory 2186 O32_SetLastError(ERROR_INVALID_HANDLE); 2187 return (WAIT_FAILED); 2188 } 2189 } 2190 2191 // OK, now forward to Open32. 2192 // @@@PH: Note this will fail on handles that do NOT belong to Open32 2193 // but to i.e. the console subsystem! 2194 rc = O32_WaitForMultipleObjects(cObjects, 2195 pArrayOfHandles, 2196 fWaitAll, 2197 dwTimeout); 2198 2199 free(pArrayOfHandles); // free memory 2200 return (rc); // OK, done 2201 } 2202 2203 2204 /***************************************************************************** 2205 * Name : HMWaitForMultipleObjectsEx 2206 * Purpose : router function for WaitForMultipleObjectsEx 2207 * Parameters: 2208 * Variables : 2209 * Result : 2210 * Remark : 2211 * Status : 2212 * 2213 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 2214 *****************************************************************************/ 2215 2216 DWORD HMWaitForMultipleObjectsEx (DWORD cObjects, 2217 PHANDLE lphObjects, 2218 BOOL fWaitAll, 2219 DWORD dwTimeout, 2220 BOOL fAlertable) 2221 { 2222 // @@@PH: Note: fAlertable is ignored ! 2223 return (HMWaitForMultipleObjects(cObjects, 2224 lphObjects, 2225 fWaitAll, 2226 dwTimeout)); 2227 } 2228
Note:
See TracChangeset
for help on using the changeset viewer.