libk  mem.h at [c7732c41c9]

File kmem/mem.h artifact bec7e80543 part of check-in c7732c41c9


#ifndef KImem
#define KImem
#include <k/type.h>

#ifndef KFclean
#	define Kmsz(e) ( sizeof (e) / sizeof (e) [0] )
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef enum kmcond {
	kmcond_ok,
	kmcond_unnecessary,

	kmcond_fail,
	kmcond_unhandled,
	kmcond_mismatch,
	kmcond_bad_address,
} kmcond;

typedef enum kmkind {
	kmkind_none,
	kmkind_fail,
	kmkind_linear,
	kmkind_heap,
	kmkind_pool,
	kmkind_ref,
	kmkind_tree
} kmkind;

typedef enum kmshred {
	kmshred_yes,
	kmshred_no
} kmshred;

typedef struct kmbox {
	kmkind kind;
	sz size;
	kmshred shred;
} kmbox;

typedef struct kmcell {
	kmbox header;
	sz refs;
	struct kmcell* src;
} kmcell;

typedef struct kmnode {
	kmbox header;
	struct kmnode* origin,
		         * branch,
				 * next,
				 * prev;
} kmnode;

typedef struct kmptr {
	kmkind kind;
	kmshred shred;
	void* ref;
} kmptr;

/* heap functions */

void*  kmheapa(sz);
kmptr  kmheapao(sz);
kmcond kmheapf(void*);

/* generic functions */

kmcond kmfree(kmptr);
kmkind kmtell(void*);
void kmzero(void*,sz);
void kmozero(kmptr);


#ifdef __cplusplus
}
#endif

#endif