ReactOS  0.4.12-dev-934-g9a4676f
callproc.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * PURPOSE: Callproc support
5  * FILE: win32ss/user/ntuser/callproc.c
6  * PROGRAMER: Thomas Weidenmueller <w3seek@reactos.com>
7  */
8 
9 #include <win32k.h>
10 DBG_DEFAULT_CHANNEL(UserClass);
11 
12 /* CALLPROC ******************************************************************/
13 
14 WNDPROC
16 {
17  /* FIXME: Check for 64 bit architectures... */
18  return (WNDPROC)((ULONG_PTR)UserHMGetHandle(CallProc) | 0xFFFF0000);
19 }
20 
21 BOOLEAN
23 {
25  return TRUE;
26 }
27 
31  IN BOOL Unicode,
33 {
34  PCALLPROCDATA NewCallProc;
35  HANDLE Handle;
36 
37  /* We can send any thread pointer to the object manager here,
38  * What's important is the process info */
40  Desktop,
41  pi->ptiList,
42  &Handle,
44  sizeof(CALLPROCDATA));
45  if (NewCallProc != NULL)
46  {
47  NewCallProc->pfnClientPrevious = WndProc;
48  NewCallProc->wType |= Unicode ? UserGetCPDA2U : UserGetCPDU2A ;
49  NewCallProc->spcpdNext = NULL;
50 
51  /* Release the extra reference (UserCreateObject added 2 references) */
52  UserDereferenceObject(NewCallProc);
53  }
54 
55  return NewCallProc;
56 }
57 
58 BOOL
60  OUT PWNDPROC_INFO wpInfo)
61 {
62  PCALLPROCDATA CallProc;
63 
64  CallProc = UserGetObject(gHandleTable,
65  hCallProc,
67  if (CallProc == NULL)
68  {
69  return FALSE;
70  }
71 
72 /* Use Handle pEntry->ppi!
73  if (CallProc->pi != GetW32ProcessInfo())
74  {
75  return FALSE;
76  }*/
77 
78  wpInfo->WindowProc = CallProc->pfnClientPrevious;
79  wpInfo->IsUnicode = !!(CallProc->wType & UserGetCPDA2U);
80 
81  return TRUE;
82 }
83 
84 /*
85  Based on UserFindCallProc.
86  */
90  PCALLPROCDATA pcpd,
92  GETCPD Type)
93 {
94  while ( pcpd && (pcpd->pfnClientPrevious != WndProc || pcpd->wType != Type) )
95  {
96  pcpd = pcpd->spcpdNext;
97  }
98  return pcpd;
99 }
100 
101 /*
102  Get Call Proc Data handle for the window proc being requested or create a
103  new Call Proc Data handle to be return for the requested window proc.
104  */
105 ULONG_PTR
106 FASTCALL
108  PVOID pvClsWnd,
109  GETCPD Flags,
110  ULONG_PTR ProcIn)
111 {
112  PCLS pCls;
113  PWND pWnd;
114  PDESKTOP pDesk;
115  PCALLPROCDATA CallProc = NULL;
116  PTHREADINFO pti;
117 
119 
122  {
123  pWnd = pvClsWnd;
124  pCls = pWnd->pcls;
125  }
126  else
127  pCls = pvClsWnd;
128 
129  // Search Class call proc data list.
130  if (pCls->spcpdFirst)
131  CallProc = UserSearchForCallProc( pCls->spcpdFirst, (WNDPROC)ProcIn, Flags);
132 
133  // No luck, create a new one for the requested proc.
134  if (!CallProc)
135  {
136  if (!pCls->rpdeskParent)
137  {
138  TRACE("Null DESKTOP Atom %u\n",pCls->atomClassName);
139  pDesk = pti->rpdesk;
140  }
141  else
142  pDesk = pCls->rpdeskParent;
143  CallProc = CreateCallProc( pDesk,
144  (WNDPROC)ProcIn,
145  !!(Flags & UserGetCPDA2U),
146  pti->ppi);
147  if (CallProc)
148  {
149  CallProc->spcpdNext = pCls->spcpdFirst;
151  CallProc);
152  CallProc->wType = Flags;
153  }
154  }
155  return (ULONG_PTR)(CallProc ? GetCallProcHandle(CallProc) : NULL);
156 }
157 
158 /* SYSCALLS *****************************************************************/
159 
160 /*
161  Retrieve the WinProcA/W or CallProcData handle for Class, Dialog or Window.
162  This Function called from user space uses Window handle for class, window
163  and dialog procs only.
164 
165  Note:
166  ProcIn is the default proc from pCls/pDlg/pWnd->lpfnXxyz, caller is
167  looking for another type of proc if the original lpfnXxyz proc is preset
168  to Ansi or Unicode.
169 
170  Example:
171  If pWnd is created from Ansi and lpfnXxyz is assumed to be Ansi, caller
172  will ask for Unicode Proc return Proc or CallProcData handle.
173 */
174 ULONG_PTR
175 APIENTRY
177  HWND hWnd,
178  GETCPD Flags,
179  ULONG_PTR ProcIn)
180 {
181  PWND Wnd;
182  ULONG_PTR Result = 0;
183 
185  if (!(Wnd = UserGetWindowObject(hWnd)))
186  {
187  goto Cleanup;
188  }
189 
190  // Processing Window only from User space.
192  Result = UserGetCPD(Wnd, Flags, ProcIn);
193 
194 Cleanup:
195  UserLeave();
196  return Result;
197 }
198 
#define IN
Definition: typedefs.h:38
BOOL FASTCALL UserDeleteObject(HANDLE h, HANDLE_TYPE type)
Definition: object.c:683
#define TRUE
Definition: types.h:120
struct _DESKTOP * rpdeskParent
Definition: ntuser.h:539
WNDPROC pfnClientPrevious
Definition: ntuser.h:520
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
Type
Definition: Type.h:6
enum _GETCPD GETCPD
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
BOOL UserGetCallProcInfo(IN HANDLE hCallProc, OUT PWNDPROC_INFO wpInfo)
Definition: callproc.c:59
HWND hWnd
Definition: settings.c:17
BOOL FASTCALL UserDereferenceObject(PVOID Object)
Definition: object.c:610
ULONG_PTR APIENTRY NtUserGetCPD(HWND hWnd, GETCPD Flags, ULONG_PTR ProcIn)
Definition: callproc.c:176
ULONG_PTR FASTCALL UserGetCPD(PVOID pvClsWnd, GETCPD Flags, ULONG_PTR ProcIn)
Definition: callproc.c:107
#define FASTCALL
Definition: nt_native.h:50
RTL_ATOM atomClassName
Definition: ntuser.h:536
struct _DESKTOP * rpdesk
Definition: win32.h:91
PVOID FASTCALL UserCreateObject(PUSER_HANDLE_TABLE ht, PDESKTOP pDesktop, PTHREADINFO pti, HANDLE *h, HANDLE_TYPE type, ULONG size)
Definition: object.c:535
WNDPROC GetCallProcHandle(IN PCALLPROCDATA CallProc)
Definition: callproc.c:15
PPROCESSINFO ppi
Definition: win32.h:87
PCALLPROCDATA CreateCallProc(IN PDESKTOP Desktop, IN WNDPROC WndProc, IN BOOL Unicode, IN PPROCESSINFO pi)
Definition: callproc.c:29
uint32_t ULONG_PTR
Definition: typedefs.h:63
struct _CALLPROCDATA * spcpdNext
Definition: ntuser.h:519
GETCPD wType
Definition: ntuser.h:521
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOLEAN DestroyCallProc(_Inout_ PVOID Object)
Definition: callproc.c:22
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: ntuser.h:533
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:103
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
#define UserHMGetHandle(obj)
Definition: ntuser.h:208
PCALLPROCDATA spcpdFirst
Definition: ntuser.h:544
_In_ HANDLE Handle
Definition: extypes.h:390
#define TRACE(s)
Definition: solgame.cpp:4
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
#define _Inout_
Definition: no_sal2.h:244
static IUnknown Object
Definition: main.c:512
static DWORD pi
Definition: protocol.c:150
struct _CALLPROCDATA * PCALLPROCDATA
static const WCHAR Cleanup[]
Definition: register.c:80
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
Definition: solitaire.cpp:598
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2859
Definition: ntuser.h:657
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, HANDLE_TYPE type)
Definition: object.c:462
DBG_DEFAULT_CHANNEL(UserClass)
#define OUT
Definition: typedefs.h:39
#define ULONG_PTR
Definition: config.h:101
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13
#define APIENTRY
Definition: api.h:79
PCALLPROCDATA FASTCALL UserSearchForCallProc(PCALLPROCDATA pcpd, WNDPROC WndProc, GETCPD Type)
Definition: callproc.c:89
PCLS pcls
Definition: ntuser.h:684