1 /* SPDX-License-Identifier: GPL-2.0 */
5 * Memory management for pre-boot and ramdisk uncompressors
7 * Authors: Alain Knaff <alain@knaff.lu>
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
28 /* A trivial malloc implementation, adapted from
29 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
31 STATIC_RW_DATA
unsigned long malloc_ptr
;
32 STATIC_RW_DATA
int malloc_count
;
34 static void *malloc(int size
)
41 malloc_ptr
= free_mem_ptr
;
43 malloc_ptr
= (malloc_ptr
+ 3) & ~3; /* Align */
45 p
= (void *)malloc_ptr
;
48 if (free_mem_end_ptr
&& malloc_ptr
>= free_mem_end_ptr
)
55 static void free(void *where
)
59 malloc_ptr
= free_mem_ptr
;
62 #define large_malloc(a) malloc(a)
63 #define large_free(a) free(a)
69 /* Code active when compiled standalone for use when loading ramdisk: */
71 #include <linux/kernel.h>
73 #include <linux/string.h>
74 #include <linux/slab.h>
75 #include <linux/vmalloc.h>
77 /* Use defines rather than static inline in order to avoid spurious
78 * warnings when not needed (indeed large_malloc / large_free are not
79 * needed by inflate */
81 #define malloc(a) kmalloc(a, GFP_KERNEL)
82 #define free(a) kfree(a)
84 #define large_malloc(a) vmalloc(a)
85 #define large_free(a) vfree(a)
90 #include <linux/init.h>
94 #endif /* DECOMPR_MM_H */