Skip to content

Commit 0fbc1e1

Browse files
committed
[ARWINSS]
- Properly set and reset Win32 process/thread info. Fixes a crash when first thread in the system terminates (and that's CSRSS thread by design). svn path=/branches/arwinss/; revision=62865
1 parent ad26cd5 commit 0fbc1e1

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

arwinss/server/include/tags.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#ifndef _WIN32K_TAGS_H
2-
#define _WIN32K_TAGS_H
1+
#pragma once
32

3+
/* GDI objects from the handle table */
44
#define TAG_BRUSHOBJ 'OHRB' /* brush object */
55
#define TAG_CLIP 'PILC' /* clipping */
66
#define TAG_CLIPOBJ 'OPLC' /* clip object */
@@ -19,6 +19,8 @@
1919
#define TAG_PENSTYLES 'ytsG' /* pen styles */
2020
#define TAG_BRUSH '@alG'
2121
#define TAG_BITMAP 'PMTB' /* bitmap */
22-
#define GDITAG_RBRUSH 'rbdG'
2322

24-
#endif /* _WIN32K_TAGS_H */
23+
/* Official tags */
24+
#define GDITAG_RBRUSH 'rbdG'
25+
#define USERTAG_PROCESSINFO 'ipsU'
26+
#define USERTAG_THREADINFO 'itsU'

arwinss/server/main/init.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <handle.h>
1818
#include <user.h>
1919

20-
#define NDEBUG
20+
//#define NDEBUG
2121
#include <debug.h>
2222

2323
void init_directories(void);
@@ -56,7 +56,7 @@ UserCreateThreadInfo(PETHREAD Thread)
5656
/* FIXME - lock the process */
5757
Win32Thread = ExAllocatePoolWithTag(NonPagedPool,
5858
sizeof(THREADINFO),
59-
't23W');
59+
USERTAG_THREADINFO);
6060

6161
if (!Win32Thread)
6262
return STATUS_NO_MEMORY;
@@ -93,14 +93,14 @@ UserDestroyThreadInfo(PETHREAD Thread)
9393
DPRINT("Destroying W32 thread TID:%d at IRQ level: %lu\n", Thread->Tcb.Teb->ClientId.UniqueThread, KeGetCurrentIrql());
9494

9595
/* USER thread-level cleanup */
96-
UserEnterExclusive();
9796
cleanup_clipboard_thread(Win32Thread);
9897
destroy_thread_windows(Win32Thread);
9998
free_msg_queue(Win32Thread);
10099
close_thread_desktop(Win32Thread);
101-
UserLeave();
102100

103-
PsSetThreadWin32Thread(Thread, NULL, NULL);
101+
/* Free THREADINFO */
102+
PsSetThreadWin32Thread(Thread, NULL, Win32Thread);
103+
ExFreePoolWithTag(Win32Thread, USERTAG_THREADINFO);
104104

105105
return STATUS_SUCCESS;
106106
}
@@ -125,7 +125,8 @@ Win32kProcessCallout(PEPROCESS Process,
125125
/* Allocate one if needed */
126126
/* FIXME - lock the process */
127127
Win32Process = ExAllocatePoolWithTag(NonPagedPool,
128-
sizeof(PROCESSINFO), 'p23W');
128+
sizeof(PROCESSINFO),
129+
USERTAG_PROCESSINFO);
129130

130131
if (!Win32Process) return STATUS_NO_MEMORY;
131132

@@ -181,6 +182,10 @@ Win32kProcessCallout(PEPROCESS Process,
181182
ZwClose(Win32Process->idle_event_handle);
182183
}
183184

185+
/* Free the PROCESSINFO */
186+
PsSetProcessWin32Process(Process, NULL, Win32Process);
187+
ExFreePoolWithTag(Win32Process, USERTAG_PROCESSINFO);
188+
184189
UserLeave();
185190
}
186191

@@ -195,7 +200,11 @@ Win32kThreadCallout(PETHREAD Thread,
195200
{
196201
NTSTATUS Status;
197202

198-
DPRINT("Enter Win32kThreadCallback, current thread id %d, process id %d\n", PsGetCurrentThread()->Tcb.Teb->ClientId.UniqueThread, PsGetCurrentThread()->Tcb.Teb->ClientId.UniqueProcess);
203+
UserEnterExclusive();
204+
205+
DPRINT("Enter Win32kThreadCallback, current thread id %d, process id %d, type %d\n",
206+
PsGetCurrentThread()->Tcb.Teb->ClientId.UniqueThread,
207+
PsGetCurrentThread()->Tcb.Teb->ClientId.UniqueProcess, Type);
199208

200209
ASSERT(NtCurrentTeb());
201210

@@ -210,6 +219,8 @@ Win32kThreadCallout(PETHREAD Thread,
210219

211220
DPRINT("Leave Win32kThreadCallback\n");
212221

222+
UserLeave();
223+
213224
return Status;
214225
}
215226

0 commit comments

Comments
 (0)