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

Loading…
Cancel
Save