Bladeren bron

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 jaren geleden
bovenliggende
commit
6d4e37cf42
4 gewijzigde bestanden met toevoegingen van 19 en 8 verwijderingen
  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 Bestand weergeven

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

+ 10
- 1
src/core/malloc.c Bestand weergeven

@@ -22,7 +22,7 @@
22 22
 #include <strings.h>
23 23
 #include <io.h>
24 24
 #include <gpxe/list.h>
25
-#include <malloc.h>
25
+#include <gpxe/malloc.h>
26 26
 
27 27
 /** @file
28 28
  *
@@ -69,6 +69,9 @@ struct autosized_block {
69 69
 /** List of free memory blocks */
70 70
 static LIST_HEAD ( free_blocks );
71 71
 
72
+/** Total amount of free memory */
73
+size_t freemem;
74
+
72 75
 /**
73 76
  * Allocate a memory block
74 77
  *
@@ -134,6 +137,9 @@ void * alloc_memblock ( size_t size, size_t align ) {
134 137
 			 */
135 138
 			if ( pre_size < MIN_MEMBLOCK_SIZE )
136 139
 				list_del ( &pre->list );
140
+			/* Update total free memory */
141
+			freemem -= size;
142
+			/* Return allocated block */
137 143
 			DBG ( "Allocated [%p,%p)\n", block,
138 144
 			      ( ( ( void * ) block ) + size ) );
139 145
 			return block;
@@ -206,6 +212,9 @@ void free_memblock ( void *ptr, size_t size ) {
206 212
 		freeing->size += block->size;
207 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 Bestand weergeven

@@ -1,5 +1,5 @@
1
-#ifndef _MALLOC_H
2
-#define _MALLOC_H
1
+#ifndef _GPXE_MALLOC_H
2
+#define _GPXE_MALLOC_H
3 3
 
4 4
 #include <stdint.h>
5 5
 
@@ -11,12 +11,14 @@
11 11
 
12 12
 /*
13 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 18
 #include <stdlib.h>
19 19
 
20
+extern size_t freemem;
21
+
20 22
 extern void * alloc_memblock ( size_t size, size_t align );
21 23
 extern void free_memblock ( void *ptr, size_t size );
22 24
 extern void mpopulate ( void *start, size_t len );
@@ -52,4 +54,4 @@ static inline void free_dma ( void *ptr, size_t size ) {
52 54
 	free_memblock ( ptr, size );
53 55
 }
54 56
 
55
-#endif /* _MALLOC_H */
57
+#endif /* _GPXE_MALLOC_H */

+ 1
- 1
src/net/pkbuff.c Bestand weergeven

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

Laden…
Annuleren
Opslaan