Subversion Repositories Kolibri OS

Rev

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

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