{"id":36633,"date":"2005-01-21T07:00:00","date_gmt":"2005-01-21T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/01\/21\/why-are-kernel-handles-always-a-multiple-of-four\/"},"modified":"2005-01-21T07:00:00","modified_gmt":"2005-01-21T07:00:00","slug":"why-are-kernel-handles-always-a-multiple-of-four","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050121-00\/?p=36633","title":{"rendered":"Why are kernel HANDLEs always a multiple of four?"},"content":{"rendered":"<p>\nNot very well known is that the bottom two bits of kernel HANDLEs\nare always zero; in other words, their numeric value is\nalways a multiple of 4.\nNote that this applies only to kernel HANDLEs;\nit does not apply to\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/dllproc\/base\/getcurrentprocess.asp\">\npseudo-handles<\/a>\nor to any other type of handle\n(USER handles, GDI handles, multimedia handles&#8230;)\nKernel handles are things you can pass to\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/sysinfo\/base\/closehandle.asp\">\nthe <\/code>CloseHandle<\/code> function<\/a>.\n<\/p>\n<p>\nThe availability of the bottom two bits is buried in the\n<code>ntdef.h<\/code> header file:\n<\/p>\n<pre>\n\/\/\n\/\/ Low order two bits of a handle are ignored by the system and available\n\/\/ for use by application code as tag bits.  The remaining bits are opaque\n\/\/ and used to store a serial number and table index.\n\/\/\n#define OBJ_HANDLE_TAGBITS  0x00000003L\n<\/pre>\n<p>\nThat at least the bottom bit of kernel HANDLEs is always zero is implied by\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/fileio\/base\/getqueuedcompletionstatus.asp\">\nthe <code>GetQueuedCompletionStatus<\/code> function<\/a>,\nwhich indicates that you can set the bottom bit of the event\nhandle to suppress completion port notification.\nIn order for this to work, the bottom bit must normally be zero.\n<\/p>\n<p>\nThis information is not useful for most application writers,\nwhich should continue to treat HANDLEs as opaque values.\nThe people who would be interested in tag bits are those who\nare implementing low-level class libraries or are wrapping\nkernel objects inside a larger framework.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not very well known is that the bottom two bits of kernel HANDLEs are always zero; in other words, their numeric value is always a multiple of 4. Note that this applies only to kernel HANDLEs; it does not apply to pseudo-handles or to any other type of handle (USER handles, GDI handles, multimedia handles&#8230;) [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-36633","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Not very well known is that the bottom two bits of kernel HANDLEs are always zero; in other words, their numeric value is always a multiple of 4. Note that this applies only to kernel HANDLEs; it does not apply to pseudo-handles or to any other type of handle (USER handles, GDI handles, multimedia handles&#8230;) [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/36633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=36633"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/36633\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=36633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=36633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=36633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}