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.

72 lines
2.3 KiB

  1. /***
  2. *new.cxx - defines C++ new routine
  3. *
  4. * Copyright (c) 1990-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Defines C++ new routine.
  8. *
  9. *Revision History:
  10. * 05-07-90 WAJ Initial version.
  11. * 08-30-90 WAJ new now takes unsigned ints.
  12. * 08-08-91 JCR call _halloc/_hfree, not halloc/hfree
  13. * 08-13-91 KRS Change new.hxx to new.h. Fix copyright.
  14. * 08-13-91 JCR ANSI-compatible _set_new_handler names
  15. * 10-30-91 JCR Split new, delete, and handler into seperate sources
  16. * 11-13-91 JCR 32-bit version
  17. * 02-16-94 SKS Move set_new_handler functionality here from malloc()
  18. * 03-01-94 SKS _pnhHeap must be declared in malloc.c, not here
  19. * 03-03-94 SKS New handler functionality moved to malloc.c but under
  20. * a new name, _nh_malloc().
  21. * 02-01-95 GJF #ifdef out the change above for the Mac (temporary).
  22. * 05-01-95 GJF Spliced on winheap version.
  23. * 05-08-95 CFW Turn on new handling for Mac.
  24. * 05-22-98 JWM Support for KFrei's RTC work, and operator new[].
  25. * 07-28-98 JWM RTC update.
  26. * 11-04-98 JWM Split off new[] to new2.cpp for better granularity.
  27. * 12-18-98 GJF Changes for 64-bit size_t.
  28. * 05-26-99 KBF Updated RTC hook func params
  29. * 02-20-02 BWT Reduce the call frame by calling heap_alloc directly (better DW traces)
  30. *
  31. *******************************************************************************/
  32. #include <cruntime.h>
  33. #include <malloc.h>
  34. #include <new.h>
  35. #include <stdlib.h>
  36. #include <winheap.h>
  37. #include <rtcsup.h>
  38. #include <internal.h>
  39. void * operator new( size_t cb )
  40. {
  41. void *res;
  42. // validate size
  43. if (cb > _HEAP_MAXREQ)
  44. res = NULL;
  45. else {
  46. for (;;) {
  47. // allocate memory block
  48. res = _heap_alloc(cb);
  49. // if successful allocation, return pointer to memory
  50. if (res)
  51. break;
  52. // call installed new handler
  53. if (!_callnewh(cb))
  54. break;
  55. // new handler was successful -- try to allocate again
  56. }
  57. }
  58. RTCCALLBACK(_RTC_Allocate_hook, (res, cb, 0));
  59. return res;
  60. }