Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Windows handle inheritance cross the 32-bit/64-bit boundary?

Is it possible for a child process to inherit a handle from its parent process if one process is 32-bit and the other is 64-bit?

HANDLE is a 64 bit type on Win64 and a 32 bit type on Win32, which suggests that even it were supposed to be possible in all cases, there would be some cases where it would fail: a 64-bit parent process, a 32-bit child process, and a handle that can't be represented in 32 bits.

Or is naming the object the only way for a 32-bit process and a 64-bit process to get a handle for the same object?

like image 380
TheBeardyMan Avatar asked Apr 23 '10 15:04

TheBeardyMan


2 Answers

If it is a file handle or other kernel handle, then yes.

It just happens that although HANDLE is a 64 bit type, it can always be converted to 32 bit and back for any valid handle value.

GDI handles cannot be inherited.

like image 93
Joshua Avatar answered Nov 03 '22 00:11

Joshua


Yes, but when converting from 32-bit handles to 64-bit handles, make sure to sign-extend the value. That is, set bits 32-63 to the value of bit 31. So, 0x80000000 becomes 0xFFFFFFFF80000000, not 0x0000000080000000. Also, note that this compatibility between 32 and 64-bit handles is only guaranteed for user-mode handles (which is all you should ever be dealing with anyway unless you're writing a driver or some such thing that runs in kernel mode.)

See also: this SO question and its answer (What is Windows HANDLE range on a 64-bit application?)

like image 28
reirab Avatar answered Nov 02 '22 23:11

reirab