david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Rename e{malloc,realloc,free} to u{malloc,realloc,free}, to more obviously

reflect the fact that they allocate and deallocate user memory (i.e.
things reached through a userptr_t).
This commit is contained in:
Michael Brown 2007-01-16 08:36:42 +00:00
parent ff8528ea9a
commit 544fa25928
8 changed files with 42 additions and 43 deletions

View File

@ -25,7 +25,7 @@
#include <gpxe/uaccess.h>
#include <gpxe/hidemem.h>
#include <gpxe/emalloc.h>
#include <gpxe/umalloc.h>
/** Alignment of external allocated memory */
#define EM_ALIGN ( 4 * 1024 )
@ -76,14 +76,14 @@ static void ecollect_free ( void ) {
/**
* Reallocate external memory
*
* @v old_ptr Memory previously allocated by emalloc(), or UNULL
* @v old_ptr Memory previously allocated by umalloc(), or UNULL
* @v new_size Requested size
* @ret new_ptr Allocated memory, or UNULL
*
* Calling realloc() with a new size of zero is a valid way to free a
* memory block.
*/
userptr_t erealloc ( userptr_t ptr, size_t new_size ) {
userptr_t urealloc ( userptr_t ptr, size_t new_size ) {
struct external_memory extmem;
userptr_t new = ptr;
size_t align;
@ -153,17 +153,17 @@ userptr_t erealloc ( userptr_t ptr, size_t new_size ) {
*
* Memory is guaranteed to be aligned to a page boundary.
*/
userptr_t emalloc ( size_t size ) {
return erealloc ( UNULL, size );
userptr_t umalloc ( size_t size ) {
return urealloc ( UNULL, size );
}
/**
* Free external memory
*
* @v ptr Memory allocated by emalloc(), or UNULL
* @v ptr Memory allocated by umalloc(), or UNULL
*
* If @c ptr is UNULL, no action is taken.
*/
void efree ( userptr_t ptr ) {
erealloc ( ptr, 0 );
void ufree ( userptr_t ptr ) {
urealloc ( ptr, 0 );
}

View File

@ -25,7 +25,7 @@
#include <errno.h>
#include <gpxe/buffer.h>
#include <gpxe/emalloc.h>
#include <gpxe/umalloc.h>
#include <gpxe/ebuffer.h>
/**
@ -46,7 +46,7 @@ static int ebuffer_expand ( struct buffer *buffer, size_t new_len ) {
actual_len <<= 1;
/* Reallocate buffer */
new_addr = erealloc ( buffer->addr, actual_len );
new_addr = urealloc ( buffer->addr, actual_len );
if ( ! new_addr )
return -ENOMEM;
@ -63,7 +63,7 @@ static int ebuffer_expand ( struct buffer *buffer, size_t new_len ) {
* @ret rc Return status code
*
* Allocates space for the buffer and stores it in @c buffer->addr.
* The space must eventually be freed by calling efree(buffer->addr).
* The space must eventually be freed by calling ufree(buffer->addr).
*/
int ebuffer_alloc ( struct buffer *buffer, size_t len ) {
memset ( buffer, 0, sizeof ( *buffer ) );

View File

@ -23,7 +23,6 @@
#include <assert.h>
#include <vsprintf.h>
#include <gpxe/list.h>
#include <gpxe/emalloc.h>
#include <gpxe/image.h>
/** @file

View File

@ -1,17 +0,0 @@
#ifndef _GPXE_EMALLOC_H
#define _GPXE_EMALLOC_H
/**
* @file
*
* External memory allocation
*
*/
#include <gpxe/uaccess.h>
extern userptr_t emalloc ( size_t size );
extern userptr_t erealloc ( userptr_t ptr, size_t new_size );
extern void efree ( userptr_t ptr );
#endif /* _GPXE_EMALLOC_H */

View File

@ -0,0 +1,17 @@
#ifndef _GPXE_UMALLOC_H
#define _GPXE_UMALLOC_H
/**
* @file
*
* User memory allocation
*
*/
#include <gpxe/uaccess.h>
extern userptr_t umalloc ( size_t size );
extern userptr_t urealloc ( userptr_t ptr, size_t new_size );
extern void ufree ( userptr_t ptr );
#endif /* _GPXE_UMALLOC_H */

View File

@ -1,9 +1,9 @@
#include <vsprintf.h>
#include <gpxe/uaccess.h>
#include <gpxe/emalloc.h>
#include <gpxe/umalloc.h>
#include <gpxe/memmap.h>
void emalloc_test ( void ) {
void umalloc_test ( void ) {
struct memory_map memmap;
userptr_t bob;
userptr_t fred;
@ -11,15 +11,15 @@ void emalloc_test ( void ) {
printf ( "Before allocation:\n" );
get_memmap ( &memmap );
bob = emalloc ( 1234 );
bob = erealloc ( bob, 12345 );
fred = emalloc ( 999 );
bob = ymalloc ( 1234 );
bob = yrealloc ( bob, 12345 );
fred = ymalloc ( 999 );
printf ( "After allocation:\n" );
get_memmap ( &memmap );
efree ( bob );
efree ( fred );
ufree ( bob );
ufree ( fred );
printf ( "After freeing:\n" );
get_memmap ( &memmap );

View File

@ -25,7 +25,7 @@
#include <errno.h>
#include <vsprintf.h>
#include <gpxe/emalloc.h>
#include <gpxe/umalloc.h>
#include <gpxe/ebuffer.h>
#include <gpxe/image.h>
#include <gpxe/uri.h>
@ -45,9 +45,9 @@
* @ret len Length of loaded file
* @ret rc Return status code
*
* Fetch file to an external buffer allocated with emalloc(). The
* Fetch file to an external buffer allocated with umalloc(). The
* caller is responsible for eventually freeing the buffer with
* efree().
* ufree().
*/
int fetch ( const char *uri_string, userptr_t *data, size_t *len ) {
struct uri *uri;
@ -101,7 +101,7 @@ int fetch ( const char *uri_string, userptr_t *data, size_t *len ) {
return 0;
err:
efree ( buffer.addr );
ufree ( buffer.addr );
err_ebuffer_alloc:
free_uri ( uri );
err_parse_uri:

View File

@ -21,7 +21,7 @@
#include <errno.h>
#include <vsprintf.h>
#include <gpxe/image.h>
#include <gpxe/emalloc.h>
#include <gpxe/umalloc.h>
#include <usr/fetch.h>
#include <usr/imgmgmt.h>
@ -66,7 +66,7 @@ int imgfetch ( const char *filename, const char *name,
return 0;
err:
efree ( image->data );
ufree ( image->data );
free ( image );
return rc;
}
@ -139,6 +139,6 @@ void imgstat ( struct image *image ) {
*/
void imgfree ( struct image *image ) {
unregister_image ( image );
efree ( image->data );
ufree ( image->data );
free ( image );
}