Changeset 21302 for trunk/src/kernel32
- Timestamp:
- Jun 18, 2009, 11:53:26 AM (16 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 2 added
- 58 edited
-
CONSOLE.ICO (modified) ( previous)
-
Fileio.cpp (modified) (13 diffs)
-
HandleManager.cpp (modified) (83 diffs)
-
KERNEL32.CPP (modified) (1 diff)
-
KERNEL32.DEF (modified) (6 diffs)
-
_ras.cpp (added)
-
comm.cpp (modified) (2 diffs)
-
conbuffer.cpp (modified) (2 diffs)
-
critsection.cpp (modified) (13 diffs)
-
dbglocal.cpp (modified) (1 diff)
-
dbglocal.h (modified) (1 diff)
-
dbglog.cpp (modified) (4 diffs)
-
directory.cpp (modified) (2 diffs)
-
environ.cpp (modified) (6 diffs)
-
exceptions.cpp (modified) (22 diffs)
-
exceptstackdump.cpp (modified) (11 diffs)
-
exceptstackdump.h (modified) (1 diff)
-
handlenames.cpp (modified) (1 diff)
-
heapshared.cpp (modified) (5 diffs)
-
hmcomm.cpp (modified) (1 diff)
-
hmdevice.cpp (modified) (3 diffs)
-
hmdevice.h (modified) (5 diffs)
-
hmdevio.cpp (modified) (5 diffs)
-
hmevent.cpp (modified) (3 diffs)
-
hmfile.cpp (modified) (15 diffs)
-
hmfile.h (modified) (2 diffs)
-
hmhandle.h (added)
-
hmmmap.cpp (modified) (2 diffs)
-
hmnpipe.cpp (modified) (2 diffs)
-
hmnpipe.h (modified) (2 diffs)
-
hmopen32.cpp (modified) (3 diffs)
-
hmopen32.h (modified) (1 diff)
-
hmsemaphore.cpp (modified) (1 diff)
-
hmthread.cpp (modified) (9 diffs)
-
hmthread.h (modified) (3 diffs)
-
initkernel32.cpp (modified) (10 diffs)
-
kernel32.mak (modified) (2 diffs)
-
kernel32dbg.def (modified) (7 diffs)
-
kobjects.cpp (modified) (15 diffs)
-
lang.cpp (modified) (5 diffs)
-
lfile.cpp (modified) (1 diff)
-
mailslot.cpp (modified) (3 diffs)
-
mmapview.cpp (modified) (5 diffs)
-
npipe.cpp (modified) (9 diffs)
-
ole2nls.c (modified) (1 diff)
-
os2heap.cpp (modified) (5 diffs)
-
oslibdos.cpp (modified) (5 diffs)
-
oslibexcept.cpp (modified) (3 diffs)
-
oslibmem.cpp (modified) (10 diffs)
-
oslibmem.h (modified) (1 diff)
-
oslibmisc.cpp (modified) (2 diffs)
-
oslibmisc.h (modified) (1 diff)
-
oslibthread.cpp (modified) (1 diff)
-
registry.cpp (modified) (1 diff)
-
thread.cpp (modified) (13 diffs)
-
time.cpp (modified) (6 diffs)
-
virtual.cpp (modified) (16 diffs)
-
windllbase.cpp (modified) (1 diff)
-
winexedummy.cpp (modified) (1 diff)
-
wprocess.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/Fileio.cpp
r9892 r21302 253 253 { 254 254 HANDLE hFind; 255 char *filename;256 int namelen;257 255 258 256 if(lpFileName == NULL || lpFindFileData == NULL || lpSearchFilter != NULL) … … 285 283 { 286 284 case FindExInfoStandard: 285 { 286 char *filename; 287 int namelen; 288 289 //Strip the backslash if 'x:\'. This function is supposed 290 //to work in that case, but fail with 'x:\directory\' 287 291 namelen = strlen(lpFileName); 288 if( lpFileName[namelen-1] == '\\')292 if(namelen == 3 && lpFileName[1] == ':' && lpFileName[2] == '\\') 289 293 { 290 294 filename = (char *)alloca(namelen+1); … … 296 300 297 301 return (HANDLE)OSLibDosFindFirst(filename, (WIN32_FIND_DATAA *)lpFindFileData); 302 } 298 303 299 304 default: //should never happen … … 445 450 //****************************************************************************** 446 451 //****************************************************************************** 447 DWORD WIN32API GetFileType(HANDLE hFile)448 {449 return(HMGetFileType(hFile));450 }451 //******************************************************************************452 //******************************************************************************453 DWORD WIN32API GetFileInformationByHandle(HANDLE arg1, BY_HANDLE_FILE_INFORMATION * arg2)454 {455 return(HMGetFileInformationByHandle(arg1,arg2));456 }457 //******************************************************************************458 //******************************************************************************459 BOOL WIN32API SetEndOfFile(HANDLE arg1)460 {461 return HMSetEndOfFile(arg1);462 }463 //******************************************************************************464 //******************************************************************************465 BOOL WIN32API SetFileTime(HANDLE arg1, const FILETIME * arg2,466 const FILETIME * arg3,467 const FILETIME * arg4)468 {469 return HMSetFileTime(arg1,470 arg2,471 arg3,472 arg4);473 }474 //******************************************************************************475 //******************************************************************************476 452 INT WIN32API CompareFileTime(FILETIME * lpft1, FILETIME * lpft2) 477 453 { … … 497 473 //****************************************************************************** 498 474 //****************************************************************************** 499 BOOL WIN32API GetFileTime(HANDLE hFile, LPFILETIME arg2, LPFILETIME arg3, LPFILETIME arg4)500 {501 return HMGetFileTime(hFile, arg2, arg3, arg4);502 }503 //******************************************************************************504 //******************************************************************************505 475 BOOL WIN32API CopyFileA(LPCSTR arg1, LPCSTR arg2, BOOL arg3) 506 476 { 477 dprintf(("CopyFileA %s %s %d", arg1, arg2, arg3)); 507 478 return OSLibDosCopyFile(arg1, arg2, arg3); 508 479 } … … 622 593 //****************************************************************************** 623 594 //****************************************************************************** 624 DWORD WIN32API GetFileSize(HANDLE arg1, PDWORD arg2)625 {626 return HMGetFileSize(arg1,627 arg2);628 }629 //******************************************************************************630 //******************************************************************************631 595 BOOL WIN32API DeleteFileA(LPCSTR lpszFile) 632 596 { … … 678 642 { 679 643 dprintf(("GetTempFileNameA %s %s", lpPathName, lpPrefixString)); 680 return O32_GetTempFileName(lpPathName, lpPrefixString, uUnique, lpTempFileName); 644 UINT rc = O32_GetTempFileName(lpPathName, lpPrefixString, uUnique, lpTempFileName); 645 dprintf(("GetTempFileNameA: returns %d (%s)\n", rc, rc > 0 && lpTempFileName ? lpTempFileName : "<nothing>")); 646 return rc; 681 647 } 682 648 //****************************************************************************** … … 812 778 //****************************************************************************** 813 779 //****************************************************************************** 814 DWORD WIN32API SetFilePointer(HANDLE hFile, LONG lDistanceToMove,815 PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)816 {817 return(HMSetFilePointer(hFile,818 lDistanceToMove,819 lpDistanceToMoveHigh,820 dwMoveMethod));821 }822 //******************************************************************************823 //******************************************************************************824 780 DWORD WIN32API GetFileAttributesA(LPCSTR lpszFileName) 825 781 { 826 782 DWORD rc, error; 827 783 784 //Disable error popus. 785 ULONG oldmode = SetErrorMode(SEM_FAILCRITICALERRORS); 786 828 787 rc = OSLibGetFileAttributes((LPSTR)lpszFileName); 788 789 SetErrorMode(oldmode); 829 790 830 791 //SvL: Open32 returns FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_NORMAL for … … 855 816 856 817 astring = UnicodeToAsciiString((LPWSTR)arg1); 818 dprintf(("GetFileAttributesW %s", astring)); 857 819 rc = GetFileAttributesA(astring); 858 820 FreeAsciiString(astring); … … 919 881 asciibuffer, asciipart)); 920 882 921 if(rc && asciibuffer)883 if(rc>0 && rc<nBufferLength && asciibuffer) 922 884 AsciiToUnicode(asciibuffer, 923 885 lpBuffer); … … 933 895 if(asciibuffer) free(asciibuffer); 934 896 return(rc); 935 }936 //******************************************************************************937 //******************************************************************************938 BOOL WIN32API LockFile(HANDLE arg1, DWORD arg2,939 DWORD arg3, DWORD arg4,940 DWORD arg5)941 {942 return HMLockFile(arg1,943 arg2,944 arg3,945 arg4,946 arg5);947 }948 949 950 /*****************************************************************************951 * Name : BOOL LockFileEx952 * Purpose : The LockFileEx function locks a byte range within an open file for shared or exclusive access.953 * Parameters: HANDLE hFile handle of file to lock954 * DWORD dwFlags functional behavior modification flags955 * DWORD dwReserved reserved, must be set to zero956 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock957 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock958 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset959 * Variables :960 * Result : TRUE / FALSE961 * Remark :962 * Status : UNTESTED STUB963 *964 * Author : Patrick Haller [Mon, 1998/06/15 08:00]965 *****************************************************************************/966 967 BOOL LockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved,968 DWORD nNumberOfBytesToLockLow,969 DWORD nNumberOfBytesToLockHigh,970 LPOVERLAPPED lpOverlapped)971 {972 return(HMLockFile(hFile,973 lpOverlapped->Offset,974 lpOverlapped->OffsetHigh,975 nNumberOfBytesToLockLow,976 nNumberOfBytesToLockHigh));977 897 } 978 898 //****************************************************************************** … … 1104 1024 1105 1025 return(rc); 1106 }1107 //******************************************************************************1108 /*****************************************************************************1109 ODINFUNCTION3(*, :,1110 HFILE, WIN32API,1111 OpenFile *, Purpose,1112 :, forwardOpenFile to Open321113 * Parameters:1114 * Variables :1115 * Result : API returncode1116 * Remark : modified for handle translation support1117 * Status : @@@PH verify if 0 is a valid "invalid handle" :)1118 *1119 * Author : Patrick Haller [Fri, 1998/06/12 02:53]1120 *****************************************************************************/1121 1122 HFILE WIN32API OpenFile(LPCSTR lpszFile, OFSTRUCT *lpOpenBuff,1123 UINT fuMode)1124 {1125 HFILE hFile;1126 1127 dprintf(("KERNEL32: OpenFile(%s, %08xh, %08xh)\n",1128 lpszFile,1129 lpOpenBuff,1130 fuMode));1131 1132 hFile = HMOpenFile(lpszFile, /* call open32 */1133 lpOpenBuff,1134 fuMode);1135 1136 return (hFile);1137 }1138 //******************************************************************************1139 //******************************************************************************1140 BOOL WIN32API UnlockFile(HANDLE arg1, DWORD arg2, DWORD arg3,1141 DWORD arg4, DWORD arg5)1142 {1143 return HMUnlockFile(arg1,1144 arg2,1145 arg3,1146 arg4,1147 arg5);1148 }1149 1150 1151 /*****************************************************************************1152 * Name : BOOL UnlockFileEx1153 * Purpose : The UnlockFileEx function unlocks a previously locked byte range in an open file.1154 * Parameters: HANDLE hFile handle of file to lock1155 * DWORD dwReserved reserved, must be set to zero1156 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock1157 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock1158 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset1159 * Variables :1160 * Result : TRUE / FALSE1161 * Remark :1162 * Status : UNTESTED STUB1163 *1164 * Author : Patrick Haller [Mon, 1998/06/15 08:00]1165 *****************************************************************************/1166 1167 BOOL WIN32API UnlockFileEx(HANDLE hFile, DWORD dwReserved,1168 DWORD nNumberOfBytesToLockLow,1169 DWORD nNumberOfBytesToLockHigh,1170 LPOVERLAPPED lpOverlapped)1171 {1172 return(HMUnlockFileEx(hFile, dwReserved,1173 nNumberOfBytesToLockLow,1174 nNumberOfBytesToLockHigh,1175 lpOverlapped));1176 1026 } 1177 1027 //****************************************************************************** … … 1675 1525 return hChange; 1676 1526 } 1677 //******************************************************************************1678 //******************************************************************************1679 BOOL WIN32API DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,1680 LPVOID lpInBuffer, DWORD nInBufferSize,1681 LPVOID lpOutBuffer, DWORD nOutBufferSize,1682 LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)1683 {1684 return HMDeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize,1685 lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped);1686 }1687 /*****************************************************************************1688 * Name : BOOL WIN32API CancelIo1689 * Purpose : The CancelIO function cancels all pending input and output1690 * (I/O) operations that were issued by the calling thread for1691 * the specified file handle. The function does not cancel1692 * I/O operations issued for the file handle by other threads.1693 * Parameters: HANDLE hFile file handle for which to cancel I/O1694 * Variables :1695 * Result : If the function succeeds, the return value is nonzero All pending1696 * I/O operations issued by the calling thread for the file handle1697 * were successfully canceled.1698 * If the function fails, the return value is zero.1699 * To get extended error information, call GetLastError.1700 * Remark : If there are any I/O operations in progress for the specified1701 * file HANDLE and they were issued by the calling thread, the1702 * CancelIO function cancels them.1703 * Note that the I/O operations must have been issued as1704 * overlapped I/O. If they were not, the I/O operations would not1705 * have returned to allow the thread to call the CancelIO function.1706 * Calling the CancelIO function with a file handle that was not1707 * opened with FILE_FLAG_OVERLAPPED does nothing.1708 * All I/O operations that are canceled will complete with the1709 * error ERROR_OPERATION_ABORTED. All completion notifications1710 * for the I/O operations will occur normally.1711 * Status :1712 *1713 * Author : Markus Montkowski [Thu, 1998/05/19 11:46]1714 *****************************************************************************/1715 BOOL WIN32API CancelIo(HANDLE hFile)1716 {1717 return HMCancelIo(hFile);1718 }1719 1527 /***************************************************************************** 1720 1528 * Name : BOOL GetOverlappedResult -
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 /* call the device handler */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 /* call the device handler */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 -
trunk/src/kernel32/KERNEL32.CPP
r10048 r21302 199 199 dprintf(("KERNEL32: GetLastError returned %d\n", rc)); 200 200 } 201 else dprintf (("KERNEL32: GetLastError returned no error\n", rc));201 else dprintf2(("KERNEL32: GetLastError returned no error\n", rc)); 202 202 return(rc); 203 203 } -
trunk/src/kernel32/KERNEL32.DEF
r10606 r21302 147 147 ; Ordinal0097 = _OS2Ordinal0097@?? @97 148 148 ; Ordinal0098 = _OS2Ordinal0098@?? @98 149 KERNEL32_99 = _KERNEL32_99@4 @99NONAME150 KERNEL32_100 = _KERNEL32_100@12 @100NONAME149 _KERNEL32_99@4 @99 NONAME 150 _KERNEL32_100@12 @100 NONAME 151 151 ; Ordinal0101 = _OS2Ordinal0101@?? @101 152 152 … … 1003 1003 GetVolumeNameForVolumeMountPointW = _GetVolumeNameForVolumeMountPointW@12 @915 1004 1004 1005 ; 1006 ; ENDOFEXPORTS 1007 ; Internal function marker 1008 ; 1005 1009 1006 1010 ; … … 1160 1164 InitializeSharedHeap @1276 NONAME 1161 1165 DestroySharedHeap @1277 NONAME 1166 _debug_smalloc @1278 NONAME 1167 _debug_smallocfill @1279 NONAME 1168 _debug_sfree @1280 NONAME 1162 1169 1163 1170 ;code memory allocation … … 1210 1217 1211 1218 OSLibDosDevIOCtl @2026 NONAME 1212 1213 OSLibImSetMsgQueueProperty @2029 NONAME1214 1219 1215 1220 fIsDBCSEnv @2103 NONAME … … 1252 1257 _ODIN_SetExceptionHandler@4 @3114 NONAME 1253 1258 _ODIN_UnsetExceptionHandler@4 @3115 NONAME 1259 1260 _PSAPI_EnumProcessModules@16 @3116 NONAME 1261 _PSAPI_GetModuleInformation@16 @3117 NONAME 1262 1263 _ODIN_SetProcessDword@12 @3118 NONAME 1254 1264 1255 1265 ; Char functions (forwarders from user32) … … 1286 1296 _IsCharUpperA@4 @3159 NONAME 1287 1297 _IsCharUpperW@4 @3160 NONAME 1298 1299 ; RAS functions 1300 RasRegisterObjectTracking = _RasRegisterObjectTracking@24 @3500 1301 RasDeregisterObjectTracking = _RasDeregisterObjectTracking@4 @3501 1302 RasAddObject = _RasAddObject@16 @3502 1303 RasRemoveObject = _RasRemoveObject@8 @3503 1304 RasSetObjectUserData = _RasSetObjectUserData@20 @3504 1305 RasQueryObjectUserData = _RasQueryObjectUserData@20 @3505 1306 RasInitialize = _RasInitialize@4 @3506 1307 RasUninitialize = _RasUninitialize@0 @3507 1308 _RasLog = _RasLog @3508 1309 RasLogMsg = _RasLogMsg@12 @3509 1310 RasLogObjects = _RasLogObjects@8 @3510 1311 RasEnterSerialize = _RasEnterSerialize@0 @3511 1312 RasExitSerialize = _RasExitSerialize@0 @3512 1313 _RasLogNoEOL = _RasLogNoEOL @3513 1314 RasOpenLogChannel = _RasOpenLogChannel@12 @3514 1315 RasWriteLogChannel = _RasWriteLogChannel@12 @3515 1316 RasCloseLogChannel = _RasCloseLogChannel@4 @3516 1317 _RasLog2 = _RasLog2 @3517 1318 RasLogMsg2 = _RasLogMsg2@16 @3518 1319 _RasLogNoEOL2 = _RasLogNoEOL2 @3519 1320 RasSaveContext = _RasSaveContext@4 @3520 1321 RasRestoreContext = _RasRestoreContext@4 @3521 1322 RasEntry = _RasEntry@12 @3522 1323 RasSetProcAddr = _RasSetProcAddr@12 @3523 1324 RasTrackMemFree = _RasTrackMemFree@8 @3524 1325 RasTrackMemAlloc = _RasTrackMemAlloc@8 @3525 1326 RasTrackMemRealloc = _RasTrackMemRealloc@12 @3526 1327 RasCountObjects = _RasCountObjects@12 @3527 1328 RasGetTrackHandle = _RasGetTrackHandle@4 @3528 1329 -
trunk/src/kernel32/comm.cpp
r7849 r21302 27 27 28 28 #include "unicode.h" 29 29 30 #include "handlemanager.h" 31 #include "hmhandle.h" 32 #include "hmcomm.h" 33 30 34 31 35 #define DBG_LOCALLOG DBG_comm 32 36 #include "dbglocal.h" 37 33 38 ODINDEBUGCHANNEL(KERNEL32-COMM) 39 40 static BOOL HMCommGetDefaultCommConfig( HANDLE hCommDev, 41 LPCOMMCONFIG lpCC, 42 LPDWORD lpdwSize); 43 static BOOL HMCommSetDefaultCommConfig( HANDLE hCommDev, 44 LPCOMMCONFIG lpCC, 45 DWORD dwSize); 34 46 35 47 /***************************************************************************** … … 606 618 607 619 /***************************************************************************** 608 * @returns 609 * @param hFile Comport handle 610 * @remark 611 * @status untested 612 * @author Markus Montkowski 620 * Name : HMCOMGetCommState 621 * Purpose : router function for GetCommState 622 * Parameters: 623 * Variables : 624 * Result : 625 * Remark : 626 * Status : 627 * 628 * Author : Achim Hasenmueller [Sat, 1999/11/27 13:40] 613 629 *****************************************************************************/ 614 630 615 BOOL WIN32API ClearCommBreak(HANDLE hFile ) 616 { 617 return HMCommClearCommBreak(hFile); 618 } 619 620 /***************************************************************************** 621 * @returns 622 * @param hFile Comport handle 623 * @param dwInQueue recommended internal buffer size in bytes 624 * @param dwOutQueue recommended internal buffer size in bytes 625 * @remark 626 * @status untested 627 * @author Markus Montkowski 628 *****************************************************************************/ 629 630 BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue ) 631 { 632 return HMCommSetupComm(hFile, dwInQueue, dwOutQueue); 633 } 634 635 /***************************************************************************** 636 * @returns 637 * @param hFile Comport handle 638 * @param dwFunc extended function to perform 639 * @remark 640 * @status untested 641 * @author Markus Montkowski 642 *****************************************************************************/ 643 644 BOOL WIN32API EscapeCommFunction(HANDLE hFile, UINT dwFunc ) 645 { 646 return HMCommEscapeCommFunction(hFile, dwFunc); 647 } 648 649 //------------------------------------------------------------------------------ 650 651 BOOL WIN32API GetCommConfig( HANDLE hCommDev, LPCOMMCONFIG lpCC, LPDWORD lpdwSize ) 652 { 653 return HMCommGetCommConfig(hCommDev,lpCC, lpdwSize); 654 } 655 656 //------------------------------------------------------------------------------ 657 658 BOOL WIN32API GetCommModemStatus( HANDLE hFile, LPDWORD lpModemStat ) 659 { 660 return HMCommGetCommModemStatus(hFile,lpModemStat); 661 } 662 663 //------------------------------------------------------------------------------ 664 665 BOOL WIN32API SetCommBreak( HANDLE hFile ) 666 { 667 return HMCommSetCommBreak(hFile); 668 } 669 670 //------------------------------------------------------------------------------ 671 672 BOOL WIN32API SetCommConfig( HANDLE hCommDev, LPCOMMCONFIG lpCC, DWORD dwSize ) 673 { 674 return HMCommSetCommConfig(hCommDev,lpCC, dwSize); 675 } 676 677 //------------------------------------------------------------------------------ 678 679 BOOL WIN32API TransmitCommChar( HANDLE hFile, CHAR cChar ) 680 { 681 return HMCommTransmitCommChar(hFile,cChar); 682 } 683 684 //------------------------------------------------------------------------------ 685 686 BOOL WIN32API SetCommTimeouts( HANDLE hCommDev, LPCOMMTIMEOUTS lpctmo) 687 { 688 return HMCommSetCommTimeouts(hCommDev, lpctmo); 689 } 690 691 //------------------------------------------------------------------------------ 692 693 BOOL WIN32API GetCommTimeouts(HANDLE hCommDev, LPCOMMTIMEOUTS lpctmo) 694 { 695 return HMCommGetCommTimeouts(hCommDev, lpctmo); 696 } 697 698 //------------------------------------------------------------------------------ 699 700 BOOL WIN32API GetCommState(HANDLE hCommDev, LPDCB lpDCB) 701 { 702 return HMCommGetCommState(hCommDev, lpDCB); 703 } 704 705 //------------------------------------------------------------------------------ 706 707 BOOL WIN32API SetCommState(HANDLE hCommDev, LPDCB lpDCB) 708 { 709 return HMCommSetCommState(hCommDev, lpDCB); 710 } 711 712 //------------------------------------------------------------------------------ 713 714 BOOL WIN32API ClearCommError(HANDLE hCommDev, LPDWORD lpdwErrors, LPCOMSTAT lpcst) 715 { 716 return HMCommClearCommError(hCommDev, lpdwErrors, lpcst); 717 } 718 719 //------------------------------------------------------------------------------ 720 721 BOOL WIN32API PurgeComm(HANDLE hCommDev, DWORD fdwAction) 722 { 723 return HMCommPurgeComm(hCommDev,fdwAction); 724 } 725 726 //------------------------------------------------------------------------------ 727 728 BOOL WIN32API SetCommMask(HANDLE hCommDev, DWORD fdwEvtMask) 729 { 730 return HMCommSetCommMask( hCommDev,fdwEvtMask); 731 } 732 733 //------------------------------------------------------------------------------ 734 735 BOOL WIN32API GetCommMask(HANDLE hCommDev, LPDWORD lpfdwEvtMask) 736 { 737 return HMCommGetCommMask( hCommDev,lpfdwEvtMask); 738 } 739 740 //------------------------------------------------------------------------------ 741 742 BOOL WIN32API GetCommProperties(HANDLE hCommDev, LPCOMMPROP lpcmmp) 743 { 744 return HMCommGetCommProperties(hCommDev, lpcmmp); 745 } 746 747 //------------------------------------------------------------------------------ 748 631 BOOL WIN32API GetCommState(HANDLE hCommDev, LPDCB lpdcb) 632 { 633 BOOL bResult; /* result from the device handler's API */ 634 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 635 636 /* validate handle */ 637 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 638 if (pHMHandle == NULL) /* error ? */ 639 { 640 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 641 } 642 643 if(IsBadWritePtr(lpdcb,sizeof(DCB))) 644 { 645 SetLastError(ERROR_INVALID_PARAMETER); 646 return FALSE; 647 } 648 649 bResult = pHMHandle->pDeviceHandler->GetCommState(&pHMHandle->hmHandleData, 650 lpdcb); 651 652 return (bResult); /* deliver return code */ 653 } 654 //****************************************************************************** 655 //****************************************************************************** 749 656 BOOL WIN32API WaitCommEvent( HANDLE hCommDev, 750 LPDWORD lpfdwEvtMask, 751 LPOVERLAPPED lpo) 752 { 753 return HMCommWaitCommEvent(hCommDev, lpfdwEvtMask, lpo); 754 } 755 756 //------------------------------------------------------------------------------ 757 657 LPDWORD lpfdwEvtMask, 658 LPOVERLAPPED lpo) 659 { 660 BOOL bResult; /* result from the device handler's API */ 661 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 662 663 /* validate handle */ 664 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 665 if (pHMHandle == NULL) /* error ? */ 666 { 667 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 668 } 669 670 if(NULL!=lpo && IsBadReadPtr(lpo,sizeof(OVERLAPPED)) ) 671 { 672 SetLastError(ERROR_INVALID_PARAMETER); 673 return FALSE; 674 } 675 676 bResult = pHMHandle->pDeviceHandler->WaitCommEvent( &pHMHandle->hmHandleData, 677 lpfdwEvtMask, 678 lpo); 679 680 return (bResult); /* deliver return code */ 681 } 682 //****************************************************************************** 683 //****************************************************************************** 684 BOOL WIN32API GetCommProperties( HANDLE hCommDev, 685 LPCOMMPROP lpcmmp) 686 { 687 BOOL bResult; /* result from the device handler's API */ 688 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 689 690 /* validate handle */ 691 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 692 if (pHMHandle == NULL) /* error ? */ 693 { 694 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 695 } 696 697 if(IsBadWritePtr(lpcmmp,sizeof(COMMPROP)) ) 698 { 699 SetLastError(ERROR_INVALID_PARAMETER); 700 return FALSE; 701 } 702 703 bResult = pHMHandle->pDeviceHandler->GetCommProperties( &pHMHandle->hmHandleData, 704 lpcmmp); 705 706 return (bResult); /* deliver return code */ 707 } 708 //****************************************************************************** 709 //****************************************************************************** 710 BOOL WIN32API GetCommMask( HANDLE hCommDev, 711 LPDWORD lpfdwEvtMask) 712 { 713 BOOL bResult; /* result from the device handler's API */ 714 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 715 716 /* validate handle */ 717 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 718 if (pHMHandle == NULL) /* error ? */ 719 { 720 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 721 } 722 723 if(IsBadWritePtr(lpfdwEvtMask,sizeof(DWORD)) ) 724 { 725 SetLastError(ERROR_INVALID_PARAMETER); 726 return FALSE; 727 } 728 729 bResult = pHMHandle->pDeviceHandler->GetCommMask( &pHMHandle->hmHandleData, 730 lpfdwEvtMask); 731 732 return (bResult); /* deliver return code */ 733 } 734 //****************************************************************************** 735 //****************************************************************************** 736 BOOL WIN32API SetCommMask( HANDLE hCommDev, 737 DWORD fdwEvtMask) 738 { 739 BOOL bResult; /* result from the device handler's API */ 740 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 741 742 /* validate handle */ 743 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 744 if (pHMHandle == NULL) /* error ? */ 745 { 746 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 747 } 748 749 bResult = pHMHandle->pDeviceHandler->SetCommMask( &pHMHandle->hmHandleData, 750 fdwEvtMask); 751 752 return (bResult); /* deliver return code */ 753 } 754 //****************************************************************************** 755 //****************************************************************************** 756 BOOL WIN32API PurgeComm( HANDLE hCommDev, 757 DWORD fdwAction) 758 { 759 BOOL bResult; /* result from the device handler's API */ 760 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 761 762 /* validate handle */ 763 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 764 if (pHMHandle == NULL) /* error ? */ 765 { 766 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 767 } 768 769 bResult = pHMHandle->pDeviceHandler->PurgeComm( &pHMHandle->hmHandleData, 770 fdwAction); 771 772 return (bResult); /* deliver return code */ 773 } 774 //****************************************************************************** 775 //****************************************************************************** 776 BOOL WIN32API ClearCommError( HANDLE hCommDev, 777 LPDWORD lpdwErrors, 778 LPCOMSTAT lpcst) 779 { 780 BOOL bResult; /* result from the device handler's API */ 781 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 782 783 /* validate handle */ 784 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 785 if (pHMHandle == NULL) /* error ? */ 786 { 787 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 788 } 789 790 if((lpdwErrors != NULL && IsBadWritePtr(lpdwErrors,sizeof(DWORD))) || 791 (NULL!=lpcst && IsBadWritePtr(lpcst,sizeof(COMSTAT)) ) ) 792 { 793 SetLastError(ERROR_INVALID_PARAMETER); 794 return FALSE; 795 } 796 797 bResult = pHMHandle->pDeviceHandler->ClearCommError(&pHMHandle->hmHandleData, 798 lpdwErrors, 799 lpcst); 800 801 return (bResult); /* deliver return code */ 802 } 803 //****************************************************************************** 804 //****************************************************************************** 805 BOOL WIN32API SetCommState( HANDLE hCommDev, 806 LPDCB lpdcb) 807 { 808 BOOL bResult; /* result from the device handler's API */ 809 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 810 811 /* validate handle */ 812 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 813 if (pHMHandle == NULL) /* error ? */ 814 { 815 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 816 } 817 818 if(IsBadReadPtr(lpdcb,sizeof(DCB)) ) 819 { 820 SetLastError(ERROR_INVALID_PARAMETER); 821 return FALSE; 822 } 823 824 bResult = pHMHandle->pDeviceHandler->SetCommState(&pHMHandle->hmHandleData, 825 lpdcb); 826 827 return (bResult); /* deliver return code */ 828 } 829 //****************************************************************************** 830 //****************************************************************************** 831 BOOL WIN32API GetCommTimeouts( HANDLE hCommDev, 832 LPCOMMTIMEOUTS lpctmo) 833 { 834 BOOL bResult; /* result from the device handler's API */ 835 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 836 837 /* validate handle */ 838 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 839 if (pHMHandle == NULL) /* error ? */ 840 { 841 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 842 } 843 844 if(IsBadWritePtr(lpctmo,sizeof(COMMTIMEOUTS)) ) 845 { 846 SetLastError(ERROR_INVALID_PARAMETER); 847 return FALSE; 848 } 849 850 bResult = pHMHandle->pDeviceHandler->GetCommTimeouts( &pHMHandle->hmHandleData, 851 lpctmo); 852 853 return (bResult); /* deliver return code */ 854 } 855 //****************************************************************************** 856 //****************************************************************************** 857 BOOL WIN32API GetCommModemStatus( HANDLE hCommDev, 858 LPDWORD lpModemStat ) 859 { 860 BOOL bResult; /* result from the device handler's API */ 861 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 862 863 /* validate handle */ 864 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 865 if (pHMHandle == NULL) /* error ? */ 866 { 867 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 868 } 869 870 if(IsBadWritePtr(lpModemStat,sizeof(DWORD)) ) 871 { 872 SetLastError(ERROR_INVALID_PARAMETER); 873 return FALSE; 874 } 875 876 bResult = pHMHandle->pDeviceHandler->GetCommModemStatus( &pHMHandle->hmHandleData, 877 lpModemStat); 878 879 return (bResult); /* deliver return code */ 880 } 881 //****************************************************************************** 882 //****************************************************************************** 883 BOOL WIN32API SetCommTimeouts( HANDLE hCommDev, 884 LPCOMMTIMEOUTS lpctmo) 885 { 886 BOOL bResult; /* result from the device handler's API */ 887 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 888 889 /* validate handle */ 890 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 891 if (pHMHandle == NULL) /* error ? */ 892 { 893 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 894 } 895 896 if(IsBadReadPtr(lpctmo,sizeof(COMMTIMEOUTS)) ) 897 { 898 SetLastError(ERROR_INVALID_PARAMETER); 899 return FALSE; 900 } 901 902 bResult = pHMHandle->pDeviceHandler->SetCommTimeouts( &pHMHandle->hmHandleData, 903 lpctmo); 904 905 return (bResult); /* deliver return code */ 906 } 907 //****************************************************************************** 908 //****************************************************************************** 909 BOOL WIN32API TransmitCommChar( HANDLE hCommDev, 910 CHAR cChar ) 911 { 912 BOOL bResult; /* result from the device handler's API */ 913 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 914 915 /* validate handle */ 916 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 917 if (pHMHandle == NULL) /* error ? */ 918 { 919 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 920 } 921 922 bResult = pHMHandle->pDeviceHandler->TransmitCommChar( &pHMHandle->hmHandleData, 923 cChar); 924 925 return (bResult); /* deliver return code */ 926 } 927 //****************************************************************************** 928 //****************************************************************************** 929 BOOL WIN32API SetCommConfig( HANDLE hCommDev, 930 LPCOMMCONFIG lpCC, 931 DWORD dwSize ) 932 { 933 BOOL bResult; /* result from the device handler's API */ 934 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 935 936 /* validate handle */ 937 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 938 if (pHMHandle == NULL) /* error ? */ 939 { 940 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 941 } 942 943 if( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) || 944 dwSize < sizeof(COMMCONFIG) ) 945 { 946 SetLastError(ERROR_INVALID_PARAMETER); 947 return FALSE; 948 } 949 950 bResult = pHMHandle->pDeviceHandler->SetCommConfig( &pHMHandle->hmHandleData, 951 lpCC, 952 dwSize); 953 954 return (bResult); /* deliver return code */ 955 } 956 //****************************************************************************** 957 //****************************************************************************** 958 BOOL WIN32API SetCommBreak( HANDLE hCommDev ) 959 { 960 BOOL bResult; /* result from the device handler's API */ 961 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 962 963 /* validate handle */ 964 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 965 if (pHMHandle == NULL) /* error ? */ 966 { 967 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 968 } 969 970 bResult = pHMHandle->pDeviceHandler->SetCommBreak( &pHMHandle->hmHandleData); 971 972 return (bResult); /* deliver return code */ 973 } 974 //****************************************************************************** 975 //****************************************************************************** 976 BOOL WIN32API GetCommConfig( HANDLE hCommDev, 977 LPCOMMCONFIG lpCC, 978 LPDWORD lpdwSize ) 979 { 980 BOOL bResult; /* result from the device handler's API */ 981 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 982 983 /* validate handle */ 984 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 985 if (pHMHandle == NULL) /* error ? */ 986 { 987 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 988 } 989 990 if(IsBadWritePtr(lpdwSize,sizeof(DWORD)) ) 991 { 992 SetLastError(ERROR_INVALID_PARAMETER); 993 return FALSE; 994 } 995 996 if( IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) || 997 *lpdwSize< sizeof(COMMCONFIG) ) 998 { 999 SetLastError(ERROR_INSUFFICIENT_BUFFER); 1000 *lpdwSize= sizeof(COMMCONFIG); 1001 return FALSE; 1002 } 1003 1004 bResult = pHMHandle->pDeviceHandler->GetCommConfig( &pHMHandle->hmHandleData, 1005 lpCC, 1006 lpdwSize); 1007 1008 return (bResult); /* deliver return code */ 1009 } 1010 //****************************************************************************** 1011 //****************************************************************************** 1012 BOOL WIN32API EscapeCommFunction( HANDLE hCommDev, 1013 UINT dwFunc ) 1014 { 1015 BOOL bResult; /* result from the device handler's API */ 1016 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1017 1018 /* validate handle */ 1019 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 1020 if (pHMHandle == NULL) /* error ? */ 1021 { 1022 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 1023 } 1024 1025 switch(dwFunc) 1026 { 1027 case CLRDTR: 1028 case CLRRTS: 1029 case SETDTR: 1030 case SETRTS: 1031 case SETXOFF: 1032 case SETXON: 1033 bResult = pHMHandle->pDeviceHandler->EscapeCommFunction( &pHMHandle->hmHandleData, 1034 dwFunc); 1035 break; 1036 case SETBREAK: 1037 bResult = pHMHandle->pDeviceHandler->SetCommBreak(&pHMHandle->hmHandleData); 1038 break; 1039 case CLRBREAK: 1040 bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData); 1041 break; 1042 default: 1043 SetLastError(ERROR_INVALID_PARAMETER); 1044 bResult = FALSE; 1045 } 1046 1047 1048 return (bResult); /* deliver return code */ 1049 } 1050 //****************************************************************************** 1051 //****************************************************************************** 1052 BOOL WIN32API SetupComm( HANDLE hCommDev, 1053 DWORD dwInQueue, 1054 DWORD dwOutQueue) 1055 { 1056 BOOL bResult; /* result from the device handler's API */ 1057 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1058 1059 /* validate handle */ 1060 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 1061 if (pHMHandle == NULL) /* error ? */ 1062 { 1063 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 1064 } 1065 1066 bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData, 1067 dwInQueue, 1068 dwOutQueue); 1069 1070 return (bResult); /* deliver return code */ 1071 } 1072 //****************************************************************************** 1073 //****************************************************************************** 1074 BOOL WIN32API ClearCommBreak(HANDLE hCommDev) 1075 { 1076 BOOL bResult; /* result from the device handler's API */ 1077 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1078 1079 /* validate handle */ 1080 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 1081 if (pHMHandle == NULL) /* error ? */ 1082 { 1083 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 1084 } 1085 1086 bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData); 1087 1088 return (bResult); /* deliver return code */ 1089 } 1090 //****************************************************************************** 1091 //****************************************************************************** 1092 static BOOL HMCommSetDefaultCommConfig( HANDLE hCommDev, 1093 LPCOMMCONFIG lpCC, 1094 DWORD dwSize) 1095 { 1096 BOOL bResult; /* result from the device handler's API */ 1097 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1098 1099 /* validate handle */ 1100 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 1101 if (pHMHandle == NULL) /* error ? */ 1102 { 1103 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 1104 } 1105 1106 if( (lpCC!=NULL) && 1107 ( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) || 1108 dwSize != sizeof(COMMCONFIG) ) ) 1109 { 1110 SetLastError(ERROR_INVALID_PARAMETER); 1111 return FALSE; 1112 } 1113 1114 bResult = pHMHandle->pDeviceHandler->SetDefaultCommConfig(&pHMHandle->hmHandleData, 1115 lpCC, 1116 dwSize); 1117 1118 return (bResult); /* deliver return code */ 1119 } 1120 //****************************************************************************** 1121 //****************************************************************************** 1122 static BOOL HMCommGetDefaultCommConfig( HANDLE hCommDev, 1123 LPCOMMCONFIG lpCC, 1124 LPDWORD lpdwSize) 1125 { 1126 BOOL bResult; /* result from the device handler's API */ 1127 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 1128 1129 /* validate handle */ 1130 pHMHandle = HMHandleQueryPtr(hCommDev); /* get the index */ 1131 if (pHMHandle == NULL) /* error ? */ 1132 { 1133 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 1134 } 1135 1136 if(IsBadWritePtr(lpdwSize,sizeof(DWORD))) 1137 { 1138 SetLastError(ERROR_INVALID_PARAMETER); 1139 return FALSE; 1140 } 1141 1142 bResult = pHMHandle->pDeviceHandler->GetDefaultCommConfig( &pHMHandle->hmHandleData, 1143 lpCC, 1144 lpdwSize); 1145 1146 return (bResult); /* deliver return code */ 1147 } 1148 //****************************************************************************** 1149 //****************************************************************************** -
trunk/src/kernel32/conbuffer.cpp
r10471 r21302 2491 2491 2492 2492 /* simply forward the request to that routine */ 2493 return (/*HMDeviceConsoleBufferClass::*/WriteFile(pHMHandleData, 2494 lpvBuffer, 2495 cchToWrite, 2496 lpcchWritten, 2497 NULL, NULL)); 2493 return (WriteFile(pHMHandleData, lpvBuffer, cchToWrite, lpcchWritten, NULL, NULL)); 2498 2494 } 2499 2495 … … 2544 2540 2545 2541 /* simply forward the request to that routine */ 2546 rc = HMDeviceConsoleBufferClass::WriteFile(pHMHandleData, 2547 pszAscii, 2548 alen, 2549 lpcchWritten, 2550 NULL, NULL); 2542 rc = WriteFile(pHMHandleData, pszAscii, alen, lpcchWritten, NULL, NULL); 2551 2543 2552 2544 *lpcchWritten = MultiByteToWideChar( GetConsoleCP(), 0, pszAscii, *lpcchWritten, 0, 0 ); -
trunk/src/kernel32/critsection.cpp
r10201 r21302 24 24 DECLARE_DEBUG_CHANNEL(relay) 25 25 26 26 #ifdef DEBUG 27 28 #include "heapshared.h" 29 #include <vmutex.h> 30 31 typedef struct _CritSectDebug 32 { 33 struct _CritSectDebug *next; 34 struct _CritSectDebug *prev; 35 CRITICAL_SECTION *ThisSect; 36 HANDLE CreatingThread; 37 LONG EnteredCount; 38 } CritSectDebug; 39 40 CritSectDebug *csfirst = NULL; 41 CritSectDebug *cslast = NULL; 42 ULONG ulCritSectCount = 0; 43 44 VMutex csmutex; 45 46 void printCriticalSectionStatistic (void) 47 { 48 ULONG leakedSectionsCount = 0; 49 CritSectDebug *iter = csfirst; 50 51 while (iter) 52 { 53 dprintf(("%d: Section %p, created by thread %8.8X, entered %d\n", leakedSectionsCount, iter->ThisSect, iter->CreatingThread, iter->EnteredCount)); 54 leakedSectionsCount++; 55 56 CritSectDebug *next = iter->next; 57 _sfree(iter); 58 iter = next; 59 } 60 61 dprintf(("Total leaked sections %d, section count is %d\n", leakedSectionsCount, ulCritSectCount)); 62 } 63 64 CritSectDebug *checkCritSectDebug (void *DebugInfo) 65 { 66 CritSectDebug *iter = csfirst; 67 68 while (iter) 69 { 70 if (iter == DebugInfo) 71 { 72 break; 73 } 74 75 iter = iter->next; 76 } 77 78 if (!iter) 79 { 80 dprintf(("DebugInfo is not in our list: %p!!!\n", DebugInfo)); 81 } 82 83 return iter; 84 } 85 86 void InitializeDebugInfo (CRITICAL_SECTION *crit) 87 { 88 csmutex.enter(); 89 if (checkCritSectDebug (crit->DebugInfo) != NULL) 90 { 91 dprintf(("InitializeDebugInfo already initialized: DebugInfo %p", crit->DebugInfo)); 92 } 93 else 94 { 95 CritSectDebug *pdbg = (CritSectDebug *)_smalloc(sizeof (CritSectDebug)); 96 if (!pdbg) 97 { 98 dprintf(("InitializeDebugInfo failed to allocate debug info!!!")); 99 } 100 else 101 { 102 dprintf(("InitializeDebugInfo DebugInfo: %p", pdbg)); 103 pdbg->ThisSect = crit; 104 pdbg->CreatingThread = ODIN_GetCurrentThreadId(); 105 pdbg->EnteredCount = 0; 106 107 pdbg->next = NULL; 108 pdbg->prev = cslast; 109 if (cslast) 110 { 111 cslast->next = pdbg; 112 } 113 114 cslast = pdbg; 115 116 if (!csfirst) 117 { 118 csfirst = pdbg; 119 } 120 } 121 122 crit->DebugInfo = pdbg; 123 124 ulCritSectCount++; 125 } 126 127 csmutex.leave(); 128 } 129 130 void DeleteDebugInfo (CRITICAL_SECTION *crit) 131 { 132 csmutex.enter(); 133 134 CritSectDebug *pdbg = checkCritSectDebug (crit->DebugInfo); 135 136 if (pdbg) 137 { 138 dprintf(("Deleting critical section with DebugInfo == %p\n", pdbg)); 139 140 if (pdbg->next) 141 { 142 pdbg->next->prev = pdbg->prev; 143 } 144 else 145 { 146 cslast = pdbg->prev; 147 } 148 149 if (pdbg->prev) 150 { 151 pdbg->prev->next = pdbg->next; 152 } 153 else 154 { 155 csfirst = pdbg->next; 156 } 157 158 _sfree (pdbg); 159 160 ulCritSectCount--; 161 162 crit->DebugInfo = NULL; 163 } 164 165 csmutex.leave(); 166 } 167 168 void DebugEnterCritSect (CRITICAL_SECTION *crit) 169 { 170 csmutex.enter(); 171 172 CritSectDebug *pdbg = checkCritSectDebug (crit->DebugInfo); 173 174 if (!pdbg) 175 { 176 InitializeDebugInfo (crit); 177 pdbg = checkCritSectDebug (crit->DebugInfo); 178 } 179 180 if (pdbg) 181 { 182 pdbg->EnteredCount++; 183 } 184 185 csmutex.leave(); 186 } 187 188 void DebugLeaveCritSect (CRITICAL_SECTION *crit) 189 { 190 csmutex.enter(); 191 192 CritSectDebug *pdbg = checkCritSectDebug (crit->DebugInfo); 193 194 if (pdbg) 195 { 196 pdbg->EnteredCount--; 197 } 198 199 csmutex.leave(); 200 } 201 #else 202 #define InitializeDebugInfo(a) 203 #define DeleteDebugInfo(a) 204 #define DebugEnterCritSect(a) 205 #define DebugLeaveCritSect(a) 206 #endif 207 208 209 210 /*********************************************************************** 211 * get_semaphore (allocate semaphore only when needed) 212 * Assign the semaphore atomically 213 */ 214 static inline HANDLE get_semaphore (CRITICAL_SECTION *crit) 215 { 216 HANDLE ret = crit->LockSemaphore; 217 218 if (!ret) 219 { 220 HANDLE sem = CreateSemaphoreA (NULL, 0, 1, NULL); 221 222 if (sem) 223 { 224 ret = InterlockedCompareExchange ((PLONG)&crit->LockSemaphore, sem, NULL); 225 226 if (ret) 227 { 228 // semaphore already assigned 229 CloseHandle (sem); 230 } 231 else 232 { 233 ret = sem; 234 } 235 } 236 } 237 238 return ret; 239 } 27 240 28 241 /*********************************************************************** … … 32 245 { 33 246 dprintf(("InitializeCriticalSection %x", crit)); 247 248 InitializeDebugInfo (crit); 249 34 250 crit->LockCount = -1; 35 251 crit->RecursionCount = 0; 36 252 crit->OwningThread = 0; 37 crit->LockSemaphore = CreateSemaphoreA( NULL, 0, 1, NULL );38 crit->Reserved = ODIN_GetCurrentProcessId();253 crit->LockSemaphore = 0; 254 crit->Reserved = 0; 39 255 } 40 256 … … 48 264 BOOL WINAPI InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD spincount ) 49 265 { 50 if(spincount) dprintf(("critsection=%p: spincount=%ld not supported\n", crit, spincount)); 266 if (spincount) dprintf(("critsection=%p: spincount=%ld not supported\n", crit, spincount)); 267 InitializeCriticalSection( crit ); 51 268 crit->Reserved = spincount; 52 InitializeCriticalSection( crit );53 269 return TRUE; 54 270 } … … 61 277 dprintf(("DeleteCriticalSection %x", crit)); 62 278 63 if (crit->LockSemaphore)64 { 279 DeleteDebugInfo (crit); 280 65 281 if (crit->RecursionCount) /* Should not happen */ 66 282 dprintf(("Deleting owned critical section (%p)\n", crit )); … … 69 285 crit->RecursionCount = 0; 70 286 crit->OwningThread = 0; 71 CloseHandle( crit->LockSemaphore );287 if (crit->LockSemaphore) CloseHandle( crit->LockSemaphore ); 72 288 crit->LockSemaphore = 0; 73 crit->Reserved = (DWORD)-1; 74 } 289 crit->Reserved = 0; 75 290 } 76 291 … … 81 296 void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit ) 82 297 { 83 DWORD res;84 85 298 dprintf2(("EnterCriticalSection %x", crit)); 86 if (!crit->LockSemaphore) 87 { 88 dprintf(("entering uninitialized section(%p)?\n",crit)); 89 InitializeCriticalSection(crit); 90 } 91 if (InterlockedIncrement( &crit->LockCount )) 299 300 #if 0 301 /* bird: this is bullcrap, memset(&MyCritSect, 0, sizeof(MyCritSect)) doesn't work in w2k (at least not here). 302 * besides this isn't safe. The leave code first sets owner=0 then decrements the lock, heavens knows what 303 * will happen if the thread is preemted there... 304 */ 305 // check for uninitialized critical section created with memset (, 0, ) 306 if (crit->LockCount != -1 && crit->OwningThread == 0) 307 { 308 dprintf(("Uninitialized section!!!")); 309 __interrupt(3); 310 InitializeCriticalSection (crit); 311 } 312 #endif 313 314 DebugEnterCritSect (crit); 315 316 if (InterlockedIncrement (&crit->LockCount)) 92 317 { 93 318 if (crit->OwningThread == ODIN_GetCurrentThreadId()) … … 100 325 for (;;) 101 326 { 102 res = WaitForSingleObject( crit->LockSemaphore, 5000L ); 103 if ( res == WAIT_TIMEOUT ) 327 HANDLE sem = get_semaphore (crit); 328 DWORD res = WaitForSingleObject (sem, 5000L); 329 330 if (res == WAIT_TIMEOUT) 104 331 { 105 dprintf(("Critical section %p wait timed out, retrying (60 sec)\n", crit ));106 res = WaitForSingleObject ( crit->LockSemaphore, 60000L);107 if ( res == WAIT_TIMEOUT && TRACE_ON(relay))332 dprintf(("Critical section %p wait timed out, retrying (60 sec)\n", crit)); 333 res = WaitForSingleObject (sem, 60000L); 334 if (res == WAIT_TIMEOUT && TRACE_ON(relay)) 108 335 { 109 dprintf(("Critical section %p wait timed out, retrying (5 min)\n", crit ));110 res = WaitForSingleObject ( crit->LockSemaphore, 300000L);336 dprintf(("Critical section %p wait timed out, retrying (5 min)\n", crit)); 337 res = WaitForSingleObject (sem, 300000L); 111 338 } 112 339 } 340 113 341 if (res == STATUS_WAIT_0) break; 114 342 … … 125 353 #endif 126 354 dprintf(("ERROR: EnterCritSection: WaitForSingleObject returned %d -> RaiseException", res)); 127 RaiseException(EXCEPTION_CRITICAL_SECTION_WAIT, 0, 1, (DWORD *)crit); 128 } 129 } 355 RaiseException(EXCEPTION_CRITICAL_SECTION_WAIT, 0, 1, (DWORD *)&crit); 356 } 357 } 358 130 359 crit->OwningThread = ODIN_GetCurrentThreadId(); 131 360 crit->RecursionCount = 1; … … 138 367 BOOL WINAPI TryEnterCriticalSection( CRITICAL_SECTION *crit ) 139 368 { 369 BOOL ret = FALSE; 370 140 371 dprintf2(("TryEnterCriticalSection %x", crit)); 141 if (InterlockedIncrement( &crit->LockCount )) 372 373 if (InterlockedCompareExchange (&crit->LockCount, 0, -1) == -1) 374 { 375 // LockCount was successfully changed from -1 to 0 and we own the section now 376 crit->OwningThread = ODIN_GetCurrentThreadId(); 377 crit->RecursionCount = 1; 378 ret = TRUE; 379 } 380 else 142 381 { 143 382 if (crit->OwningThread == ODIN_GetCurrentThreadId()) 144 383 { 384 InterlockedIncrement (&crit->LockCount); 145 385 crit->RecursionCount++; 146 return TRUE; 147 } 148 /* FIXME: this doesn't work */ 149 InterlockedDecrement( &crit->LockCount ); 150 return FALSE; 151 } 152 crit->OwningThread = ODIN_GetCurrentThreadId(); 153 crit->RecursionCount = 1; 154 return TRUE; 386 ret = TRUE; 387 } 388 } 389 390 if (ret) DebugEnterCritSect (crit); 391 392 return ret; 155 393 } 156 394 … … 162 400 { 163 401 dprintf2(("LeaveCriticalSection %x", crit)); 164 if (crit->OwningThread != ODIN_GetCurrentThreadId()) return; 402 403 DebugLeaveCritSect (crit); 404 405 /* 406 * Wine and Windows don't check if the caller is the owner. 407 * We leave this check in for debugging since odin32 may use this 408 * internally and it's good to know if we mess up. 409 */ 410 #ifdef DEBUG 411 if (crit->OwningThread != ODIN_GetCurrentThreadId()) 412 { 413 dprintf(("LeaveCriticalSection: Not owner!! OwningThread=%d CurThread=%d\n", crit->OwningThread, ODIN_GetCurrentThreadId())); 414 DebugInt3(); 415 return; 416 } 417 #endif 165 418 166 419 if (--crit->RecursionCount) 167 420 { 168 InterlockedDecrement( &crit->LockCount);421 InterlockedDecrement(&crit->LockCount); 169 422 return; 170 423 } 424 171 425 crit->OwningThread = 0; 426 172 427 if (InterlockedDecrement( &crit->LockCount ) >= 0) 173 428 { 174 429 /* Someone is waiting */ 175 ReleaseSemaphore( crit->LockSemaphore, 1, NULL ); 430 HANDLE sem = get_semaphore (crit); 431 ReleaseSemaphore (sem, 1, NULL); 176 432 } 177 433 } … … 184 440 { 185 441 dprintf(("MakeCriticalSectionGlobal %x", crit)); 186 crit->LockSemaphore = ConvertToGlobalHandle( crit->LockSemaphore ); 187 crit->Reserved = 0L; 442 443 HANDLE sem = get_semaphore(crit); 444 445 crit->LockSemaphore = ConvertToGlobalHandle (sem); 188 446 } 189 447 … … 196 454 dprintf(("ReinitializeCriticalSection %x", crit)); 197 455 198 if ( !crit->LockSemaphore ) 199 InitializeCriticalSection( crit ); 200 201 else if ( crit->Reserved && crit->Reserved != ODIN_GetCurrentProcessId() ) 202 { 203 dprintf(("(%p) called for %08lx first, %08lx now: making global\n", 204 crit, crit->Reserved, ODIN_GetCurrentProcessId() )); 205 206 MakeCriticalSectionGlobal( crit ); 456 if (!crit->LockSemaphore) 457 { 458 InitializeCriticalSection (crit); 207 459 } 208 460 } … … 215 467 { 216 468 dprintf(("UninitializeCriticalSection %x", crit)); 217 if ( crit->LockSemaphore ) 218 { 219 if ( crit->Reserved ) /* not global */ 220 DeleteCriticalSection( crit ); 221 else 222 dprintf(("(%p) for %08lx: Crst is global, don't know whether to delete\n", 223 crit, ODIN_GetCurrentProcessId() )); 224 } 225 } 226 469 DeleteCriticalSection (crit); 470 } 471 -
trunk/src/kernel32/dbglocal.cpp
r10384 r21302 145 145 "mmapdup", 146 146 "oslibthread", 147 "mmapnotify" 147 "mmapnotify", 148 "_ras" 148 149 }; 149 150 //****************************************************************************** -
trunk/src/kernel32/dbglocal.h
r10384 r21302 142 142 #define DBG_oslibthread 122 143 143 #define DBG_mmapnotify 123 144 #define DBG_MAXFILES 124 144 #define DBG__ras 124 145 #define DBG_MAXFILES 125 145 146 146 147 extern USHORT DbgEnabledKERNEL32[DBG_MAXFILES]; -
trunk/src/kernel32/dbglog.cpp
r9938 r21302 30 30 #include "initterm.h" 31 31 #include "logging.h" 32 #include "exceptions.h" 32 33 #include "exceptutil.h" 33 34 #include <wprocess.h> … … 36 37 #include <cpuhlp.h> 37 38 39 #include "asmutil.h" 40 #include "WinImageBase.h" 41 #include "WinDllBase.h" 42 #include "WinExeBase.h" 38 43 /***************************************************************************** 39 44 * PMPRINTF Version * … … 284 289 #endif 285 290 291 static void win32modname (ULONG eip, char *szModName, int cbModName) 292 { 293 Win32ImageBase *pMod = NULL; 294 if (WinExe && WinExe->insideModule(eip)) 295 pMod = WinExe; 296 else 297 pMod = Win32DllBase::findModuleByAddr(eip); 298 if (pMod != NULL) 299 { 300 szModName[0] = '\0'; 301 strncat(szModName, pMod->getModuleName(), cbModName); 302 } 303 } 304 286 305 int SYSTEM WriteLog(char *tekst, ...) 287 306 { … … 476 495 if(tekst[strlen(tekst)-1] != '\n') 477 496 fprintf(flog, "\n"); 478 497 #if 0 498 if (teb && LOWORD(teb->o.odin.threadId) > 1) 499 { 500 TEB *winteb = GetThreadTEB(); 501 PWINEXCEPTION_FRAME pframe = (PWINEXCEPTION_FRAME)winteb->except; 502 503 fprintf(flog, "debug Win32 exception chain %08X (%08X) (teb = %08X, esp = %08X)\n", pframe, QueryExceptionChain(), teb, getESP()); 504 fprintf(flog, "Top record at %08X, Prev at %08X, handler at %08X\n", (PWINEXCEPTION_FRAME)QueryExceptionChain(), ((PWINEXCEPTION_FRAME)QueryExceptionChain())->Prev, ((PWINEXCEPTION_FRAME)QueryExceptionChain())->Handler); 505 fprintf(flog, "*teb %08X %08X %08X %08X %08X %08X %08X %08X\n", 506 ((ULONG *)teb)[0],((ULONG *)teb)[1],((ULONG *)teb)[2],((ULONG *)teb)[3], 507 ((ULONG *)teb)[4],((ULONG *)teb)[5],((ULONG *)teb)[6],((ULONG *)teb)[7]); 508 while ((pframe != NULL) && ((ULONG)pframe != 0xFFFFFFFF)) { 509 if ((void *)pframe > winteb->stack_top || (void *)pframe < winteb->stack_low) 510 { 511 fprintf(flog, "Chain corrupted! Record at %08X is outside stack boundaries!\n", pframe); 512 break; 513 } 514 515 if ((ULONG)pframe < getESP()) 516 { 517 fprintf(flog, "Chain corrupted! Record at %08X is below stack pointer!\n", pframe); 518 break; 519 } 520 521 char szModName[32] = ""; 522 char szModName2[32] = ""; 523 win32modname ((ULONG)pframe->Handler, szModName, sizeof (szModName)); 524 win32modname ((ULONG)pframe->Prev, szModName2, sizeof (szModName2)); 525 fprintf(flog, "Record at %08X, Prev at %08X [%s], handler at %08X [%s]\n", pframe, pframe->Prev, szModName2, pframe->Handler, szModName); 526 if (pframe == pframe->Prev) { 527 fprintf(flog, "Chain corrupted! Record at %08X pointing to itself!\n", pframe); 528 break; 529 } 530 pframe = pframe->Prev; 531 } 532 } 533 #endif 479 534 if(fFlushLines) 480 535 fflush(flog); -
trunk/src/kernel32/directory.cpp
r9597 r21302 278 278 dprintf(("CreateDirectoryA %s", lpstrDirectory)); 279 279 280 // PH Note 2000/06/12: 281 // Creation of an existing directory is NO ERROR it seems. 280 // Creation of an existing directory will fail (verified in NT4 & XP) 282 281 DWORD dwAttr = GetFileAttributesA(lpstrDirectory); 283 282 if(dwAttr != -1) … … 285 284 if (dwAttr & FILE_ATTRIBUTE_DIRECTORY) 286 285 { 287 SetLastError(ERROR_ SUCCESS);288 return TRUE;286 SetLastError(ERROR_ALREADY_EXISTS); 287 return FALSE; 289 288 } 290 289 } -
trunk/src/kernel32/environ.cpp
r7858 r21302 25 25 #include <winnls.h> 26 26 #include <stdlib.h> 27 #include <stdio.h> 27 28 #include <string.h> 28 29 #include <heapstring.h> … … 38 39 39 40 41 //list of important OS/2 environment variables that must not be removed 42 //when creating a new process 43 static char *lpReservedEnvStrings[] = { 44 "HOSTNAME", 45 "TZ", 46 "USE_HOSTS_FIRST", 47 "MMBASE", 48 "USER_INI", 49 "SYSTEM_INI", 50 "DPATH", 51 "LANG", 52 "NCDEBUG", 53 "NLSPATH", 54 "TCPLANG", 55 "DLSINI", 56 "INIT_FILE_NAMES", 57 "INIT_FILE_RANGES", 58 "NWDBPATH", 59 "ETC", 60 "WP_OBJHANDLE", 61 "SOMIR", 62 "SOMDDIR", 63 "TMP", 64 "TEMP", 65 }; 66 67 //****************************************************************************** 68 //****************************************************************************** 69 void InitEnvironment() 70 { 71 CHAR szVar[512]; 72 static BOOL fInit = FALSE; 73 74 if(fInit) return; 75 76 //TEMP is a standard environment variable in Windows, but is not always 77 //present in OS/2, so make sure it is. 78 if(GetEnvironmentVariableA("TEMP", szVar, sizeof(szVar)) == 0) 79 { 80 if(GetEnvironmentVariableA("TMP", szVar, sizeof(szVar)) == 0) { 81 //then we just use the windows directory for garbage 82 GetWindowsDirectoryA(szVar, sizeof(szVar)); 83 } 84 SetEnvironmentVariableA("TEMP", szVar); 85 } 86 } 40 87 //****************************************************************************** 41 88 //****************************************************************************** 42 89 LPSTR WIN32API GetEnvironmentStringsA() 43 90 { 91 InitEnvironment(); 44 92 return (LPSTR) O32_GetEnvironmentStrings(); 45 93 } … … 52 100 LPWSTR wenvstrings; 53 101 int len, i; 102 103 InitEnvironment(); 54 104 55 105 if(envstrings == NULL) … … 64 114 } 65 115 len++; //terminating 0 66 wenvstrings = (LPWSTR)malloc(len*sizeof(WCHAR)); 67 for(i=0; 68 i<len; 69 i++) 116 wenvstrings = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); 117 for(i=0;i<len;i++) 70 118 { 71 119 wenvstrings[i] = envstrings[i]; … … 83 131 BOOL WIN32API FreeEnvironmentStringsW(LPWSTR envstrings) 84 132 { 85 free(envstrings);133 HeapFree(GetProcessHeap(), 0, envstrings); 86 134 return(TRUE); 87 135 } … … 283 331 } 284 332 //****************************************************************************** 285 //****************************************************************************** 333 // Create a new process environment block based on input from the application 334 // Make sure important OS/2 variables are added or else some services might 335 // fail in the child process. (gethostname relies on SET HOSTNAME) 336 //****************************************************************************** 337 char *CreateNewEnvironment(char *lpEnvironment) 338 { 339 char *tmpenvold = lpEnvironment; 340 char *tmpenvnew, *newenv; 341 int newsize = 0, len; 342 343 dprintf(("New environment:")); 344 while(*tmpenvold) { 345 dprintf(("%s", tmpenvold)); 346 len = strlen(tmpenvold); 347 newsize += len+1; 348 tmpenvold += len+1; 349 } 350 newsize++; //extra null terminator 351 352 for(int i=0;i<sizeof(lpReservedEnvStrings)/sizeof(char *);i++) { 353 if(!ENV_FindVariable(lpEnvironment, lpReservedEnvStrings[i], strlen(lpReservedEnvStrings[i]))) { 354 len = GetEnvironmentVariableA(lpReservedEnvStrings[i], NULL, 0); 355 if(len) { 356 newsize += strlen(lpReservedEnvStrings[i]) + 1 + len+1; //var = value \0 357 } 358 } 359 } 360 newsize++; //extra 0 terminator 361 362 newenv = (char *)malloc(newsize); 363 if(newenv == NULL) { 364 DebugInt3(); 365 return NULL; 366 } 367 memset(newenv, 0, newsize); 368 tmpenvold = (char *)lpEnvironment; 369 tmpenvnew = newenv; 370 while(*tmpenvold) { 371 strcat(tmpenvnew, tmpenvold); 372 len = strlen(tmpenvnew); 373 tmpenvnew += len+1; 374 tmpenvold += len+1; 375 } 376 for(i=0;i<sizeof(lpReservedEnvStrings)/sizeof(char *);i++) { 377 if(!ENV_FindVariable(lpEnvironment, lpReservedEnvStrings[i], strlen(lpReservedEnvStrings[i]))) { 378 len = GetEnvironmentVariableA(lpReservedEnvStrings[i], NULL, 0); 379 if(len) { 380 char *tmp = (char *)malloc(len+1); 381 len = GetEnvironmentVariableA(lpReservedEnvStrings[i], tmp, len+1); 382 if(len) { 383 sprintf(tmpenvnew, "%s=%s", lpReservedEnvStrings[i], tmp); 384 tmpenvnew += strlen(tmpenvnew) + 1; 385 } 386 free(tmp); 387 } 388 } 389 } 390 *tmpenvnew = 0; //final null terminator 391 392 #ifdef DEBUG 393 tmpenvnew = newenv; 394 dprintf(("Combined new environment:")); 395 while(*tmpenvnew) { 396 dprintf(("%s", tmpenvnew)); 397 len = strlen(tmpenvnew); 398 tmpenvnew += len+1; 399 } 400 #endif 401 return newenv; 402 } 403 //****************************************************************************** 404 //****************************************************************************** -
trunk/src/kernel32/exceptions.cpp
r10409 r21302 52 52 #define INCL_MISC 53 53 #define INCL_BASE 54 #define INCL_WIN 54 55 #define INCL_WINBUTTONS 55 56 #include <os2wrap.h> //Odin32 OS/2 api wrappers … … 59 60 #include <time.h> 60 61 #include <string.h> 62 #include <pmscan.h> 61 63 #include "exceptions.h" 62 64 #include "exceptutil.h" … … 66 68 #include <win32api.h> 67 69 #include "oslibexcept.h" 70 #include "oslibmem.h" 68 71 #include "exceptstackdump.h" 72 #include "hmthread.h" 69 73 70 74 #include "WinImageBase.h" … … 81 85 #define DBG_LOCALLOG DBG_exceptions 82 86 #include "dbglocal.h" 87 88 #include <_ras.h> 83 89 84 90 #ifdef WITH_KLIB … … 672 678 static BOOL fEntry = FALSE; 673 679 674 if( fEntry == FALSE) {680 if(!fExitProcess && fEntry == FALSE) { 675 681 fEntry = TRUE; 676 682 ExitProcess(666); … … 702 708 PSZ szTrapDump) 703 709 { 710 // @@VP20040507: This function uses a static buffer szTrapDump, therefore 711 // any local buffers also can be made static to save 712 // stack space and possibly avoid out of stack exception. 713 if(pERepRec->ExceptionNum == XCPT_GUARD_PAGE_VIOLATION) 714 { 715 strcpy(szTrapDump, "Guard Page Violation"); 716 return; 717 } 718 704 719 PSZ pszExceptionName = "<unknown>"; /* points to name/type excpt */ 705 720 APIRET rc = XCPT_CONTINUE_SEARCH; /* excpt-dep. code */ … … 711 726 ULONG ulModule; /* module number */ 712 727 ULONG ulObject; /* object number within the module */ 713 CHAR szModule[260]; /* buffer for the module name */728 static CHAR szModule[260]; /* buffer for the module name */ 714 729 ULONG ulOffset; /* offset within the object within the module */ 715 char szLineException[128];716 char szLineExceptionType[128];730 static char szLineException[128]; 731 static char szLineExceptionType[128]; 717 732 718 733 szLineException[0] = 0; /* initialize */ … … 944 959 if(rc == NO_ERROR && ulObject != -1) 945 960 { 946 sprintf(szLineException, "<%.*s> (#%u) obj #%u:%08x\n", 64, szModule, ulModule, ulObject, ulOffset); 961 sprintf(szLineException, "<%.*s> (#%u) obj #%u:%08x", 64, szModule, ulModule, ulObject, ulOffset); 962 #ifdef RAS 963 static char szSYMInfo[260]; 964 static char Name[260]; 965 966 DosQueryModuleName(ulModule, sizeof(Name), Name); 967 968 int namelen = strlen(Name); 969 if(namelen > 3) 970 { 971 strcpy(Name + namelen - 3, "SYM"); 972 dbgGetSYMInfo(Name, ulObject, ulOffset, szSYMInfo, sizeof (szSYMInfo)); 973 strcat(szLineException, " "); 974 strcat(szLineException, szSYMInfo); 975 } 976 #else 977 strcat(szLineException, "\n"); 978 #endif 947 979 strcat(szTrapDump, szLineException); 948 980 } … … 1044 1076 PVOID p) 1045 1077 { 1078 sprintfException(pERepRec, pERegRec, pCtxRec, p, szTrapDump); 1079 #ifdef RAS 1080 RasLog (szTrapDump); 1081 #endif 1046 1082 /* now dump the information to the logfile */ 1047 1083 dprintf(("\n%s", szTrapDump)); … … 1065 1101 //***************************************************************************** 1066 1102 //***************************************************************************** 1067 static void logException( )1103 static void logException(PEXCEPTIONREPORTRECORD pERepRec, PEXCEPTIONREGISTRATIONRECORD pERegRec, PCONTEXTRECORD pCtxRec, PVOID p) 1068 1104 { 1069 1105 APIRET rc; … … 1110 1146 DosWrite(hFile, lpszTime, strlen(lpszTime), &ulBytesWritten); 1111 1147 } 1148 sprintfException(pERepRec, pERegRec, pCtxRec, p, szTrapDump); 1149 #ifdef RAS 1150 RasLog (szTrapDump); 1151 #endif 1112 1152 DosWrite(hFile, szTrapDump, strlen(szTrapDump), &ulBytesWritten); 1113 1153 DosClose(hFile); … … 1147 1187 int prevlock = LogException(ENTER_EXCEPTION); 1148 1188 1149 //Print exception name & exception type 1150 //Not for a guard page exception as sprintfException uses a lot of stack 1151 //and can trigger nested guard page exceptions (crash) 1152 if(pERepRec->ExceptionNum != XCPT_GUARD_PAGE_VIOLATION) { 1153 sprintfException(pERepRec, pERegRec, pCtxRec, p, szTrapDump); 1154 } 1189 // @@VP20040507: no need to sprintf every exception 1190 // //Print exception name & exception type 1191 // //Not for a guard page exception as sprintfException uses a lot of stack 1192 // //and can trigger nested guard page exceptions (crash) 1193 // if(pERepRec->ExceptionNum != XCPT_GUARD_PAGE_VIOLATION) { 1194 // sprintfException(pERepRec, pERegRec, pCtxRec, p, szTrapDump); 1195 // } 1155 1196 1156 1197 /* Access violation at a known location */ … … 1296 1337 } 1297 1338 #endif 1298 1339 goto CrashAndBurn; 1340 1341 case XCPT_INVALID_LOCK_SEQUENCE: 1342 { 1343 TEB *teb = GetThreadTEB(); 1344 USHORT *eip = (USHORT *)pCtxRec->ctx_RegEip; 1345 1346 if(teb && eip && *eip == SETTHREADCONTEXT_INVALID_LOCKOPCODE) 1347 { 1348 //Is this a pending SetThreadContext exception? 1349 //(see detailed description in the HMDeviceThreadClass::SetThreadContext method) 1350 if(teb->o.odin.context.ContextFlags) 1351 { 1352 dprintfException(pERepRec, pERegRec, pCtxRec, p); 1353 1354 //NOTE: This will not work properly in case multiple threads execute this code 1355 dprintf(("Changing thread registers (SetThreadContext)!!")); 1356 1357 if(teb->o.odin.context.ContextFlags & WINCONTEXT_CONTROL) { 1358 pCtxRec->ctx_RegEbp = teb->o.odin.context.Ebp; 1359 pCtxRec->ctx_RegEip = teb->o.odin.context.Eip; 1360 //// pCtxRec->ctx_SegCs = teb->o.odin.context.SegCs; 1361 pCtxRec->ctx_EFlags = teb->o.odin.context.EFlags; 1362 pCtxRec->ctx_RegEsp = teb->o.odin.context.Esp; 1363 //// pCtxRec->ctx_SegSs = teb->o.odin.context.SegSs; 1364 } 1365 if(teb->o.odin.context.ContextFlags & WINCONTEXT_INTEGER) { 1366 pCtxRec->ctx_RegEdi = teb->o.odin.context.Edi; 1367 pCtxRec->ctx_RegEsi = teb->o.odin.context.Esi; 1368 pCtxRec->ctx_RegEbx = teb->o.odin.context.Ebx; 1369 pCtxRec->ctx_RegEdx = teb->o.odin.context.Edx; 1370 pCtxRec->ctx_RegEcx = teb->o.odin.context.Ecx; 1371 pCtxRec->ctx_RegEax = teb->o.odin.context.Eax; 1372 } 1373 if(teb->o.odin.context.ContextFlags & WINCONTEXT_SEGMENTS) { 1374 pCtxRec->ctx_SegGs = teb->o.odin.context.SegGs; 1375 //// pCtxRec->ctx_SegFs = teb->o.odin.context.SegFs; 1376 pCtxRec->ctx_SegEs = teb->o.odin.context.SegEs; 1377 pCtxRec->ctx_SegDs = teb->o.odin.context.SegDs; 1378 } 1379 if(teb->o.odin.context.ContextFlags & WINCONTEXT_FLOATING_POINT) { 1380 //TODO: First 7 dwords the same? 1381 memcpy(pCtxRec->ctx_env, &teb->o.odin.context.FloatSave, sizeof(pCtxRec->ctx_env)); 1382 memcpy(pCtxRec->ctx_stack, &teb->o.odin.context.FloatSave.RegisterArea, sizeof(pCtxRec->ctx_stack)); 1383 } 1384 USHORT *lpAlias = (USHORT *)((char *)teb->o.odin.lpAlias + teb->o.odin.dwAliasOffset); 1385 *lpAlias = teb->o.odin.savedopcode; 1386 1387 //Clear SetThreadContext markers 1388 teb->o.odin.context.ContextFlags = 0; 1389 1390 OSLibDosFreeMem(teb->o.odin.lpAlias); 1391 1392 teb->o.odin.lpAlias = NULL; 1393 teb->o.odin.dwAliasOffset = 0; 1394 1395 //restore the original priority (we boosted it to ensure this thread was scheduled first) 1396 SetThreadPriority(teb->o.odin.hThread, GetThreadPriority(teb->o.odin.hThread)); 1397 goto continueexecution; 1398 } 1399 else DebugInt3(); //oh, oh!!!!! 1400 1401 } 1402 //no break; 1403 } 1404 1405 case XCPT_PRIVILEGED_INSTRUCTION: 1406 case XCPT_ILLEGAL_INSTRUCTION: 1299 1407 case XCPT_BREAKPOINT: 1300 1408 case XCPT_ARRAY_BOUNDS_EXCEEDED: 1301 1409 case XCPT_DATATYPE_MISALIGNMENT: 1302 case XCPT_ILLEGAL_INSTRUCTION:1303 case XCPT_PRIVILEGED_INSTRUCTION:1304 case XCPT_INVALID_LOCK_SEQUENCE:1305 1410 case XCPT_INTEGER_DIVIDE_BY_ZERO: 1306 1411 case XCPT_INTEGER_OVERFLOW: 1307 1412 case XCPT_SINGLE_STEP: 1308 case XCPT_UNABLE_TO_GROW_STACK:1309 1413 case XCPT_IN_PAGE_ERROR: 1310 1414 CrashAndBurn: … … 1316 1420 goto continuesearch; 1317 1421 1318 #if def DEBUG1422 #if defined(DEBUG) || defined(RAS) 1319 1423 dprintfException(pERepRec, pERegRec, pCtxRec, p); 1424 1320 1425 if(!fExitProcess && (pCtxRec->ContextFlags & CONTEXT_CONTROL)) { 1321 1426 dbgPrintStack(pERepRec, pERegRec, pCtxRec, p); … … 1337 1442 1338 1443 rc = DosGetInfoBlocks (&pTIB, &pPIB); 1339 if(rc == NO_ERROR && pTIB->tib_ptib2->tib2_ultid != 1)1444 if(rc == NO_ERROR) 1340 1445 { 1341 1446 dprintf(("KERNEL32: OS2ExceptionHandler: Continue and kill thread")); 1342 1447 1343 pCtxRec->ctx_RegEip = ( ULONG)KillWin32Thread;1448 pCtxRec->ctx_RegEip = (pTIB->tib_ptib2->tib2_ultid != 1) ? (ULONG)KillWin32Thread : (ULONG)KillWin32Process; 1344 1449 pCtxRec->ctx_RegEsp = pCtxRec->ctx_RegEsp + 0x10; 1345 1450 pCtxRec->ctx_RegEax = pERepRec->ExceptionNum; … … 1352 1457 1353 1458 //Log fatal exception here 1354 logException( );1459 logException(pERepRec, pERegRec, pCtxRec, p); 1355 1460 1356 1461 dprintf(("KERNEL32: OS2ExceptionHandler: Continue and kill\n")); … … 1362 1467 goto continueexecution; 1363 1468 1364 //@@@PH: growing thread stacks might need special treatment1365 1469 case XCPT_GUARD_PAGE_VIOLATION: 1366 1470 { … … 1369 1473 //inside fprintf 1370 1474 //NOTE:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1371 1475 TEB *teb = GetThreadTEB(); 1476 DWORD stacktop, stackbottom; 1477 1478 if(teb == NULL) { 1479 goto continueGuardException; 1480 } 1481 1482 stacktop = (DWORD)teb->stack_top; 1483 stackbottom = (DWORD)teb->stack_low; 1484 1485 stackbottom = stackbottom & ~0xFFF; //round down to page boundary 1486 stacktop = stacktop & ~0xFFF; 1487 1488 //Make sure we detect a stack overflow condition before the system does 1489 if(!fIsOS2Image && 1490 pERepRec->ExceptionInfo[1] >= stackbottom && 1491 pERepRec->ExceptionInfo[1] < stacktop 1492 ) 1493 {//this is a guard page exception for the thread stack 1494 APIRET rc; 1495 ULONG ulAddress, cbSize, ulMemFlags; 1496 1497 //round down to page boundary 1498 ulAddress = pERepRec->ExceptionInfo[1] & ~0xFFF; 1499 1500 #if 0 1501 rc = DosQueryMem((PVOID)ulAddress, &cbSize, &ulMemFlags); 1502 if(rc) { 1503 dprintf(("ERROR: DosQueryMem old guard page failed with rc %d", rc)); 1504 goto continueGuardException; 1505 } 1506 #endif 1507 1508 if(ulAddress == stackbottom + PAGE_SIZE) 1509 {//we don't have any stack left, throw an XCPT_UNABLE_TO_GROW_STACK 1510 //exception 1511 if(!fExitProcess) //Only for real win32 apps 1512 { 1513 EXCEPTIONREPORTRECORD recoutofstack; 1514 1515 recoutofstack = *pERepRec; 1516 recoutofstack.ExceptionNum = XCPT_UNABLE_TO_GROW_STACK; 1517 recoutofstack.fHandlerFlags = 0; 1518 recoutofstack.NestedExceptionReportRecord = NULL; 1519 recoutofstack.cParameters = 0; 1520 1521 if(OSLibDispatchException(&recoutofstack, pERegRec, pCtxRec, p) == TRUE) 1522 { 1523 goto continueexecution; 1524 } 1525 } 1526 } 1527 } 1528 else 1529 {//check for memory map guard page exception 1372 1530 Win32MemMap *map; 1373 1531 BOOL fWriteAccess = FALSE, ret; … … 1387 1545 1388 1546 map = Win32MemMapView::findMapByView(pERepRec->ExceptionInfo[1], &offset, accessflag); 1389 if(map == NULL) { 1390 goto continueGuardException; 1391 } 1547 if(map) { 1392 1548 ret = map->commitGuardPage(pERepRec->ExceptionInfo[1], offset, fWriteAccess); 1393 1549 map->Release(); 1394 1550 if(ret == TRUE) 1395 1551 goto continueexecution; 1552 } 1553 } 1396 1554 1397 1555 continueGuardException: 1556 goto continuesearch; 1557 } 1558 1559 case XCPT_UNABLE_TO_GROW_STACK: 1560 { 1561 //SvL: XCPT_UNABLE_TO_GROW_STACK is typically nested (failed guard page 1562 // exception), so don't ignore them 1563 // We should no longer receive those!! 1564 // @@VP20040507: Isn't this a bit dangerous to call dprintfon such exception 1565 //#ifdef DEBUG 1566 // dprintfException(pERepRec, pERegRec, pCtxRec, p); 1567 //#endif 1398 1568 goto continuesearch; 1399 1569 } … … 1408 1578 */ 1409 1579 case XCPT_SIGNAL: 1580 { 1581 //This is not a reliable way to distinguish between Ctrl-C & Ctrl-Break 1582 BOOL breakPressed = WinGetKeyState(HWND_DESKTOP,VK_BREAK) & 0x8000; 1583 1410 1584 switch (pERepRec->ExceptionInfo[0]) 1411 1585 { 1412 1586 case XCPT_SIGNAL_BREAK: 1413 if (InternalGenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0)) 1587 breakPressed = TRUE; 1588 //no break 1589 1590 case XCPT_SIGNAL_INTR: 1591 dprintfException(pERepRec, pERegRec, pCtxRec, p); 1592 if (InternalGenerateConsoleCtrlEvent((breakPressed) ? CTRL_BREAK_EVENT : CTRL_C_EVENT, 0)) 1593 { 1594 DosAcknowledgeSignalException(pERepRec->ExceptionInfo[0]); 1414 1595 goto continueexecution; 1415 goto continuesearch; 1416 case XCPT_SIGNAL_INTR: 1417 if (InternalGenerateConsoleCtrlEvent(CTRL_C_EVENT, 0)) 1418 goto continueexecution; 1596 } 1419 1597 goto continuesearch; 1420 1598 … … 1424 1602 } 1425 1603 goto CrashAndBurn; 1604 } 1426 1605 1427 1606 default: //non-continuable exceptions … … 1497 1676 USHORT sel = RestoreOS2FS(); 1498 1677 PEXCEPTIONREGISTRATIONRECORD pExceptRec = (PEXCEPTIONREGISTRATIONRECORD)QueryExceptionChain(); 1499 1500 if(pExceptRec == (PEXCEPTIONREGISTRATIONRECORD)pExceptionRegRec) { 1678 BOOL fFound = FALSE; 1679 1680 while(pExceptRec != 0 && (ULONG)pExceptRec != -1) 1681 { 1682 if(pExceptRec == pExceptionRegRec) 1683 { 1684 fFound = TRUE; 1685 break; 1686 } 1687 pExceptRec = pExceptRec->prev_structure; 1688 } 1689 1690 #ifdef DEBUG 1691 pExceptRec = (PEXCEPTIONREGISTRATIONRECORD)QueryExceptionChain(); 1692 1693 if(fFound && pExceptRec != (PEXCEPTIONREGISTRATIONRECORD)pExceptionRegRec) 1694 { 1695 dprintf(("ERROR: ODIN_UnsetExceptionHandler: INSIDE!!!: exc rec %p, head %p\n", pExceptionRegRec, pExceptRec)); 1696 PrintExceptionChain (); 1697 } 1698 #endif 1699 if(fFound) { 1501 1700 OS2UnsetExceptionHandler(pExceptionRegRec); 1502 1701 } -
trunk/src/kernel32/exceptstackdump.cpp
r8401 r21302 25 25 #include "windllbase.h" 26 26 27 #include <_ras.h> 28 27 29 #define DBG_LOCALLOG DBG_exceptstackdump 28 30 #include "dbglocal.h" … … 30 32 int SYSTEM EXPORT WriteLogNoEOL(char *tekst, ...); 31 33 34 #define FIX64KLIMIT 35 32 36 #undef dprintf 33 #define dprintf(a) if(DbgEnabledKERNEL32[DBG_LOCALLOG] == 1) WriteLogNoEOL a 37 #ifdef RAS 38 # ifdef DEBUG 39 # define dprintf(a) RasLogNoEOL a; if(DbgEnabledKERNEL32[DBG_LOCALLOG] == 1) WriteLogNoEOL a 40 # else 41 # define dprintf(a) RasLogNoEOL a; 42 # endif 43 #else 44 # ifdef DEBUG 45 # define dprintf(a) if(DbgEnabledKERNEL32[DBG_LOCALLOG] == 1) WriteLogNoEOL a 46 # else 47 # define dprintf(a) 48 # endif 49 #endif 34 50 35 51 /* ****************************************************************** … … 55 71 */ 56 72 57 BOOL dbg PrintSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset)73 BOOL dbgGetSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset, CHAR *Info, ULONG cbInfo) 58 74 { 59 75 static FILE *SymFile; … … 88 104 if (fseek(SymFile, SegOffset, SEEK_SET)) 89 105 { 90 dprintf(("Seek error."));106 // dprintf(("Seek error.")); 91 107 goto endofprintsym; 92 108 } … … 100 116 LastVal = 0; 101 117 118 #ifdef FIX64KLIMIT 119 // Custom build dll's SYM file is much greater than 64K. 120 // SYM file structures use 16 bit offsets in the file and 121 // therefore these offsets can't be directly used as they 122 // are overflowed. 123 // Some offsets like segment definition offsets are 124 // paragraph (*16) ones and will overflow for an 1 meg file. 125 // In particular this affects SYMbol searching algorithm 126 // used here. 127 // With the #ifdef it will be changed to so we will 128 // extract symbol by symbol from the file instead of using 129 // symbol table that is far further 64K fence. 130 131 // Offset of first symbol 132 SymOffset = sizeof (SEGDEF) - 1 + SegDef.cbSegName; 133 #endif 134 102 135 // go thru all symbols in this object 103 136 for (SymNum = 0; SymNum < SegDef.cSymbols; SymNum++) 104 137 { 138 #ifndef FIX64KLIMIT 105 139 // read in symbol offset USHORT 106 140 SymPtrOffset = SYMDEFOFFSET(SegOffset, SegDef, SymNum); 107 141 fseek(SymFile, SymPtrOffset, SEEK_SET); 108 142 fread(&SymOffset, sizeof(unsigned short int), 1, SymFile); 143 #endif 109 144 110 145 // go to symbol definition … … 121 156 fread(&Buffer[1], 1, SymDef32.cbSymName, SymFile); 122 157 Buffer[SymDef32.cbSymName] = 0x00; 123 dprintf(("%s\n", Buffer)); 158 // dprintf(("%s\n", Buffer)); 159 strcpy (Info, Buffer); 124 160 rc = TRUE; 125 161 break; … … 134 170 { 135 171 // symbol found 136 dprintf(("between %s + 0x%X", Buffer, TrapOffset - LastVal)); 172 #ifdef RAS 173 snprintf(Info, cbInfo, "between %s + 0x%X", Buffer, TrapOffset - LastVal); 174 #else 175 sprintf(Info, "between %s + 0x%X", Buffer, TrapOffset - LastVal); 176 #endif 137 177 } 138 178 LastVal = SymDef32.wSymVal; … … 144 184 { 145 185 // symbol found, as above 146 dprintf((" and %s - 0x%X\n", Buffer, LastVal - TrapOffset)); 186 #ifdef RAS 187 snprintf(&Info[strlen(Info)], cbInfo - strlen(Info), " and %s - 0x%X\n", Buffer, LastVal - TrapOffset); 188 #else 189 sprintf(&Info[strlen(Info)], " and %s - 0x%X\n", Buffer, LastVal - TrapOffset); 190 #endif 147 191 rc = TRUE; 148 192 break; 149 193 } 150 194 /*printf("32 Bit Symbol <%s> Address %p",Buffer,SymDef32.wSymVal); */ 195 #ifdef FIX64KLIMIT 196 SymOffset += sizeof (SYMDEF32) + SymDef32.cbSymName - 1; 197 #endif 151 198 } 152 199 else … … 163 210 if (SymDef16.wSymVal > TrapOffset) 164 211 { 165 dprintf(("between %s + %X", Buffer, TrapOffset - LastVal)); 212 #ifdef RAS 213 snprintf(Info, cbInfo, "between %s + 0x%X", Buffer, TrapOffset - LastVal); 214 #else 215 sprintf(Info, "between %s + 0x%X", Buffer, TrapOffset - LastVal); 216 #endif 166 217 } 167 218 LastVal = SymDef16.wSymVal; … … 171 222 if (SymDef16.wSymVal > TrapOffset) 172 223 { 173 dprintf((" and %s - %X\n", Buffer, LastVal - TrapOffset)); 224 #ifdef RAS 225 snprintf(&Info[strlen(Info)], cbInfo - strlen(Info), " and %s - 0x%X\n", Buffer, LastVal - TrapOffset); 226 #else 227 sprintf(&Info[strlen(Info)], " and %s - 0x%X\n", Buffer, LastVal - TrapOffset); 228 #endif 174 229 rc = TRUE; 175 230 break; 176 231 } 177 232 /*printf("16 Bit Symbol <%s> Address %p",Buffer,SymDef16.wSymVal); */ 233 #ifdef FIX64KLIMIT 234 SymOffset += sizeof (SYMDEF16) + SymDef16.cbSymName - 1; 235 #endif 178 236 } // endif 179 237 } 238 #ifdef FIX64KLIMIT 239 if (SymNum < SegDef.cSymbols) 240 { 241 #endif 180 242 break; 243 #ifdef FIX64KLIMIT 244 } 245 #endif 181 246 } // endif 182 247 SegOffset = NEXTSEGDEFOFFSET(SegDef); … … 184 249 endofprintsym: 185 250 if(SymFile) fclose(SymFile); 186 if(rc == FALSE) dprintf(("\n")); 251 // if(rc == FALSE) dprintf(("\n")); 252 if(rc == FALSE) strcpy (Info, "\n"); 253 return rc; 254 } 255 BOOL dbgPrintSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset) 256 { 257 static char szInfo[256]; 258 BOOL rc = dbgGetSYMInfo (SymFileName, Object, TrapOffset, szInfo, sizeof (szInfo)); 259 dprintf(("%s", szInfo)); 187 260 return rc; 188 261 } -
trunk/src/kernel32/exceptstackdump.h
r3483 r21302 541 541 #pragma pack() 542 542 543 BOOL dbgGetSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset, char *Info, ULONG cbInfo); 544 BOOL dbgPrintSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset); 545 543 546 /* 544 547 * dbgPrintStack: -
trunk/src/kernel32/handlenames.cpp
r9975 r21302 164 164 BOOL fCaseInsensitive) 165 165 { 166 int cchSymbolicLink = strlen(pszSymbolicLink); 166 167 PLINEARLISTENTRY pLE = pSymbolicLinks->getFirst(); 167 168 while (pLE) 168 169 { 169 170 PHANDLENAME pHandleName = (PHANDLENAME)pLE->pObject; 170 171 int iLen = strlen(pHandleName->pszSymbolicLink); 172 171 int cch = pHandleName->ulSymbolicLinkLength; //strlen(pHandleName->pszSymbolicLink); 172 173 /* pszSymbolicLink must end a path component at cch. */ 174 if ( cch <= cchSymbolicLink 175 && (pszSymbolicLink[cch] == '\\' || pszSymbolicLink[cch] == '\0')) 176 { 173 177 if (fCaseInsensitive) 174 178 { 175 // Note: pszSymbolicLink must either terminate at [iLen] or 176 // have a delimiter. 177 if ( (pszSymbolicLink[iLen] == '\\') || 178 (pszSymbolicLink[iLen] == 0) ) 179 if (strnicmp(pHandleName->pszSymbolicLink, pszSymbolicLink, iLen) == 0) 179 if (!strnicmp(pHandleName->pszSymbolicLink, pszSymbolicLink, cch)) 180 180 return pHandleName; 181 181 } 182 182 else 183 183 { 184 if ( (pszSymbolicLink[iLen] == '\\') || 185 (pszSymbolicLink[iLen] == 0) ) 186 if (strncmp(pHandleName->pszSymbolicLink, pszSymbolicLink, iLen) == 0) 184 if (!memcmp(pHandleName->pszSymbolicLink, pszSymbolicLink, cch)) 187 185 return pHandleName; 188 186 } 189 187 } 190 188 191 189 // skip to the next entry -
trunk/src/kernel32/heapshared.cpp
r9667 r21302 17 17 #define INCL_BASE 18 18 #define INCL_DOSMEMMGR 19 #define INCL_DOSPROCESS 19 20 #include <os2wrap.h> 20 21 #include <string.h> 21 22 #include <dbglog.h> 22 #include <heapshared.h> 23 #include <stddef.h> 24 #include <stdlib.h> 25 #include <umalloc.h> 23 26 #include "initterm.h" 27 28 #define PAGE_SIZE 4096 24 29 25 30 #define DBG_LOCALLOG DBG_heapshared … … 102 107 //****************************************************************************** 103 108 //****************************************************************************** 109 #ifdef DEBUG 110 int _LNK_CONV callback_function(const void *pentry, size_t sz, int useflag, int status, 111 const char *filename, size_t line) 112 { 113 if (_HEAPOK != status) { 114 dprintf(("status is not _HEAPOK.")); 115 return 1; 116 } 117 if (_USEDENTRY == useflag && sz && filename && line) { 118 dprintf(("allocated %08x %u at %s %d\n", pentry, sz, filename, line)); 119 } 120 else dprintf(("allocated %08x %u", pentry, sz)); 121 122 return 0; 123 } 124 #endif 125 //****************************************************************************** 126 //****************************************************************************** 104 127 void SYSTEM DestroySharedHeap() 105 128 { … … 108 131 return; 109 132 } 133 134 #ifdef DEBUG 135 _uheap_walk(sharedHeap, callback_function); 136 dprintf((NULL)); 137 #endif 138 110 139 if(--refCount == 0) { 111 140 if(sharedHeap) { … … 200 229 201 230 chunk = _umalloc(sharedHeap, size); 202 dprintf 2(("_smalloc %x returned %x", size, chunk));231 dprintf(("_smalloc %x returned %x", size, chunk)); 203 232 return chunk; 204 233 } … … 213 242 memset(chunk, 0, size); 214 243 } 215 dprintf2(("_smallocfill %x %x returned %x", size, filler, chunk)); 216 return chunk; 217 } 218 //****************************************************************************** 219 //****************************************************************************** 244 dprintf(("_smallocfill %x %x returned %x", size, filler, chunk)); 245 return chunk; 246 } 247 //****************************************************************************** 248 //****************************************************************************** 249 void SYSTEM _sfree(void *block) 250 { 251 dprintf(("_sfree %x", block)); 252 free(block); 253 } 254 //****************************************************************************** 255 //****************************************************************************** 256 void * _System _debug_smalloc(int size, char *pszFile, int linenr) 257 { 258 void *chunk; 259 260 #ifdef __DEBUG_ALLOC__ 261 chunk = _debug_umalloc(sharedHeap, size, pszFile, linenr); 262 #else 263 chunk = _umalloc(sharedHeap, size); 264 #endif 265 dprintf(("_smalloc %x returned %x", size, chunk)); 266 return chunk; 267 } 268 //****************************************************************************** 269 //****************************************************************************** 270 void * _System _debug_smallocfill(int size, int filler, char *pszFile, int linenr) 271 { 272 void *chunk; 273 274 #ifdef __DEBUG_ALLOC__ 275 chunk = _debug_umalloc(sharedHeap, size, pszFile, linenr); 276 #else 277 chunk = _umalloc(sharedHeap, size); 278 #endif 279 if(chunk) { 280 memset(chunk, 0, size); 281 } 282 dprintf(("_smallocfill %x %x returned %x", size, filler, chunk)); 283 return chunk; 284 } 285 //****************************************************************************** 286 //****************************************************************************** 287 void _System _debug_sfree(void *chunk, char *pszFile, int linenr) 288 { 289 dprintf(("_sfree %x", chunk)); 290 #ifdef __DEBUG_ALLOC__ 291 _debug_free(chunk, pszFile, linenr); 292 #else 293 free(chunk); 294 #endif 295 } 296 //****************************************************************************** 297 //****************************************************************************** -
trunk/src/kernel32/hmcomm.cpp
r10433 r21302 148 148 } 149 149 150 if(namelength == 5 && lpDeviceName[4] != ':') {150 if(namelength > 5 || (namelength == 5 && lpDeviceName[4] != ':')) { 151 151 return FALSE; 152 152 } -
trunk/src/kernel32/hmdevice.cpp
r10132 r21302 138 138 PHMHANDLEDATA pHMSrcHandle, 139 139 HANDLE destprocess, 140 PHANDLE desthandle,141 140 DWORD fdwAccess, 142 141 BOOL fInherit, … … 144 143 DWORD fdwOdinOptions) 145 144 { 146 dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED!!!!!!!!\n", 147 lpHMDeviceName, 148 pHMHandleData, 149 srcprocess, pHMSrcHandle, destprocess, desthandle)); 145 dprintf(("KERNEL32:HandleManager::DuplicateHandle %s(%08x,%08x,%08x,%08x) - NOT IMPLEMENTED!!!!!!!!\n", 146 lpHMDeviceName, pHMHandleData, srcprocess, pHMSrcHandle, destprocess)); 150 147 151 148 return FALSE; … … 1419 1416 DWORD fdwCreate, 1420 1417 LPDWORD lpIDThread, 1421 BOOL f FirstThread)1418 BOOL fRegisterThread) 1422 1419 { 1423 1420 dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::CreateThread %08xh", -
trunk/src/kernel32/hmdevice.h
r10132 r21302 12 12 13 13 /***************************************************************************** 14 * Remark *15 *****************************************************************************16 */17 18 19 /*****************************************************************************20 * Includes *21 *****************************************************************************/22 23 /*****************************************************************************24 * defines *25 *****************************************************************************/26 27 #define HMTYPE_UNKNOWN 028 #define HMTYPE_MEMMAP 129 #define HMTYPE_DEVICE 230 #define HMTYPE_PROCESSTOKEN 331 #define HMTYPE_THREADTOKEN 432 #define HMTYPE_THREAD 533 #define HMTYPE_PIPE 634 #define HMTYPE_EVENTSEM 735 #define HMTYPE_MUTEXSEM 836 #define HMTYPE_SEMAPHORE 937 #define HMTYPE_COMPORT 1038 #define HMTYPE_PARPORT 1139 //.....40 41 /*****************************************************************************42 14 * Structures * 43 15 *****************************************************************************/ … … 61 33 } HMHANDLEDATA, *PHMHANDLEDATA; 62 34 63 PHMHANDLEDATA HMQueryHandleData(HANDLE handle); 35 /***************************************************************************** 36 * Remark * 37 ***************************************************************************** 38 */ 39 40 41 /***************************************************************************** 42 * Includes * 43 *****************************************************************************/ 44 64 45 65 46 … … 95 76 PHMHANDLEDATA pHMSrcHandle, 96 77 HANDLE destprocess, 97 PHANDLE desthandle,98 78 DWORD fdwAccess, 99 79 BOOL fInherit, … … 389 369 DWORD fdwCreate, 390 370 LPDWORD lpIDThread, 391 BOOL f FirstThread);371 BOOL fRegisterThread); 392 372 393 373 virtual INT GetThreadPriority(HANDLE hThread, PHMHANDLEDATA pHMHandleData); … … 478 458 VOID *pDevData); 479 459 460 461 #include "hmhandle.h" 462 480 463 #endif /* _HM_DEVICE_H_ */ 481 464 -
trunk/src/kernel32/hmdevio.cpp
r9533 r21302 27 27 #include <win\winioctl.h> 28 28 #include "hmdevio.h" 29 #include "map.h"30 29 #include "exceptutil.h" 31 30 #include "oslibdos.h" … … 471 470 QWORD time; 472 471 APIRET rc; 473 472 #if 0 473 return FALSE; 474 #else 474 475 rc = DosTmrQueryTime(&time); 475 476 if(rc) { … … 479 480 lpPerformanceCount->u.LowPart = time.ulLo; 480 481 lpPerformanceCount->u.HighPart = time.ulHi; 482 dprintf2(("QueryPerformanceCounter returned 0x%X%X\n", lpPerformanceCount->u.HighPart, lpPerformanceCount->u.LowPart)); 481 483 return(TRUE); 484 #endif 482 485 } 483 486 //****************************************************************************** … … 488 491 ULONG freq; 489 492 493 #if 0 494 return FALSE; 495 #else 490 496 rc = DosTmrQueryFreq(&freq); 491 497 if(rc) { … … 497 503 dprintf2(("QueryPerformanceFrequency returned 0x%X%X\n", lpFrequency->u.HighPart, lpFrequency->u.LowPart)); 498 504 return(TRUE); 499 } 500 //****************************************************************************** 501 //****************************************************************************** 505 #endif 506 } 507 //****************************************************************************** 508 //****************************************************************************** -
trunk/src/kernel32/hmevent.cpp
r9748 r21302 15 15 */ 16 16 17 #undef DEBUG_LOCAL18 //#define DEBUG_LOCAL19 20 17 21 18 /***************************************************************************** … … 42 39 #include "oslibdos.h" 43 40 41 #include "hmhandle.h" 42 43 44 44 #define DBG_LOCALLOG DBG_hmevent 45 45 #include "dbglocal.h" 46 46 47 /***************************************************************************** 48 * Defines * 49 *****************************************************************************/ 50 51 /***************************************************************************** 52 * Structures * 53 *****************************************************************************/ 54 55 /***************************************************************************** 56 * Local Prototypes * 57 *****************************************************************************/ 47 48 /***************************************************************************** 49 * Name : HANDLE HMCreateEvent 50 * Purpose : Wrapper for the CreateEvent() API 51 * Parameters: 52 * Variables : 53 * Result : 54 * Remark : 55 * Status : 56 * 57 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 58 *****************************************************************************/ 59 60 HANDLE WIN32API CreateEventA(LPSECURITY_ATTRIBUTES lpsa, 61 BOOL bManualReset, 62 BOOL bInitialState, 63 LPCTSTR lpName) 64 { 65 PHMHANDLE pHandle; 66 DWORD rc; /* API return code */ 67 68 69 if(lpName) { //check if shared event semaphore already exists 70 dprintf(("Event semaphore name %s", lpName)); 71 //TODO: No inheritance?? 72 HANDLE handle = OpenEventA(EVENT_ALL_ACCESS, FALSE, lpName); 73 if(handle) { 74 dprintf(("CreateEvent: return handle of existing event semaphore %x", handle)); 75 SetLastError(ERROR_ALREADY_EXISTS); 76 return handle; 77 } 78 } 79 80 pHandle = HMHandleGetFreePtr(HMTYPE_EVENTSEM); /* get free handle */ 81 if (pHandle == NULL) /* oops, no free handles ! */ 82 { 83 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 84 return 0; 85 } 86 87 /* call the device handler */ 88 rc = pHandle->pDeviceHandler->CreateEvent(&pHandle->hmHandleData, 89 lpsa, 90 bManualReset, 91 bInitialState, 92 lpName); 93 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 94 { 95 HMHandleFree(pHandle->hmHandleData.hWin32Handle); 96 SetLastError(rc); 97 return 0; /* signal error */ 98 } 99 else 100 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 101 102 return pHandle->hmHandleData.hWin32Handle; /* return valid handle */ 103 } 104 105 /***************************************************************************** 106 * Name : BOOL CreateEventW 107 * Purpose : forward call to Open32 108 * Parameters: 109 * Variables : 110 * Result : 111 * Remark : handle translation is done in CreateEventA 112 * Status : 113 * 114 * Author : Patrick Haller [Fri, 1998/06/12 03:44] 115 *****************************************************************************/ 116 117 HANDLE WIN32API CreateEventW(LPSECURITY_ATTRIBUTES arg1, 118 BOOL arg2, BOOL arg3, 119 LPCWSTR arg4) 120 { 121 HANDLE rc; 122 char *astring; 123 124 if (arg4 != NULL) // support for unnamed semaphores 125 astring = UnicodeToAsciiString((LPWSTR)arg4); 126 else 127 astring = NULL; 128 129 rc = CreateEventA(arg1, 130 arg2, 131 arg3, 132 astring); 133 134 if (astring != NULL) 135 FreeAsciiString(astring); 136 137 return(rc); 138 } 139 140 /***************************************************************************** 141 * Name : HANDLE HMOpenEvent 142 * Purpose : Wrapper for the OpenEvent() API 143 * Parameters: 144 * Variables : 145 * Result : 146 * Remark : 147 * Status : 148 * 149 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 150 *****************************************************************************/ 151 152 HANDLE WIN32API OpenEventA(DWORD fdwAccess, 153 BOOL fInherit, 154 LPCTSTR lpName) 155 { 156 PHMHANDLE pHandle; 157 DWORD rc; /* API return code */ 158 159 if(lpName) { 160 dprintf(("Event semaphore name %s", lpName)); 161 } 162 163 pHandle = HMHandleGetFreePtr(HMTYPE_EVENTSEM); /* get free handle */ 164 if (pHandle == NULL) /* oops, no free handles ! */ 165 { 166 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 167 return 0; 168 } 169 pHandle->hmHandleData.dwAccess = fdwAccess; 170 /* call the device handler */ 171 rc = pHandle->pDeviceHandler->OpenEvent(&pHandle->hmHandleData, 172 fInherit, 173 lpName); 174 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 175 { 176 HMHandleFree(pHandle->hmHandleData.hWin32Handle); 177 SetLastError(rc); 178 return 0; /* signal error */ 179 } 180 else 181 SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this? 182 183 return pHandle->hmHandleData.hWin32Handle; /* return valid handle */ 184 } 185 186 /***************************************************************************** 187 * Name : HMSetEvent 188 * Purpose : router function for SetEvent 189 * Parameters: 190 * Variables : 191 * Result : 192 * Remark : 193 * Status : 194 * 195 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 196 *****************************************************************************/ 197 198 BOOL WIN32API SetEvent(HANDLE hEvent) 199 { 200 DWORD dwResult; /* result from the device handler's API */ 201 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 202 203 /* validate handle */ 204 pHMHandle = HMHandleQueryPtr(hEvent); /* get the index */ 205 if (pHMHandle == NULL) /* error ? */ 206 { 207 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 208 } 209 210 dwResult = pHMHandle->pDeviceHandler->SetEvent(&pHMHandle->hmHandleData); 211 212 return (dwResult); /* deliver return code */ 213 } 214 215 216 /***************************************************************************** 217 * Name : HMPulseEvent 218 * Purpose : router function for PulseEvent 219 * Parameters: 220 * Variables : 221 * Result : 222 * Remark : 223 * Status : 224 * 225 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 226 *****************************************************************************/ 227 228 BOOL WIN32API PulseEvent(HANDLE hEvent) 229 { 230 DWORD dwResult; /* result from the device handler's API */ 231 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 232 233 /* validate handle */ 234 pHMHandle = HMHandleQueryPtr(hEvent); /* get the index */ 235 if (pHMHandle == NULL) /* error ? */ 236 { 237 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 238 } 239 240 dwResult = pHMHandle->pDeviceHandler->PulseEvent(&pHMHandle->hmHandleData); 241 242 return (dwResult); /* deliver return code */ 243 } 244 245 246 /***************************************************************************** 247 * Name : HMResetEvent 248 * Purpose : router function for ResetEvent 249 * Parameters: 250 * Variables : 251 * Result : 252 * Remark : 253 * Status : 254 * 255 * Author : Patrick Haller [Wed, 1999/06/17 20:44] 256 *****************************************************************************/ 257 258 BOOL WIN32API ResetEvent(HANDLE hEvent) 259 { 260 DWORD dwResult; /* result from the device handler's API */ 261 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 262 263 /* validate handle */ 264 pHMHandle = HMHandleQueryPtr(hEvent); /* get the index */ 265 if (pHMHandle == NULL) /* error ? */ 266 { 267 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 268 } 269 270 dwResult = pHMHandle->pDeviceHandler->ResetEvent(&pHMHandle->hmHandleData); 271 272 return (dwResult); /* deliver return code */ 273 } 58 274 59 275 … … 90 306 lpszEventName); 91 307 308 dprintf(("KERNEL32: HandleManager::Semaphore::CreateEvent hOpen32 = %p, pHMHandleData->hHMHandle = %p\n", hOpen32, pHMHandleData->hHMHandle)); 309 92 310 if (0 != hOpen32) // check success 93 311 { -
trunk/src/kernel32/hmfile.cpp
r10564 r21302 35 35 #include "mmap.h" 36 36 #include "oslibdos.h" 37 #include <customloader.h> 37 38 38 39 #define DBG_LOCALLOG DBG_hmfile … … 97 98 if (hFile != INVALID_HANDLE_ERROR) 98 99 { 99 pHMHandleData->dwUserData = (DWORD) new HMFileInfo( (LPSTR)lpFileName, lpSecurityAttributes);100 pHMHandleData->dwUserData = (DWORD) new HMFileInfo(hFile, (LPSTR)lpFileName, lpSecurityAttributes); 100 101 pHMHandleData->hHMHandle = hFile; 101 102 return (NO_ERROR); … … 261 262 262 263 if(hFile != HFILE_ERROR) { 263 pHMHandleData->dwUserData = (DWORD) new HMFileInfo( (LPSTR)lpFileName, NULL);264 pHMHandleData->dwUserData = (DWORD) new HMFileInfo(hFile, (LPSTR)lpFileName, NULL); 264 265 } 265 266 return (NO_ERROR); … … 302 303 PHMHANDLEDATA pHMSrcHandle, 303 304 HANDLE destprocess, 304 PHANDLE desthandle,305 305 DWORD fdwAccess, 306 306 BOOL fInherit, … … 311 311 DWORD rc; 312 312 313 dprintf(("KERNEL32:HMDeviceFileClass::DuplicateHandle (%08x,%08x,%08x,%08x ,%08x)",313 dprintf(("KERNEL32:HMDeviceFileClass::DuplicateHandle (%08x,%08x,%08x,%08x)", 314 314 pHMHandleData, 315 315 srcprocess, 316 316 pHMSrcHandle->hHMHandle, 317 destprocess, 318 desthandle)); 317 destprocess)); 319 318 320 319 //TODO: Inheritance of file handles won't work! … … 345 344 memcpy(pHMHandleData, &duphdata, sizeof(duphdata)); 346 345 347 if(fInherit) SetHandleInformation(pHMHandleData, ~HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);346 SetHandleInformation(pHMHandleData, HANDLE_FLAG_INHERIT, (fInherit) ? HANDLE_FLAG_INHERIT : 0); 348 347 349 348 SetLastError(ERROR_SUCCESS); … … 360 359 } 361 360 362 rc = OSLibDosDupHandle(pHMSrcHandle->hHMHandle,363 desthandle);361 pHMHandleData->hHMHandle = 0; 362 rc = OSLibDosDupHandle(pHMSrcHandle->hHMHandle, &pHMHandleData->hHMHandle); 364 363 if (rc) 365 364 { … … 370 369 } 371 370 else { 372 if(fInherit) SetHandleInformation(pHMHandleData, ~HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);371 SetHandleInformation(pHMHandleData, HANDLE_FLAG_INHERIT, (fInherit) ? HANDLE_FLAG_INHERIT : 0); 373 372 374 373 SetLastError(ERROR_SUCCESS); 375 pHMHandleData->hHMHandle = *desthandle;376 374 return TRUE; // OK 377 375 } … … 620 618 nrpages++; 621 619 622 map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages);620 map->commitRange((ULONG)lpBuffer, offset & ~0xfff, FALSE, nrpages); 623 621 map->Release(); 624 622 } … … 844 842 { 845 843 DWORD ret; 844 HMFileInfo *fileInfo = (HMFileInfo *)pHMHandleData->dwUserData; 846 845 847 846 dprintfl(("KERNEL32: HMDeviceFileClass::SetFilePointer %s(%08xh,%08xh,%08xh,%08xh)\n", … … 852 851 dwMoveMethod)); 853 852 853 if(fileInfo && fileInfo->dwLXOffset) 854 { 855 switch(dwMoveMethod) 856 { 857 case FILE_BEGIN: 858 dprintf(("SetFilePointer FILE_BEGIN (LX) -> change offset from %x to %x", lDistanceToMove, lDistanceToMove+fileInfo->dwLXOffset)); 859 lDistanceToMove += fileInfo->dwLXOffset; 860 break; 861 862 case FILE_END: 863 //Could overshoot the virtual beginning of the PE file 864 lDistanceToMove -= MAGIC_STUBEXE_SIZE; 865 dprintf(("SetFilePointer FILE_END -> might be dangerous!!")); 866 break; 867 868 } 869 } 854 870 ret = OSLibDosSetFilePointer(pHMHandleData->hHMHandle, 855 871 lDistanceToMove, … … 1169 1185 } 1170 1186 1171 pHMHandleData->dwUserData = (DWORD) new HMFileInfo( (LPSTR)lpFileName, lpSecurityAttributes);1187 pHMHandleData->dwUserData = (DWORD) new HMFileInfo(0, (LPSTR)lpFileName, lpSecurityAttributes); 1172 1188 pHMHandleData->hHMHandle = 0x8000000; 1173 1189 return (NO_ERROR); … … 1282 1298 } 1283 1299 FindClose(hFind); 1300 1301 if(fileInfo->dwLXOffset) 1302 { 1303 //subtract the LX header and magic qword from the file size 1304 dprintf(("GetFileSize (LX) -> change size from %x to %x", finddata.nFileSizeLow, finddata.nFileSizeLow-fileInfo->dwLXOffset-MAGIC_STUBEXE_SIZE)); 1305 finddata.nFileSizeLow -= (fileInfo->dwLXOffset+MAGIC_STUBEXE_SIZE); 1306 } 1284 1307 return finddata.nFileSizeLow; 1285 1308 } … … 1329 1352 //****************************************************************************** 1330 1353 //****************************************************************************** 1331 HMFileInfo::HMFileInfo( LPSTR lpszFileName, PVOID lpSecurityAttributes)1354 HMFileInfo::HMFileInfo(HANDLE hFile, LPSTR lpszFileName, PVOID lpSecurityAttributes) 1332 1355 { 1333 1356 this->lpszFileName = (LPSTR)malloc(strlen(lpszFileName)+1); … … 1337 1360 strcpy(this->lpszFileName, lpszFileName); 1338 1361 this->lpSecurityAttributes = lpSecurityAttributes; 1362 dwLXOffset = 0; 1363 1364 //Only check files that end with .exe for now; they might be prepended with 1365 //an LX header. We need to skip that to present the original file to the 1366 //caller 1367 if(hFile && !stricmp(lpszFileName + strlen(lpszFileName) - 4, ".EXE")) 1368 { 1369 ULONG action, ulRead, signature, ulFileSize; 1370 ULONG magic[2]; 1371 IMAGE_DOS_HEADER doshdr; 1372 1373 //read dos header 1374 if(!OSLibDosRead(hFile, (LPVOID)&doshdr, sizeof(doshdr), &ulRead)) { 1375 goto failure; 1376 } 1377 if(OSLibDosSetFilePointer(hFile, doshdr.e_lfanew, NULL, FILE_BEGIN) != doshdr.e_lfanew) { 1378 goto failure; 1379 } 1380 //read signature dword 1381 if(!OSLibDosRead(hFile, (LPVOID)&signature, sizeof(signature), &ulRead)) { 1382 goto failure; 1383 } 1384 1385 //Make sure it's an LX executable before continueing 1386 if(doshdr.e_magic != IMAGE_DOS_SIGNATURE || (WORD)signature != IMAGE_OS2_SIGNATURE_LX) 1387 { 1388 goto failure; 1389 } 1390 1391 //magic signature located at 8 bytes from file end 1392 if(OSLibDosSetFilePointer(hFile, -8, NULL, FILE_END) == -1) { 1393 goto failure; 1394 } 1395 //read magic signature + pe offset 1396 if(!OSLibDosRead(hFile, (LPVOID)&magic[0], sizeof(magic), &ulRead)) { 1397 goto failure; 1398 } 1399 if(magic[0] != MAGIC_STUBEXE_SIGNATURE || magic[1] > ulFileSize) { 1400 goto failure; 1401 } 1402 //this is the offset of the PE image inside our LX executable 1403 dwLXOffset = magic[1]; 1404 1405 dprintf(("LX wrapper: PE file %s starts at %x", lpszFileName, dwLXOffset)); 1406 //reset file pointer to PE image start 1407 if(OSLibDosSetFilePointer(hFile, dwLXOffset, NULL, FILE_BEGIN) != dwLXOffset) { 1408 DebugInt3(); 1409 } 1410 goto end; 1411 1412 failure: 1413 //reset file pointer to file start 1414 if(OSLibDosSetFilePointer(hFile, 0, NULL, FILE_BEGIN) != 0) { 1415 DebugInt3(); 1416 } 1417 } 1418 end: 1419 return; 1339 1420 } 1340 1421 //****************************************************************************** -
trunk/src/kernel32/hmfile.h
r10073 r21302 28 28 { 29 29 public: 30 HMFileInfo( LPSTR lpszFileName, PVOID lpSecurityAttributes);30 HMFileInfo(HANDLE hFile, LPSTR lpszFileName, PVOID lpSecurityAttributes); 31 31 ~HMFileInfo(); 32 32 33 33 char *lpszFileName; 34 34 PVOID lpSecurityAttributes; 35 DWORD dwLXOffset; 35 36 }; 36 37 … … 59 60 PHMHANDLEDATA pHMSrcHandle, 60 61 HANDLE destprocess, 61 PHANDLE desthandle,62 62 DWORD fdwAccess, 63 63 BOOL fInherit, -
trunk/src/kernel32/hmmmap.cpp
r9971 r21302 74 74 //It's not allowed to map a file of length 0 according to MSDN. This time 75 75 //the docs are correct. (verified in NT4 SP6) 76 //bird: It's not allowed to create a non-file based mapping with size 0. 76 77 //TODO: also need to verify access rights of the file handle (write maps need 77 78 // write access obviously) … … 81 82 dwFileSizeLow = ::GetFileSize(hFile, &dwFileSizeHigh); 82 83 if(dwFileSizeHigh == 0 && dwFileSizeLow == 0) { 84 /* 85 * Two actions, if we can grow the file we should if not fail. 86 */ 87 if (!(protect & PAGE_READWRITE)) /* TODO: check this and verify flags */ 88 { 83 89 dprintf(("CreateFileMappingA: not allowed to map a file with length 0!!")); 84 return ERROR_FILE_INVALID; 90 return ERROR_NOT_ENOUGH_MEMORY; /* XP returns this if the mapping is readonly, odd.. */ 91 } 92 /* 93 * Try extend the file. 94 * (Not sure if we need to preserve the filepointer, but it doesn't hurt I think.) 95 */ 96 LONG lFilePosHigh = 0; 97 DWORD dwFilePosLow = ::SetFilePointer(hFile, 0, &lFilePosHigh, FILE_CURRENT); 98 LONG lFileSizeHigh = size_high; 99 if ( ::SetFilePointer(hFile, size_low, &lFileSizeHigh, FILE_BEGIN) == INVALID_SET_FILE_POINTER 100 || !::SetEndOfFile(hFile)) 101 { 102 ::SetFilePointer(hFile, dwFilePosLow, &lFilePosHigh, FILE_BEGIN); 103 dprintf(("CreateFileMappingA: unable to grow file to 0x%#08x%08x bytes.\n", size_high, size_low)); 104 return ERROR_DISK_FULL; 105 } 106 ::SetFilePointer(hFile, dwFilePosLow, &lFilePosHigh, FILE_BEGIN); 85 107 } 86 108 } -
trunk/src/kernel32/hmnpipe.cpp
r10132 r21302 181 181 BOOL HMDeviceNamedPipeClass::CloseHandle(PHMHANDLEDATA pHMHandleData) 182 182 { 183 BOOL dwFlags = 0; 184 183 185 dprintf(("KERNEL32: HMDeviceNamedPipeClass::CloseHandle(%08x)", pHMHandleData->hHMHandle)); 184 186 187 GetHandleInformation(pHMHandleData->hWin32Handle, &dwFlags); 188 //Only disconnect if this handle can't be inherited. A child proces can 189 //still be using it 190 if(!(dwFlags & HANDLE_FLAG_INHERIT)) { 185 191 OSLibDosDisconnectNamedPipe(pHMHandleData->hHMHandle); 192 } 186 193 return OSLibDosClose(pHMHandleData->hHMHandle); 187 194 } … … 430 437 return bRC; 431 438 } 432 //****************************************************************************** 433 //****************************************************************************** 439 /***************************************************************************** 440 * Name : HMDeviceNamedPipeClass::DuplicateHandle 441 * Purpose : 442 * Parameters: 443 * various parameters as required 444 * Variables : 445 * Result : 446 * Remark : DUPLICATE_CLOSE_SOURCE flag handled in HMDuplicateHandle 447 * 448 * Status : partially implemented 449 * 450 * Author : SvL 451 *****************************************************************************/ 452 BOOL HMDeviceNamedPipeClass::DuplicateHandle(HANDLE srchandle, PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 453 PHMHANDLEDATA pHMSrcHandle, 454 HANDLE destprocess, 455 DWORD fdwAccess, 456 BOOL fInherit, 457 DWORD fdwOptions, 458 DWORD fdwOdinOptions) 459 { 460 DWORD rc; 461 462 dprintf(("KERNEL32:HMDeviceNamedPipeClass::DuplicateHandle (%08x,%08x,%08x,%08x)", 463 pHMHandleData, srcprocess, pHMSrcHandle->hHMHandle, destprocess)); 464 465 if(destprocess != srcprocess) 466 { 467 //TODO:!!!! 468 dprintf(("ERROR: DuplicateHandle; different processes not yet supported!!")); 469 return FALSE; 470 } 471 472 if(!(fdwOptions & DUPLICATE_SAME_ACCESS) && fdwAccess != pHMSrcHandle->dwAccess) { 473 dprintf(("WARNING: DuplicateHandle; app wants different access permission; Not supported!! (%x, %x)", fdwAccess, pHMSrcHandle->dwAccess)); 474 } 475 476 pHMHandleData->hHMHandle = 0; 477 rc = OSLibDosDupHandle(pHMSrcHandle->hHMHandle, &pHMHandleData->hHMHandle); 478 if (rc) 479 { 480 dprintf(("ERROR: DuplicateHandle: OSLibDosDupHandle(%x) failed = %u", 481 pHMSrcHandle->hHMHandle, rc)); 482 SetLastError(rc); 483 return FALSE; // ERROR 484 } 485 else { 486 SetHandleInformation(pHMHandleData, HANDLE_FLAG_INHERIT, (fInherit) ? HANDLE_FLAG_INHERIT : 0); 487 488 SetLastError(ERROR_SUCCESS); 489 return TRUE; // OK 490 } 491 } 492 //****************************************************************************** 493 //****************************************************************************** -
trunk/src/kernel32/hmnpipe.h
r10132 r21302 11 11 #ifndef _HM_NPIPE_H_ 12 12 #define _HM_NPIPE_H_ 13 14 #include "hmfile.h" 13 15 14 16 class HMDeviceNamedPipeClass : public HMDeviceFileClass … … 95 97 LPDWORD arg3, 96 98 BOOL arg4); 99 100 virtual BOOL DuplicateHandle(HANDLE srchandle, PHMHANDLEDATA pHMHandleData, HANDLE srcprocess, 101 PHMHANDLEDATA pHMSrcHandle, HANDLE destprocess, 102 DWORD fdwAccess, BOOL fInherit, DWORD fdwOptions, DWORD fdwOdinOptions); 103 97 104 }; 98 105 -
trunk/src/kernel32/hmopen32.cpp
r9748 r21302 87 87 BOOL bRC; 88 88 89 dprintfl(("KERNEL32: HandleManager::Open32::CloseHandle(%08x) \n",90 pHMHandleData ->hHMHandle));89 dprintfl(("KERNEL32: HandleManager::Open32::CloseHandle(%08x) %p\n", 90 pHMHandleData, pHMHandleData->hHMHandle)); 91 91 92 92 bRC = O32_CloseHandle(pHMHandleData->hHMHandle); … … 114 114 PHMHANDLEDATA pHMSrcHandle, 115 115 HANDLE destprocess, 116 PHANDLE desthandle,117 116 DWORD fdwAccess, 118 117 BOOL fInherit, … … 123 122 124 123 dprintf(("KERNEL32:HandleManager::Open32::DuplicateHandle %s(%08x,%08x,%08x,%08x,%08x)\n", 125 lpHMDeviceName, 126 pHMHandleData, 127 srcprocess, pHMSrcHandle->hHMHandle, destprocess, desthandle)); 128 129 rc = O32_DuplicateHandle(srcprocess, pHMSrcHandle->hHMHandle, destprocess, desthandle, fdwAccess, fInherit, fdwOptions); 130 131 if(rc == TRUE) { 132 pHMHandleData->hHMHandle = *desthandle; 133 return TRUE; 134 } 135 else return FALSE; 124 lpHMDeviceName, pHMHandleData, srcprocess, pHMSrcHandle->hHMHandle, destprocess)); 125 126 pHMHandleData->hHMHandle = 0; 127 rc = O32_DuplicateHandle(srcprocess, pHMSrcHandle->hHMHandle, destprocess, &pHMHandleData->hHMHandle, fdwAccess, fInherit, fdwOptions); 128 129 return rc; 136 130 } 137 131 -
trunk/src/kernel32/hmopen32.h
r9748 r21302 45 45 PHMHANDLEDATA pHMSrcHandle, 46 46 HANDLE destprocess, 47 PHANDLE desthandle,48 47 DWORD fdwAccess, 49 48 BOOL fInherit, -
trunk/src/kernel32/hmsemaphore.cpp
r9748 r21302 92 92 (LPTSTR)lpszSemaphoreName); 93 93 94 dprintf(("KERNEL32: HandleManager::Semaphore::CreateSemaphore hOpen32 = %p, pHMHandleData->hHMHandle = %p\n", hOpen32, pHMHandleData->hHMHandle)); 95 94 96 if (0 != hOpen32) // check success 95 97 { -
trunk/src/kernel32/hmthread.cpp
r9949 r21302 30 30 #include <HandleManager.H> 31 31 #include "HMThread.h" 32 #include "oslibdos.h" 32 33 #include "oslibthread.h" 34 #include "oslibmem.h" 33 35 34 36 #include <win\thread.h> … … 57 59 DWORD fdwCreate, 58 60 LPDWORD lpIDThread, 59 BOOL f FirstThread)61 BOOL fRegisterThread) 60 62 { 61 63 Win32Thread *winthread; … … 78 80 79 81 //SvL: This doesn't really create a thread, but only sets up the 80 // handle of th read 081 if(f FirstThread) {82 // handle of the current thread. 83 if(fRegisterThread) { 82 84 pHMHandleData->hHMHandle = O32_GetCurrentThread(); //return Open32 handle of thread 83 85 return pHMHandleData->hHMHandle; … … 144 146 PHMHANDLEDATA pHMSrcHandle, 145 147 HANDLE destprocess, 146 PHANDLE desthandle,147 148 DWORD fdwAccess, 148 149 BOOL fInherit, … … 153 154 OBJ_THREAD *threadsrc = (OBJ_THREAD *)pHMSrcHandle->dwUserData; 154 155 155 dprintf(("KERNEL32:HMDeviceThreadClass::DuplicateHandle (%08x,%08x,%08x,%08x ,%08x)",156 pHMHandleData, srcprocess, pHMSrcHandle->hHMHandle, destprocess , desthandle));156 dprintf(("KERNEL32:HMDeviceThreadClass::DuplicateHandle (%08x,%08x,%08x,%08x)", 157 pHMHandleData, srcprocess, pHMSrcHandle->hHMHandle, destprocess)); 157 158 158 159 if(destprocess != srcprocess) … … 162 163 return FALSE; 163 164 } 164 ret = O32_DuplicateHandle(srcprocess, pHMSrcHandle->hHMHandle, destprocess, desthandle, fdwAccess, fInherit, fdwOptions); 165 pHMHandleData->hHMHandle = 0; 166 ret = O32_DuplicateHandle(srcprocess, pHMSrcHandle->hHMHandle, destprocess, &pHMHandleData->hHMHandle, fdwAccess, fInherit, fdwOptions); 165 167 166 168 if(ret == TRUE) { 167 169 OBJ_THREAD *threaddest = (OBJ_THREAD *)malloc(sizeof(OBJ_THREAD)); 168 170 if(threaddest == NULL) { 169 O32_CloseHandle( *desthandle);171 O32_CloseHandle(pHMHandleData->hHMHandle); 170 172 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 171 173 return FALSE; … … 180 182 } 181 183 182 pHMHandleData->hHMHandle = *desthandle;183 184 return TRUE; 184 185 } 185 else return FALSE; 186 else 187 { 188 dprintf(("O32_DuplicateHandle failed for handle %x!!", pHMSrcHandle->hHMHandle)); 189 return FALSE; 190 } 186 191 } 187 192 //****************************************************************************** … … 209 214 { 210 215 DWORD dwSuspend; 216 CONTEXT context; 211 217 OBJ_THREAD *threadobj = (OBJ_THREAD *)pHMHandleData->dwUserData; 212 218 213 219 TEB *teb = GetTEBFromThreadHandle(GET_THREADHANDLE(hThread)); 214 if(teb) { 220 if(teb == NULL) { 221 dprintf(("ERROR: invalid thread handle")); 222 SetLastError(ERROR_INVALID_THREAD_ID); //?? 223 return -1; 224 } 225 226 context.Eip = 0; 227 if(teb->o.odin.context.ContextFlags) 228 { 229 context.ContextFlags = CONTEXT_CONTROL; 230 if(GetThreadContext(hThread, pHMHandleData, &context) == FALSE) 231 { 232 DebugInt3(); 233 context.Eip = 0; 234 } 235 if(teb->o.odin.dwSuspend == 1 && teb->o.odin.context.ContextFlags && context.Eip) 236 {//SetThreadContext was called for this thread and it's about to be restored 237 238 //Since there's no equivalent of SetThreadContext in OS/2, we put an 239 //illegal instruction at the instruction pointer of this thread to 240 //make sure an exception is triggered. Inside the exception handler 241 //of the thread we can change the registers. 242 //(XCPT_PRIVILEGED_INSTRUCTION exception handler in exceptions.cpp) 243 //(see detailed description in the HMDeviceThreadClass::SetThreadContext method) 244 USHORT *lpEIP = (USHORT *)context.Eip; 245 246 if(*lpEIP != SETTHREADCONTEXT_INVALID_LOCKOPCODE) 247 { 248 int size; 249 250 teb->o.odin.dwAliasOffset = (DWORD)lpEIP & 0xFFF; 251 if(teb->o.odin.dwAliasOffset + 2 >= PAGE_SIZE) { 252 size = 8192; 253 } 254 else size = teb->o.odin.dwAliasOffset + 2; 255 256 lpEIP = (USHORT *)((DWORD)lpEIP & ~0xFFF); 257 258 if(OSLibDosAliasMem(lpEIP, size, &teb->o.odin.lpAlias, PAG_READ|PAG_WRITE) == 0) 259 { 260 teb->o.odin.savedopcode = *(USHORT*)((char *)teb->o.odin.lpAlias+teb->o.odin.dwAliasOffset); 261 262 //sti -> undefined opcode exception 263 *(USHORT *)((char *)teb->o.odin.lpAlias+teb->o.odin.dwAliasOffset) = SETTHREADCONTEXT_INVALID_LOCKOPCODE; 264 } 265 else DebugInt3(); 266 267 //temporarily boost priority to ensure this thread is scheduled first 268 //we reduce the priority in the exception handler 269 OSLibDosSetMaxPriority(ODIN_TO_OS2_THREADID(teb->o.odin.threadId)); 270 } 271 else { 272 dprintf(("already patched!?!")); 273 DebugInt3(); 274 } 275 } 276 } 277 215 278 teb->o.odin.dwSuspend--; 216 279 dprintf(("ResumeThread (%08xh) : count %d", pHMHandleData->hHMHandle, teb->o.odin.dwSuspend)); 217 } 280 218 281 dwSuspend = O32_ResumeThread(pHMHandleData->hHMHandle); 219 if(dwSuspend == -1) { 282 if(dwSuspend == -1) 283 { 220 284 teb->o.odin.dwSuspend++; 221 285 dprintf(("!ERROR!: ResumeThread FAILED")); 222 } 286 287 if(teb->o.odin.dwSuspend == 1 && teb->o.odin.context.ContextFlags && context.Eip) 288 {//Undo previous patching 289 char *lpEIP = (char *)context.Eip; 290 291 if(*lpEIP == SETTHREADCONTEXT_INVALID_LOCKOPCODE) 292 { 293 dprintf(("Undo SetThreadContext patching!!")); 294 295 USHORT *lpAlias = (USHORT*)((char *)teb->o.odin.lpAlias + teb->o.odin.dwAliasOffset); 296 //put back old byte 297 *lpAlias = teb->o.odin.savedopcode; 298 299 //restore the original priority (we boosted it to ensure this thread was scheduled first) 300 ::SetThreadPriority(teb->o.odin.hThread, ::GetThreadPriority(teb->o.odin.hThread)); 301 302 OSLibDosFreeMem(teb->o.odin.lpAlias); 303 } 304 else { 305 dprintf(("not patched!?!")); 306 DebugInt3(); 307 } 308 teb->o.odin.dwAliasOffset = 0; 309 teb->o.odin.lpAlias = NULL; 310 teb->o.odin.context.ContextFlags = 0; 311 } 312 } 313 223 314 return dwSuspend; 224 315 } … … 264 355 } 265 356 //****************************************************************************** 266 //TODO: Implement this?? 357 //****************************************************************************** 358 #ifdef DEBUG 359 void DumpContext(CONTEXT *lpContext) 360 { 361 dprintf(("************************ THREAD CONTEXT ************************")); 362 if(lpContext->ContextFlags & CONTEXT_CONTROL) { 363 dprintf(("CS:EIP %04x:%08x FLAGS %08x", lpContext->SegCs, lpContext->Eip, lpContext->EFlags)); 364 dprintf(("SS:ESP %04x:%08x EBP %08x", lpContext->SegSs, lpContext->Esp, lpContext->Ebp)); 365 } 366 if(lpContext->ContextFlags & CONTEXT_INTEGER) { 367 dprintf(("EAX %08x EBX %08x ECX %08x EDX %08x", lpContext->Eax, lpContext->Ebx, lpContext->Ecx, lpContext->Edx)); 368 dprintf(("ESI %08x EDI %08x", lpContext->Esi, lpContext->Edi)); 369 } 370 if(lpContext->ContextFlags & CONTEXT_SEGMENTS) { 371 dprintf(("DS %04x ES %04x FS %04x GS %04x", (ULONG)lpContext->SegDs, (ULONG)lpContext->SegEs, (ULONG)lpContext->SegFs, (ULONG)lpContext->SegGs)); 372 } 373 dprintf(("************************ THREAD CONTEXT ************************")); 374 // if(lpContext->ContextFlags & CONTEXT_FLOATING_POINT) { 375 // //TODO: First 7 dwords the same? 376 // memcpy(&lpContext->FloatSave, ctxrec.ctx_env, sizeof(ctxrec.ctx_env)); 377 // memcpy(&lpContext->FloatSave.RegisterArea, ctxrec.ctx_stack, sizeof(ctxrec.ctx_stack)); 378 // } 379 } 380 #else 381 #define DumpContext(a) 382 #endif 383 //****************************************************************************** 267 384 //****************************************************************************** 268 385 BOOL HMDeviceThreadClass::GetThreadContext(HANDLE hThread, PHMHANDLEDATA pHMHandleData, PCONTEXT lpContext) 269 386 { 270 dprintf(("GetThreadContext NOT IMPLEMENTED!! (TRUE)\n")); 271 memset(lpContext, 0, sizeof(CONTEXT)); 272 273 /* make up some plausible values for segment registers */ 274 lpContext->SegCs = getCS(); 275 lpContext->SegDs = getDS(); 276 lpContext->SegSs = getSS(); 277 lpContext->SegEs = getES(); 278 lpContext->SegGs = getGS(); 279 lpContext->SegFs = GetFS(); 280 281 return TRUE; 282 } 283 //****************************************************************************** 284 //TODO: Implement this?? 387 OBJ_THREAD *threadobj = (OBJ_THREAD *)pHMHandleData->dwUserData; 388 BOOL ret; 389 390 TEB *teb = GetTEBFromThreadHandle(GET_THREADHANDLE(hThread)); 391 if(teb) { 392 if(teb->o.odin.dwSuspend == 0) { 393 dprintf(("ERROR: thread not suspended!!")); 394 DebugInt3(); 395 SetLastError(ERROR_INVALID_OPERATION); //??? 396 return FALSE; 397 } 398 399 ret = OSLibQueryThreadContext(ODIN_TO_OS2_THREADID(teb->o.odin.threadId), teb->teb_sel, lpContext); 400 if(ret == TRUE) { 401 DumpContext(lpContext); 402 } 403 return ret; 404 } 405 dprintf(("!WARNING!: TEB not found!!")); 406 SetLastError(ERROR_INVALID_HANDLE); 407 return FALSE; 408 } 409 //****************************************************************************** 410 // HMDeviceThreadClass::SetThreadContext 411 // 412 // Change the context (registers) of a suspended thread 413 // 414 // Parameters: 415 // 416 // HANDLE hThread - thread handle 417 // PHMHANDLEDATA pHMHandleData - handle data 418 // const CONTEXT *lpContext - context record (IN) 419 // 420 // Returns: 421 // TRUE - success 422 // FALSE - failure 423 // 424 // Remarks: 425 // 426 // Since OS/2 doesn't provide an equivalent for this function, we need to change 427 // the thread context manually. (DosDebug isn't really an option) 428 // 429 // We save the new context in the TEB structure. When this thread is 430 // activated by ResumeThread, we'll change the instruction addressed by the 431 // thread's EIP to an invalid instruction (sti). 432 // When the thread is activated, it will generate an exception. Inside the 433 // exception handler we change the registers, restore the original memory 434 // and continue. 435 // To make sure the thread is executed first and noone else will execute the 436 // invalid instruction, we temporarily boost the thread's priority to the max. 437 // (time critical, delta +31; max priority of win32 threads is time critical, 438 // delta 0) 439 // The priority is restored in the exception handler. 440 // 285 441 //****************************************************************************** 286 442 BOOL HMDeviceThreadClass::SetThreadContext(HANDLE hThread, PHMHANDLEDATA pHMHandleData, const CONTEXT *lpContext) 287 443 { 288 dprintf(("SetThreadContext NOT IMPLEMENTED!!\n")); 289 444 OBJ_THREAD *threadobj = (OBJ_THREAD *)pHMHandleData->dwUserData; 445 BOOL ret; 446 447 DumpContext((CONTEXT *)lpContext); 448 449 TEB *teb = GetTEBFromThreadHandle(GET_THREADHANDLE(hThread)); 450 if(teb) 451 { 452 if(teb->o.odin.dwSuspend == 0) { 453 dprintf(("ERROR: thread not suspended!!")); 454 SetLastError(ERROR_INVALID_OPERATION); //??? 455 return FALSE; 456 } 457 if(lpContext->ContextFlags & CONTEXT_CONTROL) { 458 teb->o.odin.context.ContextFlags |= CONTEXT_CONTROL; 459 teb->o.odin.context.Ebp = lpContext->Ebp; 460 teb->o.odin.context.Eip = lpContext->Eip; 461 teb->o.odin.context.SegCs = lpContext->SegCs; 462 teb->o.odin.context.EFlags = lpContext->EFlags; 463 teb->o.odin.context.Esp = lpContext->Esp; 464 teb->o.odin.context.SegSs = lpContext->SegSs; 465 } 466 if(lpContext->ContextFlags & CONTEXT_INTEGER) { 467 teb->o.odin.context.ContextFlags |= CONTEXT_INTEGER; 468 teb->o.odin.context.Edi = lpContext->Edi; 469 teb->o.odin.context.Esi = lpContext->Esi; 470 teb->o.odin.context.Ebx = lpContext->Ebx; 471 teb->o.odin.context.Edx = lpContext->Edx; 472 teb->o.odin.context.Ecx = lpContext->Ecx; 473 teb->o.odin.context.Eax = lpContext->Eax; 474 } 475 if(lpContext->ContextFlags & CONTEXT_SEGMENTS) { 476 teb->o.odin.context.ContextFlags |= CONTEXT_SEGMENTS; 477 teb->o.odin.context.SegGs = lpContext->SegGs; 478 teb->o.odin.context.SegFs = lpContext->SegFs; 479 teb->o.odin.context.SegEs = lpContext->SegEs; 480 teb->o.odin.context.SegDs = lpContext->SegDs; 481 } 482 if(lpContext->ContextFlags & CONTEXT_FLOATING_POINT) { 483 teb->o.odin.context.ContextFlags |= CONTEXT_FLOATING_POINT; 484 memcpy(&teb->o.odin.context.FloatSave, &lpContext->FloatSave, sizeof(lpContext->FloatSave)); 485 } 486 SetLastError(ERROR_SUCCESS); 487 return TRUE; 488 } 489 dprintf(("!WARNING!: TEB not found!!")); 490 SetLastError(ERROR_INVALID_HANDLE); 290 491 return FALSE; 291 492 } -
trunk/src/kernel32/hmthread.h
r9748 r21302 19 19 #define THREAD_ALIVE 1 20 20 21 #define SETTHREADCONTEXT_INVALID_LOCKOPCODE 0x90F0 //invalid lock sequence 22 21 23 class HMDeviceThreadClass : public HMDeviceOpen32Class 22 24 { … … 31 33 DWORD fdwCreate, 32 34 LPDWORD lpIDThread, 33 BOOL f FirstThread);35 BOOL fRegisterThread); 34 36 35 37 /* this is a handler method for calls to WaitForSingleObject */ … … 49 51 PHMHANDLEDATA pHMSrcHandle, 50 52 HANDLE destprocess, 51 PHANDLE desthandle,52 53 DWORD fdwAccess, 53 54 BOOL fInherit, -
trunk/src/kernel32/initkernel32.cpp
r10606 r21302 60 60 #include <stats.h> 61 61 #include <heapshared.h> 62 #include < heapstring.h>62 #include <_ras.h> 63 63 64 64 #define DBG_LOCALLOG DBG_initterm … … 71 71 extern DWORD kernel32_PEResTab; 72 72 } 73 74 extern PFN pfnImSetMsgQueueProperty;75 73 76 74 ULONG flAllocMem = 0; /* flag to optimize DosAllocMem to use all the memory on SMP machines */ … … 81 79 BOOL fInit = FALSE; 82 80 BOOL fWin32k = FALSE; 83 HMODULE imHandle = 0;84 char szModName[ 256 ] = "";85 81 86 82 /****************************************************************************/ … … 113 109 case 0 : 114 110 { 111 // This always must be the first thing to do. 112 RasInitialize (hModule); 113 #ifdef RAS 114 extern void rasInitVirtual (void); 115 rasInitVirtual (); 116 #endif 117 115 118 ParseLogStatusKERNEL32(); 116 119 … … 221 224 CODEPAGE_Init(); 222 225 223 if( IsDBCSEnv() && DosLoadModule( szModName, sizeof( szModName ), "OS2IM.DLL", &imHandle ) == 0 )224 DosQueryProcAddr( imHandle, 140, NULL, &pfnImSetMsgQueueProperty );225 226 226 InitSystemInfo(ulSysinfo); 227 227 //Set up environment as found in NT … … 237 237 SetProcessAffinityMask(GetCurrentProcess(), dwSystemAffinityMask); 238 238 239 //Activate current timezone information 240 TIME_ZONE_INFORMATION tzone; 241 GetTimeZoneInformation(&tzone); 242 SetTimeZoneInformation(&tzone); 243 239 244 //Set default paths for PE & NE loaders 240 245 InitLoaders(); 246 247 RasEntry (RAS_EVENT_Kernel32InitComplete, &dllHandle, sizeof (dllHandle)); 248 241 249 break; 242 250 } … … 264 272 dprintf(("kernel32 exit %d\n", ulReason)); 265 273 266 if( IsDBCSEnv() && imHandle )267 DosFreeModule( imHandle );268 269 274 //Flush and delete all open memory mapped files 270 275 Win32MemMap::deleteAll(); 271 276 WinExe = NULL; 277 278 FinalizeMemMaps(); 272 279 273 280 WriteOutProfiles(); … … 281 288 282 289 HMTerminate(); /* shutdown handlemanager */ 290 291 #ifdef DEBUG 292 extern void printCriticalSectionStatistic (void); 293 printCriticalSectionStatistic (); 294 #endif 283 295 284 296 #if defined(DEBUG) && defined(__IBMCPP__) && __IBMCPP__ == 300 … … 298 310 //NOTE: Must be done after DestroyTIB 299 311 ClosePrivateLogFiles(); 312 313 #ifndef DEBUG 314 //if we do a dump of the shared heap, then we'll need the logging facility 315 //for a little while longer 300 316 CloseLogFile(); 317 #endif 301 318 302 319 /* … … 305 322 libWin32kSetEnvironment(NULL, 0, 0); 306 323 libWin32kTerm(); 324 325 RasUninitialize (); 326 307 327 return ; 308 328 } -
trunk/src/kernel32/kernel32.mak
r10382 r21302 145 145 $(OBJDIR)\version.obj \ 146 146 $(OBJDIR)\mmapnotify.obj \ 147 $(OBJDIR)\exceptstackdump.obj \ 147 148 !ifdef DEBUG 148 $(OBJDIR)\exceptstackdump.obj \149 149 $(OBJDIR)\dbgwrap.obj \ 150 150 !endif … … 159 159 $(OBJDIR)\conodin32.obj \ 160 160 $(OBJDIR)\oslibwps.obj \ 161 $(OBJDIR)\_ras.obj \ 161 162 $(OBJDIR)\kernelrsrc.obj 162 163 -
trunk/src/kernel32/kernel32dbg.def
r10606 r21302 147 147 ; Ordinal0097 = _OS2Ordinal0097@?? @97 148 148 ; Ordinal0098 = _OS2Ordinal0098@?? @98 149 KERNEL32_99 = _KERNEL32_99@4 @99NONAME150 KERNEL32_100 = _KERNEL32_100@12 @100NONAME149 _KERNEL32_99@4 @99 NONAME 150 _KERNEL32_100@12 @100 NONAME 151 151 ; Ordinal0101 = _OS2Ordinal0101@?? @101 152 152 … … 1003 1003 GetVolumeNameForVolumeMountPointW = _DbgGetVolumeNameForVolumeMountPointW@12 @915 1004 1004 1005 ; 1006 ; ENDOFEXPORTS 1007 ; Internal function marker 1008 ; 1005 1009 1006 1010 ; … … 1160 1164 InitializeSharedHeap @1276 NONAME 1161 1165 DestroySharedHeap @1277 NONAME 1166 _debug_smalloc @1278 NONAME 1167 _debug_smallocfill @1279 NONAME 1168 _debug_sfree @1280 NONAME 1162 1169 1163 1170 ;code memory allocation … … 1211 1218 OSLibDosDevIOCtl @2026 NONAME 1212 1219 1213 OSLibImSetMsgQueueProperty @2029 NONAME1214 1215 1220 fIsDBCSEnv @2103 NONAME 1221 _hookInit@4 @2104 NONAME 1216 1222 1217 1223 vsnprintfW @2030 NONAME … … 1225 1231 ; override TIB switching 1226 1232 _ODIN_SetTIBSwitch@4 @2102 NONAME 1227 1228 _hookInit@4 @2104 NONAME1229 1233 1230 1234 GetDisplayCodepage @3000 NONAME … … 1252 1256 _ODIN_SetExceptionHandler@4 @3114 NONAME 1253 1257 _ODIN_UnsetExceptionHandler@4 @3115 NONAME 1258 1259 _PSAPI_EnumProcessModules@16 @3116 NONAME 1260 _PSAPI_GetModuleInformation@16 @3117 NONAME 1261 1262 _ODIN_SetProcessDword@12 @3118 NONAME 1254 1263 1255 1264 ; Char functions (forwarders from user32) … … 1286 1295 _DbgIsCharUpperA@4 @3159 NONAME 1287 1296 _DbgIsCharUpperW@4 @3160 NONAME 1297 1298 1299 ; RAS functions 1300 RasRegisterObjectTracking = _RasRegisterObjectTracking@24 @3500 1301 RasDeregisterObjectTracking = _RasDeregisterObjectTracking@4 @3501 1302 RasAddObject = _RasAddObject@16 @3502 1303 RasRemoveObject = _RasRemoveObject@8 @3503 1304 RasSetObjectUserData = _RasSetObjectUserData@20 @3504 1305 RasQueryObjectUserData = _RasQueryObjectUserData@20 @3505 1306 RasInitialize = _RasInitialize@4 @3506 1307 RasUninitialize = _RasUninitialize@0 @3507 1308 _RasLog = _RasLog @3508 1309 RasLogMsg = _RasLogMsg@12 @3509 1310 RasLogObjects = _RasLogObjects@8 @3510 1311 RasEnterSerialize = _RasEnterSerialize@0 @3511 1312 RasExitSerialize = _RasExitSerialize@0 @3512 1313 _RasLogNoEOL = _RasLogNoEOL @3513 1314 RasOpenLogChannel = _RasOpenLogChannel@12 @3514 1315 RasWriteLogChannel = _RasWriteLogChannel@12 @3515 1316 RasCloseLogChannel = _RasCloseLogChannel@4 @3516 1317 _RasLog2 = _RasLog2 @3517 1318 RasLogMsg2 = _RasLogMsg2@16 @3518 1319 _RasLogNoEOL2 = _RasLogNoEOL2 @3519 1320 RasSaveContext = _RasSaveContext@4 @3520 1321 RasRestoreContext = _RasRestoreContext@4 @3521 1322 RasEntry = _RasEntry@12 @3522 1323 RasSetProcAddr = _RasSetProcAddr@12 @3523 1324 RasTrackMemFree = _RasTrackMemFree@8 @3524 1325 RasTrackMemAlloc = _RasTrackMemAlloc@8 @3525 1326 RasTrackMemRealloc = _RasTrackMemRealloc@12 @3526 1327 RasCountObjects = _RasCountObjects@12 @3527 1328 RasGetTrackHandle = _RasGetTrackHandle@4 @3528 1329 -
trunk/src/kernel32/kobjects.cpp
r9748 r21302 31 31 32 32 33 // REMARK: THIS IS IN PREPARATION FOR HANDLEMANAGER SUPPORT (PH) !!34 //#define HMCreateEvent O32_CreateEvent35 //#define HMCreateMutex O32_CreateMutex36 //#define HMCreateSemaphore O32_CreateSemaphore37 //#define HMSetEvent O32_SetEvent38 //#define HMReleaseMutex O32_ReleaseMutex39 //#define HMWaitForSingleObject O32_WaitForSingleObject40 //#define HMWaitForSingleObjectEx O32_WaitForSingleObjectEx41 //#define HMGetOverlappedResult O32_GetOverlappedResult42 //#define HMOpenEvent O32_OpenEvent43 //#define HMOpenMutex O32_OpenMutex44 //#define HMOpenSemaphore O32_OpenSemaphore45 //#define HMPulseEvent O32_PulseEvent46 //#define HMReleaseSemaphore O32_ReleaseSemaphore47 //#define HMResetEvent O32_ResetEvent48 //#define HMWaitForMultipleObjects O32_WaitForMultipleObjects49 //#define HMWaitForMultipleObjectsEx O32_WaitForMultipleObjectsEx50 //#define HMFlushFileBuffers O32_FlushFileBuffers51 #define HMSetHandleCount O32_SetHandleCount52 #define HMGetHandleCount O32_GetHandleCount53 //#define HMDuplicateHandle O32_DuplicateHandle54 55 56 57 33 /***************************************************************************** 58 34 * Defines * … … 64 40 65 41 66 /***************************************************************************** 67 * Name : BOOL CreateEventA 68 * Purpose : forward call to Open32 69 * Parameters: 70 * Variables : 71 * Result : 72 * Remark : 73 * Status : 74 * 75 * Author : Patrick Haller [Fri, 1998/06/12 03:44] 76 *****************************************************************************/ 77 78 HANDLE WIN32API CreateEventA(LPSECURITY_ATTRIBUTES lpsa, BOOL fManualReset, 79 BOOL fInitialState, 80 LPCTSTR lpszEventName) 81 { 82 return(HMCreateEvent(lpsa, /* create event semaphore */ 83 fManualReset, 84 fInitialState, 85 lpszEventName)); 86 } 87 88 89 /***************************************************************************** 90 * Name : BOOL CreateEventW 91 * Purpose : forward call to Open32 92 * Parameters: 93 * Variables : 94 * Result : 95 * Remark : handle translation is done in CreateEventA 96 * Status : 97 * 98 * Author : Patrick Haller [Fri, 1998/06/12 03:44] 99 *****************************************************************************/ 100 101 HANDLE WIN32API CreateEventW(LPSECURITY_ATTRIBUTES arg1, 102 BOOL arg2, BOOL arg3, 103 LPCWSTR arg4) 104 { 105 HANDLE rc; 106 char *astring; 107 108 if (arg4 != NULL) // support for unnamed semaphores 109 astring = UnicodeToAsciiString((LPWSTR)arg4); 110 else 111 astring = NULL; 112 113 dprintf(("KERNEL32: CreateEventW(%s)\n", 114 astring)); 115 116 rc = HMCreateEvent(arg1, 117 arg2, 118 arg3, 119 astring); 120 121 if (astring != NULL) 122 FreeAsciiString(astring); 123 124 return(rc); 125 } 126 127 128 /***************************************************************************** 129 * Name : BOOL CreateMutexA 130 * Purpose : forward call to Open32 131 * Parameters: 132 * Variables : 133 * Result : 134 * Remark : handle translation is done in CreateMutexA 135 * Status : 136 * 137 * Author : Patrick Haller [Fri, 1999/06/18 03:44] 138 *****************************************************************************/ 139 140 HANDLE WIN32API CreateMutexA(LPSECURITY_ATTRIBUTES lpsa, 141 BOOL fInitialOwner, 142 LPCTSTR lpszMutexName) 143 { 144 dprintf(("KERNEL32: CreateMutexA(%s)\n", 145 lpszMutexName)); 146 147 return(HMCreateMutex(lpsa, 148 fInitialOwner, 149 lpszMutexName)); 150 } 42 43 151 44 152 45 … … 174 67 astring = NULL; 175 68 176 dprintf(("KERNEL32: CreateMutexW(%s)\n", 177 astring)); 178 179 rc = HMCreateMutex(arg1, 69 rc = CreateMutexA(arg1, 180 70 arg2, 181 71 astring); … … 185 75 186 76 return(rc); 187 }188 189 190 /*****************************************************************************191 * Name : BOOL ReleaseMutex192 * Purpose : forward call to Open32193 * Parameters:194 * Variables :195 * Result :196 * Remark : handle translation is done in ReleaseMutex197 * Status :198 *199 * Author : Patrick Haller [Fri, 1999/06/18 03:44]200 *****************************************************************************/201 202 BOOL WIN32API ReleaseMutex(HANDLE mutex)203 {204 return(HMReleaseMutex(mutex));205 }206 207 208 /*****************************************************************************209 * Name : BOOL SetEvent210 * Purpose : forward call to Open32211 * Parameters:212 * Variables :213 * Result :214 * Remark : handle translation is done in SetEvent215 * Status :216 *217 * Author : Patrick Haller [Fri, 1999/06/18 03:44]218 *****************************************************************************/219 220 BOOL WIN32API SetEvent(HANDLE hEvent)221 {222 return(HMSetEvent(hEvent));223 77 } 224 78 … … 274 128 } 275 129 276 277 /*****************************************************************************278 * Name : BOOL FlushFileBuffers279 * Purpose : forward call to Open32280 * Parameters:281 * Variables :282 * Result :283 * Remark : handle translation is done in FlushFileBuffers284 * Status :285 *286 * Author : Patrick Haller [Fri, 1999/06/18 03:44]287 *****************************************************************************/288 289 BOOL WIN32API FlushFileBuffers(HANDLE hFile)290 {291 return(HMFlushFileBuffers(hFile));292 }293 130 294 131 … … 351 188 352 189 353 /*****************************************************************************354 * Name : BOOL CreateSemaphoreA355 * Purpose : forward call to Open32356 * Parameters:357 * Variables :358 * Result :359 * Remark : handle translation is done in CreateSemaphoreA360 * Status :361 *362 * Author : Patrick Haller [Fri, 1999/06/18 03:44]363 *****************************************************************************/364 365 HANDLE WIN32API CreateSemaphoreA(LPSECURITY_ATTRIBUTES arg1,366 LONG arg2, LONG arg3, LPCSTR arg4)367 {368 return HMCreateSemaphore(arg1,369 arg2,370 arg3,371 (LPSTR)arg4);372 }373 374 190 375 191 /***************************************************************************** … … 396 212 astring = NULL; 397 213 398 dprintf(("KERNEL32: CreateSemaphoreW(%s)\n", 399 astring)); 400 401 rc = HMCreateSemaphore(arg1, 214 rc = CreateSemaphoreA(arg1, 402 215 arg2, 403 216 arg3, … … 409 222 } 410 223 411 /*****************************************************************************412 * Name : BOOL OpenEventA413 * Purpose : forward call to Open32414 * Parameters:415 * Variables :416 * Result :417 * Remark : handle translation is done in OpenEventA418 * Status :419 *420 * Author : Patrick Haller [Fri, 1999/06/18 03:44]421 *****************************************************************************/422 423 HANDLE WIN32API OpenEventA(DWORD arg1, BOOL arg2, LPCSTR arg3)424 {425 dprintf(("KERNEL32: OpenEventA(%s)\n",426 arg3));427 428 return HMOpenEvent(arg1,429 arg2,430 arg3);431 }432 433 224 434 225 /***************************************************************************** … … 452 243 asciiname = UnicodeToAsciiString((LPWSTR)lpName); 453 244 454 dprintf(("KERNEL32: OpenEventW(%s)\n", 455 asciiname)); 456 457 rc = HMOpenEvent(dwDesiredAccess, 245 rc = OpenEventA(dwDesiredAccess, 458 246 bInheritHandle, 459 247 asciiname); … … 464 252 465 253 /***************************************************************************** 466 * Name : BOOL OpenMutexA467 * Purpose : forward call to Open32468 * Parameters:469 * Variables :470 * Result :471 * Remark : handle translation is done in OpenMutexA472 * Status :473 *474 * Author : Patrick Haller [Fri, 1999/06/18 03:44]475 *****************************************************************************/476 477 HANDLE WIN32API OpenMutexA(DWORD arg1, BOOL arg2, LPCSTR arg3)478 {479 dprintf(("KERNEL32: OpenMutexA(%s)\n",480 arg3));481 482 return HMOpenMutex(arg1,483 arg2,484 arg3);485 }486 487 488 /*****************************************************************************489 254 * Name : BOOL OpenMutexW 490 255 * Purpose : forward call to Open32 … … 506 271 asciiname = UnicodeToAsciiString((LPWSTR)lpName); 507 272 508 dprintf(("KERNEL32: OpenMutexW(%s)\n", 509 asciiname)); 510 511 rc = HMOpenMutex(dwDesiredAccess, 273 rc = OpenMutexA(dwDesiredAccess, 512 274 bInheritHandle, 513 275 asciiname); … … 518 280 519 281 /***************************************************************************** 520 * Name : BOOL OpenSemaphoreA521 * Purpose : forward call to Open32522 * Parameters:523 * Variables :524 * Result :525 * Remark : handle translation is done in OpenSemaphoreA526 * Status :527 *528 * Author : Patrick Haller [Fri, 1999/06/18 03:44]529 *****************************************************************************/530 531 HANDLE WIN32API OpenSemaphoreA(DWORD arg1, BOOL arg2, LPCSTR arg3)532 {533 dprintf(("KERNEL32: OpenSemaphoreA(%s)\n",534 arg3));535 536 return HMOpenSemaphore(arg1,537 arg2,538 arg3);539 }540 541 542 /*****************************************************************************543 282 * Name : BOOL OpenSemaphoreW 544 283 * Purpose : forward call to Open32 … … 560 299 asciiname = UnicodeToAsciiString((LPWSTR)lpName); 561 300 562 dprintf(("KERNEL32: OpenSemaphoreW(%s)\n", 563 asciiname)); 564 565 rc = HMOpenSemaphore(dwDesiredAccess, 301 rc = OpenSemaphoreA(dwDesiredAccess, 566 302 bInheritHandle, 567 303 asciiname); … … 570 306 } 571 307 572 573 /*****************************************************************************574 * Name : BOOL PulseEvent575 * Purpose : forward call to Open32576 * Parameters:577 * Variables :578 * Result :579 * Remark : handle translation is done in PulseEvent580 * Status :581 *582 * Author : Patrick Haller [Fri, 1999/06/18 03:44]583 *****************************************************************************/584 585 BOOL WIN32API PulseEvent(HANDLE arg1)586 {587 return HMPulseEvent(arg1);588 }589 590 591 /*****************************************************************************592 * Name : BOOL ReleaseSemaphore593 * Purpose : forward call to Open32594 * Parameters:595 * Variables :596 * Result :597 * Remark : handle translation is done in ReleaseSemaphore598 * Status :599 *600 * Author : Patrick Haller [Fri, 1999/06/18 03:44]601 *****************************************************************************/602 603 BOOL WIN32API ReleaseSemaphore(HANDLE arg1, LONG arg2, PLONG arg3)604 {605 return HMReleaseSemaphore(arg1,606 arg2,607 arg3);608 }609 610 611 /*****************************************************************************612 * Name : BOOL ResetEvent613 * Purpose : forward call to Open32614 * Parameters:615 * Variables :616 * Result :617 * Remark : handle translation is done in ResetEvent618 * Status :619 *620 * Author : Patrick Haller [Fri, 1999/06/18 03:44]621 *****************************************************************************/622 623 BOOL WIN32API ResetEvent(HANDLE arg1)624 {625 return HMResetEvent(arg1);626 }627 308 628 309 … … 706 387 //****************************************************************************** 707 388 //****************************************************************************** 708 HANDLE WIN32API CreateThread(LPSECURITY_ATTRIBUTES lpsa,709 DWORD cbStack,710 LPTHREAD_START_ROUTINE lpStartAddr,711 LPVOID lpvThreadParm,712 DWORD fdwCreate,713 LPDWORD lpIDThread)714 {715 return HMCreateThread(lpsa, cbStack, lpStartAddr, lpvThreadParm, fdwCreate, lpIDThread);716 }717 //******************************************************************************718 //******************************************************************************719 INT WIN32API GetThreadPriority(HANDLE hThread)720 {721 return HMGetThreadPriority(hThread);722 }723 //******************************************************************************724 //******************************************************************************725 DWORD WIN32API SuspendThread(HANDLE hThread)726 {727 return HMSuspendThread(hThread);728 }729 //******************************************************************************730 //******************************************************************************731 BOOL WIN32API SetThreadPriority(HANDLE hThread, int priority)732 {733 return HMSetThreadPriority(hThread, priority);734 }735 //******************************************************************************736 //******************************************************************************737 BOOL WIN32API GetThreadContext(HANDLE hThread, PCONTEXT lpContext)738 {739 return HMGetThreadContext(hThread, lpContext);740 }741 //******************************************************************************742 //******************************************************************************743 BOOL WIN32API SetThreadContext(HANDLE hThread, const CONTEXT *lpContext)744 {745 return HMSetThreadContext(hThread, lpContext);746 }747 //******************************************************************************748 //******************************************************************************749 BOOL WIN32API GetThreadTimes(HANDLE hThread,750 LPFILETIME lpCreationTime,751 LPFILETIME lpExitTime,752 LPFILETIME lpKernelTime,753 LPFILETIME lpUserTime)754 {755 return HMGetThreadTimes(hThread, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime);756 }757 //******************************************************************************758 //******************************************************************************759 BOOL WIN32API TerminateThread(HANDLE hThread, DWORD exitcode)760 {761 return HMTerminateThread(hThread, exitcode);762 }763 //******************************************************************************764 //******************************************************************************765 DWORD WIN32API ResumeThread(HANDLE hThread)766 {767 return HMResumeThread(hThread);768 }769 //******************************************************************************770 //******************************************************************************771 BOOL WIN32API GetExitCodeThread(HANDLE hThread, LPDWORD arg2)772 {773 return HMGetExitCodeThread(hThread, arg2);774 }775 //******************************************************************************776 //****************************************************************************** -
trunk/src/kernel32/lang.cpp
r10422 r21302 60 60 } aLangToLangId[] = 61 61 { 62 { "ar_ae", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_UAE) }, 63 { "ar_BH", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_BAHRAIN) }, 64 { "ar_DZ", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_ALGERIA) }, 65 { "ar", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_EGYPT) }, 66 { "ar_EG", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_EGYPT) }, 67 { "ar_IQ", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_IRAQ ) }, 68 { "ar_JO", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_JORDAN ) }, 69 { "ar_KW", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_KUWAIT ) }, 70 { "ar_LB", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_LEBANON ) }, 71 { "ar_LY", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_LIBYA ) }, 72 { "ar_MA", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_MOROCCO ) }, 73 { "ar_OM", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_OMAN ) }, 74 { "ar_QA", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_QATAR ) }, 75 { "ar_SA", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_SAUDI_ARABIA) }, 76 { "ar_SY", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_SYRIA ) }, 77 { "ar_TN", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_TUNISIA ) }, 78 { "ar_YE", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_YEMEN ) }, 79 { "ar_SD", MAKELANGID(LANG_ARABIC, SUBLANG_DEFAULT) }, /* no win32 constant. */ 80 { "be", MAKELANGID(LANG_BELARUSIAN, SUBLANG_DEFAULT) }, 81 { "be_BY", MAKELANGID(LANG_BELARUSIAN, SUBLANG_DEFAULT) }, 82 { "bg_BG", MAKELANGID(LANG_BULGARIAN, SUBLANG_DEFAULT) }, 83 { "ca", MAKELANGID(LANG_CATALAN, SUBLANG_DEFAULT) }, 84 { "ca_ES", MAKELANGID(LANG_CATALAN, SUBLANG_DEFAULT) }, 85 { "cs", MAKELANGID(LANG_CZECH, SUBLANG_DEFAULT) }, 86 { "cs_CZ", MAKELANGID(LANG_CZECH, SUBLANG_DEFAULT) }, 87 { "da", MAKELANGID(LANG_DANISH, SUBLANG_DEFAULT) }, 88 { "da_DK", MAKELANGID(LANG_DANISH, SUBLANG_DEFAULT) }, 89 { "de_AT", MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN) }, 90 { "de_CH", MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS) }, 91 { "de_DE", MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN) }, 92 { "de_LU", MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_LUXEMBOURG) }, 93 { "el", MAKELANGID(LANG_GREEK, SUBLANG_DEFAULT) }, 94 { "el_GR", MAKELANGID(LANG_GREEK, SUBLANG_DEFAULT) }, 95 { "en_AU", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_AUS) }, 96 { "en_CA", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN) }, 97 { "en_GB", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK) }, 98 { "en_IE", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_EIRE) }, 99 { "en_NZ", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_NZ) }, 100 { "en_US", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) }, 101 { "en_ZA", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_SOUTH_AFRICA) }, 102 { "en_DK", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) }, /* odd ibm vac365 */ 103 { "en_JP", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) }, /* odd ibm vac365 */ 104 { "es_AR", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_ARGENTINA ) }, 105 { "es_BO", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_BOLIVIA ) }, 106 { "es_CL", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_CHILE ) }, 107 { "es_CO", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_COLOMBIA ) }, 108 { "es_CR", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_COSTA_RICA ) }, 109 { "es_DO", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_DOMINICAN_REPUBLIC) }, 110 { "es_EC", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_ECUADOR ) }, 111 { "es_ES", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH ) }, /* SUBLANG_SPANISH_MODERN? */ 112 { "es_GT", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_GUATEMALA ) }, 113 { "es_HN", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_HONDURAS ) }, 114 { "es_MX", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MEXICAN ) }, 115 { "es_NI", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_NICARAGUA ) }, 116 { "es_PA", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_PANAMA ) }, 117 { "es_PE", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_PERU ) }, 118 { "es_PR", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_PUERTO_RICO ) }, 119 { "es_PY", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_PARAGUAY ) }, 120 { "es_SV", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_EL_SALVADOR ) }, 121 { "es_UY", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_URUGUAY ) }, 122 { "es_VE", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_VENEZUELA ) }, 123 { "et", MAKELANGID(LANG_ESTONIAN, SUBLANG_DEFAULT) }, 124 { "et_EE", MAKELANGID(LANG_ESTONIAN, SUBLANG_DEFAULT) }, 125 { "fi_FI", MAKELANGID(LANG_FINNISH, SUBLANG_DEFAULT) }, 126 { "fo", MAKELANGID(LANG_FAEROESE, SUBLANG_DEFAULT) }, 127 { "fo_FO", MAKELANGID(LANG_FAEROESE, SUBLANG_DEFAULT) }, 128 { "fr_BE", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_BELGIAN) }, 129 { "fr_CA", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_CANADIAN) }, 130 { "fr_CH", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_SWISS) }, 131 { "fr_FR", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH) }, 132 { "fr_LU", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_LUXEMBOURG) }, 133 { "hr_HR", MAKELANGID(LANG_CROATIAN, SUBLANG_DEFAULT) }, 134 { "hu_HU", MAKELANGID(LANG_HUNGARIAN, SUBLANG_DEFAULT) }, 135 { "is_IS", MAKELANGID(LANG_ICELANDIC, SUBLANG_DEFAULT) }, 136 { "it_CH", MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN_SWISS) }, 137 { "it_IT", MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN) }, 138 { "iw", MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT) }, 139 { "iw_IL", MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT) }, 140 { "ja_JP", MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT) }, 141 { "ko", MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT) }, 142 { "ko_KR", MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT) }, 143 { "lt_LT", MAKELANGID(LANG_LITHUANIAN, SUBLANG_DEFAULT) }, 144 { "lv_LV", MAKELANGID(LANG_LATVIAN, SUBLANG_DEFAULT) }, 145 /*{ "mk_MK", MAKELANGID(LANG_MACEDONIAN, SUBLANG_DEFAULT) }, - no win32 eq */ 146 { "nl_BE", MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH_BELGIAN) }, 147 { "nl_NL", MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH) }, 148 { "no_NO", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK) }, /* yeah sure! Sun is medling in norwegian politics here... */ 149 { "no_NO_B", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL) }, /* yeah sure! Sun is medling in norwegian politics here... */ 150 { "ny", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK) }, 151 { "ny_NO", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK) }, 152 { "nb", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL) }, 153 { "nb_NO", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL) }, 154 { "pl_PL", MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT) }, 155 { "pt_BR", MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN) }, 156 { "pt_PT", MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE) }, 157 { "ro_RO", MAKELANGID(LANG_ROMANIAN, SUBLANG_DEFAULT) }, 158 { "ru_RU", MAKELANGID(LANG_RUSSIAN, SUBLANG_DEFAULT) }, 159 { "sh", MAKELANGID(LANG_SERBIAN, SUBLANG_SERBIAN_CYRILLIC) }, 160 { "sh_YU", MAKELANGID(LANG_SERBIAN, SUBLANG_SERBIAN_CYRILLIC) }, 161 { "sk_SK", MAKELANGID(LANG_SLOVAK, SUBLANG_DEFAULT) }, 162 { "sl_SL", MAKELANGID(LANG_SLOVENIAN, SUBLANG_DEFAULT) }, 163 { "sq", MAKELANGID(LANG_ALBANIAN, SUBLANG_DEFAULT) }, 164 { "sq_AL", MAKELANGID(LANG_ALBANIAN, SUBLANG_DEFAULT) }, 165 { "sr", MAKELANGID(LANG_SERBIAN, SUBLANG_DEFAULT) }, 166 { "sr_YU", MAKELANGID(LANG_SERBIAN, SUBLANG_DEFAULT) }, 167 { "sv", MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH) }, 168 { "sv_FI", MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH_FINLAND) }, 169 { "sv_SE", MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH) }, 170 { "th_TH", MAKELANGID(LANG_THAI, SUBLANG_DEFAULT) }, 171 { "tr_TR", MAKELANGID(LANG_TURKISH, SUBLANG_DEFAULT) }, 172 { "tr_DE", MAKELANGID(LANG_TURKISH, SUBLANG_DEFAULT) }, /* phun ;-) */ 173 { "uk", MAKELANGID(LANG_UKRAINIAN, SUBLANG_DEFAULT) }, 174 { "uk_UA", MAKELANGID(LANG_UKRAINIAN, SUBLANG_DEFAULT) }, 175 { "zh", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) }, 176 { "zh_CN", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) }, 177 { "zh_TW", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL) }, 178 { "zh_HK", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_HONGKONG) }, 179 /*{ "zh_??", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE) },*/ 62 /* most frequent */ 63 { "EN_US", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) }, 64 { "DE_DE", MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN) }, 65 /* now sorted */ 66 { "AR_AE", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_UAE) }, 67 { "AR_BH", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_BAHRAIN) }, 68 { "AR_DZ", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_ALGERIA) }, 69 { "AR", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_EGYPT) }, 70 { "AR_EG", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_EGYPT) }, 71 { "AR_IQ", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_IRAQ ) }, 72 { "AR_JO", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_JORDAN ) }, 73 { "AR_KW", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_KUWAIT ) }, 74 { "AR_LB", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_LEBANON ) }, 75 { "AR_LY", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_LIBYA ) }, 76 { "AR_MA", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_MOROCCO ) }, 77 { "AR_OM", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_OMAN ) }, 78 { "AR_QA", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_QATAR ) }, 79 { "AR_SA", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_SAUDI_ARABIA) }, 80 { "AR_SY", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_SYRIA ) }, 81 { "AR_TN", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_TUNISIA ) }, 82 { "AR_YE", MAKELANGID(LANG_ARABIC, SUBLANG_ARABIC_YEMEN ) }, 83 { "AR_SD", MAKELANGID(LANG_ARABIC, SUBLANG_DEFAULT) }, /* no win32 constant. */ 84 { "BE", MAKELANGID(LANG_BELARUSIAN, SUBLANG_DEFAULT) }, 85 { "BE_BY", MAKELANGID(LANG_BELARUSIAN, SUBLANG_DEFAULT) }, 86 { "BG_BG", MAKELANGID(LANG_BULGARIAN, SUBLANG_DEFAULT) }, 87 { "CA", MAKELANGID(LANG_CATALAN, SUBLANG_DEFAULT) }, 88 { "CA_ES", MAKELANGID(LANG_CATALAN, SUBLANG_DEFAULT) }, 89 { "CS", MAKELANGID(LANG_CZECH, SUBLANG_DEFAULT) }, 90 { "CS_CZ", MAKELANGID(LANG_CZECH, SUBLANG_DEFAULT) }, 91 { "DA", MAKELANGID(LANG_DANISH, SUBLANG_DEFAULT) }, 92 { "DA_DK", MAKELANGID(LANG_DANISH, SUBLANG_DEFAULT) }, 93 { "DE_AT", MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN) }, 94 { "DE_CH", MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS) }, 95 { "DE_LU", MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_LUXEMBOURG) }, 96 { "EL", MAKELANGID(LANG_GREEK, SUBLANG_DEFAULT) }, 97 { "EL_GR", MAKELANGID(LANG_GREEK, SUBLANG_DEFAULT) }, 98 { "EN_AU", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_AUS) }, 99 { "EN_CA", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN) }, 100 { "EN_GB", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK) }, 101 { "EN_IE", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_EIRE) }, 102 { "EN_NZ", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_NZ) }, 103 { "EN_ZA", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_SOUTH_AFRICA) }, 104 { "EN_DK", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) }, /* odd ibm vac365 */ 105 { "EN_JP", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) }, /* odd ibm vac365 */ 106 { "ES_AR", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_ARGENTINA ) }, 107 { "ES_BO", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_BOLIVIA ) }, 108 { "ES_CL", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_CHILE ) }, 109 { "ES_CO", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_COLOMBIA ) }, 110 { "ES_CR", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_COSTA_RICA ) }, 111 { "ES_DO", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_DOMINICAN_REPUBLIC) }, 112 { "ES_EC", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_ECUADOR ) }, 113 { "ES_ES", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH ) }, /* SUBLANG_SPANISH_MODERN? */ 114 { "ES_GT", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_GUATEMALA ) }, 115 { "ES_HN", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_HONDURAS ) }, 116 { "ES_MX", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MEXICAN ) }, 117 { "ES_NI", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_NICARAGUA ) }, 118 { "ES_PA", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_PANAMA ) }, 119 { "ES_PE", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_PERU ) }, 120 { "ES_PR", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_PUERTO_RICO ) }, 121 { "ES_PY", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_PARAGUAY ) }, 122 { "ES_SV", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_EL_SALVADOR ) }, 123 { "ES_UY", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_URUGUAY ) }, 124 { "ES_VE", MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_VENEZUELA ) }, 125 { "ET", MAKELANGID(LANG_ESTONIAN, SUBLANG_DEFAULT) }, 126 { "ET_EE", MAKELANGID(LANG_ESTONIAN, SUBLANG_DEFAULT) }, 127 { "FI_FI", MAKELANGID(LANG_FINNISH, SUBLANG_DEFAULT) }, 128 { "FO", MAKELANGID(LANG_FAEROESE, SUBLANG_DEFAULT) }, 129 { "FO_FO", MAKELANGID(LANG_FAEROESE, SUBLANG_DEFAULT) }, 130 { "FR_BE", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_BELGIAN) }, 131 { "FR_CA", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_CANADIAN) }, 132 { "FR_CH", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_SWISS) }, 133 { "FR_FR", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH) }, 134 { "FR_LU", MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_LUXEMBOURG) }, 135 { "HR_HR", MAKELANGID(LANG_CROATIAN, SUBLANG_DEFAULT) }, 136 { "HU_HU", MAKELANGID(LANG_HUNGARIAN, SUBLANG_DEFAULT) }, 137 { "IS_IS", MAKELANGID(LANG_ICELANDIC, SUBLANG_DEFAULT) }, 138 { "IT_CH", MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN_SWISS) }, 139 { "IT_IT", MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN) }, 140 { "IW", MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT) }, 141 { "IW_IL", MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT) }, 142 { "JA_JP", MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT) }, 143 { "KO", MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT) }, 144 { "KO_KR", MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT) }, 145 { "LT_LT", MAKELANGID(LANG_LITHUANIAN, SUBLANG_DEFAULT) }, 146 { "LV_LV", MAKELANGID(LANG_LATVIAN, SUBLANG_DEFAULT) }, 147 /*{ "MK_MK", MAKELANGID(LANG_MACEDONIAN, SUBLANG_DEFAULT) }, - no win32 eq */ 148 { "NL_BE", MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH_BELGIAN) }, 149 { "NL_NL", MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH) }, 150 { "NO_NO", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK) }, /* yeah sure! Sun is medling in norwegian politics here... */ 151 { "NO_NO_B", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL) }, /* yeah sure! Sun is medling in norwegian politics here... */ 152 { "NY", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK) }, 153 { "NY_NO", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK) }, 154 { "NB", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL) }, 155 { "NB_NO", MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL) }, 156 { "PL_PL", MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT) }, 157 { "PT_BR", MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN) }, 158 { "PT_PT", MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE) }, 159 { "RO_RO", MAKELANGID(LANG_ROMANIAN, SUBLANG_DEFAULT) }, 160 { "RU_RU", MAKELANGID(LANG_RUSSIAN, SUBLANG_DEFAULT) }, 161 { "SH", MAKELANGID(LANG_SERBIAN, SUBLANG_SERBIAN_CYRILLIC) }, 162 { "SH_YU", MAKELANGID(LANG_SERBIAN, SUBLANG_SERBIAN_CYRILLIC) }, 163 { "SK_SK", MAKELANGID(LANG_SLOVAK, SUBLANG_DEFAULT) }, 164 { "SL_SL", MAKELANGID(LANG_SLOVENIAN, SUBLANG_DEFAULT) }, 165 { "SQ", MAKELANGID(LANG_ALBANIAN, SUBLANG_DEFAULT) }, 166 { "SQ_AL", MAKELANGID(LANG_ALBANIAN, SUBLANG_DEFAULT) }, 167 { "SR", MAKELANGID(LANG_SERBIAN, SUBLANG_DEFAULT) }, 168 { "SR_YU", MAKELANGID(LANG_SERBIAN, SUBLANG_DEFAULT) }, 169 { "SV", MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH) }, 170 { "SV_FI", MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH_FINLAND) }, 171 { "SV_SE", MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH) }, 172 { "TH_TH", MAKELANGID(LANG_THAI, SUBLANG_DEFAULT) }, 173 { "TR_TR", MAKELANGID(LANG_TURKISH, SUBLANG_DEFAULT) }, 174 { "TR_DE", MAKELANGID(LANG_TURKISH, SUBLANG_DEFAULT) }, /* phun ;-) */ 175 { "UK", MAKELANGID(LANG_UKRAINIAN, SUBLANG_DEFAULT) }, 176 { "UK_UA", MAKELANGID(LANG_UKRAINIAN, SUBLANG_DEFAULT) }, 177 { "ZH", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) }, 178 { "ZH_CN", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) }, 179 { "ZH_TW", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL) }, 180 { "ZH_HK", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_HONGKONG) }, 181 /*{ "ZH_??", MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE) },*/ 180 182 }; 181 183 … … 199 201 int i; 200 202 for (i = 0; i < sizeof(aLangToLangId) / sizeof(aLangToLangId[0]); i++) 201 if (!str icmp(aLangToLangId[i].pszLang, szLang))203 if (!strcmp(aLangToLangId[i].pszLang, szLang)) 202 204 return aLangToLangId[i].ulLangId; 203 205 … … 208 210 szLang[2] = '\0'; 209 211 for (i = 0; i < sizeof(aLangToLangId) / sizeof(aLangToLangId[0]); i++) 210 if (!str icmp(aLangToLangId[i].pszLang, szLang))212 if (!strcmp(aLangToLangId[i].pszLang, szLang)) 211 213 return aLangToLangId[i].ulLangId; 212 214 … … 216 218 szLang[5] = '\0'; 217 219 for (i = 0; i < sizeof(aLangToLangId) / sizeof(aLangToLangId[0]); i++) 218 if (!str icmp(aLangToLangId[i].pszLang, szLang))220 if (!strcmp(aLangToLangId[i].pszLang, szLang)) 219 221 return aLangToLangId[i].ulLangId; 220 222 … … 223 225 */ 224 226 for (i = 0; i < sizeof(aLangToLangId) / sizeof(aLangToLangId[0]); i++) 225 if (!strn icmp(aLangToLangId[i].pszLang, szLang, 2))227 if (!strncmp(aLangToLangId[i].pszLang, szLang, 2)) 226 228 return MAKELANGID(PRIMARYLANGID(aLangToLangId[i].ulLangId), SUBLANG_NEUTRAL); 227 229 -
trunk/src/kernel32/lfile.cpp
r10083 r21302 255 255 *****************************************************************************/ 256 256 257 UINT WIN32API _lwrite(HFILE arg1,258 LPCSTR arg2,259 UINT arg3)257 UINT WIN32API _lwrite(HFILE hFile, 258 LPCSTR lpBuffer, 259 UINT cbWrite) 260 260 { 261 261 ULONG rc; 262 263 dprintf(("KERNEL32: _lwrite(%08xh, %08xh, %08xh)\n", 264 arg1,265 arg2,266 arg3));267 268 if (!WriteFile(arg1,269 (PVOID)arg2,270 arg3,262 dprintf(("KERNEL32: _lwrite(%08xh, %08xh, %08xh)\n", hFile, lpBuffer, cbWrite)); 263 264 if (!cbWrite) 265 rc = SetEndOfFile(hFile) ? 0 : HFILE_ERROR; 266 else 267 { 268 if (!WriteFile(hFile, 269 (PVOID)lpBuffer, 270 cbWrite, 271 271 &rc, 272 272 NULL)) 273 rc = -1; 274 275 dprintf(("KERNEL32: _lwrite returns %08xh.\n", 276 rc)); 277 273 rc = HFILE_ERROR; 274 } 275 276 dprintf(("KERNEL32: _lwrite returns %08xh.\n", rc)); 278 277 return rc; 279 278 } -
trunk/src/kernel32/mailslot.cpp
r7849 r21302 14 14 #include <os2win.h> 15 15 #include <string.h> 16 #include "HandleManager.h"16 #include <HandleManager.h> 17 17 #include <unicode.h> 18 19 #include "hmhandle.h" 20 #include "hmmailslot.h" 18 21 19 22 #define DBG_LOCALLOG DBG_mailslot … … 47 50 LPSECURITY_ATTRIBUTES lpSecurityAttributes) 48 51 { 49 return HMCreateMailslotA(lpName, nMaxMessageSize, lReadTimeout, lpSecurityAttributes); 52 PHMHANDLE pHandle; 53 BOOL rc; /* API return code */ 54 HMMailslotClass *pDeviceHandler; 55 56 SetLastError(ERROR_SUCCESS); 57 58 pHandle = HMHandleGetFreePtr(HMTYPE_MAILSLOT); /* get free handle */ 59 if (pHandle == NULL) /* oops, no free handles ! */ 60 { 61 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 62 return INVALID_HANDLE_VALUE; 63 } 64 65 /* call the device handler */ 66 pDeviceHandler = (HMMailslotClass *)pHandle->pDeviceHandler; 67 rc = pDeviceHandler->CreateMailslotA(&pHandle->hmHandleData, 68 lpName, nMaxMessageSize, 69 lReadTimeout, lpSecurityAttributes); 70 71 if (rc == FALSE) /* oops, creation failed within the device handler */ 72 { 73 HMHandleFree(pHandle->hmHandleData.hWin32Handle); 74 return INVALID_HANDLE_VALUE; /* signal error */ 75 } 76 77 return pHandle->hmHandleData.hWin32Handle; 50 78 } 79 /***************************************************************************** 80 * Name : BOOL GetMailslotInfo 81 * Purpose : The GetMailslotInfo function retrieves information about the 82 * specified mailslot. 83 * Parameters: HANDLE hMailslot mailslot handle 84 * LPDWORD lpMaxMessageSize address of maximum message size 85 * LPDWORD lpNextSize address of size of next message 86 * LPDWORD lpMessageCount address of number of messages 87 * LPDWORD lpReadTimeout address of read time-out 88 * Variables : 89 * Result : TRUE / FALSE 90 * Remark : 91 * Status : 92 * 93 * Author : SvL 94 *****************************************************************************/ 51 95 96 BOOL WIN32API GetMailslotInfo(HANDLE hMailslot, 97 LPDWORD lpMaxMessageSize, 98 LPDWORD lpNextSize, 99 LPDWORD lpMessageCount, 100 LPDWORD lpReadTimeout) 101 { 102 BOOL lpResult; /* result from the device handler's API */ 103 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 104 105 SetLastError(ERROR_SUCCESS); 106 /* validate handle */ 107 pHMHandle = HMHandleQueryPtr(hMailslot); /* get the index */ 108 if (pHMHandle == NULL) /* error ? */ 109 { 110 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 111 } 112 113 lpResult = pHMHandle->pDeviceHandler->GetMailslotInfo(&pHMHandle->hmHandleData, 114 lpMaxMessageSize, 115 lpNextSize, 116 lpMessageCount, 117 lpReadTimeout); 118 return (lpResult); /* deliver return code */ 119 } 120 /***************************************************************************** 121 * Name : BOOL SetMailslotInfo 122 * Purpose : The SetMailslotInfo function sets the time-out value used by the 123 * specified mailslot for a read operation. 124 * Parameters: HANDLE hObject handle to a mailslot object 125 * DWORD dwReadTimeout read time-out 126 * Variables : 127 * Result : TRUE / FALSE 128 * Remark : 129 * Status : 130 * 131 * Author : SvL 132 *****************************************************************************/ 133 BOOL SetMailslotInfo(HANDLE hMailslot, 134 DWORD dwReadTimeout) 135 { 136 BOOL fResult; 137 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 138 139 SetLastError(ERROR_SUCCESS); 140 /* validate handle */ 141 pHMHandle = HMHandleQueryPtr(hMailslot); /* get the index */ 142 if (pHMHandle == NULL) /* error ? */ 143 { 144 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 145 } 146 147 fResult = pHMHandle->pDeviceHandler->SetMailslotInfo(&pHMHandle->hmHandleData, 148 dwReadTimeout); 149 150 return fResult; /* deliver return code */ 151 } 52 152 /***************************************************************************** 53 153 * Name : HANDLE WIN32API CreateMailslotW … … 80 180 81 181 astring = UnicodeToAsciiString((LPWSTR)lpName); 82 rc = HMCreateMailslotA(astring, nMaxMessageSize, lReadTimeout, lpSecurityAttributes);182 rc = CreateMailslotA(astring, nMaxMessageSize, lReadTimeout, lpSecurityAttributes); 83 183 FreeAsciiString(astring); 84 184 return(rc); 85 185 } 86 186 87 /*****************************************************************************88 * Name : BOOL GetMailslotInfo89 * Purpose : The GetMailslotInfo function retrieves information about the90 * specified mailslot.91 * Parameters: HANDLE hMailslot mailslot handle92 * LPDWORD lpMaxMessageSize address of maximum message size93 * LPDWORD lpNextSize address of size of next message94 * LPDWORD lpMessageCount address of number of messages95 * LPDWORD lpReadTimeout address of read time-out96 * Variables :97 * Result : TRUE / FALSE98 * Remark :99 * Status :100 *101 * Author : SvL102 *****************************************************************************/103 187 104 BOOL WIN32API GetMailslotInfo(HANDLE hMailslot,105 LPDWORD lpMaxMessageSize,106 LPDWORD lpNextSize,107 LPDWORD lpMessageCount,108 LPDWORD lpReadTimeout)109 {110 return HMGetMailslotInfo(hMailslot, lpMaxMessageSize, lpNextSize,111 lpMessageCount, lpReadTimeout);112 }113 114 /*****************************************************************************115 * Name : BOOL SetMailslotInfo116 * Purpose : The SetMailslotInfo function sets the time-out value used by the117 * specified mailslot for a read operation.118 * Parameters: HANDLE hObject handle to a mailslot object119 * DWORD dwReadTimeout read time-out120 * Variables :121 * Result : TRUE / FALSE122 * Remark :123 * Status :124 *125 * Author : SvL126 *****************************************************************************/127 128 BOOL WIN32API SetMailslotInfo(HANDLE hMailslot, DWORD dwReadTimeout)129 {130 return HMSetMailslotInfo(hMailslot, dwReadTimeout);131 } -
trunk/src/kernel32/mmapview.cpp
r10369 r21302 106 106 if(mfAccess & MEMMAP_ACCESS_COPYONWRITE) 107 107 { 108 //A copy on write view is a private copy of the memory map 109 //The pages reflect the state of the original map until they are 110 //modified. 111 //We use guard pages to track access to the COW view. 112 pMapView = VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE|PAGE_GUARD); 113 if(pMapView == NULL) { 114 dprintf(("VirtualAlloc FAILED")); 108 115 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 109 116 errorState = 1; 110 117 return; 118 } 111 119 } 112 120 else … … 118 126 } 119 127 } 128 //Allocate bitmap for all pages of a COW view to track which pages are 129 //shared and which are private (copy on write -> private page) 130 if(fdwAccess == FILE_MAP_COPY) 131 { 132 DWORD nrPages = mSize >> PAGE_SHIFT; 133 if(mSize & 0xFFF) 134 nrPages++; 135 136 int sizebitmap = nrPages/8 + 1; 137 138 pCOWBitmap = (char *)malloc(sizebitmap); 139 if(pCOWBitmap) { 140 memset(pCOWBitmap, 0, sizebitmap); 141 } 142 else DebugInt3(); 143 } 120 144 121 145 dprintf(("Win32MemMapView::Win32MemMapView: created %x (alias for %x), size %d", pMapView, viewaddr, size)); … … 245 269 // PAGEVIEW_READONLY -> set page flags to readonly 246 270 // PAGEVIEW_VIEW -> set page flags to view default 271 // PAGEVIEW_GUARD -> set page flags of COW view to GUARD 247 272 // 248 273 // Returns: … … 264 289 ( (flags == PAGEVIEW_GUARD) && !(mfAccess & MEMMAP_ACCESS_COPYONWRITE) ) ) 265 290 { 291 //PAGEVIEW_GUARD only applies to COW views 266 292 //PAGEVIEW_VIEW/READONLY does not apply to COW views 267 293 return TRUE; … … 289 315 accessAttr |= PAG_WRITE; 290 316 } 291 } 292 317 if(flags == PAGEVIEW_GUARD) { 318 accessAttr |= PAG_GUARD; 319 } 320 } 321 322 if(flags == PAGEVIEW_GUARD || (mfAccess & MEMMAP_ACCESS_COPYONWRITE)) 293 323 { 324 DWORD startpage = (offset - mOffset) >> PAGE_SHIFT; 325 DWORD nrPages = size >> PAGE_SHIFT; 326 if(size & 0xFFF) 327 nrPages++; 328 329 //COW views need special treatment. If we are told to change any flags 330 //of the COW pages, then only the shared pages must be changed. 331 //So check each page if it is still shared. 332 for(int i=startpage;i<startpage+nrPages;i++) 333 { 334 if(!isCOWPage(i)) 335 {//page is still shared, so set the guard flag 336 rc = OSLibDosSetMem((char *)pMapView+(offset - mOffset), PAGE_SIZE, accessAttr); 337 if(rc) { 338 dprintf(("Win32MemMapView::changePageFlags: OSLibDosSetMem %x %x %x failed with %d", (char *)pMapView+(offset - mOffset), size, accessAttr, rc)); 339 return FALSE; 340 } 341 } 342 offset += PAGE_SIZE; 343 } 344 } 345 else { 294 346 rc = OSLibDosSetMem((char *)pMapView+(offset - mOffset), size, accessAttr); 295 347 if(rc) { -
trunk/src/kernel32/npipe.cpp
r10132 r21302 19 19 #include "oslibdos.h" 20 20 21 #include "hmhandle.h" 22 #include "hmnpipe.h" 21 23 22 24 #define DBG_LOCALLOG DBG_npipe … … 25 27 ODINDEBUGCHANNEL(KERNEL32-NPIPE) 26 28 27 //******************************************************************************28 //******************************************************************************29 BOOL WIN32API PeekNamedPipe(HANDLE hPipe, LPVOID lpvBuffer,30 DWORD cbBuffer, LPDWORD lpcbRead,31 LPDWORD lpcbAvail, LPDWORD lpcbMessage)32 {33 return (HMPeekNamedPipe(hPipe,lpvBuffer,cbBuffer,lpcbRead,lpcbAvail,lpcbMessage));34 }35 29 //****************************************************************************** 36 30 //****************************************************************************** … … 45 39 { 46 40 sprintf(szPipeName, "\\\\.\\pipe\\Win32.Pipes.%08x.%08x", GetCurrentProcessId(), GetCurrentTime()); 47 hPipeRead = ::CreateNamedPipeA(szPipeName, PIPE_ACCESS_ DUPLEX,41 hPipeRead = ::CreateNamedPipeA(szPipeName, PIPE_ACCESS_INBOUND, 48 42 PIPE_TYPE_BYTE | PIPE_WAIT, 1, cbPipe, cbPipe, 49 43 NMPWAIT_USE_DEFAULT_WAIT, lpsa); … … 84 78 return TRUE; 85 79 } 86 //****************************************************************************** 87 //****************************************************************************** 88 HANDLE WIN32API CreateNamedPipeA(LPCTSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, 89 DWORD nMaxInstances, DWORD nOutBufferSize, 90 DWORD nInBufferSize, DWORD nDefaultTimeOut, 80 81 /***************************************************************************** 82 * Name : CreateNamedPipe 83 * Purpose : 84 * Parameters: 85 * Variables : 86 * Result : 87 * Remark : 88 * Status : 89 * 90 * Author : Przemyslaw Dobrowolski 91 *****************************************************************************/ 92 HANDLE WIN32API CreateNamedPipeA(LPCTSTR lpName, 93 DWORD dwOpenMode, 94 DWORD dwPipeMode, 95 DWORD nMaxInstances, 96 DWORD nOutBufferSize, 97 DWORD nInBufferSize, 98 DWORD nDefaultTimeOut, 91 99 LPSECURITY_ATTRIBUTES lpSecurityAttributes) 92 93 { 94 return (HMCreateNamedPipe(lpName, 95 dwOpenMode, 96 dwPipeMode, 97 nMaxInstances, 98 nOutBufferSize, 99 nInBufferSize, 100 nDefaultTimeOut, 101 lpSecurityAttributes)); 102 103 } 100 { 101 PHMHANDLE pHandle; 102 HANDLE rc; /* API return code */ 103 104 SetLastError(ERROR_SUCCESS); 105 106 pHandle = HMHandleGetFreePtr(HMTYPE_PIPE); /* get free handle */ 107 if (pHandle == NULL) /* oops, no free handles ! */ 108 { 109 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 110 return INVALID_HANDLE_VALUE; 111 } 112 113 /* call the device handler */ 114 rc = pHandle->pDeviceHandler->CreateNamedPipe(&pHandle->hmHandleData, 115 lpName,dwOpenMode, 116 dwPipeMode,nMaxInstances, 117 nOutBufferSize,nInBufferSize, 118 nDefaultTimeOut,lpSecurityAttributes); 119 120 if (rc == INVALID_HANDLE_VALUE) 121 { 122 HMHandleFree(pHandle->hmHandleData.hWin32Handle); 123 return INVALID_HANDLE_VALUE; /* signal error */ 124 } 125 126 dprintf(("Named pipe %x", pHandle->hmHandleData.hWin32Handle)); 127 if(lpSecurityAttributes && lpSecurityAttributes->bInheritHandle) { 128 dprintf(("Set inheritance for child processes")); 129 HMSetHandleInformation(pHandle->hmHandleData.hWin32Handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); 130 } 131 132 return pHandle->hmHandleData.hWin32Handle; 133 } 134 /***************************************************************************** 135 * Name : BOOL WIN32API ConnectNamedPipe 136 * Purpose : The ConnectNamedPipe function enables a named pipe server process 137 * to wait for a client process to connect to an instance of a 138 * named pipe. A client process connects by calling either the 139 * CreateFile or CallNamedPipe function. 140 * Parameters: HANDLE hNamedPipe handle to named pipe to connect 141 * LPOVERLAPPED lpOverlapped pointer to overlapped structure 142 * Variables : 143 * Result : If the function succeeds, the return value is nonzero. 144 * If the function fails, the return value is zero. 145 * To get extended error information, call GetLastError. 146 * Remark : 147 * Status : NOT FULLY TESTED 148 * 149 * Author : Przemyslaw Dobrowolski [Sun, 2000/01/02 12:48] 150 *****************************************************************************/ 151 152 BOOL WIN32API ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED lpOverlapped) 153 { 154 BOOL lpResult; /* result from the device handler's API */ 155 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 156 157 SetLastError(ERROR_SUCCESS); 158 /* validate handle */ 159 pHMHandle = HMHandleQueryPtr(hPipe); /* get the index */ 160 if (pHMHandle == NULL) /* error ? */ 161 { 162 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 163 } 164 165 lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&pHMHandle->hmHandleData, 166 lpOverlapped); 167 168 return (lpResult); /* deliver return code */ 169 } 170 171 /***************************************************************************** 172 * Name : BOOL WIN32API DisconnectNamedPipe 173 * Purpose : The DisconnectNamedPipe function disconnects the server end 174 * of a named pipe instance from a client process. 175 * Parameters: HANDLE hNamedPipe handle to named pipe 176 * Variables : 177 * Result : If the function succeeds, the return value is nonzero. 178 * If the function fails, the return value is zero 179 * Remark : 180 * Status : NOT FULLY TESTED 181 * 182 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 13:34] 183 *****************************************************************************/ 184 185 BOOL WIN32API DisconnectNamedPipe(HANDLE hPipe) 186 { 187 BOOL lpResult; /* result from the device handler's API */ 188 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 189 190 SetLastError(ERROR_SUCCESS); 191 /* validate handle */ 192 pHMHandle = HMHandleQueryPtr(hPipe); /* get the index */ 193 if (pHMHandle == NULL) /* error ? */ 194 { 195 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 196 } 197 198 lpResult = pHMHandle->pDeviceHandler->DisconnectNamedPipe(&pHMHandle->hmHandleData); 199 200 return (lpResult); /* deliver return code */ 201 } 202 203 /***************************************************************************** 204 * Name : PeekNamedPipe 205 * Purpose : 206 * Parameters: 207 * Variables : 208 * Result : 209 * Remark : 210 * Status : 211 * 212 * Author : Przemyslaw Dobrowolski 213 *****************************************************************************/ 214 BOOL WIN32API PeekNamedPipe(HANDLE hPipe, 215 LPVOID lpvBuffer, 216 DWORD cbBuffer, 217 LPDWORD lpcbRead, 218 LPDWORD lpcbAvail, 219 LPDWORD lpcbMessage) 220 { 221 BOOL lpResult; /* result from the device handler's API */ 222 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 223 224 SetLastError(ERROR_SUCCESS); 225 /* validate handle */ 226 pHMHandle = HMHandleQueryPtr(hPipe); /* get the index */ 227 if (pHMHandle == NULL) /* error ? */ 228 { 229 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 230 } 231 232 lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&pHMHandle->hmHandleData, 233 lpvBuffer, 234 cbBuffer, 235 lpcbRead, 236 lpcbAvail, 237 lpcbMessage); 238 239 return (lpResult); /* deliver return code */ 240 } 241 242 /***************************************************************************** 243 * Name : BOOL GetNamedPipeHandleStateA 244 * Purpose : The GetNamedPipeHandleStateA function retrieves information about 245 * a specified named pipe. The information returned can vary during 246 * the lifetime of an instance of the named pipe. 247 * Parameters: HANDLE hNamedPipe handle of named pipe 248 * LPDWORD lpState address of flags indicating pipe state 249 * LPDWORD lpCurInstances address of number of current pipe instances 250 * LPDWORD lpMaxCollectionCount address of max. bytes before remote transmission 251 * LPDWORD lpCollectDataTimeout address of max. time before remote transmission 252 * LPTSTR lpUserName address of user name of client process 253 * DWORD nMaxUserNameSize size, in characters, of user name buffer 254 * Variables : 255 * Result : TRUE / FALSE 256 * Remark : 257 * Status : UNTESTED STUB 258 * 259 * Author : Patrick Haller [Mon, 1998/06/15 08:00] 260 *****************************************************************************/ 261 262 BOOL WIN32API GetNamedPipeHandleStateA(HANDLE hPipe, 263 LPDWORD lpState, 264 LPDWORD lpCurInstances, 265 LPDWORD lpMaxCollectionCount, 266 LPDWORD lpCollectDataTimeout, 267 LPTSTR lpUserName, 268 DWORD nMaxUserNameSize) 269 { 270 BOOL lpResult; /* result from the device handler's API */ 271 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 272 273 SetLastError(ERROR_SUCCESS); 274 /* validate handle */ 275 pHMHandle = HMHandleQueryPtr(hPipe); /* get the index */ 276 if (pHMHandle == NULL) /* error ? */ 277 { 278 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 279 } 280 281 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeHandleState(&pHMHandle->hmHandleData, 282 lpState, 283 lpCurInstances, 284 lpMaxCollectionCount, 285 lpCollectDataTimeout, 286 lpUserName, 287 nMaxUserNameSize); 288 289 290 return (lpResult); /* deliver return code */ 291 } 292 293 /***************************************************************************** 294 * Name : BOOL GetNamedPipeInfo 295 * Purpose : The GetNamedPipeInfo function retrieves information about the specified named pipe. 296 * Parameters: HANDLE hNamedPipe handle of named pipe 297 * LPDWORD lpFlags address of flags indicating type of pipe 298 * LPDWORD lpOutBufferSize address of size, in bytes, of pipe's output buffer 299 * LPDWORD lpInBufferSize address of size, in bytes, of pipe's input buffer 300 * LPDWORD lpMaxInstances address of max. number of pipe instances 301 * Variables : 302 * Result : TRUE / FALSE 303 * Remark : 304 * Status : 305 * 306 * Author : Przemyslaw Dobrowolski 307 *****************************************************************************/ 308 309 BOOL WIN32API GetNamedPipeInfo(HANDLE hPipe, 310 LPDWORD lpFlags, 311 LPDWORD lpOutBufferSize, 312 LPDWORD lpInBufferSize, 313 LPDWORD lpMaxInstances) 314 { 315 BOOL lpResult; /* result from the device handler's API */ 316 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 317 318 SetLastError(ERROR_SUCCESS); 319 /* validate handle */ 320 pHMHandle = HMHandleQueryPtr(hPipe); /* get the index */ 321 if (pHMHandle == NULL) /* error ? */ 322 { 323 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 324 } 325 326 lpResult = pHMHandle->pDeviceHandler->GetNamedPipeInfo(&pHMHandle->hmHandleData, 327 lpFlags, 328 lpOutBufferSize, 329 lpInBufferSize, 330 lpMaxInstances); 331 332 return (lpResult); /* deliver return code */ 333 } 334 335 /***************************************************************************** 336 * Name : BOOL TransactNamedPipe 337 * Purpose : The TransactNamedPipe function combines into a single network 338 * operation the functions that write a message to and read a 339 * message from the specified named pipe. 340 * Parameters: HANDLE hNamedPipe handle of named pipe 341 * LPVOID lpvWriteBuf address of write buffer 342 * DWORD cbWriteBuf size of the write buffer, in bytes 343 * LPVOID lpvReadBuf address of read buffer 344 * DWORD cbReadBuf size of read buffer, in bytes 345 * LPDWORD lpcbRead address of variable for bytes actually read 346 * LPOVERLAPPED lpo address of overlapped structure 347 * Variables : 348 * Result : TRUE / FALSE 349 * Remark : 350 * Status : NOT FULLY TESTED (YET!) 351 * 352 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 08:48] 353 *****************************************************************************/ 354 BOOL WIN32API TransactNamedPipe(HANDLE hPipe, 355 LPVOID lpvWriteBuf, 356 DWORD cbWriteBuf, 357 LPVOID lpvReadBuf, 358 DWORD cbReadBuf, 359 LPDWORD lpcbRead, 360 LPOVERLAPPED lpo) 361 { 362 BOOL lpResult; /* result from the device handler's API */ 363 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 364 365 SetLastError(ERROR_SUCCESS); 366 /* validate handle */ 367 pHMHandle = HMHandleQueryPtr(hPipe); /* get the index */ 368 if (pHMHandle == NULL) /* error ? */ 369 { 370 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 371 } 372 373 lpResult = pHMHandle->pDeviceHandler->TransactNamedPipe(&pHMHandle->hmHandleData, 374 lpvWriteBuf, 375 cbWriteBuf, 376 lpvReadBuf, 377 cbReadBuf, 378 lpcbRead, 379 lpo); 380 381 return (lpResult); /* deliver return code */ 382 } 383 384 /***************************************************************************** 385 * Name : BOOL SetNamedPipeHandleState 386 * Purpose : The SetNamedPipeHandleState function sets the read mode and the 387 * blocking mode of the specified named pipe. If the specified handle 388 * is to the client end of a named pipe and if the named pipe server 389 * process is on a remote computer, the function can also be used to 390 * control local buffering. 391 * Parameters: HANDLE hNamedPipe handle of named pipe 392 * LPDWORD lpdwMode address of new pipe mode 393 * LPDWORD lpcbMaxCollect address of max. bytes before remote transmission 394 * LPDWORD lpdwCollectDataTimeout address of max. time before remote transmission 395 * Variables : 396 * Result : TRUE / FALSE 397 * Remark : 398 * Status : 399 * 400 * Author : Przemyslaw Dobrowolski 401 *****************************************************************************/ 402 403 BOOL WIN32API SetNamedPipeHandleState(HANDLE hPipe, 404 LPDWORD lpdwMode, 405 LPDWORD lpcbMaxCollect, 406 LPDWORD lpdwCollectDataTimeout) 407 { 408 BOOL lpResult; /* result from the device handler's API */ 409 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 410 411 SetLastError(ERROR_SUCCESS); 412 /* validate handle */ 413 pHMHandle = HMHandleQueryPtr(hPipe); /* get the index */ 414 if (pHMHandle == NULL) /* error ? */ 415 { 416 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 417 } 418 419 lpResult = pHMHandle->pDeviceHandler->SetNamedPipeHandleState(&pHMHandle->hmHandleData, 420 lpdwMode, 421 lpcbMaxCollect, 422 lpdwCollectDataTimeout); 423 424 return (lpResult); /* deliver return code */ 425 } 426 427 104 428 //****************************************************************************** 105 429 //****************************************************************************** … … 114 438 asciiname = UnicodeToAsciiString((LPWSTR)lpName); 115 439 116 hPipe= HMCreateNamedPipe(asciiname,440 hPipe=CreateNamedPipeA(asciiname, 117 441 dwOpenMode, 118 442 dwPipeMode, … … 126 450 127 451 return(hPipe); 128 }129 //******************************************************************************130 //******************************************************************************131 132 133 /*****************************************************************************134 * Name : BOOL WIN32API ConnectNamedPipe135 * Purpose : The ConnectNamedPipe function enables a named pipe server process136 * to wait for a client process to connect to an instance of a137 * named pipe. A client process connects by calling either the138 * CreateFile or CallNamedPipe function.139 * Parameters: HANDLE hNamedPipe handle to named pipe to connect140 * LPOVERLAPPED lpOverlapped pointer to overlapped structure141 * Variables :142 * Result : If the function succeeds, the return value is nonzero.143 * If the function fails, the return value is zero.144 * To get extended error information, call GetLastError.145 * Remark :146 * Status : NOT FULLY TESTED147 *148 * Author : Przemyslaw Dobrowolski [Sun, 2000/01/02 12:48]149 *****************************************************************************/150 BOOL WIN32API ConnectNamedPipe(HANDLE hNamedPipe, LPOVERLAPPED lpOverlapped)151 {152 return (HMConnectNamedPipe(hNamedPipe,lpOverlapped));153 452 } 154 453 … … 263 562 } 264 563 265 /*****************************************************************************266 * Name : BOOL WIN32API DisconnectNamedPipe267 * Purpose : The DisconnectNamedPipe function disconnects the server end268 * of a named pipe instance from a client process.269 * Parameters: HANDLE hNamedPipe handle to named pipe270 * Variables :271 * Result : If the function succeeds, the return value is nonzero.272 * If the function fails, the return value is zero273 * Remark :274 * Status : NOT FULLY TESTED275 *276 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 13:34]277 *****************************************************************************/278 279 BOOL WIN32API DisconnectNamedPipe(HANDLE hNamedPipe)280 {281 return (HMDisconnectNamedPipe(hNamedPipe));282 }283 284 /*****************************************************************************285 * Name : BOOL GetNamedPipeHandleStateA286 * Purpose : The GetNamedPipeHandleStateA function retrieves information about287 * a specified named pipe. The information returned can vary during288 * the lifetime of an instance of the named pipe.289 * Parameters: HANDLE hNamedPipe handle of named pipe290 * LPDWORD lpState address of flags indicating pipe state291 * LPDWORD lpCurInstances address of number of current pipe instances292 * LPDWORD lpMaxCollectionCount address of max. bytes before remote transmission293 * LPDWORD lpCollectDataTimeout address of max. time before remote transmission294 * LPTSTR lpUserName address of user name of client process295 * DWORD nMaxUserNameSize size, in characters, of user name buffer296 * Variables :297 * Result : TRUE / FALSE298 * Remark :299 * Status : UNTESTED STUB300 *301 * Author : Patrick Haller [Mon, 1998/06/15 08:00]302 *****************************************************************************/303 304 BOOL WIN32API GetNamedPipeHandleStateA(HANDLE hNamedPipe,305 LPDWORD lpState,306 LPDWORD lpCurInstances,307 LPDWORD lpMaxCollectionCount,308 LPDWORD lpCollectDataTimeout,309 LPTSTR lpUserName,310 DWORD nMaxUserNameSize)311 {312 // Not implemented but waiting to implementation in hmnpipe.cpp313 return ( HMGetNamedPipeHandleState( hNamedPipe,314 lpState,315 lpCurInstances,316 lpMaxCollectionCount,317 lpCollectDataTimeout,318 lpUserName,319 nMaxUserNameSize));320 }321 322 564 323 565 /***************************************************************************** … … 355 597 356 598 // Not implemented but waiting to implementation in hmnpipe.cpp 357 rc= HMGetNamedPipeHandleState( hNamedPipe,599 rc= GetNamedPipeHandleStateA( hNamedPipe, 358 600 lpState, 359 601 lpCurInstances, … … 367 609 368 610 return (rc); 369 }370 371 372 /*****************************************************************************373 * Name : BOOL GetNamedPipeInfo374 * Purpose : The GetNamedPipeInfo function retrieves information about the specified named pipe.375 * Parameters: HANDLE hNamedPipe handle of named pipe376 * LPDWORD lpFlags address of flags indicating type of pipe377 * LPDWORD lpOutBufferSize address of size, in bytes, of pipe's output buffer378 * LPDWORD lpInBufferSize address of size, in bytes, of pipe's input buffer379 * LPDWORD lpMaxInstances address of max. number of pipe instances380 * Variables :381 * Result : TRUE / FALSE382 * Remark :383 * Status : UNTESTED STUB384 *385 * Author : Patrick Haller [Mon, 1998/06/15 08:00]386 *****************************************************************************/387 388 BOOL WIN32API GetNamedPipeInfo(HANDLE hNamedPipe,389 LPDWORD lpFlags,390 LPDWORD lpOutBufferSize,391 LPDWORD lpInBufferSize,392 LPDWORD lpMaxInstances)393 {394 // Not implemented but waiting to implementation in hmnpipe.cpp395 return ( HMGetNamedPipeInfo( hNamedPipe,396 lpFlags,397 lpOutBufferSize,398 lpInBufferSize,399 lpMaxInstances));400 401 }402 403 /*****************************************************************************404 * Name : BOOL SetNamedPipeHandleState405 * Purpose : The SetNamedPipeHandleState function sets the read mode and the406 * blocking mode of the specified named pipe. If the specified handle407 * is to the client end of a named pipe and if the named pipe server408 * process is on a remote computer, the function can also be used to409 * control local buffering.410 * Parameters: HANDLE hNamedPipe handle of named pipe411 * LPDWORD lpdwMode address of new pipe mode412 * LPDWORD lpcbMaxCollect address of max. bytes before remote transmission413 * LPDWORD lpdwCollectDataTimeout address of max. time before remote transmission414 * Variables :415 * Result : TRUE / FALSE416 * Remark :417 * Status : UNTESTED STUB418 *419 * Author : Patrick Haller [Mon, 1998/06/15 08:00]420 *****************************************************************************/421 422 BOOL WIN32API SetNamedPipeHandleState(HANDLE hNamedPipe,423 LPDWORD lpdwMode,424 LPDWORD lpcbMaxCollect,425 LPDWORD lpdwCollectDataTimeout)426 {427 // Not implemented but waiting to implementation in hmnpipe.cpp428 return ( HMSetNamedPipeHandleState( hNamedPipe,429 lpdwMode,430 lpcbMaxCollect,431 lpdwCollectDataTimeout));432 }433 434 /*****************************************************************************435 * Name : BOOL TransactNamedPipe436 * Purpose : The TransactNamedPipe function combines into a single network437 * operation the functions that write a message to and read a438 * message from the specified named pipe.439 * Parameters: HANDLE hNamedPipe handle of named pipe440 * LPVOID lpvWriteBuf address of write buffer441 * DWORD cbWriteBuf size of the write buffer, in bytes442 * LPVOID lpvReadBuf address of read buffer443 * DWORD cbReadBuf size of read buffer, in bytes444 * LPDWORD lpcbRead address of variable for bytes actually read445 * LPOVERLAPPED lpo address of overlapped structure446 * Variables :447 * Result : TRUE / FALSE448 * Remark :449 * Status : NOT FULLY TESTED (YET!)450 *451 * Author : Przemyslaw Dobrowolski [Mon, 2000/01/03 08:48]452 *****************************************************************************/453 454 BOOL WIN32API TransactNamedPipe(HANDLE hNamedPipe,455 LPVOID lpvWriteBuf,456 DWORD cbWriteBuf,457 LPVOID lpvReadBuf,458 DWORD cbReadBuf,459 LPDWORD lpcbRead,460 LPOVERLAPPED lpo)461 {462 return(HMTransactNamedPipe( hNamedPipe,463 lpvWriteBuf,464 cbWriteBuf,465 lpvReadBuf,466 cbReadBuf,467 lpcbRead,468 lpo));469 611 } 470 612 -
trunk/src/kernel32/ole2nls.c
r9975 r21302 1912 1912 } 1913 1913 1914 #ifdef __WIN32OS2__ 1915 /* For WCHAR we better use the WCHAR toupper/lower. 1916 * (VAC308 toupper/tolower doesn't do range checks according to standards 1917 * which may cause illegal memory reads access when misused like it were here. 1918 */ 1919 if (mapflags & LCMAP_UPPERCASE) 1920 f = toupperW; 1921 else if (mapflags & LCMAP_LOWERCASE) 1922 f = tolowerW; 1923 #else 1914 1924 if (mapflags & LCMAP_UPPERCASE) 1915 1925 f = toupper; 1916 1926 else if (mapflags & LCMAP_LOWERCASE) 1917 1927 f = tolower; 1928 #endif 1918 1929 if (f) 1919 1930 { -
trunk/src/kernel32/os2heap.cpp
r8877 r21302 41 41 #include "dbglocal.h" 42 42 43 #include <_ras.h> 44 45 #ifdef RAS 46 RAS_TRACK_HANDLE rthHeap = 0; 47 #endif 48 43 49 #ifndef HEAP_NO_SERIALIZE 44 50 #define HEAP_NO_SERIALIZE 1 … … 94 100 else heap = this; 95 101 next = NULL; 102 103 #ifdef RAS 104 if (!rthHeap) 105 { 106 RasRegisterObjectTracking (&rthHeap, "Heap*, Global* and Local* memory", 107 0, RAS_TRACK_FLAG_MEMORY | RAS_TRACK_FLAG_LOG_AT_EXIT, 108 NULL, NULL); 109 } 110 #endif 96 111 97 112 heaplistmutex.leave(); … … 173 188 return(NULL); 174 189 } 190 191 RasTrackMemAlloc (rthHeap, dwAllocBytes); 192 175 193 if(dwFlags & HEAP_ZERO_MEMORY) { 176 194 memset(lpMem, 0, dwAllocBytes+HEAP_OVERHEAD); … … 238 256 if (dwBytes <= maxSize) { 239 257 dprintf(("ReAlloc with smaller size than original (%d); return old pointer", maxSize)); 258 259 RasTrackMemRealloc (rthHeap, helem->cursize, dwBytes); 260 240 261 //update current size so HeapSize will return the right value 241 262 helem->cursize = dwBytes; … … 280 301 #endif 281 302 303 RasTrackMemFree (rthHeap, helem->cursize); 304 282 305 free(helem->lpMem); 306 283 307 return(TRUE); 284 308 } -
trunk/src/kernel32/oslibdos.cpp
r10132 r21302 265 265 case ERROR_WRONG_DISK: //34 266 266 return ERROR_WRONG_DISK_W; 267 268 case ERROR_BAD_NETPATH: //53 269 return ERROR_BAD_NETPATH_W; 267 270 268 271 case ERROR_SHARING_BUFFER_EXCEEDED: //36 … … 1045 1048 // @@@AH 2001-06-02 Win2k SP2 returns error 2 in this case 1046 1049 int winError = error2WinError(rc); 1047 if (winError == ERROR_OPEN_FAILED_W || winError == ERROR_PATH_NOT_FOUND_W)1050 if (winError == ERROR_OPEN_FAILED_W) 1048 1051 { 1049 1052 //Windows returns ERROR_FILE_EXISTS if create new & file exists … … 2383 2386 { 2384 2387 FILESTATUS3 statusBuf; 2385 char lOemFileName[CCHMAXPATH];2388 char *lOemFileName; 2386 2389 char *lpszBackslash, *lpszColon; 2387 2390 APIRET rc; 2388 2391 2389 //testestest 2390 if(strlen(lpFileName) > CCHMAXPATH) DebugInt3(); 2391 //testestset 2392 lOemFileName = (char *)malloc(strlen(lpFileName)+64); 2393 lOemFileName[0] = 0; 2392 2394 2393 2395 //Convert file name from Windows to OS/2 codepage … … 2399 2401 { 2400 2402 lpszColon = CharPrevA(lOemFileName, lpszBackslash); 2401 if( lpszColon && *lpszColon != ':')2403 if(strlen(lOemFileName) > 1 && lpszColon && *lpszColon != ':') 2402 2404 {//only rootdir is allowed to have terminating backslash 2403 2405 *lpszBackslash = 0; … … 2420 2422 rc = DosQueryPathInfo(lOemFileName, FIL_STANDARD, &statusBuf, sizeof(statusBuf)); 2421 2423 } 2424 free(lOemFileName); 2422 2425 2423 2426 if(rc == NO_ERROR) -
trunk/src/kernel32/oslibexcept.cpp
r5905 r21302 171 171 case XCPT_ILLEGAL_INSTRUCTION: 172 172 case XCPT_PRIVILEGED_INSTRUCTION: 173 case XCPT_INTEGER_DIVIDE_BY_ZERO: 174 case XCPT_UNABLE_TO_GROW_STACK: 173 175 #ifndef DEBUG 174 176 case XCPT_BREAKPOINT: … … 180 182 case XCPT_BREAKPOINT: 181 183 #endif 182 case XCPT_INTEGER_DIVIDE_BY_ZERO:183 184 case XCPT_INTEGER_OVERFLOW: 184 185 case XCPT_SINGLE_STEP: … … 187 188 case XCPT_INVALID_LOCK_SEQUENCE: 188 189 case XCPT_GUARD_PAGE_VIOLATION: 189 case XCPT_UNABLE_TO_GROW_STACK:190 190 case XCPT_IN_PAGE_ERROR: 191 191 default: -
trunk/src/kernel32/oslibmem.cpp
r9945 r21302 32 32 #include <winconst.h> 33 33 #include <win\winioctl.h> 34 #include <misc.h> 34 #include <dbglog.h> 35 #include <vmutex.h> 35 36 #include "initterm.h" 36 37 #include "oslibdos.h" … … 38 39 #include "dosqss.h" 39 40 #include "win32k.h" 41 #include "exceptstackdump.h" 40 42 41 43 #define DBG_LOCALLOG DBG_oslibmem 42 44 #include "dbglocal.h" 43 45 46 #include <_ras.h> 47 48 #ifdef RAS 49 RAS_TRACK_HANDLE rthVirtual = 0; 50 51 void rasInitVirtual (void) 52 { 53 RasRegisterObjectTracking (&rthVirtual, "Virtual* memory allocation", 54 0, RAS_TRACK_FLAG_MEMORY | RAS_TRACK_FLAG_LOG_OBJECTS_AT_EXIT, 55 NULL, NULL); 56 } 57 #endif 58 59 typedef struct _VirtAllocRec { 60 ULONG baseaddr; 61 ULONG size; 62 ULONG attr; 63 64 struct _VirtAllocRec *next; 65 } VirtAllocRec; 66 67 static VirtAllocRec *allocrecords = NULL; 68 static CRITICAL_SECTION_OS2 alloccritsect = {0}; 69 70 //****************************************************************************** 71 //****************************************************************************** 72 void AddAllocRec(ULONG baseaddr, ULONG size, ULONG attr) 73 { 74 VirtAllocRec *rec, *tmp; 75 76 rec = (VirtAllocRec *)malloc(sizeof(VirtAllocRec)); 77 if(!rec) { 78 DebugInt3(); 79 return; 80 } 81 rec->baseaddr = baseaddr; 82 rec->size = size; 83 rec->attr = attr; 84 85 DosEnterCriticalSection(&alloccritsect); 86 if(!allocrecords || allocrecords->baseaddr > baseaddr) { 87 rec->next = allocrecords; 88 allocrecords = rec; 89 } 90 else { 91 tmp = allocrecords; 92 while(tmp->next) { 93 if(tmp->next->baseaddr > baseaddr) { 94 break; 95 } 96 tmp = tmp->next; 97 } 98 99 rec->next = tmp->next; 100 tmp->next = rec; 101 } 102 DosLeaveCriticalSection(&alloccritsect); 103 } 104 //****************************************************************************** 105 //****************************************************************************** 106 void FreeAllocRec(ULONG baseaddr) 107 { 108 VirtAllocRec *rec = NULL, *tmp; 109 110 if(!allocrecords) { 111 DebugInt3(); 112 return; 113 } 114 115 DosEnterCriticalSection(&alloccritsect); 116 if(allocrecords->baseaddr == baseaddr) { 117 rec = allocrecords; 118 allocrecords = allocrecords->next; 119 } 120 else { 121 tmp = allocrecords; 122 while(tmp->next) { 123 if(tmp->next->baseaddr == baseaddr) { 124 break; 125 } 126 tmp = tmp->next; 127 } 128 if(tmp->next) { 129 rec = tmp->next; 130 tmp->next = tmp->next->next; 131 } 132 else dprintf(("ERROR: FreeAllocRec: allocation not found!! (%x)", baseaddr)); 133 } 134 DosLeaveCriticalSection(&alloccritsect); 135 if(rec) free(rec); 136 } 137 //****************************************************************************** 138 //****************************************************************************** 139 BOOL FindAllocRec(ULONG addr, ULONG *lpBase, ULONG *lpSize, ULONG *lpAttr) 140 { 141 VirtAllocRec *rec = NULL; 142 143 DosEnterCriticalSection(&alloccritsect); 144 rec = allocrecords; 145 while(rec) { 146 if(rec->baseaddr <= addr && rec->baseaddr + rec->size > addr) { 147 *lpBase = rec->baseaddr; 148 *lpSize = rec->size; 149 *lpAttr = rec->attr; 150 break; //found it 151 } 152 if(rec->baseaddr > addr) { 153 //sorted list, so no need to search any further 154 rec = NULL; 155 break; 156 } 157 rec = rec->next; 158 } 159 DosLeaveCriticalSection(&alloccritsect); 160 return (rec != NULL); 161 } 44 162 //****************************************************************************** 45 163 //TODO: Check if this works for code aliases... … … 83 201 pAlias += size; 84 202 } 203 AddAllocRec((ULONG)*ppbAlias, cb, fl); 85 204 return 0; 86 205 } … … 99 218 fMemFlags = 0; 100 219 } 220 101 221 /* 102 222 * Let's try use the extended DosAllocMem API of Win32k.sys. … … 105 225 { 106 226 rc = DosAllocMemEx(lplpMemAddr, cbSize, flFlags | fMemFlags | OBJ_ALIGN64K); 227 #ifdef RAS 228 if (rc == NO_ERROR) 229 { 230 RasAddObject (rthVirtual, (ULONG)*lplpMemAddr, NULL, cbSize); 231 } 232 #endif 107 233 if (rc != ERROR_NOT_SUPPORTED) /* This call was stubbed until recently. */ 108 234 return rc; … … 132 258 return rc; 133 259 } 260 261 PVOID baseAddr = (PVOID)addr64kb; // sunlover20040613: save returned address for a possible Free on failure 262 134 263 dprintf(("Allocate aligned memory %x -> %x", addr64kb, (addr64kb + 0xFFFF) & ~0xFFFF)); 135 264 … … 144 273 if(rc) { 145 274 dprintf(("!ERROR!: DosSetMem failed with rc %d", rc)); 275 DosFreeMem (baseAddr); // sunlover20040613: Free allocated memory 146 276 return rc; 147 277 } … … 149 279 } 150 280 151 if(!rc) 281 if(!rc) { 152 282 *lplpMemAddr = pvMemAddr; 153 283 AddAllocRec((ULONG)pvMemAddr, cbSize, flFlags); 284 RasAddObject (rthVirtual, (ULONG)*lplpMemAddr, NULL, cbSize); 285 } 154 286 return rc; 155 287 } … … 157 289 //Locate the base page of a memory allocation (the page with the PAG_BASE attribute) 158 290 //****************************************************************************** 159 PVOID OSLibDosFindMemBase(LPVOID lpMemAddr )160 { 161 ULONG ulAttr, ulSize, ulAddr ;291 PVOID OSLibDosFindMemBase(LPVOID lpMemAddr, DWORD *lpAttr) 292 { 293 ULONG ulAttr, ulSize, ulAddr, ulBase; 162 294 APIRET rc; 295 VirtAllocRec *allocrec; 296 297 *lpAttr = 0; 163 298 299 if(FindAllocRec((ULONG)lpMemAddr, &ulBase, &ulSize, lpAttr) == TRUE) { 300 return (PVOID)ulBase; 301 } 302 303 ulSize = PAGE_SIZE; 164 304 rc = DosQueryMem(lpMemAddr, &ulSize, &ulAttr); 165 305 if(rc != NO_ERROR) { … … 226 366 dprintf(("!ERROR!: OSLibDosFreeMem: Unable to find base of %x", lpMemAddr)); 227 367 DebugInt3(); 228 } 229 else { 230 lpMemAddr = (PVOID)ulAddr; 231 } 232 return DosFreeMem(lpMemAddr); 368 return ERROR_INVALID_PARAMETER; 369 } 370 FreeAllocRec((ULONG)lpMemAddr); 371 372 RasRemoveObject (rthVirtual, (ULONG)lpMemAddr); 373 374 return DosFreeMem((PVOID)ulAddr); 233 375 } 234 376 //****************************************************************************** -
trunk/src/kernel32/oslibmem.h
r9617 r21302 52 52 DWORD OSLibDosAllocSharedMem(LPVOID *lplpMemAddr, DWORD size, DWORD flags, LPSTR name); 53 53 DWORD OSLibDosGetNamedSharedMem(LPVOID *lplpMemAddr, LPSTR name); 54 PVOID OSLibDosFindMemBase(LPVOID lpMemAddr );54 PVOID OSLibDosFindMemBase(LPVOID lpMemAddr, DWORD *lpAttr); 55 55 56 56 #ifdef __cplusplus -
trunk/src/kernel32/oslibmisc.cpp
r10606 r21302 24 24 #include "oslibmisc.h" 25 25 #include <misc.h> 26 #include <heapstring.h>27 26 28 27 #define DBG_LOCALLOG DBG_oslibmisc 29 28 #include "dbglocal.h" 30 31 typedef APIRET ( APIENTRY *PFN_IMSETMSGQUEUEPROPERTY )( HMQ, ULONG );32 33 PFN_IMSETMSGQUEUEPROPERTY pfnImSetMsgQueueProperty = NULL;34 29 35 30 //****************************************************************************** … … 344 339 //****************************************************************************** 345 340 //****************************************************************************** 346 ULONG OSLibImSetMsgQueueProperty( ULONG hmq, ULONG ulFlag ) 347 { 348 USHORT sel; 349 APIRET rc; 350 351 if( !pfnImSetMsgQueueProperty ) 352 return 1; 353 354 sel = RestoreOS2FS(); 355 rc = pfnImSetMsgQueueProperty( hmq, ulFlag ); 356 SetFS( sel ); 357 358 return rc; 359 } 360 //****************************************************************************** 361 //****************************************************************************** 362 341 void OSLibSetBeginLibpath(char *lpszBeginlibpath) 342 { 343 DosSetExtLIBPATH(lpszBeginlibpath, BEGIN_LIBPATH); 344 } 345 //****************************************************************************** 346 //****************************************************************************** 347 void OSLibQueryBeginLibpath(char *lpszBeginlibpath, int size) 348 { 349 DosQueryExtLIBPATH(lpszBeginlibpath, BEGIN_LIBPATH); 350 } 351 //****************************************************************************** 352 //****************************************************************************** 353 -
trunk/src/kernel32/oslibmisc.h
r10606 r21302 100 100 ULONG OSLibQueryCountry(); 101 101 102 ULONG OSLibImSetMsgQueueProperty( ULONG hmq, ULONG ulFlag ); 102 void OSLibSetBeginLibpath(char *lpszBeginlibpath); 103 void OSLibQueryBeginLibpath(char *lpszBeginlibpath, int size); 103 104 104 105 #ifdef __cplusplus -
trunk/src/kernel32/oslibthread.cpp
r9945 r21302 123 123 if(rc != NO_ERROR) { 124 124 dprintf(("ERROR: DosQueryThreadContext failed with rc %d!!", rc)); 125 if(rc == ERROR_NOT_FROZEN && ++nrtries < 5) { 125 //testestest 126 if((rc == ERROR_NOT_FROZEN || rc == ERROR_INVALID_THREADID) && ++nrtries < 5) { 126 127 DosSleep(50); 127 128 goto tryagain; 128 129 } 130 DebugInt3(); 129 131 SetLastError(error2WinError(rc, ERROR_INVALID_PARAMETER)); 130 132 return FALSE; -
trunk/src/kernel32/registry.cpp
r10624 r21302 712 712 } 713 713 714 /*****************************************************************************715 * Name :716 * Purpose :717 * Parameters:718 * Variables :719 * Result :720 * Remark :721 * Status : UNTESTED STUB722 *723 * Author : Chris []724 *****************************************************************************/725 726 LONG WIN32API RegOpenCurrentUser(REGSAM samDesired, PHKEY phkResult)727 {728 LONG rc;729 730 rc = O32_RegOpenKeyEx(ConvertKey(HKEY_CURRENT_USER),731 NULL,732 0,733 samDesired,734 phkResult);735 if(rc)736 *phkResult = 0;737 738 dprintf(("RegOpenCurrentUser: rc=%d\n", rc));739 740 return(rc);741 }742 714 743 715 /***************************************************************************** -
trunk/src/kernel32/thread.cpp
r10606 r21302 34 34 #include <handlemanager.h> 35 35 #include <codepage.h> 36 #include <heapstring.h> 36 37 #include "hmhandle.h" 38 #include "hmthread.h" 39 #include <kbdhook.h> 37 40 38 41 #include <FastInfoBlocks.h> 42 #include <custombuild.h> 39 43 40 44 #define DBG_LOCALLOG DBG_thread … … 45 49 static ULONG priorityclass = NORMAL_PRIORITY_CLASS; 46 50 51 //****************************************************************************** 52 //****************************************************************************** 53 HANDLE WIN32API CreateThread(LPSECURITY_ATTRIBUTES lpsa, 54 DWORD cbStack, 55 LPTHREAD_START_ROUTINE lpStartAddr, 56 LPVOID lpvThreadParm, 57 DWORD fdwCreate, 58 LPDWORD lpIDThread) 59 { 60 return HMCreateThread(lpsa, cbStack, lpStartAddr, lpvThreadParm, fdwCreate, lpIDThread); 61 } 62 /***************************************************************************** 63 * Name : HMCreateThread 64 * Purpose : router function for CreateThread 65 * Parameters: 66 * Variables : 67 * Result : 68 * Remark : 69 * Status : 70 * 71 * Author : SvL 72 *****************************************************************************/ 73 HANDLE HMCreateThread(LPSECURITY_ATTRIBUTES lpsa, 74 DWORD cbStack, 75 LPTHREAD_START_ROUTINE lpStartAddr, 76 LPVOID lpvThreadParm, 77 DWORD fdwCreate, 78 LPDWORD lpIDThread, 79 BOOL fRegisterThread) 80 { 81 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 82 PHMHANDLE pHandle; 83 HANDLE rc; /* API return code */ 84 85 SetLastError(ERROR_SUCCESS); 86 87 pHandle = HMHandleGetFreePtr(HMTYPE_THREAD); /* get free handle */ 88 if (pHandle == NULL) /* oops, no free handles ! */ 89 { 90 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 91 return 0; //according to MSDN 92 } 93 94 /* call the device handler */ 95 rc = pHandle->pDeviceHandler->CreateThread(&pHandle->hmHandleData, 96 lpsa, cbStack, lpStartAddr, 97 lpvThreadParm, fdwCreate, lpIDThread, fRegisterThread); 98 99 if (rc == 0) /* oops, creation failed within the device handler */ 100 { 101 HMHandleFree(pHandle->hmHandleData.hWin32Handle); 102 return 0; /* signal error */ 103 } 104 105 return pHandle->hmHandleData.hWin32Handle; 106 } 107 /***************************************************************************** 108 * Name : HMGetThreadPriority 109 * Purpose : router function for GetThreadPriority 110 * Parameters: 111 * Variables : 112 * Result : 113 * Remark : 114 * Status : 115 * 116 * Author : SvL 117 *****************************************************************************/ 118 INT WIN32API GetThreadPriority(HANDLE hThread) 119 { 120 INT lpResult; /* result from the device handler's API */ 121 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 122 123 SetLastError(ERROR_SUCCESS); 124 /* validate handle */ 125 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 126 if (pHMHandle == NULL) /* error ? */ 127 { 128 return -1; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 129 } 130 131 lpResult = pHMHandle->pDeviceHandler->GetThreadPriority(hThread, &pHMHandle->hmHandleData); 132 133 return (lpResult); /* deliver return code */ 134 } 135 /***************************************************************************** 136 * Name : HMSuspendThread 137 * Purpose : router function for SuspendThread 138 * Parameters: 139 * Variables : 140 * Result : 141 * Remark : 142 * Status : 143 * 144 * Author : SvL 145 *****************************************************************************/ 146 DWORD WIN32API SuspendThread(HANDLE hThread) 147 { 148 HANDLE lpResult; /* result from the device handler's API */ 149 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 150 151 SetLastError(ERROR_SUCCESS); 152 /* validate handle */ 153 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 154 if (pHMHandle == NULL) /* error ? */ 155 { 156 return -1; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 157 } 158 159 lpResult = pHMHandle->pDeviceHandler->SuspendThread(hThread, &pHMHandle->hmHandleData); 160 161 return (lpResult); /* deliver return code */ 162 } 163 /***************************************************************************** 164 * Name : HMSetThreadPriority 165 * Purpose : router function for SetThreadPriority 166 * Parameters: 167 * Variables : 168 * Result : 169 * Remark : 170 * Status : 171 * 172 * Author : SvL 173 *****************************************************************************/ 174 BOOL WIN32API SetThreadPriority(HANDLE hThread, int priority) 175 { 176 BOOL lpResult; /* result from the device handler's API */ 177 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 178 179 SetLastError(ERROR_SUCCESS); 180 /* validate handle */ 181 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 182 if (pHMHandle == NULL) /* error ? */ 183 { 184 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 185 } 186 lpResult = pHMHandle->pDeviceHandler->SetThreadPriority(hThread, &pHMHandle->hmHandleData, priority); 187 188 return (lpResult); /* deliver return code */ 189 } 190 /***************************************************************************** 191 * Name : HMGetThreadContext 192 * Purpose : router function for GetThreadContext 193 * Parameters: 194 * Variables : 195 * Result : 196 * Remark : 197 * Status : 198 * 199 * Author : SvL 200 *****************************************************************************/ 201 BOOL WIN32API GetThreadContext(HANDLE hThread, CONTEXT *lpContext) 202 { 203 BOOL lpResult; /* result from the device handler's API */ 204 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 205 206 SetLastError(ERROR_SUCCESS); 207 /* validate handle */ 208 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 209 if (pHMHandle == NULL) /* error ? */ 210 { 211 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 212 } 213 214 lpResult = pHMHandle->pDeviceHandler->GetThreadContext(hThread, &pHMHandle->hmHandleData, lpContext); 215 216 return (lpResult); /* deliver return code */ 217 } 218 /***************************************************************************** 219 * Name : HMSetThreadContext 220 * Purpose : router function for SetThreadContext 221 * Parameters: 222 * Variables : 223 * Result : 224 * Remark : 225 * Status : 226 * 227 * Author : SvL 228 *****************************************************************************/ 229 BOOL WIN32API SetThreadContext(HANDLE hThread, const CONTEXT *lpContext) 230 { 231 BOOL lpResult; /* result from the device handler's API */ 232 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 233 234 SetLastError(ERROR_SUCCESS); 235 /* validate handle */ 236 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 237 if (pHMHandle == NULL) /* error ? */ 238 { 239 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 240 } 241 lpResult = pHMHandle->pDeviceHandler->SetThreadContext(hThread, &pHMHandle->hmHandleData, lpContext); 242 243 return (lpResult); /* deliver return code */ 244 } 245 /***************************************************************************** 246 * Name : HMGetThreadTimes 247 * Purpose : router function for HMGetThreadTimes 248 * Parameters: 249 * Variables : 250 * Result : 251 * Remark : 252 * Status : 253 * 254 * Author : SvL 255 *****************************************************************************/ 256 BOOL WIN32API GetThreadTimes(HANDLE hThread, LPFILETIME lpCreationTime, 257 LPFILETIME lpExitTime, LPFILETIME lpKernelTime, 258 LPFILETIME lpUserTime) 259 { 260 BOOL lpResult; /* result from the device handler's API */ 261 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 262 263 SetLastError(ERROR_SUCCESS); 264 /* validate handle */ 265 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 266 if (pHMHandle == NULL) /* error ? */ 267 { 268 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 269 } 270 271 lpResult = pHMHandle->pDeviceHandler->GetThreadTimes(hThread, &pHMHandle->hmHandleData, 272 lpCreationTime, lpExitTime, 273 lpKernelTime, lpUserTime); 274 275 return (lpResult); /* deliver return code */ 276 } 277 /***************************************************************************** 278 * Name : HMTerminateThread 279 * Purpose : router function for TerminateThread 280 * Parameters: 281 * Variables : 282 * Result : 283 * Remark : 284 * Status : 285 * 286 * Author : SvL 287 *****************************************************************************/ 288 BOOL WIN32API TerminateThread(HANDLE hThread, DWORD exitcode) 289 { 290 BOOL lpResult; /* result from the device handler's API */ 291 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 292 293 SetLastError(ERROR_SUCCESS); 294 /* validate handle */ 295 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 296 if (pHMHandle == NULL) /* error ? */ 297 { 298 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 299 } 300 301 lpResult = pHMHandle->pDeviceHandler->TerminateThread(hThread, &pHMHandle->hmHandleData, exitcode); 302 303 return (lpResult); /* deliver return code */ 304 } 305 /***************************************************************************** 306 * Name : HMResumeThread 307 * Purpose : router function for ResumeThread 308 * Parameters: 309 * Variables : 310 * Result : 311 * Remark : 312 * Status : 313 * 314 * Author : SvL 315 *****************************************************************************/ 316 DWORD WIN32API ResumeThread(HANDLE hThread) 317 { 318 DWORD lpResult; /* result from the device handler's API */ 319 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 320 321 SetLastError(ERROR_SUCCESS); 322 /* validate handle */ 323 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 324 if (pHMHandle == NULL) /* error ? */ 325 { 326 return -1; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 327 } 328 329 lpResult = pHMHandle->pDeviceHandler->ResumeThread(hThread, &pHMHandle->hmHandleData); 330 331 return (lpResult); /* deliver return code */ 332 } 333 334 /***************************************************************************** 335 * Name : HMGetExitCodeThread 336 * Purpose : router function for GetExitCodeThread 337 * Parameters: 338 * Variables : 339 * Result : 340 * Remark : 341 * Status : 342 * 343 * Author : SvL 344 *****************************************************************************/ 345 BOOL WIN32API GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode) 346 { 347 BOOL lpResult; /* result from the device handler's API */ 348 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 349 350 SetLastError(ERROR_SUCCESS); 351 /* validate handle */ 352 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 353 if (pHMHandle == NULL) /* error ? */ 354 { 355 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 356 } 357 358 lpResult = pHMHandle->pDeviceHandler->GetExitCodeThread(hThread, &pHMHandle->hmHandleData, lpExitCode); 359 360 return (lpResult); /* deliver return code */ 361 } 362 /***************************************************************************** 363 * Name : HMSetThreadTerminated 364 * Purpose : 365 * Parameters: 366 * Variables : 367 * Result : 368 * Remark : 369 * Status : 370 * 371 * Author : SvL 372 *****************************************************************************/ 373 BOOL HMSetThreadTerminated(HANDLE hThread) 374 { 375 BOOL lpResult; /* result from the device handler's API */ 376 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 377 378 SetLastError(ERROR_SUCCESS); 379 /* validate handle */ 380 pHMHandle = HMHandleQueryPtr(hThread); /* get the index */ 381 if (pHMHandle == NULL) /* error ? */ 382 { 383 return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE) 384 } 385 lpResult = pHMHandle->pDeviceHandler->SetThreadTerminated(hThread, &pHMHandle->hmHandleData); 386 387 return (lpResult); /* deliver return code */ 388 } 47 389 //****************************************************************************** 48 390 //****************************************************************************** … … 312 654 } 313 655 } 314 315 #define MQP_INSTANCE_PERMQ 0x00000001 // from os2im.h316 656 //****************************************************************************** 317 657 //****************************************************************************** … … 320 660 EXCEPTION_FRAME exceptFrame; 321 661 Win32Thread *me = (Win32Thread *)lpData; 662 ULONG dwFlags = me->dwFlags; 322 663 ULONG threadCallback = (ULONG)me->pCallback; 323 664 LPVOID userdata = me->lpUserData; … … 334 675 dprintf(("Win32ThreadProc: Thread handle 0x%x, thread id %d", GetCurrentThread(), GetCurrentThreadId())); 335 676 336 winteb->flags = me->dwFlags;677 winteb->flags = dwFlags; 337 678 338 679 winteb->entry_point = (void *)threadCallback; … … 343 684 winteb->o.odin.hmq = OSLibWinQueryMsgQueue(winteb->o.odin.hab); 344 685 rc = OSLibWinSetCp(winteb->o.odin.hmq, GetDisplayCodepage()); 345 dprintf(("WinSetCP was %sOK(%d, %d)", rc ? "" : "not ")); 686 dprintf(("WinSetCP was %sOK", rc ? "" : "not ")); 687 hookInit(winteb->o.odin.hab); 346 688 347 689 dprintf(("Win32ThreadProc: hab %x hmq %x", winteb->o.odin.hab, winteb->o.odin.hmq)); 348 690 dprintf(("Stack top 0x%x, stack end 0x%x", winteb->stack_top, winteb->stack_low)); 349 350 if( IsDBCSEnv())351 /* IM instace is created per message queue, that is, thread */352 OSLibImSetMsgQueueProperty( winteb->o.odin.hmq, MQP_INSTANCE_PERMQ );353 691 354 692 //Note: The Win32 exception structure referenced by FS:[0] is the same … … 389 727 } 390 728 else { 729 hookKill(winteb->o.odin.hab); 391 730 HMSetThreadTerminated(GetCurrentThread()); 392 731 winteb->o.odin.exceptFrame = 0; … … 416 755 * @param fForceFSSwitch If set we will force switching to Odin32 FS selector. 417 756 * If clear it depends on defaults. 757 * @deprecated 418 758 */ 419 759 USHORT WIN32API ODIN_ThreadEnterOdinContext(void *pExceptionRegRec, BOOL fForceFSSwitch) … … 429 769 if (!pTeb) 430 770 { 431 BOOL fMainThread = fibGetTid() == 1; 432 HANDLE hThreadMain = HMCreateThread(NULL, 0, 0, 0, 0, 0, fMainThread); 433 pTeb = CreateTEB(hThreadMain, fibGetTid()); 434 if (!pTeb || InitializeThread(pTeb, fMainThread) == FALSE) 771 HANDLE hThreadMain = HMCreateThread(NULL, 0, 0, 0, 0, 0, TRUE); 772 pTeb = CreateTEB(hThreadMain, ODIN_GetCurrentThreadId()); 773 if (!pTeb || InitializeThread(pTeb, fibGetTid() == 1) == FALSE) 435 774 { 436 775 dprintf(("ODIN_ThreadEnterOdinContext: Failed to create TEB!")); … … 471 810 * @param fForceFSSwitch If set we will force switching to Odin32 FS selector. 472 811 * If clear it depends on defaults. 812 * @deprecated 473 813 */ 474 814 void WIN32API ODIN_ThreadLeaveOdinContext(void *pExceptionRegRec, USHORT selFSOld) … … 505 845 * Must be located on the callers stack. 506 846 * @param fRemoveOdinExcpt Remove the odin exception handler. 847 * @deprecated 507 848 */ 508 849 USHORT WIN32API ODIN_ThreadLeaveOdinContextNested(void *pExceptionRegRec, BOOL fRemoveOdinExcpt) … … 551 892 * @param selFSOld The Odin FS selector returned by the Nested Leave api. 552 893 * 894 * @deprecated 553 895 */ 554 896 void WIN32API ODIN_ThreadEnterOdinContextNested(void *pExceptionRegRec, BOOL fRestoreOdinExcpt, USHORT selFSOld) … … 578 920 579 921 922 /** Save thread context and/or load other thread context. 923 * @param pCtx Where to save the current thread context. 924 * @param fFlags Flags telling what to do. 925 * @todo Need to do special handling of NESTED flag? 926 */ 927 void WIN32API ODIN_ThreadContextSave(PODINTHREADCTX pCtx, unsigned fFlags) 928 { 929 TEB *pTeb = NULL; 930 931 /* 932 * Do requested saves. 933 */ 934 if (pCtx) 935 { 936 memset(pCtx, 0, sizeof(*pCtx)); 937 pCtx->fFlags = fFlags; 938 if (fFlags & OTCTXF_SAVE_FPU) 939 pCtx->cw = _control87(0, 0); 940 if (fFlags & OTCTXF_SAVE_FS) 941 pCtx->fs = GetFS(); 942 } 943 944 /* 945 * Get Odin32 TEB. 946 */ 947 if (fFlags & (OTCTXF_LOAD_FS_ODIN32 | OTCTXF_LOAD_XCPT_ODIN32)) 948 { 949 /* 950 * Get TEB pointer, create it if necessary. 951 * @todo Check if this really is the thread which the TEB was created 952 * for. If not create the TEB. This is rather unlikely.. 953 */ 954 pTeb = GetThreadTEB(); 955 if (!pTeb) 956 { 957 HANDLE hThreadMain = HMCreateThread(NULL, 0, 0, 0, 0, 0, TRUE); 958 dprintf(("Setup external thread %x!", hThreadMain)); 959 pTeb = CreateTEB(hThreadMain, ODIN_GetCurrentThreadId()); 960 if (!pTeb || !InitializeThread(pTeb, fibGetTid() == 1)) 961 { 962 dprintf(("ODIN_ThreadContextSave: Failed to create TEB!")); 963 DebugInt3(); 964 } 965 } 966 } 967 968 /* 969 * Install exception handler if requested. 970 */ 971 if (fFlags & OTCTXF_LOAD_XCPT_ODIN32) 972 { 973 OS2UnsetExceptionHandler(&pCtx->XctpRegRec); 974 if ( pTeb 975 && !pTeb->o.odin.exceptFrame) /* if allready present, we'll keep the first one. */ 976 pTeb->o.odin.exceptFrame = (ULONG)&pCtx->XctpRegRec; 977 } 978 979 /* 980 * Do requested loads. 981 */ 982 if (fFlags & OTCTXF_LOAD_FPU_ODIN32) 983 CONTROL87(0x27F, 0xFFFF); //Set FPU control word to 0x27F (same as in NT) 984 if (fFlags & OTCTXF_LOAD_FPU_OS2) 985 CONTROL87(0x37F, 0xFFFF); //Set FPU control word to 0x37F as that's most common on OS/2. 986 if ((fFlags & OTCTXF_LOAD_FS_ODIN32) && pTeb) 987 SetFS(pTeb->teb_sel); 988 } 989 990 991 /** Restore saved thread context and/or do additional loads. 992 * @param pCtx Where to save the current thread context. 993 * @param fFlags Flags telling extra stuff to load. 994 * Only CTCTXF_LOAD_* flags will be evaluated. 995 * @todo Need to do special handling of NESTED flag? 996 */ 997 void WIN32API ODIN_ThreadContextRestore(PODINTHREADCTX pCtx, unsigned fFlags) 998 { 999 /* 1000 * Restore context. 1001 */ 1002 if (pCtx) 1003 { 1004 if (pCtx->fFlags & OTCTXF_SAVE_FPU) 1005 CONTROL87(pCtx->cw, 0xffff); 1006 if (pCtx->fFlags & OTCTXF_SAVE_FS) 1007 SetFS(pCtx->fs); 1008 if (pCtx->fFlags & OTCTXF_LOAD_XCPT_ODIN32) 1009 { 1010 TEB *pTeb = GetThreadTEB(); 1011 if (pTeb && pTeb->o.odin.exceptFrame == (ULONG)&pCtx->XctpRegRec) 1012 pTeb->o.odin.exceptFrame = 0; 1013 OS2UnsetExceptionHandler(&pCtx->XctpRegRec); 1014 } 1015 memset(pCtx, 0, sizeof(*pCtx)); 1016 } 1017 1018 /* 1019 * Do requested loads. 1020 */ 1021 if (fFlags & OTCTXF_LOAD_FPU_ODIN32) 1022 CONTROL87(0x27F, 0xFFFF); //Set FPU control word to 0x27F (same as in NT) 1023 if (fFlags & OTCTXF_LOAD_FPU_OS2) 1024 CONTROL87(0x37F, 0xFFFF); //Set FPU control word to 0x37F as that's most common on OS/2. 1025 if ((fFlags & OTCTXF_LOAD_FS_ODIN32)) 1026 { 1027 /* 1028 * Get TEB pointer, create it if necessary. 1029 * @todo Check if this really is the thread which the TEB was created 1030 * for. If not create the TEB. This is rather unlikely.. 1031 */ 1032 TEB *pTeb = GetThreadTEB(); 1033 if (!pTeb) 1034 { 1035 HANDLE hThreadMain = HMCreateThread(NULL, 0, 0, 0, 0, 0, TRUE); 1036 pTeb = CreateTEB(hThreadMain, ODIN_GetCurrentThreadId()); 1037 if ( !pTeb 1038 || !InitializeThread(pTeb, fibGetTid() == 1)) 1039 { 1040 dprintf(("ODIN_ThreadContextRestore: Failed to create TEB!")); 1041 DebugInt3(); 1042 } 1043 } 1044 if (pTeb) 1045 SetFS(pTeb->teb_sel); 1046 } 1047 } 1048 -
trunk/src/kernel32/time.cpp
r9647 r21302 19 19 #include <odinwrap.h> 20 20 #include <os2sel.h> 21 #include <FastInfoBlocks.h> 21 22 22 23 #include <os2win.h> … … 93 94 94 95 ret = O32_FileTimeToSystemTime(lpFileTime, lpSystemTime); 95 dprintf(("time: %d-%d-%d % d:%d:%d", lpSystemTime->wDay, lpSystemTime->wMonth, lpSystemTime->wYear, lpSystemTime->wHour, lpSystemTime->wMinute, lpSystemTime->wSecond));96 dprintf(("time: %d-%d-%d %02d:%02d:%02d", lpSystemTime->wDay, lpSystemTime->wMonth, lpSystemTime->wYear, lpSystemTime->wHour, lpSystemTime->wMinute, lpSystemTime->wSecond)); 96 97 return ret; 97 98 } … … 153 154 } 154 155 O32_GetSystemTime(lpSystemTime); 156 dprintf2(("time: %d-%d-%d %02d:%02d:%02d", lpSystemTime->wDay, lpSystemTime->wMonth, lpSystemTime->wYear, lpSystemTime->wHour, lpSystemTime->wMinute, lpSystemTime->wSecond)); 155 157 } 156 158 //****************************************************************************** … … 245 247 RegCloseKey(hkey); 246 248 247 //TODO: we should return whether or we are in standard or daylight time 248 return TIME_ZONE_ID_STANDARD; 249 dprintf(("Bias %x", lpTimeZone->Bias)); 250 dprintf(("StandardName %ls", lpTimeZone->StandardName)); 251 dprintf(("StandardBias %x", lpTimeZone->StandardBias)); 252 dprintf(("StandardDate %d-%d-%d-%d", lpTimeZone->StandardDate.wYear, lpTimeZone->StandardDate.wMonth, lpTimeZone->StandardDate.wDay, lpTimeZone->StandardDate.wDayOfWeek)); 253 dprintf(("DaylightName %ls", lpTimeZone->DaylightName)); 254 dprintf(("DaylightBias %x", lpTimeZone->DaylightBias)); 255 dprintf(("DaylightDate %d-%d-%d-%d\n", lpTimeZone->DaylightDate.wYear, lpTimeZone->DaylightDate.wMonth, lpTimeZone->DaylightDate.wDay, lpTimeZone->DaylightDate.wDayOfWeek)); 256 257 //TODO: determine daylight or standard time 258 return TIME_ZONE_ID_UNKNOWN; 249 259 } 250 260 else … … 262 272 lstrcpynAtoW(lpTimeZone->DaylightName, (LPSTR)tzone.DaylightName, len); 263 273 lpTimeZone->DaylightName[len] = 0; 274 275 dprintf(("Bias %x", lpTimeZone->Bias)); 276 dprintf(("StandardName %ls", lpTimeZone->StandardName)); 277 dprintf(("StandardBias %x", lpTimeZone->StandardBias)); 278 dprintf(("StandardDate %d-%d-%d-%d", lpTimeZone->StandardDate.wYear, lpTimeZone->StandardDate.wMonth, lpTimeZone->StandardDate.wDay, lpTimeZone->StandardDate.wDayOfWeek)); 279 dprintf(("DaylightName %ls", lpTimeZone->DaylightName)); 280 dprintf(("DaylightBias %x", lpTimeZone->DaylightBias)); 281 dprintf(("DaylightDate %d-%d-%d-%d\n", lpTimeZone->DaylightDate.wYear, lpTimeZone->DaylightDate.wMonth, lpTimeZone->DaylightDate.wDay, lpTimeZone->DaylightDate.wDayOfWeek)); 264 282 return ret; 265 283 } … … 312 330 * Author : Patrick Haller [Mon, 1998/06/15 08:00] 313 331 *****************************************************************************/ 314 315 332 VOID WIN32API GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime) 316 333 { 334 /* 335 * Speculative time caching. 336 * We assume GetSystemTime is using DosGetDateTime. 337 * We assume DosGetDateTime uses the global info segment. 338 * We assume that SIS_MsCount is updated when the rest of the date/time 339 * members of the global info segment is updated. 340 * 341 * Possible sideffects: 342 * - The code doens't take in account changes of timezone, and hence will 343 * be wrong until the next timer tick. This isn't a problem I think. 344 * - 345 */ 346 #if 1 347 static FILETIME LastFileTime; 348 static ULONG LastMsCount = -1; 349 if (fibGetMsCount() == LastMsCount) { 350 *lpSystemTimeAsFileTime = LastFileTime; 351 } 352 else 353 { 354 SYSTEMTIME st; 355 ULONG ulNewMsCount = fibGetMsCount(); 356 GetSystemTime(&st); 357 SystemTimeToFileTime(&st, lpSystemTimeAsFileTime); 358 LastFileTime = *lpSystemTimeAsFileTime; 359 LastMsCount = ulNewMsCount; 360 } 361 dprintf2(("Time %08x%08x", lpSystemTimeAsFileTime->dwHighDateTime, lpSystemTimeAsFileTime->dwLowDateTime)); 362 #else 317 363 SYSTEMTIME st; 318 319 364 GetSystemTime(&st); 320 365 SystemTimeToFileTime(&st, lpSystemTimeAsFileTime); 321 } 322 //****************************************************************************** 323 //****************************************************************************** 324 325 366 dprintf2(("Time %08x%08x", lpSystemTimeAsFileTime->dwHighDateTime, lpSystemTimeAsFileTime->dwLowDateTime)); 367 #endif 368 } 369 //****************************************************************************** 370 //****************************************************************************** 371 372 -
trunk/src/kernel32/virtual.cpp
r9971 r21302 7 7 * Copyright 1998 Knut St. Osmundsen 8 8 * Copyright 1998 Peter FitzSimmons 9 * Copyright 2002-2003 Innotek Systemberatung GmbH (sandervl@innotek.de) 9 10 * 10 11 * Parts (VIRTUAL_MapFileA/W) based on Wine code (memory\virtual.c): … … 267 268 return hMapping; 268 269 } 269 270 //****************************************************************************** 270 //****************************************************************************** 271 // Translate OS2 page attributes to Windows attribute, state and type values 272 //****************************************************************************** 273 void TranslateOS2PageAttr(DWORD os2attr, DWORD *lpdwWinProtect, DWORD *lpdwWinState, 274 DWORD *lpdwWinType) 275 { 276 DWORD State, Type; 277 278 if(!lpdwWinState) lpdwWinState = &State; 279 if(!lpdwWinType) lpdwWinType = &Type; 280 281 *lpdwWinProtect = 0; 282 *lpdwWinState = 0; 283 *lpdwWinType = 0; 284 285 if(os2attr & PAG_READ && !(os2attr & PAG_WRITE)) 286 *lpdwWinProtect |= PAGE_READONLY; 287 else 288 if(os2attr & PAG_WRITE) 289 *lpdwWinProtect |= PAGE_READWRITE; 290 291 if((os2attr & (PAG_WRITE | PAG_EXECUTE)) == (PAG_WRITE | PAG_EXECUTE)) 292 *lpdwWinProtect |= PAGE_EXECUTE_READWRITE; 293 else 294 if(os2attr & PAG_EXECUTE) 295 *lpdwWinProtect |= PAGE_EXECUTE_READ; 296 297 if(os2attr & PAG_GUARD) 298 *lpdwWinProtect |= PAGE_GUARD; 299 300 if(os2attr & PAG_FREE) 301 *lpdwWinState = MEM_FREE; 302 else 303 if(os2attr & PAG_COMMIT) 304 *lpdwWinState = MEM_COMMIT; 305 else 306 *lpdwWinState = MEM_RESERVE; 307 308 //TODO: MEM_MAPPED & MEM_IMAGE (==SEC_IMAGE) 309 if(!(os2attr & PAG_SHARED)) 310 *lpdwWinType = MEM_PRIVATE; 311 312 // Pages can be committed but not necessarily accessible!! 313 if (!(os2attr & (PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_GUARD))) 314 *lpdwWinProtect = PAGE_NOACCESS; 315 316 } 317 //****************************************************************************** 318 // Translate Windows page attributes to OS/2 page attributes 319 //****************************************************************************** 320 void TranslateWinPageAttr(DWORD dwProtect, DWORD *lpdwOS2Attr) 321 { 322 *lpdwOS2Attr = 0; 323 324 if(dwProtect & PAGE_READONLY) *lpdwOS2Attr |= PAG_READ; 325 if(dwProtect & PAGE_READWRITE) *lpdwOS2Attr |= (PAG_READ | PAG_WRITE); 326 if(dwProtect & PAGE_WRITECOPY) *lpdwOS2Attr |= (PAG_READ | PAG_WRITE); 327 328 if(dwProtect & PAGE_EXECUTE) *lpdwOS2Attr |= (PAG_EXECUTE | PAG_READ); 329 if(dwProtect & PAGE_EXECUTE_READ) *lpdwOS2Attr |= (PAG_EXECUTE | PAG_READ); 330 if(dwProtect & PAGE_EXECUTE_READWRITE) 331 *lpdwOS2Attr |= (PAG_EXECUTE | PAG_WRITE | PAG_READ); 332 if(dwProtect & PAGE_EXECUTE_WRITECOPY) 333 *lpdwOS2Attr |= (PAG_EXECUTE | PAG_WRITE | PAG_READ); 334 335 if(dwProtect & PAGE_GUARD) { 336 dprintf(("WARNING: PAGE_GUARD bit set for VirtualAlloc -> we don't support this right now!")); 337 *lpdwOS2Attr |= PAG_GUARD; 338 } 339 if(dwProtect & PAGE_NOACCESS) *lpdwOS2Attr |= PAG_READ; //can't do this in OS/2 340 } 341 //****************************************************************************** 342 //NOTE: Do NOT set the last error to ERROR_SUCCESS if successful. Windows 343 // does not do this either! 271 344 //****************************************************************************** 272 345 LPVOID WIN32API VirtualAlloc(LPVOID lpvAddress, … … 280 353 DWORD rc; 281 354 282 SetLastError(ERROR_SUCCESS);283 284 355 if (cbSize > 0x7fc00000) /* 2Gb - 4Mb */ 285 356 { … … 289 360 } 290 361 362 // We're ignoring MEM_TOP_DOWN for now 291 363 if (!(fdwAllocationType & (MEM_COMMIT | MEM_RESERVE)) || 292 (fdwAllocationType & ~(MEM_COMMIT | MEM_RESERVE )))364 (fdwAllocationType & ~(MEM_COMMIT | MEM_RESERVE | MEM_TOP_DOWN))) 293 365 { 294 366 dprintf(("VirtualAlloc: Invalid parameter")); … … 308 380 cbSize += PAGE_SIZE; 309 381 382 //Translate windows page attributes (flag is reset to 0!!) 383 TranslateWinPageAttr(fdwProtect, &flag); 384 310 385 if(fdwAllocationType & MEM_COMMIT) 311 386 { 312 387 dprintf(("VirtualAlloc: commit\n")); 313 flag = PAG_COMMIT;388 flag |= PAG_COMMIT; 314 389 } 315 390 … … 322 397 // it will have the old (alloc time) attributes 323 398 flag |= PAG_READ|PAG_WRITE; 324 }325 if(fdwProtect & PAGE_READONLY) flag |= PAG_READ;326 if(fdwProtect & PAGE_NOACCESS) flag |= PAG_READ; //can't do this in OS/2327 if(fdwProtect & PAGE_READWRITE) flag |= (PAG_READ | PAG_WRITE);328 if(fdwProtect & PAGE_WRITECOPY) flag |= (PAG_READ | PAG_WRITE);329 330 if(fdwProtect & PAGE_EXECUTE_READWRITE) flag |= (PAG_EXECUTE | PAG_WRITE | PAG_READ);331 if(fdwProtect & PAGE_EXECUTE_READ) flag |= (PAG_EXECUTE | PAG_READ);332 if(fdwProtect & PAGE_EXECUTE) flag |= PAG_EXECUTE;333 334 if(fdwProtect & PAGE_GUARD) {335 dprintf(("WARNING: PAGE_GUARD bit set for VirtualAlloc -> we don't support this right now!"));336 flag |= PAG_GUARD;337 399 } 338 400 … … 470 532 471 533 dprintf(("VirtualAlloc returned %X\n", Address)); 472 SetLastError(ERROR_SUCCESS);473 534 return(Address); 474 535 } 475 536 //****************************************************************************** 537 //NOTE: Do NOT set the last error to ERROR_SUCCESS if successful. Windows 538 // does not do this either! 476 539 //****************************************************************************** 477 540 BOOL WIN32API VirtualFree(LPVOID lpvAddress, … … 481 544 DWORD rc; 482 545 483 SetLastError(ERROR_SUCCESS);484 485 546 // verify parameters 486 547 if((FreeType & MEM_RELEASE) && (cbSize != 0)) … … 496 557 SetLastError(ERROR_INVALID_PARAMETER); 497 558 return(FALSE); 559 } 560 561 /* Assuming that we don't allocate memory in the first 64kb. */ 562 if ((unsigned)lpvAddress < 0x10000) 563 { 564 if (!lpvAddress) 565 dprintf(("WARNING: VirtualFree: bogus address %p!!", lpvAddress)); 566 SetLastError(ERROR_INVALID_ADDRESS); 567 return FALSE; 498 568 } 499 569 … … 579 649 } 580 650 dprintf(("Old memory flags %X\n", pageFlags)); 581 *pfdwOldProtect = 0; 582 if(pageFlags & PAG_READ && !(pageFlags & PAG_WRITE)) 583 *pfdwOldProtect |= PAGE_READONLY; 584 if(pageFlags & (PAG_WRITE)) 585 *pfdwOldProtect |= PAGE_READWRITE; 586 587 if((pageFlags & (PAG_WRITE | PAG_EXECUTE)) == (PAG_WRITE | PAG_EXECUTE)) 588 *pfdwOldProtect |= PAGE_EXECUTE_READWRITE; 589 else 590 if(pageFlags & PAG_EXECUTE) 591 *pfdwOldProtect |= PAGE_EXECUTE_READ; 592 593 if(pageFlags & PAG_GUARD) 594 *pfdwOldProtect |= PAGE_GUARD; 595 pageFlags = 0; 596 597 if(fdwNewProtect & PAGE_READONLY) pageFlags |= PAG_READ; 598 if(fdwNewProtect & PAGE_READWRITE) pageFlags |= (PAG_READ | PAG_WRITE); 599 if(fdwNewProtect & PAGE_WRITECOPY) pageFlags |= (PAG_READ | PAG_WRITE); 600 if(fdwNewProtect & PAGE_EXECUTE_READ) pageFlags |= (PAG_EXECUTE | PAG_READ); 601 if(fdwNewProtect & PAGE_EXECUTE_READWRITE) 602 pageFlags |= (PAG_EXECUTE | PAG_WRITE | PAG_READ); 603 if(fdwNewProtect & PAGE_EXECUTE_WRITECOPY) 604 pageFlags |= (PAG_EXECUTE | PAG_WRITE | PAG_READ); 605 if(fdwNewProtect & PAGE_GUARD) pageFlags |= PAG_GUARD; 606 //Not supported in OS/2?? 607 // if(fdwNewProtect & PAGE_NOACCESS) 651 TranslateOS2PageAttr(pageFlags, pfdwOldProtect, NULL, NULL); 652 653 TranslateWinPageAttr(fdwNewProtect, &pageFlags); 608 654 609 655 dprintf(("New memory flags %X\n", pageFlags)); … … 658 704 659 705 rc = OSLibDosQueryMem(lpBase, &cbRangeSize, &dAttr); 706 if(rc==487) 707 { 708 dprintf(("VirtualQuery - OSLibDosQueryMem %x %x returned %d, REMOVING ERROR!\n", 709 lpBase, cbLength, rc)); 710 SetLastError(0); 711 return 0; 712 } 660 713 if(rc) 661 714 { … … 672 725 pmbiBuffer->RegionSize = (cbRangeSize + 0xFFF) & 0xFFFFF000; 673 726 674 if(dAttr & PAG_READ && !(dAttr & PAG_WRITE)) 675 pmbiBuffer->Protect |= PAGE_READONLY; 676 677 if(dAttr & PAG_WRITE) 678 pmbiBuffer->Protect |= PAGE_READWRITE; 679 680 if((dAttr & (PAG_WRITE | PAG_EXECUTE)) == (PAG_WRITE | PAG_EXECUTE)) 681 pmbiBuffer->Protect |= PAGE_EXECUTE_READWRITE; 682 else 683 if(dAttr & PAG_EXECUTE) 684 pmbiBuffer->Protect |= PAGE_EXECUTE_READ; 685 686 if(dAttr & PAG_GUARD) 687 pmbiBuffer->Protect |= PAGE_GUARD; 688 689 if(dAttr & PAG_FREE) 690 pmbiBuffer->State = MEM_FREE; 691 else 692 if(dAttr & PAG_COMMIT) 693 pmbiBuffer->State = MEM_COMMIT; 694 else 695 pmbiBuffer->State = MEM_RESERVE; 696 697 //TODO: MEM_MAPPED & MEM_IMAGE (==SEC_IMAGE) 698 if(!(dAttr & PAG_SHARED)) 699 pmbiBuffer->Type = MEM_PRIVATE; 700 701 // Pages can be committed but not necessarily accessible!! 702 if (!(dAttr & (PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_GUARD))) 703 pmbiBuffer->Protect = PAGE_NOACCESS; 727 TranslateOS2PageAttr(dAttr, &pmbiBuffer->Protect, &pmbiBuffer->State, &pmbiBuffer->Type); 704 728 705 729 //TODO: This is not correct: AllocationProtect should contain the protection 706 730 // flags used in the initial call to VirtualAlloc 707 731 pmbiBuffer->AllocationProtect = pmbiBuffer->Protect; 708 pmbiBuffer->AllocationBase = OSLibDosFindMemBase(lpBase); 709 732 pmbiBuffer->AllocationBase = OSLibDosFindMemBase(lpBase, &dAttr); 733 if(dAttr) { 734 TranslateOS2PageAttr(dAttr, &pmbiBuffer->AllocationProtect, NULL, NULL); 735 } 710 736 dprintf(("Memory region alloc base 0x%08x", pmbiBuffer->AllocationBase)); 711 737 dprintf(("Memory region alloc protect flags %x", pmbiBuffer->AllocationProtect)); … … 725 751 return TRUE; 726 752 } 727 753 //****************************************************************************** 728 754 //****************************************************************************** 729 755 BOOL WIN32API VirtualUnlock(LPVOID lpAddress, DWORD dwSize) … … 802 828 803 829 //****************************************************************************** 804 // SvL: Privateapi830 // Private Odin api 805 831 //****************************************************************************** 806 832 LPVOID VirtualAllocShared(DWORD cbSize, DWORD fdwAllocationType, … … 828 854 } 829 855 856 //Translate windows page attributes (flag is reset to 0!!) 857 TranslateWinPageAttr(fdwProtect, &flag); 858 830 859 if(fdwAllocationType & MEM_COMMIT) 831 860 { 832 861 dprintf(("VirtualAllocShared: commit\n")); 833 flag = PAG_COMMIT; 834 } 835 836 if(fdwProtect & PAGE_READONLY) flag |= PAG_READ; 837 if(fdwProtect & PAGE_NOACCESS) flag |= PAG_READ; //can't do this in OS/2 838 if(fdwProtect & PAGE_READWRITE) flag |= (PAG_READ | PAG_WRITE); 839 if(fdwProtect & PAGE_WRITECOPY) flag |= (PAG_READ | PAG_WRITE); 840 841 if(fdwProtect & PAGE_EXECUTE_READWRITE) flag |= (PAG_EXECUTE | PAG_WRITE | PAG_READ); 842 if(fdwProtect & PAGE_EXECUTE_READ) flag |= (PAG_EXECUTE | PAG_READ); 843 if(fdwProtect & PAGE_EXECUTE) flag |= PAG_EXECUTE; 844 845 if(fdwProtect & PAGE_GUARD) { 846 dprintf(("ERROR: PAGE_GUARD bit set for VirtualAllocShared -> we don't support this right now!")); 847 flag |= PAG_GUARD; 862 flag |= PAG_COMMIT; 848 863 } 849 864 … … 867 882 return(Address); 868 883 } 884 //****************************************************************************** 885 //****************************************************************************** -
trunk/src/kernel32/windllbase.cpp
r10590 r21302 708 708 PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "CRTDLL32", "CRTDLL"); 709 709 } 710 if(PROFILE_GetOdinIniString(DLLRENAMEWIN_SECTION, "IMM32", "", renameddll,711 sizeof(renameddll)-1) <= 1)712 {713 PROFILE_SetOdinIniString(DLLRENAMEWIN_SECTION, "IMM32", "IMM32OS2");714 PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "IMM32OS2", "IMM32");715 }716 710 } 717 711 //****************************************************************************** -
trunk/src/kernel32/winexedummy.cpp
r10397 r21302 34 34 BOOL WIN32API RegisterDummyExe(LPSTR pszExeName) 35 35 { 36 if(WinExe != NULL) //should never happen37 delete(WinExe);36 if(WinExe != NULL) 37 return TRUE; 38 38 39 39 Win32DummyExe *winexe; -
trunk/src/kernel32/wprocess.cpp
r10481 r21302 67 67 ODINDEBUGCHANNEL(KERNEL32-WPROCESS) 68 68 69 70 //environ.cpp 71 char *CreateNewEnvironment(char *lpEnvironment); 69 72 70 73 /******************************************************************************* … … 1906 1909 STARTUPINFOA startinfo; 1907 1910 TEB *pThreadDB = (TEB*)GetThreadTEB(); 1908 char *cmdline = NULL, *newenv = NULL ;1911 char *cmdline = NULL, *newenv = NULL, *oldlibpath = NULL; 1909 1912 BOOL rc; 1910 1913 … … 1939 1942 1940 1943 memcpy(&startinfo, lpStartupInfo, sizeof(startinfo)); 1944 if(lpStartupInfo->hStdInput) { 1941 1945 retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdInput, &startinfo.hStdInput); 1946 } 1947 if(lpStartupInfo->hStdOutput) { 1942 1948 retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdOutput, &startinfo.hStdOutput); 1949 } 1950 if(lpStartupInfo->hStdError) { 1943 1951 retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdError, &startinfo.hStdError); 1952 } 1944 1953 1945 1954 if(retcode) { … … 2019 2028 break; 2020 2029 } 2021 2030 else 2031 {//maybe it's a short name 2032 if(GetLongPathNameA(buffer, szAppName, sizeof(szAppName))) 2033 { 2034 if(fTerminate) exename++; 2035 break; 2036 } 2037 } 2022 2038 if(fTerminate) { 2023 2039 *exename = ' '; … … 2039 2055 } 2040 2056 2057 if(lpEnvironment) { 2058 newenv = CreateNewEnvironment((char *)lpEnvironment); 2059 if(newenv == NULL) { 2060 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 2061 rc = FALSE; 2062 goto finished; 2063 } 2064 lpEnvironment = newenv; 2065 } 2066 2041 2067 DWORD Characteristics, SubSystem, fNEExe, fPEExe; 2042 2068 … … 2050 2076 if(!fPEExe || (fPEExe && fWin32k)) 2051 2077 { 2078 2079 trylaunchagain: 2052 2080 if(O32_CreateProcess(szAppName, lpCommandLine, lpProcessAttributes, 2053 2081 lpThreadAttributes, bInheritHandles, dwCreationFlags, … … 2078 2106 goto finished; 2079 2107 } 2080 2108 else 2109 if(!oldlibpath) 2110 {//might have failed because it wants to load dlls in its current directory 2111 // Add the application directory to the ENDLIBPATH, so dlls can be found there 2112 // Only necessary for OS/2 applications 2113 oldlibpath = (char *)calloc(4096, 1); 2114 if(oldlibpath) 2115 { 2116 OSLibQueryBeginLibpath(oldlibpath, 4096); 2117 2118 char *tmp = strrchr(szAppName, '\\'); 2119 if(tmp) *tmp = 0; 2120 2121 OSLibSetBeginLibpath(szAppName); 2122 if(tmp) *tmp = '\\'; 2123 2124 goto trylaunchagain; 2125 } 2126 2127 } 2081 2128 // verify why O32_CreateProcess actually failed. 2082 2129 // If GetLastError() == 191 (ERROR_INVALID_EXE_SIGNATURE) … … 2102 2149 if(fPEExe) 2103 2150 { 2104 char *lpszPE; 2105 char *lpszExecutable; 2151 LPCSTR lpszExecutable; 2106 2152 int iNewCommandLineLength; 2107 2153 … … 2110 2156 2111 2157 if(SubSystem == IMAGE_SUBSYSTEM_WINDOWS_CUI) 2112 lpszExecutable = (LPSTR)szPECmdLoader;2158 lpszExecutable = szPECmdLoader; 2113 2159 else 2114 lpszExecutable = (LPSTR)szPEGUILoader; 2115 2116 lpszPE = lpszExecutable; 2160 lpszExecutable = szPEGUILoader; 2117 2161 2118 2162 // 2002-04-24 PH 2119 2163 // set the ODIN32.DEBUG_CHILD environment variable to start new PE processes 2120 2164 // under a new instance of the (IPMD) debugger. 2165 const char *pszDebugChildArg = ""; 2121 2166 #ifdef DEBUG 2122 CHAR debug_szPE[ 512];2123 PSZ debug_pszOS2Debugger= getenv("ODIN32.DEBUG_CHILD");2124 if ( NULL != debug_pszOS2Debugger)2167 char szDebugChild[512]; 2168 const char *pszChildDebugger = getenv("ODIN32.DEBUG_CHILD"); 2169 if (pszChildDebugger) 2125 2170 { 2126 // build new start command 2127 strcpy(debug_szPE, debug_pszOS2Debugger); 2128 strcat(debug_szPE, " "); 2129 strcat(debug_szPE, lpszExecutable); 2130 2131 // we require more space in the new command line 2132 iNewCommandLineLength += strlen( debug_szPE ); 2133 2134 // only launch the specified executable (ICSDEBUG.EXE) 2135 lpszPE = debug_szPE; 2136 lpszExecutable = debug_pszOS2Debugger; 2171 /* 2172 * Change the executable to the debugger (icsdebug.exe) and 2173 * move the previous executable onto the commandline. 2174 */ 2175 szDebugChild[0] = ' '; 2176 strcpy(&szDebugChild[1], lpszExecutable); 2177 iNewCommandLineLength += strlen(&szDebugChild[0]); 2178 2179 pszDebugChildArg = &szDebugChild[0]; 2180 lpszExecutable = pszChildDebugger; 2137 2181 } 2138 2182 #endif … … 2144 2188 2145 2189 newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + iNewCommandLineLength + 64); 2146 sprintf(newcmdline, " /OPT:[CURDIR=%s] %s %s", lpCurrentDirectory, szAppName, lpCommandLine);2190 sprintf(newcmdline, "%s /OPT:[CURDIR=%s] %s %s", pszDebugChildArg, lpCurrentDirectory, szAppName, lpCommandLine); 2147 2191 free(cmdline); 2148 2192 cmdline = newcmdline; … … 2152 2196 2153 2197 newcmdline = (char *)malloc(iNewCommandLineLength + 16); 2154 sprintf(newcmdline, " %s %s", szAppName, lpCommandLine);2198 sprintf(newcmdline, "%s %s %s", pszDebugChildArg, szAppName, lpCommandLine); 2155 2199 free(cmdline); 2156 2200 cmdline = newcmdline; … … 2192 2236 lpProcessInfo); 2193 2237 } 2238 if(!lpEnvironment) { 2239 // Restore old ENDLIBPATH variable 2240 // TODO: 2241 } 2242 2194 2243 if(rc == TRUE) 2195 2244 { … … 2222 2271 finished: 2223 2272 2273 if(oldlibpath) { 2274 OSLibSetBeginLibpath(oldlibpath); 2275 free(oldlibpath); 2276 } 2224 2277 if(cmdline) free(cmdline); 2225 2278 if(newenv) free(newenv);
Note:
See TracChangeset
for help on using the changeset viewer.
