Преглед на файлове

[umalloc] Formalise the user memory allocation API

tags/v0.9.6
Michael Brown преди 16 години
родител
ревизия
831e4cfc27

+ 1
- 1
src/arch/i386/include/bits/errfile.h Целия файл

@@ -6,7 +6,7 @@
6 6
  * @{
7 7
  */
8 8
 
9
-#define ERRFILE_umalloc		( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 )
9
+#define ERRFILE_memtop_umalloc	( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 )
10 10
 #define ERRFILE_memmap		( ERRFILE_ARCH | ERRFILE_CORE | 0x00010000 )
11 11
 #define ERRFILE_pnpbios		( ERRFILE_ARCH | ERRFILE_CORE | 0x00020000 )
12 12
 #define ERRFILE_smbios		( ERRFILE_ARCH | ERRFILE_CORE | 0x00030000 )

+ 12
- 0
src/arch/i386/include/bits/umalloc.h Целия файл

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_UMALLOC_H
2
+#define _BITS_UMALLOC_H
3
+
4
+/** @file
5
+ *
6
+ * i386-specific user memory allocation API implementations
7
+ *
8
+ */
9
+
10
+#include <gpxe/memtop_umalloc.h>
11
+
12
+#endif /* _BITS_UMALLOC_H */

+ 16
- 0
src/arch/i386/include/gpxe/memtop_umalloc.h Целия файл

@@ -0,0 +1,16 @@
1
+#ifndef _GPXE_MEMTOP_UMALLOC_H
2
+#define _GPXE_MEMTOP_UMALLOC_H
3
+
4
+/** @file
5
+ *
6
+ * External memory allocation
7
+ *
8
+ */
9
+
10
+#ifdef UMALLOC_MEMTOP
11
+#define UMALLOC_PREFIX_memtop
12
+#else
13
+#define UMALLOC_PREFIX_memtop __memtop_
14
+#endif
15
+
16
+#endif /* _GPXE_MEMTOP_UMALLOC_H */

src/arch/i386/core/umalloc.c → src/arch/i386/interface/pcbios/memtop_umalloc.c Целия файл

@@ -36,9 +36,6 @@
36 36
 /** Equivalent of NOWHERE for user pointers */
37 37
 #define UNOWHERE ( ~UNULL )
38 38
 
39
-/** Start of Etherboot text, as defined by the linker */
40
-extern char _text[];
41
-
42 39
 /** An external memory block */
43 40
 struct external_memory {
44 41
 	/** Size of this memory block (excluding this header) */
@@ -135,7 +132,7 @@ static void ecollect_free ( void ) {
135 132
  * Calling realloc() with a new size of zero is a valid way to free a
136 133
  * memory block.
137 134
  */
138
-userptr_t urealloc ( userptr_t ptr, size_t new_size ) {
135
+static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
139 136
 	struct external_memory extmem;
140 137
 	userptr_t new = ptr;
141 138
 	size_t align;
@@ -200,25 +197,4 @@ userptr_t urealloc ( userptr_t ptr, size_t new_size ) {
200 197
 	return ( new_size ? new : UNOWHERE );
201 198
 }
202 199
 
203
-/**
204
- * Allocate external memory
205
- *
206
- * @v size		Requested size
207
- * @ret ptr		Memory, or UNULL
208
- *
209
- * Memory is guaranteed to be aligned to a page boundary.
210
- */
211
-userptr_t umalloc ( size_t size ) {
212
-	return urealloc ( UNULL, size );
213
-}
214
-
215
-/**
216
- * Free external memory
217
- *
218
- * @v ptr		Memory allocated by umalloc(), or UNULL
219
- *
220
- * If @c ptr is UNULL, no action is taken.
221
- */
222
-void ufree ( userptr_t ptr ) {
223
-	urealloc ( ptr, 0 );
224
-}
200
+PROVIDE_UMALLOC ( memtop, urealloc, memtop_urealloc );

+ 1
- 0
src/config/defaults/pcbios.h Целия файл

@@ -13,5 +13,6 @@
13 13
 #define TIMER_PCBIOS
14 14
 #define CONSOLE_PCBIOS
15 15
 #define NAP_PCBIOS
16
+#define UMALLOC_MEMTOP
16 17
 
17 18
 #endif /* CONFIG_DEFAULTS_PCBIOS_H */

+ 12
- 0
src/config/umalloc.h Целия файл

@@ -0,0 +1,12 @@
1
+#ifndef CONFIG_UMALLOC_H
2
+#define CONFIG_UMALLOC_H
3
+
4
+/** @file
5
+ *
6
+ * User memory allocation API configuration
7
+ *
8
+ */
9
+
10
+#include <config/defaults.h>
11
+
12
+#endif /* CONFIG_UMALLOC_H */

+ 51
- 3
src/include/gpxe/umalloc.h Целия файл

@@ -8,10 +8,58 @@
8 8
  *
9 9
  */
10 10
 
11
+#include <gpxe/api.h>
12
+#include <config/umalloc.h>
11 13
 #include <gpxe/uaccess.h>
12 14
 
13
-extern userptr_t umalloc ( size_t size );
14
-extern userptr_t urealloc ( userptr_t ptr, size_t new_size );
15
-extern void ufree ( userptr_t ptr );
15
+/**
16
+ * Provide a user memory allocation API implementation
17
+ *
18
+ * @v _prefix		Subsystem prefix
19
+ * @v _api_func		API function
20
+ * @v _func		Implementing function
21
+ */
22
+#define PROVIDE_UMALLOC( _subsys, _api_func, _func ) \
23
+	PROVIDE_SINGLE_API ( UMALLOC_PREFIX_ ## _subsys, _api_func, _func )
24
+
25
+/* Include all architecture-independent I/O API headers */
26
+
27
+/* Include all architecture-dependent I/O API headers */
28
+#include <bits/umalloc.h>
29
+
30
+/**
31
+ * Reallocate external memory
32
+ *
33
+ * @v userptr		Memory previously allocated by umalloc(), or UNULL
34
+ * @v new_size		Requested size
35
+ * @ret userptr		Allocated memory, or UNULL
36
+ *
37
+ * Calling realloc() with a new size of zero is a valid way to free a
38
+ * memory block.
39
+ */
40
+userptr_t urealloc ( userptr_t userptr, size_t new_size );
41
+
42
+/**
43
+ * Allocate external memory
44
+ *
45
+ * @v size		Requested size
46
+ * @ret userptr		Memory, or UNULL
47
+ *
48
+ * Memory is guaranteed to be aligned to a page boundary.
49
+ */
50
+static inline __always_inline userptr_t umalloc ( size_t size ) {
51
+	return urealloc ( UNULL, size );
52
+}
53
+
54
+/**
55
+ * Free external memory
56
+ *
57
+ * @v userptr		Memory allocated by umalloc(), or UNULL
58
+ *
59
+ * If @c ptr is UNULL, no action is taken.
60
+ */
61
+static inline __always_inline void ufree ( userptr_t userptr ) {
62
+	urealloc ( userptr, 0 );
63
+}
16 64
 
17 65
 #endif /* _GPXE_UMALLOC_H */

Loading…
Отказ
Запис