Browse Source

Move include/malloc.h to include/gpxe/malloc.h, since everything in there

is now gPXE-specific.  (The standard malloc() et al have been in stdlib.h
for a while).

Add free memory counter.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
6d4e37cf42
4 changed files with 19 additions and 8 deletions
  1. 1
    1
      src/core/heap.c
  2. 10
    1
      src/core/malloc.c
  3. 7
    5
      src/include/gpxe/malloc.h
  4. 1
    1
      src/net/pkbuff.c

+ 1
- 1
src/core/heap.c View File

1
-#include <malloc.h>
1
+#include <gpxe/malloc.h>
2
 #include <gpxe/heap.h>
2
 #include <gpxe/heap.h>
3
 
3
 
4
 /**
4
 /**

+ 10
- 1
src/core/malloc.c View File

22
 #include <strings.h>
22
 #include <strings.h>
23
 #include <io.h>
23
 #include <io.h>
24
 #include <gpxe/list.h>
24
 #include <gpxe/list.h>
25
-#include <malloc.h>
25
+#include <gpxe/malloc.h>
26
 
26
 
27
 /** @file
27
 /** @file
28
  *
28
  *
69
 /** List of free memory blocks */
69
 /** List of free memory blocks */
70
 static LIST_HEAD ( free_blocks );
70
 static LIST_HEAD ( free_blocks );
71
 
71
 
72
+/** Total amount of free memory */
73
+size_t freemem;
74
+
72
 /**
75
 /**
73
  * Allocate a memory block
76
  * Allocate a memory block
74
  *
77
  *
134
 			 */
137
 			 */
135
 			if ( pre_size < MIN_MEMBLOCK_SIZE )
138
 			if ( pre_size < MIN_MEMBLOCK_SIZE )
136
 				list_del ( &pre->list );
139
 				list_del ( &pre->list );
140
+			/* Update total free memory */
141
+			freemem -= size;
142
+			/* Return allocated block */
137
 			DBG ( "Allocated [%p,%p)\n", block,
143
 			DBG ( "Allocated [%p,%p)\n", block,
138
 			      ( ( ( void * ) block ) + size ) );
144
 			      ( ( ( void * ) block ) + size ) );
139
 			return block;
145
 			return block;
206
 		freeing->size += block->size;
212
 		freeing->size += block->size;
207
 		list_del ( &block->list );
213
 		list_del ( &block->list );
208
 	}
214
 	}
215
+
216
+	/* Update free memory counter */
217
+	freemem += size;
209
 }
218
 }
210
 
219
 
211
 /**
220
 /**

src/include/malloc.h → src/include/gpxe/malloc.h View File

1
-#ifndef _MALLOC_H
2
-#define _MALLOC_H
1
+#ifndef _GPXE_MALLOC_H
2
+#define _GPXE_MALLOC_H
3
 
3
 
4
 #include <stdint.h>
4
 #include <stdint.h>
5
 
5
 
11
 
11
 
12
 /*
12
 /*
13
  * Prototypes for the standard functions (malloc() et al) are in
13
  * Prototypes for the standard functions (malloc() et al) are in
14
- * stdlib.h.  Include <malloc.h> only if you need the non-standard
15
- * functions, such as malloc_dma().
14
+ * stdlib.h.  Include <gpxe/malloc.h> only if you need the
15
+ * non-standard functions, such as malloc_dma().
16
  *
16
  *
17
  */
17
  */
18
 #include <stdlib.h>
18
 #include <stdlib.h>
19
 
19
 
20
+extern size_t freemem;
21
+
20
 extern void * alloc_memblock ( size_t size, size_t align );
22
 extern void * alloc_memblock ( size_t size, size_t align );
21
 extern void free_memblock ( void *ptr, size_t size );
23
 extern void free_memblock ( void *ptr, size_t size );
22
 extern void mpopulate ( void *start, size_t len );
24
 extern void mpopulate ( void *start, size_t len );
52
 	free_memblock ( ptr, size );
54
 	free_memblock ( ptr, size );
53
 }
55
 }
54
 
56
 
55
-#endif /* _MALLOC_H */
57
+#endif /* _GPXE_MALLOC_H */

+ 1
- 1
src/net/pkbuff.c View File

17
  */
17
  */
18
 
18
 
19
 #include <stdint.h>
19
 #include <stdint.h>
20
-#include <malloc.h>
20
+#include <gpxe/malloc.h>
21
 #include <gpxe/pkbuff.h>
21
 #include <gpxe/pkbuff.h>
22
 
22
 
23
 /** @file
23
 /** @file

Loading…
Cancel
Save