libk  heapo.fn.c at [c36308ecd9]

File mod/kmem/heapo.fn.c artifact 5d74e5db6e part of check-in c36308ecd9


#include <k/core.h>
#include <k/mem.h>
/* heapo.fn.c - kmheapo() "allocate heap object"
 * ~ lexi hale <lexi@hale.su>
 * kmheapo() allocates a region in heap memory
 * and returns a kmptr struct referencing that
 * newly allocated region.
 */

kmres kmheapo(sz size) {
	kmres e = kmheapa(size);
	kmres reply;

	if (e.cond != kmcond_ok) {
		reply.cond = e.cond;
		reply.ptr.ref = (void*)0;
		reply.ptr.kind = kmkind_broken;
		return reply;
	}

	kmptr p = {
		.kind = (e.raw != null ? kmkind_heap : kmkind_broken),
		.ref = e.raw,
		.shred = false,
	};

	reply.ptr = p;
	reply.cond = kmcond_ok;
	return reply;
}