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.

71 lines
2.0 KiB

  1. /***************************************************************************
  2. Name : MEMUTIL.C
  3. Comment : Mem mgmnt and utilty functions
  4. Revision Log
  5. Date Name Description
  6. -------- ----- ---------------------------------------------------------
  7. ***************************************************************************/
  8. #define USE_DEBUG_CONTEXT DEBUG_CONTEXT_T30_MAIN
  9. #include "prep.h"
  10. #include "glbproto.h"
  11. void MyAllocInit(PThrdGlbl pTG)
  12. {
  13. pTG->uCount=0;
  14. pTG->uUsed=0;
  15. }
  16. LPBUFFER MyAllocBuf(PThrdGlbl pTG, LONG sSize)
  17. {
  18. LPBUFFER lpbf;
  19. DEBUG_FUNCTION_NAME(_T("MyAllocBuf"));
  20. if(pTG->uCount >= STATICBUFCOUNT)
  21. {
  22. DebugPrintEx(DEBUG_ERR,"Already alloced %d bufs", pTG->uCount);
  23. return NULL;
  24. }
  25. else if(pTG->uUsed+sSize > STATICBUFSIZE)
  26. {
  27. DebugPrintEx( DEBUG_ERR,
  28. "Already alloced %d bytes out of %d. Want %d",
  29. pTG->uUsed,
  30. STATICBUFSIZE,
  31. sSize);
  32. return NULL;
  33. }
  34. // init header
  35. pTG->bfStaticBuf[pTG->uCount].lpbBegData = pTG->bfStaticBuf[pTG->uCount].lpbBegBuf =
  36. pTG->bStaticBufData + pTG->uUsed;
  37. pTG->bfStaticBuf[pTG->uCount].wLengthBuf = (USHORT) sSize;
  38. pTG->uUsed += (USHORT) sSize;
  39. pTG->bfStaticBuf[pTG->uCount].wLengthData = 0;
  40. lpbf = &(pTG->bfStaticBuf[pTG->uCount++]);
  41. return lpbf;
  42. }
  43. BOOL MyFreeBuf(PThrdGlbl pTG, LPBUFFER lpbf)
  44. {
  45. DEBUG_FUNCTION_NAME(_T("MyFreeBuf"));
  46. if(pTG->uCount==0 || lpbf!= &(pTG->bfStaticBuf[pTG->uCount-1]))
  47. {
  48. DebugPrintEx( DEBUG_ERR,
  49. "Not alloced or out-of-order free. Count=%d lpbf=%08lx bf=%08lx",
  50. pTG->uCount,
  51. lpbf,
  52. (LPBUFFER)&pTG->bfStaticBuf);
  53. return FALSE;
  54. }
  55. pTG->uCount--;
  56. pTG->uUsed -= lpbf->wLengthBuf;
  57. return TRUE;
  58. }