Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.8 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntrtloverflow.h
  5. Abstract:
  6. 32bit/64bit signed/unsigned add/multiply with overflow checking
  7. Author:
  8. Jay Krell (JayKrell) March 2002
  9. Environment:
  10. anywhere
  11. Revision History:
  12. --*/
  13. #ifndef _NTRTLOVERFLOW_
  14. #define _NTRTLOVERFLOW_
  15. #if (_MSC_VER > 1020)
  16. #pragma once
  17. #endif
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. //
  22. // add functions are FORCEINLINE in ntrtl.h
  23. //
  24. //
  25. // *pc = a * b
  26. // return value is STATUS_INTEGER_OVERFLOW or STATUS_SUCCESS
  27. //
  28. NTSYSAPI
  29. NTSTATUS
  30. NTAPI
  31. RtlMultiplyWithOverflowCheckSigned32(
  32. __int32 * pc,
  33. __int32 a,
  34. __int32 b
  35. );
  36. // not implemented
  37. // NTSYSAPI
  38. // NTSTATUS
  39. // NTAPI
  40. // RtlMultiplyWithOverflowCheckSigned64(
  41. // __int64 * pc,
  42. // __int64 a,
  43. // __int64 b
  44. // );
  45. //
  46. // *pc = a * b
  47. // return value is STATUS_INTEGER_OVERFLOW or STATUS_SUCCESS
  48. //
  49. NTSYSAPI
  50. NTSTATUS
  51. NTAPI
  52. RtlMultiplyWithOverflowCheckUnsigned32(
  53. unsigned __int32 * pc,
  54. unsigned __int32 a,
  55. unsigned __int32 b
  56. );
  57. //
  58. // *pc = a * b
  59. // return value is STATUS_INTEGER_OVERFLOW or STATUS_SUCCESS
  60. //
  61. NTSYSAPI
  62. NTSTATUS
  63. NTAPI
  64. RtlMultiplyWithOverflowCheckUnsigned64(
  65. unsigned __int64 * pc,
  66. unsigned __int64 a,
  67. unsigned __int64 b
  68. );
  69. #define RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK(type, base) ((NTSTATUS (NTAPI * )(type *, type, type))base)
  70. #define RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED32(type) \
  71. RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK(type, RtlMultiplyWithOverflowCheckUnsigned32)
  72. #define RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED64(type) \
  73. RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK(type, RtlMultiplyWithOverflowCheckUnsigned64)
  74. #define RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED32(type) \
  75. RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK(type, RtlMultiplyWithOverflowCheckSigned32)
  76. // signed64 not implemented
  77. #if !defined(_WIN64)
  78. #define RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED_PTR(x) RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED32(x)
  79. #else
  80. #define RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED_PTR(x) RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED64(x)
  81. #endif
  82. #define RtlMultiplyWithOverflowCheckUint RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED32(UINT)
  83. #define RtlMultiplyWithOverflowCheckUint32 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED32(UINT32)
  84. #define RtlMultiplyWithOverflowCheckUlong RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED32(ULONG)
  85. #define RtlMultiplyWithOverflowCheckUlong32 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED32(ULONG32)
  86. #define RtlMultiplyWithOverflowCheckDword RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED32(DWORD)
  87. #define RtlMultiplyWithOverflowCheckDword32 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED32(DWORD32)
  88. #define RtlMultiplyWithOverflowCheckUint64 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED64(UINT64)
  89. #define RtlMultiplyWithOverflowCheckUlong64 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED64(ULONG64)
  90. #define RtlMultiplyWithOverflowCheckDword64 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED64(DWORD64)
  91. #define RtlMultiplyWithOverflowCheckUlonglong RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED64(ULONGLONG)
  92. #define RtlMultiplyWithOverflowCheckInt RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED32(INT)
  93. #define RtlMultiplyWithOverflowCheckInt32 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED32(INT32)
  94. #define RtlMultiplyWithOverflowCheckLong RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED32(LONG)
  95. #define RtlMultiplyWithOverflowCheckLong32 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED32(LONG32)
  96. //not implemented
  97. //#define RtlMultiplyWithOverflowCheckInt64 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED64(INT64)
  98. //#define RtlMultiplyWithOverflowCheckLong64 RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED64(LONG64)
  99. //#define RtlMultiplyWithOverflowCheckLonglong RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED64(LONGLONG)
  100. #define RtlMultiplyWithOverflowCheckUintPtr RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED_PTR(UINT_PTR)
  101. #define RtlMultiplyWithOverflowCheckUlongPtr RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED_PTR(ULONG_PTR)
  102. #define RtlMultiplyWithOverflowCheckDwordPtr RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED_PTR(DWORD_PTR)
  103. #define RtlMultiplyWithOverflowCheckSizet RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_UNSIGNED_PTR(SIZE_T)
  104. //not implemented
  105. //#define RtlMultiplyWithOverflowCheckIntPtr RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED_PTR(INT_PTR)
  106. //#define RtlMultiplyWithOverflowCheckLongPtr RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED_PTR(LONG_PTR)
  107. //#define RtlMultiplyWithOverflowCheckSsizet RTL_CAST_MULTIPLY_WITH_OVERFLOW_CHECK_SIGNED_PTR(SSIZE_T)
  108. #ifdef __cplusplus
  109. } // extern "C"
  110. #endif
  111. #endif