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.

85 lines
3.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: custmact_c_wrap.c
  7. //
  8. // Contents: Wrapper file
  9. //
  10. // Functions: Redefines MIDL_user_allocate\MIDL_user_free for the RPC
  11. // functions defined in custmact.idl.
  12. //
  13. // History: 24-Mar-01 JSimmons Created
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <windows.h>
  17. //--------------------------------------------------------------------------
  18. //
  19. // Why are we doing this? We are doing this because RPC's pickling
  20. // functionality (encode, decode) has some issues when errors (typically
  21. // out-of-mem) are encountered. They do not guarantee the state of the
  22. // out-params when encoding or decoding is ended prematurely. One
  23. // suggestion was to modify MIDL_user_allocate to always zero out the
  24. // contents of any new allocation - this is undesirable from a perf
  25. // perspective, since it would impose a lot of unnecessary overhead
  26. // for everybody. Instead, we decided to overload alloc\free for
  27. // just those functions (encode\decode) that need it. Our custom
  28. // allocator will zero out any new memory allocations since RPC does
  29. // not. This will allow us to deterministically cleanup after any
  30. // failed operations. Fortunately all of the encode\decode functions
  31. // are defined in one idl file, so this change is fairly localized.
  32. //
  33. //--------------------------------------------------------------------------
  34. //+-------------------------------------------------------------------------
  35. //
  36. // Function: CUSTMACT_MIDL_user_allocate
  37. //
  38. // Purpose: allocates memory on behalf of midl-generated stubs. The
  39. // memory block is zeroed out before returning.
  40. //
  41. //--------------------------------------------------------------------------
  42. void* __RPC_API CUSTMACT_MIDL_user_allocate(size_t cb)
  43. {
  44. void* pv = MIDL_user_allocate(cb);
  45. if (pv)
  46. {
  47. ZeroMemory(pv, cb);
  48. }
  49. return pv;
  50. }
  51. //+-------------------------------------------------------------------------
  52. //
  53. // Function: CUSTMACT_MIDL_user_free
  54. //
  55. // Purpose: frees memory allocated by CUSTMACT_MIDL_user_allocate
  56. //
  57. //--------------------------------------------------------------------------
  58. void __RPC_API CUSTMACT_MIDL_user_free(void *pv)
  59. {
  60. MIDL_user_free(pv);
  61. }
  62. //--------------------------------------------------------------------------
  63. //
  64. // Redefine MIDL_user_allocate and MIDL_user_free
  65. //
  66. // Note: Redefining MIDL_user_free is not strictly necessary since
  67. // the regular MIDL_user_free would behave exactly the same as
  68. // CUSTMACT_MIDL_user_free. I include it more for completeness
  69. // than anything else.
  70. //
  71. //--------------------------------------------------------------------------
  72. #define MIDL_user_allocate CUSTMACT_MIDL_user_allocate
  73. #define MIDL_user_free CUSTMACT_MIDL_user_free
  74. //--------------------------------------------------------------------------
  75. //
  76. // Include the midl-generated code
  77. //
  78. //--------------------------------------------------------------------------
  79. #include "custmact_c.c"