使用NT_SUCCESS()宏判断驱动返回NTSTATUS值的原因

版权声明:欢迎转载,注明出处 https://blog.csdn.net/youyou519/article/details/83142161

根据大佬的博客,首先

//
//  Status values are 32 bit values laid out as follows:
//
//   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
//   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
//  +---+-+-------------------------+-------------------------------+
//  |Sev|C|       Facility          |               Code            |
//  +---+-+-------------------------+-------------------------------+
//
//  where
//
//      Sev - is the severity code
//
//          00 - Success
//          01 - Informational
//          10 - Warning
//          11 - Error
//
//      C - is the Customer code flag
//
//      Facility - is the facility code
//
//      Code - is the facility's status code
//

//
// Generic test for success on any status value (non-negative numbers
// indicate success).
//

#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)

//
// Generic test for information on any status value.
//

所以可见NTSTATUS是个有符号的长整数,在Sev域中,是安全码,正的代表成功,负的代表失败,所以00和01表示成功的状态,10和11表示错误状态。即对于这样的有符号长整数的最高位(也就是符号位) ,0成功,1错误。,如果NTSTATUS>=0为成功,NTSTATUS<0为错误。所以定义

#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)

大于1时候成功

猜你喜欢

转载自blog.csdn.net/youyou519/article/details/83142161