libk  lini.fn.c at [12a51d9c50]

File mod/kmem/lini.fn.c artifact 537b55b516 part of check-in 12a51d9c50


/* lini.fn.c - kmlini() - initiate a linear segment
 * ~ lexi hale <lexi@hale.su>
 * this function is the initiator function for the
 * linear memory store. it simply returns the current
 * heap position by invoking the brk syscall with the
 * value `0`. (note that the brk syscall and the libc
 * wrapper have different behavior.) */

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

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

/* returns void* instead of kmres because kmlini has
 * no failure state */
void* kmlini(void) {
	k_platform_syscall_arg zero = 0;
	/* brk adjusts the heap break then returns the new
	 * break. by passing zero, we can get retrieve the
	 * current heap break. */
	struct k_platform_syscall_answer a = k_platform_syscall
		(k_platform_syscall_brk, 1, &zero);

	/* no point in checking for errors, since none can
	 * actually occur; just return the kernel's answer. */
	return (void*)a.ret;
}