4 * Memory management for pre-boot and ramdisk uncompressors
6 * Authors: Alain Knaff <alain@knaff.lu>
15 /* Code active when included from pre-boot environment: */
17 /* A trivial malloc implementation, adapted from
18 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
20 static unsigned long malloc_ptr
;
21 static int malloc_count
;
23 static void *malloc(int size
)
28 error("Malloc error");
30 malloc_ptr
= free_mem_ptr
;
32 malloc_ptr
= (malloc_ptr
+ 3) & ~3; /* Align */
34 p
= (void *)malloc_ptr
;
37 if (free_mem_end_ptr
&& malloc_ptr
>= free_mem_end_ptr
)
38 error("Out of memory");
44 static void free(void *where
)
48 malloc_ptr
= free_mem_ptr
;
51 #define large_malloc(a) malloc(a)
52 #define large_free(a) free(a)
54 #define set_error_fn(x)
60 /* Code active when compiled standalone for use when loading ramdisk: */
62 #include <linux/kernel.h>
64 #include <linux/string.h>
65 #include <linux/vmalloc.h>
67 /* Use defines rather than static inline in order to avoid spurious
68 * warnings when not needed (indeed large_malloc / large_free are not
69 * needed by inflate */
71 #define malloc(a) kmalloc(a, GFP_KERNEL)
72 #define free(a) kfree(a)
74 #define large_malloc(a) vmalloc(a)
75 #define large_free(a) vfree(a)
77 static void(*error
)(char *m
);
78 #define set_error_fn(x) error = x;
83 #include <linux/init.h>
87 #endif /* DECOMPR_MM_H */