From: David F. on

Hi,

So everything I've read seems to suggest that Handles are global in Windows
space and even between x64 and x32 processes. One thing I haven't seen
addressed is if opening a handle in one process and then closing in another
is allowed or does that create a potential for double closing the handle? I
mean the process that opened the handle would automatically close any open
handles, but would it know that the handle was closed? If not, I guess if
one wanted to transparently use a handle as it would itself one would
duplicate the handle from the other process and use then close the
duplicated handle and let the other process close the handle it opened. Or
pass something other than a handle to a process and open that within the
process where it will be used.

?

TIA!!

From: Don Burn on

Handles are unique to processes, there is nothing global about them.
When the process that opens the handle terminates they get closed.
Passing a handle to another process will just cause it to get an invalid
handle or if you are really unlucky the wrong handle. If you want to
pass a handle look at the DuplicateHandle function, but this is creating
a new handle.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr




"David F." <df2705(a)community.nospam> wrote in message
news:B6984F33-F6DE-4283-B036-CACC6767EBCE(a)microsoft.com:

> Hi,
>
> So everything I've read seems to suggest that Handles are global in Windows
> space and even between x64 and x32 processes. One thing I haven't seen
> addressed is if opening a handle in one process and then closing in another
> is allowed or does that create a potential for double closing the handle? I
> mean the process that opened the handle would automatically close any open
> handles, but would it know that the handle was closed? If not, I guess if
> one wanted to transparently use a handle as it would itself one would
> duplicate the handle from the other process and use then close the
> duplicated handle and let the other process close the handle it opened. Or
> pass something other than a handle to a process and open that within the
> process where it will be used.
>
> ?
>
> TIA!!


__________ Information from ESET Smart Security, version of virus
signature database 4896 (20100225) __________

The message was checked by ESET Smart Security.

http://www.eset.com


From: Jonathan de Boyne Pollard on
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<blockquote
cite="mid:B6984F33-F6DE-4283-B036-CACC6767EBCE(a)microsoft.com"
type="cite">
<p>So everything I've read seems to suggest that Handles are global
in Windows space and even between x64 and x32 processes.</p>
</blockquote>
<p>You haven't read nearly enough.&nbsp; Start with <a
href="http://msdn.microsoft.com/en-gb/library/ms724485%28VS.85%29.aspx">the
MSDN Libary discussion of kernel objects</a>.</p>
</body>
</html>
From: David F. on
I guess it depends on the type of handle:

"64-bit versions of Windows use 32-bit handles for interoperability. When
sharing a handle between 32-bit and 64-bit applications, only the lower 32
bits are significant, so it is safe to truncate the handle (when passing it
from 64-bit to 32-bit) or sign-extend the handle (when passing it from
32-bit to 64-bit). Handles that can be shared include handles to user
objects such as windows (HWND), handles to GDI objects such as pens and
brushes (HBRUSH and HPEN), and handles to named objects such as mutexes,
semaphores, and file handles."

From http://msdn.microsoft.com/en-us/library/aa384203(VS.85).aspx


"Jonathan de Boyne Pollard" <J.deBoynePollard-newsgroups(a)NTLWorld.COM> wrote
in message

news:IU.D20100226.T083821.P9445.Q0(a)J.de.Boyne.Pollard.localhost...
So everything I've read seems to suggest that Handles are global in Windows
space and even between x64 and x32 processes.
You haven't read nearly enough. Start with the MSDN Libary discussion of
kernel objects.

From: rogero on
On Feb 26, 10:29 am, "David F." <df2...(a)community.nospam> wrote:
> I guess it depends on the type of handle:

It depends more on how it is created.

If you create a handle with inheritable attributes it is passed down
to the child process using the same handle value. However, each
process actually has its own handle to the same underlying kernel
object and each process must explicitly or implicitly close the handle
before the underlying object is released.

Simply passing the handle value to another process does not enable the
handle to be used by the other process -- in general this value may
even be a genuine handle in the target process but not to the same
object.

Example:

parentProcess.exe:

HANDLE h1 = OpenMutex(MUTEX_ALL_ACCESS, TRUE, "Global\\RogerOrr");
CreateProcess("childProcess.exe", ...)

childProcess.exe:
will be created with an already open handle to the mutex with the same
numeric value as h1.

siblingProcess:
HANDLE h2 = OpenMutex(MUTEX_ALL_ACCESS, TRUE, "Global\\RogerOrr");

h2 may or may not have the same numeric value as h1.

HTH,
Roger.