brickOS Kernel Developer v0.9.0
mm.h
Go to the documentation of this file.
1
6/*
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.0 (the "License"); you may not use this file except in
9 * compliance with the License. You may obtain a copy of the License
10 * at http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14 * the License for the specific language governing rights and
15 * limitations under the License.
16 *
17 * The Original Code is legOS code, released October 17, 1999.
18 *
19 * The Initial Developer of the Original Code is Markus L. Noga.
20 * Portions created by Markus L. Noga are Copyright (C) 1999
21 * Markus L. Noga. All Rights Reserved.
22 *
23 * Contributor(s): Markus L. Noga <markus@noga.de>
24 */
25
26#ifndef __sys_mm_h__
27#define __sys_mm_h__
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <config.h>
34
35#ifdef CONF_MM
36
37#include <mem.h>
38#include <stdlib.h>
39
40
42//
43// Definitions
44//
46
47#define MM_FREE 0x0000
48#define MM_RESERVED 0xffff
49
50// as data generally nees to be word aligned, 1 unit ^= 2 bytes
51//
52
53#define MM_HEADER_SIZE 2
54#define MM_SPLIT_THRESH (MM_HEADER_SIZE+8)
55
56extern size_t mm_start;
57
58extern size_t* mm_first_free;
59
60// Macros for mm_init()
61// Always alternate FREE and RESERVED.
62//
63
65
68#define MM_BLOCK_FREE(addr) \
69 next=(size_t*)(addr); \
70 *current=((((size_t)next)-(size_t)current)-2)>>1; \
71 *(next++)=MM_FREE; \
72 current=next;
73
74
76
79#define MM_BLOCK_RESERVED(addr) \
80 next=(size_t*)(((size_t)addr)-4); \
81 *current=((((size_t)next)-(size_t)current)-2)>>1; \
82 *(next++)=MM_RESERVED; \
83 current=next;
84
85
87//
88// Functions
89//
91
93extern void mm_init();
94
96extern void mm_reaper();
97
99extern int mm_free_mem(void);
100
101#endif // CONF_MM
102
103#ifdef __cplusplus
104}
105#endif
106
107#endif // __sys_mm_h__
kernel configuration file
Interface: memory data types.
int mm_free_mem(void)
how many bytes of memory are free?
void mm_init()
initialize memory management
void mm_reaper()
free all blocks allocated by the current process
size_t mm_start
end of kernel code + data
size_t * mm_first_free
ptr to first free block.
Interface: reduced standard C library.