Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | /* SPDX-License-Identifier: GPL-2.0 */ /* * Written by Mark Hemment, 1996 (markhe@nextd.demon.co.uk). * * (C) SGI 2006, Christoph Lameter * Cleaned up and restructured to ease the addition of alternative * implementations of SLAB allocators. * (C) Linux Foundation 2008-2013 * Unified interface for all slab allocators * * Memory allocation functions for Linux kernel compatibility. * These map to U-Boot's malloc/free infrastructure. */ #ifndef _LINUX_SLAB_H #define _LINUX_SLAB_H #include <malloc.h> #include <linux/types.h> #include <linux/string.h> #ifndef GFP_ATOMIC #define GFP_ATOMIC ((gfp_t)0) #endif #ifndef GFP_KERNEL #define GFP_KERNEL ((gfp_t)0) #endif #ifndef GFP_NOFS #define GFP_NOFS ((gfp_t)0) #endif #ifndef GFP_USER #define GFP_USER ((gfp_t)0) #endif #ifndef GFP_NOWAIT #define GFP_NOWAIT ((gfp_t)0) #endif #ifndef __GFP_NOWARN #define __GFP_NOWARN ((gfp_t)0) #endif #ifndef __GFP_ZERO #define __GFP_ZERO ((__force gfp_t)0x8000u) #endif #ifndef __GFP_NOFAIL #define __GFP_NOFAIL ((gfp_t)0) #endif void *kmalloc(size_t size, gfp_t flags); static inline void *kzalloc(size_t size, gfp_t flags) { return kmalloc(size, flags | __GFP_ZERO); } static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) { if (size != 0 && n > SIZE_MAX / size) return NULL; return kmalloc(n * size, flags | __GFP_ZERO); } static inline void *kcalloc(size_t n, size_t size, gfp_t flags) { return kmalloc_array(n, size, flags | __GFP_ZERO); } static inline void kfree(const void *block) { free((void *)block); } static inline void kvfree(const void *addr) { kfree(addr); } static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags) { return kmalloc_array(n, size, flags); } static inline void *krealloc(const void *p, size_t new_size, gfp_t flags) { return realloc((void *)p, new_size); } void *kmemdup(const void *src, size_t len, gfp_t gfp); /* kmem_cache stubs */ struct kmem_cache { int sz; }; struct kmem_cache *get_mem(int element_sz); #define kmem_cache_create(a, sz, c, d, e) ({ (void)(a); (void)(e); get_mem(sz); }) void *kmem_cache_alloc(struct kmem_cache *obj, gfp_t flag); static inline void *kmem_cache_zalloc(struct kmem_cache *obj, gfp_t flags) { void *ret = kmem_cache_alloc(obj, flags); if (ret) memset(ret, 0, obj->sz); return ret; } static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj) { free(obj); } static inline void kmem_cache_destroy(struct kmem_cache *cachep) { free(cachep); } #endif /* _LINUX_SLAB_H */ |