alloc_c.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright (C) 2009-2015 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <rth@redhat.com>.
  3. This file is part of the GNU Transactional Memory Library (libitm).
  4. Libitm is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #include "libitm_i.h"
  20. using namespace GTM;
  21. extern "C" {
  22. /* Wrap: malloc (size_t sz) */
  23. void *
  24. _ITM_malloc (size_t sz)
  25. {
  26. void *r = malloc (sz);
  27. if (r)
  28. gtm_thr()->record_allocation (r, free);
  29. return r;
  30. }
  31. /* Wrap: calloc (size_t nm, size_t sz) */
  32. void *
  33. _ITM_calloc (size_t nm, size_t sz)
  34. {
  35. void *r = calloc (nm, sz);
  36. if (r)
  37. gtm_thr()->record_allocation (r, free);
  38. return r;
  39. }
  40. /* Wrap: free (void *ptr) */
  41. void
  42. _ITM_free (void *ptr)
  43. {
  44. if (ptr)
  45. gtm_thr()->forget_allocation (ptr, free);
  46. }
  47. /* Forget any internal references to PTR. */
  48. __attribute__((transaction_pure))
  49. void ITM_REGPARM
  50. _ITM_dropReferences (void *ptr, size_t len)
  51. {
  52. // The semantics of _ITM_dropReferences are not sufficiently defined in the
  53. // ABI specification, so it does not make sense to support it right now. See
  54. // the libitm documentation for details.
  55. GTM_fatal("_ITM_dropReferences is not supported");
  56. }
  57. } // extern "C"