Skip to content

Commit ad26cd5

Browse files
committed
[ARWINSS]
- Factor out Win32 thread info create/destroy into UserCreateThreadInfo and UserDestroyThreadInfo like in trunk. - Improve NtUserInitialize. svn path=/branches/arwinss/; revision=62851
1 parent 3e3a3dd commit ad26cd5

File tree

2 files changed

+108
-45
lines changed

2 files changed

+108
-45
lines changed

arwinss/server/main/csr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ CsrInit(void)
4848
CsrProcess = PsGetCurrentProcess();
4949
DPRINT("Win32k registered with CSRSS\n");
5050
#else
51-
UNIMPLEMENTED;
51+
CsrProcess = PsGetCurrentProcess();
52+
DPRINT("Win32k called by CSRSS\n");
5253
#endif
5354
}
5455

arwinss/server/main/init.c

Lines changed: 106 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,83 @@ NTSTATUS FASTCALL InitDcImpl(VOID);
2828
PGDI_HANDLE_TABLE GdiHandleTable = NULL;
2929
PSECTION_OBJECT GdiTableSection = NULL;
3030
LIST_ENTRY GlobalDriverListHead;
31+
BOOL gbInitialized;
3132

3233
/* PRIVATE FUNCTIONS *********************************************************/
3334

