INNER CODE UNIT · C

n_units

lh3/ksw2 · kalloc.c:138

	n_units = 1 + (n_bytes + sizeof(size_t) - 1) / sizeof(size_t);
	p = (size_t*)ap - 1;
	if (*p >= n_units) return ap; /* TODO: this prevents shrinking */
	q = (size_t*)kmalloc(km, n_bytes);
	memcpy(q, ap, (*p - 1) * sizeof(size_t));
	kfree(km, ap);
	return q;
}

void *kmalloc(void *_km, size_t n_bytes)
{
	kmem_t *km = (kmem_t*)_km;
	size_t n_units, *p, *q;

	if (n_bytes == 0) return 0;
	if (km == 0) return malloc(n_bytes);
	/* "n_units" means the number of units. The size of one unit equals to sizeof(kheader_t).
	 * "1" is the kheader_t of a block, which is always required. */

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…