Changeset 3128 for trunk/src


Ignore:
Timestamp:
Mar 16, 2000, 8:21:54 PM (25 years ago)
Author:
sandervl
Message:

handlemanager support for thread handles + WaitForSingleObject (thread) fix

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

Legend:

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

    r2802 r3128  
    1 /* $Id: HandleManager.cpp,v 1.35 2000-02-16 14:23:57 sandervl Exp $ */
     1/* $Id: HandleManager.cpp,v 1.36 2000-03-16 19:20:36 sandervl Exp $ */
    22
    33/*
     
    5757#include "HMComm.h"
    5858#include "HMToken.h"
    59 #include <winconst.h>
     59#include "HMThread.h"
     60#include <vmutex.h>
    6061
    6162#define DBG_LOCALLOG    DBG_handlemanager
     
    109110            /* the device name is repeated here to enable device alias names */
    110111static PHMDEVICE TabWin32Devices = NULL;
     112
    111113static HMHANDLE TabWin32Handles[MAX_OS2_HMHANDLES];   /* static handle table */
    112 
     114VMutex          handleMutex;
    113115
    114116struct _HMGlobals
     
    128130  HMDeviceHandler        *pHMComm;                   /* serial communication */
    129131  HMDeviceHandler        *pHMToken;         /* security tokens */
     132  HMDeviceHandler        *pHMThread;
    130133
    131134  ULONG         ulHandleLast;                   /* index of last used handle */
     
    195198  register ULONG ulLoop;
    196199
     200  handleMutex.enter();
     201
    197202  for (ulLoop = 1; // @@@PH Note, this is an experimental change
    198203                   // 0L as hHandle is sometimes considered invalid!
     
    205210        TabWin32Handles[ulLoop].hmHandleData.dwUserData     = 0;
    206211        TabWin32Handles[ulLoop].hmHandleData.dwInternalType = HMTYPE_UNKNOWN;
     212        handleMutex.leave();
    207213        return (ulLoop);                    /* OK, then return it to the caller */
    208214    }
    209215  }
    210216
     217  handleMutex.leave();
    211218  return (INVALID_HANDLE_VALUE);             /* haven't found any free handle */
    212219}
     
    326333    HMGlobals.fIsInitialized = TRUE;                             /* OK, done */
    327334
     335    handleMutex.enter();
    328336    // 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();
    333341
    334342    dprintf(("KERNEL32:HandleManager:HMInitialize() storing handles.\n"));
     
    338346           sizeof(HMGlobals));
    339347
    340                        /* copy standard handles from OS/2's Open32 Subsystem */
     348    /* copy standard handles from OS/2's Open32 Subsystem */
    341349    HMSetStdHandle(STD_INPUT_HANDLE,  GetStdHandle(STD_INPUT_HANDLE));
    342350    HMSetStdHandle(STD_OUTPUT_HANDLE, GetStdHandle(STD_OUTPUT_HANDLE));
     
    351359    HMGlobals.pHMComm       = new HMDeviceCommClass("\\\\COM\\");
    352360    HMGlobals.pHMToken      = new HMDeviceTokenClass("\\\\TOKEN\\");
     361    HMGlobals.pHMThread     = new HMDeviceThreadClass("\\\\THREAD\\");
    353362  }
    354363  return (NO_ERROR);
     
    408417 *****************************************************************************/
    409418
    410 DWORD  HMHandleAllocate (PULONG phHandle16,
    411                          ULONG  hHandleOS2)
     419DWORD HMHandleAllocate (PULONG phHandle16,
     420                        ULONG  hHandleOS2)
    412421{
    413422  register ULONG ulHandle;
     
    421430  ulHandle = HMGlobals.ulHandleLast;                      /* get free handle */
    422431
     432  handleMutex.enter();
     433
    423434  if(ulHandle == 0) {
    424435        ulHandle = 1; //SvL: Start searching from index 1
     
    426437  do
    427438  {
    428                                                   /* check if handle is free */
     439    /* check if handle is free */
    429440    if (TabWin32Handles[ulHandle].hmHandleData.hHMHandle == INVALID_HANDLE_VALUE)
    430441    {
    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 */
    436448    }
    437449
     
    442454  }
    443455  while (ulHandle != HMGlobals.ulHandleLast);
     456
     457  handleMutex.leave();
    444458
    445459  return (ERROR_TOO_MANY_OPEN_FILES);                      /* OK, we're done */
     
    29102924  return STATUS_SUCCESS;
    29112925}
    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 *****************************************************************************/
     2937HANDLE 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 *****************************************************************************/
     3005INT 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 *****************************************************************************/
     3036DWORD 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 *****************************************************************************/
     3067BOOL 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 *****************************************************************************/
     3098BOOL 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 *****************************************************************************/
     3129BOOL 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 *****************************************************************************/
     3160BOOL 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 *****************************************************************************/
     3191DWORD 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 *****************************************************************************/
     3223BOOL 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 *****************************************************************************/
     3254BOOL 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}
  • trunk/src/kernel32/dbglocal.cpp

    r3059 r3128  
    1 /* $Id: dbglocal.cpp,v 1.3 2000-03-09 19:03:18 sandervl Exp $ */
     1/* $Id: dbglocal.cpp,v 1.4 2000-03-16 19:20:37 sandervl Exp $ */
    22
    33/*
     
    112112"oslibdebug",
    113113"registry",
    114 "queue"
     114"queue",
     115"hmthread",
     116"hmprocess"
    115117};
    116118//******************************************************************************
  • trunk/src/kernel32/dbglocal.h

    r3059 r3128  
    1 /* $Id: dbglocal.h,v 1.3 2000-03-09 19:03:18 sandervl Exp $ */
     1/* $Id: dbglocal.h,v 1.4 2000-03-16 19:20:37 sandervl Exp $ */
    22
    33/*
     
    113113#define DBG_registry       92
    114114#define DBG_queue          93
    115 #define DBG_MAXFILES       94
     115#define DBG_hmthread       94
     116#define DBG_hmprocess      95
     117#define DBG_MAXFILES       96
    116118
    117119extern USHORT DbgEnabled[DBG_MAXFILES];
  • trunk/src/kernel32/hmdevice.cpp

    r2802 r3128  
    1 /* $Id: hmdevice.cpp,v 1.16 2000-02-16 14:23:58 sandervl Exp $ */
     1/* $Id: hmdevice.cpp,v 1.17 2000-03-16 19:20:37 sandervl Exp $ */
    22
    33/*
     
    11731173  return ERROR_INVALID_HANDLE;
    11741174}
     1175/*****************************************************************************
     1176 * Name      : DWORD HMDeviceHandler::CreateThread
     1177 * Purpose   :
     1178 * Variables :
     1179 * Result    :
     1180 * Remark    :
     1181 * Status    :
     1182 *
     1183 * Author    : SvL
     1184 *****************************************************************************/
     1185HANDLE HMDeviceHandler::CreateThread(PHMHANDLEDATA pHMHandleData,
     1186                                     LPSECURITY_ATTRIBUTES  lpsa,
     1187                                     DWORD                  cbStack,
     1188                                     LPTHREAD_START_ROUTINE lpStartAddr,
     1189                                     LPVOID                 lpvThreadParm,
     1190                                     DWORD                  fdwCreate,
     1191                                     LPDWORD                lpIDThread)
     1192{
     1193  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::CreateThread %08xh",
     1194           pHMHandleData->hHMHandle));
     1195
     1196  return ERROR_INVALID_HANDLE;
     1197}
     1198/*****************************************************************************
     1199 * Name      : DWORD HMDeviceHandler::GetThreadPriority
     1200 * Purpose   :
     1201 * Variables :
     1202 * Result    :
     1203 * Remark    :
     1204 * Status    :
     1205 *
     1206 * Author    : SvL
     1207 *****************************************************************************/
     1208INT HMDeviceHandler::GetThreadPriority(PHMHANDLEDATA pHMHandleData)
     1209{
     1210  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::GetThreadPriority %08xh",
     1211           pHMHandleData->hHMHandle));
     1212
     1213  return ERROR_INVALID_HANDLE;
     1214}
     1215/*****************************************************************************
     1216 * Name      : DWORD HMDeviceHandler::SuspendThread
     1217 * Purpose   :
     1218 * Variables :
     1219 * Result    :
     1220 * Remark    :
     1221 * Status    :
     1222 *
     1223 * Author    : SvL
     1224 *****************************************************************************/
     1225DWORD HMDeviceHandler::SuspendThread(PHMHANDLEDATA pHMHandleData)
     1226{
     1227  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::SuspendThread %08xh",
     1228           pHMHandleData->hHMHandle));
     1229
     1230  return ERROR_INVALID_HANDLE;
     1231}
     1232/*****************************************************************************
     1233 * Name      : DWORD HMDeviceHandler::SetThreadPriority
     1234 * Purpose   :
     1235 * Variables :
     1236 * Result    :
     1237 * Remark    :
     1238 * Status    :
     1239 *
     1240 * Author    : SvL
     1241 *****************************************************************************/
     1242BOOL HMDeviceHandler::SetThreadPriority(PHMHANDLEDATA pHMHandleData, int priority)
     1243{
     1244  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::SetThreadPriority %08xh",
     1245           pHMHandleData->hHMHandle));
     1246
     1247  return ERROR_INVALID_HANDLE;
     1248}
     1249/*****************************************************************************
     1250 * Name      : DWORD HMDeviceHandler::GetThreadContext
     1251 * Purpose   :
     1252 * Variables :
     1253 * Result    :
     1254 * Remark    :
     1255 * Status    :
     1256 *
     1257 * Author    : SvL
     1258 *****************************************************************************/
     1259BOOL HMDeviceHandler::GetThreadContext(PHMHANDLEDATA pHMHandleData, PCONTEXT lpContext)
     1260{
     1261  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::GetThreadContext %08xh",
     1262           pHMHandleData->hHMHandle));
     1263
     1264  return ERROR_INVALID_HANDLE;
     1265}
     1266/*****************************************************************************
     1267 * Name      : DWORD HMDeviceHandler::SetThreadContext
     1268 * Purpose   :
     1269 * Variables :
     1270 * Result    :
     1271 * Remark    :
     1272 * Status    :
     1273 *
     1274 * Author    : SvL
     1275 *****************************************************************************/
     1276BOOL HMDeviceHandler::SetThreadContext(PHMHANDLEDATA pHMHandleData, const CONTEXT *lpContext)
     1277{
     1278  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::SetThreadContext %08xh",
     1279           pHMHandleData->hHMHandle));
     1280
     1281  return ERROR_INVALID_HANDLE;
     1282}
     1283/*****************************************************************************
     1284 * Name      : DWORD HMDeviceHandler::TerminateThread
     1285 * Purpose   :
     1286 * Variables :
     1287 * Result    :
     1288 * Remark    :
     1289 * Status    :
     1290 *
     1291 * Author    : SvL
     1292 *****************************************************************************/
     1293BOOL HMDeviceHandler::TerminateThread(PHMHANDLEDATA pHMHandleData, DWORD exitcode)
     1294{
     1295  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::TerminateThread %08xh",
     1296           pHMHandleData->hHMHandle));
     1297
     1298  return ERROR_INVALID_HANDLE;
     1299}
     1300/*****************************************************************************
     1301 * Name      : DWORD HMDeviceHandler::ResumeThread
     1302 * Purpose   :
     1303 * Variables :
     1304 * Result    :
     1305 * Remark    :
     1306 * Status    :
     1307 *
     1308 * Author    : SvL
     1309 *****************************************************************************/
     1310DWORD  HMDeviceHandler::ResumeThread(PHMHANDLEDATA pHMHandleData)
     1311{
     1312  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::ResumeThread %08xh",
     1313           pHMHandleData->hHMHandle));
     1314
     1315  return ERROR_INVALID_HANDLE;
     1316}
     1317/*****************************************************************************
     1318 * Name      : DWORD HMDeviceHandler::GetExitCodeThread
     1319 * Purpose   :
     1320 * Variables :
     1321 * Result    :
     1322 * Remark    :
     1323 * Status    :
     1324 *
     1325 * Author    : SvL
     1326 *****************************************************************************/
     1327BOOL HMDeviceHandler::GetExitCodeThread(PHMHANDLEDATA pHMHandleData, LPDWORD lpExitCode)
     1328{
     1329  dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::GetExitCodeThread %08xh",
     1330           pHMHandleData->hHMHandle));
     1331
     1332  return ERROR_INVALID_HANDLE;
     1333}
     1334/*****************************************************************************
     1335 * Name      : DWORD HMDeviceHandler::SetThreadTerminated
     1336 * Purpose   :
     1337 * Variables :
     1338 * Result    :
     1339 * Remark    :
     1340 * Status    :
     1341 *
     1342 * Author    : SvL
     1343 *****************************************************************************/
     1344BOOL HMDeviceHandler::SetThreadTerminated(PHMHANDLEDATA pHMHandleData)
     1345{
     1346    return FALSE;
     1347}
  • trunk/src/kernel32/hmdevice.h

    r2329 r3128  
    1 /* $Id: hmdevice.h,v 1.15 2000-01-05 19:39:56 sandervl Exp $ */
     1/* $Id: hmdevice.h,v 1.16 2000-03-16 19:20:38 sandervl Exp $ */
    22
    33/*
     
    3030#define HMTYPE_PROCESSTOKEN     3
    3131#define HMTYPE_THREADTOKEN      4
     32#define HMTYPE_THREAD           5
     33
    3234//.....
    3335
     
    6668
    6769  HMDeviceHandler(LPCSTR lpDeviceName);      /* constructor with device name */
    68 
    6970
    7071  /***********************************
     
    302303                                  HANDLE  ProcessHandle);
    303304
     305 virtual HANDLE CreateThread(PHMHANDLEDATA          pHMHandleData,
     306                             LPSECURITY_ATTRIBUTES  lpsa,
     307                             DWORD                  cbStack,
     308                             LPTHREAD_START_ROUTINE lpStartAddr,
     309                             LPVOID                 lpvThreadParm,
     310                             DWORD                  fdwCreate,
     311                             LPDWORD                lpIDThread);
     312
     313 virtual INT    GetThreadPriority(PHMHANDLEDATA pHMHandleData);
     314 virtual DWORD  SuspendThread(PHMHANDLEDATA pHMHandleData);
     315 virtual BOOL   SetThreadPriority(PHMHANDLEDATA pHMHandleData, int priority);
     316
     317 virtual BOOL   GetThreadContext(PHMHANDLEDATA pHMHandleData, PCONTEXT lpContext);
     318 virtual BOOL   SetThreadContext(PHMHANDLEDATA pHMHandleData, const CONTEXT *lpContext);
     319
     320 virtual BOOL   TerminateThread(PHMHANDLEDATA pHMHandleData, DWORD exitcode);
     321 virtual DWORD  ResumeThread(PHMHANDLEDATA pHMHandleData);
     322 virtual BOOL   SetThreadTerminated(PHMHANDLEDATA pHMHandleData);
     323
     324 virtual BOOL   GetExitCodeThread(PHMHANDLEDATA pHMHandleData, LPDWORD lpExitCode);
    304325};
    305326
  • trunk/src/kernel32/initterm.cpp

    r3074 r3128  
    1 /* $Id: initterm.cpp,v 1.38 2000-03-10 16:11:59 sandervl Exp $ */
     1/* $Id: initterm.cpp,v 1.39 2000-03-16 19:20:39 sandervl Exp $ */
    22
    33/*
     
    159159            OSLibDosSetInitialMaxFileHandles(ODIN_DEFAULT_MAX_FILEHANDLES);
    160160
    161             InitializeTIB(TRUE);
    162161            //SvL: Do it here instead of during the exe object creation
    163162            //(std handles can be used in win32 dll initialization routines
    164163            HMInitialize();             /* store standard handles within HandleManager */
     164            InitializeTIB(TRUE);        //MUST be done after HMInitialize!
    165165            InitDirectories();
    166166            RegisterDevices();
     
    192192    //Flush and delete all open memory mapped files
    193193    Win32MemMap::deleteAll();
     194    WinExe = NULL;
    194195
    195196    WriteOutProfiles();
  • trunk/src/kernel32/kobjects.cpp

    r2802 r3128  
    1 /* $Id: kobjects.cpp,v 1.9 2000-02-16 14:25:41 sandervl Exp $ */
     1/* $Id: kobjects.cpp,v 1.10 2000-03-16 19:20:39 sandervl Exp $ */
    22
    33/*
     
    786786}
    787787
    788 
     788//******************************************************************************
     789//******************************************************************************
     790ODINFUNCTION6(HANDLE,CreateThread,LPSECURITY_ATTRIBUTES,  lpsa,
     791                                  DWORD,                  cbStack,
     792                                  LPTHREAD_START_ROUTINE, lpStartAddr,
     793                                  LPVOID,                 lpvThreadParm,
     794                                  DWORD,                  fdwCreate,
     795                                  LPDWORD,                lpIDThread)
     796{
     797    return HMCreateThread(lpsa, cbStack, lpStartAddr, lpvThreadParm, fdwCreate, lpIDThread);
     798}
     799//******************************************************************************
     800//******************************************************************************
     801INT WIN32API GetThreadPriority(HANDLE hThread)
     802{
     803    return HMGetThreadPriority(hThread);
     804}
     805//******************************************************************************
     806//******************************************************************************
     807DWORD WIN32API SuspendThread(HANDLE hThread)
     808{
     809    return HMSuspendThread(hThread);
     810}
     811//******************************************************************************
     812//******************************************************************************
     813BOOL WIN32API SetThreadPriority(HANDLE hThread, int priority)
     814{
     815  return HMSetThreadPriority(hThread, priority);
     816}
     817//******************************************************************************
     818//******************************************************************************
     819BOOL WIN32API GetThreadContext(HANDLE hThread, PCONTEXT lpContext)
     820{
     821  return HMGetThreadContext(hThread, lpContext);
     822}
     823//******************************************************************************
     824//******************************************************************************
     825BOOL WIN32API SetThreadContext(HANDLE hThread, const CONTEXT *lpContext)
     826{
     827  return HMSetThreadContext(hThread, lpContext);
     828}
     829//******************************************************************************
     830//******************************************************************************
     831BOOL WIN32API TerminateThread(HANDLE hThread, DWORD exitcode)
     832{
     833  return HMTerminateThread(hThread, exitcode);
     834}
     835//******************************************************************************
     836//******************************************************************************
     837DWORD WIN32API ResumeThread(HANDLE hThread)
     838{
     839  return HMResumeThread(hThread);
     840}
     841//******************************************************************************
     842//******************************************************************************
     843BOOL WIN32API GetExitCodeThread(HANDLE hThread, LPDWORD arg2)
     844{
     845    return HMGetExitCodeThread(hThread, arg2);
     846}
     847//******************************************************************************
     848//******************************************************************************
  • trunk/src/kernel32/makefile

    r3059 r3128  
    1 # $Id: makefile,v 1.90 2000-03-09 19:03:19 sandervl Exp $
     1# $Id: makefile,v 1.91 2000-03-16 19:20:39 sandervl Exp $
    22
    33#
     
    118118$(OBJDIR)\registry.obj \
    119119$(OBJDIR)\queue.obj \
     120$(OBJDIR)\hmthread.obj \
    120121$(OBJDIR)\kernelrsrc.obj
    121122
  • trunk/src/kernel32/thread.H

    r126 r3128  
    1 /* $Id: thread.H,v 1.5 1999-06-20 10:55:36 sandervl Exp $ */
     1/* $Id: thread.H,v 1.6 2000-03-16 19:20:40 sandervl Exp $ */
    22
    33/*
     
    2020{
    2121public:
    22     Win32Thread(LPTHREAD_START_ROUTINE pUserCallback, LPVOID lpData, DWORD dwFlags);
    23     ~Win32Thread();
     22    Win32Thread(LPTHREAD_START_ROUTINE pUserCallback, LPVOID lpData, DWORD dwFlags, HANDLE hThread);
    2423
    25     PTHREAD_START_ROUTINE_O32 GetOS2Callback();
     24    PTHREAD_START_ROUTINE_O32 GetOS2Callback()  { return Win32ThreadProc; };
     25
    2626private:
    2727
     
    2929 LPTHREAD_START_ROUTINE pCallback;
    3030 DWORD       dwFlags;
     31 HANDLE      hThread;
    3132
    32  friend static DWORD OPEN32API Win32ThreadProc(LPVOID lpData);
     33 friend DWORD OPEN32API Win32ThreadProc(LPVOID lpData);
    3334};
    3435
  • trunk/src/kernel32/thread.cpp

    r2802 r3128  
    1 /* $Id: thread.cpp,v 1.23 2000-02-16 14:23:12 sandervl Exp $ */
     1/* $Id: thread.cpp,v 1.24 2000-03-16 19:20:40 sandervl Exp $ */
    22
    33/*
     
    2424#include <string.h>
    2525#include "thread.h"
    26 #include "exceptutil.h"
    2726#include <misc.h>
    2827#include <wprocess.h>
     
    3130#include "exceptutil.h"
    3231#include "oslibmisc.h"
     32#include <handlemanager.h>
    3333
    3434#define DBG_LOCALLOG    DBG_thread
     
    3737ODINDEBUGCHANNEL(KERNEL32-THREAD)
    3838
    39 
    40 static DWORD OPEN32API Win32ThreadProc(LPVOID lpData);
    41 
    42 
    43 //******************************************************************************
    44 //******************************************************************************
    45 ODINFUNCTION6(HANDLE,CreateThread,LPSECURITY_ATTRIBUTES,  lpsa,
    46                                   DWORD,                  cbStack,
    47                                   LPTHREAD_START_ROUTINE, lpStartAddr,
    48                                   LPVOID,                 lpvThreadParm,
    49                                   DWORD,                  fdwCreate,
    50                                   LPDWORD,                lpIDThread)
    51 {
    52   Win32Thread *winthread;
    53 
    54   winthread = new Win32Thread(lpStartAddr, lpvThreadParm, fdwCreate);
    55 
    56   if(winthread == 0)
    57     return(0);
    58 
    59 #ifdef DEBUG
    60   // @@@PH Note: with debug code enabled, ODIN might request more stack space!
    61   if (cbStack > 0)
    62      cbStack <<= 1;     // double stack
    63   else
    64      cbStack = 1048576; // per default 1MB stack per thread
    65 #endif
    66 
    67   return(O32_CreateThread(lpsa,
    68                           cbStack,
    69                           winthread->GetOS2Callback(),
    70                           (LPVOID)winthread,
    71                           fdwCreate,
    72                           lpIDThread));
    73 }
    7439//******************************************************************************
    7540//******************************************************************************
     
    8348HANDLE WIN32API GetCurrentThread()
    8449{
    85 ////  dprintf(("GetCurrentThread\n"));
    86   return(O32_GetCurrentThread());
    87 }
    88 //******************************************************************************
    89 //******************************************************************************
    90 BOOL WIN32API GetExitCodeThread(HANDLE hThread, LPDWORD arg2)
    91 {
    92     dprintf(("GetExitCodeThread (%08xh,%08xh)\n",
    93              hThread,
    94              arg2));
     50 THDB *thdb;
    9551
    96     return O32_GetExitCodeThread(hThread, arg2);
    97 }
    98 //******************************************************************************
    99 //******************************************************************************
    100 BOOL WIN32API TerminateThread(HANDLE hThread, DWORD arg2)
    101 {
    102     dprintf(("TerminateThread (%08xh,%08xh)\n",
    103              hThread,
    104              arg2));
    105 
    106     return O32_TerminateThread(hThread, arg2);
    107 }
    108 //******************************************************************************
    109 //******************************************************************************
    110 DWORD WIN32API ResumeThread(HANDLE hThread)
    111 {
    112     dprintf(("ResumeThread (%08xh)\n",
    113              hThread));
    114 
    115     return O32_ResumeThread(hThread);
    116 }
    117 //******************************************************************************
    118 //******************************************************************************
    119 INT WIN32API GetThreadPriority(HANDLE hThread)
    120 {
    121     dprintf(("OS2GetThreadPriority(%08xh)\n",
    122              hThread));
    123 
    124     return O32_GetThreadPriority(hThread);
    125 }
    126 //******************************************************************************
    127 //******************************************************************************
    128 DWORD WIN32API SuspendThread(HANDLE hThread)
    129 {
    130     dprintf(("OS2SuspendThread %08xh)\n",
    131              hThread));
    132 
    133     return O32_SuspendThread(hThread);
    134 }
    135 //******************************************************************************
    136 //******************************************************************************
    137 BOOL WIN32API SetThreadPriority(HANDLE hThread, int priority)
    138 {
    139     dprintf(("OS2SetThreadPriority (%08xh,%08xh)\n",
    140              hThread,
    141              priority));
    142 
    143     return O32_SetThreadPriority(hThread, priority);
    144 }
    145 //******************************************************************************
    146 //TODO: Implement this??
    147 //******************************************************************************
    148 BOOL WIN32API GetThreadContext(HANDLE hThread, PCONTEXT lpContext)
    149 {
    150   dprintf(("GetThreadContext NOT IMPLEMENTED!! (TRUE)\n"));
    151   memset(lpContext, 0, sizeof(CONTEXT));
    152 
    153   /* make up some plausible values for segment registers */
    154   lpContext->SegCs   = getCS();
    155   lpContext->SegDs   = getDS();
    156   lpContext->SegSs   = getSS();
    157   lpContext->SegEs   = getES();
    158   lpContext->SegGs   = getGS();
    159   lpContext->SegFs   = GetFS();
    160 
    161   return TRUE;
    162 }
    163 //******************************************************************************
    164 //TODO: Implement this??
    165 //******************************************************************************
    166 BOOL WIN32API SetThreadContext(HANDLE hThread, const CONTEXT *lpContext)
    167 {
    168   dprintf(("SetThreadContext NOT IMPLEMENTED!!\n"));
    169 
    170   return FALSE;
     52    thdb = GetThreadTHDB();
     53    if(thdb == 0) {
     54        SetLastError(ERROR_INVALID_HANDLE); //todo
     55        return 0;
     56    }
     57    return thdb->hThread;
    17158}
    17259//******************************************************************************
     
    17461VOID WIN32API ExitThread(DWORD exitcode)
    17562{
    176   dprintf(("ExitThread (%08xu)\n",
    177            exitcode));
     63 EXCEPTION_FRAME *exceptFrame;
     64 THDB            *thdb;
    17865
     66  dprintf(("ExitThread %x (%x)", GetCurrentThread(), exitcode));
     67
     68  thdb = GetThreadTHDB();
     69  if(thdb != 0) {
     70        exceptFrame = (EXCEPTION_FRAME *)thdb->exceptFrame;
     71  }
     72  else  DebugInt3();
     73
     74  HMSetThreadTerminated(GetCurrentThread());
    17975  Win32DllBase::detachThreadFromAllDlls();      //send DLL_THREAD_DETACH message to all dlls
    18076  Win32DllBase::tlsDetachThreadFromAllDlls(); //destroy TLS structures of all dlls
    18177  WinExe->tlsDetachThread();                    //destroy TLS structure of main exe
    18278  DestroyTIB();
     79
     80  if(exceptFrame) OS2UnsetExceptionHandler((void *)exceptFrame);
     81
    18382  O32_ExitThread(exitcode);
    18483}
    18584//******************************************************************************
    18685//******************************************************************************
    187 Win32Thread::Win32Thread(LPTHREAD_START_ROUTINE pUserCallback, LPVOID lpData, DWORD dwFlags)
     86Win32Thread::Win32Thread(LPTHREAD_START_ROUTINE pUserCallback, LPVOID lpData, DWORD dwFlags, HANDLE hThread)
    18887{
    18988  lpUserData = lpData;
    19089  pCallback  = pUserCallback;
    19190  this->dwFlags = dwFlags;
     91  this->hThread = hThread;
    19292}
    19393//******************************************************************************
    19494//******************************************************************************
    195 Win32Thread::~Win32Thread()
    196 {
    197 
    198 }
    199 //******************************************************************************
    200 //******************************************************************************
    201 PTHREAD_START_ROUTINE_O32 Win32Thread::GetOS2Callback()
    202 {
    203   return Win32ThreadProc;
    204 }
    205 //******************************************************************************
    206 //******************************************************************************
    207 static DWORD OPEN32API Win32ThreadProc(LPVOID lpData)
     95DWORD OPEN32API Win32ThreadProc(LPVOID lpData)
    20896{
    20997 EXCEPTION_FRAME exceptFrame;
     
    21199 WIN32THREADPROC  winthread = me->pCallback;
    212100 LPVOID           userdata  = me->lpUserData;
     101 HANDLE           hThread   = me->hThread;
    213102 DWORD            rc;
    214103
     
    227116  thdb->entry_point = (void *)winthread;
    228117  thdb->entry_arg   = (void *)userdata;
     118  thdb->hThread     = hThread;
    229119
    230120  thdb->hab = OSLibWinInitialize();
     
    235125  //      in OS/2
    236126  OS2SetExceptionHandler((void *)&exceptFrame);
     127  thdb->exceptFrame = (ULONG)&exceptFrame;
    237128
    238129  SetWin32TIB();
     
    243134  rc = winthread(userdata);
    244135
     136  HMSetThreadTerminated(GetCurrentThread());
     137  thdb->exceptFrame = 0;
    245138  Win32DllBase::detachThreadFromAllDlls();  //send DLL_THREAD_DETACH message to all dlls
    246139  Win32DllBase::tlsDetachThreadFromAllDlls(); //destroy TLS structures of all dlls
  • trunk/src/kernel32/wprocess.cpp

    r3059 r3128  
    1 /* $Id: wprocess.cpp,v 1.72 2000-03-09 19:03:23 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.73 2000-03-16 19:20:40 sandervl Exp $ */
    22
    33/*
     
    2626#include "winfakepeldr.h"
    2727#include <vmutex.h>
     28#include <handlemanager.h>
    2829
    2930#ifdef __IBMCPP__
     
    126127  TEB   *winteb;
    127128  THDB  *thdb;
    128 
     129  ULONG  hThreadMain;
    129130  USHORT tibsel;
    130131
    131132   //Allocate one dword to store the flat address of our TEB
    132133   if(fMainThread) {
    133     TIBFlatPtr = (DWORD *)OSLibAllocThreadLocalMemory(1);
    134     if(TIBFlatPtr == 0) {
    135         dprintf(("InitializeTIB: local thread memory alloc failed!!"));
    136         DebugInt3();
    137         return NULL;
    138     }
     134        TIBFlatPtr = (DWORD *)OSLibAllocThreadLocalMemory(1);
     135        if(TIBFlatPtr == 0) {
     136                dprintf(("InitializeTIB: local thread memory alloc failed!!"));
     137                DebugInt3();
     138                return NULL;
     139        }
     140        HMHandleAllocate(&hThreadMain, O32_GetCurrentThread());
    139141   }
    140142   if(OSLibAllocSel(PAGE_SIZE, &tibsel) == FALSE)
    141143   {
    142     dprintf(("InitializeTIB: selector alloc failed!!"));
    143     DebugInt3();
    144     return NULL;
     144        dprintf(("InitializeTIB: selector alloc failed!!"));
     145        DebugInt3();
     146        return NULL;
    145147   }
    146148   winteb = (TEB *)OSLibSelToFlat(tibsel);
    147149   if(winteb == NULL)
    148150   {
    149     dprintf(("InitializeTIB: DosSelToFlat failed!!"));
    150     DebugInt3();
    151     return NULL;
     151        dprintf(("InitializeTIB: DosSelToFlat failed!!"));
     152        DebugInt3();
     153        return NULL;
    152154   }
    153155   memset(winteb, 0, PAGE_SIZE);
     
    173175   thdb->pWsockData      = NULL;
    174176   thdb->threadId        = GetCurrentThreadId();
    175    thdb->hThread         = GetCurrentThread();
     177   if(fMainThread) {
     178        thdb->hThread    = hThreadMain;
     179   }
     180   else thdb->hThread    = GetCurrentThread();
    176181
    177182   threadListMutex.enter();
Note: See TracChangeset for help on using the changeset viewer.