GetCurrentProcess returns pseudo handle. Really.

The MSDN document on GetCurrentProcess API function is really wired.

GetCurrentProcess Function

Retrieves a pseudo handle for the current process.

OK, what’s the "pseudo handle?" It actually explains it.

A pseudo handle is a special constant, currently (HANDLE)-1, that is interpreted as the current process handle. For compatibility with future operating systems, it is best to call GetCurrentProcess instead of hard-coding this constant value. The calling process can use a pseudo handle to specify its own process whenever a process handle is required. Pseudo handles are not inherited by child processes.

So, What does GetCurrentProcess() do exactly? Does it just return -1? Yes. Here is the disassemble result of the function.

7c80de95 83c8ff          or      eax,0FFFFFFFFh
7c80de98 c3              ret

Probably, this is the most light weight Windows API function.


About Moto

Engineer who likes coding
This entry was posted in Tips. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s