4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Ricardo Correia. All rights reserved.
23 * Use is subject to license terms.
30 static umem_nofail_callback_t *nofail_cb = NULL;
33 umem_constructor_t *constructor;
34 umem_destructor_t *destructor;
40 * Simple stub for umem_alloc(). The callback isn't expected to return.
42 void *umem_alloc(size_t size, int flags)
44 assert(flags == UMEM_DEFAULT || flags == UMEM_NOFAIL);
49 void *ret = malloc(size);
51 if(!(flags & UMEM_NOFAIL))
63 * Simple stub for umem_zalloc().
65 void *umem_zalloc(size_t size, int flags)
67 assert(flags == UMEM_DEFAULT || flags == UMEM_NOFAIL);
72 void *ret = calloc(1, size);
74 if(!(flags & UMEM_NOFAIL))
86 * Simple stub for umem_free().
88 void umem_free(void *buf, size_t size)
94 * Simple stub for umem_nofail_callback().
96 void umem_nofail_callback(umem_nofail_callback_t *callback)
102 * Simple stub for umem_cache_create().
104 umem_cache_t *umem_cache_create(char *debug_name, size_t bufsize, size_t align, umem_constructor_t *constructor, umem_destructor_t *destructor, umem_reclaim_t *reclaim, void *callback_data, void *source, int cflags)
106 assert(source == NULL);
108 umem_cache_t *cache = malloc(sizeof(umem_cache_t));
112 cache->constructor = constructor;
113 cache->destructor = destructor;
114 cache->callback_data = callback_data;
115 cache->bufsize = bufsize;
121 * Simple stub for umem_cache_alloc(). The nofail callback isn't expected to return.
123 void *umem_cache_alloc(umem_cache_t *cache, int flags)
125 void *buf = malloc(cache->bufsize);
127 if(!(flags & UMEM_NOFAIL))
130 if(nofail_cb != NULL)
135 if(cache->constructor != NULL) {
136 if(cache->constructor(buf, cache->callback_data, flags) != 0) {
138 if(!(flags & UMEM_NOFAIL))
141 if(nofail_cb != NULL)
151 * Simple stub for umem_cache_free().
153 void umem_cache_free(umem_cache_t *cache, void *buffer)
155 if(cache->destructor != NULL)
156 cache->destructor(buffer, cache->callback_data);
162 * Simple stub for umem_cache_destroy().
164 void umem_cache_destroy(umem_cache_t *cache)