Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/slab.h
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | |||||
#define SLAB_RECLAIM_ACCOUNT (1 << 2) | #define SLAB_RECLAIM_ACCOUNT (1 << 2) | ||||
#define SLAB_DESTROY_BY_RCU \ | #define SLAB_DESTROY_BY_RCU \ | ||||
SLAB_TYPESAFE_BY_RCU | SLAB_TYPESAFE_BY_RCU | ||||
#define ARCH_KMALLOC_MINALIGN \ | #define ARCH_KMALLOC_MINALIGN \ | ||||
__alignof(unsigned long long) | __alignof(unsigned long long) | ||||
/* | /* drm-kmod 5.4 compat */ | ||||
* Critical section-friendly version of kfree(). | #define kfree_async(ptr) kfree(ptr); | ||||
* Requires knowledge of the allocation size at build time. | |||||
*/ | |||||
#define kfree_async(ptr) do { \ | |||||
_Static_assert(sizeof(*(ptr)) >= sizeof(struct llist_node), \ | |||||
"Size of object to free is unknown or too small"); \ | |||||
if (curthread->td_critnest != 0) \ | |||||
linux_kfree_async(ptr); \ | |||||
else \ | |||||
kfree(ptr); \ | |||||
} while (0) | |||||
static inline gfp_t | static inline gfp_t | ||||
linux_check_m_flags(gfp_t flags) | linux_check_m_flags(gfp_t flags) | ||||
{ | { | ||||
const gfp_t m = M_NOWAIT | M_WAITOK; | const gfp_t m = M_NOWAIT | M_WAITOK; | ||||
/* make sure either M_NOWAIT or M_WAITOK is set */ | /* make sure either M_NOWAIT or M_WAITOK is set */ | ||||
if ((flags & m) == 0) | if ((flags & m) == 0) | ||||
flags |= M_NOWAIT; | flags |= M_NOWAIT; | ||||
else if ((flags & m) == m) | else if ((flags & m) == m) | ||||
flags &= ~M_WAITOK; | flags &= ~M_WAITOK; | ||||
/* mask away LinuxKPI specific flags */ | /* mask away LinuxKPI specific flags */ | ||||
return (flags & GFP_NATIVE_MASK); | return (flags & GFP_NATIVE_MASK); | ||||
} | } | ||||
static inline void * | static inline void * | ||||
kmalloc(size_t size, gfp_t flags) | kmalloc(size_t size, gfp_t flags) | ||||
{ | { | ||||
return (malloc(size, M_KMALLOC, linux_check_m_flags(flags))); | return (malloc(MAX(size, sizeof(struct llist_node)), M_KMALLOC, | ||||
linux_check_m_flags(flags))); | |||||
} | } | ||||
static inline void * | static inline void * | ||||
kmalloc_node(size_t size, gfp_t flags, int node) | kmalloc_node(size_t size, gfp_t flags, int node) | ||||
{ | { | ||||
return (malloc_domainset(size, M_KMALLOC, | return (malloc_domainset(size, M_KMALLOC, | ||||
linux_get_vm_domain_set(node), linux_check_m_flags(flags))); | linux_get_vm_domain_set(node), linux_check_m_flags(flags))); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static inline void * | static inline void * | ||||
krealloc(void *ptr, size_t size, gfp_t flags) | krealloc(void *ptr, size_t size, gfp_t flags) | ||||
{ | { | ||||
return (realloc(ptr, size, M_KMALLOC, linux_check_m_flags(flags))); | return (realloc(ptr, size, M_KMALLOC, linux_check_m_flags(flags))); | ||||
} | } | ||||
extern void linux_kfree_async(void *); | |||||
hselasky: Maybe put "extern" in front. Matches style in this file better. | |||||
static inline void | static inline void | ||||
kfree(const void *ptr) | kfree(const void *ptr) | ||||
{ | { | ||||
if (curthread->td_critnest != 0) | |||||
linux_kfree_async(__DECONST(void *, ptr)); | |||||
else | |||||
free(__DECONST(void *, ptr), M_KMALLOC); | free(__DECONST(void *, ptr), M_KMALLOC); | ||||
} | } | ||||
static __inline void | static __inline void | ||||
kfree_sensitive(const void *ptr) | kfree_sensitive(const void *ptr) | ||||
{ | { | ||||
zfree(__DECONST(void *, ptr), M_KMALLOC); | zfree(__DECONST(void *, ptr), M_KMALLOC); | ||||
} | } | ||||
static inline size_t | static inline size_t | ||||
ksize(const void *ptr) | ksize(const void *ptr) | ||||
{ | { | ||||
return (malloc_usable_size(ptr)); | return (malloc_usable_size(ptr)); | ||||
} | } | ||||
extern struct linux_kmem_cache *linux_kmem_cache_create(const char *name, | extern struct linux_kmem_cache *linux_kmem_cache_create(const char *name, | ||||
size_t size, size_t align, unsigned flags, linux_kmem_ctor_t *ctor); | size_t size, size_t align, unsigned flags, linux_kmem_ctor_t *ctor); | ||||
extern void *lkpi_kmem_cache_alloc(struct linux_kmem_cache *, gfp_t); | extern void *lkpi_kmem_cache_alloc(struct linux_kmem_cache *, gfp_t); | ||||
extern void *lkpi_kmem_cache_zalloc(struct linux_kmem_cache *, gfp_t); | extern void *lkpi_kmem_cache_zalloc(struct linux_kmem_cache *, gfp_t); | ||||
extern void lkpi_kmem_cache_free(struct linux_kmem_cache *, void *); | extern void lkpi_kmem_cache_free(struct linux_kmem_cache *, void *); | ||||
extern void linux_kmem_cache_destroy(struct linux_kmem_cache *); | extern void linux_kmem_cache_destroy(struct linux_kmem_cache *); | ||||
void linux_kfree_async(void *); | |||||
#endif /* _LINUX_SLAB_H_ */ | #endif /* _LINUX_SLAB_H_ */ |
Maybe put "extern" in front. Matches style in this file better.