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.

108 lines
4.2 KiB

  1. /* Copyright (C) Boris Nikolaus, Germany, 1996-1997. All rights reserved. */
  2. /* Copyright (C) Microsoft Corporation, 1997-1998. All rights reserved. */
  3. #ifndef _MS_UT_H_
  4. #define _MS_UT_H_
  5. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
  6. // #define FIELD_OFFSET(type, field) ((long)&(((type *)0)->field)) // from winnt.h
  7. #define PARAMS_SIZE_N_ARRARY(arr) ARRAY_SIZE(arr), arr
  8. #define LPVOID_ADD(ptr,inc) (LPVOID) ((ASN1octet_t *) (ptr) + (ASN1uint32_t) (inc))
  9. #define LPVOID_SUB(ptr,dec) (LPVOID) ((ASN1octet_t *) (ptr) - (ASN1uint32_t) (inc))
  10. #define LPVOID_NEXT(ptr) *(LPVOID FAR *) (ptr)
  11. // the following constants is for calculating decoded data structure size
  12. // we are conservative here and try to be 4-byte aligned due to Alpha platform.
  13. #define ASN1_SIZE_ALIGNED(n) (n) = ((((n) + 3) >> 2) << 2)
  14. #ifdef ENABLE_BER
  15. int My_memcmp(ASN1octet_t *pBuf1, ASN1uint32_t cbBuf1Size, ASN1octet_t *pBuf2, ASN1uint32_t cbBuf2Size);
  16. #endif // ENABLE_BER
  17. #define UNKNOWN_MODULE 0
  18. #ifdef ENABLE_MEMORY_TRACKING
  19. void DbgMemTrackFinalCheck ( void );
  20. LPVOID DbgMemAlloc ( UINT cbSize, ASN1uint32_t nModuleName, LPSTR pszFileName, UINT nLineNumber );
  21. void DbgMemFree ( LPVOID ptr );
  22. LPVOID DbgMemReAlloc ( LPVOID ptr, UINT cbSize, ASN1uint32_t nModuleName, LPSTR pszFileName, UINT nLineNumber );
  23. #define MemAlloc(cb,modname) DbgMemAlloc((cb), modname, __FILE__, __LINE__)
  24. #define MemFree(lp) DbgMemFree((lp))
  25. #define MemReAlloc(lp,cb,modname) DbgMemReAlloc((lp), (cb), modname, __FILE__, __LINE__)
  26. #define _ModName(enc_dec) (enc_dec)->module->nModuleName
  27. LPVOID DbgDecMemAlloc ( ASN1decoding_t dec, ASN1uint32_t cbSize, LPSTR pszFileName, ASN1uint32_t nLineNumber);
  28. LPVOID DbgDecMemReAlloc ( ASN1decoding_t dec, LPVOID lpData, ASN1uint32_t cbSize, LPSTR pszFileName, ASN1uint32_t nLineNumber);
  29. #define DecMemAlloc(dec,cb) DbgDecMemAlloc((dec), (cb), __FILE__, __LINE__)
  30. #define DecMemReAlloc(dec,lp,cb) DbgDecMemReAlloc((dec), (lp), (cb), __FILE__, __LINE__)
  31. #define EncMemAlloc(enc,cb) DbgMemAlloc((cb), _ModName(enc), __FILE__, __LINE__)
  32. #define EncMemReAlloc(enc,lp,cb) DbgMemReAlloc((lp), (cb), _ModName(enc), __FILE__, __LINE__)
  33. #else // ! ENABLE_MEMORY_TRACKING
  34. #define MemAllocEx(dec,cb,fZero) LocalAlloc((fZero)?LPTR:LMEM_FIXED, (cb))
  35. #define MemAlloc(cb,modname) LocalAlloc(LPTR,(cb))
  36. #define MemFree(lp) LocalFree(lp)
  37. #define MemReAllocEx(dec,lp,cb,fZero) ((lp) ? \
  38. LocalReAlloc((lp),(cb),(fZero)?LMEM_MOVEABLE|LMEM_ZEROINIT:LMEM_MOVEABLE) : \
  39. LocalAlloc((fZero)?LPTR:LMEM_FIXED, (cb)))
  40. #define MemReAlloc(lp,cb,modname) ((lp) ? \
  41. LocalReAlloc((lp),(cb),LMEM_MOVEABLE|LMEM_ZEROINIT) : \
  42. LocalAlloc(LPTR, (cb)))
  43. #define _ModName(enc_dec)
  44. LPVOID DecMemAlloc ( ASN1decoding_t dec, ASN1uint32_t cbSize );
  45. LPVOID DecMemReAlloc ( ASN1decoding_t dec, LPVOID lpData, ASN1uint32_t cbSize );
  46. #define EncMemAlloc(enc,cb) MemAlloc((cb),0)
  47. #define EncMemReAlloc(enc,lp,cb) MemReAlloc((lp),(cb),0)
  48. #endif // ! ENABLE_MEMORY_TRACKING
  49. void DecMemFree ( ASN1decoding_t dec, LPVOID lpData );
  50. #define EncMemFree(enc,lpData) MemFree(lpData)
  51. int IsDigit(char p);
  52. unsigned int DecimalStringToUINT(char * pcszString, ASN1uint32_t cch);
  53. void * ms_bSearch (
  54. const void *key,
  55. const void *base,
  56. size_t num,
  57. size_t width,
  58. int (__cdecl *compare)(const void *, const void *)
  59. );
  60. #define MyAssert(f)
  61. #ifdef _DEBUG
  62. void MyDebugBreak(void);
  63. __inline void EncAssert(ASN1encoding_t enc, int val)
  64. {
  65. if ((! (enc->dwFlags & ASN1FLAGS_NOASSERT)) && (! (val)))
  66. {
  67. MyDebugBreak();
  68. }
  69. }
  70. __inline void DecAssert(ASN1decoding_t dec, int val)
  71. {
  72. if ((! (dec->dwFlags & ASN1FLAGS_NOASSERT)) && (! (val)))
  73. {
  74. MyDebugBreak();
  75. }
  76. }
  77. #else
  78. #define EncAssert(enc,f)
  79. #define DecAssert(dec,f)
  80. #endif // _DEBUG
  81. #endif // _MS_UT_H_