malloc.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apple Public Source License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://www.opensource.apple.com/apsl/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. */
  23. #ifndef THIRD_PARTY_APPLE_APSL_MALLOC_H_
  24. #define THIRD_PARTY_APPLE_APSL_MALLOC_H_
  25. #include <mach/boolean.h>
  26. typedef struct _ChromeMallocZone {
  27. /* Only zone implementors should depend on the layout of this structure;
  28. Regular callers should use the access functions below */
  29. void *reserved1; /* RESERVED FOR CFAllocator DO NOT USE */
  30. void *reserved2; /* RESERVED FOR CFAllocator DO NOT USE */
  31. size_t (*size)(struct _malloc_zone_t *zone, const void *ptr); /* returns the size of a block or 0 if not in this zone; must be fast, especially for negative answers */
  32. void *(*malloc)(struct _malloc_zone_t *zone, size_t size);
  33. void *(*calloc)(struct _malloc_zone_t *zone, size_t num_items, size_t size); /* same as malloc, but block returned is set to zero */
  34. void *(*valloc)(struct _malloc_zone_t *zone, size_t size); /* same as malloc, but block returned is set to zero and is guaranteed to be page aligned */
  35. void (*free)(struct _malloc_zone_t *zone, void *ptr);
  36. void *(*realloc)(struct _malloc_zone_t *zone, void *ptr, size_t size);
  37. void (*destroy)(struct _malloc_zone_t *zone); /* zone is destroyed and all memory reclaimed */
  38. const char *zone_name;
  39. /* Optional batch callbacks; these may be NULL */
  40. unsigned (*batch_malloc)(struct _malloc_zone_t *zone, size_t size, void **results, unsigned num_requested); /* given a size, returns pointers capable of holding that size; returns the number of pointers allocated (maybe 0 or less than num_requested) */
  41. void (*batch_free)(struct _malloc_zone_t *zone, void **to_be_freed, unsigned num_to_be_freed); /* frees all the pointers in to_be_freed; note that to_be_freed may be overwritten during the process */
  42. struct malloc_introspection_t *introspect;
  43. unsigned version;
  44. /* aligned memory allocation. The callback may be NULL. Present in version >= 5. */
  45. void *(*memalign)(struct _malloc_zone_t *zone, size_t alignment, size_t size);
  46. /* free a pointer known to be in zone and known to have the given size. The callback may be NULL. Present in version >= 6.*/
  47. void (*free_definite_size)(struct _malloc_zone_t *zone, void *ptr, size_t size);
  48. /* Empty out caches in the face of memory pressure. The callback may be NULL. Present in version >= 8. */
  49. size_t (*pressure_relief)(struct _malloc_zone_t *zone, size_t goal);
  50. /*
  51. * Checks whether an address might belong to the zone. May be NULL. Present in version >= 10.
  52. * False positives are allowed (e.g. the pointer was freed, or it's in zone space that has
  53. * not yet been allocated. False negatives are not allowed.
  54. */
  55. boolean_t (*claimed_address)(struct _malloc_zone_t *zone, void *ptr);
  56. } ChromeMallocZone;
  57. #endif // THIRD_PARTY_APPLE_APSL_MALLOC_H_