Exemple #1
0
static struct liballoc_major *allocate_new_page( unsigned int size )
{
	unsigned int st;
	struct liballoc_major *maj;

		// This is how much space is required.
		st  = size + sizeof(struct liballoc_major);
		st += sizeof(struct liballoc_minor);

				// Perfect amount of space?
		if ( (st % l_pageSize) == 0 )
			st  = st / (l_pageSize);
		else
			st  = st / (l_pageSize) + 1;
							// No, add the buffer.


		// Make sure it's >= the minimum size.
		if ( st < l_pageCount ) st = l_pageCount;

		maj = (struct liballoc_major*)liballoc_alloc( st );
		liballoc_memset(maj, 0, st*l_pageSize);
		if ( maj == NULL )
		{
			l_warningCount += 1;
			#if defined DEBUG || defined INFO
			serial_printf( "liballoc: WARNING: liballoc_alloc( %i ) return NULL\n", st );
			FLUSH();
			#endif
			return NULL;	// uh oh, we ran out of memory.
		}

		maj->prev 	= NULL;
		maj->next 	= NULL;
		maj->pages 	= st;
		maj->size 	= st * l_pageSize;
		maj->usage 	= sizeof(struct liballoc_major);
		maj->first 	= NULL;

		l_allocated += maj->size;

		#ifdef DEBUG
		serial_printf( "liballoc: Resource allocated %x of %i pages (%i bytes) for %i size.\n", maj, st, maj->size, size );
		serial_printf("PAGE SIZE %X\n", l_pageSize);

		//serial_printf( "liballoc: Total memory usage = %i KB\n",  (int)((l_allocated / (1024))) );
		FLUSH();
		#endif


      return maj;
}
Exemple #2
0
void* PREFIX(calloc)(size_t nobj, size_t size)
{
       int real_size;
       void *p;

       real_size = nobj * size;

       p = PREFIX(malloc)( real_size );

       liballoc_memset( p, 0, real_size );

       return p;
}
void* calloc(uint64_t nobj, uint64_t size)
{
       int real_size;
       void *p;

       real_size = nobj * size;

       p = malloc( real_size );

       liballoc_memset( p, 0, real_size );

       return p;
}