Browse Source

Fix the only bug (which was to use DBGC() in place of DBG()!) and add 4kB

alignment.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
77b7640af4
1 changed files with 9 additions and 2 deletions
  1. 9
    2
      src/arch/i386/core/emalloc.c

+ 9
- 2
src/arch/i386/core/emalloc.c View File

@@ -27,6 +27,9 @@
27 27
 #include <gpxe/hidemem.h>
28 28
 #include <gpxe/emalloc.h>
29 29
 
30
+/** Alignment of external allocated memory */
31
+#define EM_ALIGN ( 4 * 1024 )
32
+
30 33
 /** Equivalent of NOWHERE for user pointers */
31 34
 #define UNOWHERE ( ~UNULL )
32 35
 
@@ -80,6 +83,7 @@ static void ecollect_free ( void ) {
80 83
 userptr_t erealloc ( userptr_t ptr, size_t new_size ) {
81 84
 	struct external_memory extmem;
82 85
 	userptr_t new = ptr;
86
+	size_t align;
83 87
 
84 88
 	/* Initialise external memory allocator if necessary */
85 89
 	if ( ! bottom  )
@@ -93,8 +97,8 @@ userptr_t erealloc ( userptr_t ptr, size_t new_size ) {
93 97
 	} else {
94 98
 		/* Create a zero-length block */
95 99
 		ptr = bottom = userptr_add ( bottom, -sizeof ( extmem ) );
96
-		DBGC ( "EXTMEM allocating [%lx,%lx)\n",
97
-		       user_to_phys ( ptr, 0 ), user_to_phys ( ptr, 0 ) );
100
+		DBG ( "EXTMEM allocating [%lx,%lx)\n",
101
+		      user_to_phys ( ptr, 0 ), user_to_phys ( ptr, 0 ) );
98 102
 		extmem.size = 0;
99 103
 	}
100 104
 	extmem.used = ( new_size > 0 );
@@ -103,6 +107,9 @@ userptr_t erealloc ( userptr_t ptr, size_t new_size ) {
103 107
 	if ( ptr == bottom ) {
104 108
 		/* Update block */
105 109
 		new = userptr_add ( ptr, - ( new_size - extmem.size ) );
110
+		align = ( user_to_phys ( new, 0 ) & ( EM_ALIGN - 1 ) );
111
+		new_size += align;
112
+		new = userptr_add ( new, -align );
106 113
 		DBG ( "EXTMEM expanding [%lx,%lx) to [%lx,%lx)\n",
107 114
 		      user_to_phys ( ptr, 0 ),
108 115
 		      user_to_phys ( ptr, extmem.size ),

Loading…
Cancel
Save