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.

126 lines
2.5 KiB

  1. //***************************************************************************
  2. //
  3. // PROVEXPT.H
  4. //
  5. // Module: OLE MS Provider Framework
  6. //
  7. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  8. //
  9. //***************************************************************************
  10. #ifndef _PROVIDER_NEW_DELETE_EXCEPT_H
  11. #define _PROVIDER_NEW_DELETE_EXCEPT_H
  12. #include <eh.h>
  13. void * __cdecl operator new( size_t n);
  14. void* __cdecl operator new[]( size_t n);
  15. void __cdecl operator delete( void *ptr );
  16. void __cdecl operator delete[]( void *ptr );
  17. //taken from new.h
  18. #ifndef __PLACEMENT_NEW_INLINE
  19. #define __PLACEMENT_NEW_INLINE
  20. inline void *__cdecl operator new(size_t, void *_P)
  21. {return (_P); }
  22. #if _MSC_VER >= 1200
  23. inline void __cdecl operator delete(void *, void *)
  24. {return; }
  25. #endif
  26. #endif
  27. class CurveBall
  28. {
  29. private:
  30. UINT nSE;
  31. EXCEPTION_POINTERS* m_pExp;
  32. public:
  33. CurveBall() {}
  34. CurveBall( UINT n, EXCEPTION_POINTERS* pExp ) : nSE( n ), m_pExp( pExp ) {}
  35. ~CurveBall() {}
  36. UINT GetSENumber() { return nSE; }
  37. EXCEPTION_POINTERS* GetExtendedInfo() { return m_pExp; }
  38. };
  39. class Structured_Exception
  40. {
  41. private:
  42. UINT nSE;
  43. EXCEPTION_POINTERS* m_pExp;
  44. public:
  45. Structured_Exception() {}
  46. Structured_Exception( UINT n, EXCEPTION_POINTERS* pExp ) : nSE( n ), m_pExp( pExp ) {}
  47. ~Structured_Exception() {}
  48. UINT GetSENumber() { return nSE; }
  49. EXCEPTION_POINTERS* GetExtendedInfo() { return m_pExp; }
  50. };
  51. class SetStructuredExceptionHandler
  52. {
  53. private:
  54. _se_translator_function m_PrevFunc;
  55. public:
  56. static void __cdecl trans_func( UINT u, EXCEPTION_POINTERS* pExp )
  57. {
  58. #ifdef CRASH_ON_EXCEPTION
  59. throw CurveBall(u, pExp);
  60. #else
  61. throw Structured_Exception(u, pExp);
  62. #endif
  63. }
  64. SetStructuredExceptionHandler() : m_PrevFunc(NULL)
  65. {
  66. m_PrevFunc = _set_se_translator( trans_func );
  67. }
  68. ~SetStructuredExceptionHandler()
  69. {
  70. _set_se_translator( m_PrevFunc );
  71. }
  72. };
  73. class Heap_Exception
  74. {
  75. public:
  76. enum HEAP_ERROR
  77. {
  78. E_ALLOCATION_ERROR = 0,
  79. E_FREE_ERROR
  80. };
  81. private:
  82. HEAP_ERROR m_Error;
  83. public:
  84. Heap_Exception(HEAP_ERROR e) : m_Error(e) {}
  85. ~Heap_Exception() {}
  86. HEAP_ERROR GetError() { return m_Error; }
  87. };
  88. template<typename T>
  89. void realloc_throw(T ** ptr, size_t size)
  90. {
  91. T * tmp = (T*)realloc (*ptr, size);
  92. if (tmp == 0)
  93. {
  94. free (*ptr);
  95. *ptr = 0;
  96. throw Heap_Exception(Heap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  97. };
  98. *ptr = tmp;
  99. };
  100. #endif //_PROVIDER_NEW_DELETE_EXCEPT_H