ExceptionPort的作用,是在用戶態異常的第2輪分發過程中,如果第二輪還無人處理,那麼就會發到ExceptionPort 。關於異常的分發,部分可以參考 理解UnhandledExceptionFilter
對於ExceptionPort,每個普通進程都會設置,CSRSS進程負責監聽。CSRSS收到異常消息後一般是立刻終止進程,Win7開始,略有變化。
可以使用windbg做個實驗,加深對上述概念的理解。來段簡單的代碼,
int main(int argc, char* argv[])
{
*(int*)0=1;
return 0;
}
進入windbg
0:000> g
Thu Feb 24 09:53:34.370 2011 (UTC + 8:00): (c7c.12c0): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000027 ebx=7ffda000 ecx=00424a60 edx=00424a60 esi=00000000 edi=0012ff48
eip=00401035 esp=0012fefc ebp=0012ff48 iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010206
*** WARNING: Unable to verify checksum for UEF.exe
UEF!main+0x25:
00401035 c7050000000001000000 mov dword ptr ds:[0],1 ds:0023:00000000=????????