Changeset 4285 for trunk/src/kernel32/HandleManager.cpp
- Timestamp:
- Sep 20, 2000, 11:32:58 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r4256 r4285 1 /* $Id: HandleManager.cpp,v 1. 49 2000-09-13 21:10:56 sandervlExp $ */1 /* $Id: HandleManager.cpp,v 1.50 2000-09-20 21:32:50 hugh Exp $ */ 2 2 3 3 /* … … 12 12 */ 13 13 14 #undef DEBUG_LOCAL15 //#define DEBUG_LOCAL14 //#undef DEBUG_LOCAL 15 #define DEBUG_LOCAL 16 16 17 17 … … 63 63 #include <vmutex.h> 64 64 65 #define DBG_LOCALLOG 65 #define DBG_LOCALLOG DBG_handlemanager 66 66 #include "dbglocal.h" 67 67 … … 78 78 *****************************************************************************/ 79 79 80 typedef struct _HMDEVICE; 80 81 81 82 typedef struct _HMHANDLE … … 92 93 LPSTR pszDeviceName; /* name or alias of the pseudo-device */ 93 94 HMDeviceHandler *pDeviceHandler; /* handler for this pseudo-device */ 95 VOID *pDevData; /* Pointer To Device data */ 94 96 } HMDEVICE, *PHMDEVICE; 95 97 … … 155 157 static ULONG _Optlink _HMHandleQuery(HANDLE hHandle); 156 158 159 // Get GlobalDeviceData 160 static VOID *_HMDeviceGetData (LPSTR pszDeviceName); 157 161 158 162 … … 199 203 return (HMGlobals.pHMOpen32); /* haven't found anything, return default */ 200 204 } 201 205 /***************************************************************************** 206 * Name : static VOID *_HMDeviceGetData 207 * Purpose : obtain pointer to device data from the table by searching 208 * for a device name or alias 209 * Parameters: PSZ pszDeviceName 210 * Variables : 211 * Result : VOID * - pointer to the handlers device data 212 * Remark : 213 * Status : 214 * 215 * Author : Markus Montkowski 216 *****************************************************************************/ 217 218 static VOID *_HMDeviceGetData (LPSTR pszDeviceName) 219 { 220 PHMDEVICE pHMDevice; /* iterator over the device table */ 221 222 if (pszDeviceName != NULL) 223 for (pHMDevice = TabWin32Devices; /* loop over all devices in the table */ 224 pHMDevice != NULL; 225 pHMDevice = pHMDevice->pNext) 226 { 227 if (stricmp(pHMDevice->pszDeviceName, /* case-insensitive search */ 228 pszDeviceName) == 0) 229 return (pHMDevice->pDevData); /* OK, we've found our device */ 230 } 231 232 return (NULL); /* haven't found anything, return NULL */ 233 } 202 234 203 235 /***************************************************************************** … … 227 259 /* free handle found ? */ 228 260 if (INVALID_HANDLE_VALUE == TabWin32Handles[ulLoop].hmHandleData.hHMHandle) { 229 TabWin32Handles[ulLoop].hmHandleData.dwUserData = 0; 230 TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN; 231 handleMutex.leave(); 232 return (ulLoop); /* OK, then return it to the caller */ 261 TabWin32Handles[ulLoop].hmHandleData.dwUserData = 0; 262 TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN; 263 TabWin32Handles[ulLoop].hmHandleData.lpDeviceData = NULL; 264 handleMutex.leave(); 265 return (ulLoop); /* OK, then return it to the caller */ 233 266 } 234 267 } … … 261 294 } 262 295 263 264 296 /***************************************************************************** 265 297 * Name : static int _HMHandleQuery … … 301 333 *****************************************************************************/ 302 334 303 DWORD HMDeviceRegister(LPSTR pszDeviceName, 304 HMDeviceHandler *pDeviceHandler) 335 DWORD HMDeviceRegisterEx(LPSTR pszDeviceName, 336 HMDeviceHandler *pDeviceHandler, 337 VOID *pDevData) 305 338 { 306 339 PHMDEVICE pHMDevice; /* our new device to be allocated */ … … 324 357 pHMDevice->pDeviceHandler = pDeviceHandler; /* store pointer to device */ 325 358 pHMDevice->pNext = TabWin32Devices; /* establish linkage */ 359 pHMDevice->pDevData = pDevData; 326 360 327 361 TabWin32Devices = pHMDevice; /* insert new node as root in the list */ … … 330 364 } 331 365 366 DWORD HMDeviceRegister(LPSTR pszDeviceName, 367 HMDeviceHandler *pDeviceHandler) 368 { 369 return HMDeviceRegisterEx(pszDeviceName, pDeviceHandler, NULL); 370 } 332 371 333 372 /***************************************************************************** … … 355 394 // fill handle table 356 395 for(ulIndex = 0; ulIndex < MAX_OS2_HMHANDLES; ulIndex++) { 357 396 TabWin32Handles[ulIndex].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 358 397 } 359 398 handleMutex.leave(); … … 471 510 472 511 if(ulHandle == 0) { 473 512 ulHandle = 1; //SvL: Start searching from index 1 474 513 } 475 514 do … … 478 517 if (TabWin32Handles[ulHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE) 479 518 { 480 *phHandle16 = ulHandle; 481 TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2; 482 HMGlobals.ulHandleLast = ulHandle; /* to shorten search times */ 483 484 handleMutex.leave(); 485 return (NO_ERROR); /* OK */ 519 *phHandle16 = ulHandle; 520 TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2; 521 TabWin32Handles[ulHandle].hmHandleData.lpDeviceData = NULL; 522 HMGlobals.ulHandleLast = ulHandle; /* to shorten search times */ 523 524 handleMutex.leave(); 525 return (NO_ERROR); /* OK */ 486 526 } 487 527 … … 771 811 772 812 if((fdwOdinOptions & DUPLICATE_ACCESS_READWRITE) == DUPLICATE_ACCESS_READWRITE) { 773 774 } 775 else 813 pHMHandleData->dwAccess = GENERIC_READ | GENERIC_WRITE; 814 } 815 else 776 816 if(fdwOdinOptions & DUPLICATE_ACCESS_READ) { 777 817 pHMHandleData->dwAccess = GENERIC_READ; 778 818 } 779 819 780 820 if(fdwOdinOptions & DUPLICATE_SHARE_READ) { 781 782 } 821 pHMHandleData->dwShare = FILE_SHARE_READ; 822 } 783 823 else 784 824 if(fdwOdinOptions & DUPLICATE_SHARE_DENYNONE) { 785 825 pHMHandleData->dwShare = FILE_SHARE_READ | FILE_SHARE_WRITE; 786 826 } 787 827 else pHMHandleData->dwShare = TabWin32Handles[srchandle].hmHandleData.dwShare; … … 798 838 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 799 839 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 800 801 840 /* call the device handler */ 802 841 rc = pDeviceHandler->DuplicateHandle(&TabWin32Handles[iIndexNew].hmHandleData, … … 854 893 PHMHANDLEDATA pHMHandleData; 855 894 HMHANDLEDATA HMHandleTemp; /* temporary buffer for handle data */ 895 VOID *pDevData; 856 896 857 897 /* create new handle by either lpFileName or hTemplateFile */ … … 874 914 { 875 915 pDeviceHandler = _HMDeviceFind((LPSTR)lpFileName); /* find device */ 876 877 916 if (NULL == pDeviceHandler) /* this name is unknown to us */ 878 917 { … … 883 922 pHMHandleData = NULL; 884 923 924 pDevData = _HMDeviceGetData((LPSTR)lpFileName); 925 885 926 if(pDeviceHandler == HMGlobals.pHMOpen32) { 886 927 pDeviceHandler = HMGlobals.pHMFile; 887 928 } 888 929 } … … 910 951 HMHandleTemp.dwFlags = dwFlagsAndAttributes; 911 952 HMHandleTemp.lpHandlerData = NULL; 953 HMHandleTemp.lpDeviceData = pDevData; 912 954 } 913 955 … … 918 960 HMHandleTemp.hHMHandle = iIndexNew; 919 961 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 920 921 962 /* now copy back our temporary handle data */ 922 963 memcpy(&TabWin32Handles[iIndexNew].hmHandleData, … … 1008 1049 int iIndexNew; /* index into the handle table */ 1009 1050 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 1051 VOID *pDevData; 1010 1052 PHMHANDLEDATA pHMHandleData; 1011 1053 DWORD rc; /* API return code */ … … 1020 1062 else 1021 1063 pHMHandleData = NULL; 1064 1065 pDevData = _HMDeviceGetData((LPSTR)lpFileName); 1022 1066 1023 1067 if(pDeviceHandler == HMGlobals.pHMOpen32) { … … 1046 1090 pHMHandleData->dwFlags = 0; 1047 1091 pHMHandleData->lpHandlerData = NULL; 1048 1092 pHMHandleData->lpDeviceData = pDevData; 1049 1093 1050 1094 /* we've got to mark the handle as occupied here, since another device */ … … 1053 1097 /* write appropriate entry into the handle table if open succeeded */ 1054 1098 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 1055 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler;1099 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 1056 1100 1057 1101 rc = pDeviceHandler->OpenFile (lpFileName, /* call the device handler */ … … 1069 1113 if(rc != NO_ERROR) /* oops, creation failed within the device handler */ 1070 1114 { 1071 1072 1073 1115 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1116 SetLastError(pOFStruct->nErrCode); 1117 return (INVALID_HANDLE_VALUE); /* signal error */ 1074 1118 } 1075 1119 else { 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1120 if(fuMode & (OF_DELETE|OF_EXIST)) { 1121 //file handle already closed 1122 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1123 return TRUE; //TODO: correct? 1124 } 1125 if(fuMode & OF_PARSE) { 1126 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1127 return 0; 1128 } 1129 if(fuMode & OF_VERIFY) { 1130 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 1131 return 1; //TODO: correct? 1132 } 1089 1133 } 1090 1134 … … 1092 1136 dprintf(("KERNEL32/HandleManager: OpenFile(%s)=%08xh\n", 1093 1137 lpFileName, 1094 hResult));1138 iIndexNew)); 1095 1139 #endif 1096 1140 … … 1804 1848 dprintf(("KERNEL32: HandleManager:HMWaitForSingleObject(%08xh) passed on to Open32.\n", 1805 1849 hObject)); 1806 1850 1807 1851 // maybe handles from CreateProcess() ... 1808 1852 dwResult = O32_WaitForSingleObject(hObject, dwTimeout); … … 2576 2620 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 2577 2621 { 2578 2579 2580 2581 2582 2583 elsereturn (NULL); /* signal error */2622 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2623 SetLastError(rc); /* Hehe, OS/2 and NT are pretty compatible :) */ 2624 if(rc == ERROR_ALREADY_EXISTS) { 2625 return hOldMemMap; //return handle of existing file mapping 2626 } 2627 else return (NULL); /* signal error */ 2584 2628 } 2585 2629 else … … 2758 2802 *pLoop1)); 2759 2803 2760 2804 *pLoop2 = *pLoop1; 2761 2805 //// O32_SetLastError(ERROR_INVALID_HANDLE); 2762 2806 //// return (WAIT_FAILED); … … 2813 2857 *****************************************************************************/ 2814 2858 2815 DWORD HMMsgWaitForMultipleObjects (DWORD nCount,2816 LPHANDLE pHandles,2817 BOOL 2818 DWORD dwMilliseconds,2819 DWORD 2859 DWORD HMMsgWaitForMultipleObjects (DWORD nCount, 2860 LPHANDLE pHandles, 2861 BOOL fWaitAll, 2862 DWORD dwMilliseconds, 2863 DWORD dwWakeMask) 2820 2864 { 2821 2865 ULONG ulIndex; … … 2829 2873 if (pArrayOfHandles == NULL) 2830 2874 { 2831 2832 2833 2875 dprintf(("ERROR: HMMsgWaitForMultipleObjects: alloca failed to allocate %d handles", nCount)); 2876 O32_SetLastError(ERROR_NOT_ENOUGH_MEMORY); 2877 return WAIT_FAILED; 2834 2878 } 2835 2879 else … … 2854 2898 *pLoop1)); 2855 2899 2856 2900 *pLoop2 = *pLoop1; 2857 2901 //// O32_SetLastError(ERROR_INVALID_HANDLE); 2858 2902 //// return (WAIT_FAILED); … … 2910 2954 2911 2955 2912 /***************************************************************************** 2913 * Name : HMSetupComm 2914 * Purpose : router function for SetupComm 2915 * Parameters: 2916 * Variables : 2917 * Result : 2918 * Remark : 2919 * Status : 2920 * 2921 * Author : Achim Hasenmueller [Sat, 1999/11/27 13:13] 2922 *****************************************************************************/ 2923 2924 BOOL HMSetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue) 2956 2957 /***************************************************************************** 2958 * Name : HMCOMGetCommState 2959 * Purpose : router function for GetCommState 2960 * Parameters: 2961 * Variables : 2962 * Result : 2963 * Remark : 2964 * Status : 2965 * 2966 * Author : Achim Hasenmueller [Sat, 1999/11/27 13:40] 2967 *****************************************************************************/ 2968 2969 BOOL HMCommGetCommState(HANDLE hCommDev, LPDCB lpdcb) 2925 2970 { 2926 2971 int iIndex; /* index into the handle table */ … … 2929 2974 2930 2975 /* validate handle */ 2931 iIndex = _HMHandleQuery(h File); /* get the index */2976 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 2932 2977 if (-1 == iIndex) /* error ? */ 2933 2978 { … … 2936 2981 } 2937 2982 2938 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 2939 bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData, 2940 dwInQueue, dwOutQueue); 2941 2942 return (bResult); /* deliver return code */ 2943 } 2944 2945 2946 /***************************************************************************** 2947 * Name : HMGetCommState 2948 * Purpose : router function for GetCommState 2949 * Parameters: 2950 * Variables : 2951 * Result : 2952 * Remark : 2953 * Status : 2954 * 2955 * Author : Achim Hasenmueller [Sat, 1999/11/27 13:40] 2956 *****************************************************************************/ 2957 2958 BOOL HMGetCommState(INT hCommDev, LPDCB lpdcb) 2959 { 2960 int iIndex; /* index into the handle table */ 2961 BOOL bResult; /* result from the device handler's API */ 2962 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 2963 2964 /* validate handle */ 2965 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 2966 if (-1 == iIndex) /* error ? */ 2967 { 2968 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 2969 return (NULL); /* signal failure */ 2983 if(IsBadWritePtr(lpdcb,sizeof(DCB))) 2984 { 2985 SetLastError(ERROR_INVALID_PARAMETER); 2986 return FALSE; 2970 2987 } 2971 2988 … … 2973 2990 bResult = pHMHandle->pDeviceHandler->GetCommState(&pHMHandle->hmHandleData, 2974 2991 lpdcb); 2992 2993 return (bResult); /* deliver return code */ 2994 } 2995 2996 BOOL HMCommWaitCommEvent( HANDLE hCommDev, 2997 LPDWORD lpfdwEvtMask, 2998 LPOVERLAPPED lpo) 2999 { 3000 int iIndex; /* index into the handle table */ 3001 BOOL bResult; /* result from the device handler's API */ 3002 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3003 3004 /* validate handle */ 3005 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3006 if (-1 == iIndex) /* error ? */ 3007 { 3008 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3009 return FALSE; /* signal failure */ 3010 } 3011 3012 if(NULL!=lpo && IsBadReadPtr(lpo,sizeof(OVERLAPPED)) ) 3013 { 3014 SetLastError(ERROR_INVALID_PARAMETER); 3015 return FALSE; 3016 } 3017 3018 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3019 bResult = pHMHandle->pDeviceHandler->WaitCommEvent( &pHMHandle->hmHandleData, 3020 lpfdwEvtMask, 3021 lpo); 3022 3023 return (bResult); /* deliver return code */ 3024 } 3025 3026 BOOL HMCommGetCommProperties( HANDLE hCommDev, 3027 LPCOMMPROP lpcmmp) 3028 { 3029 int iIndex; /* index into the handle table */ 3030 BOOL bResult; /* result from the device handler's API */ 3031 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3032 3033 /* validate handle */ 3034 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3035 if (-1 == iIndex) /* error ? */ 3036 { 3037 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3038 return (NULL); /* signal failure */ 3039 } 3040 3041 if(IsBadWritePtr(lpcmmp,sizeof(COMMPROP)) ) 3042 { 3043 SetLastError(ERROR_INVALID_PARAMETER); 3044 return FALSE; 3045 } 3046 3047 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3048 bResult = pHMHandle->pDeviceHandler->GetCommProperties( &pHMHandle->hmHandleData, 3049 lpcmmp); 3050 3051 return (bResult); /* deliver return code */ 3052 } 3053 3054 BOOL HMCommGetCommMask( HANDLE hCommDev, 3055 LPDWORD lpfdwEvtMask) 3056 { 3057 int iIndex; /* index into the handle table */ 3058 BOOL bResult; /* result from the device handler's API */ 3059 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3060 3061 /* validate handle */ 3062 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3063 if (-1 == iIndex) /* error ? */ 3064 { 3065 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3066 return (NULL); /* signal failure */ 3067 } 3068 3069 if(IsBadWritePtr(lpfdwEvtMask,sizeof(DWORD)) ) 3070 { 3071 SetLastError(ERROR_INVALID_PARAMETER); 3072 return FALSE; 3073 } 3074 3075 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3076 bResult = pHMHandle->pDeviceHandler->GetCommMask( &pHMHandle->hmHandleData, 3077 lpfdwEvtMask); 3078 3079 return (bResult); /* deliver return code */ 3080 } 3081 3082 BOOL HMCommSetCommMask( HANDLE hCommDev, 3083 DWORD fdwEvtMask) 3084 { 3085 int iIndex; /* index into the handle table */ 3086 BOOL bResult; /* result from the device handler's API */ 3087 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3088 3089 /* validate handle */ 3090 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3091 if (-1 == iIndex) /* error ? */ 3092 { 3093 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3094 return (NULL); /* signal failure */ 3095 } 3096 3097 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3098 bResult = pHMHandle->pDeviceHandler->SetCommMask( &pHMHandle->hmHandleData, 3099 fdwEvtMask); 3100 3101 return (bResult); /* deliver return code */ 3102 } 3103 3104 BOOL HMCommPurgeComm( HANDLE hCommDev, 3105 DWORD fdwAction) 3106 { 3107 int iIndex; /* index into the handle table */ 3108 BOOL bResult; /* result from the device handler's API */ 3109 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3110 3111 /* validate handle */ 3112 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3113 if (-1 == iIndex) /* error ? */ 3114 { 3115 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3116 return (NULL); /* signal failure */ 3117 } 3118 3119 3120 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3121 bResult = pHMHandle->pDeviceHandler->PurgeComm( &pHMHandle->hmHandleData, 3122 fdwAction); 3123 3124 return (bResult); /* deliver return code */ 3125 } 3126 3127 BOOL HMCommClearCommError( HANDLE hCommDev, 3128 LPDWORD lpdwErrors, 3129 LPCOMSTAT lpcst) 3130 { 3131 int iIndex; /* index into the handle table */ 3132 BOOL bResult; /* result from the device handler's API */ 3133 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3134 3135 /* validate handle */ 3136 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3137 if (-1 == iIndex) /* error ? */ 3138 { 3139 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3140 return (NULL); /* signal failure */ 3141 } 3142 3143 if(IsBadWritePtr(lpdwErrors,sizeof(DWORD)) || 3144 (NULL!=lpcst && IsBadWritePtr(lpcst,sizeof(COMSTAT)) ) ) 3145 { 3146 SetLastError(ERROR_INVALID_PARAMETER); 3147 return FALSE; 3148 } 3149 3150 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3151 bResult = pHMHandle->pDeviceHandler->ClearCommError(&pHMHandle->hmHandleData, 3152 lpdwErrors, 3153 lpcst); 3154 3155 return (bResult); /* deliver return code */ 3156 } 3157 3158 BOOL HMCommSetCommState( HANDLE hCommDev, 3159 LPDCB lpdcb) 3160 { 3161 int iIndex; /* index into the handle table */ 3162 BOOL bResult; /* result from the device handler's API */ 3163 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3164 3165 /* validate handle */ 3166 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3167 if (-1 == iIndex) /* error ? */ 3168 { 3169 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3170 return (NULL); /* signal failure */ 3171 } 3172 3173 if(IsBadReadPtr(lpdcb,sizeof(DCB)) ) 3174 { 3175 SetLastError(ERROR_INVALID_PARAMETER); 3176 return FALSE; 3177 } 3178 3179 3180 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3181 bResult = pHMHandle->pDeviceHandler->SetCommState(&pHMHandle->hmHandleData, 3182 lpdcb); 3183 3184 return (bResult); /* deliver return code */ 3185 } 3186 3187 3188 BOOL HMCommGetCommTimeouts( HANDLE hCommDev, 3189 LPCOMMTIMEOUTS lpctmo) 3190 { 3191 int iIndex; /* index into the handle table */ 3192 BOOL bResult; /* result from the device handler's API */ 3193 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3194 3195 /* validate handle */ 3196 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3197 if (-1 == iIndex) /* error ? */ 3198 { 3199 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3200 return (NULL); /* signal failure */ 3201 } 3202 3203 if(IsBadWritePtr(lpctmo,sizeof(COMMTIMEOUTS)) ) 3204 { 3205 SetLastError(ERROR_INVALID_PARAMETER); 3206 return FALSE; 3207 } 3208 3209 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3210 bResult = pHMHandle->pDeviceHandler->GetCommTimeouts( &pHMHandle->hmHandleData, 3211 lpctmo); 3212 3213 return (bResult); /* deliver return code */ 3214 } 3215 BOOL HMCommGetCommModemStatus( HANDLE hCommDev, 3216 LPDWORD lpModemStat ) 3217 { 3218 int iIndex; /* index into the handle table */ 3219 BOOL bResult; /* result from the device handler's API */ 3220 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3221 3222 /* validate handle */ 3223 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3224 if (-1 == iIndex) /* error ? */ 3225 { 3226 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3227 return (NULL); /* signal failure */ 3228 } 3229 3230 if(IsBadWritePtr(lpModemStat,sizeof(DWORD)) ) 3231 { 3232 SetLastError(ERROR_INVALID_PARAMETER); 3233 return FALSE; 3234 } 3235 3236 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3237 bResult = pHMHandle->pDeviceHandler->GetCommModemStatus( &pHMHandle->hmHandleData, 3238 lpModemStat); 3239 3240 return (bResult); /* deliver return code */ 3241 } 3242 3243 BOOL HMCommSetCommTimeouts( HANDLE hCommDev, 3244 LPCOMMTIMEOUTS lpctmo) 3245 { 3246 int iIndex; /* index into the handle table */ 3247 BOOL bResult; /* result from the device handler's API */ 3248 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3249 3250 /* validate handle */ 3251 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3252 if (-1 == iIndex) /* error ? */ 3253 { 3254 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3255 return (NULL); /* signal failure */ 3256 } 3257 3258 if(IsBadReadPtr(lpctmo,sizeof(COMMTIMEOUTS)) ) 3259 { 3260 SetLastError(ERROR_INVALID_PARAMETER); 3261 return FALSE; 3262 } 3263 3264 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3265 bResult = pHMHandle->pDeviceHandler->SetCommTimeouts( &pHMHandle->hmHandleData, 3266 lpctmo); 3267 3268 return (bResult); /* deliver return code */ 3269 } 3270 3271 BOOL HMCommTransmitCommChar( HANDLE hCommDev, 3272 CHAR cChar ) 3273 { 3274 int iIndex; /* index into the handle table */ 3275 BOOL bResult; /* result from the device handler's API */ 3276 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3277 3278 /* validate handle */ 3279 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3280 if (-1 == iIndex) /* error ? */ 3281 { 3282 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3283 return (NULL); /* signal failure */ 3284 } 3285 3286 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3287 bResult = pHMHandle->pDeviceHandler->TransmitCommChar( &pHMHandle->hmHandleData, 3288 cChar); 3289 3290 return (bResult); /* deliver return code */ 3291 } 3292 3293 BOOL HMCommSetCommConfig( HANDLE hCommDev, 3294 LPCOMMCONFIG lpCC, 3295 DWORD dwSize ) 3296 { 3297 int iIndex; /* index into the handle table */ 3298 BOOL bResult; /* result from the device handler's API */ 3299 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3300 3301 /* validate handle */ 3302 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3303 if (-1 == iIndex) /* error ? */ 3304 { 3305 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3306 return (NULL); /* signal failure */ 3307 } 3308 3309 if( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) || 3310 dwSize < sizeof(COMMCONFIG) ) 3311 { 3312 SetLastError(ERROR_INVALID_PARAMETER); 3313 return FALSE; 3314 } 3315 3316 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3317 bResult = pHMHandle->pDeviceHandler->SetCommConfig( &pHMHandle->hmHandleData, 3318 lpCC, 3319 dwSize); 3320 3321 return (bResult); /* deliver return code */ 3322 } 3323 3324 BOOL HMCommSetCommBreak( HANDLE hCommDev ) 3325 { 3326 int iIndex; /* index into the handle table */ 3327 BOOL bResult; /* result from the device handler's API */ 3328 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3329 3330 /* validate handle */ 3331 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3332 if (-1 == iIndex) /* error ? */ 3333 { 3334 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3335 return (NULL); /* signal failure */ 3336 } 3337 3338 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3339 bResult = pHMHandle->pDeviceHandler->SetCommBreak( &pHMHandle->hmHandleData); 3340 3341 return (bResult); /* deliver return code */ 3342 } 3343 3344 BOOL HMCommGetCommConfig( HANDLE hCommDev, 3345 LPCOMMCONFIG lpCC, 3346 LPDWORD lpdwSize ) 3347 { 3348 int iIndex; /* index into the handle table */ 3349 BOOL bResult; /* result from the device handler's API */ 3350 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3351 3352 /* validate handle */ 3353 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3354 if (-1 == iIndex) /* error ? */ 3355 { 3356 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3357 return (NULL); /* signal failure */ 3358 } 3359 3360 if(IsBadWritePtr(lpdwSize,sizeof(DWORD)) ) 3361 { 3362 SetLastError(ERROR_INVALID_PARAMETER); 3363 return FALSE; 3364 } 3365 3366 if( IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) || 3367 *lpdwSize< sizeof(COMMCONFIG) ) 3368 { 3369 SetLastError(ERROR_INSUFFICIENT_BUFFER); 3370 *lpdwSize= sizeof(COMMCONFIG); 3371 return FALSE; 3372 } 3373 3374 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3375 bResult = pHMHandle->pDeviceHandler->GetCommConfig( &pHMHandle->hmHandleData, 3376 lpCC, 3377 lpdwSize); 3378 3379 return (bResult); /* deliver return code */ 3380 } 3381 3382 BOOL HMCommEscapeCommFunction( HANDLE hCommDev, 3383 UINT dwFunc ) 3384 { 3385 int iIndex; /* index into the handle table */ 3386 BOOL bResult; /* result from the device handler's API */ 3387 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3388 3389 /* validate handle */ 3390 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3391 if (-1 == iIndex) /* error ? */ 3392 { 3393 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3394 return (NULL); /* signal failure */ 3395 } 3396 3397 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3398 3399 switch(dwFunc) 3400 { 3401 case CLRDTR: 3402 case CLRRTS: 3403 case SETDTR: 3404 case SETRTS: 3405 case SETXOFF: 3406 case SETXON: 3407 bResult = pHMHandle->pDeviceHandler->EscapeCommFunction( &pHMHandle->hmHandleData, 3408 dwFunc); 3409 break; 3410 case SETBREAK: 3411 bResult = pHMHandle->pDeviceHandler->SetCommBreak(&pHMHandle->hmHandleData); 3412 break; 3413 case CLRBREAK: 3414 bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData); 3415 break; 3416 default: 3417 SetLastError(ERROR_INVALID_PARAMETER); 3418 bResult = FALSE; 3419 } 3420 3421 3422 return (bResult); /* deliver return code */ 3423 } 3424 3425 BOOL HMCommSetupComm( HANDLE hCommDev, 3426 DWORD dwInQueue, 3427 DWORD dwOutQueue) 3428 { 3429 int iIndex; /* index into the handle table */ 3430 BOOL bResult; /* result from the device handler's API */ 3431 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3432 3433 /* validate handle */ 3434 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3435 if (-1 == iIndex) /* error ? */ 3436 { 3437 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3438 return (NULL); /* signal failure */ 3439 } 3440 3441 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3442 bResult = pHMHandle->pDeviceHandler->SetupComm(&pHMHandle->hmHandleData, 3443 dwInQueue, 3444 dwOutQueue); 3445 3446 return (bResult); /* deliver return code */ 3447 } 3448 3449 BOOL HMCommClearCommBreak(HANDLE hCommDev) 3450 { 3451 int iIndex; /* index into the handle table */ 3452 BOOL bResult; /* result from the device handler's API */ 3453 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3454 3455 /* validate handle */ 3456 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3457 if (-1 == iIndex) /* error ? */ 3458 { 3459 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3460 return (NULL); /* signal failure */ 3461 } 3462 3463 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3464 bResult = pHMHandle->pDeviceHandler->ClearCommBreak(&pHMHandle->hmHandleData); 3465 3466 return (bResult); /* deliver return code */ 3467 } 3468 3469 BOOL HMCommSetDefaultCommConfig( HANDLE hCommDev, 3470 LPCOMMCONFIG lpCC, 3471 DWORD dwSize) 3472 { 3473 int iIndex; /* index into the handle table */ 3474 BOOL bResult; /* result from the device handler's API */ 3475 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3476 3477 /* validate handle */ 3478 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3479 if (-1 == iIndex) /* error ? */ 3480 { 3481 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3482 return (NULL); /* signal failure */ 3483 } 3484 3485 if( (lpCC!=NULL) && 3486 ( IsBadReadPtr(lpCC,sizeof(COMMCONFIG)) || 3487 dwSize != sizeof(COMMCONFIG) ) ) 3488 { 3489 SetLastError(ERROR_INVALID_PARAMETER); 3490 return FALSE; 3491 } 3492 3493 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3494 bResult = pHMHandle->pDeviceHandler->SetDefaultCommConfig(&pHMHandle->hmHandleData, 3495 lpCC, 3496 dwSize); 3497 3498 return (bResult); /* deliver return code */ 3499 } 3500 3501 BOOL HMCommGetDefaultCommConfig( HANDLE hCommDev, 3502 LPCOMMCONFIG lpCC, 3503 LPDWORD lpdwSize) 3504 { 3505 int iIndex; /* index into the handle table */ 3506 BOOL bResult; /* result from the device handler's API */ 3507 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3508 3509 /* validate handle */ 3510 iIndex = _HMHandleQuery(hCommDev); /* get the index */ 3511 if (-1 == iIndex) /* error ? */ 3512 { 3513 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3514 return (NULL); /* signal failure */ 3515 } 3516 3517 if(IsBadWritePtr(lpdwSize,sizeof(DWORD))) 3518 { 3519 SetLastError(ERROR_INVALID_PARAMETER); 3520 return FALSE; 3521 } 3522 3523 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3524 bResult = pHMHandle->pDeviceHandler->GetDefaultCommConfig( &pHMHandle->hmHandleData, 3525 lpCC, 3526 lpdwSize); 2975 3527 2976 3528 return (bResult); /* deliver return code */ … … 3006 3558 { 3007 3559 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 3008 return ERROR_NOT_ENOUGH_MEMORY; 3560 return ERROR_NOT_ENOUGH_MEMORY; 3009 3561 } 3010 3562 … … 3036 3588 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 3037 3589 { 3038 3039 3590 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3591 return (rc); /* signal error */ 3040 3592 } 3041 3593 else … … 3074 3626 { 3075 3627 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 3076 return ERROR_NOT_ENOUGH_MEMORY; 3628 return ERROR_NOT_ENOUGH_MEMORY; 3077 3629 } 3078 3630 … … 3104 3656 if (rc != NO_ERROR) /* oops, creation failed within the device handler */ 3105 3657 { 3106 3107 3658 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3659 return (rc); /* signal error */ 3108 3660 } 3109 3661 else … … 3146 3698 { 3147 3699 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 3148 return 0; 3700 return 0; 3149 3701 } 3150 3702 … … 3176 3728 if (rc == 0) /* oops, creation failed within the device handler */ 3177 3729 { 3178 3179 3730 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 3731 return 0; /* signal error */ 3180 3732 } 3181 3733 … … 3433 3985 /***************************************************************************** 3434 3986 * Name : HMSetThreadTerminated 3435 * Purpose : 3987 * Purpose : 3436 3988 * Parameters: 3437 3989 * Variables : … … 3465 4017 /***************************************************************************** 3466 4018 * Name : HMPeekNamedPipe 3467 * Purpose : 4019 * Purpose : 3468 4020 * Parameters: 3469 4021 * Variables : … … 3495 4047 3496 4048 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3497 lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 4049 lpResult = pHMHandle->pDeviceHandler->PeekNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 3498 4050 lpvBuffer, 3499 4051 cbBuffer, … … 3507 4059 /***************************************************************************** 3508 4060 * Name : HMCreateNamedPipe 3509 * Purpose : 4061 * Purpose : 3510 4062 * Parameters: 3511 4063 * Variables : … … 3516 4068 * Author : Przemyslaw Dobrowolski 3517 4069 *****************************************************************************/ 3518 DWORD HMCreateNamedPipe(LPCTSTR lpName, 3519 DWORD dwOpenMode, 4070 DWORD HMCreateNamedPipe(LPCTSTR lpName, 4071 DWORD dwOpenMode, 3520 4072 DWORD dwPipeMode, 3521 DWORD nMaxInstances, 4073 DWORD nMaxInstances, 3522 4074 DWORD nOutBufferSize, 3523 DWORD nInBufferSize, 4075 DWORD nInBufferSize, 3524 4076 DWORD nDefaultTimeOut, 3525 4077 LPSECURITY_ATTRIBUTES lpSecurityAttributes) … … 3539 4091 { 3540 4092 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 3541 return 0; 4093 return 0; 3542 4094 } 3543 4095 … … 3568 4120 if (rc == 0) /* oops, creation failed within the device handler */ 3569 4121 { 3570 3571 4122 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 4123 return 0; /* signal error */ 3572 4124 } 3573 4125 … … 3579 4131 /***************************************************************************** 3580 4132 * Name : HMConnectNamedPipe 3581 * Purpose : 4133 * Purpose : 3582 4134 * Parameters: 3583 4135 * Variables : … … 3604 4156 3605 4157 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3606 lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 4158 lpResult = pHMHandle->pDeviceHandler->ConnectNamedPipe(&TabWin32Handles[iIndex].hmHandleData, 3607 4159 lpOverlapped); 3608 4160 … … 3612 4164 /***************************************************************************** 3613 4165 * Name : HMDisconnectNamedPipe 3614 * Purpose : 4166 * Purpose : 3615 4167 * Parameters: 3616 4168 * Variables : … … 3644 4196 /***************************************************************************** 3645 4197 * Name : HMGetNamedPipeHandleState 3646 * Purpose : 4198 * Purpose : 3647 4199 * Parameters: 3648 4200 * Variables : … … 3689 4241 /***************************************************************************** 3690 4242 * Name : HMGetNamedPipeInfo 3691 * Purpose : 4243 * Purpose : 3692 4244 * Parameters: 3693 4245 * Variables : … … 3729 4281 /***************************************************************************** 3730 4282 * Name : HMTransactNamedPipe 3731 * Purpose : 4283 * Purpose : 3732 4284 * Parameters: 3733 4285 * Variables : … … 3773 4325 /***************************************************************************** 3774 4326 * Name : HMSetNamedPipeHandleState 3775 * Purpose : 4327 * Purpose : 3776 4328 * Parameters: 3777 4329 * Variables : … … 3811 4363 /***************************************************************************** 3812 4364 * Name : HMCreatePipe 3813 * Purpose : 4365 * Purpose : 3814 4366 * Parameters: 3815 4367 * Variables : … … 3822 4374 BOOL HMCreatePipe(PHANDLE phRead, 3823 4375 PHANDLE phWrite, 3824 LPSECURITY_ATTRIBUTES lpsa, 4376 LPSECURITY_ATTRIBUTES lpsa, 3825 4377 DWORD cbPipe) 3826 4378 { … … 3840 4392 { 3841 4393 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 3842 return 0; 4394 return 0; 3843 4395 } 3844 4396 … … 3847 4399 { 3848 4400 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 3849 return 0; 4401 return 0; 3850 4402 } 3851 4403 … … 3891 4443 if (rc == 0) /* oops, creation failed within the device handler */ 3892 4444 { 3893 3894 3895 4445 TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 4446 TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 4447 return FALSE; /* signal error */ 3896 4448 } 3897 4449
Note:
See TracChangeset
for help on using the changeset viewer.