source: trunk/src/user32/win32wndhandle.cpp@ 9490

Last change on this file since 9490 was 9490, checked in by sandervl, 23 years ago

Fixed wrong access of global window handle critical section

File size: 4.0 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.17 2002-12-12 12:33:22 sandervl Exp $ */
2/*
3 * Win32 Handle Management Code for OS/2
4 *
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * TODO: The table should be dynamically increased when necessary
10 * This is just a quick and dirty implementation
11 * TODO: Probably need to clean up the table when app closes
12 * (also store PID and remove all handles with PID of terminating app)
13 * TODO: a linear list might not be the optimal implementation. Look
14 * into using some sort of tree (not important)
15 *
16 * Project Odin Software License can be found in LICENSE.TXT
17 *
18 */
19
20#include <os2win.h>
21#include <vmutex.h>
22#include "win32wndhandle.h"
23#include <custombuild.h>
24
25#define DBG_LOCALLOG DBG_win32wndhandle
26#include "dbglocal.h"
27
28//******************************************************************************
29
30//Global DLL Data
31#pragma data_seg(_GLOBALDATA)
32ULONG WindowHandleTable[MAX_WINDOW_HANDLES] = {0};
33CRITICAL_SECTION_OS2 globalwhandlecritsect = {0};
34ULONG lastIndex = 0;
35#pragma data_seg()
36
37static char *pszWndHandleSemName = WINHANDLE_CRITSECTION_NAME;
38
39//******************************************************************************
40//******************************************************************************
41void WIN32API SetCustomWndHandleSemName(LPSTR pszSemName)
42{
43 pszWndHandleSemName = pszSemName;
44}
45//******************************************************************************
46//******************************************************************************
47void InitializeWindowHandles()
48{
49 if(globalwhandlecritsect.hmtxLock == 0) {
50 DosInitializeCriticalSection(&globalwhandlecritsect, pszWndHandleSemName);
51 }
52 else {
53 dprintf(("InitializeWindowHandles -> access shared critical section"));
54 DosAccessCriticalSection(&globalwhandlecritsect, pszWndHandleSemName);
55 }
56}
57//******************************************************************************
58//******************************************************************************
59BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
60{
61 DosEnterCriticalSection(&globalwhandlecritsect);
62
63 //find next free handle
64 if(lastIndex >= MAX_WINDOW_HANDLES-1) {
65 lastIndex = 0;
66 }
67 for(int i=lastIndex;i<MAX_WINDOW_HANDLES;i++) {
68 if(WindowHandleTable[i] == 0) {
69 lastIndex = i;
70 break;
71 }
72 }
73 if(i == MAX_WINDOW_HANDLES) {
74 //oops, out of handles
75 DosLeaveCriticalSection(&globalwhandlecritsect);
76 dprintf(("ERROR: USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
77 DebugInt3();
78 return FALSE;
79 }
80 *hwnd = lastIndex+1; //we skip handle 0x68000000
81 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
82 WindowHandleTable[lastIndex] = dwUserData;
83
84 lastIndex++;
85 DosLeaveCriticalSection(&globalwhandlecritsect);
86 dprintf2(("HwAllocateWindowHandle %x", *hwnd));
87 return TRUE;
88}
89//******************************************************************************
90//******************************************************************************
91void HwFreeWindowHandle(HWND hwnd)
92{
93 hwnd = hwnd - 1; //we skip handle 0x68000000
94 hwnd &= WNDHANDLE_MAGIC_MASK;
95 if(hwnd < MAX_WINDOW_HANDLES) {
96 DosEnterCriticalSection(&globalwhandlecritsect);
97 WindowHandleTable[hwnd] = 0;
98 DosLeaveCriticalSection(&globalwhandlecritsect);
99 }
100 dprintf2(("HwFreeWindowHandle %x", hwnd));
101}
102//******************************************************************************
103//******************************************************************************
104BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
105{
106 hwnd = hwnd - 1; //we skip handle 0x68000000
107 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
108 return FALSE; //unknown window (PM?)
109 }
110 hwnd &= WNDHANDLE_MAGIC_MASK;
111 if(hwnd < MAX_WINDOW_HANDLES) {
112 *pdwUserData = WindowHandleTable[hwnd];
113 return TRUE;
114 }
115 *pdwUserData = 0;
116 return FALSE;
117}
118//******************************************************************************
119//******************************************************************************
Note: See TracBrowser for help on using the repository browser.