- Timestamp:
- Jun 19, 2001, 12:50:26 PM (24 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r5791 r6049 1 /* $Id: HandleManager.cpp,v 1.6 4 2001-05-24 08:19:17sandervl Exp $ */1 /* $Id: HandleManager.cpp,v 1.65 2001-06-19 10:50:23 sandervl Exp $ */ 2 2 3 3 /* … … 2223 2223 2224 2224 2225 if(lpName) { //check if shared event semaphore already exists 2226 //TODO: No inheritance?? 2227 HANDLE handle = HMOpenEvent(EVENT_ALL_ACCESS, FALSE, lpName); 2228 if(handle) { 2229 dprintf(("CreateEvent: return handle of existing event semaphore %x", handle)); 2230 return handle; 2231 } 2232 } 2233 2225 2234 pDeviceHandler = HMGlobals.pHMEvent; /* device is predefined */ 2235 2236 iIndexNew = _HMHandleGetFree(); /* get free handle */ 2237 if (-1 == iIndexNew) /* oops, no free handles ! */ 2238 { 2239 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 2240 return 0; /* signal error */ 2241 } 2242 2243 /* Initialize the complete HMHANDLEDATA structure */ 2244 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 2245 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */ 2246 pHMHandleData->dwAccess = 0; 2247 pHMHandleData->dwShare = 0; 2248 pHMHandleData->dwCreation = 0; 2249 pHMHandleData->dwFlags = 0; 2250 pHMHandleData->lpHandlerData = NULL; 2251 2252 /* we've got to mark the handle as occupied here, since another device */ 2253 /* could be created within the device handler -> deadlock */ 2254 2255 /* write appropriate entry into the handle table if open succeeded */ 2256 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2257 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 2258 2259 /* call the device handler */ 2260 rc = pDeviceHandler->CreateEvent(&TabWin32Handles[iIndexNew].hmHandleData, 2261 lpsa, 2262 bManualReset, 2263 bInitialState, 2264 lpName); 2265 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2266 { 2267 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2268 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2269 return 0; /* signal error */ 2270 } 2271 else 2272 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 2273 2274 return iIndexNew; /* return valid handle */ 2275 } 2276 2277 2278 /***************************************************************************** 2279 * Name : HANDLE HMCreateMutex 2280 * Purpose : Wrapper for the CreateMutex() API 2281 * Parameters: 2282 * Variables : 2283 * Result : 2284 * Remark : 2285 * Status : 2286 * 2287 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 2288 *****************************************************************************/ 2289 2290 HANDLE HMCreateMutex(LPSECURITY_ATTRIBUTES lpsa, 2291 BOOL bInitialOwner, 2292 LPCTSTR lpName) 2293 { 2294 int iIndex; /* index into the handle table */ 2295 int iIndexNew; /* index into the handle table */ 2296 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 2297 PHMHANDLEDATA pHMHandleData; 2298 DWORD rc; /* API return code */ 2299 2300 2301 if(lpName) { //check if shared mutex semaphore already exists 2302 //TODO: No inheritance?? 2303 HANDLE handle = HMOpenMutex(MUTEX_ALL_ACCESS, FALSE, lpName); 2304 if(handle) { 2305 dprintf(("CreateMutex: return handle of existing mutex semaphore %x", handle)); 2306 return handle; 2307 } 2308 } 2309 2310 pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */ 2226 2311 2227 2312 iIndexNew = _HMHandleGetFree(); /* get free handle */ … … 2251 2336 2252 2337 /* call the device handler */ 2253 rc = pDeviceHandler->CreateEvent(&TabWin32Handles[iIndexNew].hmHandleData,2254 lpsa,2255 bManualReset,2256 bInitialState,2257 lpName);2258 if (rc != NO_ERROR) /* oops, creation failed within the device handler */2259 {2260 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;2261 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */2262 return 0; /* signal error */2263 }2264 else2265 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?2266 2267 return iIndexNew; /* return valid handle */2268 }2269 2270 2271 /*****************************************************************************2272 * Name : HANDLE HMCreateMutex2273 * Purpose : Wrapper for the CreateMutex() API2274 * Parameters:2275 * Variables :2276 * Result :2277 * Remark :2278 * Status :2279 *2280 * Author : Patrick Haller [Wed, 1998/02/11 20:44]2281 *****************************************************************************/2282 2283 HANDLE HMCreateMutex(LPSECURITY_ATTRIBUTES lpsa,2284 BOOL bInitialOwner,2285 LPCTSTR lpName)2286 {2287 int iIndex; /* index into the handle table */2288 int iIndexNew; /* index into the handle table */2289 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */2290 PHMHANDLEDATA pHMHandleData;2291 DWORD rc; /* API return code */2292 2293 2294 pDeviceHandler = HMGlobals.pHMMutex; /* device is predefined */2295 2296 iIndexNew = _HMHandleGetFree(); /* get free handle */2297 if (-1 == iIndexNew) /* oops, no free handles ! */2298 {2299 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */2300 return 0; /* signal error */2301 }2302 2303 2304 /* initialize the complete HMHANDLEDATA structure */2305 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData;2306 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */2307 pHMHandleData->dwAccess = 0;2308 pHMHandleData->dwShare = 0;2309 pHMHandleData->dwCreation = 0;2310 pHMHandleData->dwFlags = 0;2311 pHMHandleData->lpHandlerData = NULL;2312 2313 2314 /* we've got to mark the handle as occupied here, since another device */2315 /* could be created within the device handler -> deadlock */2316 2317 /* write appropriate entry into the handle table if open succeeded */2318 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;2319 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;2320 2321 /* call the device handler */2322 2338 rc = pDeviceHandler->CreateMutex(&TabWin32Handles[iIndexNew].hmHandleData, 2323 2339 lpsa, … … 2494 2510 DWORD rc; /* API return code */ 2495 2511 2496 2512 if(lpName) { //check if shared event semaphore already exists 2513 //TODO: No inheritance?? 2514 HANDLE handle = HMOpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, lpName); 2515 if(handle) { 2516 dprintf(("CreateSemaphore: return handle of existing semaphore %x", handle)); 2517 return handle; 2518 } 2519 } 2520 2497 2521 pDeviceHandler = HMGlobals.pHMSemaphore; /* device is predefined */ 2498 2522 … … 2984 3008 pLoop2); 2985 3009 3010 dprintf2(("MsgWaitForMultipleObjects handle %x->%x", *pLoop1, *pLoop2)); 2986 3011 // SvL: We still use Open32 handles for threads & processes -> don't fail here! 2987 3012 if (rc != NO_ERROR) -
trunk/src/kernel32/hmdevice.cpp
r5587 r6049 1 /* $Id: hmdevice.cpp,v 1.2 6 2001-04-26 13:22:44sandervl Exp $ */1 /* $Id: hmdevice.cpp,v 1.27 2001-06-19 10:50:23 sandervl Exp $ */ 2 2 3 3 /* … … 203 203 pHMHandleData)); 204 204 205 return(ERROR_INVALID_FUNCTION); 205 SetLastError(ERROR_INVALID_FUNCTION); 206 return FALSE; 206 207 } 207 208 -
trunk/src/kernel32/hmdisk.cpp
r6036 r6049 1 /* $Id: hmdisk.cpp,v 1. 9 2001-06-17 13:58:32sandervl Exp $ */1 /* $Id: hmdisk.cpp,v 1.10 2001-06-19 10:50:24 sandervl Exp $ */ 2 2 3 3 /* … … 368 368 SRB_ExecSCSICmd *psrb; 369 369 370 if(hInstAspi == NULL) { 371 SetLastError(ERROR_ACCESS_DENIED); 372 return FALSE; 373 } 374 370 375 if(nOutBufferSize < sizeof(SCSI_PASS_THROUGH_DIRECT) || 371 376 !pPacket || pPacket->Length < sizeof(SCSI_PASS_THROUGH_DIRECT)) -
trunk/src/kernel32/hmevent.cpp
r5332 r6049 1 /* $Id: hmevent.cpp,v 1. 4 2001-03-19 19:27:13sandervl Exp $ */1 /* $Id: hmevent.cpp,v 1.5 2001-06-19 10:50:24 sandervl Exp $ */ 2 2 3 3 /* 4 * Win32 Event Semaphore implementation 5 * 6 * TODO: Inheritance 7 * TODO: Does DCE_POSTONE work in Warp 3 or 4 with no FP applied? 8 * TODO: No inheritance when CreateEvent is called for existing named event semaphore? 9 * (see HMCreateEvent in handlemanager.cpp) 10 * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2 11 * 4 12 * Project Odin Software License can be found in LICENSE.TXT 5 * Win32 Unified Handle Manager for OS/26 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)13 * 14 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl) 7 15 */ 8 16 … … 22 30 *****************************************************************************/ 23 31 32 #ifdef USE_OS2SEMAPHORES 33 #define INCL_DOSSEMAPHORES 34 #include <os2wrap.h> 35 #include <win32type.h> 36 #include <win32api.h> 37 #include <winconst.h> 38 #else 24 39 #include <os2win.h> 40 #endif 41 25 42 #include <stdlib.h> 26 43 #include <string.h> … … 30 47 #include "HandleManager.H" 31 48 #include "HMEvent.h" 49 #include "oslibdos.h" 32 50 33 51 #define DBG_LOCALLOG DBG_hmevent 34 52 #include "dbglocal.h" 53 54 #ifndef DCE_AUTORESET 55 #define DCE_AUTORESET 0x1000 /* DosCreateEventSem option to auto-reset */ 56 /* event semaphore on post. */ 57 #define DCE_POSTONE 0x0800 /* DosCreateEventSem option to post only */ 58 /* waiter and auto-reset the semaphore when*/ 59 /* there are multiple waiters. */ 60 #endif 35 61 36 62 /***************************************************************************** … … 65 91 LPCTSTR lpszEventName) 66 92 { 67 HANDLE hOpen32; 93 #ifdef USE_OS2SEMAPHORES 94 APIRET rc; 95 HEV hev; 96 char szSemName[CCHMAXPATH]; 68 97 69 98 dprintf(("KERNEL32: HandleManager::Event::CreateEvent(%08xh,%08xh,%08xh,%08xh,%s)\n", … … 74 103 lpszEventName)); 75 104 105 if(lpszEventName) { 106 strcpy(szSemName, "\\SEM32\\"); 107 strcat(szSemName, lpszEventName); 108 lpszEventName = szSemName; 109 } 110 //Manual reset means all threads waiting on the event semaphore will be 111 //unblocked and the app must manually reset the event semaphore 112 //Automatic reset -> only one waiting thread unblocked & state reset 113 rc = DosCreateEventSem(lpszEventName, &hev, (fManualReset) ? 0 : DCE_POSTONE, fInitialState); 114 115 if(rc) { 116 dprintf(("DosCreateEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 117 pHMHandleData->hHMHandle = 0; 118 return error2WinError(rc); 119 } 120 pHMHandleData->dwAccess = EVENT_ALL_ACCESS_W; 121 pHMHandleData->dwFlags = fManualReset; 122 pHMHandleData->hHMHandle = hev; 123 return ERROR_SUCCESS_W; 124 #else 125 HANDLE hOpen32; 126 127 dprintf(("KERNEL32: HandleManager::Event::CreateEvent(%08xh,%08xh,%08xh,%08xh,%s)\n", 128 pHMHandleData, 129 lpsa, 130 fManualReset, 131 fInitialState, 132 lpszEventName)); 133 76 134 hOpen32 = O32_CreateEvent(lpsa, // call Open32 77 135 fManualReset, … … 86 144 else 87 145 return (O32_GetLastError()); 146 #endif 88 147 } 89 148 … … 105 164 LPCTSTR lpszEventName) 106 165 { 107 HANDLE hOpen32; 166 #ifdef USE_OS2SEMAPHORES 167 HEV hev; 168 APIRET rc; 169 char szSemName[CCHMAXPATH]; 108 170 109 171 dprintf(("KERNEL32: HandleManager::Event::OpenEvent(%08xh,%08xh,%s)\n", … … 112 174 lpszEventName)); 113 175 176 if(lpszEventName == NULL) { 177 pHMHandleData->hHMHandle = 0; 178 return ERROR_INVALID_PARAMETER_W; 179 } 180 181 strcpy(szSemName, "\\SEM32\\"); 182 strcat(szSemName, lpszEventName); 183 rc = DosOpenEventSem(szSemName, &hev); 184 if(rc) { 185 dprintf(("DosOpenEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 186 pHMHandleData->hHMHandle = 0; 187 return error2WinError(rc); 188 } 189 pHMHandleData->hHMHandle = hev; 190 return ERROR_SUCCESS_W; 191 #else 192 HANDLE hOpen32; 193 194 dprintf(("KERNEL32: HandleManager::Event::OpenEvent(%08xh,%08xh,%s)\n", 195 pHMHandleData, 196 fInheritHandle, 197 lpszEventName)); 198 114 199 hOpen32 = O32_OpenEvent(pHMHandleData->dwAccess, // call Open32 115 200 fInheritHandle, … … 123 208 else 124 209 return (O32_GetLastError()); 125 } 126 210 #endif 211 } 212 213 /***************************************************************************** 214 * Name : HMDeviceEventClass::CloseHandle 215 * Purpose : close the handle 216 * Parameters: PHMHANDLEDATA pHMHandleData 217 * Variables : 218 * Result : API returncode 219 * Remark : 220 * Status : 221 * 222 * Author : 223 *****************************************************************************/ 224 225 #ifdef USE_OS2SEMAPHORES 226 BOOL HMDeviceEventClass::CloseHandle(PHMHANDLEDATA pHMHandleData) 227 { 228 APIRET rc; 229 230 if(pHMHandleData->hHMHandle) { 231 rc = DosCloseEventSem((HEV)pHMHandleData->hHMHandle); 232 if(rc) { 233 dprintf(("DosCloseEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 234 SetLastError(error2WinError(rc)); 235 return FALSE; 236 } 237 } 238 return TRUE; 239 } 240 #endif 241 242 /***************************************************************************** 243 * Name : HMDeviceEventClass::DuplicateHandle 244 * Purpose : 245 * Parameters: 246 * various parameters as required 247 * Variables : 248 * Result : 249 * Remark : the standard behaviour is to return an error code for non- 250 * existant request codes 251 * Status : 252 * 253 * Author : 254 *****************************************************************************/ 255 #ifdef USE_OS2SEMAPHORES 256 BOOL HMDeviceEventClass::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 257 PHMHANDLEDATA pHMSrcHandle, 258 HANDLE destprocess, 259 PHANDLE desthandle, 260 DWORD fdwAccess, 261 BOOL fInherit, 262 DWORD fdwOptions, 263 DWORD fdwOdinOptions) 264 { 265 APIRET rc; 266 HEV hev; 267 268 dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED!!!!!!!!\n", 269 lpHMDeviceName, 270 pHMHandleData, 271 srcprocess, pHMSrcHandle, destprocess, desthandle)); 272 273 if(srcprocess != destprocess) { 274 DebugInt3(); 275 SetLastError(ERROR_ACCESS_DENIED_W); 276 return FALSE; 277 } 278 hev = (HEV)pHMSrcHandle->hHMHandle; 279 rc = DosOpenEventSem(NULL, &hev); 280 if(rc) { 281 dprintf(("DosOpenEventSem %x failed with rc %d", pHMSrcHandle->hHMHandle, rc)); 282 pHMHandleData->hHMHandle = 0; 283 SetLastError(error2WinError(rc)); 284 return FALSE; 285 } 286 pHMHandleData->dwAccess = fdwAccess; 287 pHMHandleData->dwFlags = pHMSrcHandle->dwFlags; //fManualReset 288 pHMHandleData->hHMHandle = hev; 289 SetLastError(ERROR_SUCCESS_W); 290 return TRUE; 291 } 292 #endif 127 293 128 294 /***************************************************************************** … … 140 306 BOOL HMDeviceEventClass::SetEvent(PHMHANDLEDATA pHMHandleData) 141 307 { 142 //testestest 308 #ifdef USE_OS2SEMAPHORES 309 APIRET rc; 310 143 311 dprintf(("KERNEL32: HandleManager::Event::SetEvent(%08xh)\n", 144 312 pHMHandleData->hHMHandle)); 145 313 314 if(!(pHMHandleData->dwAccess & EVENT_MODIFY_STATE_W) ) 315 { 316 dprintf(("ERROR: Access denied!!")); 317 SetLastError(ERROR_ACCESS_DENIED_W); 318 return FALSE; 319 } 320 321 rc = DosPostEventSem(pHMHandleData->hHMHandle); 322 if(rc) { 323 dprintf(("DosPostEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 324 SetLastError(error2WinError(rc)); 325 return FALSE; 326 } 327 SetLastError(ERROR_SUCCESS_W); 328 return TRUE; 329 #else 330 dprintf(("KERNEL32: HandleManager::Event::SetEvent(%08xh)\n", 331 pHMHandleData->hHMHandle)); 332 146 333 return (O32_SetEvent(pHMHandleData->hHMHandle)); 334 #endif 147 335 } 148 336 … … 162 350 BOOL HMDeviceEventClass::PulseEvent(PHMHANDLEDATA pHMHandleData) 163 351 { 352 #ifdef USE_OS2SEMAPHORES 353 APIRET rc; 354 ULONG count; 355 164 356 dprintf2(("KERNEL32: HandleManager::Event::PulseEvent(%08xh)\n", 165 357 pHMHandleData->hHMHandle)); 166 358 359 if(!(pHMHandleData->dwAccess & EVENT_MODIFY_STATE_W) ) 360 { 361 dprintf(("ERROR: Access denied!!")); 362 SetLastError(ERROR_ACCESS_DENIED_W); 363 return FALSE; 364 } 365 366 rc = DosPostEventSem(pHMHandleData->hHMHandle); 367 if(rc) { 368 dprintf(("DosPostEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 369 SetLastError(error2WinError(rc)); 370 return FALSE; 371 } 372 if(pHMHandleData->dwFlags == TRUE) {//fManualReset 373 rc = DosResetEventSem(pHMHandleData->hHMHandle, &count); 374 if(rc) { 375 dprintf(("DosResetEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 376 SetLastError(error2WinError(rc)); 377 return FALSE; 378 } 379 } 380 SetLastError(ERROR_SUCCESS_W); 381 return TRUE; 382 #else 383 dprintf2(("KERNEL32: HandleManager::Event::PulseEvent(%08xh)\n", 384 pHMHandleData->hHMHandle)); 385 167 386 return (O32_PulseEvent(pHMHandleData->hHMHandle)); 387 #endif 168 388 } 169 389 … … 183 403 BOOL HMDeviceEventClass::ResetEvent(PHMHANDLEDATA pHMHandleData) 184 404 { 405 #ifdef USE_OS2SEMAPHORES 406 APIRET rc; 407 ULONG count; 408 185 409 dprintf2(("KERNEL32: HandleManager::Event::ResetEvent(%08xh)\n", 186 410 pHMHandleData->hHMHandle)); 187 411 412 if(!(pHMHandleData->dwAccess & EVENT_MODIFY_STATE_W) ) 413 { 414 dprintf(("ERROR: Access denied!!")); 415 SetLastError(ERROR_ACCESS_DENIED_W); 416 return FALSE; 417 } 418 419 rc = DosResetEventSem(pHMHandleData->hHMHandle, &count); 420 if(rc) { 421 dprintf(("DosResetEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 422 SetLastError(error2WinError(rc)); 423 return FALSE; 424 } 425 SetLastError(ERROR_SUCCESS_W); 426 return TRUE; 427 #else 428 dprintf2(("KERNEL32: HandleManager::Event::ResetEvent(%08xh)\n", 429 pHMHandleData->hHMHandle)); 430 188 431 return (O32_ResetEvent(pHMHandleData->hHMHandle)); 189 } 190 432 #endif 433 } 434 -
trunk/src/kernel32/hmevent.h
r768 r6049 1 /* $Id: hmevent.h,v 1. 2 1999-08-31 23:14:03 phallerExp $ */1 /* $Id: hmevent.h,v 1.3 2001-06-19 10:50:24 sandervl Exp $ */ 2 2 3 3 /* … … 29 29 *****************************************************************************/ 30 30 31 #ifdef USE_OS2SEMAPHORES 32 class HMDeviceEventClass : public HMDeviceHandler 33 #else 31 34 class HMDeviceEventClass : public HMDeviceOpen32Class 35 #endif 32 36 { 33 37 public: 34 38 HMDeviceEventClass(LPCSTR lpDeviceName) : HMDeviceOpen32Class(lpDeviceName) {} 35 39 36 40 /* this is a handler method for calls to CreateEvent() */ 37 41 virtual DWORD CreateEvent (PHMHANDLEDATA pHMHandleData, 38 42 LPSECURITY_ATTRIBUTES lpsa, … … 41 45 LPCTSTR lpszEventName); 42 46 43 /* this is a handler method for calls to OpenEvent() */ 47 #ifdef USE_OS2SEMAPHORES 48 virtual BOOL CloseHandle(PHMHANDLEDATA pHMHandleData); 49 50 virtual BOOL DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 51 PHMHANDLEDATA pHMSrcHandle, 52 HANDLE destprocess, 53 PHANDLE desthandle, 54 DWORD fdwAccess, 55 BOOL fInherit, 56 DWORD fdwOptions, 57 DWORD fdwOdinOptions); 58 #endif 59 60 /* this is a handler method for calls to OpenEvent() */ 44 61 virtual DWORD OpenEvent (PHMHANDLEDATA pHMHandleData, 45 62 BOOL fInheritHandle, 46 63 LPCTSTR lpszEventName); 47 64 48 65 /* this is a handle method for calls to ResetEvent() */ 49 66 virtual BOOL ResetEvent (PHMHANDLEDATA pHMHandleData); 50 67 51 68 /* this is a handle method for calls to SetEvent() */ 52 69 virtual BOOL SetEvent (PHMHANDLEDATA pHMHandleData); 53 70 54 71 /* this is a handle method for calls to PulseEvent() */ 55 72 virtual BOOL PulseEvent (PHMHANDLEDATA pHMHandleData); 56 73 }; -
trunk/src/kernel32/hmmutex.cpp
r2802 r6049 1 /* $Id: hmmutex.cpp,v 1. 3 2000-02-16 14:24:00sandervl Exp $ */1 /* $Id: hmmutex.cpp,v 1.4 2001-06-19 10:50:25 sandervl Exp $ */ 2 2 3 3 /* 4 * Win32 Mutex Semaphore implementation 5 * 6 * TODO: Inheritance 7 * TODO: No inheritance when CreateMutex is called for existing named event semaphore? 8 * (see HMCreateMutex in handlemanager.cpp) 9 * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2 10 * 4 11 * Project Odin Software License can be found in LICENSE.TXT 5 * Win32 Unified Handle Manager for OS/26 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)12 * 13 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl) 7 14 */ 8 15 … … 22 29 *****************************************************************************/ 23 30 31 #ifdef USE_OS2SEMAPHORES 32 #define INCL_DOSSEMAPHORES 33 #include <os2wrap.h> 34 #include <win32type.h> 35 #include <win32api.h> 36 #include <winconst.h> 37 #else 24 38 #include <os2win.h> 39 #endif 25 40 #include <stdlib.h> 26 41 #include <string.h> 27 42 #include "unicode.h" 28 43 #include "misc.h" 44 #include "oslibdos.h" 29 45 30 46 #include "HandleManager.H" … … 64 80 LPCTSTR lpszMutexName) 65 81 { 82 #ifdef USE_OS2SEMAPHORES 83 APIRET rc; 84 HMTX htmx; 85 char szSemName[CCHMAXPATH]; 86 87 dprintf(("KERNEL32: HandleManager::Mutex::CreateMutex(%08xh,%08xh,%08xh,%s)\n", 88 pHMHandleData, 89 lpsa, 90 fInitialOwner, 91 lpszMutexName)); 92 93 if(lpszMutexName) { 94 strcpy(szSemName, "\\SEM32\\"); 95 strcat(szSemName, lpszMutexName); 96 lpszMutexName = szSemName; 97 } 98 rc = DosCreateMutexSem(lpszMutexName, &htmx, 0, fInitialOwner); 99 100 if(rc) { 101 dprintf(("DosCreateMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 102 pHMHandleData->hHMHandle = 0; 103 return error2WinError(rc); 104 } 105 pHMHandleData->dwAccess = MUTEX_ALL_ACCESS_W; 106 pHMHandleData->hHMHandle = htmx; 107 return ERROR_SUCCESS_W; 108 #else 66 109 HANDLE hOpen32; 67 110 … … 83 126 else 84 127 return (O32_GetLastError()); 128 #endif 85 129 } 86 130 … … 102 146 LPCTSTR lpszMutexName) 103 147 { 148 #ifdef USE_OS2SEMAPHORES 149 HMTX hmtx; 150 APIRET rc; 151 char szSemName[CCHMAXPATH]; 152 153 dprintf(("KERNEL32: HandleManager::Mutex::OpenMutex(%08xh,%08xh,%s)\n", 154 pHMHandleData, 155 fInheritHandle, 156 lpszMutexName)); 157 158 if(lpszMutexName == NULL) { 159 pHMHandleData->hHMHandle = 0; 160 return ERROR_INVALID_PARAMETER_W; 161 } 162 163 strcpy(szSemName, "\\SEM32\\"); 164 strcat(szSemName, lpszMutexName); 165 rc = DosOpenMutexSem(szSemName, &hmtx); 166 if(rc) { 167 dprintf(("DosOpenMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 168 pHMHandleData->hHMHandle = 0; 169 return error2WinError(rc); 170 } 171 pHMHandleData->hHMHandle = hmtx; 172 return ERROR_SUCCESS_W; 173 #else 104 174 HANDLE hOpen32; 105 175 … … 120 190 else 121 191 return (O32_GetLastError()); 122 } 123 192 #endif 193 } 194 195 /***************************************************************************** 196 * Name : HMDeviceMutexClass::CloseHandle 197 * Purpose : close the handle 198 * Parameters: PHMHANDLEDATA pHMHandleData 199 * Variables : 200 * Result : API returncode 201 * Remark : 202 * Status : 203 * 204 * Author : 205 *****************************************************************************/ 206 207 #ifdef USE_OS2SEMAPHORES 208 BOOL HMDeviceMutexClass::CloseHandle(PHMHANDLEDATA pHMHandleData) 209 { 210 APIRET rc; 211 212 if(pHMHandleData->hHMHandle) { 213 rc = DosCloseMutexSem((HEV)pHMHandleData->hHMHandle); 214 if(rc) { 215 dprintf(("DosCloseMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 216 SetLastError(error2WinError(rc)); 217 return FALSE; 218 } 219 } 220 return TRUE; 221 } 222 #endif 223 224 /***************************************************************************** 225 * Name : HMDeviceMutexClass::DuplicateHandle 226 * Purpose : 227 * Parameters: 228 * various parameters as required 229 * Variables : 230 * Result : 231 * Remark : the standard behaviour is to return an error code for non- 232 * existant request codes 233 * Status : 234 * 235 * Author : 236 *****************************************************************************/ 237 #ifdef USE_OS2SEMAPHORES 238 BOOL HMDeviceMutexClass::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 239 PHMHANDLEDATA pHMSrcHandle, 240 HANDLE destprocess, 241 PHANDLE desthandle, 242 DWORD fdwAccess, 243 BOOL fInherit, 244 DWORD fdwOptions, 245 DWORD fdwOdinOptions) 246 { 247 APIRET rc; 248 HMTX hmtx; 249 250 dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED!!!!!!!!\n", 251 lpHMDeviceName, 252 pHMHandleData, 253 srcprocess, pHMSrcHandle, destprocess, desthandle)); 254 255 if(srcprocess != destprocess) { 256 DebugInt3(); 257 SetLastError(ERROR_ACCESS_DENIED_W); 258 return FALSE; 259 } 260 hmtx = (HMTX)pHMSrcHandle->hHMHandle; 261 rc = DosOpenMutexSem(NULL, &hmtx); 262 if(rc) { 263 dprintf(("DosOpenMutexSem %x failed with rc %d", pHMSrcHandle->hHMHandle, rc)); 264 pHMHandleData->hHMHandle = 0; 265 SetLastError(error2WinError(rc)); 266 return FALSE; 267 } 268 pHMHandleData->dwAccess = fdwAccess; 269 pHMHandleData->hHMHandle = hmtx; 270 SetLastError(ERROR_SUCCESS_W); 271 return TRUE; 272 } 273 #endif 124 274 125 275 /***************************************************************************** … … 137 287 BOOL HMDeviceMutexClass::ReleaseMutex(PHMHANDLEDATA pHMHandleData) 138 288 { 289 #ifdef USE_OS2SEMAPHORES 290 APIRET rc; 291 139 292 dprintf(("KERNEL32: HandleManager::Mutex::ReleaseMutex(%08xh)\n", 140 293 pHMHandleData->hHMHandle)); 141 294 295 rc = DosReleaseMutexSem(pHMHandleData->hHMHandle); 296 if(rc) { 297 dprintf(("DosReleaseMutexSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 298 SetLastError(error2WinError(rc)); 299 return FALSE; 300 } 301 SetLastError(ERROR_SUCCESS_W); 302 return TRUE; 303 #else 304 dprintf(("KERNEL32: HandleManager::Mutex::ReleaseMutex(%08xh)\n", 305 pHMHandleData->hHMHandle)); 306 142 307 return (O32_ReleaseMutex(pHMHandleData->hHMHandle)); 143 } 144 308 #endif 309 } 310 -
trunk/src/kernel32/hmmutex.h
r768 r6049 1 /* $Id: hmmutex.h,v 1. 2 1999-08-31 23:14:03 phallerExp $ */1 /* $Id: hmmutex.h,v 1.3 2001-06-19 10:50:25 sandervl Exp $ */ 2 2 3 3 /* … … 29 29 *****************************************************************************/ 30 30 31 #ifdef USE_OS2SEMAPHORES 32 class HMDeviceMutexClass : public HMDeviceHandler 33 #else 31 34 class HMDeviceMutexClass : public HMDeviceOpen32Class 35 #endif 32 36 { 33 37 public: 34 38 HMDeviceMutexClass(LPCSTR lpDeviceName) : HMDeviceOpen32Class(lpDeviceName) {} 35 39 36 40 /* this is a handler method for calls to CreateMutex() */ 37 41 virtual DWORD CreateMutex (PHMHANDLEDATA pHMHandleData, 38 42 LPSECURITY_ATTRIBUTES lpsa, … … 40 44 LPCTSTR lpszMutexName); 41 45 42 46 /* this is a handler method for calls to OpenMutex() */ 43 47 virtual DWORD OpenMutex (PHMHANDLEDATA pHMHandleData, 44 48 BOOL fInheritHandle, 45 49 LPCTSTR lpszMutexName); 46 50 47 /* this is a handle method for calls to ReleaseMutex() */ 51 #ifdef USE_OS2SEMAPHORES 52 virtual BOOL CloseHandle(PHMHANDLEDATA pHMHandleData); 53 54 virtual BOOL DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 55 PHMHANDLEDATA pHMSrcHandle, 56 HANDLE destprocess, 57 PHANDLE desthandle, 58 DWORD fdwAccess, 59 BOOL fInherit, 60 DWORD fdwOptions, 61 DWORD fdwOdinOptions); 62 #endif 63 64 /* this is a handle method for calls to ReleaseMutex() */ 48 65 virtual BOOL ReleaseMutex(PHMHANDLEDATA pHMHandleData); 49 66 }; -
trunk/src/kernel32/hmsemaphore.cpp
r2802 r6049 1 /* $Id: hmsemaphore.cpp,v 1. 3 2000-02-16 14:24:00sandervl Exp $ */1 /* $Id: hmsemaphore.cpp,v 1.4 2001-06-19 10:50:25 sandervl Exp $ */ 2 2 3 3 /* 4 * Win32 Semaphore implementation 5 * 6 * TODO: Inheritance 7 * TODO: Does DCE_POSTONE work in Warp 3 or 4 with no FP applied? 8 * TODO: No inheritance when CreateSemaphore is called for existing named event semaphore? 9 * (see HMCreateSemaphore in handlemanager.cpp) 10 * TODO: Name collisions with files & mutex not allowed. Check if this can happen in OS/2 11 * TODO: Does NOT work for sharing semaphores between processes!! 12 * 4 13 * Project Odin Software License can be found in LICENSE.TXT 5 * Win32 Unified Handle Manager for OS/26 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)14 * 15 * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl) 7 16 */ 8 17 … … 22 31 *****************************************************************************/ 23 32 33 #ifdef USE_OS2SEMAPHORES 34 #define INCL_DOSSEMAPHORES 35 #include <os2wrap.h> 36 #include <win32type.h> 37 #include <win32api.h> 38 #include <winconst.h> 39 #else 24 40 #include <os2win.h> 41 #endif 25 42 #include <stdlib.h> 26 43 #include <string.h> … … 30 47 #include "HandleManager.H" 31 48 #include "HMSemaphore.h" 49 #include "oslibdos.h" 32 50 33 51 #define DBG_LOCALLOG DBG_hmsemaphore 34 52 #include "dbglocal.h" 53 54 #ifndef DCE_AUTORESET 55 #define DCE_AUTORESET 0x1000 /* DosCreateEventSem option to auto-reset */ 56 /* event semaphore on post. */ 57 #define DCE_POSTONE 0x0800 /* DosCreateEventSem option to post only */ 58 /* waiter and auto-reset the semaphore when*/ 59 /* there are multiple waiters. */ 60 #endif 35 61 36 62 … … 66 92 LPCTSTR lpszSemaphoreName) 67 93 { 68 HANDLE hOpen32; 94 #ifdef USE_OS2SEMAPHORES 95 APIRET rc; 96 HEV hev; 97 char szSemName[CCHMAXPATH]; 98 69 99 70 100 dprintf(("KERNEL32: HandleManager::Semaphore::CreateSemaphore(%08xh,%08xh,%08xh,%08xh,%s)\n", … … 75 105 lpszSemaphoreName)); 76 106 107 if(lMaximumCount <= 0 || lInitialCount < 0 || lInitialCount > lMaximumCount) { 108 dprintf(("ERROR: invalid parameter")); 109 return ERROR_INVALID_PARAMETER_W; 110 } 111 112 if(lpszSemaphoreName) { 113 strcpy(szSemName, "\\SEM32\\"); 114 strcat(szSemName, lpszSemaphoreName); 115 lpszSemaphoreName = szSemName; 116 } 117 //Manual reset means all threads waiting on the event semaphore will be 118 //unblocked and the app must manually reset the event semaphore 119 //Automatic reset -> only one waiting thread unblocked & state reset 120 rc = DosCreateEventSem(lpszSemaphoreName, &hev, DCE_POSTONE, lInitialCount); 121 122 if(rc) { 123 dprintf(("DosCreateEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 124 pHMHandleData->hHMHandle = 0; 125 return error2WinError(rc); 126 } 127 pHMHandleData->dwAccess = SEMAPHORE_ALL_ACCESS_W; 128 pHMHandleData->dwFlags = lMaximumCount; 129 pHMHandleData->hHMHandle = hev; 130 return ERROR_SUCCESS_W; 131 #else 132 HANDLE hOpen32; 133 134 dprintf(("KERNEL32: HandleManager::Semaphore::CreateSemaphore(%08xh,%08xh,%08xh,%08xh,%s)\n", 135 pHMHandleData, 136 lpsa, 137 lInitialCount, 138 lMaximumCount, 139 lpszSemaphoreName)); 140 77 141 hOpen32 = O32_CreateSemaphore(lpsa, // call Open32 78 142 lInitialCount, … … 87 151 else 88 152 return (O32_GetLastError()); 153 #endif 89 154 } 90 155 … … 106 171 LPCTSTR lpszSemaphoreName) 107 172 { 173 #ifdef USE_OS2SEMAPHORES 174 HEV hev; 175 APIRET rc; 176 char szSemName[CCHMAXPATH]; 177 178 dprintf(("KERNEL32: HandleManager::Semaphore::OpenSemaphore(%08xh,%08xh,%s)\n", 179 pHMHandleData, 180 fInheritHandle, 181 lpszSemaphoreName)); 182 183 if(lpszSemaphoreName == NULL) { 184 pHMHandleData->hHMHandle = 0; 185 return ERROR_INVALID_PARAMETER_W; 186 } 187 188 strcpy(szSemName, "\\SEM32\\"); 189 strcat(szSemName, lpszSemaphoreName); 190 rc = DosOpenEventSem(szSemName, &hev); 191 if(rc) { 192 dprintf(("DosOpenEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 193 pHMHandleData->hHMHandle = 0; 194 return error2WinError(rc); 195 } 196 pHMHandleData->hHMHandle = hev; 197 return ERROR_SUCCESS_W; 198 #else 108 199 HANDLE hOpen32; 109 200 … … 124 215 else 125 216 return (O32_GetLastError()); 126 } 127 217 #endif 218 } 219 220 /***************************************************************************** 221 * Name : HMDeviceEventClass::CloseHandle 222 * Purpose : close the handle 223 * Parameters: PHMHANDLEDATA pHMHandleData 224 * Variables : 225 * Result : API returncode 226 * Remark : 227 * Status : 228 * 229 * Author : 230 *****************************************************************************/ 231 232 #ifdef USE_OS2SEMAPHORES 233 BOOL HMDeviceSemaphoreClass::CloseHandle(PHMHANDLEDATA pHMHandleData) 234 { 235 APIRET rc; 236 237 if(pHMHandleData->hHMHandle) { 238 rc = DosCloseEventSem((HEV)pHMHandleData->hHMHandle); 239 if(rc) { 240 dprintf(("DosCloseEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 241 SetLastError(error2WinError(rc)); 242 return FALSE; 243 } 244 } 245 return TRUE; 246 } 247 #endif 248 249 250 /***************************************************************************** 251 * Name : HMDeviceEventClass::DuplicateHandle 252 * Purpose : 253 * Parameters: 254 * various parameters as required 255 * Variables : 256 * Result : 257 * Remark : the standard behaviour is to return an error code for non- 258 * existant request codes 259 * Status : 260 * 261 * Author : 262 *****************************************************************************/ 263 #ifdef USE_OS2SEMAPHORES 264 BOOL HMDeviceSemaphoreClass::DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 265 PHMHANDLEDATA pHMSrcHandle, 266 HANDLE destprocess, 267 PHANDLE desthandle, 268 DWORD fdwAccess, 269 BOOL fInherit, 270 DWORD fdwOptions, 271 DWORD fdwOdinOptions) 272 { 273 APIRET rc; 274 HEV hev; 275 276 dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x)", 277 lpHMDeviceName, 278 pHMHandleData, 279 srcprocess, pHMSrcHandle, destprocess, desthandle)); 280 281 if(srcprocess != destprocess) { 282 DebugInt3(); 283 SetLastError(ERROR_ACCESS_DENIED_W); 284 return FALSE; 285 } 286 hev = (HEV)pHMSrcHandle->hHMHandle; 287 rc = DosOpenEventSem(NULL, &hev); 288 if(rc) { 289 dprintf(("DosOpenEventSem %x failed with rc %d", pHMSrcHandle->hHMHandle, rc)); 290 pHMHandleData->hHMHandle = 0; 291 SetLastError(error2WinError(rc)); 292 return FALSE; 293 } 294 pHMHandleData->dwAccess = fdwAccess; 295 pHMHandleData->dwFlags = pHMSrcHandle->dwFlags; //lMaximumCount; 296 pHMHandleData->hHMHandle = hev; 297 SetLastError(ERROR_SUCCESS_W); 298 return TRUE; 299 } 300 #endif 128 301 129 302 /***************************************************************************** … … 143 316 LPLONG lpPreviousCount) 144 317 { 318 #ifdef USE_OS2SEMAPHORES 319 APIRET rc; 320 ULONG count; 321 322 dprintf2(("KERNEL32: HandleManager::Semaphore::ReleaseSemaphore(%08xh,%08xh,%08xh)\n", 323 pHMHandleData->hHMHandle, 324 cReleaseCount, 325 lpPreviousCount)); 326 327 if(!(pHMHandleData->dwAccess & SEMAPHORE_MODIFY_STATE_W) ) 328 { 329 dprintf(("ERROR: Access denied!!")); 330 SetLastError(ERROR_ACCESS_DENIED_W); 331 return FALSE; 332 } 333 334 rc = DosResetEventSem(pHMHandleData->hHMHandle, &count); 335 if(rc) { 336 dprintf(("DosResetEventSem %x failed with rc %d", pHMHandleData->hHMHandle, rc)); 337 SetLastError(error2WinError(rc)); 338 return FALSE; 339 } 340 SetLastError(ERROR_SUCCESS_W); 341 return TRUE; 342 #else 145 343 dprintf(("KERNEL32: HandleManager::Semaphore::ReleaseSemaphore(%08xh,%08xh,%08xh)\n", 146 344 pHMHandleData->hHMHandle, … … 151 349 cReleaseCount, 152 350 lpPreviousCount)); 153 } 154 351 #endif 352 } 353 -
trunk/src/kernel32/hmsemaphore.h
r768 r6049 1 /* $Id: hmsemaphore.h,v 1. 2 1999-08-31 23:14:03 phallerExp $ */1 /* $Id: hmsemaphore.h,v 1.3 2001-06-19 10:50:25 sandervl Exp $ */ 2 2 3 3 /* … … 29 29 *****************************************************************************/ 30 30 31 #ifdef USE_OS2SEMAPHORES 32 class HMDeviceSemaphoreClass : public HMDeviceHandler 33 #else 31 34 class HMDeviceSemaphoreClass : public HMDeviceOpen32Class 35 #endif 32 36 { 33 37 public: 34 38 HMDeviceSemaphoreClass(LPCSTR lpDeviceName) : HMDeviceOpen32Class(lpDeviceName) {} 35 39 36 40 /* this is a handler method for calls to CreateSemaphore() */ 37 41 virtual DWORD CreateSemaphore (PHMHANDLEDATA pHMHandleData, 38 42 LPSECURITY_ATTRIBUTES lpsa, … … 41 45 LPCTSTR lpszSemaphoreName); 42 46 43 47 /* this is a handler method for calls to OpenSemaphore() */ 44 48 virtual DWORD OpenSemaphore (PHMHANDLEDATA pHMHandleData, 45 49 BOOL fInheritHandle, 46 50 LPCTSTR lpszSemaphoreName); 47 51 48 /* this is a handle method for calls to ReleaseSemaphore() */ 52 #ifdef USE_OS2SEMAPHORES 53 virtual BOOL CloseHandle(PHMHANDLEDATA pHMHandleData); 54 55 virtual BOOL DuplicateHandle(PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 56 PHMHANDLEDATA pHMSrcHandle, 57 HANDLE destprocess, 58 PHANDLE desthandle, 59 DWORD fdwAccess, 60 BOOL fInherit, 61 DWORD fdwOptions, 62 DWORD fdwOdinOptions); 63 #endif 64 65 /* this is a handle method for calls to ReleaseSemaphore() */ 49 66 virtual BOOL ReleaseSemaphore(PHMHANDLEDATA pHMHandleData, 50 67 LONG cReleaseCount, -
trunk/src/kernel32/oslibdos.cpp
r6029 r6049 1 /* $Id: oslibdos.cpp,v 1.6 5 2001-06-16 16:10:12sandervl Exp $ */1 /* $Id: oslibdos.cpp,v 1.66 2001-06-19 10:50:25 sandervl Exp $ */ 2 2 /* 3 3 * Wrappers for OS/2 Dos* API … … 102 102 // NOTE: add all codes you need, list is not complete! 103 103 //****************************************************************************** 104 DWORD error2WinError(APIRET rc,DWORD defaultCode = ERROR_NOT_ENOUGH_MEMORY_W)104 DWORD error2WinError(APIRET rc,DWORD defaultCode) 105 105 { 106 106 switch (rc) -
trunk/src/kernel32/oslibdos.h
r6029 r6049 1 /* $Id: oslibdos.h,v 1.3 0 2001-06-16 16:10:13sandervl Exp $ */1 /* $Id: oslibdos.h,v 1.31 2001-06-19 10:50:26 sandervl Exp $ */ 2 2 3 3 /* … … 13 13 #define __OSLIBDOS_H__ 14 14 15 16 #ifdef OS2_INCLUDED 17 DWORD error2WinError(APIRET rc,DWORD defaultCode = ERROR_NOT_ENOUGH_MEMORY_W); 18 #else 19 DWORD error2WinError(DWORD rc,DWORD defaultCode = ERROR_NOT_ENOUGH_MEMORY); 20 #endif 15 21 16 22 void OSLibInitWSeBFileIO();
Note:
See TracChangeset
for help on using the changeset viewer.