Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include "kolibc.h"
  2.  
  3. #define PINUSE_BIT    1
  4. #define CINUSE_BIT    2
  5. #define INUSE_BITS    3
  6.  
  7.  
  8. struct m_seg
  9. {
  10.   char*         base;          /* base address */
  11.   dword         size;          /* allocated size */
  12.   struct m_seg* next;          /* ptr to next segment */
  13.   dword         flags;         /* mmap and extern flag */
  14. };
  15.  
  16. struct m_chunk
  17. {
  18.   dword           prev_foot;  /* Size of previous chunk (if free).  */
  19.   dword           head;       /* Size and inuse bits. */
  20.   struct m_chunk* fd;         /* double links -- used only if free. */
  21.   struct m_chunk* bk;
  22. };
  23.  
  24. typedef struct m_chunk* mchunkptr;
  25.  
  26. struct t_chunk
  27. {
  28.   /* The first four fields must be compatible with malloc_chunk */
  29.   dword           prev_foot;
  30.   dword           head;
  31.  
  32.   struct t_chunk* fd;
  33.   struct t_chunk* bk;
  34.  
  35.   struct t_chunk* child[2];
  36.  
  37.   struct t_chunk* parent;
  38.   dword           index;
  39. };
  40.  
  41. typedef struct t_chunk* tchunkptr;
  42. typedef struct t_chunk* tbinptr;
  43.  
  44. struct m_state
  45. {
  46.   dword      smallmap;
  47.   dword      treemap;
  48. //  DWORD      dvsize;
  49.   dword      topsize;
  50.   char*      least_addr;
  51. //  mchunkptr  dv;
  52.   mchunkptr  top;
  53.   dword      magic;
  54.   struct m_chunk    smallbins[32];
  55.   tbinptr    treebins[32];
  56. };
  57.  
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif /* __cplusplus */
  61.  
  62. extern struct m_state ms;
  63.  
  64. void init_malloc(void* p);
  65. void* mf_alloc(size_t);
  66. void  mf_free(void*);
  67.  
  68. #ifdef __cplusplus
  69. }
  70. #endif /* __cplusplus */
  71.  
  72.  
  73. dword compute_tree_index(size_t s);
  74.  
  75. void insert_chunk(mchunkptr P, size_t S);
  76. void insert_large_chunk(tchunkptr X, size_t S);
  77.  
  78. void unlink_large_chunk(tchunkptr X);
  79.  
  80. //void replace_dv(mchunkptr P, size_t S);
  81. static void* malloc_small(size_t nb);
  82. static void* malloc_large(size_t nb);
  83.  
  84. #define leftshift_for_tree_index(i) \
  85.    ((i == 31)? 0 : (31 - (i >> 1) + 8 - 2))
  86.  
  87. #define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])
  88. #define chunk2mem(p)    (void*)((char*)p + 8)
  89. #define mem2chunk(mem)  (mchunkptr)((char*)mem - 8)
  90. #define chunk_plus_offset(p, s)  ((mchunkptr)(((char*)(p)) + (s)))
  91.  
  92.