61#define memnode_data(t,m) (t) (((memnode_t *) (m))+1)
67#define MEMNODE_SEAL 0xFAAFA123
161 for (
m = pool->
root;
m;
m =
m->next) {
167 printf(
"Memory list corrupted!\n");
182 m->next =
m->next->next;
189 }
while (compacted > 0);
210 if (((
unsigned char *) ptr < pool->
base) ||
213 printf(
"Pointer %08X does not belong to pool %08X\n",
ptr,pool);
223 printf(
"Invalid node freed: %08X\n",
m);
249 printf(
"PANIC: out of memory!\n");
283 if (ptralign <
sizeof(
void *)) ptralign =
sizeof(
uint64_t);
290 if (
size == 0)
size =
sizeof(
void *);
291 if (
size & (
sizeof(
void *)-1)) {
292 size +=
sizeof(
void *);
293 size &= ~(
sizeof(
void *)-1);
301 for (
m = pool->
root;
m;
m =
m->next) {
312 if (daddr & (ptralign-1)) {
313 extra =
size + (ptralign - (daddr & (ptralign-1)));
315 realsize =
size + extra;
317 if (
m->length < realsize)
continue;
335 if (daddr & (ptralign-1)) {
337 daddr &= ~(ptralign-1);
342 m->data = (
unsigned char *) daddr;
374 if (daddr & (
uintptr_t)(
sizeof(
void *)-1)) {
383 newm->
next =
m->next;
409 for (
m = pool->
root;
m;
m =
m->next) {
426 if (
m->next && ((daddr +
m->length) != (
uintptr_t)
m->next)) {
429 if (
m->next && (
m->next <
m)) {
432 if (
m->data < (
unsigned char *)
m) {
436 backptr = (
memnode_t **) (
m->data -
sizeof(
void *));
467 for (
m = pool->
root;
m;
m =
m->next) {
469 printf(
"%08X: Next=%08X Len=%5u %s Data=%08X ",
471 m->status ?
"alloc" :
"free ",
476 if (verbose) printf(
"BadSeal ");
479 if (
m->next && (daddr +
m->length != (
unsigned int)
m->next)) {
480 if (verbose) printf(
"BadLength ");
483 if (
m->next && (
m->next <
m)) {
484 if (verbose) printf(
"BadOrder ");
487 if (
m->data < (
unsigned char *)
m) {
488 if (verbose) printf(
"BadData ");
492 backptr = (
memnode_t **) (
m->data -
sizeof(
void *));
494 if (verbose) printf(
"BadBackPtr ");
498 if (verbose) printf(
"\n");
505#define MEMSIZE 1024*1024
507unsigned char *ptrs[4096];
508unsigned int sizes[4096];
523void main(
int argc,
char *argv[])
533 mem = malloc(MEMSIZE);
541 if (items == 4096)
break;
542 size = rand() % 1024;
544 if (!ptrs[items])
break;
550 printf(
"%d items allocated, %d total bytes\n",items,totalsize);
567 sizes[0] = sizes[idx];
575 nfree = rand() % items;
578 for (idx = nfree; idx < items; idx++) {
579 kfree(pool,ptrs[idx]);
580 totalsize -= sizes[idx];
604static unsigned char heap[1*1024*1024];
605static int kmem_init_done=0;
610 printf(
"Calling kmem_init() before usb_init() is deprecated.\n");
void lib_outofmemory(void)
void kfree(mempool_t *pool, void *ptr)
int kmempoolsize(mempool_t *pool)
int kmemstats(mempool_t *pool, memstats_t *stats)
#define memnode_data(t, m)
void * kmalloc(mempool_t *pool, unsigned int size, unsigned int align)
void * kmempoolbase(mempool_t *pool)
void kmeminit(mempool_t *pool, unsigned char *buffer, int length)
int kmemchk(mempool_t *pool, int verbose)
struct memnode_s memnode_t
int main(int argc, char *argv[])