libk  Artifact [d8d36f64f5]

Artifact d8d36f64f59fceb8977af3cbb862f0975cbea0168cada9c318483e509620dbbf:

  • File mod/kmem/mem.h — part of check-in [e50a476efe] at 2019-08-22 02:52:20 on branch trunk — removed sneaky segfault in x86-64 syscall fn where %r8 (the register that contains the pointer to the syscall arguments from the C syscall wrapper, which need to be copied into the correct registers before the kernel is invoked) gets overwritten if the syscall valency > 5, because of overlapping ccall and syscall ABI argument registers - r8 is clobbered by argument 5 and any further attempts to use it as a ptr segfault at best. also modified the report function so that it immediate cancels compilation if a sub-process reports failure. changed allocator function signatures so they can return a condition code if the kernel reports an error; updated example code so it compiles and runs without fault. (user: lexi, size: 1288) [annotate] [blame] [check-ins using]

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

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

#ifdef __cplusplus
extern "C" {
#endif

typedef enum kmcond {
	kmcond_ok = kmcond_id,
	kmcond_unnecessary,

	kmcond_fail,
	kmcond_unhandled,
	kmcond_mismatch,
	kmcond_bad_address,
	kmcond_bad_lock,
	kmcond_bad_size,
	kmcond_no_room,
	kmcond_too_many,

	/* when something truly should
	 * never happen: */
	kmcond_fail_assert,
} 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 */

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

/* generic functions */

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


#ifdef __cplusplus
}
#endif

#endif