开发者

Is it safe to catch EXCEPTION_GUARD_PAGE

Environment is VC++ 9 on various Win platforms (XP and later)

I'm writing an unhandled exception handler. I have a vague recollection from my kernel days that it was bad to catch an EXCEPTION_GUARD_PAGE, as this was generated to tell the OS to enlarge the stack.

My question is twofold:

  1. Can such an exception occur in user space?

  2. If so, is it safe to catch it?

I'm not especially interested in doing anything with it. I just want to know if I need to put special code in to not catch it (as I'm catching everything at the moment).

Update:

I've recalled my source, it is Raymond Chen's blog (http://blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx)

My initial concern is that when catching all exceptions, if I catch a EXCEPTION_GUARD_PAGE, I might prevent the OS from seeing the exception and enlarging the stack.

On further thought, I suspect that the EXCEPTION_GUARD_PAGE might be handled in the Kernel during the read/write operation that generated it and thus will never reach my user-space code.

I guess I am looking for someone to confirm (or contradict) that.

Second Update:

I haven't selected an answer yet as nobody has really answered the question. I'll leave it o开发者_如何学Gopen in the hope that somebody may yet offer the information that I seek.

Third Update

Still living in (faint) hope.

Fourth Update

Well, I never did get a usable answer. I've long finished the module I was writing when I asked the question. I think the question is, for practical purposes, dead. I probably won't update again.


Setting up a page to generate a STATUS_GUARD_PAGE_VIOLATION with VirtualProtectEx() and the PAGE_GUARD flag is a documented procedure. The exception can be generated only once for a page so there's no danger you'll die while processing the exception.

I don't do anything special for the exception but that doesn't proof too much, getting this exception would be extraordinarily rare. Never seen it once in any of our crash reports.

The feature is really meant for generating stack overflow exceptions. Which you really do need to handle specially since you have so little stack left. I assume that's where the warning came from that you mention in your question. It will however never generate a page guard exception, that's handled at kernel level before getting translated to a stack overflow.


According to MSDN:

The thread accessed memory allocated with the PAGE_GUARD modifier.

Which sounds like something that should never happen unless you've got a bug; so I'd handle it accordingly.

Edit

The OS exception handlers are registered before yours, so handling it yourself doesn't mean the OS didn't get to see it first.


According to my observation with virtualquery, it is similar to the kernel mode case. The exception can be caught by debugger if the accessed guard page stack does not belong to the accessing thread. You should have the answer already, anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