libk  Artifact [5feb3edaf1]

Artifact 5feb3edaf1c8d441f0f1a1bf464e909ada55d12a689f2bb919106ad8d476166b:


/* lina.fn.c - kmlina() - linear allocate
 * ~ lexi hale <lexi@hale.su>
 * kmlina() allocates the requested amount of space on
 * the heap and returns a pointer to it. it allocates
 * this memory simply by growing the heap the proper
 * length. */

#include <k/mem.h>
#include <k/def.h>

#ifdef KFenv_posix
#	include <posix.h>
#endif

kmres kmlina(sz size) {
	k_platform_syscall_arg
		   top = (sz)kmlini(),
		newbrk = top + size;

	struct k_platform_syscall_answer a = k_platform_syscall
		(k_platform_syscall_brk, 1, &newbrk);

	kmres reply;

	if (a.error != 0) reply.cond = kmcond_no_room,
	                  reply.raw = 0;
		else reply.cond = kmcond_ok,
			 reply.raw = (void*)a.ret;

	return reply;
}