XINU
system
getstk.c
Go to the documentation of this file.
1
5
#include <
xinu.h
>
6
25
char
*
getstk
(
uint32
nbytes)
26
{
27
intmask
mask;
/* Saved interrupt mask */
28
struct
memblk
*prev, *curr;
/* Walk through memory list */
29
struct
memblk
*fits, *fitsprev;
/* Record block that fits */
30
31
mask =
disable
();
32
if
(nbytes == 0)
33
{
34
restore
(mask);
35
return
(
char
*)
SYSERR
;
36
}
37
38
nbytes = (
uint32
)
roundmb
(nbytes);
/* Use mblock multiples */
39
40
prev = &
memlist
;
41
curr =
memlist
.
mnext
;
42
fits =
NULL
;
43
fitsprev =
NULL
;
/* Just to avoid a compiler warning */
44
45
while
(curr !=
NULL
)
46
{
/* Scan entire list */
47
if
(curr->
mlength
>= nbytes)
48
{
/* Record block address */
49
fits = curr;
/* when request fits */
50
fitsprev = prev;
51
}
52
prev = curr;
53
curr = curr->
mnext
;
54
}
55
56
if
(fits ==
NULL
)
57
{
/* No block was found */
58
restore
(mask);
59
return
(
char
*)
SYSERR
;
60
}
61
if
(nbytes == fits->
mlength
)
62
{
/* Block is exact match */
63
fitsprev->
mnext
= fits->
mnext
;
64
}
65
else
66
{
/* Remove top section */
67
fits->
mlength
-= nbytes;
68
fits = (
struct
memblk
*)((
uint32
)fits + fits->
mlength
);
69
}
70
memlist
.
mlength
-= nbytes;
71
restore
(mask);
72
return
(
char
*)((
uint32
)fits + nbytes -
sizeof
(
uint32
));
73
}
NULL
#define NULL
連結リスト用のNULLポインタ
Definition:
kernel.h:68
memblk
メモリブロックを管理するための構造体。
Definition:
memory.h:53
restore
void restore(intmask)
xinu.h
全てのシステムヘッダファイルをインクルードする。
SYSERR
#define SYSERR
処理が失敗した場合
Definition:
kernel.h:79
roundmb
#define roundmb(x)
メモリブロックサイズ(8の倍数)にアドレスを変換するために、8の倍数で丸める。
Definition:
memory.h:25
memblk::mnext
struct memblk * mnext
次のフリーメモリブロックへのポインタ
Definition:
memory.h:56
memlist
struct memblk memlist
フリーメモリリストの先頭
Definition:
initialize.c:27
intmask
uint32 intmask
保存された割り込みマスク
Definition:
kernel.h:38
memblk::mlength
uint32 mlength
memblk構造体のサイズを含むブロックサイズ
Definition:
memory.h:58
uint32
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition:
kernel.h:15
getstk
char * getstk(uint32 nbytes)
スタックメモリを割り当て、最上位のワードアドレスを返す。
Definition:
getstk.c:25
disable
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Generated by
1.8.13