libk  free.fn.c at [6aeac330ce]

File mod/kmem/free.fn.c artifact bac849b7ff part of check-in 6aeac330ce


#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_broken) return kmcond_unnecessary;
	switch (ptr.kind) {
		case kmkind_heap: return kmheapf(ptr.ref);
	}

	return kmcond_unhandled;
}