|
From: David W. <we...@cw...> - 2002-05-22 22:39:39
|
On Tue, May 21, 2002 at 09:58:22PM +0200, Hartmut Birr wrote: > This means, at each position where KeAttacheProcess is called, there must > be disable all thread switching. > I don't think that is possible since a KeAttachProcess'ed thread can access user space, in fact this is its main use. > The patch solves my problem. But there exist two other problems. The patch > does not check if the stack is in kernel or in user space and there exist a > problem if the stack is located over a 4MB boundary. I think the real > problem is, that the mapping for the stack is created within the wrong > proccess context. My second patch solve this problem, but it must disable a > warning for bad mappings. > I don't think there are any circumstances where a thread's kernel stack could be in user-space however the 4MB boundary problem needs solving. I've attached a new more complete patch: Index: ntoskrnl/include/internal/ps.h =================================================================== RCS file: /CVS/ReactOS/reactos/ntoskrnl/include/internal/ps.h,v retrieving revision 1.33 diff -u -r1.33 ps.h --- ntoskrnl/include/internal/ps.h 14 May 2002 21:19:17 -0000 1.33 +++ ntoskrnl/include/internal/ps.h 22 May 2002 22:35:22 -0000 @@ -32,6 +32,7 @@ * Defines for accessing KPCR and KTHREAD structure members */ #define KTHREAD_INITIAL_STACK 0x18 +#define KTHREAD_STACK_LIMIT 0x1C #define KTHREAD_TEB 0x20 #define KTHREAD_KERNEL_STACK 0x28 #define KTHREAD_PREVIOUS_MODE 0x137 Index: ntoskrnl/ke/i386/tskswitch.S =================================================================== RCS file: /CVS/ReactOS/reactos/ntoskrnl/ke/i386/tskswitch.S,v retrieving revision 1.9 diff -u -r1.9 tskswitch.S --- ntoskrnl/ke/i386/tskswitch.S 15 Jan 2002 02:51:32 -0000 1.9 +++ ntoskrnl/ke/i386/tskswitch.S 22 May 2002 22:35:25 -0000 @@ -29,9 +29,10 @@ #include <internal/i386/segment.h> #include <internal/ps.h> #include <ddk/i386/tss.h> - +#include <internal/ntoskrnl.h> + /* FUNCTIONS ****************************************************************/ - + .globl _Ki386ContextSwitch _Ki386ContextSwitch: /* @@ -97,6 +98,7 @@ movl %esp, KTHREAD_KERNEL_STACK(%ebx) movl 8(%ebp), %ebx movl KTHREAD_KERNEL_STACK(%ebx), %esp + movl KTHREAD_STACK_LIMIT(%ebx), %edi /* * Set the stack pointer in this processors TSS @@ -110,8 +112,25 @@ */ movl ETHREAD_THREADS_PROCESS(%ebx), %ebx movl KPROCESS_DIRECTORY_TABLE_BASE(%ebx), %eax - movl %eax, %cr3 + movl %eax, %cr3 + /* + * Set up the PDE for the top of the new stack. + */ + movl $0, %ebx +.L2: movl %edi, %esi + shr $22, %esi + movl 0xF03C0000(,%esi, 4), %eax + cmpl $0, %eax + jne .L1 + movl _MmGlobalKernelPageDirectory(,%esi, 4), %eax + movl %eax, 0xF03C0000(,%esi, 4) +.L1: + addl $4096, %edi + incl %ebx + cmp $(MM_STACK_SIZE / 4096), %ebx + jl .L2 + /* * FIXME: Restore floating point state */ |