好友
阅读权限100
听众
最后登录1970-1-1
|
本帖最后由 爱飞的猫 于 2025-3-16 19:56 编辑
可以看微软的技术博客:
https://devblogs.microsoft.com/oldnewthing/20080228-00/?p=23283
总结:都是巧合。
上面的链接有提到一个更老的文章(连接没了,要找快照):
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...) Kernel handles are things you can pass to the CloseHandle function.
The availability of the bottom two bits is buried in the ntdef.h header file:
//
// Low order two bits of a handle are ignored by the system and available
// for use by application code as tag bits. The remaining bits are opaque
// and used to store a serial number and table index.
//
#define OBJ_HANDLE_TAGBITS 0x00000003L
That at least the bottom bit of kernel HANDLEs is always zero is implied by the GetQueuedCompletionStatus function, which indicates that you can set the bottom bit of the event handle to suppress completion port notification. In order for this to work, the bottom bit must normally be zero.
This information is not useful for most application writers, which should continue to treat HANDLEs as opaque values. The people who would be interested in tag bits are those who are implementing low-level class libraries or are wrapping kernel objects inside a larger framework. 内核句柄低二位有其他作用,而进程 id 等也是内核句柄。所以低 2 位为零,也就是都是 4 的倍数。 |
免费评分
-
查看全部评分
|