Blame view
include/linux/decompress/mm.h
1.82 KB
bc22c17e1
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/* * linux/compr_mm.h * * Memory management for pre-boot and ramdisk uncompressors * * Authors: Alain Knaff <alain@knaff.lu> * */ #ifndef DECOMPR_MM_H #define DECOMPR_MM_H #ifdef STATIC /* Code active when included from pre-boot environment: */ |
5ceaa2f39
|
16 17 |
/* * Some architectures want to ensure there is no local data in their |
25985edce
|
18 |
* pre-boot environment, so that data can arbitrarily relocated (via |
5ceaa2f39
|
19 20 21 22 23 24 |
* GOT references). This is achieved by defining STATIC_RW_DATA to * be null. */ #ifndef STATIC_RW_DATA #define STATIC_RW_DATA static #endif |
bc22c17e1
|
25 26 27 |
/* A trivial malloc implementation, adapted from * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994 */ |
5ceaa2f39
|
28 29 |
STATIC_RW_DATA unsigned long malloc_ptr; STATIC_RW_DATA int malloc_count; |
bc22c17e1
|
30 31 32 33 34 35 |
static void *malloc(int size) { void *p; if (size < 0) |
c1e7c3ae5
|
36 |
return NULL; |
bc22c17e1
|
37 38 39 40 41 42 43 44 45 |
if (!malloc_ptr) malloc_ptr = free_mem_ptr; malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */ p = (void *)malloc_ptr; malloc_ptr += size; if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr) |
c1e7c3ae5
|
46 |
return NULL; |
bc22c17e1
|
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
malloc_count++; return p; } static void free(void *where) { malloc_count--; if (!malloc_count) malloc_ptr = free_mem_ptr; } #define large_malloc(a) malloc(a) #define large_free(a) free(a) |
bc22c17e1
|
61 62 63 64 65 66 67 68 69 |
#define INIT #else /* STATIC */ /* Code active when compiled standalone for use when loading ramdisk: */ #include <linux/kernel.h> #include <linux/fs.h> #include <linux/string.h> |
2b6b5caa6
|
70 |
#include <linux/slab.h> |
bc22c17e1
|
71 72 73 74 75 76 77 78 79 80 81 |
#include <linux/vmalloc.h> /* Use defines rather than static inline in order to avoid spurious * warnings when not needed (indeed large_malloc / large_free are not * needed by inflate */ #define malloc(a) kmalloc(a, GFP_KERNEL) #define free(a) kfree(a) #define large_malloc(a) vmalloc(a) #define large_free(a) vfree(a) |
bc22c17e1
|
82 83 84 85 86 87 88 89 |
#define INIT __init #define STATIC #include <linux/init.h> #endif /* STATIC */ #endif /* DECOMPR_MM_H */ |