Source code of Windows XP (NT5)
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.

124 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. StrucAlg.c
  5. Abstract:
  6. This module contains Remote Admin Protocol (RAP) routines. These routines
  7. are shared between XactSrv and RpcXlate.
  8. Author:
  9. John Rogers (JohnRo) 10-Jul-1991
  10. Environment:
  11. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  12. Requires ANSI C extensions: slash-slash comments, long external names.
  13. Revision History:
  14. 10-Jul-1991 JohnRo
  15. Created.
  16. --*/
  17. // These must be included first:
  18. #include <windef.h> // IN, LPDWORD, NULL, OPTIONAL, DWORD, etc.
  19. #include <lmcons.h> // NET_API_STATUS
  20. // These may be included in any order:
  21. #include <align.h> // ALIGN_ equates.
  22. #include <netdebug.h> // NetpKdPrint(()), FORMAT_DWORD.
  23. #include <rap.h> // My prototype, LPDESC, FORMAT_LPDESC.
  24. #include <rapdebug.h> // IF_DEBUG().
  25. DWORD
  26. RapStructureAlignment (
  27. IN LPDESC Descriptor,
  28. IN RAP_TRANSMISSION_MODE TransmissionMode,
  29. IN BOOL Native
  30. )
  31. /*++
  32. Routine Description:
  33. This routine determines how much a given structure would need to be
  34. aligned if present in an array.
  35. Arguments:
  36. Descriptor - the format of the structure.
  37. Transmission Mode - Indicates whether this array is part of a response,
  38. a request, or both.
  39. Native - TRUE iff the descriptor defines a native structure. (This flag is
  40. used to decide whether or not to align fields.)
  41. Return Value:
  42. DWORD - The number of bytes of alignment for the structure. This may be
  43. 1 for byte alignment.
  44. --*/
  45. {
  46. DWORD Alignment;
  47. #if DBG
  48. DWORD FixedSize;
  49. #endif
  50. //
  51. // I (JR) have a theory that this must only being used for data structures,
  52. // and never requests or responses. (Request and responses are never
  53. // aligned; that's part of the Remote Admin Protocol definition.) So,
  54. // let's do a quick check:
  55. //
  56. NetpAssert( TransmissionMode == Both );
  57. //
  58. // Walk the descriptor and find the worst alignment for it.
  59. //
  60. RapExamineDescriptor(
  61. Descriptor,
  62. NULL,
  63. #if DBG
  64. & FixedSize,
  65. #else
  66. NULL, // don't need structure size
  67. #endif
  68. NULL,
  69. NULL,
  70. NULL,
  71. & Alignment,
  72. TransmissionMode,
  73. Native
  74. );
  75. IF_DEBUG(STRUCALG) {
  76. NetpKdPrint(( "RapStructureAlignment: alignment of " FORMAT_LPDESC
  77. " is " FORMAT_DWORD ".\n", Descriptor, Alignment ));
  78. }
  79. //
  80. // Let's do some sanity checked of the alignment value we got back.
  81. //
  82. NetpAssert( Alignment >= ALIGN_BYTE );
  83. NetpAssert( Alignment <= ALIGN_WORST );
  84. #if DBG
  85. NetpAssert( Alignment <= FixedSize );
  86. #endif
  87. return Alignment;
  88. } // RapStructureAlignment