Rev 3 | Details | Compare with Previous | 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 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | ------------ |
||
21 | CVS : $Id: addregio.c,v 1.1.1.1 2002-03-29 14:12:52 pj Exp $ |
||
22 | |||
23 | File: $File$ |
||
24 | Revision: $Revision: 1.1.1.1 $ |
||
25 | Last update: $Date: 2002-03-29 14:12:52 $ |
||
26 | ------------ |
||
27 | |||
28 | this code is from: |
||
29 | List-based Memory Management, from OsKit. |
||
30 | |||
31 | **/ |
||
32 | |||
33 | /* |
||
34 | * Copyright (C) 2000 Paolo Gai |
||
35 | * |
||
36 | * This program is free software; you can redistribute it and/or modify |
||
37 | * it under the terms of the GNU General Public License as published by |
||
38 | * the Free Software Foundation; either version 2 of the License, or |
||
39 | * (at your option) any later version. |
||
40 | * |
||
41 | * This program is distributed in the hope that it will be useful, |
||
42 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
43 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
44 | * GNU General Public License for more details. |
||
45 | * |
||
46 | * You should have received a copy of the GNU General Public License |
||
47 | * along with this program; if not, write to the Free Software |
||
48 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
49 | * |
||
50 | */ |
||
51 | |||
52 | /* |
||
53 | * Copyright (c) 1995, 1998 University of Utah and the Flux Group. |
||
54 | * All rights reserved. |
||
55 | * |
||
56 | * This file is part of the Flux OSKit. The OSKit is free software, also known |
||
57 | * as "open source;" you can redistribute it and/or modify it under the terms |
||
58 | * of the GNU General Public License (GPL), version 2, as published by the Free |
||
59 | * Software Foundation (FSF). To explore alternate licensing terms, contact |
||
60 | * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271. |
||
61 | * |
||
62 | * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY |
||
63 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
||
64 | * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have |
||
65 | * received a copy of the GPL along with the OSKit; see the file COPYING. If |
||
66 | * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA. |
||
67 | */ |
||
68 | |||
69 | #include <kernel/lmm.h> |
||
70 | #define assert(test) assertk(test) |
||
71 | |||
72 | void lmm_add_region(lmm_t *lmm, lmm_region_t *reg, |
||
73 | void *addr, size_t size, |
||
74 | lmm_flags_t flags, lmm_pri_t pri) |
||
75 | { |
||
76 | DWORD min = (DWORD)addr; |
||
77 | DWORD max = min + size; |
||
78 | struct lmm_region **rp, *r; |
||
79 | |||
80 | /* Align the start and end addresses appropriately. */ |
||
81 | min = (min + ALIGN_MASK) & ~ALIGN_MASK; |
||
82 | max &= ~ALIGN_MASK; |
||
83 | |||
84 | /* If there's not enough memory to do anything with, |
||
85 | then just drop the region on the floor. |
||
86 | Since we haven't put it on the lmm's list, |
||
87 | we'll never see it again. */ |
||
88 | if (max <= min) |
||
89 | return; |
||
90 | |||
91 | /* Initialize the new region header. */ |
||
92 | reg->nodes = 0; |
||
93 | reg->min = min; |
||
94 | reg->max = max; |
||
95 | reg->flags = flags; |
||
96 | reg->pri = pri; |
||
97 | reg->free = 0; |
||
98 | |||
99 | /* Add the region to the lmm's region list in descending priority order. |
||
100 | For regions with the same priority, sort from largest to smallest |
||
101 | to reduce the average amount of list traversing we need to do. */ |
||
102 | for (rp = &lmm->regions; |
||
103 | (r = *rp) && ((r->pri > pri) || |
||
104 | ((r->pri == pri) && |
||
105 | (r->max - r->min > reg->max - reg->min))); |
||
106 | rp = &r->next) |
||
107 | { |
||
108 | assert(r != reg); |
||
109 | assert((reg->max <= r->min) || (reg->min >= r->max)); |
||
110 | } |
||
111 | reg->next = r; |
||
112 | *rp = reg; |
||
113 | } |
||
114 |