Subversion Repositories Kolibri OS

Rev

Rev 300 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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