Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/malloc.h
Show First 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | |||||
extern void Free(void *p, const char *file, int line); | extern void Free(void *p, const char *file, int line); | ||||
extern void *Malloc(size_t bytes, const char *file, int line); | extern void *Malloc(size_t bytes, const char *file, int line); | ||||
/* | /* | ||||
* Minimal standalone malloc implementation / environment. None of the | * Minimal standalone malloc implementation / environment. None of the | ||||
* flags mean anything and there's no need declare malloc types. | * flags mean anything and there's no need declare malloc types. | ||||
* Define the simple alloc / free routines in terms of Malloc and | * Define the simple alloc / free routines in terms of Malloc and | ||||
* Free. None of the kernel features that this stuff disables are needed. | * 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_WAITOK 1 | ||||
#define M_ZERO 0 | #define M_ZERO 0 | ||||
#define M_NOWAIT 0 | #define M_NOWAIT 2 | ||||
#define MALLOC_DECLARE(x) | #define MALLOC_DECLARE(x) | ||||
#define kmem_zalloc(size, flags) Malloc((size), __FILE__, __LINE__) | #define kmem_zalloc(size, flags) ({ \ | ||||
void *p = Malloc((size), __FILE__, __LINE__); \ | |||||
tsoome: Shouldn't this order be reversed? or maybe create inline [function] instead? just thinking... | |||||
impAuthorUnsubmitted Done Inline ActionsOrder of what? imp: Order of what?
It can't be an inline function because I want __FILE__ and __LINE__ and I didn't… | |||||
tsoomeUnsubmitted Not Done Inline Actions
tsoome: > Order of what?
> It can't be an inline function because I want __FILE__ and __LINE__ and I… | |||||
if (flags & M_WAITOK) \ | |||||
impAuthorUnsubmitted Done Inline ActionsThis should be if (p == 0 && (flags & M_WAITOK) != 0) imp: This should be if (p == 0 && (flags & M_WAITOK) != 0)
| |||||
panic("Could not malloc %zd bytes with M_WAITOK from %s line %d", \ | |||||
(size_t)size, __FILE__, __LINE__); \ | |||||
p; \ | |||||
}) | |||||
#define kmem_free(p, size) Free(p, __FILE__, __LINE__) | #define kmem_free(p, size) Free(p, __FILE__, __LINE__) | ||||
/* | /* | ||||
* ZFS mem.h define that's the OpenZFS porting layer way of saying | * ZFS mem.h define that's the OpenZFS porting layer way of saying | ||||
* M_WAITOK. Given the above, it will also be a nop. | * M_WAITOK. Given the above, it will also be a nop. | ||||
*/ | */ | ||||
#define KM_SLEEP M_WAITOK | #define KM_SLEEP M_WAITOK | ||||
#define KM_NOSLEEP M_NOWAIT | |||||
impAuthorUnsubmitted Done Inline ActionsThis crept in because we never were testing flags before. imp: This crept in because we never were testing flags before. | |||||
#endif /* _STANDALONE */ | #endif /* _STANDALONE */ | ||||
#endif /* !_SYS_MALLOC_H_ */ | #endif /* !_SYS_MALLOC_H_ */ |
Shouldn't this order be reversed? or maybe create inline [function] instead? just thinking...