<html>
<head>
<style>
<!--
body { background-color:#ffffff }
.file { border:1px solid #eeeeee; margin-top:1em; margin-bottom:1em }
.pathname { font-family:monospace; float:right }
.fileheader { margin-bottom:.5em }
.diff { margin:0 }
.tasklist { padding:4px; border:1px dashed #000000; margin-top:1em }
.tasklist ul { margin-top:0; margin-bottom:0 }
tr.alt { background-color:#eeeeee }
#added { background-color:#ddffdd }
#addedchars { background-color:#99ff99; font-weight:bolder }
tr.alt #added { background-color:#ccf7cc }
#removed { background-color:#ffdddd }
#removedchars { background-color:#ff9999; font-weight:bolder }
tr.alt #removed { background-color:#f7cccc }
#info { color:#888888 }
#context { background-color:#eeeeee }
td {padding-left:.3em; padding-right:.3em }
tr.head { border-bottom-width:1px; border-bottom-style:solid }
tr.head td { padding:0; padding-top:.2em }
.task { background-color:#ffff00 }
.comment { padding:4px; border:1px dashed #000000; background-color:#ffffdd }
.error { color:red }
hr { border-width:0px; height:2px; background:black }
-->
</style>
</head>
<body>
<pre class="comment">- Remove KiServiceCheck and implement PsConvertToGuiThread in its place. Has support for detecting and returning errors in case of invalid cases, currently disabled code for doing the required 4kb-&gt;12kb stack conversion, and handling certain failures.</pre><pre class="diff" id="context">Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S
Modified: trunk/reactos/ntoskrnl/ke/kthread.c
Modified: trunk/reactos/ntoskrnl/ps/win32.c
</pre><hr /><div class="file">
<div class="fileheader"><big><b>Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S</b></big></div>
<pre class="diff"><small id="info">--- trunk/reactos/ntoskrnl/ke/i386/syscall.S        2006-01-11 05:24:40 UTC (rev 20778)
+++ trunk/reactos/ntoskrnl/ke/i386/syscall.S        2006-01-11 05:42:32 UTC (rev 20779)
@@ -614,7 +614,7 @@
</small></pre><pre class="diff" id="context"> &nbsp; &nbsp; /* Set up Win32K Table */
 &nbsp; &nbsp; push edx
 &nbsp; &nbsp; push ebx
</pre><pre class="diff" id="removed">- &nbsp; &nbsp;call _<span id="removedchars">KiServiceCheck</span>@0
</pre><pre class="diff" id="added">+ &nbsp; &nbsp;call _<span id="addedchars">PsConvertToGuiThread</span>@0
</pre><pre class="diff" id="context"> 
 &nbsp; &nbsp; /* FIXME: Handle failure */
 &nbsp; &nbsp; pop eax
</pre></div>
<hr /><div class="file">
<div class="fileheader"><big><b>Modified: trunk/reactos/ntoskrnl/ke/kthread.c</b></big></div>
<pre class="diff"><small id="info">--- trunk/reactos/ntoskrnl/ke/kthread.c        2006-01-11 05:24:40 UTC (rev 20778)
+++ trunk/reactos/ntoskrnl/ke/kthread.c        2006-01-11 05:42:32 UTC (rev 20779)
@@ -1466,21 +1466,6 @@
</small></pre><pre class="diff" id="context"> &nbsp; &nbsp; return OldState;
 }
 
</pre><pre class="diff" id="removed">-VOID
-NTAPI
-KiServiceCheck(VOID)
-{
- &nbsp; &nbsp;PKTHREAD Thread = KeGetCurrentThread();
-
- &nbsp; &nbsp;/* Check if we need to inialize Win32 for this Thread */
- &nbsp; &nbsp;if (Thread-&gt;ServiceTable != KeServiceDescriptorTableShadow) {
-
- &nbsp; &nbsp; &nbsp; &nbsp;/* We do. Initialize it and save the new table */
- &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;ServiceTable = KeServiceDescriptorTableShadow;
- &nbsp; &nbsp; &nbsp; &nbsp;PsInitWin32Thread((PETHREAD)Thread);
- &nbsp; &nbsp;}
-}
-
</pre><pre class="diff" id="context"> /*
 &nbsp;*
 &nbsp;* NOT EXPORTED
</pre></div>
<hr /><div class="file">
<div class="fileheader"><big><b>Modified: trunk/reactos/ntoskrnl/ps/win32.c</b></big></div>
<pre class="diff"><small id="info">--- trunk/reactos/ntoskrnl/ps/win32.c        2006-01-11 05:24:40 UTC (rev 20778)
+++ trunk/reactos/ntoskrnl/ps/win32.c        2006-01-11 05:42:32 UTC (rev 20779)
@@ -41,6 +41,13 @@
</small></pre><pre class="diff" id="context"> } NTW32CALL_SAVED_STATE, *PNTW32CALL_SAVED_STATE;
 #endif
 
</pre><pre class="diff" id="added">+PVOID
+STDCALL
+KeSwitchKernelStack(
+ &nbsp; &nbsp;IN PVOID StackBase,
+ &nbsp; &nbsp;IN PVOID StackLimit
+);
+
</pre><pre class="diff" id="context"> /* FUNCTIONS ***************************************************************/
 
 /*
@@ -62,33 +69,105 @@
</pre><pre class="diff" id="context"> 
 NTSTATUS
 NTAPI
</pre><pre class="diff" id="removed">-Ps<span id="removedchars">InitWin32Thread (PETHREAD Thread</span>)
</pre><pre class="diff" id="added">+Ps<span id="addedchars">ConvertToGuiThread(VOID</span>)
</pre><pre class="diff" id="context"> {
</pre><pre class="diff" id="removed">- &nbsp; &nbsp;PEPROCESS Process;
- &nbsp; &nbsp;<span id="removedchars">NTSTATUS Status = STATUS_SUCCESS</span>;
</pre><pre class="diff" id="added">+ &nbsp; &nbsp;<span id="addedchars">//PVOID NewStack, OldStack</span>;
+ &nbsp; &nbsp;PETHREAD Thread = PsGetCurrentThread();
+ &nbsp; &nbsp;PEPROCESS Process = PsGetCurrentProcess();
+ &nbsp; &nbsp;NTSTATUS Status;
+ &nbsp; &nbsp;PAGED_CODE();
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="removed">- &nbsp; &nbsp;<span id="removedchars">Process = Thread-&gt;ThreadsProcess;</span>
</pre><pre class="diff" id="added">+ &nbsp; &nbsp;<span id="addedchars">/* Validate the previous mode */</span>
+ &nbsp; &nbsp;if (KeGetPreviousMode() == KernelMode)
+ &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp;DPRINT1(&quot;Danger: win32k call being made in kernel-mode?!\n&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;return STATUS_INVALID_PARAMETER;
+ &nbsp; &nbsp;}
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="removed">- &nbsp; &nbsp;<span id="removedchars">if (Process-&gt;Win32Process == NULL)</span>
</pre><pre class="diff" id="added">+ &nbsp; &nbsp;<span id="addedchars">/* Make sure win32k is here */</span>
+ &nbsp; &nbsp;if (!PspWin32ProcessCallback)
</pre><pre class="diff" id="context"> &nbsp; &nbsp; {
</pre><pre class="diff" id="removed">- &nbsp; &nbsp; &nbsp; &nbsp;<span id="removedchars">if (PspWin32ProcessCallback != NULL)</span>
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp; &nbsp;<span id="addedchars">DPRINT1(&quot;Danger: Win32K call attempted but Win32k not ready!\n&quot;);</span>
+ &nbsp; &nbsp; &nbsp; &nbsp;return STATUS_ACCESS_DENIED;
+ &nbsp; &nbsp;}
+
+ &nbsp; &nbsp;/* Make sure it's not already win32 */
+ &nbsp; &nbsp;if (Thread-&gt;Tcb.ServiceTable != KeServiceDescriptorTable)
+ &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp;DPRINT1(&quot;Danger: Thread is already a win32 thread. Limit bypassed?\n&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;return STATUS_ALREADY_WIN32;
+ &nbsp; &nbsp;}
+
+ &nbsp; &nbsp;/* Check if we don't already have a kernel-mode stack */
+#if 0
+ &nbsp; &nbsp;if (!Thread-&gt;Tcb.LargeStack)
+ &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp;/* We don't create one */
+ &nbsp; &nbsp; &nbsp; &nbsp;DPRINT1(&quot;Creating large stack\n&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;NewStack = MmCreateKernelStack(TRUE);
+ &nbsp; &nbsp; &nbsp; &nbsp;if (!NewStack)
</pre><pre class="diff" id="context"> &nbsp; &nbsp; &nbsp; &nbsp; {
</pre><pre class="diff" id="removed">- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span id="removedchars">Status = PspWin32ProcessCallback(Process, TRUE);</span>
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span id="addedchars">/* Panic in user-mode */</span>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NtCurrentTeb()-&gt;LastErrorValue = ERROR_NOT_ENOUGH_MEMORY;
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return STATUS_NO_MEMORY;
</pre><pre class="diff" id="context"> &nbsp; &nbsp; &nbsp; &nbsp; }
</pre><pre class="diff" id="added">+
+ &nbsp; &nbsp; &nbsp; &nbsp;/* We're about to switch stacks. Enter a critical region */
+ &nbsp; &nbsp; &nbsp; &nbsp;KeEnterCriticalRegion();
+
+ &nbsp; &nbsp; &nbsp; &nbsp;/* Switch stacks */
+ &nbsp; &nbsp; &nbsp; &nbsp;DPRINT1(&quot;Switching stacks. NS IT, SL, SB, KS %p %p %p %p %p\n&quot;,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NewStack,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;Tcb.InitialStack,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;Tcb.StackLimit,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;Tcb.StackBase,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;Tcb.KernelStack);
+ &nbsp; &nbsp; &nbsp; &nbsp;OldStack = KeSwitchKernelStack((PVOID)((ULONG_PTR)NewStack + 0x3000),
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NewStack);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;/* Leave the critical region */
+ &nbsp; &nbsp; &nbsp; &nbsp;KeLeaveCriticalRegion();
+ &nbsp; &nbsp; &nbsp; &nbsp;DPRINT1(&quot;We made it!\n&quot;);
+
+ &nbsp; &nbsp; &nbsp; &nbsp;/* Delete the old stack */
+ &nbsp; &nbsp; &nbsp; &nbsp;//MmDeleteKernelStack(OldStack, FALSE);
+ &nbsp; &nbsp; &nbsp; &nbsp;DPRINT1(&quot;Old stack deleted. IT, SL, SB, KS %p %p %p %p\n&quot;,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;Tcb.InitialStack,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;Tcb.StackLimit,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;Tcb.StackBase,
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;Tcb.KernelStack);
</pre><pre class="diff" id="context"> &nbsp; &nbsp; }
</pre><pre class="diff" id="added">+#endif
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="removed">- &nbsp; &nbsp;<span id="removedchars">if (Thread-&gt;Tcb.Win32Thread == NULL)</span>
</pre><pre class="diff" id="added">+ &nbsp; &nbsp;<span id="addedchars">/* This check is bizare. Check out win32k later */</span>
+ &nbsp; &nbsp;if (!Process-&gt;Win32Process)
</pre><pre class="diff" id="context"> &nbsp; &nbsp; {
</pre><pre class="diff" id="removed">- &nbsp; &nbsp; &nbsp; &nbsp;<span id="removedchars">if (PspWin32ThreadCallback != NULL)</span>
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp; &nbsp;<span id="addedchars">/* Now tell win32k about us */</span>
+ &nbsp; &nbsp; &nbsp; &nbsp;Status = PspWin32ProcessCallback(Process, TRUE);
+ &nbsp; &nbsp; &nbsp; &nbsp;if (!NT_SUCCESS(Status))
</pre><pre class="diff" id="context"> &nbsp; &nbsp; &nbsp; &nbsp; {
</pre><pre class="diff" id="removed">- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span id="removedchars">Status = PspWin32ThreadCallback(Thread, TRUE</span>);
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span id="addedchars">DPRINT1(&quot;Danger: Win32k wasn't happy about us!\n&quot;</span>);
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return Status;
</pre><pre class="diff" id="context"> &nbsp; &nbsp; &nbsp; &nbsp; }
 &nbsp; &nbsp; }
 
</pre><pre class="diff" id="added">+ &nbsp; &nbsp;/* Set the new service table */
+ &nbsp; &nbsp;Thread-&gt;Tcb.ServiceTable = KeServiceDescriptorTableShadow;
+ &nbsp; &nbsp;ASSERT(Thread-&gt;Tcb.Win32Thread == 0);
+
+ &nbsp; &nbsp;/* Tell Win32k about our thread */
+ &nbsp; &nbsp;Status = PspWin32ThreadCallback(Thread, TRUE);
+ &nbsp; &nbsp;if (!NT_SUCCESS(Status))
+ &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp;/* Revert our table */
+ &nbsp; &nbsp; &nbsp; &nbsp;DPRINT1(&quot;Danger: Win32k wasn't happy about us!\n&quot;);
+ &nbsp; &nbsp; &nbsp; &nbsp;Thread-&gt;Tcb.ServiceTable = KeServiceDescriptorTable;
+ &nbsp; &nbsp;}
+
+ &nbsp; &nbsp;/* Return status */
</pre><pre class="diff" id="context"> &nbsp; &nbsp; return Status;
 }
 
</pre><pre class="diff" id="removed">-
</pre><pre class="diff" id="context"> VOID
 NTAPI
 PsTerminateWin32Process (PEPROCESS Process)
@@ -122,72 +201,6 @@
</pre><pre class="diff" id="context"> &nbsp; }
 }
 
</pre><pre class="diff" id="removed">-VOID
-STDCALL
-DumpEspData(ULONG Esp, ULONG ThLimit, ULONG ThStack, ULONG PcrLimit, ULONG PcrStack, ULONG Esp0)
-{
- &nbsp; &nbsp;DPRINT1(&quot;Current Esp: %p\n Thread Stack Limit: %p\n Thread Stack: %p\n Pcr Limit: %p, Pcr Stack: %p\n Esp0 :%p\n&quot;,Esp, ThLimit, ThStack, PcrLimit, PcrStack, Esp0) &nbsp; ;
-}
-
- PVOID
-STDCALL
- PsAllocateCallbackStack(ULONG StackSize)
- {
- &nbsp; PVOID KernelStack = NULL;
- &nbsp; NTSTATUS Status;
- &nbsp; PMEMORY_AREA StackArea;
- &nbsp; ULONG i, j;
- &nbsp; PHYSICAL_ADDRESS BoundaryAddressMultiple;
- &nbsp; PPFN_TYPE Pages = alloca(sizeof(PFN_TYPE) * (StackSize /PAGE_SIZE));
-
- &nbsp; &nbsp;DPRINT1(&quot;PsAllocateCallbackStack\n&quot;);
- &nbsp; BoundaryAddressMultiple.QuadPart = 0;
- &nbsp; StackSize = PAGE_ROUND_UP(StackSize);
- &nbsp; MmLockAddressSpace(MmGetKernelAddressSpace());
- &nbsp; Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MEMORY_AREA_KERNEL_STACK,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;KernelStack,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StackSize,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PAGE_READWRITE,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;StackArea,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FALSE,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BoundaryAddressMultiple);
- &nbsp; MmUnlockAddressSpace(MmGetKernelAddressSpace());
- &nbsp; if (!NT_SUCCESS(Status))
- &nbsp; &nbsp; {
- &nbsp; &nbsp; &nbsp; DPRINT1(&quot;Failed to create thread stack\n&quot;);
- &nbsp; &nbsp; &nbsp; return(NULL);
- &nbsp; &nbsp; }
- &nbsp; for (i = 0; i &lt; (StackSize / PAGE_SIZE); i++)
- &nbsp; &nbsp; {
- &nbsp; &nbsp; &nbsp; Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &amp;Pages[i]);
- &nbsp; &nbsp; &nbsp; if (!NT_SUCCESS(Status))
- &nbsp; &nbsp; &nbsp; &nbsp; {
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (j = 0; j &lt; i; j++)
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MmReleasePageMemoryConsumer(MC_NPPOOL, Pages[j]);
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return(NULL);
- &nbsp; &nbsp; &nbsp; &nbsp; }
- &nbsp; &nbsp; }
- &nbsp; Status = MmCreateVirtualMapping(NULL,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KernelStack,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PAGE_READWRITE,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pages,
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StackSize / PAGE_SIZE);
- &nbsp; if (!NT_SUCCESS(Status))
- &nbsp; &nbsp; {
- &nbsp; &nbsp; &nbsp;for (i = 0; i &lt; (StackSize / PAGE_SIZE); i++)
- &nbsp; &nbsp; &nbsp; &nbsp; {
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MmReleasePageMemoryConsumer(MC_NPPOOL, Pages[i]);
- &nbsp; &nbsp; &nbsp; &nbsp; }
- &nbsp; &nbsp; &nbsp; return(NULL);
- &nbsp; &nbsp; }
- &nbsp; &nbsp; DPRINT1(&quot;PsAllocateCallbackStack %x\n&quot;, KernelStack);
- &nbsp; return(KernelStack);
-}
-
</pre><pre class="diff" id="context"> NTSTATUS
 STDCALL
 NtW32Call(IN ULONG RoutineIndex,
</pre>
</div>

</body>
</html>