X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/9385eb3d10ebe5eb398c52040ec3dbfba9b0cdcf..7ba935f9833da45a0dbcb06329e3015acee97223:/include/malloc/malloc.h diff --git a/include/malloc/malloc.h b/include/malloc/malloc.h index c6a4172..ec9fcf1 100644 --- a/include/malloc/malloc.h +++ b/include/malloc/malloc.h @@ -3,8 +3,6 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in @@ -36,8 +34,8 @@ __BEGIN_DECLS typedef struct _malloc_zone_t { /* Only zone implementors should depend on the layout of this structure; Regular callers should use the access functions below */ - unsigned version; - void *reserved2; + void *reserved1; /* RESERVED FOR CFAllocator DO NOT USE */ + void *reserved2; /* RESERVED FOR CFAllocator DO NOT USE */ 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 */ void *(*malloc)(struct _malloc_zone_t *zone, size_t size); void *(*calloc)(struct _malloc_zone_t *zone, size_t num_items, size_t size); /* same as malloc, but block returned is set to zero */ @@ -52,7 +50,13 @@ typedef struct _malloc_zone_t { 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 */ struct malloc_introspection_t *introspect; - void *reserved5; + unsigned version; + + /* aligned memory allocation. The callback may be NULL. */ + void *(*memalign)(struct _malloc_zone_t *zone, size_t alignment, size_t size); + + /* free a pointer known to be in zone and known to have the given size. The callback may be NULL. */ + void (*free_definite_size)(struct _malloc_zone_t *zone, void *ptr, size_t size); } malloc_zone_t; /********* Creation and destruction ************/ @@ -61,7 +65,7 @@ extern malloc_zone_t *malloc_default_zone(void); /* The initial zone */ extern malloc_zone_t *malloc_create_zone(vm_size_t start_size, unsigned flags); - /* Create a new zone */ + /* Creates a new zone with default behavior and registers it */ extern void malloc_destroy_zone(malloc_zone_t *zone); /* Destroys zone and everything it allocated */ @@ -90,6 +94,16 @@ extern malloc_zone_t *malloc_zone_from_ptr(const void *ptr); extern size_t malloc_size(const void *ptr); /* Returns size of given ptr */ +extern size_t malloc_good_size(size_t size); + /* Returns number of bytes greater than or equal to size that can be allocated without padding */ + +extern void *malloc_zone_memalign(malloc_zone_t *zone, size_t alignment, size_t size); + /* + * Allocates a new pointer of size size whose address is an exact multiple of alignment. + * alignment must be a power of two and at least as large as sizeof(void *). + * zone must be non-NULL. + */ + /********* Batch methods ************/ extern unsigned malloc_zone_batch_malloc(malloc_zone_t *zone, size_t size, void **results, unsigned num_requested); @@ -98,11 +112,26 @@ extern unsigned malloc_zone_batch_malloc(malloc_zone_t *zone, size_t size, void extern void malloc_zone_batch_free(malloc_zone_t *zone, void **to_be_freed, unsigned num); /* frees all the pointers in to_be_freed; note that to_be_freed may be overwritten during the process; This function will always free even if the zone has no batch callback */ +/********* Functions for libcache ************/ + +extern malloc_zone_t *malloc_default_purgeable_zone(void); + /* Returns a pointer to the default purgeable_zone. */ + +extern void malloc_make_purgeable(void *ptr); + /* Make an allocation from the purgeable zone purgeable if possible. */ + +extern int malloc_make_nonpurgeable(void *ptr); + /* Makes an allocation from the purgeable zone nonpurgeable. + * Returns zero if the contents were not purged since the last + * call to malloc_make_purgeable, else returns non-zero. */ + /********* Functions for zone implementors ************/ extern void malloc_zone_register(malloc_zone_t *zone); - /* Registers a freshly created zone; - Should typically be called after a zone has been created */ + /* Registers a custom malloc zone; Should typically be called after a + * malloc_zone_t has been filled in with custom methods by a client. See + * malloc_create_zone for creating additional malloc zones with the + * default allocation and free behavior. */ extern void malloc_zone_unregister(malloc_zone_t *zone); /* De-registers a zone @@ -133,6 +162,7 @@ local_memory: set to a contiguous chunk of memory; validity of local_memory is a #define MALLOC_PTR_IN_USE_RANGE_TYPE 1 /* for allocated pointers */ #define MALLOC_PTR_REGION_RANGE_TYPE 2 /* for region containing pointers */ #define MALLOC_ADMIN_REGION_RANGE_TYPE 4 /* for region used internally */ +#define MALLOC_ZONE_SPECIFIC_FLAGS 0xff00 /* bits reserved for zone-specific purposes */ typedef void vm_range_recorder_t(task_t, void *, unsigned type, vm_range_t *, unsigned); /* given a task and context, "records" the specified addresses */ @@ -146,6 +176,7 @@ typedef struct malloc_introspection_t { void (*force_lock)(malloc_zone_t *zone); /* Forces locking zone */ void (*force_unlock)(malloc_zone_t *zone); /* Forces unlocking zone */ void (*statistics)(malloc_zone_t *zone, malloc_statistics_t *stats); /* Fills statistics */ + boolean_t (*zone_locked)(malloc_zone_t *zone); /* Are any zone locks held */ } malloc_introspection_t; extern void malloc_printf(const char *format, ...); @@ -179,6 +210,17 @@ extern void malloc_zone_log(malloc_zone_t *zone, void *address); If address==0 nothing is logged; If address==-1 all activity is logged; Else only the activity regarding address is logged */ + +struct mstats { + size_t bytes_total; + size_t chunks_used; + size_t bytes_used; + size_t chunks_free; + size_t bytes_free; +}; + +extern struct mstats mstats(void); + __END_DECLS #endif /* _MALLOC_MALLOC_H_ */