@@ -1,4 +1,6 @@
#ifndef _TOOLS_INCLUDE_LINUX_GFP_H
#define _TOOLS_INCLUDE_LINUX_GFP_H
+#define __GFP_ZERO 0x100u
+
#endif /* _TOOLS_INCLUDE_LINUX_GFP_H */
new file mode 100644
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __TOOLS_LINUX_SLAB_H
+#define __TOOLS_LINUX_SLAB_H
+
+#include <linux/gfp.h>
+#include <linux/cache.h>
+
+static inline void *kmalloc(size_t size, gfp_t gfp)
+{
+ void *p;
+
+ p = memalign(SMP_CACHE_BYTES, size);
+ if (!p)
+ return p;
+
+ if (gfp & __GFP_ZERO)
+ memset(p, 0, size);
+
+ return p;
+}
+
+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)
+{
+ return kmalloc(n * size, flags);
+}
+
+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(void *p)
+{
+ free(p);
+}
+
+#define kvmalloc_array kmalloc_array
+#define kvfree kfree
+#define KMALLOC_MAX_SIZE SIZE_MAX
+
+#endif
Implement the kmalloc/vmalloc related interface based on malloc interface in user space. Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com> --- tools/include/linux/gfp.h | 2 ++ tools/include/linux/slab.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tools/include/linux/slab.h