Changeset 21302 for trunk/src/kernel32


Ignore:
Timestamp:
Jun 18, 2009, 11:53:26 AM (16 years ago)
Author:
ydario
Message:

Kernel32 updates.

Location:
trunk/src/kernel32
Files:
2 added
58 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/Fileio.cpp

    r9892 r21302  
    253253{   
    254254  HANDLE hFind;
    255   char  *filename;
    256   int    namelen;
    257255
    258256    if(lpFileName == NULL || lpFindFileData == NULL || lpSearchFilter != NULL)
     
    285283    {
    286284    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\'
    287291        namelen = strlen(lpFileName);
    288         if(lpFileName[namelen-1] == '\\')
     292        if(namelen == 3 && lpFileName[1] == ':' && lpFileName[2] == '\\')
    289293        {
    290294            filename = (char *)alloca(namelen+1);
     
    296300 
    297301        return (HANDLE)OSLibDosFindFirst(filename, (WIN32_FIND_DATAA *)lpFindFileData);
     302    }
    298303
    299304    default: //should never happen
     
    445450//******************************************************************************
    446451//******************************************************************************
    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 //******************************************************************************
    476452INT WIN32API CompareFileTime(FILETIME * lpft1, FILETIME * lpft2)
    477453{
     
    497473//******************************************************************************
    498474//******************************************************************************
    499 BOOL WIN32API GetFileTime(HANDLE hFile, LPFILETIME arg2, LPFILETIME arg3, LPFILETIME arg4)
    500 {
    501     return HMGetFileTime(hFile, arg2, arg3, arg4);
    502 }
    503 //******************************************************************************
    504 //******************************************************************************
    505475BOOL WIN32API CopyFileA(LPCSTR arg1, LPCSTR arg2, BOOL arg3)
    506476{
     477    dprintf(("CopyFileA %s %s %d", arg1, arg2, arg3));
    507478  return OSLibDosCopyFile(arg1, arg2, arg3);
    508479}
     
    622593//******************************************************************************
    623594//******************************************************************************
    624 DWORD WIN32API GetFileSize(HANDLE arg1, PDWORD arg2)
    625 {
    626   return HMGetFileSize(arg1,
    627                        arg2);
    628 }
    629 //******************************************************************************
    630 //******************************************************************************
    631595BOOL WIN32API DeleteFileA(LPCSTR lpszFile)
    632596{
     
    678642{
    679643    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;
    681647}
    682648//******************************************************************************
     
    812778//******************************************************************************
    813779//******************************************************************************
    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 //******************************************************************************
    824780DWORD WIN32API GetFileAttributesA(LPCSTR lpszFileName)
    825781{
    826782    DWORD rc, error;
    827783
     784    //Disable error popus.
     785    ULONG oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
     786
    828787    rc = OSLibGetFileAttributes((LPSTR)lpszFileName);
     788
     789    SetErrorMode(oldmode);
    829790
    830791    //SvL: Open32 returns FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_NORMAL for
     
    855816
    856817  astring = UnicodeToAsciiString((LPWSTR)arg1);
     818  dprintf(("GetFileAttributesW %s", astring));
    857819  rc = GetFileAttributesA(astring);
    858820  FreeAsciiString(astring);
     
    919881           asciibuffer, asciipart));
    920882
    921   if(rc && asciibuffer)
     883  if(rc>0 && rc<nBufferLength && asciibuffer)
    922884    AsciiToUnicode(asciibuffer,
    923885                   lpBuffer);
     
    933895  if(asciibuffer) free(asciibuffer);
    934896  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 LockFileEx
    952  * 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 lock
    954  *             DWORD  dwFlags                   functional behavior modification flags
    955  *             DWORD  dwReserved                reserved, must be set to zero
    956  *             DWORD  nNumberOfBytesToLockLow   low-order 32 bits of length to lock
    957  *             DWORD  nNumberOfBytesToLockHigh  high-order 32 bits of length to lock
    958  *             LPOVERLAPPED  LPOVERLAPPED       addr. of structure with lock region start offset
    959  * Variables :
    960  * Result    : TRUE / FALSE
    961  * Remark    :
    962  * Status    : UNTESTED STUB
    963  *
    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));
    977897}
    978898//******************************************************************************
     
    11041024 
    11051025  return(rc);
    1106 }
    1107 //******************************************************************************
    1108 /*****************************************************************************
    1109 ODINFUNCTION3(*, :,
    1110               HFILE, WIN32API,
    1111               OpenFile *, Purpose,
    1112               :, forwardOpenFile to Open32
    1113  * Parameters:
    1114  * Variables :
    1115  * Result    : API returncode
    1116  * Remark    : modified for handle translation support
    1117  * 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 UnlockFileEx
    1153  * Purpose   : The UnlockFileEx function unlocks a previously locked byte range in an open file.
    1154  * Parameters: HANDLE hFile                     handle of file to lock
    1155  *             DWORD  dwReserved                reserved, must be set to zero
    1156  *             DWORD  nNumberOfBytesToLockLow   low-order 32 bits of length to lock
    1157  *             DWORD  nNumberOfBytesToLockHigh  high-order 32 bits of length to lock
    1158  *             LPOVERLAPPED  LPOVERLAPPED       addr. of structure with lock region start offset
    1159  * Variables :
    1160  * Result    : TRUE / FALSE
    1161  * Remark    :
    1162  * Status    : UNTESTED STUB
    1163  *
    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));
    11761026}
    11771027//******************************************************************************
     
    16751525    return hChange;
    16761526}
    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 CancelIo
    1689  * Purpose   : The CancelIO function cancels all pending input and output
    1690  *             (I/O) operations that were issued by the calling thread for
    1691  *             the specified file handle. The function does not cancel
    1692  *             I/O operations issued for the file handle by other threads.
    1693  * Parameters: HANDLE hFile   file handle for which to cancel I/O
    1694  * Variables :
    1695  * Result    : If the function succeeds, the return value is nonzero All pending
    1696  *             I/O operations issued by the calling thread for the file handle
    1697  *             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 specified
    1701  *             file HANDLE and they were issued by the calling thread, the
    1702  *             CancelIO function cancels them.
    1703  *             Note that the I/O operations must have been issued as
    1704  *             overlapped I/O. If they were not, the I/O operations would not
    1705  *             have returned to allow the thread to call the CancelIO function.
    1706  *             Calling the CancelIO function with a file handle that was not
    1707  *             opened with FILE_FLAG_OVERLAPPED does nothing.
    1708  *             All I/O operations that are canceled will complete with the
    1709  *             error ERROR_OPERATION_ABORTED. All completion notifications
    1710  *             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 }
    17191527/*****************************************************************************
    17201528 * Name      : BOOL GetOverlappedResult
  • trunk/src/kernel32/HandleManager.cpp

    r10132 r21302  
    4545#include <string.h>
    4646
    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>
    5151#include "handlenames.h"
    5252#include "HMDevice.h"
     
    6767#include "HMMailslot.h"
    6868
     69#include "hmhandle.h"
     70
    6971#include <vmutex.h>
    7072#include <win\thread.h>
    7173
     74#include <odinapi.h>
     75
     76#include <_ras.h>
     77
    7278#define DBG_LOCALLOG  DBG_handlemanager
    7379#include "dbglocal.h"
     
    7783 *****************************************************************************/
    7884
    79                     /* this is the size of our currently static handle table */
    80 #define MAX_OS2_HMHANDLES 4096
     85// this is the size of our currently static handle table
     86#define MAX_OS2_HMHANDLES       (4*1024)
    8187
    8288
     
    8490 * Structures                                                                *
    8591 *****************************************************************************/
    86 
    87 typedef struct _HMHANDLE
    88 {
    89   HMDeviceHandler *pDeviceHandler;         /* handler for this pseudo-device */
    90   HMHANDLEDATA    hmHandleData;                  /* attributes of the handle */
    91 } HMHANDLE, *PHMHANDLE;
    9292
    9393
     
    120120            /* the device name is repeated here to enable device alias names */
    121121static PHMDEVICE TabWin32Devices = NULL;
    122 
     122static int       lastIndex       = 1;
    123123static HMHANDLE *TabWin32Handles = NULL;   /* static handle table */
    124124VMutex           handleMutex;
     
    154154
    155155
     156#ifdef RAS
     157
     158RAS_TRACK_HANDLE rthHandles = 0;
     159
     160ULONG 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
    156173/*****************************************************************************
    157174 * Local Prototypes                                                          *
     
    254271  handleMutex.enter();
    255272
    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++)
    261279  {
    262280                                                       /* 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));
    266285        TabWin32Handles[ulLoop].hmHandleData.hHMHandle      = ulLoop;
    267         TabWin32Handles[ulLoop].hmHandleData.dwUserData     = 0;
    268286        TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN;
    269287        TabWin32Handles[ulLoop].hmHandleData.hWin32Handle   = (HANDLE)ulLoop;
    270         TabWin32Handles[ulLoop].hmHandleData.lpDeviceData   = NULL;
    271         TabWin32Handles[ulLoop].hmHandleData.dwHandleInformation = 0;
     288        lastIndex = ulLoop+1;
    272289        handleMutex.leave();
     290        RasAddObject (rthHandles, ulLoop, NULL, 0);
    273291        return (ulLoop);                    /* OK, then return it to the caller */
    274292    }
     
    276294
    277295  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
    278301  return (INVALID_HANDLE_VALUE);             /* haven't found any free handle */
    279302}
    280303
     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 *****************************************************************************/
     315PHMHANDLE 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}
    281371
    282372/*****************************************************************************
     
    293383DWORD HMHandleGetUserData(ULONG  hHandle)
    294384{
    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    }
    297399                                                   /* Oops, invalid handle ! */
    298400  if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle)
    299     return (-1);              /* nope, ERROR_INVALID_HANDLE */
     401        return(-1);              /* nope, ERROR_INVALID_HANDLE */
    300402
    301403  return TabWin32Handles[hHandle].hmHandleData.dwUserData;
     
    315417DWORD HMHandleSetUserData(ULONG  hHandle, ULONG dwUserData)
    316418{
    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
    319434                                                   /* Oops, invalid handle ! */
    320435  if (INVALID_HANDLE_VALUE == TabWin32Handles[hHandle].hmHandleData.hHMHandle)
    321     return (-1);              /* nope, ERROR_INVALID_HANDLE */
     436        return(-1);              /* nope, ERROR_INVALID_HANDLE */
    322437
    323438  TabWin32Handles[hHandle].hmHandleData.dwUserData = dwUserData;
     
    341456static ULONG INLINE _HMHandleQuery(HANDLE hHandle)
    342457{
    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    }
    345472
    346473                                                   /* Oops, invalid handle ! */
    347474  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
     493PHMHANDLE 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 */
    351519}
    352520
     
    421589  if (HMGlobals.fIsInitialized != TRUE)
    422590  {
     591 
     592#ifdef RAS 
     593    RasRegisterObjectTracking(&rthHandles, "KERNEL32 handles",
     594                              0, RAS_TRACK_FLAG_LOGOBJECTCONTENT,
     595                              LogObjectContent_Handle, NULL);
     596#endif
     597
    423598    handleMutex.enter();
    424599
    425     TabWin32Handles = (HMHANDLE *)malloc(MAX_OS2_HMHANDLES*sizeof(HMHANDLE));
     600    TabWin32Handles = (HMHANDLE *)VirtualAlloc(NULL, MAX_OS2_HMHANDLES*sizeof(HMHANDLE), MEM_COMMIT, PAGE_READWRITE);
    426601    if(TabWin32Handles == NULL) {
    427602        DebugInt3();
    428603        return ERROR_NOT_ENOUGH_MEMORY;
    429604    }
    430     memset(TabWin32Handles, 0, MAX_OS2_HMHANDLES*sizeof(HMHANDLE));
    431605
    432606    // fill handle table
     
    523697{
    524698  /* @@@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);
    525711
    526712  if(HMGlobals.pHMOpen32)
     
    617803
    618804        handleMutex.leave();
     805        RasAddObject (rthHandles, ulHandle, NULL, 0);
    619806        return (NO_ERROR);                                               /* OK */
    620807    }
     
    629816  handleMutex.leave();
    630817
     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
    631833  return (ERROR_TOO_MANY_OPEN_FILES);                      /* OK, we're done */
    632834}
     
    659861    return (rc);                                    /* raise error condition */
    660862
    661   TabWin32Handles[hHandle16].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     863  FREEHANDLE(hHandle16);
     864//  TabWin32Handles[hHandle16].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     865//  RasRemoveObjects(rthHandles, hHandle16);
    662866                                                                 /* OK, done */
    663867
     
    669873 * Name      : DWORD HMHandleValidate
    670874 * Purpose   : validate a handle through the translation table
    671  * Parameters: ULONG hHandle16 - the handle to be verified
     875 * Parameters: ULONG hHandle - the handle to be verified
    672876 * Variables :
    673877 * Result    : API returncode
     
    678882 *****************************************************************************/
    679883
    680 DWORD  HMHandleValidate (ULONG hHandle16)
     884DWORD  HMHandleValidate (ULONG hHandle)
    681885{
    682886#ifdef DEBUG_LOCAL
    683   dprintf(("KERNEL32: HMHandleValidate (%08xh)\n",
    684            hHandle16));
     887    dprintf(("KERNEL32: HMHandleValidate (%08xh)\n", hHandle));
    685888#endif
    686889
    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)
    691906                                                                  /* 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);
    695910}
    696911//*****************************************************************************
     
    9661181  pHMHandleData->dwFlags       = TabWin32Handles[srchandle].hmHandleData.dwFlags;
    9671182  pHMHandleData->lpHandlerData = TabWin32Handles[srchandle].hmHandleData.lpHandlerData;
     1183  pHMHandleData->dwInternalType = TabWin32Handles[srchandle].hmHandleData.dwInternalType;
    9681184
    9691185
     
    9801196                                       &TabWin32Handles[srchandle].hmHandleData,
    9811197                                       destprocess,
    982                                        desthandle,
    9831198                                       fdwAccess,
    9841199                                       fInherit,
     
    9911206  if(rc == FALSE)     /* oops, creation failed within the device handler */
    9921207  {
    993     TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1208//    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1209    FREEHANDLE(iIndexNew);
    9941210    return FALSE;                           /* signal error */
    9951211  }
     
    10731289
    10741290    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!"));
    10761295             pDeviceHandler = HMGlobals.pHMInfoFile;
    10771296        }
     
    10961315  else
    10971316  {
     1317    memset(&HMHandleTemp, 0, sizeof(HMHandleTemp));
    10981318    HMHandleTemp.dwAccess   = dwDesiredAccess;
    10991319    HMHandleTemp.dwShare    = dwShareMode;
    11001320    HMHandleTemp.dwCreation = dwCreationDisposition;
    11011321    HMHandleTemp.dwFlags    = dwFlagsAndAttributes;
    1102     HMHandleTemp.lpHandlerData = NULL;
    11031322    HMHandleTemp.hWin32Handle  = iIndexNew;
    11041323    HMHandleTemp.lpDeviceData  = pDevData;
    1105     HMHandleTemp.dwHandleInformation = 0;
    11061324  }
    11071325
     
    11301348  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
    11311349  {
    1132     TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1350    FREEHANDLE(iIndexNew);
     1351//    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    11331352
    11341353    // Note:
     
    11961415}
    11971416
    1198 HANDLE HMOpenFile(LPCSTR    lpFileName,
    1199                   OFSTRUCT* pOFStruct,
     1417HFILE WIN32API OpenFile(LPCSTR lpFileName, OFSTRUCT* pOFStruct,
    12001418                  UINT      fuMode)
    12011419{
     
    12071425  DWORD           rc;                                     /* API return code */
    12081426
     1427
     1428  dprintf(("KERNEL32: OpenFile(%s, %08xh, %08xh)\n",
     1429           lpFileName, pOFStruct, fuMode));
     1430
    12091431  // name resolving
    12101432  CHAR szFilename[260];
     
    12861508   */
    12871509  if (fuMode & OF_PARSE) {
    1288     TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1510    FREEHANDLE(iIndexNew);
     1511//    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    12891512    return 0;
    12901513  }
     
    12921515  if(rc != NO_ERROR)     /* oops, creation failed within the device handler */
    12931516  {
    1294       TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1517    FREEHANDLE(iIndexNew);
     1518//      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    12951519      SetLastError(pOFStruct->nErrCode);
    12961520      return (INVALID_HANDLE_VALUE);                           /* signal error */
     
    12991523      if(fuMode & (OF_DELETE|OF_EXIST)) {
    13001524          //file handle already closed
    1301           TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1525          FREEHANDLE(iIndexNew);
     1526//          TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    13021527          return TRUE; //TODO: correct?
    13031528      }
    13041529
    13051530      if(fuMode & OF_VERIFY) {
    1306           TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     1531          FREEHANDLE(iIndexNew);
     1532//          TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    13071533          return 1; //TODO: correct?
    13081534      }
     
    14931719
    14941720  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"));
    14961722      SetLastError(ERROR_SUCCESS);
    14971723      return TRUE;
     
    15111737  if (fResult == TRUE)                   /* remove handle if close succeeded */
    15121738  {
    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 */
    15141741    SetLastError(ERROR_SUCCESS); //@@@PH 1999/10/27 rc5desg requires this?
    15151742  }
     
    15911818  }
    15921819
     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
    15931830  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
    15941831  fResult = pHMHandle->pDeviceHandler->WriteFile(&pHMHandle->hmHandleData,
     
    16141851 *****************************************************************************/
    16151852
    1616 DWORD HMGetFileType(HANDLE hFile)
     1853DWORD WIN32API GetFileType(HANDLE hFile)
    16171854{
    16181855  int       iIndex;                           /* index into the handle table */
     
    16921929 *****************************************************************************/
    16931930
    1694 BOOL HMGetFileInformationByHandle (HANDLE                     hFile,
     1931BOOL WIN32API GetFileInformationByHandle (HANDLE                     hFile,
    16951932                                   BY_HANDLE_FILE_INFORMATION *pHFI)
    16961933{
     
    17271964 *****************************************************************************/
    17281965
    1729 BOOL HMSetEndOfFile (HANDLE hFile)
     1966BOOL WIN32API SetEndOfFile (HANDLE hFile)
    17301967{
    17311968  int       iIndex;                           /* index into the handle table */
     
    17601997 *****************************************************************************/
    17611998
    1762 BOOL HMSetFileTime (HANDLE         hFile,
     1999BOOL WIN32API SetFileTime (HANDLE         hFile,
    17632000                    const FILETIME *pFT1,
    17642001                    const FILETIME *pFT2,
     
    17982035 *****************************************************************************/
    17992036
    1800 BOOL HMGetFileTime (HANDLE         hFile,
    1801                     const FILETIME *pFT1,
    1802                     const FILETIME *pFT2,
    1803                     const FILETIME *pFT3)
     2037BOOL WIN32API GetFileTime (HANDLE hFile, FILETIME *pFT1,
     2038                           FILETIME *pFT2, FILETIME *pFT3)
    18042039{
    18052040  int       iIndex;                           /* index into the handle table */
     
    18372072 *****************************************************************************/
    18382073
    1839 DWORD HMGetFileSize (HANDLE hFile,
    1840                      PDWORD pSize)
     2074DWORD WIN32API GetFileSize (HANDLE hFile, PDWORD pSize)
    18412075{
    18422076  int       iIndex;                           /* index into the handle table */
     
    18722106 *****************************************************************************/
    18732107
    1874 DWORD HMSetFilePointer (HANDLE hFile,
     2108DWORD WIN32API SetFilePointer (HANDLE hFile,
    18752109                        LONG   lDistanceToMove,
    18762110                        PLONG  lpDistanceToMoveHigh,
     
    19112145 *****************************************************************************/
    19122146
    1913 BOOL HMLockFile (HFILE         hFile,
     2147BOOL WIN32API LockFile (HANDLE        hFile,
    19142148                 DWORD         arg2,
    19152149                 DWORD         arg3,
     
    19412175
    19422176/*****************************************************************************
    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
     2193BOOL WIN32API LockFileEx(HANDLE        hFile,
    19552194                  DWORD         dwFlags,
    19562195                  DWORD         dwReserved,
     
    19962235 *****************************************************************************/
    19972236
    1998 BOOL HMUnlockFile (HANDLE        hFile,
     2237BOOL WIN32API UnlockFile (HANDLE        hFile,
    19992238                   DWORD         arg2,
    20002239                   DWORD         arg3,
     
    20262265
    20272266/*****************************************************************************
    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
     2282BOOL WIN32API UnlockFileEx(HANDLE        hFile,
    20402283                    DWORD         dwReserved,
    20412284                    DWORD         nNumberOfBytesToLockLow,
     
    21552398       }
    21562399  }
    2157 
    2158   //If the timeout is less than 20 milliseconds (and not zero), then we are likely to
    2159   //return too late if the thread priority isn't time critical (time slices
    2160   //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 timeouts
    2173           if(dwTimeout > 8)
    2174               dwTimeout = (dwTimeout/8)*8;
    2175           fChangePriority = TRUE;
    2176       }
    2177   }
    2178 
    21792400  pHMHandle = &TabWin32Handles[iIndex];               /* call device handler */
    21802401  dwResult = pHMHandle->pDeviceHandler->WaitForSingleObject(&pHMHandle->hmHandleData,
    21812402                                                            dwTimeout);
    21822403
    2183   //Restore thread priority if we previously changed it
    2184   if(fChangePriority) {
    2185       SetThreadPriority(hThread, dwThreadPriority);
    2186   }
    21872404  return (dwResult);                                  /* deliver return code */
    21882405}
     
    22382455 *****************************************************************************/
    22392456
    2240 BOOL HMFlushFileBuffers(HANDLE hFile)
     2457BOOL WIN32API FlushFileBuffers(HANDLE hFile)
    22412458{
    22422459  int       iIndex;                           /* index into the handle table */
     
    23102527 *****************************************************************************/
    23112528
    2312 BOOL HMReleaseMutex(HANDLE hObject)
     2529BOOL WIN32API ReleaseMutex(HANDLE hObject)
    23132530{
    23142531  int       iIndex;                           /* index into the handle table */
     
    23312548
    23322549
    2333 /*****************************************************************************
    2334  * Name      : HMSetEvent
    2335  * Purpose   : router function for SetEvent
     2550
     2551
     2552/*****************************************************************************
     2553 * Name      : HANDLE  HMCreateMutex
     2554 * Purpose   : Wrapper for the CreateMutex() API
    23362555 * Parameters:
    23372556 * Variables :
     
    23402559 * Status    :
    23412560 *
    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      : HMPulseEvent
    2368  * Purpose   : router function for PulseEvent
    2369  * 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      : HMResetEvent
    2401  * Purpose   : router function for ResetEvent
    2402  * 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  HMCreateEvent
    2434  * Purpose   : Wrapper for the CreateEvent() API
    2435  * Parameters:
    2436  * Variables :
    2437  * Result    :
    2438  * Remark    :
    2439  * Status    :
    2440  *
    24412561 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    24422562 *****************************************************************************/
    24432563
    2444 HANDLE HMCreateEvent(LPSECURITY_ATTRIBUTES lpsa,
    2445                      BOOL                  bManualReset,
    2446                      BOOL                  bInitialState,
     2564HANDLE WIN32API CreateMutexA(LPSECURITY_ATTRIBUTES lpsa,
     2565                             BOOL                  bInitialOwner,
    24472566                     LPCTSTR               lpName)
    24482567{
     
    24542573
    24552574
    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
    24572578      //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);
    25352580      if(handle) {
    25362581          dprintf(("CreateMutex: return handle of existing mutex semaphore %x", handle));
     
    25572602  pHMHandleData->dwFlags    = 0;
    25582603  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 */
    25652611  TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew;
    25662612  TabWin32Handles[iIndexNew].pDeviceHandler         = pDeviceHandler;
    25672613
    2568                                                   /* call the device handler */
     2614  /* call the device handler */
    25692615  rc = pDeviceHandler->CreateMutex(&TabWin32Handles[iIndexNew].hmHandleData,
    25702616                                   lpsa,
     
    25732619  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
    25742620  {
    2575     TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     2621    FREEHANDLE(iIndexNew);
     2622//    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    25762623    SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
    25772624    return 0;                           /* signal error */
     
    25842631
    25852632
    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
    25892637 * Parameters:
    25902638 * Variables :
     
    25962644 *****************************************************************************/
    25972645
    2598 HANDLE HMOpenEvent(DWORD   fdwAccess,
    2599                    BOOL    fInherit,
    2600                    LPCTSTR lpName)
     2646HANDLE WIN32API OpenMutexA(DWORD   fdwAccess,
     2647                           BOOL    fInherit,
     2648                     LPCTSTR              lpName)
    26012649{
    26022650  int             iIndex;                     /* index into the handle table */
     
    26072655
    26082656
    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 */
    26102662
    26112663  iIndexNew = _HMHandleGetFree();                         /* get free handle */
     
    26242676  pHMHandleData->dwFlags    = 0;
    26252677  pHMHandleData->lpHandlerData = NULL;
     2678  pHMHandleData->dwInternalType = HMTYPE_MUTEXSEM;
    26262679
    26272680
     
    26342687
    26352688                                                  /* call the device handler */
    2636   rc = pDeviceHandler->OpenEvent(&TabWin32Handles[iIndexNew].hmHandleData,
     2689  rc = pDeviceHandler->OpenMutex(&TabWin32Handles[iIndexNew].hmHandleData,
    26372690                                 fInherit,
    26382691                                 lpName);
    26392692  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
    26402693  {
    2641     TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     2694    FREEHANDLE(iIndexNew);
     2695//    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    26422696    SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
    26432697    return 0;                           /* signal error */
     
    26512705
    26522706/*****************************************************************************
    2653  * Name      : HANDLE  HMOpenMutex
    2654  * Purpose   : Wrapper for the OpenMutex() API
     2707 * Name      : HANDLE  HMCreateSemaphore
     2708 * Purpose   : Wrapper for the CreateSemaphore() API
    26552709 * Parameters:
    26562710 * Variables :
     
    26622716 *****************************************************************************/
    26632717
    2664 HANDLE HMOpenMutex(DWORD   fdwAccess,
    2665                    BOOL    fInherit,
    2666                    LPCTSTR lpName)
     2718HANDLE WIN32API CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpsa,
     2719                         LONG                  lInitialCount,
     2720                         LONG                  lMaximumCount,
     2721                         LPCTSTR               lpName)
    26672722{
    26682723  int             iIndex;                     /* index into the handle table */
     
    26722727  DWORD           rc;                                     /* API return code */
    26732728
    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
     2800HANDLE 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 */
    26762816
    26772817  iIndexNew = _HMHandleGetFree();                         /* get free handle */
     
    26902830  pHMHandleData->dwFlags    = 0;
    26912831  pHMHandleData->lpHandlerData = NULL;
     2832  pHMHandleData->dwInternalType = HMTYPE_SEMAPHORE;
    26922833
    26932834
     
    27002841
    27012842                                                  /* call the device handler */
    2702   rc = pDeviceHandler->OpenMutex(&TabWin32Handles[iIndexNew].hmHandleData,
    2703                                  fInherit,
    2704                                  lpName);
     2843  rc = pDeviceHandler->OpenSemaphore(&TabWin32Handles[iIndexNew].hmHandleData,
     2844                                     fInherit,
     2845                                     lpName);
    27052846  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
    27062847  {
    2707     TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     2848    FREEHANDLE(iIndexNew);
     2849//    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    27082850    SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
    2709     return 0;                           /* signal error */
     2851    return 0;                         /* signal failure */
    27102852  }
    27112853  else
     
    27172859
    27182860/*****************************************************************************
    2719  * Name      : HANDLE  HMCreateSemaphore
    2720  * Purpose   : Wrapper for the CreateSemaphore() API
     2861 * Name      : HMReleaseSemaphore
     2862 * Purpose   : router function for ReleaseSemaphore
    27212863 * Parameters:
    27222864 * Variables :
     
    27252867 * Status    :
    27262868 *
     2869 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     2870 *****************************************************************************/
     2871
     2872BOOL 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 *
    27272908 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    27282909 *****************************************************************************/
    27292910
    2730 HANDLE HMCreateSemaphore(LPSECURITY_ATTRIBUTES lpsa,
    2731                          LONG                  lInitialCount,
    2732                          LONG                  lMaximumCount,
    2733                          LPCTSTR               lpName)
     2911HANDLE HMCreateFileMapping(HANDLE                hFile,
     2912                           LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
     2913                           DWORD                 flProtect,
     2914                           DWORD                 dwMaximumSizeHigh,
     2915                           DWORD                 dwMaximumSizeLow,
     2916                           LPCTSTR               lpName)
    27342917{
    27352918  int             iIndex;                     /* index into the handle table */
     
    27392922  DWORD           rc;                                     /* API return code */
    27402923
    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 */
    27522925
    27532926  iIndexNew = _HMHandleGetFree();                         /* get free handle */
     
    27572930    return 0;                           /* signal error */
    27582931  }
    2759 
    27602932
    27612933                           /* initialize the complete HMHANDLEDATA structure */
     
    27662938  pHMHandleData->dwFlags    = 0;
    27672939  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;
    29422941
    29432942      /* we've got to mark the handle as occupied here, since another device */
     
    29632962  {
    29642963      if(rc != ERROR_ALREADY_EXISTS) {
    2965           TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     2964          FREEHANDLE(iIndexNew);
     2965//          TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    29662966          SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
    29672967          return (NULL);                                           /* signal error */
     
    30333033  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
    30343034  {
    3035     TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     3035    FREEHANDLE(iIndexNew);
     3036//    TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    30363037    SetLastError(rc);          /* Hehe, OS/2 and NT are pretty compatible :) */
    30373038    return (NULL);                                           /* signal error */
     
    31503151  }
    31513152
    3152   //If the timeout is less than 20 milliseconds (and not zero), then we are likely to
    3153   //return too late if the thread priority isn't time critical (time slices
    3154   //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 timeouts
    3167           if(dwTimeout > 8)
    3168               dwTimeout = (dwTimeout/8)*8;
    3169           fChangePriority = TRUE;
    3170       }
    3171   }
    3172 
    31733153  // OK, now forward to Open32.
    31743154  // @@@PH: Note this will fail on handles that do NOT belong to Open32
     
    31793159                                  dwTimeout);
    31803160
    3181   //Restore old thread priority if we changed it before
    3182   if(fChangePriority) {
    3183       SetThreadPriority(hThread, dwThreadPriority);
    3184   }
    3185 
    31863161  return (rc);                            // OK, done
    31873162}
     
    32713246////      return (WAIT_FAILED);
    32723247    }
    3273   }
    3274 
    3275   //If the timeout is less than 20 milliseconds (and not zero), then we are likely to
    3276   //return too late if the thread priority isn't time critical (time slices
    3277   //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 timeouts
    3290           if(dwTimeout > 8)
    3291               dwTimeout = (dwTimeout/8)*8;
    3292           fChangePriority = TRUE;
    3293       }
    32943248  }
    32953249
     
    33023256                                     dwWakeMask);
    33033257
    3304   //Restore old thread priority if we changed it before
    3305   if(fChangePriority) {
    3306       SetThreadPriority(hThread, dwThreadPriority);
    3307   }
    3308 
    33093258  dprintf2(("MsgWaitForMultipleObjects returned %d", rc));
    33103259  return (rc);                            // OK, done
     
    33223271 *****************************************************************************/
    33233272
    3324 BOOL HMDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
     3273BOOL WIN32API DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
    33253274                       LPVOID lpInBuffer, DWORD nInBufferSize,
    33263275                       LPVOID lpOutBuffer, DWORD nOutBufferSize,
     
    33493298}
    33503299/*****************************************************************************
    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.
    33573323 * Status    :
    33583324 *
    33593325 * Author    : Sander van Leeuwen
    33603326 *****************************************************************************/
    3361 BOOL  HMCancelIo(HANDLE hDevice)
     3327BOOL WIN32API CancelIo(HANDLE hDevice)
    33623328{
    33633329  int       iIndex;                           /* index into the handle table */
     
    33773343
    33783344  return (fResult);                                   /* deliver return code */
    3379 }
    3380 /*****************************************************************************
    3381  * Name      : HMCOMGetCommState
    3382  * Purpose   : router function for GetCommState
    3383  * 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 */
    39523345}
    39533346
     
    39693362                        HANDLE *TokenHandle)
    39703363{
    3971   int             iIndex;                     /* index into the handle table */
     3364  int       iIndex;                           /* index into the handle table */
    39723365  int             iIndexNew;                  /* index into the handle table */
    39733366  HMDeviceHandler *pDeviceHandler;         /* device handler for this handle */
     
    39913384  pHMHandleData->dwFlags    = 0;
    39923385  pHMHandleData->lpHandlerData = NULL;
     3386  pHMHandleData->dwInternalType = HMTYPE_THREADTOKEN;
    39933387
    39943388
     
    40103404  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
    40113405  {
    4012       TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     3406    FREEHANDLE(iIndexNew);
     3407//      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    40133408  return (rc);                                           /* signal error */
    40143409  }
     
    40363431                         HANDLE *TokenHandle)
    40373432{
    4038   int             iIndex;                     /* index into the handle table */
     3433  int       iIndex;                           /* index into the handle table */
    40393434  int             iIndexNew;                  /* index into the handle table */
    40403435  HMDeviceHandler *pDeviceHandler;         /* device handler for this handle */
     
    40583453  pHMHandleData->dwFlags    = 0;
    40593454  pHMHandleData->lpHandlerData = NULL;
     3455  pHMHandleData->dwInternalType = HMTYPE_PROCESSTOKEN;
    40603456
    40613457
     
    40673463  TabWin32Handles[iIndexNew].pDeviceHandler         = pDeviceHandler;
    40683464
    4069                                                   /* call the device handler */
     3465  /* call the device handler */
    40703466
    40713467  // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to
     
    40773473  if (rc != NO_ERROR)     /* oops, creation failed within the device handler */
    40783474  {
    4079       TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
     3475    FREEHANDLE(iIndexNew);
     3476//      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    40803477  return (rc);                                           /* signal error */
    40813478  }
     
    40863483  return STATUS_SUCCESS;
    40873484}
    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 */
     3494unsigned 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  
    199199       dprintf(("KERNEL32: GetLastError returned %d\n", rc));
    200200  }
    201   else dprintf(("KERNEL32: GetLastError returned no error\n", rc));
     201  else dprintf2(("KERNEL32: GetLastError returned no error\n", rc));
    202202  return(rc);
    203203}
  • trunk/src/kernel32/KERNEL32.DEF

    r10606 r21302  
    147147;  Ordinal0097 = _OS2Ordinal0097@??           @97
    148148;  Ordinal0098 = _OS2Ordinal0098@??           @98
    149    KERNEL32_99 = _KERNEL32_99@4               @99  NONAME
    150    KERNEL32_100 = _KERNEL32_100@12            @100      NONAME
     149                 _KERNEL32_99@4               @99 NONAME
     150                 _KERNEL32_100@12             @100 NONAME
    151151;  Ordinal0101 = _OS2Ordinal0101@??           @101
    152152
     
    10031003    GetVolumeNameForVolumeMountPointW = _GetVolumeNameForVolumeMountPointW@12 @915
    10041004
     1005;
     1006; ENDOFEXPORTS
     1007; Internal function marker
     1008;
    10051009
    10061010;
     
    11601164    InitializeSharedHeap                                          @1276 NONAME
    11611165    DestroySharedHeap                                             @1277 NONAME
     1166    _debug_smalloc                                                @1278 NONAME
     1167    _debug_smallocfill                                            @1279 NONAME
     1168    _debug_sfree                                                  @1280 NONAME
    11621169
    11631170;code memory allocation
     
    12101217
    12111218    OSLibDosDevIOCtl                                              @2026 NONAME
    1212 
    1213     OSLibImSetMsgQueueProperty                                    @2029 NONAME
    12141219
    12151220    fIsDBCSEnv                                                    @2103 NONAME
     
    12521257    _ODIN_SetExceptionHandler@4                                   @3114 NONAME
    12531258    _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
    12541264
    12551265; Char functions (forwarders from user32)
     
    12861296    _IsCharUpperA@4                                               @3159 NONAME
    12871297    _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  
    2727
    2828#include "unicode.h"
     29
    2930#include "handlemanager.h"
     31#include "hmhandle.h"
     32#include "hmcomm.h"
     33
    3034
    3135#define DBG_LOCALLOG  DBG_comm
    3236#include "dbglocal.h"
     37
    3338ODINDEBUGCHANNEL(KERNEL32-COMM)
     39
     40static BOOL HMCommGetDefaultCommConfig( HANDLE hCommDev,
     41                                        LPCOMMCONFIG lpCC,
     42                                        LPDWORD lpdwSize);
     43static BOOL HMCommSetDefaultCommConfig( HANDLE hCommDev,
     44                                        LPCOMMCONFIG lpCC,
     45                                        DWORD dwSize);
    3446
    3547/*****************************************************************************
     
    606618
    607619/*****************************************************************************
    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]
    613629 *****************************************************************************/
    614630
    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 
     631BOOL 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//******************************************************************************
    749656BOOL 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//******************************************************************************
     684BOOL 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//******************************************************************************
     710BOOL 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//******************************************************************************
     736BOOL 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//******************************************************************************
     756BOOL 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//******************************************************************************
     776BOOL 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//******************************************************************************
     805BOOL 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//******************************************************************************
     831BOOL 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//******************************************************************************
     857BOOL 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//******************************************************************************
     883BOOL 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//******************************************************************************
     909BOOL 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//******************************************************************************
     929BOOL 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//******************************************************************************
     958BOOL 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//******************************************************************************
     976BOOL 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//******************************************************************************
     1012BOOL 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//******************************************************************************
     1052BOOL 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//******************************************************************************
     1074BOOL 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//******************************************************************************
     1092static 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//******************************************************************************
     1122static 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  
    24912491
    24922492  /* 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));
    24982494}
    24992495
     
    25442540
    25452541  /* 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);
    25512543
    25522544  *lpcchWritten = MultiByteToWideChar( GetConsoleCP(), 0, pszAscii, *lpcchWritten, 0, 0 );
  • trunk/src/kernel32/critsection.cpp

    r10201 r21302  
    2424DECLARE_DEBUG_CHANNEL(relay)
    2525
    26 
     26#ifdef DEBUG
     27
     28#include "heapshared.h"
     29#include <vmutex.h>
     30
     31typedef struct _CritSectDebug
     32{
     33    struct _CritSectDebug *next;
     34    struct _CritSectDebug *prev;
     35    CRITICAL_SECTION *ThisSect;
     36    HANDLE CreatingThread;
     37    LONG EnteredCount;
     38} CritSectDebug;
     39
     40CritSectDebug *csfirst = NULL;
     41CritSectDebug *cslast = NULL;
     42ULONG ulCritSectCount = 0;
     43
     44VMutex csmutex;
     45
     46void 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
     64CritSectDebug *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
     86void 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
     130void 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
     168void 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
     188void 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 */
     214static 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}
    27240
    28241/***********************************************************************
     
    32245{
    33246    dprintf(("InitializeCriticalSection %x", crit));
     247
     248    InitializeDebugInfo (crit);
     249
    34250    crit->LockCount      = -1;
    35251    crit->RecursionCount = 0;
    36252    crit->OwningThread   = 0;
    37     crit->LockSemaphore  = CreateSemaphoreA( NULL, 0, 1, NULL );
    38     crit->Reserved       = ODIN_GetCurrentProcessId();
     253    crit->LockSemaphore  = 0;
     254    crit->Reserved       = 0;
    39255}
    40256
     
    48264BOOL WINAPI InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD spincount )
    49265{
    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 );
    51268    crit->Reserved = spincount;
    52     InitializeCriticalSection( crit );
    53269    return TRUE;
    54270}
     
    61277    dprintf(("DeleteCriticalSection %x", crit));
    62278
    63     if (crit->LockSemaphore)
    64     {
     279    DeleteDebugInfo (crit);
     280
    65281        if (crit->RecursionCount)  /* Should not happen */
    66282            dprintf(("Deleting owned critical section (%p)\n", crit ));
     
    69285        crit->RecursionCount = 0;
    70286        crit->OwningThread   = 0;
    71         CloseHandle( crit->LockSemaphore );
     287    if (crit->LockSemaphore) CloseHandle( crit->LockSemaphore );
    72288        crit->LockSemaphore  = 0;
    73         crit->Reserved       = (DWORD)-1;
    74     }
     289    crit->Reserved       = 0;
    75290}
    76291
     
    81296void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit )
    82297{
    83     DWORD res;
    84 
    85298    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))
    92317    {
    93318        if (crit->OwningThread == ODIN_GetCurrentThreadId())
     
    100325        for (;;)
    101326        {
    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)
    104331            {
    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))
    108335                {
    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);
    111338                }
    112339            }
     340
    113341            if (res == STATUS_WAIT_0) break;
    114342
     
    125353#endif
    126354            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
    130359    crit->OwningThread   = ODIN_GetCurrentThreadId();
    131360    crit->RecursionCount = 1;
     
    138367BOOL WINAPI TryEnterCriticalSection( CRITICAL_SECTION *crit )
    139368{
     369    BOOL ret = FALSE;
     370
    140371    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
    142381    {
    143382        if (crit->OwningThread == ODIN_GetCurrentThreadId())
    144383        {
     384            InterlockedIncrement (&crit->LockCount);
    145385            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;
    155393}
    156394
     
    162400{
    163401    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
    165418       
    166419    if (--crit->RecursionCount)
    167420    {
    168         InterlockedDecrement( &crit->LockCount );
     421        InterlockedDecrement(&crit->LockCount);
    169422        return;
    170423    }
     424
    171425    crit->OwningThread = 0;
     426
    172427    if (InterlockedDecrement( &crit->LockCount ) >= 0)
    173428    {
    174429        /* Someone is waiting */
    175         ReleaseSemaphore( crit->LockSemaphore, 1, NULL );
     430        HANDLE sem = get_semaphore (crit);
     431        ReleaseSemaphore (sem, 1, NULL);
    176432    }
    177433}
     
    184440{
    185441    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);
    188446}
    189447
     
    196454    dprintf(("ReinitializeCriticalSection %x", crit));
    197455
    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);
    207459    }
    208460}
     
    215467{
    216468    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  
    145145"mmapdup",
    146146"oslibthread",
    147 "mmapnotify"
     147"mmapnotify",
     148"_ras"
    148149};
    149150//******************************************************************************
  • trunk/src/kernel32/dbglocal.h

    r10384 r21302  
    142142#define DBG_oslibthread    122
    143143#define DBG_mmapnotify     123
    144 #define DBG_MAXFILES       124
     144#define DBG__ras           124
     145#define DBG_MAXFILES       125
    145146
    146147extern USHORT DbgEnabledKERNEL32[DBG_MAXFILES];
  • trunk/src/kernel32/dbglog.cpp

    r9938 r21302  
    3030#include "initterm.h"
    3131#include "logging.h"
     32#include "exceptions.h"
    3233#include "exceptutil.h"
    3334#include <wprocess.h>
     
    3637#include <cpuhlp.h>
    3738
     39#include "asmutil.h"
     40#include "WinImageBase.h"
     41#include "WinDllBase.h"
     42#include "WinExeBase.h"
    3843/*****************************************************************************
    3944 * PMPRINTF Version                                                          *
     
    284289#endif
    285290
     291static 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
    286305int SYSTEM WriteLog(char *tekst, ...)
    287306{
     
    476495        if(tekst[strlen(tekst)-1] != '\n')
    477496            fprintf(flog, "\n");
    478 
     497#if 0       
     498if (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
    479534        if(fFlushLines)
    480535            fflush(flog);
  • trunk/src/kernel32/directory.cpp

    r9597 r21302  
    278278  dprintf(("CreateDirectoryA %s", lpstrDirectory));
    279279 
    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)
    282281  DWORD dwAttr = GetFileAttributesA(lpstrDirectory);
    283282  if(dwAttr != -1)
     
    285284      if (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
    286285      {
    287           SetLastError(ERROR_SUCCESS);
    288           return TRUE;
     286          SetLastError(ERROR_ALREADY_EXISTS);
     287          return FALSE;
    289288      }
    290289  } 
  • trunk/src/kernel32/environ.cpp

    r7858 r21302  
    2525#include <winnls.h>
    2626#include <stdlib.h>
     27#include <stdio.h>
    2728#include <string.h>
    2829#include <heapstring.h>
     
    3839
    3940
     41//list of important OS/2 environment variables that must not be removed
     42//when creating a new process
     43static 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//******************************************************************************
     69void 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}
    4087//******************************************************************************
    4188//******************************************************************************
    4289LPSTR WIN32API GetEnvironmentStringsA()
    4390{
     91  InitEnvironment();
    4492  return (LPSTR) O32_GetEnvironmentStrings();
    4593}
     
    52100  LPWSTR wenvstrings;
    53101  int len, i;
     102
     103  InitEnvironment();
    54104
    55105  if(envstrings == NULL)
     
    64114  }
    65115  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++)
    70118  {
    71119     wenvstrings[i] = envstrings[i];
     
    83131BOOL WIN32API FreeEnvironmentStringsW(LPWSTR envstrings)
    84132{
    85   free(envstrings);
     133  HeapFree(GetProcessHeap(), 0, envstrings);
    86134  return(TRUE);
    87135}
     
    283331}
    284332//******************************************************************************
    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//******************************************************************************
     337char *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  
    5252#define INCL_MISC
    5353#define INCL_BASE
     54#define INCL_WIN
    5455#define INCL_WINBUTTONS
    5556#include <os2wrap.h>                     //Odin32 OS/2 api wrappers
     
    5960#include <time.h>
    6061#include <string.h>
     62#include <pmscan.h>
    6163#include "exceptions.h"
    6264#include "exceptutil.h"
     
    6668#include <win32api.h>
    6769#include "oslibexcept.h"
     70#include "oslibmem.h"
    6871#include "exceptstackdump.h"
     72#include "hmthread.h"
    6973
    7074#include "WinImageBase.h"
     
    8185#define DBG_LOCALLOG    DBG_exceptions
    8286#include "dbglocal.h"
     87
     88#include <_ras.h>
    8389
    8490#ifdef WITH_KLIB
     
    672678    static BOOL fEntry = FALSE;
    673679
    674     if(fEntry == FALSE) {
     680    if(!fExitProcess && fEntry == FALSE) {
    675681        fEntry = TRUE;
    676682        ExitProcess(666);
     
    702708                             PSZ                          szTrapDump)
    703709{
     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   
    704719    PSZ    pszExceptionName = "<unknown>";        /* points to name/type excpt */
    705720    APIRET rc               = XCPT_CONTINUE_SEARCH;        /* excpt-dep.  code */
     
    711726    ULONG  ulModule;                                          /* module number */
    712727    ULONG  ulObject;                        /* object number within the module */
    713     CHAR   szModule[260];                        /* buffer for the module name */
     728static    CHAR   szModule[260];                        /* buffer for the module name */
    714729    ULONG  ulOffset;             /* offset within the object within the module */
    715     char   szLineException[128];
    716     char   szLineExceptionType[128];
     730static    char   szLineException[128];
     731static    char   szLineExceptionType[128];
    717732
    718733    szLineException[0]  = 0;                                              /* initialize */
     
    944959    if(rc == NO_ERROR && ulObject != -1)
    945960    {
    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
    947979        strcat(szTrapDump, szLineException);
    948980    }
     
    10441076                             PVOID                        p)
    10451077{
     1078    sprintfException(pERepRec, pERegRec, pCtxRec, p, szTrapDump);
     1079#ifdef RAS
     1080    RasLog (szTrapDump);
     1081#endif
    10461082    /* now dump the information to the logfile */
    10471083    dprintf(("\n%s", szTrapDump));
     
    10651101//*****************************************************************************
    10661102//*****************************************************************************
    1067 static void logException()
     1103static void logException(PEXCEPTIONREPORTRECORD pERepRec, PEXCEPTIONREGISTRATIONRECORD pERegRec, PCONTEXTRECORD pCtxRec, PVOID p)
    10681104{
    10691105    APIRET rc;
     
    11101146            DosWrite(hFile, lpszTime, strlen(lpszTime), &ulBytesWritten);
    11111147        }
     1148        sprintfException(pERepRec, pERegRec, pCtxRec, p, szTrapDump);
     1149#ifdef RAS
     1150        RasLog (szTrapDump);
     1151#endif
    11121152        DosWrite(hFile, szTrapDump, strlen(szTrapDump), &ulBytesWritten);
    11131153        DosClose(hFile);
     
    11471187    int prevlock = LogException(ENTER_EXCEPTION);
    11481188
    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//    }
    11551196
    11561197    /* Access violation at a known location */
     
    12961337    }
    12971338#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:
    12991407    case XCPT_BREAKPOINT:
    13001408    case XCPT_ARRAY_BOUNDS_EXCEEDED:
    13011409    case XCPT_DATATYPE_MISALIGNMENT:
    1302     case XCPT_ILLEGAL_INSTRUCTION:
    1303     case XCPT_PRIVILEGED_INSTRUCTION:
    1304     case XCPT_INVALID_LOCK_SEQUENCE:
    13051410    case XCPT_INTEGER_DIVIDE_BY_ZERO:
    13061411    case XCPT_INTEGER_OVERFLOW:
    13071412    case XCPT_SINGLE_STEP:
    1308     case XCPT_UNABLE_TO_GROW_STACK:
    13091413    case XCPT_IN_PAGE_ERROR:
    13101414CrashAndBurn:
     
    13161420                goto continuesearch;
    13171421
    1318 #ifdef DEBUG
     1422#if defined(DEBUG) || defined(RAS)
    13191423        dprintfException(pERepRec, pERegRec, pCtxRec, p);
     1424
    13201425        if(!fExitProcess && (pCtxRec->ContextFlags & CONTEXT_CONTROL)) {
    13211426                dbgPrintStack(pERepRec, pERegRec, pCtxRec, p);
     
    13371442
    13381443                rc = DosGetInfoBlocks (&pTIB, &pPIB);
    1339                 if(rc == NO_ERROR && pTIB->tib_ptib2->tib2_ultid != 1)
     1444                if(rc == NO_ERROR)
    13401445                {
    13411446                    dprintf(("KERNEL32: OS2ExceptionHandler: Continue and kill thread"));
    13421447
    1343                     pCtxRec->ctx_RegEip = (ULONG)KillWin32Thread;
     1448                    pCtxRec->ctx_RegEip = (pTIB->tib_ptib2->tib2_ultid != 1) ? (ULONG)KillWin32Thread : (ULONG)KillWin32Process;
    13441449                    pCtxRec->ctx_RegEsp = pCtxRec->ctx_RegEsp + 0x10;
    13451450                    pCtxRec->ctx_RegEax = pERepRec->ExceptionNum;
     
    13521457
    13531458        //Log fatal exception here
    1354         logException();
     1459        logException(pERepRec, pERegRec, pCtxRec, p);
    13551460
    13561461        dprintf(("KERNEL32: OS2ExceptionHandler: Continue and kill\n"));
     
    13621467        goto continueexecution;
    13631468
    1364     //@@@PH: growing thread stacks might need special treatment
    13651469    case XCPT_GUARD_PAGE_VIOLATION:
    13661470    {
     
    13691473        //inside fprintf
    13701474        //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
    13721530        Win32MemMap *map;
    13731531        BOOL  fWriteAccess = FALSE, ret;
     
    13871545
    13881546        map = Win32MemMapView::findMapByView(pERepRec->ExceptionInfo[1], &offset, accessflag);
    1389         if(map == NULL) {
    1390             goto continueGuardException;
    1391         }
     1547            if(map) {
    13921548        ret = map->commitGuardPage(pERepRec->ExceptionInfo[1], offset, fWriteAccess);
    13931549        map->Release();
    13941550        if(ret == TRUE)
    13951551            goto continueexecution;
     1552            }           
     1553        }
    13961554
    13971555continueGuardException:
     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     
    13981568        goto continuesearch;
    13991569    }
     
    14081578     */
    14091579    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
    14101584        switch (pERepRec->ExceptionInfo[0])
    14111585        {
    14121586            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]);
    14141595                    goto continueexecution;
    1415                 goto continuesearch;
    1416             case XCPT_SIGNAL_INTR:
    1417                 if (InternalGenerateConsoleCtrlEvent(CTRL_C_EVENT, 0))
    1418                     goto continueexecution;
     1596                }
    14191597                goto continuesearch;
    14201598
     
    14241602        }
    14251603        goto CrashAndBurn;
     1604    }
    14261605
    14271606    default: //non-continuable exceptions
     
    14971676  USHORT sel = RestoreOS2FS();
    14981677  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) {
    15011700      OS2UnsetExceptionHandler(pExceptionRegRec);
    15021701  }
  • trunk/src/kernel32/exceptstackdump.cpp

    r8401 r21302  
    2525#include "windllbase.h"
    2626
     27#include <_ras.h>
     28
    2729#define DBG_LOCALLOG    DBG_exceptstackdump
    2830#include "dbglocal.h"
     
    3032int SYSTEM EXPORT WriteLogNoEOL(char *tekst, ...);
    3133
     34#define FIX64KLIMIT
     35
    3236#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
    3450
    3551/* ******************************************************************
     
    5571 */
    5672
    57 BOOL dbgPrintSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset)
     73BOOL dbgGetSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset, CHAR *Info, ULONG cbInfo)
    5874{
    5975    static FILE    *SymFile;
     
    88104        if (fseek(SymFile, SegOffset, SEEK_SET))
    89105        {
    90             dprintf(("Seek error."));
     106//            dprintf(("Seek error."));
    91107            goto endofprintsym;
    92108        }
     
    100116            LastVal = 0;
    101117
     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
    102135            // go thru all symbols in this object
    103136            for (SymNum = 0; SymNum < SegDef.cSymbols; SymNum++)
    104137            {
     138#ifndef FIX64KLIMIT
    105139                // read in symbol offset USHORT
    106140                SymPtrOffset = SYMDEFOFFSET(SegOffset, SegDef, SymNum);
    107141                fseek(SymFile, SymPtrOffset, SEEK_SET);
    108142                fread(&SymOffset, sizeof(unsigned short int), 1, SymFile);
     143#endif
    109144
    110145                // go to symbol definition
     
    121156                        fread(&Buffer[1], 1, SymDef32.cbSymName, SymFile);
    122157                        Buffer[SymDef32.cbSymName] = 0x00;
    123                         dprintf(("%s\n", Buffer));
     158//                        dprintf(("%s\n", Buffer));
     159                        strcpy (Info, Buffer);
    124160                        rc = TRUE;
    125161                        break;
     
    134170                    {
    135171                        // 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
    137177                    }
    138178                    LastVal = SymDef32.wSymVal;
     
    144184                    {
    145185                        // 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
    147191                        rc = TRUE;
    148192                        break;
    149193                    }
    150194                    /*printf("32 Bit Symbol <%s> Address %p",Buffer,SymDef32.wSymVal); */
     195#ifdef FIX64KLIMIT
     196                    SymOffset += sizeof (SYMDEF32) + SymDef32.cbSymName - 1;
     197#endif
    151198                }
    152199                else
     
    163210                    if (SymDef16.wSymVal > TrapOffset)
    164211                    {
    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
    166217                    }
    167218                    LastVal = SymDef16.wSymVal;
     
    171222                    if (SymDef16.wSymVal > TrapOffset)
    172223                    {
    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
    174229                        rc = TRUE;
    175230                        break;
    176231                    }
    177232                    /*printf("16 Bit Symbol <%s> Address %p",Buffer,SymDef16.wSymVal); */
     233#ifdef FIX64KLIMIT
     234                    SymOffset += sizeof (SYMDEF16) + SymDef16.cbSymName - 1;
     235#endif
    178236                }               // endif
    179237            }
     238#ifdef FIX64KLIMIT
     239            if (SymNum < SegDef.cSymbols)
     240            {
     241#endif
    180242            break;
     243#ifdef FIX64KLIMIT
     244            }
     245#endif
    181246        }                       // endif
    182247        SegOffset = NEXTSEGDEFOFFSET(SegDef);
     
    184249endofprintsym:
    185250    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}
     255BOOL 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));
    187260    return rc;
    188261}
  • trunk/src/kernel32/exceptstackdump.h

    r3483 r21302  
    541541    #pragma pack()
    542542
     543    BOOL dbgGetSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset, char *Info, ULONG cbInfo);
     544    BOOL dbgPrintSYMInfo(CHAR * SymFileName, ULONG Object, ULONG TrapOffset);
     545   
    543546    /*
    544547     * dbgPrintStack:
  • trunk/src/kernel32/handlenames.cpp

    r9975 r21302  
    164164                                          BOOL fCaseInsensitive)
    165165{
     166  int               cchSymbolicLink = strlen(pszSymbolicLink);
    166167  PLINEARLISTENTRY pLE = pSymbolicLinks->getFirst();
    167168  while (pLE)
    168169  {
    169170    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    {
    173177    if (fCaseInsensitive)
    174178    {
    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))
    180180          return pHandleName;
    181181    }
    182182    else
    183183    {
    184       if ( (pszSymbolicLink[iLen] == '\\') ||
    185            (pszSymbolicLink[iLen] == 0) )
    186         if (strncmp(pHandleName->pszSymbolicLink, pszSymbolicLink, iLen) == 0)
     184            if (!memcmp(pHandleName->pszSymbolicLink, pszSymbolicLink, cch))
    187185          return pHandleName;
    188186    }
    189    
     187    }
    190188   
    191189    // skip to the next entry
  • trunk/src/kernel32/heapshared.cpp

    r9667 r21302  
    1717#define INCL_BASE
    1818#define INCL_DOSMEMMGR
     19#define INCL_DOSPROCESS
    1920#include <os2wrap.h>
    2021#include <string.h>
    2122#include <dbglog.h>
    22 #include <heapshared.h>
     23#include <stddef.h>
     24#include <stdlib.h>
     25#include <umalloc.h>
    2326#include "initterm.h"
     27
     28#define PAGE_SIZE               4096
    2429
    2530#define DBG_LOCALLOG    DBG_heapshared
     
    102107//******************************************************************************
    103108//******************************************************************************
     109#ifdef DEBUG
     110int _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//******************************************************************************
    104127void SYSTEM DestroySharedHeap()
    105128{
     
    108131        return;
    109132    }
     133
     134#ifdef DEBUG
     135    _uheap_walk(sharedHeap, callback_function);
     136    dprintf((NULL));
     137#endif
     138
    110139    if(--refCount == 0) {
    111140            if(sharedHeap) {
     
    200229
    201230    chunk = _umalloc(sharedHeap, size);
    202     dprintf2(("_smalloc %x returned %x", size, chunk));
     231    dprintf(("_smalloc %x returned %x", size, chunk));
    203232    return chunk;
    204233}
     
    213242        memset(chunk, 0, size);
    214243    }
    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//******************************************************************************
     249void SYSTEM _sfree(void *block)
     250{
     251    dprintf(("_sfree %x", block));
     252    free(block);
     253}
     254//******************************************************************************
     255//******************************************************************************
     256void * _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//******************************************************************************
     270void * _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//******************************************************************************
     287void   _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  
    148148    }
    149149
    150     if(namelength == 5 && lpDeviceName[4] != ':') {
     150    if(namelength > 5 || (namelength == 5 && lpDeviceName[4] != ':')) {
    151151        return FALSE;
    152152    }
  • trunk/src/kernel32/hmdevice.cpp

    r10132 r21302  
    138138                               PHMHANDLEDATA pHMSrcHandle,
    139139                               HANDLE  destprocess,
    140                                PHANDLE desthandle,
    141140                               DWORD   fdwAccess,
    142141                               BOOL    fInherit,
     
    144143                               DWORD   fdwOdinOptions)
    145144{
    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));
    150147
    151148  return FALSE;
     
    14191416                                     DWORD                  fdwCreate,
    14201417                                     LPDWORD                lpIDThread,
    1421                                      BOOL                   fFirstThread)
     1418                                     BOOL                   fRegisterThread)
    14221419{
    14231420  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::CreateThread %08xh",
  • trunk/src/kernel32/hmdevice.h

    r10132 r21302  
    1212
    1313/*****************************************************************************
    14  * Remark                                                                    *
    15  *****************************************************************************
    16  */
    17 
    18 
    19 /*****************************************************************************
    20  * Includes                                                                  *
    21  *****************************************************************************/
    22 
    23 /*****************************************************************************
    24  * defines                                                                   *
    25  *****************************************************************************/
    26 
    27 #define HMTYPE_UNKNOWN          0
    28 #define HMTYPE_MEMMAP           1
    29 #define HMTYPE_DEVICE           2
    30 #define HMTYPE_PROCESSTOKEN     3
    31 #define HMTYPE_THREADTOKEN      4
    32 #define HMTYPE_THREAD           5
    33 #define HMTYPE_PIPE             6
    34 #define HMTYPE_EVENTSEM         7
    35 #define HMTYPE_MUTEXSEM         8
    36 #define HMTYPE_SEMAPHORE        9
    37 #define HMTYPE_COMPORT          10
    38 #define HMTYPE_PARPORT          11
    39 //.....
    40 
    41 /*****************************************************************************
    4214 * Structures                                                                *
    4315 *****************************************************************************/
     
    6133} HMHANDLEDATA, *PHMHANDLEDATA;
    6234
    63 PHMHANDLEDATA HMQueryHandleData(HANDLE handle);
     35/*****************************************************************************
     36 * Remark                                                                    *
     37 *****************************************************************************
     38 */
     39
     40
     41/*****************************************************************************
     42 * Includes                                                                  *
     43 *****************************************************************************/
     44
    6445
    6546
     
    9576                               PHMHANDLEDATA pHMSrcHandle,
    9677                               HANDLE  destprocess,
    97                                PHANDLE desthandle,
    9878                               DWORD   fdwAccess,
    9979                               BOOL    fInherit,
     
    389369                             DWORD                  fdwCreate,
    390370                             LPDWORD                lpIDThread,
    391                              BOOL                   fFirstThread);
     371                             BOOL                   fRegisterThread);
    392372
    393373 virtual INT    GetThreadPriority(HANDLE hThread, PHMHANDLEDATA pHMHandleData);
     
    478458                          VOID            *pDevData);
    479459
     460
     461#include "hmhandle.h"
     462
    480463#endif /* _HM_DEVICE_H_ */
    481464
  • trunk/src/kernel32/hmdevio.cpp

    r9533 r21302  
    2727#include <win\winioctl.h>
    2828#include "hmdevio.h"
    29 #include "map.h"
    3029#include "exceptutil.h"
    3130#include "oslibdos.h"
     
    471470    QWORD  time;
    472471    APIRET rc;
    473 
     472#if 0
     473    return FALSE;
     474#else
    474475    rc = DosTmrQueryTime(&time);
    475476    if(rc) {
     
    479480    lpPerformanceCount->u.LowPart  = time.ulLo;
    480481    lpPerformanceCount->u.HighPart = time.ulHi;
     482    dprintf2(("QueryPerformanceCounter returned 0x%X%X\n", lpPerformanceCount->u.HighPart, lpPerformanceCount->u.LowPart));
    481483    return(TRUE);
     484#endif
    482485}
    483486//******************************************************************************
     
    488491    ULONG   freq;
    489492
     493#if 0
     494    return FALSE;
     495#else
    490496    rc = DosTmrQueryFreq(&freq);
    491497    if(rc) {
     
    497503    dprintf2(("QueryPerformanceFrequency returned 0x%X%X\n", lpFrequency->u.HighPart, lpFrequency->u.LowPart));
    498504    return(TRUE);
    499 }
    500 //******************************************************************************
    501 //******************************************************************************
     505#endif
     506}
     507//******************************************************************************
     508//******************************************************************************
  • trunk/src/kernel32/hmevent.cpp

    r9748 r21302  
    1515 */
    1616
    17 #undef DEBUG_LOCAL
    18 //#define DEBUG_LOCAL
    19 
    2017
    2118/*****************************************************************************
     
    4239#include "oslibdos.h"
    4340
     41#include "hmhandle.h"
     42
     43
    4444#define DBG_LOCALLOG    DBG_hmevent
    4545#include "dbglocal.h"
    4646
    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
     60HANDLE 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
     117HANDLE 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
     152HANDLE 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
     198BOOL 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
     228BOOL 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
     258BOOL 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}
    58274
    59275
     
    90306                            lpszEventName);
    91307
     308  dprintf(("KERNEL32: HandleManager::Semaphore::CreateEvent hOpen32 = %p, pHMHandleData->hHMHandle = %p\n", hOpen32, pHMHandleData->hHMHandle));
     309
    92310  if (0 != hOpen32)                            // check success
    93311  {
  • trunk/src/kernel32/hmfile.cpp

    r10564 r21302  
    3535#include "mmap.h"
    3636#include "oslibdos.h"
     37#include <customloader.h>
    3738
    3839#define DBG_LOCALLOG    DBG_hmfile
     
    9798  if (hFile != INVALID_HANDLE_ERROR)
    9899  {
    99         pHMHandleData->dwUserData = (DWORD) new HMFileInfo((LPSTR)lpFileName, lpSecurityAttributes);
     100        pHMHandleData->dwUserData = (DWORD) new HMFileInfo(hFile, (LPSTR)lpFileName, lpSecurityAttributes);
    100101        pHMHandleData->hHMHandle  = hFile;
    101102        return (NO_ERROR);
     
    261262   
    262263        if(hFile != HFILE_ERROR) {
    263             pHMHandleData->dwUserData = (DWORD) new HMFileInfo((LPSTR)lpFileName, NULL);
     264            pHMHandleData->dwUserData = (DWORD) new HMFileInfo(hFile, (LPSTR)lpFileName, NULL);
    264265        }
    265266        return (NO_ERROR);
     
    302303                                        PHMHANDLEDATA pHMSrcHandle,
    303304                                        HANDLE  destprocess,
    304                                         PHANDLE desthandle,
    305305                                        DWORD   fdwAccess,
    306306                                        BOOL    fInherit,
     
    311311 DWORD rc;
    312312
    313   dprintf(("KERNEL32:HMDeviceFileClass::DuplicateHandle (%08x,%08x,%08x,%08x,%08x)",
     313  dprintf(("KERNEL32:HMDeviceFileClass::DuplicateHandle (%08x,%08x,%08x,%08x)",
    314314           pHMHandleData,
    315315           srcprocess,
    316316           pHMSrcHandle->hHMHandle,
    317            destprocess,
    318            desthandle));
     317           destprocess));
    319318
    320319  //TODO: Inheritance of file handles won't work!
     
    345344            memcpy(pHMHandleData, &duphdata, sizeof(duphdata));
    346345
    347             if(fInherit) SetHandleInformation(pHMHandleData, ~HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     346            SetHandleInformation(pHMHandleData, HANDLE_FLAG_INHERIT, (fInherit) ? HANDLE_FLAG_INHERIT : 0);
    348347
    349348            SetLastError(ERROR_SUCCESS);
     
    360359    }
    361360
    362     rc = OSLibDosDupHandle(pHMSrcHandle->hHMHandle,
    363                            desthandle);
     361    pHMHandleData->hHMHandle = 0;
     362    rc = OSLibDosDupHandle(pHMSrcHandle->hHMHandle, &pHMHandleData->hHMHandle);
    364363    if (rc)
    365364    {
     
    370369    }
    371370    else {
    372       if(fInherit) SetHandleInformation(pHMHandleData, ~HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     371      SetHandleInformation(pHMHandleData, HANDLE_FLAG_INHERIT, (fInherit) ? HANDLE_FLAG_INHERIT : 0);
    373372
    374373      SetLastError(ERROR_SUCCESS);
    375       pHMHandleData->hHMHandle = *desthandle;
    376374      return TRUE;    // OK
    377375    }
     
    620618           nrpages++;
    621619 
    622        map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages);
     620       map->commitRange((ULONG)lpBuffer, offset & ~0xfff, FALSE, nrpages);
    623621       map->Release();
    624622  }
     
    844842{
    845843  DWORD ret;
     844  HMFileInfo *fileInfo = (HMFileInfo *)pHMHandleData->dwUserData;
    846845
    847846  dprintfl(("KERNEL32: HMDeviceFileClass::SetFilePointer %s(%08xh,%08xh,%08xh,%08xh)\n",
     
    852851           dwMoveMethod));
    853852
     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  }
    854870  ret = OSLibDosSetFilePointer(pHMHandleData->hHMHandle,
    855871                               lDistanceToMove,
     
    11691185  }
    11701186
    1171   pHMHandleData->dwUserData = (DWORD) new HMFileInfo((LPSTR)lpFileName, lpSecurityAttributes);
     1187  pHMHandleData->dwUserData = (DWORD) new HMFileInfo(0, (LPSTR)lpFileName, lpSecurityAttributes);
    11721188  pHMHandleData->hHMHandle  = 0x8000000;
    11731189  return (NO_ERROR);
     
    12821298  }
    12831299  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  }
    12841307  return finddata.nFileSizeLow;
    12851308}
     
    13291352//******************************************************************************
    13301353//******************************************************************************
    1331 HMFileInfo::HMFileInfo(LPSTR lpszFileName, PVOID lpSecurityAttributes)
     1354HMFileInfo::HMFileInfo(HANDLE hFile, LPSTR lpszFileName, PVOID lpSecurityAttributes)
    13321355{
    13331356  this->lpszFileName = (LPSTR)malloc(strlen(lpszFileName)+1);
     
    13371360  strcpy(this->lpszFileName, lpszFileName);
    13381361  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
     1412failure:
     1413      //reset file pointer to file start
     1414      if(OSLibDosSetFilePointer(hFile, 0, NULL, FILE_BEGIN) != 0) {
     1415          DebugInt3();
     1416      }
     1417  }
     1418end:
     1419  return;
    13391420}
    13401421//******************************************************************************
  • trunk/src/kernel32/hmfile.h

    r10073 r21302  
    2828{
    2929public:
    30   HMFileInfo(LPSTR lpszFileName, PVOID lpSecurityAttributes);
     30  HMFileInfo(HANDLE hFile, LPSTR lpszFileName, PVOID lpSecurityAttributes);
    3131 ~HMFileInfo();
    3232
    3333  char *lpszFileName;
    3434  PVOID lpSecurityAttributes;
     35  DWORD dwLXOffset;
    3536};
    3637
     
    5960                               PHMHANDLEDATA pHMSrcHandle,
    6061                               HANDLE  destprocess,
    61                                PHANDLE desthandle,
    6262                               DWORD   fdwAccess,
    6363                               BOOL    fInherit,
  • trunk/src/kernel32/hmmmap.cpp

    r9971 r21302  
    7474  //It's not allowed to map a file of length 0 according to MSDN. This time
    7575  //the docs are correct. (verified in NT4 SP6)
     76  //bird: It's not allowed to create a non-file based mapping with size 0.
    7677  //TODO: also need to verify access rights of the file handle (write maps need
    7778  //      write access obviously)
     
    8182      dwFileSizeLow = ::GetFileSize(hFile, &dwFileSizeHigh);
    8283      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          {
    8389          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);
    85107      }
    86108  }
  • trunk/src/kernel32/hmnpipe.cpp

    r10132 r21302  
    181181BOOL HMDeviceNamedPipeClass::CloseHandle(PHMHANDLEDATA pHMHandleData)
    182182{
     183  BOOL dwFlags = 0;
     184
    183185  dprintf(("KERNEL32: HMDeviceNamedPipeClass::CloseHandle(%08x)", pHMHandleData->hHMHandle));
    184186
     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)) {
    185191  OSLibDosDisconnectNamedPipe(pHMHandleData->hHMHandle);
     192  }
    186193  return OSLibDosClose(pHMHandleData->hHMHandle);
    187194}
     
    430437  return bRC;
    431438}
    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 *****************************************************************************/
     452BOOL 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  
    1111#ifndef _HM_NPIPE_H_
    1212#define _HM_NPIPE_H_
     13
     14#include "hmfile.h"
    1315
    1416class HMDeviceNamedPipeClass : public HMDeviceFileClass
     
    9597                                    LPDWORD       arg3,
    9698                                    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
    97104};
    98105
  • trunk/src/kernel32/hmopen32.cpp

    r9748 r21302  
    8787  BOOL bRC;
    8888
    89   dprintfl(("KERNEL32: HandleManager::Open32::CloseHandle(%08x)\n",
    90            pHMHandleData->hHMHandle));
     89  dprintfl(("KERNEL32: HandleManager::Open32::CloseHandle(%08x) %p\n",
     90           pHMHandleData, pHMHandleData->hHMHandle));
    9191
    9292  bRC = O32_CloseHandle(pHMHandleData->hHMHandle);
     
    114114                               PHMHANDLEDATA pHMSrcHandle,
    115115                               HANDLE  destprocess,
    116                                PHANDLE desthandle,
    117116                               DWORD   fdwAccess,
    118117                               BOOL    fInherit,
     
    123122
    124123  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;
    136130}
    137131
  • trunk/src/kernel32/hmopen32.h

    r9748 r21302  
    4545                               PHMHANDLEDATA pHMSrcHandle,
    4646                               HANDLE  destprocess,
    47                                PHANDLE desthandle,
    4847                               DWORD   fdwAccess,
    4948                               BOOL    fInherit,
  • trunk/src/kernel32/hmsemaphore.cpp

    r9748 r21302  
    9292                                (LPTSTR)lpszSemaphoreName);
    9393
     94  dprintf(("KERNEL32: HandleManager::Semaphore::CreateSemaphore hOpen32 = %p, pHMHandleData->hHMHandle = %p\n", hOpen32, pHMHandleData->hHMHandle));
     95
    9496  if (0 != hOpen32)                            // check success
    9597  {
  • trunk/src/kernel32/hmthread.cpp

    r9949 r21302  
    3030#include <HandleManager.H>
    3131#include "HMThread.h"
     32#include "oslibdos.h"
    3233#include "oslibthread.h"
     34#include "oslibmem.h"
    3335
    3436#include <win\thread.h>
     
    5759                                         DWORD                  fdwCreate,
    5860                                         LPDWORD                lpIDThread,
    59                                          BOOL                   fFirstThread)
     61                                         BOOL                   fRegisterThread)
    6062{
    6163    Win32Thread *winthread;
     
    7880
    7981    //SvL: This doesn't really create a thread, but only sets up the
    80     //     handle of thread 0
    81     if(fFirstThread) {
     82    //     handle of the current thread.
     83    if(fRegisterThread) {
    8284        pHMHandleData->hHMHandle = O32_GetCurrentThread(); //return Open32 handle of thread
    8385        return pHMHandleData->hHMHandle;
     
    144146                                          PHMHANDLEDATA pHMSrcHandle,
    145147                                          HANDLE  destprocess,
    146                                           PHANDLE desthandle,
    147148                                          DWORD   fdwAccess,
    148149                                          BOOL    fInherit,
     
    153154  OBJ_THREAD *threadsrc = (OBJ_THREAD *)pHMSrcHandle->dwUserData;
    154155
    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));
    157158
    158159  if(destprocess != srcprocess)
     
    162163      return FALSE;
    163164  }
    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);
    165167
    166168  if(ret == TRUE) {
    167169       OBJ_THREAD *threaddest = (OBJ_THREAD *)malloc(sizeof(OBJ_THREAD));
    168170       if(threaddest == NULL) {
    169            O32_CloseHandle(*desthandle);
     171           O32_CloseHandle(pHMHandleData->hHMHandle);
    170172           SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    171173           return FALSE;
     
    180182       }
    181183
    182        pHMHandleData->hHMHandle = *desthandle;
    183184       return TRUE;
    184185  }
    185   else return FALSE;
     186  else
     187  {
     188      dprintf(("O32_DuplicateHandle failed for handle %x!!", pHMSrcHandle->hHMHandle));
     189      return FALSE;
     190  }
    186191}
    187192//******************************************************************************
     
    209214{
    210215    DWORD dwSuspend;
     216    CONTEXT     context;
    211217    OBJ_THREAD *threadobj = (OBJ_THREAD *)pHMHandleData->dwUserData;
    212218
    213219    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
    215278        teb->o.odin.dwSuspend--;
    216279        dprintf(("ResumeThread (%08xh) : count %d", pHMHandleData->hHMHandle, teb->o.odin.dwSuspend));
    217     }
     280
    218281    dwSuspend = O32_ResumeThread(pHMHandleData->hHMHandle);
    219     if(dwSuspend == -1) {
     282    if(dwSuspend == -1)
     283    {
    220284        teb->o.odin.dwSuspend++;
    221285        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
    223314    return dwSuspend;
    224315}
     
    264355}
    265356//******************************************************************************
    266 //TODO: Implement this??
     357//******************************************************************************
     358#ifdef DEBUG
     359void 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//******************************************************************************
    267384//******************************************************************************
    268385BOOL HMDeviceThreadClass::GetThreadContext(HANDLE hThread, PHMHANDLEDATA pHMHandleData, PCONTEXT lpContext)
    269386{
    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//
    285441//******************************************************************************
    286442BOOL HMDeviceThreadClass::SetThreadContext(HANDLE hThread, PHMHANDLEDATA pHMHandleData, const CONTEXT *lpContext)
    287443{
    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);
    290491  return FALSE;
    291492}
  • trunk/src/kernel32/hmthread.h

    r9748 r21302  
    1919#define THREAD_ALIVE            1
    2020
     21#define SETTHREADCONTEXT_INVALID_LOCKOPCODE     0x90F0  //invalid lock sequence
     22
    2123class HMDeviceThreadClass : public HMDeviceOpen32Class
    2224{
     
    3133                              DWORD                  fdwCreate,
    3234                              LPDWORD                lpIDThread,
    33                               BOOL                   fFirstThread);
     35                              BOOL                   fRegisterThread);
    3436
    3537  /* this is a handler method for calls to WaitForSingleObject */
     
    4951                               PHMHANDLEDATA pHMSrcHandle,
    5052                               HANDLE  destprocess,
    51                                PHANDLE desthandle,
    5253                               DWORD   fdwAccess,
    5354                               BOOL    fInherit,
  • trunk/src/kernel32/initkernel32.cpp

    r10606 r21302  
    6060#include <stats.h>
    6161#include <heapshared.h>
    62 #include <heapstring.h>
     62#include <_ras.h>
    6363
    6464#define DBG_LOCALLOG    DBG_initterm
     
    7171 extern DWORD kernel32_PEResTab;
    7272}
    73 
    74 extern PFN pfnImSetMsgQueueProperty;
    7573
    7674       ULONG   flAllocMem = 0;    /* flag to optimize DosAllocMem to use all the memory on SMP machines */
     
    8179       BOOL    fInit     = FALSE;
    8280       BOOL    fWin32k   = FALSE;
    83        HMODULE imHandle = 0;
    84        char    szModName[ 256 ] = "";
    8581
    8682/****************************************************************************/
     
    113109        case 0 :
    114110        {
     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
    115118            ParseLogStatusKERNEL32();
    116119
     
    221224            CODEPAGE_Init();
    222225
    223             if( IsDBCSEnv() && DosLoadModule( szModName, sizeof( szModName ), "OS2IM.DLL", &imHandle ) == 0 )
    224                 DosQueryProcAddr( imHandle, 140, NULL, &pfnImSetMsgQueueProperty );
    225 
    226226            InitSystemInfo(ulSysinfo);
    227227            //Set up environment as found in NT
     
    237237            SetProcessAffinityMask(GetCurrentProcess(), dwSystemAffinityMask);
    238238
     239            //Activate current timezone information
     240            TIME_ZONE_INFORMATION tzone;
     241            GetTimeZoneInformation(&tzone);
     242            SetTimeZoneInformation(&tzone);
     243
    239244            //Set default paths for PE & NE loaders
    240245            InitLoaders();
     246           
     247            RasEntry (RAS_EVENT_Kernel32InitComplete, &dllHandle, sizeof (dllHandle));
     248           
    241249            break;
    242250        }
     
    264272    dprintf(("kernel32 exit %d\n", ulReason));
    265273
    266     if( IsDBCSEnv() && imHandle )
    267         DosFreeModule( imHandle );
    268 
    269274    //Flush and delete all open memory mapped files
    270275    Win32MemMap::deleteAll();
    271276    WinExe = NULL;
     277
     278    FinalizeMemMaps();
    272279
    273280    WriteOutProfiles();
     
    281288
    282289    HMTerminate(); /* shutdown handlemanager */
     290
     291#ifdef DEBUG
     292    extern void printCriticalSectionStatistic (void);
     293    printCriticalSectionStatistic ();
     294#endif
    283295
    284296#if defined(DEBUG) && defined(__IBMCPP__) && __IBMCPP__ == 300
     
    298310    //NOTE: Must be done after DestroyTIB
    299311    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
    300316    CloseLogFile();
     317#endif
    301318
    302319    /*
     
    305322    libWin32kSetEnvironment(NULL, 0, 0);
    306323    libWin32kTerm();
     324
     325    RasUninitialize ();
     326   
    307327    return ;
    308328}
  • trunk/src/kernel32/kernel32.mak

    r10382 r21302  
    145145$(OBJDIR)\version.obj \
    146146$(OBJDIR)\mmapnotify.obj \
     147$(OBJDIR)\exceptstackdump.obj \
    147148!ifdef DEBUG
    148 $(OBJDIR)\exceptstackdump.obj \
    149149$(OBJDIR)\dbgwrap.obj \
    150150!endif
     
    159159$(OBJDIR)\conodin32.obj \
    160160$(OBJDIR)\oslibwps.obj \
     161$(OBJDIR)\_ras.obj \
    161162$(OBJDIR)\kernelrsrc.obj
    162163
  • trunk/src/kernel32/kernel32dbg.def

    r10606 r21302  
    147147;  Ordinal0097 = _OS2Ordinal0097@??           @97
    148148;  Ordinal0098 = _OS2Ordinal0098@??           @98
    149    KERNEL32_99 = _KERNEL32_99@4               @99  NONAME
    150    KERNEL32_100 = _KERNEL32_100@12            @100      NONAME
     149                 _KERNEL32_99@4               @99 NONAME
     150                 _KERNEL32_100@12             @100 NONAME
    151151;  Ordinal0101 = _OS2Ordinal0101@??           @101
    152152
     
    10031003    GetVolumeNameForVolumeMountPointW = _DbgGetVolumeNameForVolumeMountPointW@12 @915
    10041004
     1005;
     1006; ENDOFEXPORTS
     1007; Internal function marker
     1008;
    10051009
    10061010;
     
    11601164    InitializeSharedHeap                                          @1276 NONAME
    11611165    DestroySharedHeap                                             @1277 NONAME
     1166    _debug_smalloc                                                @1278 NONAME
     1167    _debug_smallocfill                                            @1279 NONAME
     1168    _debug_sfree                                                  @1280 NONAME
    11621169
    11631170;code memory allocation
     
    12111218    OSLibDosDevIOCtl                                              @2026 NONAME
    12121219
    1213     OSLibImSetMsgQueueProperty                                    @2029 NONAME
    1214 
    12151220    fIsDBCSEnv                                                    @2103 NONAME
     1221    _hookInit@4                                                   @2104 NONAME
    12161222
    12171223    vsnprintfW                            @2030 NONAME
     
    12251231; override TIB switching
    12261232    _ODIN_SetTIBSwitch@4                                          @2102 NONAME
    1227 
    1228     _hookInit@4                                                   @2104 NONAME
    12291233
    12301234    GetDisplayCodepage                                            @3000 NONAME
     
    12521256    _ODIN_SetExceptionHandler@4                                   @3114 NONAME
    12531257    _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
    12541263
    12551264; Char functions (forwarders from user32)
     
    12861295    _DbgIsCharUpperA@4                                               @3159 NONAME
    12871296    _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  
    3131
    3232
    33 // REMARK: THIS IS IN PREPARATION FOR HANDLEMANAGER SUPPORT (PH) !!
    34 //#define HMCreateEvent              O32_CreateEvent
    35 //#define HMCreateMutex              O32_CreateMutex
    36 //#define HMCreateSemaphore          O32_CreateSemaphore
    37 //#define HMSetEvent                 O32_SetEvent
    38 //#define HMReleaseMutex             O32_ReleaseMutex
    39 //#define HMWaitForSingleObject      O32_WaitForSingleObject
    40 //#define HMWaitForSingleObjectEx    O32_WaitForSingleObjectEx
    41 //#define HMGetOverlappedResult      O32_GetOverlappedResult
    42 //#define HMOpenEvent                O32_OpenEvent
    43 //#define HMOpenMutex                O32_OpenMutex
    44 //#define HMOpenSemaphore            O32_OpenSemaphore
    45 //#define HMPulseEvent               O32_PulseEvent
    46 //#define HMReleaseSemaphore         O32_ReleaseSemaphore
    47 //#define HMResetEvent               O32_ResetEvent
    48 //#define HMWaitForMultipleObjects   O32_WaitForMultipleObjects
    49 //#define HMWaitForMultipleObjectsEx O32_WaitForMultipleObjectsEx
    50 //#define HMFlushFileBuffers         O32_FlushFileBuffers
    51 #define HMSetHandleCount           O32_SetHandleCount
    52 #define HMGetHandleCount           O32_GetHandleCount
    53 //#define HMDuplicateHandle          O32_DuplicateHandle
    54 
    55 
    56 
    5733/*****************************************************************************
    5834 * Defines                                                                   *
     
    6440
    6541
    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
    15144
    15245
     
    17467    astring = NULL;
    17568
    176   dprintf(("KERNEL32: CreateMutexW(%s)\n",
    177            astring));
    178 
    179   rc = HMCreateMutex(arg1,
     69  rc = CreateMutexA(arg1,
    18070                     arg2,
    18171                     astring);
     
    18575
    18676  return(rc);
    187 }
    188 
    189 
    190 /*****************************************************************************
    191  * Name      : BOOL ReleaseMutex
    192  * Purpose   : forward call to Open32
    193  * Parameters:
    194  * Variables :
    195  * Result    :
    196  * Remark    : handle translation is done in ReleaseMutex
    197  * 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 SetEvent
    210  * Purpose   : forward call to Open32
    211  * Parameters:
    212  * Variables :
    213  * Result    :
    214  * Remark    : handle translation is done in SetEvent
    215  * 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));
    22377}
    22478
     
    274128}
    275129
    276 
    277 /*****************************************************************************
    278  * Name      : BOOL FlushFileBuffers
    279  * Purpose   : forward call to Open32
    280  * Parameters:
    281  * Variables :
    282  * Result    :
    283  * Remark    : handle translation is done in FlushFileBuffers
    284  * 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 }
    293130
    294131
     
    351188
    352189
    353 /*****************************************************************************
    354  * Name      : BOOL CreateSemaphoreA
    355  * Purpose   : forward call to Open32
    356  * Parameters:
    357  * Variables :
    358  * Result    :
    359  * Remark    : handle translation is done in CreateSemaphoreA
    360  * 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 
    374190
    375191/*****************************************************************************
     
    396212    astring = NULL;
    397213
    398   dprintf(("KERNEL32: CreateSemaphoreW(%s)\n",
    399            astring));
    400 
    401   rc = HMCreateSemaphore(arg1,
     214  rc = CreateSemaphoreA(arg1,
    402215                         arg2,
    403216                         arg3,
     
    409222}
    410223
    411 /*****************************************************************************
    412  * Name      : BOOL OpenEventA
    413  * Purpose   : forward call to Open32
    414  * Parameters:
    415  * Variables :
    416  * Result    :
    417  * Remark    : handle translation is done in OpenEventA
    418  * 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 
    433224
    434225/*****************************************************************************
     
    452243  asciiname = UnicodeToAsciiString((LPWSTR)lpName);
    453244
    454   dprintf(("KERNEL32: OpenEventW(%s)\n",
    455            asciiname));
    456 
    457   rc = HMOpenEvent(dwDesiredAccess,
     245  rc = OpenEventA(dwDesiredAccess,
    458246                   bInheritHandle,
    459247                   asciiname);
     
    464252
    465253/*****************************************************************************
    466  * Name      : BOOL OpenMutexA
    467  * Purpose   : forward call to Open32
    468  * Parameters:
    469  * Variables :
    470  * Result    :
    471  * Remark    : handle translation is done in OpenMutexA
    472  * 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 /*****************************************************************************
    489254 * Name      : BOOL OpenMutexW
    490255 * Purpose   : forward call to Open32
     
    506271  asciiname = UnicodeToAsciiString((LPWSTR)lpName);
    507272
    508   dprintf(("KERNEL32: OpenMutexW(%s)\n",
    509            asciiname));
    510 
    511   rc = HMOpenMutex(dwDesiredAccess,
     273  rc = OpenMutexA(dwDesiredAccess,
    512274                   bInheritHandle,
    513275                   asciiname);
     
    518280
    519281/*****************************************************************************
    520  * Name      : BOOL OpenSemaphoreA
    521  * Purpose   : forward call to Open32
    522  * Parameters:
    523  * Variables :
    524  * Result    :
    525  * Remark    : handle translation is done in OpenSemaphoreA
    526  * 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 /*****************************************************************************
    543282 * Name      : BOOL OpenSemaphoreW
    544283 * Purpose   : forward call to Open32
     
    560299  asciiname = UnicodeToAsciiString((LPWSTR)lpName);
    561300
    562   dprintf(("KERNEL32: OpenSemaphoreW(%s)\n",
    563            asciiname));
    564 
    565   rc = HMOpenSemaphore(dwDesiredAccess,
     301  rc = OpenSemaphoreA(dwDesiredAccess,
    566302                       bInheritHandle,
    567303                       asciiname);
     
    570306}
    571307
    572 
    573 /*****************************************************************************
    574  * Name      : BOOL PulseEvent
    575  * Purpose   : forward call to Open32
    576  * Parameters:
    577  * Variables :
    578  * Result    :
    579  * Remark    : handle translation is done in PulseEvent
    580  * 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 ReleaseSemaphore
    593  * Purpose   : forward call to Open32
    594  * Parameters:
    595  * Variables :
    596  * Result    :
    597  * Remark    : handle translation is done in ReleaseSemaphore
    598  * 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 ResetEvent
    613  * Purpose   : forward call to Open32
    614  * Parameters:
    615  * Variables :
    616  * Result    :
    617  * Remark    : handle translation is done in ResetEvent
    618  * 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 }
    627308
    628309
     
    706387//******************************************************************************
    707388//******************************************************************************
    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  
    6060        }   aLangToLangId[] =
    6161        {
    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) },*/
    180182        };
    181183
     
    199201        int i;
    200202        for (i = 0; i < sizeof(aLangToLangId) / sizeof(aLangToLangId[0]); i++)
    201             if (!stricmp(aLangToLangId[i].pszLang, szLang))
     203            if (!strcmp(aLangToLangId[i].pszLang, szLang))
    202204                return aLangToLangId[i].ulLangId;
    203205
     
    208210        szLang[2] = '\0';
    209211        for (i = 0; i < sizeof(aLangToLangId) / sizeof(aLangToLangId[0]); i++)
    210             if (!stricmp(aLangToLangId[i].pszLang, szLang))
     212            if (!strcmp(aLangToLangId[i].pszLang, szLang))
    211213                return aLangToLangId[i].ulLangId;
    212214
     
    216218        szLang[5] = '\0';
    217219        for (i = 0; i < sizeof(aLangToLangId) / sizeof(aLangToLangId[0]); i++)
    218             if (!stricmp(aLangToLangId[i].pszLang, szLang))
     220            if (!strcmp(aLangToLangId[i].pszLang, szLang))
    219221                return aLangToLangId[i].ulLangId;
    220222
     
    223225         */
    224226        for (i = 0; i < sizeof(aLangToLangId) / sizeof(aLangToLangId[0]); i++)
    225             if (!strnicmp(aLangToLangId[i].pszLang, szLang, 2))
     227            if (!strncmp(aLangToLangId[i].pszLang, szLang, 2))
    226228                return MAKELANGID(PRIMARYLANGID(aLangToLangId[i].ulLangId), SUBLANG_NEUTRAL);
    227229
  • trunk/src/kernel32/lfile.cpp

    r10083 r21302  
    255255 *****************************************************************************/
    256256
    257 UINT WIN32API _lwrite(HFILE arg1,
    258                       LPCSTR arg2,
    259                       UINT  arg3)
     257UINT WIN32API _lwrite(HFILE hFile,
     258                      LPCSTR lpBuffer,
     259                      UINT  cbWrite)
    260260{
    261261   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,
    271271                  &rc,
    272272                  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));
    278277   return rc;
    279278}
  • trunk/src/kernel32/mailslot.cpp

    r7849 r21302  
    1414#include <os2win.h>
    1515#include <string.h>
    16 #include "HandleManager.h"
     16#include <HandleManager.h>
    1717#include <unicode.h>
     18
     19#include "hmhandle.h"
     20#include "hmmailslot.h"
    1821
    1922#define DBG_LOCALLOG    DBG_mailslot
     
    4750                                LPSECURITY_ATTRIBUTES lpSecurityAttributes)
    4851{
    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;
    5078}
     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 *****************************************************************************/
    5195
     96BOOL 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 *****************************************************************************/
     133BOOL 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}
    52152/*****************************************************************************
    53153 * Name      : HANDLE WIN32API CreateMailslotW
     
    80180
    81181  astring = UnicodeToAsciiString((LPWSTR)lpName);
    82   rc = HMCreateMailslotA(astring, nMaxMessageSize, lReadTimeout, lpSecurityAttributes);
     182  rc = CreateMailslotA(astring, nMaxMessageSize, lReadTimeout, lpSecurityAttributes);
    83183  FreeAsciiString(astring);
    84184  return(rc);
    85185}
    86186
    87 /*****************************************************************************
    88  * Name      : BOOL GetMailslotInfo
    89  * Purpose   : The GetMailslotInfo function retrieves information about the
    90  *             specified mailslot.
    91  * Parameters: HANDLE  hMailslot        mailslot handle
    92  *             LPDWORD lpMaxMessageSize address of maximum message size
    93  *             LPDWORD lpNextSize       address of size of next message
    94  *             LPDWORD lpMessageCount   address of number of messages
    95  *             LPDWORD lpReadTimeout    address of read time-out
    96  * Variables :
    97  * Result    : TRUE / FALSE
    98  * Remark    :
    99  * Status    :
    100  *
    101  * Author    : SvL
    102  *****************************************************************************/
    103187
    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 SetMailslotInfo
    116  * Purpose   : The SetMailslotInfo function sets the time-out value used by the
    117  *             specified mailslot for a read operation.
    118  * Parameters: HANDLE hObject       handle to a mailslot object
    119  *             DWORD  dwReadTimeout read time-out
    120  * Variables :
    121  * Result    : TRUE / FALSE
    122  * Remark    :
    123  * Status    :
    124  *
    125  * Author    : SvL
    126  *****************************************************************************/
    127 
    128 BOOL WIN32API SetMailslotInfo(HANDLE hMailslot, DWORD dwReadTimeout)
    129 {
    130   return HMSetMailslotInfo(hMailslot, dwReadTimeout);
    131 }
  • trunk/src/kernel32/mmapview.cpp

    r10369 r21302  
    106106        if(mfAccess & MEMMAP_ACCESS_COPYONWRITE)
    107107        {
     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"));
    108115            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    109116            errorState = 1;
    110117            return;
     118        }
    111119        }
    112120        else
     
    118126        }
    119127    }
     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    }
    120144
    121145    dprintf(("Win32MemMapView::Win32MemMapView: created %x (alias for %x), size %d", pMapView, viewaddr, size));
     
    245269//       PAGEVIEW_READONLY      -> set page flags to readonly
    246270//       PAGEVIEW_VIEW          -> set page flags to view default
     271//       PAGEVIEW_GUARD         -> set page flags of COW view to GUARD
    247272//
    248273// Returns:
     
    264289        ( (flags == PAGEVIEW_GUARD) && !(mfAccess & MEMMAP_ACCESS_COPYONWRITE) ) )
    265290    {
     291        //PAGEVIEW_GUARD only applies to COW views
    266292        //PAGEVIEW_VIEW/READONLY does not apply to COW views
    267293        return TRUE;
     
    289315            accessAttr |= PAG_WRITE;
    290316        }
    291     }
    292 
     317        if(flags == PAGEVIEW_GUARD) {
     318            accessAttr |= PAG_GUARD;
     319        }
     320    }
     321
     322    if(flags == PAGEVIEW_GUARD || (mfAccess & MEMMAP_ACCESS_COPYONWRITE))
    293323    {
     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 {
    294346        rc = OSLibDosSetMem((char *)pMapView+(offset - mOffset), size, accessAttr);
    295347        if(rc) {
  • trunk/src/kernel32/npipe.cpp

    r10132 r21302  
    1919#include "oslibdos.h"
    2020
     21#include "hmhandle.h"
     22#include "hmnpipe.h"
    2123
    2224#define DBG_LOCALLOG    DBG_npipe
     
    2527ODINDEBUGCHANNEL(KERNEL32-NPIPE)
    2628
    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 }
    3529//******************************************************************************
    3630//******************************************************************************
     
    4539  {
    4640        sprintf(szPipeName, "\\\\.\\pipe\\Win32.Pipes.%08x.%08x", GetCurrentProcessId(), GetCurrentTime());
    47         hPipeRead = ::CreateNamedPipeA(szPipeName, PIPE_ACCESS_DUPLEX,
     41        hPipeRead = ::CreateNamedPipeA(szPipeName, PIPE_ACCESS_INBOUND,
    4842                                     PIPE_TYPE_BYTE | PIPE_WAIT, 1, cbPipe, cbPipe,
    4943                                     NMPWAIT_USE_DEFAULT_WAIT, lpsa);
     
    8478  return TRUE;
    8579}
    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 *****************************************************************************/
     92HANDLE WIN32API CreateNamedPipeA(LPCTSTR lpName,
     93                                 DWORD   dwOpenMode,
     94                                 DWORD   dwPipeMode,
     95                                 DWORD   nMaxInstances,
     96                                 DWORD   nOutBufferSize,
     97                                 DWORD   nInBufferSize,
     98                                 DWORD   nDefaultTimeOut,
    9199                                 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
     152BOOL 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
     185BOOL 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 *****************************************************************************/
     214BOOL 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
     262BOOL 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
     309BOOL 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 *****************************************************************************/
     354BOOL 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
     403BOOL 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
    104428//******************************************************************************
    105429//******************************************************************************
     
    114438  asciiname  = UnicodeToAsciiString((LPWSTR)lpName);
    115439
    116   hPipe=HMCreateNamedPipe(asciiname,
     440  hPipe=CreateNamedPipeA(asciiname,
    117441                          dwOpenMode,
    118442                          dwPipeMode,
     
    126450
    127451  return(hPipe);
    128 }
    129 //******************************************************************************
    130 //******************************************************************************
    131 
    132 
    133 /*****************************************************************************
    134  * Name      : BOOL WIN32API ConnectNamedPipe
    135  * Purpose   : The ConnectNamedPipe function enables a named pipe server process
    136  *             to wait for a client process to connect to an instance of a
    137  *             named pipe. A client process connects by calling either the
    138  *             CreateFile or CallNamedPipe function.
    139  * Parameters:  HANDLE hNamedPipe      handle to named pipe to connect
    140  *              LPOVERLAPPED lpOverlapped  pointer to overlapped structure
    141  * 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 TESTED
    147  *
    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));
    153452}
    154453
     
    263562}
    264563
    265 /*****************************************************************************
    266  * Name      : BOOL WIN32API DisconnectNamedPipe
    267  * Purpose   : The DisconnectNamedPipe function disconnects the server end
    268  *             of a named pipe instance from a client process.
    269  * Parameters: HANDLE hNamedPipe    handle to named pipe
    270  * Variables :
    271  * Result    : If the function succeeds, the return value is nonzero.
    272  *             If the function fails, the return value is zero
    273  * Remark    :
    274  * Status    : NOT FULLY TESTED
    275  *
    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 GetNamedPipeHandleStateA
    286  * Purpose   : The GetNamedPipeHandleStateA function retrieves information about
    287  *             a specified named pipe. The information returned can vary during
    288  *             the lifetime of an instance of the named pipe.
    289  * Parameters: HANDLE  hNamedPipe           handle of named pipe
    290  *             LPDWORD lpState              address of flags indicating pipe state
    291  *             LPDWORD lpCurInstances       address of number of current pipe instances
    292  *             LPDWORD lpMaxCollectionCount address of max. bytes before remote transmission
    293  *             LPDWORD lpCollectDataTimeout address of max. time before remote transmission
    294  *             LPTSTR  lpUserName           address of user name of client process
    295  *             DWORD   nMaxUserNameSize     size, in characters, of user name buffer
    296  * Variables :
    297  * Result    : TRUE / FALSE
    298  * Remark    :
    299  * Status    : UNTESTED STUB
    300  *
    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.cpp
    313   return ( HMGetNamedPipeHandleState( hNamedPipe,
    314                                        lpState,
    315                                        lpCurInstances,
    316                                        lpMaxCollectionCount,
    317                                        lpCollectDataTimeout,
    318                                        lpUserName,
    319                                        nMaxUserNameSize));
    320 }
    321 
    322564
    323565/*****************************************************************************
     
    355597
    356598  // Not implemented but waiting to implementation in hmnpipe.cpp
    357   rc= HMGetNamedPipeHandleState( hNamedPipe,
     599  rc= GetNamedPipeHandleStateA( hNamedPipe,
    358600                                  lpState,
    359601                                  lpCurInstances,
     
    367609
    368610  return (rc);
    369 }
    370 
    371 
    372 /*****************************************************************************
    373  * Name      : BOOL GetNamedPipeInfo
    374  * Purpose   : The GetNamedPipeInfo function retrieves information about the specified named pipe.
    375  * Parameters: HANDLE  hNamedPipe      handle of named pipe
    376  *             LPDWORD lpFlags         address of flags indicating type of pipe
    377  *             LPDWORD lpOutBufferSize address of size, in bytes, of pipe's output buffer
    378  *             LPDWORD lpInBufferSize  address of size, in bytes, of pipe's input buffer
    379  *             LPDWORD lpMaxInstances  address of max. number of pipe instances
    380  * Variables :
    381  * Result    : TRUE / FALSE
    382  * Remark    :
    383  * Status    : UNTESTED STUB
    384  *
    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.cpp
    395   return ( HMGetNamedPipeInfo( hNamedPipe,
    396                                lpFlags,
    397                                lpOutBufferSize,
    398                                lpInBufferSize,
    399                                lpMaxInstances));
    400 
    401 }
    402 
    403 /*****************************************************************************
    404  * Name      : BOOL SetNamedPipeHandleState
    405  * Purpose   : The SetNamedPipeHandleState function sets the read mode and the
    406  *             blocking mode of the specified named pipe. If the specified handle
    407  *             is to the client end of a named pipe and if the named pipe server
    408  *             process is on a remote computer, the function can also be used to
    409  *             control local buffering.
    410  * Parameters: HANDLE  hNamedPipe     handle of named pipe
    411  *             LPDWORD lpdwMode       address of new pipe mode
    412  *             LPDWORD lpcbMaxCollect address of max. bytes before remote transmission
    413  *             LPDWORD lpdwCollectDataTimeout address of max. time before remote transmission
    414  * Variables :
    415  * Result    : TRUE / FALSE
    416  * Remark    :
    417  * Status    : UNTESTED STUB
    418  *
    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.cpp
    428   return ( HMSetNamedPipeHandleState( hNamedPipe,
    429                                lpdwMode,
    430                                lpcbMaxCollect,
    431                                lpdwCollectDataTimeout));
    432 }
    433 
    434 /*****************************************************************************
    435  * Name      : BOOL TransactNamedPipe
    436  * Purpose   : The TransactNamedPipe function combines into a single network
    437  *             operation the functions that write a message to and read a
    438  *             message from the specified named pipe.
    439  * Parameters: HANDLE       hNamedPipe  handle of named pipe
    440  *             LPVOID       lpvWriteBuf address of write buffer
    441  *             DWORD        cbWriteBuf  size of the write buffer, in bytes
    442  *             LPVOID       lpvReadBuf  address of read buffer
    443  *             DWORD        cbReadBuf   size of read buffer, in bytes
    444  *             LPDWORD      lpcbRead    address of variable for bytes actually read
    445  *             LPOVERLAPPED lpo         address of overlapped structure
    446  * Variables :
    447  * Result    : TRUE / FALSE
    448  * 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));
    469611}
    470612
  • trunk/src/kernel32/ole2nls.c

    r9975 r21302  
    19121912    }
    19131913
     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
    19141924    if (mapflags & LCMAP_UPPERCASE)
    19151925      f = toupper;
    19161926    else if (mapflags & LCMAP_LOWERCASE)
    19171927      f = tolower;
     1928#endif
    19181929    if (f)
    19191930    {
  • trunk/src/kernel32/os2heap.cpp

    r8877 r21302  
    4141#include "dbglocal.h"
    4242
     43#include <_ras.h>
     44
     45#ifdef RAS
     46RAS_TRACK_HANDLE rthHeap = 0;
     47#endif
     48
    4349#ifndef HEAP_NO_SERIALIZE
    4450  #define HEAP_NO_SERIALIZE 1
     
    94100    else  heap = this;
    95101    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
    96111
    97112    heaplistmutex.leave();
     
    173188        return(NULL);
    174189    }
     190   
     191    RasTrackMemAlloc (rthHeap, dwAllocBytes);
     192   
    175193    if(dwFlags & HEAP_ZERO_MEMORY) {
    176194        memset(lpMem, 0, dwAllocBytes+HEAP_OVERHEAD);
     
    238256    if (dwBytes <= maxSize) {
    239257        dprintf(("ReAlloc with smaller size than original (%d); return old pointer", maxSize));
     258       
     259        RasTrackMemRealloc (rthHeap, helem->cursize, dwBytes);
     260       
    240261        //update current size so HeapSize will return the right value
    241262        helem->cursize = dwBytes; 
     
    280301#endif
    281302
     303    RasTrackMemFree (rthHeap, helem->cursize);
     304
    282305    free(helem->lpMem);
     306   
    283307    return(TRUE);
    284308}
  • trunk/src/kernel32/oslibdos.cpp

    r10132 r21302  
    265265    case ERROR_WRONG_DISK: //34
    266266        return ERROR_WRONG_DISK_W;
     267
     268    case ERROR_BAD_NETPATH: //53
     269        return ERROR_BAD_NETPATH_W;
    267270
    268271    case ERROR_SHARING_BUFFER_EXCEEDED: //36
     
    10451048      // @@@AH 2001-06-02 Win2k SP2 returns error 2 in this case
    10461049      int winError = error2WinError(rc);
    1047       if (winError == ERROR_OPEN_FAILED_W || winError == ERROR_PATH_NOT_FOUND_W)
     1050      if (winError == ERROR_OPEN_FAILED_W)
    10481051      {
    10491052          //Windows returns ERROR_FILE_EXISTS if create new & file exists
     
    23832386{
    23842387   FILESTATUS3 statusBuf;
    2385    char        lOemFileName[CCHMAXPATH];
     2388   char        *lOemFileName;
    23862389   char       *lpszBackslash, *lpszColon;
    23872390   APIRET      rc;
    23882391
    2389 //testestest
    2390    if(strlen(lpFileName) > CCHMAXPATH) DebugInt3();
    2391 //testestset
     2392   lOemFileName = (char *)malloc(strlen(lpFileName)+64);
     2393   lOemFileName[0] = 0;
    23922394
    23932395   //Convert file name from Windows to OS/2 codepage
     
    23992401       {
    24002402           lpszColon = CharPrevA(lOemFileName, lpszBackslash);
    2401            if(lpszColon && *lpszColon != ':')
     2403           if(strlen(lOemFileName) > 1 && lpszColon && *lpszColon != ':')
    24022404           {//only rootdir is allowed to have terminating backslash
    24032405               *lpszBackslash = 0;
     
    24202422           rc = DosQueryPathInfo(lOemFileName, FIL_STANDARD, &statusBuf, sizeof(statusBuf));
    24212423   }
     2424   free(lOemFileName);
    24222425
    24232426   if(rc == NO_ERROR)
  • trunk/src/kernel32/oslibexcept.cpp

    r5905 r21302  
    171171  case XCPT_ILLEGAL_INSTRUCTION:
    172172  case XCPT_PRIVILEGED_INSTRUCTION:
     173  case XCPT_INTEGER_DIVIDE_BY_ZERO:
     174  case XCPT_UNABLE_TO_GROW_STACK:
    173175#ifndef DEBUG
    174176  case XCPT_BREAKPOINT:
     
    180182  case XCPT_BREAKPOINT:
    181183#endif
    182   case XCPT_INTEGER_DIVIDE_BY_ZERO:
    183184  case XCPT_INTEGER_OVERFLOW:
    184185  case XCPT_SINGLE_STEP:
     
    187188  case XCPT_INVALID_LOCK_SEQUENCE:
    188189  case XCPT_GUARD_PAGE_VIOLATION:
    189   case XCPT_UNABLE_TO_GROW_STACK:
    190190  case XCPT_IN_PAGE_ERROR:
    191191  default:
  • trunk/src/kernel32/oslibmem.cpp

    r9945 r21302  
    3232#include <winconst.h>
    3333#include <win\winioctl.h>
    34 #include <misc.h>
     34#include <dbglog.h>
     35#include <vmutex.h>
    3536#include "initterm.h"
    3637#include "oslibdos.h"
     
    3839#include "dosqss.h"
    3940#include "win32k.h"
     41#include "exceptstackdump.h"
    4042
    4143#define DBG_LOCALLOG    DBG_oslibmem
    4244#include "dbglocal.h"
    4345
     46#include <_ras.h>
     47
     48#ifdef RAS
     49RAS_TRACK_HANDLE rthVirtual = 0;
     50
     51void 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
     59typedef struct _VirtAllocRec {
     60  ULONG baseaddr;
     61  ULONG size;
     62  ULONG attr;
     63
     64  struct _VirtAllocRec *next;
     65} VirtAllocRec;
     66
     67static VirtAllocRec         *allocrecords  = NULL;
     68static CRITICAL_SECTION_OS2  alloccritsect = {0};
     69
     70//******************************************************************************
     71//******************************************************************************
     72void 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//******************************************************************************
     106void 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//******************************************************************************
     139BOOL 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}
    44162//******************************************************************************
    45163//TODO: Check if this works for code aliases...
     
    83201        pAlias += size;
    84202    }
     203    AddAllocRec((ULONG)*ppbAlias, cb, fl);
    85204    return 0;
    86205}
     
    99218        fMemFlags = 0;
    100219    }
     220   
    101221    /*
    102222     * Let's try use the extended DosAllocMem API of Win32k.sys.
     
    105225    {
    106226        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
    107233        if (rc != ERROR_NOT_SUPPORTED)  /* This call was stubbed until recently. */
    108234            return rc;
     
    132258            return rc;
    133259        }
     260       
     261        PVOID baseAddr = (PVOID)addr64kb; // sunlover20040613: save returned address for a possible Free on failure
     262       
    134263        dprintf(("Allocate aligned memory %x -> %x", addr64kb, (addr64kb + 0xFFFF) & ~0xFFFF));
    135264
     
    144273            if(rc) {
    145274                dprintf(("!ERROR!: DosSetMem failed with rc %d", rc));
     275                DosFreeMem (baseAddr); // sunlover20040613: Free allocated memory
    146276                return rc;
    147277            }
     
    149279    }
    150280
    151     if(!rc)
     281    if(!rc) {
    152282        *lplpMemAddr = pvMemAddr;
    153 
     283        AddAllocRec((ULONG)pvMemAddr, cbSize, flFlags);
     284        RasAddObject (rthVirtual, (ULONG)*lplpMemAddr, NULL, cbSize);
     285    }
    154286    return rc;
    155287}
     
    157289//Locate the base page of a memory allocation (the page with the PAG_BASE attribute)
    158290//******************************************************************************
    159 PVOID OSLibDosFindMemBase(LPVOID lpMemAddr)
    160 {
    161     ULONG  ulAttr, ulSize, ulAddr;
     291PVOID OSLibDosFindMemBase(LPVOID lpMemAddr, DWORD *lpAttr)
     292{
     293    ULONG  ulAttr, ulSize, ulAddr, ulBase;
    162294    APIRET rc;
     295    VirtAllocRec *allocrec;
     296
     297    *lpAttr = 0;
    163298   
     299    if(FindAllocRec((ULONG)lpMemAddr, &ulBase, &ulSize, lpAttr) == TRUE) {
     300        return (PVOID)ulBase;
     301    }
     302   
     303    ulSize = PAGE_SIZE;
    164304    rc = DosQueryMem(lpMemAddr, &ulSize, &ulAttr);
    165305    if(rc != NO_ERROR) {
     
    226366        dprintf(("!ERROR!: OSLibDosFreeMem: Unable to find base of %x", lpMemAddr));
    227367        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);
    233375}
    234376//******************************************************************************
  • trunk/src/kernel32/oslibmem.h

    r9617 r21302  
    5252DWORD OSLibDosAllocSharedMem(LPVOID *lplpMemAddr, DWORD size, DWORD flags, LPSTR name);
    5353DWORD OSLibDosGetNamedSharedMem(LPVOID *lplpMemAddr, LPSTR name);
    54 PVOID OSLibDosFindMemBase(LPVOID lpMemAddr);
     54PVOID OSLibDosFindMemBase(LPVOID lpMemAddr, DWORD *lpAttr);
    5555
    5656#ifdef __cplusplus
  • trunk/src/kernel32/oslibmisc.cpp

    r10606 r21302  
    2424#include "oslibmisc.h"
    2525#include <misc.h>
    26 #include <heapstring.h>
    2726
    2827#define DBG_LOCALLOG    DBG_oslibmisc
    2928#include "dbglocal.h"
    30 
    31 typedef APIRET ( APIENTRY *PFN_IMSETMSGQUEUEPROPERTY )( HMQ, ULONG );
    32 
    33 PFN_IMSETMSGQUEUEPROPERTY pfnImSetMsgQueueProperty = NULL;
    3429
    3530//******************************************************************************
     
    344339//******************************************************************************
    345340//******************************************************************************
    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 
     341void OSLibSetBeginLibpath(char *lpszBeginlibpath)
     342{
     343    DosSetExtLIBPATH(lpszBeginlibpath, BEGIN_LIBPATH);
     344}
     345//******************************************************************************
     346//******************************************************************************
     347void OSLibQueryBeginLibpath(char *lpszBeginlibpath, int size)
     348{
     349    DosQueryExtLIBPATH(lpszBeginlibpath, BEGIN_LIBPATH);
     350}
     351//******************************************************************************
     352//******************************************************************************
     353
  • trunk/src/kernel32/oslibmisc.h

    r10606 r21302  
    100100ULONG OSLibQueryCountry();
    101101
    102 ULONG OSLibImSetMsgQueueProperty( ULONG hmq, ULONG ulFlag );
     102void OSLibSetBeginLibpath(char *lpszBeginlibpath);
     103void OSLibQueryBeginLibpath(char *lpszBeginlibpath, int size);
    103104
    104105#ifdef __cplusplus
  • trunk/src/kernel32/oslibthread.cpp

    r9945 r21302  
    123123    if(rc != NO_ERROR) {
    124124        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) {
    126127            DosSleep(50);
    127128            goto tryagain;
    128129        }
     130        DebugInt3();
    129131        SetLastError(error2WinError(rc, ERROR_INVALID_PARAMETER));
    130132        return FALSE;
  • trunk/src/kernel32/registry.cpp

    r10624 r21302  
    712712}
    713713
    714 /*****************************************************************************
    715  * Name      :
    716  * Purpose   :
    717  * Parameters:
    718  * Variables :
    719  * Result    :
    720  * Remark    :
    721  * Status    : UNTESTED STUB
    722  *
    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 }
    742714
    743715/*****************************************************************************
  • trunk/src/kernel32/thread.cpp

    r10606 r21302  
    3434#include <handlemanager.h>
    3535#include <codepage.h>
    36 #include <heapstring.h>
     36
     37#include "hmhandle.h"
     38#include "hmthread.h"
     39#include <kbdhook.h>
    3740
    3841#include <FastInfoBlocks.h>
     42#include <custombuild.h>
    3943
    4044#define DBG_LOCALLOG    DBG_thread
     
    4549static ULONG priorityclass = NORMAL_PRIORITY_CLASS;
    4650
     51//******************************************************************************
     52//******************************************************************************
     53HANDLE 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 *****************************************************************************/
     73HANDLE 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 *****************************************************************************/
     118INT 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 *****************************************************************************/
     146DWORD 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 *****************************************************************************/
     174BOOL 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 *****************************************************************************/
     201BOOL 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 *****************************************************************************/
     229BOOL 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 *****************************************************************************/
     256BOOL 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 *****************************************************************************/
     288BOOL 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 *****************************************************************************/
     316DWORD 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 *****************************************************************************/
     345BOOL 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 *****************************************************************************/
     373BOOL 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}
    47389//******************************************************************************
    48390//******************************************************************************
     
    312654    }
    313655}
    314 
    315 #define MQP_INSTANCE_PERMQ              0x00000001 // from os2im.h
    316656//******************************************************************************
    317657//******************************************************************************
     
    320660    EXCEPTION_FRAME  exceptFrame;
    321661    Win32Thread     *me = (Win32Thread *)lpData;
     662    ULONG            dwFlags = me->dwFlags;
    322663    ULONG            threadCallback = (ULONG)me->pCallback;
    323664    LPVOID           userdata  = me->lpUserData;
     
    334675    dprintf(("Win32ThreadProc: Thread handle 0x%x, thread id %d", GetCurrentThread(), GetCurrentThreadId()));
    335676
    336     winteb->flags = me->dwFlags;
     677    winteb->flags = dwFlags;
    337678
    338679    winteb->entry_point = (void *)threadCallback;
     
    343684    winteb->o.odin.hmq = OSLibWinQueryMsgQueue(winteb->o.odin.hab);
    344685    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);
    346688
    347689    dprintf(("Win32ThreadProc: hab %x hmq %x", winteb->o.odin.hab, winteb->o.odin.hmq));
    348690    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 );
    353691
    354692    //Note: The Win32 exception structure referenced by FS:[0] is the same
     
    389727    }
    390728    else {
     729        hookKill(winteb->o.odin.hab);
    391730        HMSetThreadTerminated(GetCurrentThread());
    392731        winteb->o.odin.exceptFrame = 0;
     
    416755 * @param   fForceFSSwitch      If set we will force switching to Odin32 FS selector.
    417756 *                              If clear it depends on defaults.
     757 * @deprecated
    418758 */
    419759USHORT WIN32API ODIN_ThreadEnterOdinContext(void *pExceptionRegRec, BOOL fForceFSSwitch)
     
    429769    if (!pTeb)
    430770    {
    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)
    435774        {
    436775            dprintf(("ODIN_ThreadEnterOdinContext: Failed to create TEB!"));
     
    471810 * @param   fForceFSSwitch      If set we will force switching to Odin32 FS selector.
    472811 *                              If clear it depends on defaults.
     812 * @deprecated
    473813 */
    474814void   WIN32API ODIN_ThreadLeaveOdinContext(void *pExceptionRegRec, USHORT selFSOld)
     
    505845 *                              Must be located on the callers stack.
    506846 * @param   fRemoveOdinExcpt    Remove the odin exception handler.
     847 * @deprecated
    507848 */
    508849USHORT WIN32API ODIN_ThreadLeaveOdinContextNested(void *pExceptionRegRec, BOOL fRemoveOdinExcpt)
     
    551892 * @param   selFSOld            The Odin FS selector returned by the Nested Leave api.
    552893 *
     894 * @deprecated
    553895 */
    554896void   WIN32API ODIN_ThreadEnterOdinContextNested(void *pExceptionRegRec, BOOL fRestoreOdinExcpt, USHORT selFSOld)
     
    578920
    579921
     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 */
     927void    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 */
     997void    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  
    1919#include <odinwrap.h>
    2020#include <os2sel.h>
     21#include <FastInfoBlocks.h>
    2122
    2223#include <os2win.h>
     
    9394
    9495    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));
    9697    return ret;
    9798}
     
    153154    }
    154155    O32_GetSystemTime(lpSystemTime);
     156    dprintf2(("time: %d-%d-%d %02d:%02d:%02d", lpSystemTime->wDay, lpSystemTime->wMonth, lpSystemTime->wYear, lpSystemTime->wHour, lpSystemTime->wMinute, lpSystemTime->wSecond));
    155157}
    156158//******************************************************************************
     
    245247        RegCloseKey(hkey);
    246248
    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;
    249259    }
    250260    else
     
    262272        lstrcpynAtoW(lpTimeZone->DaylightName, (LPSTR)tzone.DaylightName, len);
    263273        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));
    264282        return ret;
    265283    }
     
    312330 * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
    313331 *****************************************************************************/
    314 
    315332VOID WIN32API GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
    316333{
     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
    317363    SYSTEMTIME st;
    318 
    319364    GetSystemTime(&st);
    320365    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  
    77 * Copyright 1998 Knut St. Osmundsen
    88 * Copyright 1998 Peter FitzSimmons
     9 * Copyright 2002-2003 Innotek Systemberatung GmbH (sandervl@innotek.de)
    910 *
    1011 * Parts (VIRTUAL_MapFileA/W) based on Wine code (memory\virtual.c):
     
    267268    return hMapping;
    268269}
    269 
    270 //******************************************************************************
     270//******************************************************************************
     271// Translate OS2 page attributes to Windows attribute, state and type values
     272//******************************************************************************
     273void 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//******************************************************************************
     320void 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!
    271344//******************************************************************************
    272345LPVOID WIN32API VirtualAlloc(LPVOID lpvAddress,
     
    280353    DWORD rc;
    281354
    282     SetLastError(ERROR_SUCCESS);
    283 
    284355    if (cbSize > 0x7fc00000)  /* 2Gb - 4Mb */
    285356    {
     
    289360    }
    290361
     362    // We're ignoring MEM_TOP_DOWN for now
    291363    if (!(fdwAllocationType & (MEM_COMMIT | MEM_RESERVE)) ||
    292        (fdwAllocationType & ~(MEM_COMMIT | MEM_RESERVE)))
     364       (fdwAllocationType & ~(MEM_COMMIT | MEM_RESERVE | MEM_TOP_DOWN)))
    293365    {
    294366        dprintf(("VirtualAlloc: Invalid parameter"));
     
    308380        cbSize += PAGE_SIZE;
    309381
     382    //Translate windows page attributes (flag is reset to 0!!)
     383    TranslateWinPageAttr(fdwProtect, &flag);
     384
    310385    if(fdwAllocationType & MEM_COMMIT)
    311386    {
    312387        dprintf(("VirtualAlloc: commit\n"));
    313         flag = PAG_COMMIT;
     388        flag |= PAG_COMMIT;
    314389    }
    315390
     
    322397        // it will have the old (alloc time) attributes
    323398        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/2
    327     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;
    337399    }
    338400   
     
    470532
    471533    dprintf(("VirtualAlloc returned %X\n", Address));
    472     SetLastError(ERROR_SUCCESS);
    473534    return(Address);
    474535}
    475536//******************************************************************************
     537//NOTE: Do NOT set the last error to ERROR_SUCCESS if successful. Windows
     538//      does not do this either!
    476539//******************************************************************************
    477540BOOL WIN32API VirtualFree(LPVOID lpvAddress,
     
    481544    DWORD rc;
    482545
    483     SetLastError(ERROR_SUCCESS);
    484 
    485546    // verify parameters
    486547    if((FreeType & MEM_RELEASE) && (cbSize != 0))
     
    496557        SetLastError(ERROR_INVALID_PARAMETER);
    497558        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;
    498568    }
    499569
     
    579649    }
    580650    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);
    608654
    609655    dprintf(("New memory flags %X\n", pageFlags));
     
    658704
    659705    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    }
    660713    if(rc)
    661714    {
     
    672725    pmbiBuffer->RegionSize  = (cbRangeSize + 0xFFF) & 0xFFFFF000;
    673726
    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);
    704728
    705729    //TODO: This is not correct: AllocationProtect should contain the protection
    706730    //      flags used in the initial call to VirtualAlloc
    707731    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    }
    710736    dprintf(("Memory region alloc base          0x%08x", pmbiBuffer->AllocationBase));
    711737    dprintf(("Memory region alloc protect flags %x", pmbiBuffer->AllocationProtect));
     
    725751    return TRUE;
    726752}
    727 
     753//******************************************************************************
    728754//******************************************************************************
    729755BOOL WIN32API VirtualUnlock(LPVOID lpAddress, DWORD dwSize)
     
    802828
    803829//******************************************************************************
    804 //SvL: Private api
     830// Private Odin api
    805831//******************************************************************************
    806832LPVOID VirtualAllocShared(DWORD cbSize, DWORD  fdwAllocationType,
     
    828854  }
    829855
     856  //Translate windows page attributes (flag is reset to 0!!)
     857  TranslateWinPageAttr(fdwProtect, &flag);
     858
    830859  if(fdwAllocationType & MEM_COMMIT)
    831860  {
    832861        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;
    848863  }
    849864
     
    867882  return(Address);
    868883}
     884//******************************************************************************
     885//******************************************************************************
  • trunk/src/kernel32/windllbase.cpp

    r10590 r21302  
    708708        PROFILE_SetOdinIniString(DLLRENAMEOS2_SECTION, "CRTDLL32", "CRTDLL");
    709709    }
    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     }
    716710}
    717711//******************************************************************************
  • trunk/src/kernel32/winexedummy.cpp

    r10397 r21302  
    3434BOOL WIN32API RegisterDummyExe(LPSTR pszExeName)
    3535{
    36     if(WinExe != NULL) //should never happen
    37         delete(WinExe);
     36    if(WinExe != NULL)
     37        return TRUE;
    3838
    3939    Win32DummyExe *winexe;
  • trunk/src/kernel32/wprocess.cpp

    r10481 r21302  
    6767ODINDEBUGCHANNEL(KERNEL32-WPROCESS)
    6868
     69
     70//environ.cpp
     71char *CreateNewEnvironment(char *lpEnvironment);
    6972
    7073/*******************************************************************************
     
    19061909 STARTUPINFOA startinfo;
    19071910 TEB *pThreadDB = (TEB*)GetThreadTEB();
    1908  char *cmdline = NULL, *newenv = NULL;
     1911 char *cmdline = NULL, *newenv = NULL, *oldlibpath = NULL;
    19091912 BOOL  rc;
    19101913
     
    19391942
    19401943        memcpy(&startinfo, lpStartupInfo, sizeof(startinfo));
     1944        if(lpStartupInfo->hStdInput) {
    19411945        retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdInput, &startinfo.hStdInput);
     1946        }
     1947        if(lpStartupInfo->hStdOutput) {
    19421948        retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdOutput, &startinfo.hStdOutput);
     1949        }
     1950        if(lpStartupInfo->hStdError) {
    19431951        retcode |= HMHandleTranslateToOS2(lpStartupInfo->hStdError, &startinfo.hStdError);
     1952        }
    19441953
    19451954        if(retcode) {
     
    20192028                 break;
    20202029             }
    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             }
    20222038             if(fTerminate) {
    20232039                  *exename = ' ';
     
    20392055    }
    20402056
     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
    20412067    DWORD Characteristics, SubSystem, fNEExe, fPEExe;
    20422068
     
    20502076    if(!fPEExe || (fPEExe && fWin32k))
    20512077    {
     2078
     2079    trylaunchagain:
    20522080      if(O32_CreateProcess(szAppName, lpCommandLine, lpProcessAttributes,
    20532081                         lpThreadAttributes, bInheritHandles, dwCreationFlags,
     
    20782106        goto finished;
    20792107      }
    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        }
    20812128      // verify why O32_CreateProcess actually failed.
    20822129      // If GetLastError() == 191 (ERROR_INVALID_EXE_SIGNATURE)
     
    21022149    if(fPEExe)
    21032150    {
    2104       char *lpszPE;
    2105       char *lpszExecutable;
     2151      LPCSTR    lpszExecutable;
    21062152      int  iNewCommandLineLength;
    21072153
     
    21102156
    21112157      if(SubSystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
    2112         lpszExecutable = (LPSTR)szPECmdLoader;
     2158        lpszExecutable = szPECmdLoader;
    21132159      else
    2114         lpszExecutable = (LPSTR)szPEGUILoader;
    2115 
    2116       lpszPE = lpszExecutable;
     2160        lpszExecutable = szPEGUILoader;
    21172161
    21182162      // 2002-04-24 PH
    21192163      // set the ODIN32.DEBUG_CHILD environment variable to start new PE processes
    21202164      // under a new instance of the (IPMD) debugger.
     2165      const char *pszDebugChildArg = "";
    21212166#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)
    21252170      {
    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;
    21372181      }
    21382182#endif
     
    21442188
    21452189            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);
    21472191            free(cmdline);
    21482192            cmdline = newcmdline;
     
    21522196
    21532197            newcmdline = (char *)malloc(iNewCommandLineLength + 16);
    2154             sprintf(newcmdline, " %s %s", szAppName, lpCommandLine);
     2198            sprintf(newcmdline, "%s %s %s", pszDebugChildArg, szAppName, lpCommandLine);
    21552199            free(cmdline);
    21562200            cmdline = newcmdline;
     
    21922236                               lpProcessInfo);
    21932237    }
     2238    if(!lpEnvironment) {
     2239        // Restore old ENDLIBPATH variable
     2240        // TODO:
     2241    }
     2242
    21942243    if(rc == TRUE)
    21952244    {
     
    22222271finished:
    22232272
     2273    if(oldlibpath) {
     2274        OSLibSetBeginLibpath(oldlibpath);
     2275        free(oldlibpath);
     2276    }
    22242277    if(cmdline) free(cmdline);
    22252278    if(newenv)  free(newenv);
Note: See TracChangeset for help on using the changeset viewer.