Initial MCTP core code

Just a skeleton of the MCTP library at present.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/alloc.c b/alloc.c
new file mode 100644
index 0000000..2389dd3
--- /dev/null
+++ b/alloc.c
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+
+#include <assert.h>
+
+#include "libmctp-alloc.h"
+
+struct {
+	void	*(*alloc)(size_t);
+	void	(*free)(void *);
+	void	*(*realloc)(void *, size_t);
+} alloc_ops = {
+	malloc,
+	free,
+	realloc,
+};
+
+/* internal-only allocation functions */
+void *__mctp_alloc(size_t size)
+{
+	if (alloc_ops.alloc)
+		return alloc_ops.alloc(size);
+	if (alloc_ops.realloc)
+		return alloc_ops.realloc(NULL, size);
+	assert(0);
+}
+
+void __mctp_free(void *ptr)
+{
+	if (alloc_ops.free)
+		alloc_ops.free(ptr);
+	else if (alloc_ops.realloc)
+		alloc_ops.realloc(ptr, 0);
+	else
+		assert(0);
+}
+
+void *__mctp_realloc(void *ptr, size_t size)
+{
+	if (alloc_ops.realloc)
+		return alloc_ops.realloc(ptr, size);
+	assert(0);
+}
+
+void mctp_set_alloc_ops(void *(*alloc)(size_t),
+		void (*free)(void *),
+		void *(realloc)(void *, size_t))
+{
+	alloc_ops.alloc = alloc;
+	alloc_ops.free = free;
+	alloc_ops.realloc = realloc;
+}