KS_STATUS_PAGE_SIZE, /* could not get system page-size */
KS_STATUS_OPEN_ZERO, /* could not open /dev/zero */
KS_STATUS_NO_MEM, /* no memory available */
- KS_STATUS_MMAP, /* problems with mmap */
KS_STATUS_SIZE, /* error processing requested size */
KS_STATUS_TOO_BIG, /* allocation exceeded max size */
KS_STATUS_MEM, /* invalid memory address */
"GENERR",\
"INACTIVE",\
"TIMEOUT",\
+ "DUPLICATE_OPERATION",\
"ARG_NULL",\
"ARG_INVALID",\
"PNT",\
"PAGE_SIZE",\
"OPEN_ZERO",\
"NO_MEM",\
- "MMAP",\
"SIZE",\
"TOO_BIG",\
"MEM",\
* library which was close to what we needed but did not exactly do
* what I wanted.
*
- * The following uses mmap from /dev/zero. It allows a number of
- * allocations to be made inside of a memory pool then with a clear or
- * close the pool can be reset without any memory fragmentation and
- * growth problems.
*/
#include "ks.h"
-#include <sys/mman.h>
#define KS_POOL_MAGIC 0xABACABA /* magic for struct */
#define BLOCK_MAGIC 0xB1B1007 /* magic for blocks */
unsigned int mp_page_size; /* page-size of our system */
off_t mp_top; /* top of our allocations in fd */
ks_pool_log_func_t mp_log_func; /* log callback function */
- void *mp_addr; /* current address for mmaping */
void *mp_min_p; /* min address in pool for checks */
void *mp_bounds_p; /* max address in pool for checks */
struct ks_pool_block_st *mp_first_p; /* first memory block we are using */
{
void *mem;
unsigned long size;
- int state;
/* are we over our max-pages? */
if (mp_p->mp_max_pages > 0 && mp_p->mp_page_c >= mp_p->mp_max_pages) {
#endif
- state = MAP_PRIVATE | MAP_ANON;
-
-#if defined(MAP_FILE)
- state |= MAP_FILE;
-#endif
-
-#if defined(MAP_VARIABLE)
- state |= MAP_VARIABLE;
-#endif
-
- /* mmap from /dev/zero */
- mem = mmap(mp_p->mp_addr, size, PROT_READ | PROT_WRITE, state, -1, mp_p->mp_top);
-
- if (mem == (void *) MAP_FAILED) {
- if (errno == ENOMEM) {
- SET_POINTER(error_p, KS_STATUS_NO_MEM);
- } else {
- SET_POINTER(error_p, KS_STATUS_MMAP);
- }
- return NULL;
- }
+ mem = malloc(size);
+ ks_assert(mem);
mp_p->mp_top += size;
-
- if (mp_p->mp_addr != NULL) {
- mp_p->mp_addr = (char *) mp_p->mp_addr + size;
- }
-
mp_p->mp_page_c += page_n;
SET_POINTER(error_p, KS_STATUS_SUCCESS);
*
* size -> Size of the block that we are freeing.
*
- * sbrk_b -> Set to one if the pages were allocated with sbrk else mmap.
*/
static int free_pages(void *pages, const unsigned long size)
{
- (void) munmap(pages, size);
+ free(pages);
return KS_STATUS_SUCCESS;
}
/* mp.mp_page_size set below */
/* mp.mp_blocks_bit_n set below */
/* mp.mp_top set below */
- /* mp.mp_addr set below */
mp.mp_log_func = NULL;
mp.mp_min_p = NULL;
mp.mp_bounds_p = NULL;
}
}
- mp.mp_addr = start_addr;
/* we start at the front of the file */
mp.mp_top = 0;
{
ks_pool_block_t *block_p, *next_p;
void *addr;
- unsigned long size;
+ //unsigned long size;
int ret, final = KS_STATUS_SUCCESS;
/* special case, just return no-error */
} else {
addr = mp_p;
}
- size = SIZE_OF_PAGES(mp_p, PAGES_IN_SIZE(mp_p, sizeof(ks_pool_t)));
+
+ //size = SIZE_OF_PAGES(mp_p, PAGES_IN_SIZE(mp_p, sizeof(ks_pool_t)));
- (void) munmap(addr, size);
+ free(addr);
ks_mutex_unlock(mutex);
ks_mutex_destroy(&mutex);
case KS_STATUS_NO_MEM:
return "no memory available";
break;
- case KS_STATUS_MMAP:
- return "problems with mmap";
- break;
case KS_STATUS_SIZE:
return "error processing requested size";
break;