libk  lina.fn.c at [8618103a4e]

File mod/kmem/lina.fn.c artifact 0011a847e1 part of check-in 8618103a4e


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