Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * (see the web pages for full authors list) |
||
13 | * |
||
14 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
15 | * |
||
16 | * http://www.sssup.it |
||
17 | * http://retis.sssup.it |
||
18 | * http://shark.sssup.it |
||
19 | */ |
||
20 | |||
21 | |||
22 | /** |
||
23 | ------------ |
||
24 | CVS : $Id: lmm.h,v 1.1.1.1 2002-03-29 14:12:51 pj Exp $ |
||
25 | |||
26 | File: $File$ |
||
27 | Revision: $Revision: 1.1.1.1 $ |
||
28 | Last update: $Date: 2002-03-29 14:12:51 $ |
||
29 | ------------ |
||
30 | |||
31 | this code is from: |
||
32 | List-based Memory Management, from OsKit. |
||
33 | |||
34 | it is used in kernel/mem.c to implement the memory allocators... |
||
35 | |||
36 | **/ |
||
37 | |||
38 | /* |
||
39 | * Copyright (C) 2000 Paolo Gai |
||
40 | * |
||
41 | * This program is free software; you can redistribute it and/or modify |
||
42 | * it under the terms of the GNU General Public License as published by |
||
43 | * the Free Software Foundation; either version 2 of the License, or |
||
44 | * (at your option) any later version. |
||
45 | * |
||
46 | * This program is distributed in the hope that it will be useful, |
||
47 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
48 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
49 | * GNU General Public License for more details. |
||
50 | * |
||
51 | * You should have received a copy of the GNU General Public License |
||
52 | * along with this program; if not, write to the Free Software |
||
53 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
54 | * |
||
55 | */ |
||
56 | |||
57 | /* |
||
58 | * Copyright (c) 1995-1996, 1998 University of Utah and the Flux Group. |
||
59 | * All rights reserved. |
||
60 | * |
||
61 | * This file is part of the Flux OSKit. The OSKit is free software, also known |
||
62 | * as "open source;" you can redistribute it and/or modify it under the terms |
||
63 | * of the GNU General Public License (GPL), version 2, as published by the Free |
||
64 | * Software Foundation (FSF). To explore alternate licensing terms, contact |
||
65 | * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271. |
||
66 | * |
||
67 | * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY |
||
68 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
||
69 | * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have |
||
70 | * received a copy of the GPL along with the OSKit; see the file COPYING. If |
||
71 | * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA. |
||
72 | */ |
||
73 | |||
74 | /* |
||
75 | * Public header file for the List Memory Manager. |
||
76 | */ |
||
77 | #ifndef __KERNEL_LMM_H__ |
||
78 | #define __KERNEL_LMM_H__ |
||
79 | |||
80 | // this part was oskit/lmm.h |
||
81 | |||
82 | #include <sys/types.h> |
||
83 | |||
84 | typedef DWORD lmm_flags_t; |
||
85 | typedef int lmm_pri_t; |
||
86 | |||
87 | /* The contents of these structures are opaque to users. */ |
||
88 | typedef struct lmm_region |
||
89 | { |
||
90 | struct lmm_region *next; |
||
91 | |||
92 | /* List of free memory blocks in this region. */ |
||
93 | struct lmm_node *nodes; |
||
94 | |||
95 | /* Virtual addresses of the start and end of the memory region. */ |
||
96 | DWORD min; |
||
97 | DWORD max; |
||
98 | |||
99 | /* Attributes of this memory. */ |
||
100 | lmm_flags_t flags; |
||
101 | |||
102 | /* Allocation priority of this region with respect to other regions. */ |
||
103 | lmm_pri_t pri; |
||
104 | |||
105 | /* Current amount of free space in this region in bytes. */ |
||
106 | size_t free; |
||
107 | } lmm_region_t; |
||
108 | |||
109 | typedef struct lmm |
||
110 | { |
||
111 | struct lmm_region *regions; |
||
112 | } lmm_t; |
||
113 | |||
114 | #define LMM_INITIALIZER { 0 } |
||
115 | |||
116 | // OSKIT_BEGIN_DECLS |
||
117 | |||
118 | void lmm_init(lmm_t *lmm); |
||
119 | void lmm_add_region(lmm_t *lmm, lmm_region_t *lmm_region, |
||
120 | void *addr, size_t size, |
||
121 | lmm_flags_t flags, lmm_pri_t pri); |
||
122 | void lmm_add_free(lmm_t *lmm, void *block, size_t size); |
||
123 | void lmm_remove_free(lmm_t *lmm, void *block, size_t size); |
||
124 | void *lmm_alloc(lmm_t *lmm, size_t size, lmm_flags_t flags); |
||
125 | void *lmm_alloc_aligned(lmm_t *lmm, size_t size, lmm_flags_t flags, |
||
126 | int align_bits, DWORD align_ofs); |
||
127 | void *lmm_alloc_page(lmm_t *lmm, lmm_flags_t flags); |
||
128 | void *lmm_alloc_gen(lmm_t *lmm, size_t size, lmm_flags_t flags, |
||
129 | int align_bits, DWORD align_ofs, |
||
130 | DWORD bounds_min, DWORD bounds_max); |
||
131 | size_t lmm_avail(lmm_t *lmm, lmm_flags_t flags); |
||
132 | void lmm_find_free(lmm_t *lmm, DWORD *inout_addr, |
||
133 | size_t *out_size, lmm_flags_t *out_flags); |
||
134 | void lmm_free(lmm_t *lmm, void *block, size_t size); |
||
135 | void lmm_free_page(lmm_t *lmm, void *block); |
||
136 | |||
137 | /* Only available if debugging turned on. */ |
||
138 | void lmm_dump(lmm_t *lmm); |
||
139 | void lmm_stats(lmm_t *lmm); |
||
140 | // OSKIT_END_DECLS |
||
141 | |||
142 | |||
143 | // this part was llm.h |
||
144 | |||
145 | #include <kernel/assert.h> |
||
146 | |||
147 | struct lmm_node |
||
148 | { |
||
149 | struct lmm_node *next; |
||
150 | size_t size; |
||
151 | }; |
||
152 | |||
153 | #define ALIGN_SIZE sizeof(struct lmm_node) |
||
154 | #define ALIGN_MASK (ALIGN_SIZE - 1) |
||
155 | |||
156 | #define CHECKREGPTR(p) { \ |
||
157 | assertk((reg->nodes == 0 && reg->free == 0) \ |
||
158 | || (DWORD)reg->nodes >= reg->min); \ |
||
159 | assertk(reg->nodes == 0 || (DWORD)reg->nodes < reg->max); \ |
||
160 | assertk(reg->free >= 0); \ |
||
161 | assertk(reg->free <= reg->max - reg->min); \ |
||
162 | } |
||
163 | |||
164 | #endif |