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.
This commit is contained in:
parent
b1c57f89ce
commit
e34fac850c
@ -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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user