svn commit: r366101 - head/sys/sys
Warner Losh
imp at FreeBSD.org
Thu Sep 24 06:40:36 UTC 2020
Author: imp
Date: Thu Sep 24 06:40:35 2020
New Revision: 366101
URL: https://svnweb.freebsd.org/changeset/base/366101
Log:
Create a standalone version of sys/malloc.h
The ZSTD support for the boot loader will need to include files that
use the kernel's malloc interface. Create a standalone stub version
that's functional enough to allow this to work. There's some
limitations in this interface, and it's not quite a perfect
match. Specifically, M_WAITOK allocations can fail because there's
nothing that can be done we no memory is available.
Modified:
head/sys/sys/malloc.h
Modified: head/sys/sys/malloc.h
==============================================================================
--- head/sys/sys/malloc.h Thu Sep 24 06:12:57 2020 (r366100)
+++ head/sys/sys/malloc.h Thu Sep 24 06:40:35 2020 (r366101)
@@ -37,6 +37,7 @@
#ifndef _SYS_MALLOC_H_
#define _SYS_MALLOC_H_
+#ifndef _STANDALONE
#include <sys/param.h>
#ifdef _KERNEL
#include <sys/systm.h>
@@ -267,4 +268,34 @@ WOULD_OVERFLOW(size_t nmemb, size_t size)
#undef MUL_NO_OVERFLOW
#endif /* _KERNEL */
+#else
+/*
+ * The native stand malloc / free interface we're mapping to
+ */
+extern void Free(void *p, const char *file, int line);
+extern void *Malloc(size_t bytes, const char *file, int line);
+
+/*
+ * Minimal standalone malloc implementation / environment. None of the
+ * flags mean anything and there's no need declare malloc types.
+ * Define the simple alloc / free routines in terms of Malloc and
+ * Free. None of the kernel features that this stuff disables are needed.
+ *
+ * XXX we are setting ourselves up for a potential crash if we can't allocate
+ * memory for a M_WAITOK call.
+ */
+#define M_WAITOK 0
+#define M_ZERO 0
+#define M_NOWAIT 0
+#define MALLOC_DECLARE(x)
+
+#define kmem_zalloc(size, flags) Malloc((size), __FILE__, __LINE__)
+#define kmem_free(p, size) Free(p, __FILE__, __LINE__)
+
+/*
+ * ZFS mem.h define that's the OpenZFS porting layer way of saying
+ * M_WAITOK. Given the above, it will also be a nop.
+ */
+#define KM_SLEEP M_WAITOK
+#endif /* _STANDALONE */
#endif /* !_SYS_MALLOC_H_ */
More information about the svn-src-all
mailing list