Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
141 | trimarchi | 1 | /* |
2 | * Doubly indexed dynamic memory allocator (DIDMA) |
||
3 | * Version 0.61 |
||
4 | * |
||
5 | * Written by Miguel Masmano Tello <mmasmano@disca.upv.es> |
||
6 | * Copyright (C) Dec, 2002 OCERA Consortium |
||
7 | * Release under the terms of the GNU General Public License Version 2 |
||
8 | * |
||
9 | */ |
||
10 | |||
11 | #ifndef _INDEXED_MALLOC_H_ |
||
12 | #define _INDEXED_MALLOC_H_ |
||
13 | |||
14 | #include <kernel/mem.h> |
||
15 | #include <stdio.h> |
||
16 | |||
17 | #define size_t unsigned int |
||
18 | /* |
||
19 | * if __DEBUG__ is defined several functions like mem_dump(), |
||
20 | * free_blocks_context() will be availables. |
||
21 | */ |
||
22 | //#define __DEBUG__ |
||
23 | |||
24 | /* |
||
25 | * MAX_FL_INDEX define the max first level number of indexes |
||
26 | */ |
||
27 | static int MAX_FL_INDEX = 25; |
||
28 | |||
29 | #define PRINT_MSG printk |
||
30 | #define PRINT_DBG_C(message) printk(message) |
||
31 | #define PRINT_DBG_D(message) printk("%i", message); |
||
32 | //#define PRINT_DBG_F(message) rtl_printf("%f", message); |
||
33 | #define PRINT_DBG_H(message) printk("%i", message); |
||
34 | |||
35 | #define SYSTEM_MALLOC(size) (void *) kern_alloc(size) |
||
36 | #define SYSTEM_FREE(ptr) kern_free((void *) ptr, 0); |
||
37 | |||
38 | int init_memory_pool (int max_size); |
||
39 | void destroy_memory_pool(void); |
||
40 | |||
41 | /* see man malloc */ |
||
42 | void *rt_malloc (size_t size); |
||
43 | |||
44 | /* see man realloc */ |
||
45 | void *rt_realloc(void *p, size_t new_len); |
||
46 | |||
47 | /* see man calloc */ |
||
48 | void *rt_calloc(size_t nelem, size_t elem_size); |
||
49 | |||
50 | /* |
||
51 | * see man free |
||
52 | * |
||
53 | * rt_free () is only guaranteed to work if ptr is the address of a block |
||
54 | * allocated by rt_malloc() (and not yet freed). |
||
55 | */ |
||
56 | void rt_free (void *ptr); |
||
57 | |||
58 | #ifdef __DEBUG__ |
||
59 | |||
60 | /* dump_mem () does a dumped of the memory context */ |
||
61 | void dump_mem (void); |
||
62 | |||
63 | /* |
||
64 | * free_blocks_context () show the content |
||
65 | * of free blocks |
||
66 | */ |
||
67 | void free_blocks_context(void); |
||
68 | |||
69 | /* |
||
70 | * structure_context () gives information about |
||
71 | * algorithm structures |
||
72 | */ |
||
73 | void structure_context (void); |
||
74 | |||
75 | /* |
||
76 | * check_mem () checks memory searching |
||
77 | * errors and incoherences |
||
78 | * return : |
||
79 | * 0 if there isn't any error |
||
80 | * or |
||
81 | * -1 in other case |
||
82 | */ |
||
83 | int check_mem (void); |
||
84 | |||
85 | /* |
||
86 | * global_state () returns overhead, free and used space |
||
87 | */ |
||
88 | void global_state (int *free, int *used, int *overhead); |
||
89 | |||
90 | #endif // DEBUG |
||
91 | #endif // #ifndef _INDEXED_MALLOC_H_ |