locked
Passing HANDLEs from WOW64 to x64 kernel RRS feed

  • Question

  • This is somewhat offtopic for this forum, so I apologize in advance for that, but it is tangentially related.

     

    I have a mechanism for passing data between kernel and user mode in my WFP application which involves an event that is opened by user mode, and is passed to kernel mode where the code does ObReferenceObjectByHandle, and later KeSetEvent to notify user mode when data is available.  This is probably a pretty common use-case, and works fine.  But my question is, what is the mechanism for passing a 32-bit HANDLE from WOW64 to a 64-bit kernel driver?  Is there some function in the kernel for mapping a 32-bit HANDLE to its 64-bit counterpart?  Do I just stuff it in a 64-bit HANDLE and leave the upper DWORD as zero?  I found this question in a few places online, but I never found an answer.  I know this is more generally Windows kernel related than WFP in particular, but this is the best place I knew to ask, and I figure it is something that WFP developers must run into from time to time.

     

    Thanks,

    Jeremy

    Monday, November 19, 2007 7:09 PM

Answers

  •  Jeremy Drake wrote:

    Do I just stuff it in a 64-bit HANDLE and leave the upper DWORD as zero? 

     

    Yes I am pretty sure that's all you need to do (or use the UlongToPtr macro). A user mode handle in NT is just an index into the handle/object table so it is just a number and should be perfectly safe to cast 32-bit UM handle to 64-bit and pass it down to 64-bit kernel. 

     

    Just curious, why not develop a 64-bit version of the UM component?

     

    Hope this helps,

    Biao.W. 

    Tuesday, November 27, 2007 8:21 AM

All replies

  •  Jeremy Drake wrote:

    Do I just stuff it in a 64-bit HANDLE and leave the upper DWORD as zero? 

     

    Yes I am pretty sure that's all you need to do (or use the UlongToPtr macro). A user mode handle in NT is just an index into the handle/object table so it is just a number and should be perfectly safe to cast 32-bit UM handle to 64-bit and pass it down to 64-bit kernel. 

     

    Just curious, why not develop a 64-bit version of the UM component?

     

    Hope this helps,

    Biao.W. 

    Tuesday, November 27, 2007 8:21 AM
  •  Biao Wang [MSFT] wrote:

    A user mode handle in NT is just an index into the handle/object table so it is just a number and should be perfectly safe to cast 32-bit UM handle to 64-bit and pass it down to 64-bit kernel.

     

    That's what I figured out by trial and error.  But it is good to have confirmation that what I am doing is correct.

     

     Biao Wang [MSFT] wrote:

    Just curious, why not develop a 64-bit version of the UM component?

     

    Because whoever originally wrote the UM component definately did not have portability in mind.  I just recently managed to seperate the UI from the service, since interactive services are deprecated on Vista, and this is how the previous developers decided to support NT platforms (fast user switching be damned).  After the horror of that project, I am loathe to attempt any wide, sweeping changes to the UM part like trying to port it to x64, unless absolutely necessary.

    Tuesday, November 27, 2007 9:35 PM