Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Which types of exceptions cannot be handled?

0xrepnz0xrepnz Member Posts: 41

Hey:)
I know some exceptions like PAGE_FAULT_IN_NONPAGED_AREA cannot be caught using __try and __except. Is there any resource detailing which types of exceptions cannot be caught? How can I know which exceptions cannot be caught?

I don't need it for a specific reason, just because I'm curious (And don't want to cause bugchecks)

- Ori Damari

Comments

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,627

    There's probably a really raucous religious discussion waiting to be had here. ;)

    I almost never use __try/__except in a kernel driver, unless I'm handling user-mode addresses in a METHOD_NEITHER ioctl. I tend to think it's a crutch to spackle over lazy programming. If I have processing that might throw an exception, I'd rather get the BSOD so I can diagnose it and add protection. An ounce of prevention is better than a pound of cure.

    That does mean my testing had better be pretty thorough.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • 0xrepnz0xrepnz Member Posts: 41
    I'm asking because one of the third party software drivers installed on my PC (again, I did not develop the driver) caused a blue screen today. Analyzing the blue screen I saw it happened because the driver accessed a pointer from user mode with __try (the developer of the driver passed the address of a kernel object he obtained from user mode using SystemHandleInformation.. Heh) this object was already removed and that caused the fault in a nonpaged area,
    I removed this aweful driver.

    I don't intend to do shady stuff in a kernel driver, I'm just curious.
    - Ori Damari
  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,351

    You can only catch invalid user pointer accesses. If you touch an invalid kernel address it will crash the machine.

    Analyzing the blue screen I saw it happened because the driver accessed a pointer from user mode with __try

    Before you touch a pointer from user mode you need to call either ProbeForRead or ProbeForWrite on it. These will raise an exception if the address supplied by user mode is a kernel address.

    -scott
    OSR

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE