libk  Artifact [0011a847e1]

Artifact 0011a847e179dc1a00f0aa60bb07305b41c8039eb5691a98d6e81deeba67762d:


/* 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/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;
}