Changeset 3128 for trunk/src/kernel32/HandleManager.cpp
- Timestamp:
- Mar 16, 2000, 8:21:54 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/HandleManager.cpp
r2802 r3128 1 /* $Id: HandleManager.cpp,v 1.3 5 2000-02-16 14:23:57sandervl Exp $ */1 /* $Id: HandleManager.cpp,v 1.36 2000-03-16 19:20:36 sandervl Exp $ */ 2 2 3 3 /* … … 57 57 #include "HMComm.h" 58 58 #include "HMToken.h" 59 #include <winconst.h> 59 #include "HMThread.h" 60 #include <vmutex.h> 60 61 61 62 #define DBG_LOCALLOG DBG_handlemanager … … 109 110 /* the device name is repeated here to enable device alias names */ 110 111 static PHMDEVICE TabWin32Devices = NULL; 112 111 113 static HMHANDLE TabWin32Handles[MAX_OS2_HMHANDLES]; /* static handle table */ 112 114 VMutex handleMutex; 113 115 114 116 struct _HMGlobals … … 128 130 HMDeviceHandler *pHMComm; /* serial communication */ 129 131 HMDeviceHandler *pHMToken; /* security tokens */ 132 HMDeviceHandler *pHMThread; 130 133 131 134 ULONG ulHandleLast; /* index of last used handle */ … … 195 198 register ULONG ulLoop; 196 199 200 handleMutex.enter(); 201 197 202 for (ulLoop = 1; // @@@PH Note, this is an experimental change 198 203 // 0L as hHandle is sometimes considered invalid! … … 205 210 TabWin32Handles[ulLoop].hmHandleData.dwUserData = 0; 206 211 TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN; 212 handleMutex.leave(); 207 213 return (ulLoop); /* OK, then return it to the caller */ 208 214 } 209 215 } 210 216 217 handleMutex.leave(); 211 218 return (INVALID_HANDLE_VALUE); /* haven't found any free handle */ 212 219 } … … 326 333 HMGlobals.fIsInitialized = TRUE; /* OK, done */ 327 334 335 handleMutex.enter(); 328 336 // fill handle table 329 for (ulIndex = 0;330 ulIndex < MAX_OS2_HMHANDLES;331 ulIndex++)332 TabWin32Handles[ulIndex].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;337 for(ulIndex = 0; ulIndex < MAX_OS2_HMHANDLES; ulIndex++) { 338 TabWin32Handles[ulIndex].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 339 } 340 handleMutex.leave(); 333 341 334 342 dprintf(("KERNEL32:HandleManager:HMInitialize() storing handles.\n")); … … 338 346 sizeof(HMGlobals)); 339 347 340 348 /* copy standard handles from OS/2's Open32 Subsystem */ 341 349 HMSetStdHandle(STD_INPUT_HANDLE, GetStdHandle(STD_INPUT_HANDLE)); 342 350 HMSetStdHandle(STD_OUTPUT_HANDLE, GetStdHandle(STD_OUTPUT_HANDLE)); … … 351 359 HMGlobals.pHMComm = new HMDeviceCommClass("\\\\COM\\"); 352 360 HMGlobals.pHMToken = new HMDeviceTokenClass("\\\\TOKEN\\"); 361 HMGlobals.pHMThread = new HMDeviceThreadClass("\\\\THREAD\\"); 353 362 } 354 363 return (NO_ERROR); … … 408 417 *****************************************************************************/ 409 418 410 DWORD 411 419 DWORD HMHandleAllocate (PULONG phHandle16, 420 ULONG hHandleOS2) 412 421 { 413 422 register ULONG ulHandle; … … 421 430 ulHandle = HMGlobals.ulHandleLast; /* get free handle */ 422 431 432 handleMutex.enter(); 433 423 434 if(ulHandle == 0) { 424 435 ulHandle = 1; //SvL: Start searching from index 1 … … 426 437 do 427 438 { 428 439 /* check if handle is free */ 429 440 if (TabWin32Handles[ulHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE) 430 441 { 431 *phHandle16 = ulHandle; 432 TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2; 433 HMGlobals.ulHandleLast = ulHandle; /* to shorten search times */ 434 435 return (NO_ERROR); /* OK */ 442 *phHandle16 = ulHandle; 443 TabWin32Handles[ulHandle].hmHandleData.hHMHandle = hHandleOS2; 444 HMGlobals.ulHandleLast = ulHandle; /* to shorten search times */ 445 446 handleMutex.leave(); 447 return (NO_ERROR); /* OK */ 436 448 } 437 449 … … 442 454 } 443 455 while (ulHandle != HMGlobals.ulHandleLast); 456 457 handleMutex.leave(); 444 458 445 459 return (ERROR_TOO_MANY_OPEN_FILES); /* OK, we're done */ … … 2910 2924 return STATUS_SUCCESS; 2911 2925 } 2912 2926 /***************************************************************************** 2927 * Name : HMCreateThread 2928 * Purpose : router function for CreateThread 2929 * Parameters: 2930 * Variables : 2931 * Result : 2932 * Remark : 2933 * Status : 2934 * 2935 * Author : SvL 2936 *****************************************************************************/ 2937 HANDLE HMCreateThread(LPSECURITY_ATTRIBUTES lpsa, 2938 DWORD cbStack, 2939 LPTHREAD_START_ROUTINE lpStartAddr, 2940 LPVOID lpvThreadParm, 2941 DWORD fdwCreate, 2942 LPDWORD lpIDThread) 2943 { 2944 int iIndex; /* index into the handle table */ 2945 int iIndexNew; /* index into the handle table */ 2946 HMDeviceHandler *pDeviceHandler; /* device handler for this handle */ 2947 PHMHANDLEDATA pHMHandleData; 2948 HANDLE rc; /* API return code */ 2949 2950 SetLastError(ERROR_SUCCESS); 2951 2952 pDeviceHandler = HMGlobals.pHMThread; /* device is predefined */ 2953 2954 iIndexNew = _HMHandleGetFree(); /* get free handle */ 2955 if (-1 == iIndexNew) /* oops, no free handles ! */ 2956 { 2957 SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */ 2958 return 0; 2959 } 2960 2961 /* initialize the complete HMHANDLEDATA structure */ 2962 pHMHandleData = &TabWin32Handles[iIndexNew].hmHandleData; 2963 pHMHandleData->dwType = FILE_TYPE_UNKNOWN; /* unknown handle type */ 2964 pHMHandleData->dwAccess = 0; 2965 pHMHandleData->dwShare = 0; 2966 pHMHandleData->dwCreation = 0; 2967 pHMHandleData->dwFlags = 0; 2968 pHMHandleData->lpHandlerData = NULL; 2969 2970 2971 /* we've got to mark the handle as occupied here, since another device */ 2972 /* could be created within the device handler -> deadlock */ 2973 2974 /* write appropriate entry into the handle table if open succeeded */ 2975 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = iIndexNew; 2976 TabWin32Handles[iIndexNew].pDeviceHandler = pDeviceHandler; 2977 2978 /* call the device handler */ 2979 2980 // @@@PH: Note: hFile is a Win32-style handle, it's not (yet) converted to 2981 // a valid HandleManager-internal handle! 2982 rc = pDeviceHandler->CreateThread(&TabWin32Handles[iIndexNew].hmHandleData, 2983 lpsa, cbStack, lpStartAddr, 2984 lpvThreadParm, fdwCreate, lpIDThread); 2985 2986 if (rc == 0) /* oops, creation failed within the device handler */ 2987 { 2988 TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE; 2989 return 0; /* signal error */ 2990 } 2991 2992 return iIndexNew; 2993 } 2994 /***************************************************************************** 2995 * Name : HMGetThreadPriority 2996 * Purpose : router function for GetThreadPriority 2997 * Parameters: 2998 * Variables : 2999 * Result : 3000 * Remark : 3001 * Status : 3002 * 3003 * Author : SvL 3004 *****************************************************************************/ 3005 INT HMGetThreadPriority(HANDLE hThread) 3006 { 3007 int iIndex; /* index into the handle table */ 3008 INT lpResult; /* result from the device handler's API */ 3009 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3010 3011 SetLastError(ERROR_SUCCESS); 3012 /* validate handle */ 3013 iIndex = _HMHandleQuery(hThread); /* get the index */ 3014 if (-1 == iIndex) /* error ? */ 3015 { 3016 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3017 return (-1); /* signal failure */ 3018 } 3019 3020 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3021 lpResult = pHMHandle->pDeviceHandler->GetThreadPriority(&TabWin32Handles[iIndex].hmHandleData); 3022 3023 return (lpResult); /* deliver return code */ 3024 } 3025 /***************************************************************************** 3026 * Name : HMSuspendThread 3027 * Purpose : router function for SuspendThread 3028 * Parameters: 3029 * Variables : 3030 * Result : 3031 * Remark : 3032 * Status : 3033 * 3034 * Author : SvL 3035 *****************************************************************************/ 3036 DWORD HMSuspendThread(HANDLE hThread) 3037 { 3038 int iIndex; /* index into the handle table */ 3039 HANDLE lpResult; /* result from the device handler's API */ 3040 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3041 3042 SetLastError(ERROR_SUCCESS); 3043 /* validate handle */ 3044 iIndex = _HMHandleQuery(hThread); /* get the index */ 3045 if (-1 == iIndex) /* error ? */ 3046 { 3047 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3048 return -1; /* signal failure */ 3049 } 3050 3051 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3052 lpResult = pHMHandle->pDeviceHandler->SuspendThread(&TabWin32Handles[iIndex].hmHandleData); 3053 3054 return (lpResult); /* deliver return code */ 3055 } 3056 /***************************************************************************** 3057 * Name : HMSetThreadPriority 3058 * Purpose : router function for SetThreadPriority 3059 * Parameters: 3060 * Variables : 3061 * Result : 3062 * Remark : 3063 * Status : 3064 * 3065 * Author : SvL 3066 *****************************************************************************/ 3067 BOOL HMSetThreadPriority(HANDLE hThread, int priority) 3068 { 3069 int iIndex; /* index into the handle table */ 3070 BOOL lpResult; /* result from the device handler's API */ 3071 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3072 3073 SetLastError(ERROR_SUCCESS); 3074 /* validate handle */ 3075 iIndex = _HMHandleQuery(hThread); /* get the index */ 3076 if (-1 == iIndex) /* error ? */ 3077 { 3078 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3079 return FALSE; /* signal failure */ 3080 } 3081 3082 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3083 lpResult = pHMHandle->pDeviceHandler->SetThreadPriority(&TabWin32Handles[iIndex].hmHandleData, priority); 3084 3085 return (lpResult); /* deliver return code */ 3086 } 3087 /***************************************************************************** 3088 * Name : HMGetThreadContext 3089 * Purpose : router function for GetThreadContext 3090 * Parameters: 3091 * Variables : 3092 * Result : 3093 * Remark : 3094 * Status : 3095 * 3096 * Author : SvL 3097 *****************************************************************************/ 3098 BOOL HMGetThreadContext(HANDLE hThread, CONTEXT *lpContext) 3099 { 3100 int iIndex; /* index into the handle table */ 3101 BOOL lpResult; /* result from the device handler's API */ 3102 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3103 3104 SetLastError(ERROR_SUCCESS); 3105 /* validate handle */ 3106 iIndex = _HMHandleQuery(hThread); /* get the index */ 3107 if (-1 == iIndex) /* error ? */ 3108 { 3109 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3110 return FALSE; /* signal failure */ 3111 } 3112 3113 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3114 lpResult = pHMHandle->pDeviceHandler->GetThreadContext(&TabWin32Handles[iIndex].hmHandleData, lpContext); 3115 3116 return (lpResult); /* deliver return code */ 3117 } 3118 /***************************************************************************** 3119 * Name : HMSetThreadContext 3120 * Purpose : router function for SetThreadContext 3121 * Parameters: 3122 * Variables : 3123 * Result : 3124 * Remark : 3125 * Status : 3126 * 3127 * Author : SvL 3128 *****************************************************************************/ 3129 BOOL HMSetThreadContext(HANDLE hThread, const CONTEXT *lpContext) 3130 { 3131 int iIndex; /* index into the handle table */ 3132 BOOL lpResult; /* result from the device handler's API */ 3133 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3134 3135 SetLastError(ERROR_SUCCESS); 3136 /* validate handle */ 3137 iIndex = _HMHandleQuery(hThread); /* get the index */ 3138 if (-1 == iIndex) /* error ? */ 3139 { 3140 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3141 return FALSE; /* signal failure */ 3142 } 3143 3144 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3145 lpResult = pHMHandle->pDeviceHandler->SetThreadContext(&TabWin32Handles[iIndex].hmHandleData, lpContext); 3146 3147 return (lpResult); /* deliver return code */ 3148 } 3149 /***************************************************************************** 3150 * Name : HMTerminateThread 3151 * Purpose : router function for TerminateThread 3152 * Parameters: 3153 * Variables : 3154 * Result : 3155 * Remark : 3156 * Status : 3157 * 3158 * Author : SvL 3159 *****************************************************************************/ 3160 BOOL HMTerminateThread(HANDLE hThread, DWORD exitcode) 3161 { 3162 int iIndex; /* index into the handle table */ 3163 BOOL lpResult; /* result from the device handler's API */ 3164 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3165 3166 SetLastError(ERROR_SUCCESS); 3167 /* validate handle */ 3168 iIndex = _HMHandleQuery(hThread); /* get the index */ 3169 if (-1 == iIndex) /* error ? */ 3170 { 3171 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3172 return FALSE; /* signal failure */ 3173 } 3174 3175 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3176 lpResult = pHMHandle->pDeviceHandler->TerminateThread(&TabWin32Handles[iIndex].hmHandleData, exitcode); 3177 3178 return (lpResult); /* deliver return code */ 3179 } 3180 /***************************************************************************** 3181 * Name : HMResumeThread 3182 * Purpose : router function for ResumeThread 3183 * Parameters: 3184 * Variables : 3185 * Result : 3186 * Remark : 3187 * Status : 3188 * 3189 * Author : SvL 3190 *****************************************************************************/ 3191 DWORD HMResumeThread(HANDLE hThread) 3192 { 3193 int iIndex; /* index into the handle table */ 3194 DWORD lpResult; /* result from the device handler's API */ 3195 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3196 3197 SetLastError(ERROR_SUCCESS); 3198 /* validate handle */ 3199 iIndex = _HMHandleQuery(hThread); /* get the index */ 3200 if (-1 == iIndex) /* error ? */ 3201 { 3202 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3203 return -1; /* signal failure */ 3204 } 3205 3206 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3207 lpResult = pHMHandle->pDeviceHandler->ResumeThread(&TabWin32Handles[iIndex].hmHandleData); 3208 3209 return (lpResult); /* deliver return code */ 3210 } 3211 3212 /***************************************************************************** 3213 * Name : HMGetExitCodeThread 3214 * Purpose : router function for GetExitCodeThread 3215 * Parameters: 3216 * Variables : 3217 * Result : 3218 * Remark : 3219 * Status : 3220 * 3221 * Author : SvL 3222 *****************************************************************************/ 3223 BOOL HMGetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode) 3224 { 3225 int iIndex; /* index into the handle table */ 3226 BOOL lpResult; /* result from the device handler's API */ 3227 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3228 3229 SetLastError(ERROR_SUCCESS); 3230 /* validate handle */ 3231 iIndex = _HMHandleQuery(hThread); /* get the index */ 3232 if (-1 == iIndex) /* error ? */ 3233 { 3234 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3235 return FALSE; /* signal failure */ 3236 } 3237 3238 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3239 lpResult = pHMHandle->pDeviceHandler->GetExitCodeThread(&TabWin32Handles[iIndex].hmHandleData, lpExitCode); 3240 3241 return (lpResult); /* deliver return code */ 3242 } 3243 /***************************************************************************** 3244 * Name : HMSetThreadTerminated 3245 * Purpose : 3246 * Parameters: 3247 * Variables : 3248 * Result : 3249 * Remark : 3250 * Status : 3251 * 3252 * Author : SvL 3253 *****************************************************************************/ 3254 BOOL HMSetThreadTerminated(HANDLE hThread) 3255 { 3256 int iIndex; /* index into the handle table */ 3257 BOOL lpResult; /* result from the device handler's API */ 3258 PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */ 3259 3260 SetLastError(ERROR_SUCCESS); 3261 /* validate handle */ 3262 iIndex = _HMHandleQuery(hThread); /* get the index */ 3263 if (-1 == iIndex) /* error ? */ 3264 { 3265 SetLastError(ERROR_INVALID_HANDLE); /* set win32 error information */ 3266 return FALSE; /* signal failure */ 3267 } 3268 3269 pHMHandle = &TabWin32Handles[iIndex]; /* call device handler */ 3270 lpResult = pHMHandle->pDeviceHandler->SetThreadTerminated(&TabWin32Handles[iIndex].hmHandleData); 3271 3272 return (lpResult); /* deliver return code */ 3273 }
Note:
See TracChangeset
for help on using the changeset viewer.