blob: bad0bcb2a614d1838eb137d7a21934d7b85262c5 [file] [log] [blame]
Jens Axboed24c33a2008-03-01 18:27:36 +01001/*
2 * simple memory allocator, backed by mmap() so that it hands out memory
3 * that can be shared across processes and threads
4 */
5#include <sys/mman.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <assert.h>
9#include <string.h>
10#include <unistd.h>
11#include <sys/types.h>
12#include <limits.h>
13
14#include "mutex.h"
15
Jens Axboe1f37f632008-05-27 11:40:37 +020016#define MP_SAFE /* define to make thread safe */
Jens Axboe55f64912008-05-26 09:37:21 +020017#define SMALLOC_REDZONE /* define to detect memory corruption */
Jens Axboed24c33a2008-03-01 18:27:36 +010018
Jens Axboeec996e92008-05-27 11:39:39 +020019#define SMALLOC_BPB 32 /* block size, bytes-per-bit in bitmap */
20#define SMALLOC_BPI (sizeof(unsigned int) * 8)
21#define SMALLOC_BPL (SMALLOC_BPB * SMALLOC_BPI)
22
23#define INITIAL_SIZE 1024*1024 /* new pool size */
Jens Axboec5dda9e2008-05-23 10:10:54 +020024#define MAX_POOLS 4 /* maximum number of pools to setup */
Jens Axboed24c33a2008-03-01 18:27:36 +010025
Jens Axboe55f64912008-05-26 09:37:21 +020026#define SMALLOC_PRE_RED 0xdeadbeefU
27#define SMALLOC_POST_RED 0x5aa55aa5U
Jens Axboe55f64912008-05-26 09:37:21 +020028
Jens Axboe2b386d22008-03-26 10:32:57 +010029unsigned int smalloc_pool_size = INITIAL_SIZE;
30
Jens Axboed24c33a2008-03-01 18:27:36 +010031struct pool {
32 struct fio_mutex *lock; /* protects this pool */
33 void *map; /* map of blocks */
Jens Axboeec996e92008-05-27 11:39:39 +020034 unsigned int *bitmap; /* blocks free/busy map */
35 unsigned int free_blocks; /* free blocks */
36 unsigned int nr_blocks; /* total blocks */
37 unsigned int next_non_full;
Jens Axboed24c33a2008-03-01 18:27:36 +010038 int fd; /* memory backing fd */
39 char file[PATH_MAX]; /* filename for fd */
Jens Axboeec996e92008-05-27 11:39:39 +020040 unsigned int mmap_size;
41};
42
43struct block_hdr {
44 unsigned int size;
45#ifdef SMALLOC_REDZONE
46 unsigned int prered;
47#endif
Jens Axboed24c33a2008-03-01 18:27:36 +010048};
49
50static struct pool mp[MAX_POOLS];
51static unsigned int nr_pools;
52static unsigned int last_pool;
53static struct fio_mutex *lock;
54
Jens Axboed24c33a2008-03-01 18:27:36 +010055static inline void pool_lock(struct pool *pool)
56{
57 if (pool->lock)
58 fio_mutex_down(pool->lock);
59}
60
61static inline void pool_unlock(struct pool *pool)
62{
63 if (pool->lock)
64 fio_mutex_up(pool->lock);
65}
66
Jens Axboe65864cf2008-03-03 10:36:36 +010067static inline void global_read_lock(void)
Jens Axboed24c33a2008-03-01 18:27:36 +010068{
69 if (lock)
Jens Axboe65864cf2008-03-03 10:36:36 +010070 fio_mutex_down_read(lock);
Jens Axboed24c33a2008-03-01 18:27:36 +010071}
72
Jens Axboe65864cf2008-03-03 10:36:36 +010073static inline void global_read_unlock(void)
Jens Axboed24c33a2008-03-01 18:27:36 +010074{
75 if (lock)
Jens Axboe65864cf2008-03-03 10:36:36 +010076 fio_mutex_up_read(lock);
77}
78
79static inline void global_write_lock(void)
80{
81 if (lock)
82 fio_mutex_down_write(lock);
83}
84
85static inline void global_write_unlock(void)
86{
87 if (lock)
88 fio_mutex_up_write(lock);
Jens Axboed24c33a2008-03-01 18:27:36 +010089}
90
Jens Axboed24c33a2008-03-01 18:27:36 +010091static inline int ptr_valid(struct pool *pool, void *ptr)
92{
Jens Axboedcb69092008-05-27 20:35:18 +020093 unsigned int pool_size = pool->nr_blocks * SMALLOC_BPL;
Jens Axboeec996e92008-05-27 11:39:39 +020094
95 return (ptr >= pool->map) && (ptr < pool->map + pool_size);
Jens Axboed24c33a2008-03-01 18:27:36 +010096}
97
Jens Axboe808e9ea2008-05-27 14:12:45 +020098static inline unsigned int size_to_blocks(unsigned int size)
99{
100 return (size + SMALLOC_BPB - 1) / SMALLOC_BPB;
101}
102
Jens Axboedcb69092008-05-27 20:35:18 +0200103static int blocks_iter(struct pool *pool, unsigned int pool_idx,
104 unsigned int idx, unsigned int nr_blocks,
Jens Axboeec996e92008-05-27 11:39:39 +0200105 int (*func)(unsigned int *map, unsigned int mask))
Jens Axboed24c33a2008-03-01 18:27:36 +0100106{
Jens Axboedcb69092008-05-27 20:35:18 +0200107
Jens Axboeec996e92008-05-27 11:39:39 +0200108 while (nr_blocks) {
109 unsigned int this_blocks, mask;
Jens Axboedcb69092008-05-27 20:35:18 +0200110 unsigned int *map;
111
112 if (pool_idx >= pool->nr_blocks)
113 return 0;
114
115 map = &pool->bitmap[pool_idx];
Jens Axboed24c33a2008-03-01 18:27:36 +0100116
Jens Axboeec996e92008-05-27 11:39:39 +0200117 this_blocks = nr_blocks;
118 if (this_blocks + idx > SMALLOC_BPI) {
119 this_blocks = SMALLOC_BPI - idx;
120 idx = SMALLOC_BPI - this_blocks;
Jens Axboed24c33a2008-03-01 18:27:36 +0100121 }
Jens Axboeec996e92008-05-27 11:39:39 +0200122
123 if (this_blocks == SMALLOC_BPI)
124 mask = -1U;
125 else
126 mask = ((1U << this_blocks) - 1) << idx;
127
128 if (!func(map, mask))
129 return 0;
130
131 nr_blocks -= this_blocks;
132 idx = 0;
Jens Axboedcb69092008-05-27 20:35:18 +0200133 pool_idx++;
Jens Axboed24c33a2008-03-01 18:27:36 +0100134 }
135
Jens Axboeec996e92008-05-27 11:39:39 +0200136 return 1;
Jens Axboeec996e92008-05-27 11:39:39 +0200137}
138
139static int mask_cmp(unsigned int *map, unsigned int mask)
140{
141 return !(*map & mask);
142}
143
144static int mask_clear(unsigned int *map, unsigned int mask)
145{
Jens Axboedcb69092008-05-27 20:35:18 +0200146 assert((*map & mask) == mask);
Jens Axboeec996e92008-05-27 11:39:39 +0200147 *map &= ~mask;
148 return 1;
149}
150
151static int mask_set(unsigned int *map, unsigned int mask)
152{
Jens Axboedcb69092008-05-27 20:35:18 +0200153 assert(!(*map & mask));
Jens Axboeec996e92008-05-27 11:39:39 +0200154 *map |= mask;
155 return 1;
156}
157
Jens Axboedcb69092008-05-27 20:35:18 +0200158static int blocks_free(struct pool *pool, unsigned int pool_idx,
159 unsigned int idx, unsigned int nr_blocks)
Jens Axboeec996e92008-05-27 11:39:39 +0200160{
Jens Axboedcb69092008-05-27 20:35:18 +0200161 return blocks_iter(pool, pool_idx, idx, nr_blocks, mask_cmp);
Jens Axboeec996e92008-05-27 11:39:39 +0200162}
163
Jens Axboedcb69092008-05-27 20:35:18 +0200164static void set_blocks(struct pool *pool, unsigned int pool_idx,
165 unsigned int idx, unsigned int nr_blocks)
Jens Axboeec996e92008-05-27 11:39:39 +0200166{
Jens Axboedcb69092008-05-27 20:35:18 +0200167 blocks_iter(pool, pool_idx, idx, nr_blocks, mask_set);
Jens Axboeec996e92008-05-27 11:39:39 +0200168}
169
Jens Axboedcb69092008-05-27 20:35:18 +0200170static void clear_blocks(struct pool *pool, unsigned int pool_idx,
171 unsigned int idx, unsigned int nr_blocks)
Jens Axboeec996e92008-05-27 11:39:39 +0200172{
Jens Axboedcb69092008-05-27 20:35:18 +0200173 blocks_iter(pool, pool_idx, idx, nr_blocks, mask_clear);
Jens Axboeec996e92008-05-27 11:39:39 +0200174}
175
176static inline int __ffs(int word)
177{
178 int r = 0;
179
180 if (!(word & 0xffff)) {
181 word >>= 16;
182 r += 16;
183 }
184 if (!(word & 0xff)) {
185 word >>= 8;
186 r += 8;
187 }
188 if (!(word & 0xf)) {
189 word >>= 4;
190 r += 4;
191 }
192 if (!(word & 3)) {
193 word >>= 2;
194 r += 2;
195 }
196 if (!(word & 1)) {
197 word >>= 1;
198 r += 1;
199 }
200
201 return r;
202}
203
204static int find_next_zero(int word, int start)
205{
206 assert(word != -1U);
207 word >>= (start + 1);
208 return __ffs(~word) + start + 1;
Jens Axboed24c33a2008-03-01 18:27:36 +0100209}
210
Jens Axboeadf57092008-04-16 19:43:17 +0200211static int add_pool(struct pool *pool, unsigned int alloc_size)
Jens Axboed24c33a2008-03-01 18:27:36 +0100212{
Jens Axboed24c33a2008-03-01 18:27:36 +0100213 void *ptr;
Jens Axboeec996e92008-05-27 11:39:39 +0200214 int fd, bitmap_blocks;
215
Jens Axboed24c33a2008-03-01 18:27:36 +0100216 strcpy(pool->file, "/tmp/.fio_smalloc.XXXXXX");
217 fd = mkstemp(pool->file);
218 if (fd < 0)
219 goto out_close;
220
Jens Axboe55f64912008-05-26 09:37:21 +0200221#ifdef SMALLOC_REDZONE
Jens Axboeec996e92008-05-27 11:39:39 +0200222 alloc_size += sizeof(unsigned int);
Jens Axboe55f64912008-05-26 09:37:21 +0200223#endif
Jens Axboeec996e92008-05-27 11:39:39 +0200224 alloc_size += sizeof(struct block_hdr);
225 if (alloc_size < INITIAL_SIZE)
226 alloc_size = INITIAL_SIZE;
Jens Axboeadf57092008-04-16 19:43:17 +0200227
Jens Axboeec996e92008-05-27 11:39:39 +0200228 /* round up to nearest full number of blocks */
229 alloc_size = (alloc_size + SMALLOC_BPL - 1) & ~(SMALLOC_BPL - 1);
230 bitmap_blocks = alloc_size / SMALLOC_BPL;
231 alloc_size += bitmap_blocks * sizeof(unsigned int);
232 pool->mmap_size = alloc_size;
233
234 pool->nr_blocks = bitmap_blocks;
235 pool->free_blocks = bitmap_blocks * SMALLOC_BPB;
236
237 if (ftruncate(fd, alloc_size) < 0)
Jens Axboed24c33a2008-03-01 18:27:36 +0100238 goto out_unlink;
239
Jens Axboeec996e92008-05-27 11:39:39 +0200240 ptr = mmap(NULL, alloc_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
Jens Axboed24c33a2008-03-01 18:27:36 +0100241 if (ptr == MAP_FAILED)
242 goto out_unlink;
243
Jens Axboeec996e92008-05-27 11:39:39 +0200244 memset(ptr, 0, alloc_size);
245 pool->map = ptr;
246 pool->bitmap = (void *) ptr + (pool->nr_blocks * SMALLOC_BPL);
Jens Axboed24c33a2008-03-01 18:27:36 +0100247
248#ifdef MP_SAFE
249 pool->lock = fio_mutex_init(1);
250 if (!pool->lock)
251 goto out_unlink;
252#endif
253
254 pool->fd = fd;
255
Jens Axboe65864cf2008-03-03 10:36:36 +0100256 global_write_lock();
Jens Axboed24c33a2008-03-01 18:27:36 +0100257 nr_pools++;
Jens Axboe65864cf2008-03-03 10:36:36 +0100258 global_write_unlock();
Jens Axboed24c33a2008-03-01 18:27:36 +0100259 return 0;
260out_unlink:
Jens Axboeec996e92008-05-27 11:39:39 +0200261 fprintf(stderr, "smalloc: failed adding pool\n");
Jens Axboed24c33a2008-03-01 18:27:36 +0100262 if (pool->map)
Jens Axboeec996e92008-05-27 11:39:39 +0200263 munmap(pool->map, pool->mmap_size);
Jens Axboed24c33a2008-03-01 18:27:36 +0100264 unlink(pool->file);
265out_close:
266 if (fd >= 0)
267 close(fd);
268 return 1;
269}
270
271void sinit(void)
272{
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100273 int ret;
Jens Axboed24c33a2008-03-01 18:27:36 +0100274
275#ifdef MP_SAFE
Jens Axboe9c5b5292008-03-03 11:08:19 +0100276 lock = fio_mutex_rw_init();
Jens Axboed24c33a2008-03-01 18:27:36 +0100277#endif
Jens Axboeadf57092008-04-16 19:43:17 +0200278 ret = add_pool(&mp[0], INITIAL_SIZE);
Jens Axboed24c33a2008-03-01 18:27:36 +0100279 assert(!ret);
280}
281
282static void cleanup_pool(struct pool *pool)
283{
284 unlink(pool->file);
285 close(pool->fd);
Jens Axboeec996e92008-05-27 11:39:39 +0200286 munmap(pool->map, pool->mmap_size);
Jens Axboed24c33a2008-03-01 18:27:36 +0100287
288 if (pool->lock)
289 fio_mutex_remove(pool->lock);
290}
291
292void scleanup(void)
293{
294 unsigned int i;
295
296 for (i = 0; i < nr_pools; i++)
297 cleanup_pool(&mp[i]);
298
299 if (lock)
300 fio_mutex_remove(lock);
301}
302
Jens Axboeec996e92008-05-27 11:39:39 +0200303static void fill_redzone(struct block_hdr *hdr)
Jens Axboe55f64912008-05-26 09:37:21 +0200304{
305#ifdef SMALLOC_REDZONE
Jens Axboeec996e92008-05-27 11:39:39 +0200306 unsigned int *postred = (void *) hdr + hdr->size - sizeof(unsigned int);
Jens Axboe55f64912008-05-26 09:37:21 +0200307
Jens Axboeec996e92008-05-27 11:39:39 +0200308 hdr->prered = SMALLOC_PRE_RED;
309 *postred = SMALLOC_POST_RED;
310#endif
311}
Jens Axboe55f64912008-05-26 09:37:21 +0200312
Jens Axboeec996e92008-05-27 11:39:39 +0200313static void sfree_check_redzone(struct block_hdr *hdr)
314{
315#ifdef SMALLOC_REDZONE
316 unsigned int *postred = (void *) hdr + hdr->size - sizeof(unsigned int);
317
318 if (hdr->prered != SMALLOC_PRE_RED) {
Jens Axboe55f64912008-05-26 09:37:21 +0200319 fprintf(stderr, "smalloc pre redzone destroyed!\n");
320 fprintf(stderr, " ptr=%p, prered=%x, expected %x\n",
Jens Axboeec996e92008-05-27 11:39:39 +0200321 hdr, hdr->prered, SMALLOC_PRE_RED);
Jens Axboe55f64912008-05-26 09:37:21 +0200322 assert(0);
323 }
324 if (*postred != SMALLOC_POST_RED) {
325 fprintf(stderr, "smalloc post redzone destroyed!\n");
326 fprintf(stderr, " ptr=%p, postred=%x, expected %x\n",
Jens Axboeec996e92008-05-27 11:39:39 +0200327 hdr, *postred, SMALLOC_POST_RED);
Jens Axboe55f64912008-05-26 09:37:21 +0200328 assert(0);
329 }
330#endif
331}
332
Jens Axboed24c33a2008-03-01 18:27:36 +0100333static void sfree_pool(struct pool *pool, void *ptr)
334{
Jens Axboeec996e92008-05-27 11:39:39 +0200335 struct block_hdr *hdr;
Jens Axboe179446e2008-05-27 14:11:56 +0200336 unsigned int i, idx;
Jens Axboeec996e92008-05-27 11:39:39 +0200337 unsigned long offset;
Jens Axboed24c33a2008-03-01 18:27:36 +0100338
339 if (!ptr)
340 return;
341
Jens Axboeec996e92008-05-27 11:39:39 +0200342 ptr -= sizeof(*hdr);
343 hdr = ptr;
Jens Axboe55f64912008-05-26 09:37:21 +0200344
Jens Axboed24c33a2008-03-01 18:27:36 +0100345 assert(ptr_valid(pool, ptr));
346
Jens Axboeec996e92008-05-27 11:39:39 +0200347 sfree_check_redzone(hdr);
348
349 offset = ptr - pool->map;
350 i = offset / SMALLOC_BPL;
351 idx = (offset % SMALLOC_BPL) / SMALLOC_BPB;
352
Jens Axboed24c33a2008-03-01 18:27:36 +0100353 pool_lock(pool);
Jens Axboedcb69092008-05-27 20:35:18 +0200354 clear_blocks(pool, i, idx, size_to_blocks(hdr->size));
Jens Axboeec996e92008-05-27 11:39:39 +0200355 if (i < pool->next_non_full)
356 pool->next_non_full = i;
Jens Axboe179446e2008-05-27 14:11:56 +0200357 pool->free_blocks += size_to_blocks(hdr->size);
Jens Axboed24c33a2008-03-01 18:27:36 +0100358 pool_unlock(pool);
359}
360
361void sfree(void *ptr)
362{
363 struct pool *pool = NULL;
364 unsigned int i;
365
Jens Axboe8e5732e2008-04-16 19:51:46 +0200366 if (!ptr)
367 return;
368
Jens Axboe65864cf2008-03-03 10:36:36 +0100369 global_read_lock();
Jens Axboed24c33a2008-03-01 18:27:36 +0100370
371 for (i = 0; i < nr_pools; i++) {
372 if (ptr_valid(&mp[i], ptr)) {
373 pool = &mp[i];
374 break;
375 }
376 }
377
Jens Axboe65864cf2008-03-03 10:36:36 +0100378 global_read_unlock();
Jens Axboed24c33a2008-03-01 18:27:36 +0100379
380 assert(pool);
381 sfree_pool(pool, ptr);
382}
383
Jens Axboe55f64912008-05-26 09:37:21 +0200384static void *__smalloc_pool(struct pool *pool, unsigned int size)
Jens Axboed24c33a2008-03-01 18:27:36 +0100385{
Jens Axboeec996e92008-05-27 11:39:39 +0200386 unsigned int nr_blocks;
387 unsigned int i;
388 unsigned int offset;
389 unsigned int last_idx;
390 void *ret = NULL;
Jens Axboed24c33a2008-03-01 18:27:36 +0100391
Jens Axboed24c33a2008-03-01 18:27:36 +0100392 pool_lock(pool);
Jens Axboe179446e2008-05-27 14:11:56 +0200393
394 nr_blocks = size_to_blocks(size);
Jens Axboeec996e92008-05-27 11:39:39 +0200395 if (nr_blocks > pool->free_blocks)
Jens Axboed24c33a2008-03-01 18:27:36 +0100396 goto fail;
397
Jens Axboeec996e92008-05-27 11:39:39 +0200398 i = pool->next_non_full;
399 last_idx = 0;
400 offset = -1U;
401 while (i < pool->nr_blocks) {
402 unsigned int idx;
Jens Axboed24c33a2008-03-01 18:27:36 +0100403
Jens Axboeec996e92008-05-27 11:39:39 +0200404 if (pool->bitmap[i] == -1U) {
405 i++;
406 pool->next_non_full = i;
407 last_idx = 0;
408 continue;
Jens Axboed24c33a2008-03-01 18:27:36 +0100409 }
Jens Axboeec996e92008-05-27 11:39:39 +0200410
411 idx = find_next_zero(pool->bitmap[i], last_idx);
Jens Axboedcb69092008-05-27 20:35:18 +0200412 if (!blocks_free(pool, i, idx, nr_blocks)) {
Jens Axboeec996e92008-05-27 11:39:39 +0200413 idx += nr_blocks;
414 if (idx < SMALLOC_BPI)
415 last_idx = idx;
416 else {
417 last_idx = 0;
418 while (idx >= SMALLOC_BPI) {
419 i++;
420 idx -= SMALLOC_BPI;
421 }
422 }
423 continue;
424 }
Jens Axboedcb69092008-05-27 20:35:18 +0200425 set_blocks(pool, i, idx, nr_blocks);
Jens Axboeec996e92008-05-27 11:39:39 +0200426 offset = i * SMALLOC_BPL + idx * SMALLOC_BPB;
427 break;
Jens Axboed24c33a2008-03-01 18:27:36 +0100428 }
Jens Axboeec996e92008-05-27 11:39:39 +0200429
430 if (i < pool->nr_blocks) {
431 pool->free_blocks -= nr_blocks;
432 ret = pool->map + offset;
433 }
434fail:
Jens Axboed24c33a2008-03-01 18:27:36 +0100435 pool_unlock(pool);
Jens Axboeec996e92008-05-27 11:39:39 +0200436 return ret;
Jens Axboed24c33a2008-03-01 18:27:36 +0100437}
438
Jens Axboe55f64912008-05-26 09:37:21 +0200439static void *smalloc_pool(struct pool *pool, unsigned int size)
440{
Jens Axboeec996e92008-05-27 11:39:39 +0200441 struct block_hdr *hdr;
442 unsigned int alloc_size;
Jens Axboe55f64912008-05-26 09:37:21 +0200443 void *ptr;
444
Jens Axboeec996e92008-05-27 11:39:39 +0200445 alloc_size = size + sizeof(*hdr);
446#ifdef SMALLOC_REDZONE
447 alloc_size += sizeof(unsigned int);
Jens Axboe55f64912008-05-26 09:37:21 +0200448#endif
Jens Axboeec996e92008-05-27 11:39:39 +0200449
450 ptr = __smalloc_pool(pool, alloc_size);
Jens Axboe076b17c2008-05-27 14:13:26 +0200451 if (!ptr)
Jens Axboeec996e92008-05-27 11:39:39 +0200452 return NULL;
Jens Axboeec996e92008-05-27 11:39:39 +0200453
454 hdr = ptr;
455 hdr->size = alloc_size;
456 ptr += sizeof(*hdr);
457
458 fill_redzone(hdr);
459
460 memset(ptr, 0, size);
461 return ptr;
Jens Axboe55f64912008-05-26 09:37:21 +0200462}
463
Jens Axboed24c33a2008-03-01 18:27:36 +0100464void *smalloc(unsigned int size)
465{
466 unsigned int i;
467
Jens Axboe65864cf2008-03-03 10:36:36 +0100468 global_read_lock();
Jens Axboed24c33a2008-03-01 18:27:36 +0100469 i = last_pool;
470
471 do {
472 for (; i < nr_pools; i++) {
473 void *ptr = smalloc_pool(&mp[i], size);
474
475 if (ptr) {
476 last_pool = i;
Jens Axboe65864cf2008-03-03 10:36:36 +0100477 global_read_unlock();
Jens Axboed24c33a2008-03-01 18:27:36 +0100478 return ptr;
479 }
480 }
481 if (last_pool) {
482 last_pool = 0;
483 continue;
484 }
485
Jens Axboeec996e92008-05-27 11:39:39 +0200486 if (nr_pools + 1 > MAX_POOLS)
Jens Axboed24c33a2008-03-01 18:27:36 +0100487 break;
488 else {
489 i = nr_pools;
Jens Axboe65864cf2008-03-03 10:36:36 +0100490 global_read_unlock();
Jens Axboeadf57092008-04-16 19:43:17 +0200491 if (add_pool(&mp[nr_pools], size))
Jens Axboe65864cf2008-03-03 10:36:36 +0100492 goto out;
493 global_read_lock();
Jens Axboed24c33a2008-03-01 18:27:36 +0100494 }
495 } while (1);
496
Jens Axboe65864cf2008-03-03 10:36:36 +0100497 global_read_unlock();
498out:
Jens Axboed24c33a2008-03-01 18:27:36 +0100499 return NULL;
500}
501
502char *smalloc_strdup(const char *str)
503{
504 char *ptr;
505
506 ptr = smalloc(strlen(str) + 1);
507 strcpy(ptr, str);
508 return ptr;
509}