X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/43866e378188c25dd1e2208016ab3cbeb086ae6c..7e4a7d3939db04e70062ae6c7bf24b8c8b2f5a7c:/osfmk/kern/zalloc.h diff --git a/osfmk/kern/zalloc.h b/osfmk/kern/zalloc.h index 659efb92e..b21f71253 100644 --- a/osfmk/kern/zalloc.h +++ b/osfmk/kern/zalloc.h @@ -1,16 +1,19 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * 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 - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER @@ -20,7 +23,7 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * @OSF_COPYRIGHT@ @@ -59,21 +62,21 @@ * */ +#ifdef KERNEL_PRIVATE + #ifndef _KERN_ZALLOC_H_ #define _KERN_ZALLOC_H_ #include #include - -#include - -#ifdef __APPLE_API_PRIVATE +#include #ifdef MACH_KERNEL_PRIVATE #include #include #include +#include #include #include @@ -88,11 +91,15 @@ struct zone { int count; /* Number of elements used now */ vm_offset_t free_elements; + decl_lck_mtx_data(,lock) /* zone lock */ + lck_mtx_ext_t lock_ext; /* placeholder for indirect mutex */ + lck_attr_t lock_attr; /* zone lock attribute */ + lck_grp_t lock_grp; /* zone lock group */ + lck_grp_attr_t lock_grp_attr; /* zone lock group attribute */ vm_size_t cur_size; /* current memory utilization */ vm_size_t max_size; /* how large can this zone grow */ vm_size_t elem_size; /* size of an element */ vm_size_t alloc_size; /* size used for more memory */ - char *zone_name; /* a name for the zone */ unsigned int /* boolean_t */ exhaustible :1, /* (F) merely return if empty? */ /* boolean_t */ collectable :1, /* (F) garbage collect empty pages */ @@ -100,121 +107,131 @@ struct zone { /* boolean_t */ allows_foreign :1,/* (F) allow non-zalloc space */ /* boolean_t */ doing_alloc :1, /* is zone expanding now? */ /* boolean_t */ waiting :1, /* is thread waiting for expansion? */ - /* boolean_t */ async_pending :1; /* asynchronous allocation pending? */ + /* boolean_t */ async_pending :1, /* asynchronous allocation pending? */ + /* boolean_t */ doing_gc :1; /* garbage collect in progress? */ struct zone * next_zone; /* Link for all-zones list */ call_entry_data_t call_async_alloc; /* callout for asynchronous alloc */ + const char *zone_name; /* a name for the zone */ #if ZONE_DEBUG queue_head_t active_zones; /* active elements */ #endif /* ZONE_DEBUG */ - decl_simple_lock_data(,lock) /* generic lock */ }; extern void zone_gc(void); -extern void consider_zone_gc(void); +extern void consider_zone_gc(boolean_t); /* Steal memory for zone module */ extern void zone_steal_memory(void); /* Bootstrap zone module (create zone zone) */ -extern void zone_bootstrap(void); +extern void zone_bootstrap(void) __attribute__((section("__TEXT, initcode"))); /* Init zone module */ -extern void zone_init(vm_size_t); +extern void zone_init( + vm_size_t map_size) __attribute__((section("__TEXT, initcode"))); -#endif /* MACH_KERNEL_PRIVATE */ +/* Stack use statistics */ +extern void stack_fake_zone_info( + int *count, + vm_size_t *cur_size, + vm_size_t *max_size, + vm_size_t *elem_size, + vm_size_t *alloc_size, + int *collectable, + int *exhaustable); -#endif /* __APPLE_API_PRIVATE */ +#if ZONE_DEBUG -/* Allocate from zone */ -extern vm_offset_t zalloc( - zone_t zone); +#if MACH_KDB -/* Non-blocking version of zalloc */ -extern vm_offset_t zalloc_noblock( - zone_t zone); +extern void * next_element( + zone_t z, + void *elt); -/* Get from zone free list */ -extern vm_offset_t zget( - zone_t zone); +extern void * first_element( + zone_t z); -/* Create zone */ -extern zone_t zinit( - vm_size_t size, /* the size of an element */ - vm_size_t max, /* maximum memory to use */ - vm_size_t alloc, /* allocation size */ - char *name); /* a name for the zone */ +#endif /* MACH_KDB */ + +extern void zone_debug_enable( + zone_t z); + +extern void zone_debug_disable( + zone_t z); + +#endif /* ZONE_DEBUG */ + +#endif /* MACH_KERNEL_PRIVATE */ + +__BEGIN_DECLS + +#ifdef XNU_KERNEL_PRIVATE + +/* Allocate from zone */ +extern void * zalloc( + zone_t zone); /* Free zone element */ extern void zfree( - zone_t zone, - vm_offset_t elem); + zone_t zone, + void *elem); + +/* Create zone */ +extern zone_t zinit( + vm_size_t size, /* the size of an element */ + vm_size_t maxmem, /* maximum memory to use */ + vm_size_t alloc, /* allocation size */ + const char *name); /* a name for the zone */ + + +/* Non-blocking version of zalloc */ +extern void * zalloc_noblock( + zone_t zone); + +/* direct (non-wrappered) interface */ +extern void * zalloc_canblock( + zone_t zone, + boolean_t canblock); + +/* Get from zone free list */ +extern void * zget( + zone_t zone); /* Fill zone with memory */ extern void zcram( - zone_t zone, - vm_offset_t newmem, - vm_size_t size); + zone_t zone, + void *newmem, + vm_size_t size); /* Initially fill zone with specified number of elements */ extern int zfill( - zone_t zone, - int nelem); + zone_t zone, + int nelem); + /* Change zone parameters */ extern void zone_change( - zone_t zone, - unsigned int item, - boolean_t value); - -/* Preallocate space for zone from zone map */ -extern void zprealloc( - zone_t zone, - vm_size_t size); - -/* - * zone_free_count returns a hint as to the current number of free elements - * in the zone. By the time it returns, it may no longer be true (a new - * element might have been added, or an element removed). - * This routine may be used in conjunction with zcram and a lock to regulate - * adding memory to a non-expandable zone. - */ -extern integer_t zone_free_count(zone_t zone); + zone_t zone, + unsigned int item, + boolean_t value); -/* - * Item definitions for zone_change: - */ +/* Item definitions */ #define Z_EXHAUST 1 /* Make zone exhaustible */ #define Z_COLLECT 2 /* Make zone collectable */ #define Z_EXPAND 3 /* Make zone expandable */ -#define Z_FOREIGN 4 /* Allow collectable zone to contain foreign */ - /* (not allocated via zalloc) elements. */ - -#ifdef __APPLE_API_PRIVATE - -#ifdef MACH_KERNEL_PRIVATE - -#if ZONE_DEBUG +#define Z_FOREIGN 4 /* Allow collectable zone to contain foreign elements */ -#if MACH_KDB - -extern vm_offset_t next_element( - zone_t z, - vm_offset_t elt); - -extern vm_offset_t first_element( - zone_t z); - -#endif /* MACH_KDB */ - -extern void zone_debug_enable( - zone_t z); - -extern void zone_debug_disable( - zone_t z); +/* Preallocate space for zone from zone map */ +extern void zprealloc( + zone_t zone, + vm_size_t size); -#endif /* ZONE_DEBUG */ +extern integer_t zone_free_count( + zone_t zone); -#endif MACH_KERNEL_PRIVATE +#endif /* XNU_KERNEL_PRIVATE */ -#endif /* __APPLE_API_PRIVATE */ +__END_DECLS #endif /* _KERN_ZALLOC_H_ */ + +#endif /* KERNEL_PRIVATE */