diff options
| author | Zheng Da <zhengda1936@gmail.com> | 2010-06-15 18:28:34 +0200 |
|---|---|---|
| committer | Zheng Da <zhengda1936@gmail.com> | 2010-06-15 18:28:34 +0200 |
| commit | 3e063ba1f5b518d6042e16b3779be8dcd769c199 (patch) | |
| tree | b0c418ec60b1296142368b25938c0469bc5e366a | |
| parent | e0c7d9e618426c0cf8764a6ff126af6ea638e0b1 (diff) | |
Revert "Use malloc/free by default in slab."
This reverts commit 198a98db43a1cce35242ea5cc12e1d9c5c57db40.
| -rw-r--r-- | libhurd-slab/slab.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libhurd-slab/slab.c b/libhurd-slab/slab.c index 58222704..b20a8e74 100644 --- a/libhurd-slab/slab.c +++ b/libhurd-slab/slab.c @@ -24,6 +24,7 @@ #include <stdlib.h> #include <errno.h> +#include <sys/mman.h> #include <assert.h> #include <string.h> #include <unistd.h> @@ -76,8 +77,9 @@ allocate_buffer (struct hurd_slab_space *space, size_t size, void **ptr) return space->allocate_buffer (space->hook, size, ptr); else { - *ptr = malloc (size); - if (*ptr == NULL) + *ptr = mmap (NULL, size, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); + if (*ptr == MAP_FAILED) return errno; else return 0; @@ -93,8 +95,10 @@ deallocate_buffer (struct hurd_slab_space *space, void *buffer, size_t size) return space->deallocate_buffer (space->hook, buffer, size); else { - free (buffer); - return 0; + if (munmap (buffer, size) == -1) + return errno; + else + return 0; } } |
