Changeset 664 for trunk/src/kernel32/HandleManager.cpp
- Timestamp:
- Aug 24, 1999, 8:48:10 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r659 r664 1 /* $Id: HandleManager.cpp,v 1.1 2 1999-08-24 14:36:04 phallerExp $ */1 /* $Id: HandleManager.cpp,v 1.13 1999-08-24 18:46:38 sandervl Exp $ */ 2 2 3 3 /* … … 56 56 #include "HMMutex.h" 57 57 #include "HMSemaphore.h" 58 #include "HMFileMapping.h" 59 58 #include "HMMMap.h" 60 59 61 60 /***************************************************************************** … … 122 121 HMDeviceHandler *pHMMutex; 123 122 HMDeviceHandler *pHMSemaphore; 124 HMDeviceHandler *pHMFileMapping; 123 HMDeviceHandler *pHMFileMapping; /* static instances of subsystems */ 125 124 126 125 ULONG ulHandleLast; /* index of last used handle */ … … 197 196 { 198 197 /* free handle found ? */ 199 if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) 200 return (ulLoop); /* OK, then return it to the caller */ 198 if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) { 199 TabWin32Handles[ulLoop].hmHandleData.dwUserData = 0; 200 TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN; 201 return (ulLoop); /* OK, then return it to the caller */ 202 } 201 203 } 202 204 … … 313 315 314 316 /* create handle manager instance for Open32 handles */ 315 HMGlobals.pHMOpen32 316 HMGlobals.pHMEvent 317 HMGlobals.pHMMutex 318 HMGlobals.pHMSemaphore 319 HMGlobals.pHMFileMapping = new HMDeviceFileMappingClass("\\\\FILEMAPPING\\");317 HMGlobals.pHMOpen32 = new HMDeviceOpen32Class("\\\\.\\"); 318 HMGlobals.pHMEvent = new HMDeviceEventClass("\\\\EVENT\\"); 319 HMGlobals.pHMMutex = new HMDeviceMutexClass("\\\\MUTEX\\"); 320 HMGlobals.pHMSemaphore = new HMDeviceSemaphoreClass("\\\\SEM\\"); 321 HMGlobals.pHMFileMapping = new HMDeviceMemMapClass("\\\\MEMMAP\\"); 320 322 } 321 323 return (NO_ERROR); … … 2151 2153 2152 2154 /***************************************************************************** 2153 * Name : HMWaitForMultipleObjects2154 * Purpose : router function for WaitForMultipleObjects2155 * Parameters:2156 * Variables :2157 * Result :2158 * Remark :2159 * Status :2160 *2161 * Author : Patrick Haller [Wed, 1999/06/17 20:44]2162 *****************************************************************************/2163 2164 DWORD HMWaitForMultipleObjects (DWORD cObjects,2165 PHANDLE lphObjects,2166 BOOL fWaitAll,2167 DWORD dwTimeout)2168 {2169 ULONG ulIndex;2170 PHANDLE pArrayOfHandles;2171 PHANDLE pLoop1 = lphObjects;2172 PHANDLE pLoop2;2173 DWORD rc;2174 2175 // allocate array for handle table2176 pArrayOfHandles = (PHANDLE)malloc(cObjects * sizeof(HANDLE));2177 if (pArrayOfHandles == NULL)2178 {2179 O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY);2180 return WAIT_FAILED;2181 }2182 else2183 pLoop2 = pArrayOfHandles;2184 2185 // convert array to odin handles2186 for (ulIndex = 0;2187 2188 ulIndex < cObjects;2189 2190 ulIndex++,2191 pLoop1++,2192 pLoop2++)2193 {2194 rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle2195 pLoop2);2196 2197 if (rc != NO_ERROR)2198 {2199 free (pArrayOfHandles); // free memory2200 O32_SetLastError(ERROR_INVALID_HANDLE);2201 return (WAIT_FAILED);2202 }2203 }2204 2205 // OK, now forward to Open32.2206 // @@@PH: Note this will fail on handles that do NOT belong to Open322207 // but to i.e. the console subsystem!2208 rc = O32_WaitForMultipleObjects(cObjects,2209 pArrayOfHandles,2210 fWaitAll,2211 dwTimeout);2212 2213 free(pArrayOfHandles); // free memory2214 return (rc); // OK, done2215 }2216 2217 2218 /*****************************************************************************2219 * Name : HMWaitForMultipleObjectsEx2220 * Purpose : router function for WaitForMultipleObjectsEx2221 * Parameters:2222 * Variables :2223 * Result :2224 * Remark :2225 * Status :2226 *2227 * Author : Patrick Haller [Wed, 1999/06/17 20:44]2228 *****************************************************************************/2229 2230 DWORD HMWaitForMultipleObjectsEx (DWORD cObjects,2231 PHANDLE lphObjects,2232 BOOL fWaitAll,2233 DWORD dwTimeout,2234 BOOL fAlertable)2235 {2236 // @@@PH: Note: fAlertable is ignored !2237 return (HMWaitForMultipleObjects(cObjects,2238 lphObjects,2239 fWaitAll,2240 dwTimeout));2241 }2242 2243 2244 /*****************************************************************************2245 2155 * Name : HANDLE HMCreateFileMapping 2246 2156 * Purpose : Wrapper for the CreateFileMapping() API … … 2350 2260 } 2351 2261 2352 2353 /* initialize the complete HMHANDLEDATA structure */ 2262 /* initialize the complete HMHANDLEDATA structure */ 2354 2263 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 2355 2264 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */ … … 2361 2270 2362 2271 2363 2364 2365 2366 2272 /* we've got to mark the handle as occupied here, since another device */ 2273 /* could be created within the device handler -> deadlock */ 2274 2275 /* write appropriate entry into the handle table if open succeeded */ 2367 2276 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2368 2277 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; … … 2370 2279 /* call the device handler */ 2371 2280 rc = pDeviceHandler->OpenFileMapping(&TabWin32Handles[iIndexNew].hmHandleData, 2281 fdwAccess, 2372 2282 fInherit, 2373 2283 lpName); … … 2381 2291 return iIndexNew; /* return valid handle */ 2382 2292 } 2383 2384 2385 /*****************************************************************************2386 * Name : HMMapViewOfFile2387 * Purpose : router function for MapViewOfFile2388 * Parameters:2389 * Variables :2390 * Result :2391 * Remark :2392 * Status :2393 *2394 * Author : Patrick Haller [Wed, 1999/06/17 20:44]2395 *****************************************************************************/2396 2397 LPVOID HMMapViewOfFile(HANDLE hFileMappingObject,2398 DWORD dwDesiredAccess,2399 DWORD dwFileOffsetHigh,2400 DWORD dwFileOffsetLow,2401 DWORD dwNumberOfBytesToMap)2402 {2403 int iIndex; /* index into the handle table */2404 LPVOID lpResult; /* result from the device handler's API */2405 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */2406 2407 /* validate handle */2408 iIndex = _HMHandleQuery(hFileMappingObject); /* get the index */2409 if (-1 == iIndex) /* error ? */2410 {2411 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */2412 return (NULL); /* signal failure */2413 }2414 2415 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */2416 lpResult = pHMHandle->pDeviceHandler->MapViewOfFile(&pHMHandle->hmHandleData,2417 dwDesiredAccess,2418 dwFileOffsetHigh,2419 dwFileOffsetLow,2420 dwNumberOfBytesToMap);2421 2422 return (lpResult); /* deliver return code */2423 }2424 2425 2293 2426 2294 … … 2458 2326 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 2459 2327 lpResult = pHMHandle->pDeviceHandler->MapViewOfFileEx(&pHMHandle->hmHandleData, 2460 2461 2462 2463 2464 2328 dwDesiredAccess, 2329 dwFileOffsetHigh, 2330 dwFileOffsetLow, 2331 dwNumberOfBytesToMap, 2332 lpBaseAddress); 2465 2333 2466 2334 return (lpResult); /* deliver return code */ 2467 2335 } 2468 2336 2469 2470 /***************************************************************************** 2471 * Name : HMUnmapViewOfFile 2472 * Purpose : router function for UnmapViewOfFile 2473 * Parameters: 2474 * Variables : 2475 * Result : 2476 * Remark : No handle is specified, that makes things a bit more difficult! 2477 * We've got to identify the object by the base address and check 2478 * back with HandleManager manually! 2337 /***************************************************************************** 2338 * Name : HMWaitForMultipleObjects 2339 * Purpose : router function for WaitForMultipleObjects 2340 * Parameters: 2341 * Variables : 2342 * Result : 2343 * Remark : 2479 2344 * Status : 2480 2345 * … … 2482 2347 *****************************************************************************/ 2483 2348 2484 BOOL HMUnmapViewOfFile(LPVOID lpBaseAddress) 2485 { 2486 int iIndex; /* index into the handle table */ 2487 BOOL flResult; /* result from the device handler's API */ 2488 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 2489 2490 // Identify the correct handle by the base address. Thus call a special 2491 // static function within the FileMapping class. 2492 iIndex = HMDeviceFileMappingClass::findByBaseAddress(lpBaseAddress); /* validate handle */ 2493 if (-1 == iIndex) /* error ? */ 2494 { 2495 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 2496 return (FALSE); /* signal failure */ 2497 } 2498 2499 flResult = pHMHandle->pDeviceHandler->UnmapViewOfFile(&pHMHandle->hmHandleData, 2500 lpBaseAddress); 2501 2502 // @@@PH automatically call CloseHandle of no more references to the object 2503 // are active. 2504 2505 return (flResult); /* deliver return code */ 2506 } 2507 2508 2509 /***************************************************************************** 2510 * Name : HMFlushViewOfFile 2511 * Purpose : router function for FlushViewOfFile 2512 * Parameters: 2513 * Variables : 2514 * Result : 2515 * Remark : No handle is specified, that makes things a bit more difficult! 2516 * We've got to identify the object by the base address and check 2517 * back with HandleManager manually! 2349 DWORD HMWaitForMultipleObjects (DWORD cObjects, 2350 PHANDLE lphObjects, 2351 BOOL fWaitAll, 2352 DWORD dwTimeout) 2353 { 2354 ULONG ulIndex; 2355 PHANDLE pArrayOfHandles; 2356 PHANDLE pLoop1 = lphObjects; 2357 PHANDLE pLoop2; 2358 DWORD rc; 2359 2360 // allocate array for handle table 2361 pArrayOfHandles = (PHANDLE)malloc(cObjects * sizeof(HANDLE)); 2362 if (pArrayOfHandles == NULL) 2363 { 2364 O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY); 2365 return WAIT_FAILED; 2366 } 2367 else 2368 pLoop2 = pArrayOfHandles; 2369 2370 // convert array to odin handles 2371 for (ulIndex = 0; 2372 2373 ulIndex < cObjects; 2374 2375 ulIndex++, 2376 pLoop1++, 2377 pLoop2++) 2378 { 2379 rc = HMHandleTranslateToOS2 (*pLoop1, // translate handle 2380 pLoop2); 2381 2382 if (rc != NO_ERROR) 2383 { 2384 free (pArrayOfHandles); // free memory 2385 O32_SetLastError(ERROR_INVALID_HANDLE); 2386 return (WAIT_FAILED); 2387 } 2388 } 2389 2390 // OK, now forward to Open32. 2391 // @@@PH: Note this will fail on handles that do NOT belong to Open32 2392 // but to i.e. the console subsystem! 2393 rc = O32_WaitForMultipleObjects(cObjects, 2394 pArrayOfHandles, 2395 fWaitAll, 2396 dwTimeout); 2397 2398 free(pArrayOfHandles); // free memory 2399 return (rc); // OK, done 2400 } 2401 2402 2403 /***************************************************************************** 2404 * Name : HMWaitForMultipleObjectsEx 2405 * Purpose : router function for WaitForMultipleObjectsEx 2406 * Parameters: 2407 * Variables : 2408 * Result : 2409 * Remark : 2518 2410 * Status : 2519 2411 * … … 2521 2413 *****************************************************************************/ 2522 2414 2523 BOOL HMFlushViewOfFile(LPVOID lpBaseAddress, 2524 DWORD dwNumberOfBytesToFlush) 2525 { 2526 int iIndex; /* index into the handle table */ 2527 BOOL flResult; /* result from the device handler's API */ 2528 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 2529 2530 // Identify the correct handle by the base address. Thus call a special 2531 // static function within the FileMapping class. 2532 iIndex = HMDeviceFileMappingClass::findByBaseAddress(lpBaseAddress); /* validate handle */ 2533 if (-1 == iIndex) /* error ? */ 2534 { 2535 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 2536 return (FALSE); /* signal failure */ 2537 } 2538 2539 flResult = pHMHandle->pDeviceHandler->FlushViewOfFile(&pHMHandle->hmHandleData, 2540 lpBaseAddress, 2541 dwNumberOfBytesToFlush); 2542 2543 return (flResult); /* deliver return code */ 2544 } 2415 DWORD HMWaitForMultipleObjectsEx (DWORD cObjects, 2416 PHANDLE lphObjects, 2417 BOOL fWaitAll, 2418 DWORD dwTimeout, 2419 BOOL fAlertable) 2420 { 2421 // @@@PH: Note: fAlertable is ignored ! 2422 return (HMWaitForMultipleObjects(cObjects, 2423 lphObjects, 2424 fWaitAll, 2425 dwTimeout)); 2426 } 2427
Note:
See TracChangeset
for help on using the changeset viewer.