35+
NTSTATUS
36+
APIENTRY
37+
UserCreateThreadInfo(PETHREAD Thread)
38+
{
39+
struct _EPROCESS *Process;
40+
PTHREADINFO Win32Thread;
41+
PPROCESSINFO Win32Process;
42+
43+
Process = Thread->ThreadsProcess;
44+
45+
/* Get the Win32 Thread and Process */
46+
Win32Thread = PsGetThreadWin32Thread(Thread);
47+
Win32Process = PsGetProcessWin32Process(Process);
48+
DPRINT("Win32 thread %p, process %p\n", Win32Thread, Win32Process);
49+
50+
DPRINT("Creating W32 thread TID:%d PID:%d at IRQ level: %lu. Win32Process %p, desktop %x\n",
51+
Thread->Tcb.Teb->ClientId.UniqueThread, Thread->Tcb.Teb->ClientId.UniqueProcess, KeGetCurrentIrql(), Win32Process, Win32Process->desktop);
52+
53+
/* Allocate one if needed */
54+
if (!Win32Thread)
55+
{
56+
/* FIXME - lock the process */
57+
Win32Thread = ExAllocatePoolWithTag(NonPagedPool,
58+
sizeof(THREADINFO),
59+
't23W');
60+
61+
if (!Win32Thread)
62+
return STATUS_NO_MEMORY;
63+
64+
RtlZeroMemory(Win32Thread, sizeof(THREADINFO));
65+
66+
PsSetThreadWin32Thread(Thread, Win32Thread, NULL);
67+
/* FIXME - unlock the process */
68+
}
69+
70+
Win32Thread->process = Win32Process;
71+
Win32Thread->peThread = Thread;
72+
Win32Thread->desktop = Win32Process->desktop;
73+
Win32Thread->KeyboardLayout = UserGetDefaultKeyBoardLayout();
74+
75+
return STATUS_SUCCESS;
76+
}
77+
78+
NTSTATUS
79+
APIENTRY
80+
UserDestroyThreadInfo(PETHREAD Thread)
81+
{
82+
struct _EPROCESS *Process;
83+
PTHREADINFO Win32Thread;
84+
PPROCESSINFO Win32Process;
85+
86+
Process = Thread->ThreadsProcess;
87+
88+
/* Get the Win32 Thread and Process */
89+
Win32Thread = PsGetThreadWin32Thread(Thread);
90+
Win32Process = PsGetProcessWin32Process(Process);
91+
DPRINT("Win32 thread %p, process %p\n", Win32Thread, Win32Process);
92+
93+
DPRINT("Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread->Tcb.Teb->ClientId.UniqueThread, KeGetCurrentIrql());
94+
95+
/* USER thread-level cleanup */
96+
UserEnterExclusive();
97+
cleanup_clipboard_thread(Win32Thread);
98+
destroy_thread_windows(Win32Thread);
99+
free_msg_queue(Win32Thread);
100+
close_thread_desktop(Win32Thread);
101+
UserLeave();
102+
103+
PsSetThreadWin32Thread(Thread, NULL, NULL);
104+
105+
return STATUS_SUCCESS;
106+
}
107+
34108
NTSTATUS
35109
APIENTRY
36110
Win32kProcessCallout(PEPROCESS Process,
@@ -119,62 +193,24 @@ APIENTRY
119193
Win32kThreadCallout(PETHREAD Thread,
120194
PSW32THREADCALLOUTTYPE Type)
121195
{
122-
struct _EPROCESS *Process;
123-
PTHREADINFO Win32Thread;
124-
PPROCESSINFO Win32Process;
196+
NTSTATUS Status;
125197

126198
DPRINT("Enter Win32kThreadCallback, current thread id %d, process id %d\n", PsGetCurrentThread()->Tcb.Teb->ClientId.UniqueThread, PsGetCurrentThread()->Tcb.Teb->ClientId.UniqueProcess);
127199

128-
Process = Thread->ThreadsProcess;
129-
130-
/* Get the Win32 Thread and Process */
131-
Win32Thread = PsGetThreadWin32Thread(Thread);
132-
Win32Process = PsGetProcessWin32Process(Process);
133-
DPRINT("Win32 thread %p, process %p\n", Win32Thread, Win32Process);
134-
/* Allocate one if needed */
135-
if (!Win32Thread)
136-
{
137-
/* FIXME - lock the process */
138-
Win32Thread = ExAllocatePoolWithTag(NonPagedPool,
139-
sizeof(THREADINFO),
140-
't23W');
141-
142-
if (!Win32Thread)
143-
return STATUS_NO_MEMORY;
144-
145-
RtlZeroMemory(Win32Thread, sizeof(THREADINFO));
200+
ASSERT(NtCurrentTeb());
146201

147-
PsSetThreadWin32Thread(Thread, Win32Thread, NULL);
148-
/* FIXME - unlock the process */
149-
}
150202
if (Type == PsW32ThreadCalloutInitialize)
151203
{
152-
DPRINT("Creating W32 thread TID:%d PID:%d at IRQ level: %lu. Win32Process %p, desktop %x\n",
153-
Thread->Tcb.Teb->ClientId.UniqueThread, Thread->Tcb.Teb->ClientId.UniqueProcess, KeGetCurrentIrql(), Win32Process, Win32Process->desktop);
154-
155-
Win32Thread->process = Win32Process;
156-
Win32Thread->peThread = Thread;
157-
Win32Thread->desktop = Win32Process->desktop;
158-
Win32Thread->KeyboardLayout = UserGetDefaultKeyBoardLayout();
204+
Status = UserCreateThreadInfo(Thread);
159205
}
160206
else
161207
{
162-
DPRINT("Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread->Tcb.Teb->ClientId.UniqueThread, KeGetCurrentIrql());
163-
164-
/* USER thread-level cleanup */
165-
UserEnterExclusive();
166-
cleanup_clipboard_thread(Win32Thread);
167-
destroy_thread_windows(Win32Thread);
168-
free_msg_queue(Win32Thread);
169-
close_thread_desktop(Win32Thread);
170-
UserLeave();
171-
172-
PsSetThreadWin32Thread(Thread, NULL, NULL);
208+
Status = UserDestroyThreadInfo(Thread);
173209
}
174210

175211
DPRINT("Leave Win32kThreadCallback\n");
176212

177-
return STATUS_SUCCESS;
213+
return Status;
178214
}
179215

180216
NTSTATUS
@@ -304,9 +340,35 @@ NtUserInitialize(
304340
HANDLE hPowerRequestEvent,
305341
HANDLE hMediaRequestEvent)
306342
{
307-
/* Connect CSR subsystem */
343+
/* Check the Windows version */
344+
if (dwWinVersion != 0)
345+
{
346+
return STATUS_UNSUCCESSFUL;
347+
}
348+
349+
/* Grab the lock exclusively */
350+
UserEnterExclusive();
351+
352+
/* Check if already initialized */
353+
if (gbInitialized)
354+
{
355+
/* Release the lock and exit */
356+
UserLeave();
357+
return STATUS_UNSUCCESSFUL;
358+
}
359+
360+
/* Save CSR process */
308361
CsrInit();
309362

363+
/* Create win32 info for the current thread */
364+
UserCreateThreadInfo(PsGetCurrentThread());
365+
366+
/* User server is initialized now */
367+
gbInitialized = TRUE;
368+
369+
/* Release the lock */
370+
UserLeave();
371+
310372
return STATUS_SUCCESS;
311373
}
312374

0 commit comments

Comments
 (0)