1/* 2 * linux/compr_mm.h 3 * 4 * Memory management for pre-boot and ramdisk uncompressors 5 * 6 * Authors: Alain Knaff <alain@knaff.lu> 7 * 8 */ 9 10#ifndef DECOMPR_MM_H 11#define DECOMPR_MM_H 12 13#ifdef STATIC 14 15/* Code active when included from pre-boot environment: */ 16 17/* A trivial malloc implementation, adapted from 18 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994 19 */ 20static unsigned long malloc_ptr; 21static int malloc_count; 22 23static void *malloc(int size) 24{ 25 void *p; 26 27 if (size < 0) 28 error("Malloc error"); 29 if (!malloc_ptr) 30 malloc_ptr = free_mem_ptr; 31 32 malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */ 33 34 p = (void *)malloc_ptr; 35 malloc_ptr += size; 36 37 if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr) 38 error("Out of memory"); 39 40 malloc_count++; 41 return p; 42} 43 44static void free(void *where) 45{ 46 malloc_count--; 47 if (!malloc_count) 48 malloc_ptr = free_mem_ptr; 49} 50 51#define large_malloc(a) malloc(a) 52#define large_free(a) free(a) 53 54#define set_error_fn(x) 55 56#define INIT 57 58#else /* STATIC */ 59 60/* Code active when compiled standalone for use when loading ramdisk: */ 61 62#include <linux/kernel.h> 63#include <linux/fs.h> 64#include <linux/string.h> 65#include <linux/vmalloc.h> 66 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 */ 70 71#define malloc(a) kmalloc(a, GFP_KERNEL) 72#define free(a) kfree(a) 73 74#define large_malloc(a) vmalloc(a) 75#define large_free(a) vfree(a) 76 77static void(*error)(char *m); 78#define set_error_fn(x) error = x; 79 80#define INIT __init 81#define STATIC 82 83#include <linux/init.h> 84 85#endif /* STATIC */ 86 87#endif /* DECOMPR_MM_H */ 88

