libk  free.fn.c at [b590aba21d]

File kmem/free.fn.c artifact cc32756862 part of check-in b590aba21d


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

/* free.fn.c - kmfree() "arbitrary free"
 * ~ lexi hale <lexi@hale.su>
 * kmfree() frees memory allocated in any manner.
 * it ignores non-dynamically allocated memory,
 * returning kmcond_unnecessary. to check for
 * success, compare result < kmcond_fail.
 */

kmcond kmfree(kmptr ptr) {
	if (ptr.kind <= kmkind_fail) return kmcond_unnecessary;
	switch (ptr.kind) {
		case kmkind_heap: return kmheapf(ptr.ref);
	}

	return kmcond_unhandled;
}