See uma.h */
| 3060 | |
| 3061 | /* See uma.h */ |
| 3062 | uma_zone_t |
| 3063 | uma_zcreate(const char *name, size_t size, uma_ctor ctor, uma_dtor dtor, |
| 3064 | uma_init uminit, uma_fini fini, int align, uint32_t flags) |
| 3065 | |
| 3066 | { |
| 3067 | struct uma_zctor_args args; |
| 3068 | uma_zone_t res; |
| 3069 | |
| 3070 | KASSERT(powerof2(align + 1), ("invalid zone alignment %d for \"%s\"", |
| 3071 | align, name)); |
| 3072 | |
| 3073 | /* This stuff is essential for the zone ctor */ |
| 3074 | memset(&args, 0, sizeof(args)); |
| 3075 | args.name = name; |
| 3076 | args.size = size; |
| 3077 | args.ctor = ctor; |
| 3078 | args.dtor = dtor; |
| 3079 | args.uminit = uminit; |
| 3080 | args.fini = fini; |
| 3081 | #ifdef INVARIANTS |
| 3082 | /* |
| 3083 | * Inject procedures which check for memory use after free if we are |
| 3084 | * allowed to scramble the memory while it is not allocated. This |
| 3085 | * requires that: UMA is actually able to access the memory, no init |
| 3086 | * or fini procedures, no dependency on the initial value of the |
| 3087 | * memory, and no (legitimate) use of the memory after free. Note, |
| 3088 | * the ctor and dtor do not need to be empty. |
| 3089 | */ |
| 3090 | if ((!(flags & (UMA_ZONE_ZINIT | UMA_ZONE_NOTOUCH | |
| 3091 | UMA_ZONE_NOFREE))) && uminit == NULL && fini == NULL) { |
| 3092 | args.uminit = trash_init; |
| 3093 | args.fini = trash_fini; |
| 3094 | } |
| 3095 | #endif |
| 3096 | args.align = align; |
| 3097 | args.flags = flags; |
| 3098 | args.keg = NULL; |
| 3099 | |
| 3100 | sx_slock(&uma_reclaim_lock); |
| 3101 | res = zone_alloc_item(zones, &args, UMA_ANYDOMAIN, M_WAITOK); |
| 3102 | sx_sunlock(&uma_reclaim_lock); |
| 3103 | |
| 3104 | return (res); |
| 3105 | } |
| 3106 | |
| 3107 | /* See uma.h */ |
| 3108 | uma_zone_t |
no test coverage detected