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/


Does ObOpenObjectByPointer() in the case Wow64 returns HANDLE 32-bit?

I asked to move compilation of one old written driver from VS2012 to the VS2017 and run into the problem which VS2010 "eat", but VS2017 generates
warning C4311: 'type cast': pointer truncation from 'HANDLE' to 'ULONG'

I analyzed the code and found that
API ObOpenObjectByPointer() returns last parameter as HANDLE, which driver for case Wow64 (IoIs32bitProcess(Irp) returns TRUE) tries to save as ULONG (32 bit) which generates warning above.

MSDN [https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-obopenobjectbypointer] keeps silence about the case Wow64.
Does HANDLE for case Wow64 has real size 32-bit or this is bug?

Regards,
Michael Grabelkovsky.

Comments

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,631

    Everything compiled in kernel mode is going to have HANDLE defined as a 64-bit type. So, the warning is correct and you need to pass a PHANDLE as the argument.

    However, when you’re creating a HANDLE for a Wow64 process you’re guaranteed that the resulting HANDLE will only have the low 32-bits valid. So, after the call is successful you can cast the result to an ULONG to return it to a 32-bit process.

    -scott
    OSR

  • Scott,
    Thanks a lot, detail answer!
    I supposed something same.

    As I understand you described common principle of mapping handles for 32 bit Appl inside 64-bit environment.
    And it may be used for other same cases too, even if Documentation keeps silent...

    Regards,
    MG.

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,631

    For completeness it also applies to user mode virtual address mappings. For example, calling MmMapLockedPagesSpecifyCache with an AccessMode of UserMode will return a 64-bit virtual address with only the low 32-bits valid.

    -scott
    OSR

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

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!
Kernel Debugging 16-20 October 2023 Live, Online
Developing Minifilters 13-17 November 2023 Live, Online
Internals & Software Drivers 4-8 Dec 2023 Live, Online
Writing WDF Drivers 10-14 July 2023 Live, Online