1 /* SPDX-License-Identifier: GPL-2.0 */
5 * Memory management for pre-boot and ramdisk uncompressors
16 /* Code active when included from pre-boot environment: */
19 * Some architectures want to ensure there is no local data in their
20 * pre-boot environment, so that data can arbitrarily relocated (via
21 * GOT references). This is achieved by defining STATIC_RW_DATA to
24 #ifndef STATIC_RW_DATA
25 #define STATIC_RW_DATA static
29 * When an architecture needs to share the malloc()/free() implementation
30 * between compilation units, it needs to have non-local visibility.
32 #ifndef MALLOC_VISIBLE
33 #define MALLOC_VISIBLE static
36 /* A trivial malloc implementation, adapted from
37 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
39 STATIC_RW_DATA unsigned long malloc_ptr;
40 STATIC_RW_DATA int malloc_count;
42 MALLOC_VISIBLE void *malloc(int size)
49 malloc_ptr = free_mem_ptr;
51 malloc_ptr = (malloc_ptr + 7) & ~7; /* Align */
53 p = (void *)malloc_ptr;
56 if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
63 MALLOC_VISIBLE void free(void *where)
67 malloc_ptr = free_mem_ptr;
70 #define large_malloc(a) malloc(a)
71 #define large_free(a) free(a)
77 /* Code active when compiled standalone for use when loading ramdisk: */
79 #include <linux/kernel.h>
81 #include <linux/string.h>
82 #include <linux/slab.h>
83 #include <linux/vmalloc.h>
85 /* Use defines rather than static inline in order to avoid spurious
86 * warnings when not needed (indeed large_malloc / large_free are not
87 * needed by inflate */
89 #define malloc(a) kmalloc(a, GFP_KERNEL)
90 #define free(a) kfree(a)
92 #define large_malloc(a) vmalloc(a)
93 #define large_free(a) vfree(a)
98 #include <linux/init.h>
102 #endif /* DECOMPR_MM_H */