mirror of
https://github.com/ipxe/ipxe
synced 2025-12-16 17:41:18 +03:00
[uaccess] Remove redundant userptr_add() and userptr_diff()
The userptr_add() and userptr_diff() functions are now just straightforward wrappers around addition and subtraction. Remove these redundant wrappers. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -431,7 +431,7 @@ static int bzimage_check_initrds ( struct image *image,
|
||||
}
|
||||
|
||||
/* Calculate lowest usable address */
|
||||
bottom = userptr_add ( bzimg->pm_kernel, bzimg->pm_sz );
|
||||
bottom = ( bzimg->pm_kernel + bzimg->pm_sz );
|
||||
|
||||
/* Check that total length fits within space available for
|
||||
* reshuffling. This is a conservative check, since CPIO
|
||||
@@ -471,14 +471,12 @@ static void bzimage_load_initrds ( struct image *image,
|
||||
size_t len;
|
||||
|
||||
/* Reshuffle initrds into desired order */
|
||||
initrd_reshuffle ( userptr_add ( bzimg->pm_kernel, bzimg->pm_sz ) );
|
||||
initrd_reshuffle ( bzimg->pm_kernel + bzimg->pm_sz );
|
||||
|
||||
/* Find highest initrd */
|
||||
for_each_image ( initrd ) {
|
||||
if ( ( highest == NULL ) ||
|
||||
( userptr_diff ( initrd->data, highest->data ) > 0 ) ) {
|
||||
if ( ( highest == NULL ) || ( initrd->data > highest->data ) )
|
||||
highest = initrd;
|
||||
}
|
||||
}
|
||||
|
||||
/* Do nothing if there are no initrds */
|
||||
@@ -486,7 +484,7 @@ static void bzimage_load_initrds ( struct image *image,
|
||||
return;
|
||||
|
||||
/* Find highest usable address */
|
||||
top = userptr_add ( highest->data, bzimage_align ( highest->len ) );
|
||||
top = ( highest->data + bzimage_align ( highest->len ) );
|
||||
if ( user_to_phys ( top, -1 ) > bzimg->mem_limit ) {
|
||||
top = phys_to_user ( ( bzimg->mem_limit + 1 ) &
|
||||
~( INITRD_ALIGN - 1 ) );
|
||||
@@ -509,7 +507,7 @@ static void bzimage_load_initrds ( struct image *image,
|
||||
}
|
||||
|
||||
/* Load initrd at this address */
|
||||
dest = userptr_add ( top, -offset );
|
||||
dest = ( top - offset );
|
||||
len = bzimage_load_initrd ( image, initrd, dest );
|
||||
|
||||
/* Record initrd location */
|
||||
|
||||
@@ -61,10 +61,9 @@ static userptr_t initrd_squash_high ( userptr_t top ) {
|
||||
/* Find the highest image not yet in its final position */
|
||||
highest = NULL;
|
||||
for_each_image ( initrd ) {
|
||||
if ( ( userptr_diff ( initrd->data, current ) < 0 ) &&
|
||||
if ( ( initrd->data < current ) &&
|
||||
( ( highest == NULL ) ||
|
||||
( userptr_diff ( initrd->data,
|
||||
highest->data ) > 0 ) ) ) {
|
||||
( initrd->data > highest->data ) ) ) {
|
||||
highest = initrd;
|
||||
}
|
||||
}
|
||||
@@ -74,7 +73,7 @@ static userptr_t initrd_squash_high ( userptr_t top ) {
|
||||
/* Move this image to its final position */
|
||||
len = ( ( highest->len + INITRD_ALIGN - 1 ) &
|
||||
~( INITRD_ALIGN - 1 ) );
|
||||
current = userptr_add ( current, -len );
|
||||
current -= len;
|
||||
DBGC ( &images, "INITRD squashing %s [%#08lx,%#08lx)->"
|
||||
"[%#08lx,%#08lx)\n", highest->name,
|
||||
user_to_phys ( highest->data, 0 ),
|
||||
@@ -87,10 +86,10 @@ static userptr_t initrd_squash_high ( userptr_t top ) {
|
||||
|
||||
/* Copy any remaining initrds (e.g. embedded images) to the region */
|
||||
for_each_image ( initrd ) {
|
||||
if ( userptr_diff ( initrd->data, top ) >= 0 ) {
|
||||
if ( initrd->data >= top ) {
|
||||
len = ( ( initrd->len + INITRD_ALIGN - 1 ) &
|
||||
~( INITRD_ALIGN - 1 ) );
|
||||
current = userptr_add ( current, -len );
|
||||
current -= len;
|
||||
DBGC ( &images, "INITRD copying %s [%#08lx,%#08lx)->"
|
||||
"[%#08lx,%#08lx)\n", initrd->name,
|
||||
user_to_phys ( initrd->data, 0 ),
|
||||
@@ -149,7 +148,7 @@ static void initrd_swap ( struct image *low, struct image *high,
|
||||
|
||||
/* Adjust data pointers */
|
||||
high->data = low->data;
|
||||
low->data = userptr_add ( low->data, len );
|
||||
low->data += len;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +170,7 @@ static int initrd_swap_any ( userptr_t free, size_t free_len ) {
|
||||
/* Calculate location of adjacent image (if any) */
|
||||
padded_len = ( ( low->len + INITRD_ALIGN - 1 ) &
|
||||
~( INITRD_ALIGN - 1 ) );
|
||||
adjacent = userptr_add ( low->data, padded_len );
|
||||
adjacent = ( low->data + padded_len );
|
||||
|
||||
/* Search for adjacent image */
|
||||
for_each_image ( high ) {
|
||||
@@ -235,7 +234,7 @@ void initrd_reshuffle ( userptr_t bottom ) {
|
||||
|
||||
/* Calculate limits of available space for initrds */
|
||||
top = initrd_top;
|
||||
if ( userptr_diff ( initrd_bottom, bottom ) > 0 )
|
||||
if ( initrd_bottom > bottom )
|
||||
bottom = initrd_bottom;
|
||||
|
||||
/* Debug */
|
||||
@@ -248,7 +247,7 @@ void initrd_reshuffle ( userptr_t bottom ) {
|
||||
|
||||
/* Calculate available free space */
|
||||
free = bottom;
|
||||
free_len = userptr_diff ( used, free );
|
||||
free_len = ( used - free );
|
||||
|
||||
/* Bubble-sort initrds into desired order */
|
||||
while ( initrd_swap_any ( free, free_len ) ) {}
|
||||
@@ -270,9 +269,9 @@ int initrd_reshuffle_check ( size_t len, userptr_t bottom ) {
|
||||
|
||||
/* Calculate limits of available space for initrds */
|
||||
top = initrd_top;
|
||||
if ( userptr_diff ( initrd_bottom, bottom ) > 0 )
|
||||
if ( initrd_bottom > bottom )
|
||||
bottom = initrd_bottom;
|
||||
available = userptr_diff ( top, bottom );
|
||||
available = ( top - bottom );
|
||||
|
||||
/* Allow for a sensible minimum amount of free space */
|
||||
len += INITRD_MIN_FREE_LEN;
|
||||
@@ -296,7 +295,7 @@ static void initrd_startup ( void ) {
|
||||
* can safely reuse when rearranging).
|
||||
*/
|
||||
len = largest_memblock ( &initrd_bottom );
|
||||
initrd_top = userptr_add ( initrd_bottom, len );
|
||||
initrd_top = ( initrd_bottom + len );
|
||||
}
|
||||
|
||||
/** initrd startup function */
|
||||
|
||||
@@ -184,10 +184,10 @@ static int nbi_process_segments ( struct image *image,
|
||||
dest = phys_to_user ( sh.loadaddr );
|
||||
break;
|
||||
case NBI_LOADADDR_AFTER:
|
||||
dest = userptr_add ( dest, memsz + sh.loadaddr );
|
||||
dest = ( dest + memsz + sh.loadaddr );
|
||||
break;
|
||||
case NBI_LOADADDR_BEFORE:
|
||||
dest = userptr_add ( dest, -sh.loadaddr );
|
||||
dest = ( dest - sh.loadaddr );
|
||||
break;
|
||||
case NBI_LOADADDR_END:
|
||||
/* Not correct according to the spec, but
|
||||
|
||||
@@ -137,17 +137,6 @@ UACCESS_INLINE ( librm, user_to_virt ) ( userptr_t userptr, off_t offset ) {
|
||||
return trivial_user_to_virt ( userptr, offset );
|
||||
}
|
||||
|
||||
static inline __always_inline userptr_t
|
||||
UACCESS_INLINE ( librm, userptr_add ) ( userptr_t userptr, off_t offset ) {
|
||||
return trivial_userptr_add ( userptr, offset );
|
||||
}
|
||||
|
||||
static inline __always_inline off_t
|
||||
UACCESS_INLINE ( librm, userptr_diff ) ( userptr_t userptr,
|
||||
userptr_t subtrahend ) {
|
||||
return trivial_userptr_diff ( userptr, subtrahend );
|
||||
}
|
||||
|
||||
static inline __always_inline void
|
||||
UACCESS_INLINE ( librm, memcpy_user ) ( userptr_t dest, off_t dest_off,
|
||||
userptr_t src, off_t src_off,
|
||||
|
||||
@@ -122,7 +122,7 @@ static void init_eheap ( void ) {
|
||||
userptr_t base;
|
||||
|
||||
heap_size = largest_memblock ( &base );
|
||||
bottom = top = userptr_add ( base, heap_size );
|
||||
bottom = top = ( base + heap_size );
|
||||
DBG ( "External heap grows downwards from %lx (size %zx)\n",
|
||||
user_to_phys ( top, 0 ), heap_size );
|
||||
}
|
||||
@@ -144,7 +144,7 @@ static void ecollect_free ( void ) {
|
||||
DBG ( "EXTMEM freeing [%lx,%lx)\n", user_to_phys ( bottom, 0 ),
|
||||
user_to_phys ( bottom, extmem.size ) );
|
||||
len = ( extmem.size + sizeof ( extmem ) );
|
||||
bottom = userptr_add ( bottom, len );
|
||||
bottom += len;
|
||||
heap_size += len;
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,7 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
|
||||
DBG ( "EXTMEM out of space\n" );
|
||||
return UNULL;
|
||||
}
|
||||
ptr = bottom = userptr_add ( bottom, -sizeof ( extmem ) );
|
||||
ptr = bottom = ( bottom - sizeof ( extmem ) );
|
||||
heap_size -= sizeof ( extmem );
|
||||
DBG ( "EXTMEM allocating [%lx,%lx)\n",
|
||||
user_to_phys ( ptr, 0 ), user_to_phys ( ptr, 0 ) );
|
||||
@@ -190,10 +190,10 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
|
||||
/* Expand/shrink block if possible */
|
||||
if ( ptr == bottom ) {
|
||||
/* Update block */
|
||||
new = userptr_add ( ptr, - ( new_size - extmem.size ) );
|
||||
new = ( ptr - ( new_size - extmem.size ) );
|
||||
align = ( user_to_phys ( new, 0 ) & ( EM_ALIGN - 1 ) );
|
||||
new_size += align;
|
||||
new = userptr_add ( new, -align );
|
||||
new -= align;
|
||||
if ( new_size > ( heap_size + extmem.size ) ) {
|
||||
DBG ( "EXTMEM out of space\n" );
|
||||
return UNULL;
|
||||
|
||||
@@ -432,7 +432,6 @@ PROVIDE_UACCESS_INLINE ( librm, phys_to_user );
|
||||
PROVIDE_UACCESS_INLINE ( librm, user_to_phys );
|
||||
PROVIDE_UACCESS_INLINE ( librm, virt_to_user );
|
||||
PROVIDE_UACCESS_INLINE ( librm, user_to_virt );
|
||||
PROVIDE_UACCESS_INLINE ( librm, userptr_add );
|
||||
PROVIDE_UACCESS_INLINE ( librm, memcpy_user );
|
||||
PROVIDE_UACCESS_INLINE ( librm, memmove_user );
|
||||
PROVIDE_UACCESS_INLINE ( librm, memset_user );
|
||||
|
||||
@@ -625,7 +625,7 @@ static int sandev_rw ( struct san_device *sandev, uint64_t lba,
|
||||
|
||||
/* Move to next fragment */
|
||||
frag_len = ( sandev->capacity.blksize * params.rw.count );
|
||||
params.rw.buffer = userptr_add ( params.rw.buffer, frag_len );
|
||||
params.rw.buffer += frag_len;
|
||||
params.rw.lba += params.rw.count;
|
||||
remaining -= params.rw.count;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ PROVIDE_UACCESS_INLINE ( flat, phys_to_user );
|
||||
PROVIDE_UACCESS_INLINE ( flat, user_to_phys );
|
||||
PROVIDE_UACCESS_INLINE ( flat, virt_to_user );
|
||||
PROVIDE_UACCESS_INLINE ( flat, user_to_virt );
|
||||
PROVIDE_UACCESS_INLINE ( flat, userptr_add );
|
||||
PROVIDE_UACCESS_INLINE ( flat, memcpy_user );
|
||||
PROVIDE_UACCESS_INLINE ( flat, memmove_user );
|
||||
PROVIDE_UACCESS_INLINE ( flat, memset_user );
|
||||
|
||||
@@ -807,7 +807,7 @@ static inline __attribute__ (( always_inline )) userptr_t
|
||||
gve_buffer ( struct gve_queue *queue, unsigned int index ) {
|
||||
|
||||
/* Pages are currently allocated as a single contiguous block */
|
||||
return userptr_add ( queue->qpl.data, gve_address ( queue, index ) );
|
||||
return ( queue->qpl.data + gve_address ( queue, index ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -111,7 +111,7 @@ static int gzip_extract ( struct image *image, struct image *extracted ) {
|
||||
}
|
||||
|
||||
/* Initialise input chunk */
|
||||
deflate_chunk_init ( &in, userptr_add ( image->data, offset ), 0, len );
|
||||
deflate_chunk_init ( &in, ( image->data + offset ), 0, len );
|
||||
|
||||
/* Presize extracted image */
|
||||
if ( ( rc = image_set_len ( extracted,
|
||||
|
||||
@@ -69,17 +69,6 @@ UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) {
|
||||
return trivial_user_to_virt ( userptr, offset );
|
||||
}
|
||||
|
||||
static inline __always_inline userptr_t
|
||||
UACCESS_INLINE ( linux, userptr_add ) ( userptr_t userptr, off_t offset ) {
|
||||
return trivial_userptr_add ( userptr, offset );
|
||||
}
|
||||
|
||||
static inline __always_inline off_t
|
||||
UACCESS_INLINE ( linux, userptr_diff ) ( userptr_t userptr,
|
||||
userptr_t subtrahend ) {
|
||||
return trivial_userptr_diff ( userptr, subtrahend );
|
||||
}
|
||||
|
||||
static inline __always_inline void
|
||||
UACCESS_INLINE ( linux, memcpy_user ) ( userptr_t dest, off_t dest_off,
|
||||
userptr_t src, off_t src_off,
|
||||
|
||||
@@ -65,30 +65,6 @@ trivial_user_to_virt ( userptr_t userptr, off_t offset ) {
|
||||
return ( ( void * ) userptr + offset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add offset to user pointer
|
||||
*
|
||||
* @v userptr User pointer
|
||||
* @v offset Offset
|
||||
* @ret userptr New pointer value
|
||||
*/
|
||||
static inline __always_inline userptr_t
|
||||
trivial_userptr_add ( userptr_t userptr, off_t offset ) {
|
||||
return ( userptr + offset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract user pointers
|
||||
*
|
||||
* @v userptr User pointer
|
||||
* @v subtrahend User pointer to be subtracted
|
||||
* @ret offset Offset
|
||||
*/
|
||||
static inline __always_inline off_t
|
||||
trivial_userptr_diff ( userptr_t userptr, userptr_t subtrahend ) {
|
||||
return ( userptr - subtrahend );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy data between user buffers
|
||||
*
|
||||
@@ -231,17 +207,6 @@ UACCESS_INLINE ( flat, user_to_virt ) ( userptr_t userptr, off_t offset ) {
|
||||
return trivial_user_to_virt ( userptr, offset );
|
||||
}
|
||||
|
||||
static inline __always_inline userptr_t
|
||||
UACCESS_INLINE ( flat, userptr_add ) ( userptr_t userptr, off_t offset ) {
|
||||
return trivial_userptr_add ( userptr, offset );
|
||||
}
|
||||
|
||||
static inline __always_inline off_t
|
||||
UACCESS_INLINE ( flat, userptr_diff ) ( userptr_t userptr,
|
||||
userptr_t subtrahend ) {
|
||||
return trivial_userptr_diff ( userptr, subtrahend );
|
||||
}
|
||||
|
||||
static inline __always_inline void
|
||||
UACCESS_INLINE ( flat, memcpy_user ) ( userptr_t dest, off_t dest_off,
|
||||
userptr_t src, off_t src_off,
|
||||
@@ -322,24 +287,6 @@ userptr_t virt_to_user ( volatile const void *addr );
|
||||
*/
|
||||
void * user_to_virt ( userptr_t userptr, off_t offset );
|
||||
|
||||
/**
|
||||
* Add offset to user pointer
|
||||
*
|
||||
* @v userptr User pointer
|
||||
* @v offset Offset
|
||||
* @ret userptr New pointer value
|
||||
*/
|
||||
userptr_t userptr_add ( userptr_t userptr, off_t offset );
|
||||
|
||||
/**
|
||||
* Subtract user pointers
|
||||
*
|
||||
* @v userptr User pointer
|
||||
* @v subtrahend User pointer to be subtracted
|
||||
* @ret offset Offset
|
||||
*/
|
||||
off_t userptr_diff ( userptr_t userptr, userptr_t subtrahend );
|
||||
|
||||
/**
|
||||
* Convert virtual address to a physical address
|
||||
*
|
||||
|
||||
@@ -30,7 +30,6 @@ FILE_LICENCE(GPL2_OR_LATER);
|
||||
PROVIDE_UACCESS_INLINE(linux, user_to_phys);
|
||||
PROVIDE_UACCESS_INLINE(linux, virt_to_user);
|
||||
PROVIDE_UACCESS_INLINE(linux, user_to_virt);
|
||||
PROVIDE_UACCESS_INLINE(linux, userptr_add);
|
||||
PROVIDE_UACCESS_INLINE(linux, memcpy_user);
|
||||
PROVIDE_UACCESS_INLINE(linux, memmove_user);
|
||||
PROVIDE_UACCESS_INLINE(linux, memset_user);
|
||||
|
||||
Reference in New Issue
Block a user