You said:
“There is no context switch. CS, EIP, and ESP all change, but the page
tables (and hence CR3) remain the same”
Yes. Becaues of that i said it is all about cr3. Let me explain:
In Intel Doc.
For Task Switch:
“The TSS state is loaded into the processor. This includes the LDTR
register, the PDBR (control register CR3), the EFLAGS registers, the EIP
register, the general-purpose registers, and the segment selectors.”
For Interrupt Exception Handling:
“EFLAGS, CS, and EIP are saved”
So this is about what you said:“This is why articles about interrupt
handlers talk about them running in an “arbitrary context”. They run as
whatever process was running at the time of the interrupt. That process is
still alive and in memory, but it is frozen until the interrupt finishes its
job and returns.”
Right?
But there is nothing for thread switching. It is all about Windows. So i
looked SDK. This is CONTEXT structure:
typedef struct _CONTEXT {
DWORD ContextFlags;
//
// This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
// set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
// included in CONTEXT_FULL.
//
DWORD Dr0;
DWORD Dr1;
DWORD Dr2;
DWORD Dr3;
DWORD Dr6;
DWORD Dr7;
//
// This section is specified/returned if the
// ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
//
FLOATING_SAVE_AREA FloatSave;
//
// This section is specified/returned if the
// ContextFlags word contians the flag CONTEXT_SEGMENTS.
//
DWORD SegGs;
DWORD SegFs;
DWORD SegEs;
DWORD SegDs;
//
// This section is specified/returned if the
// ContextFlags word contians the flag CONTEXT_INTEGER.
//
DWORD Edi;
DWORD Esi;
DWORD Ebx;
DWORD Edx;
DWORD Ecx;
DWORD Eax;
//
// This section is specified/returned if the
// ContextFlags word contians the flag CONTEXT_CONTROL.
//
DWORD Ebp;
DWORD Eip;
DWORD SegCs; // MUST BE SANITIZED
DWORD EFlags; // MUST BE SANITIZED
DWORD Esp;
DWORD SegSs;
//
// This section is specified/returned if the ContextFlags word
// contains the flag CONTEXT_EXTENDED_REGISTERS.
// The format and contexts are processor specific
//
BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
} CONTEXT;
Here all registers is changed except Control registers(especially cr3).
Can we say the difference between process and thread switch is related cr3
register.
And in Driver Development world.
If i read something that says: “executing within the context of requester”
means context switching doesn’t effect CR3.
Am i right?
If changing CR3 means there is a task switch occurs, why do they underline
execute within this exception context?
Driver codes are not self executable, they must be called from running
application?
I confused because whatever i read say: “execute within same context” Is
this have special meaning in driver development world?
Or secret code that newbies like me, mustn’t understand but driver
developers communicate 
Thanks…
2008/4/17, Tim Roberts :
>
> serimc wrote:
>
> >
> > So can we say context switching is all about cr3 register?
> >
>
> No, I don’t think we can. As I said, the term “context switching” means
> different things in different circumstances. Changing CR3 is certainly part
> of a “process switch”, but CR3 is not changed when switching to a new
> thread, and yet some people would call that a “context switch”.
>
>
> In the same chapter it says:“When the hardware (or software) generates an
> > acknowledged interrupt, whatever code is executing within the system is
> > stopped dead in its tracks. The executing context is saved and control is
> > promptly handed over to a service routine appropriate for the kind of
> > interrupt that occurred.”
> >
> > Now context switching occurs because i assume that this paragraph tries
> > to tell “cr3 is changed”. If cr3 isn’t change and there is only a function
> > call(only changes in CS,EIP and ESP), this doesn’t mean context switching.
> > Is that right?
> >
>
> Not necessarily. In this particular case, the interrupt will “hijack” the
> thread that had been running. There is no context switch. CS, EIP, and ESP
> all change, but the page tables (and hence CR3) remain the same. This is
> why articles about interrupt handlers talk about them running in an
> “arbitrary context”. They run as whatever process was running at the time
> of the interrupt. That process is still alive and in memory, but it is
> frozen until the interrupt finishes its job and returns.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>