mm.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #ifndef DECOMPR_MM_H
  10. #define DECOMPR_MM_H
  11. #ifdef STATIC
  12. /* Code active when included from pre-boot environment: */
  13. /* A trivial malloc implementation, adapted from
  14. * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
  15. */
  16. static unsigned long malloc_ptr;
  17. static int malloc_count;
  18. static void *malloc(int size)
  19. {
  20. void *p;
  21. if (size < 0)
  22. return NULL;
  23. if (!malloc_ptr)
  24. malloc_ptr = free_mem_ptr;
  25. malloc_ptr = (malloc_ptr + 3) & ~3; /* Align */
  26. p = (void *)malloc_ptr;
  27. malloc_ptr += size;
  28. if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
  29. return NULL;
  30. malloc_count++;
  31. return p;
  32. }
  33. static void free(void *where)
  34. {
  35. malloc_count--;
  36. if (!malloc_count)
  37. malloc_ptr = free_mem_ptr;
  38. }
  39. #define large_malloc(a) malloc(a)
  40. #define large_free(a) free(a)
  41. #define set_error_fn(x)
  42. #define INIT
  43. #else /* STATIC */
  44. /* Code active when compiled standalone for use when loading ramdisk: */
  45. #include <linux/kernel.h>
  46. #include <linux/fs.h>
  47. #include <linux/string.h>
  48. #include <linux/vmalloc.h>
  49. /* Use defines rather than static inline in order to avoid spurious
  50. * warnings when not needed (indeed large_malloc / large_free are not
  51. * needed by inflate */
  52. #define malloc(a) kmalloc(a, GFP_KERNEL)
  53. #define free(a) kfree(a)
  54. #define large_malloc(a) vmalloc(a)
  55. #define large_free(a) vfree(a)
  56. static void(*error)(char *m);
  57. #define set_error_fn(x) error = x;
  58. #define INIT __init
  59. #define STATIC
  60. #include <linux/init.h>
  61. #endif /* STATIC */
  62. #endif /* DECOMPR_MM_H */