/* Find the highest image not yet in its final position */
highest = NULL;
for_each_image ( initrd ) {
- data = initrd->data;
- if ( ( virt_to_phys ( data ) < current ) &&
+ if ( ( virt_to_phys ( initrd->data ) < current ) &&
( ( highest == NULL ) ||
- ( virt_to_phys ( data ) >
+ ( virt_to_phys ( initrd->data ) >
virt_to_phys ( highest->data ) ) ) ) {
highest = initrd;
}
/* Swap fragments */
memcpy ( free, ( high->data + len ), frag_len );
- memmove ( ( low->data + new_len ), ( low->data + len ),
+ memmove ( ( low->rwdata + new_len ), ( low->data + len ),
low->len );
- memcpy ( ( low->data + len ), free, frag_len );
+ memcpy ( ( low->rwdata + len ), free, frag_len );
len = new_len;
}
static int initrd_swap_any ( void *free, size_t free_len ) {
struct image *low;
struct image *high;
+ const void *adjacent;
size_t padded_len;
- void *adjacent;
/* Find any pair of initrds that can be swapped */
for_each_image ( low ) {
* @ret rc Return status code
*/
static int sdi_exec ( struct image *image ) {
- struct sdi_header *sdi;
+ const struct sdi_header *sdi;
uint32_t sdiptr;
/* Sanity check */
int rc;
/* Parse image */
- if ( ( rc = fdt_parse ( fdt, image->data, image->len ) ) != 0 ) {
+ if ( ( rc = fdt_parse ( fdt, image->rwdata, image->len ) ) != 0 ) {
DBGC ( fdt, "FDT image \"%s\" is invalid: %s\n",
image->name, strerror ( rc ) );
return rc;
/* Free image data and image itself, if dynamically allocated */
if ( ! ( image->flags & IMAGE_STATIC ) ) {
- ufree ( image->data );
+ ufree ( image->rwdata );
free ( image );
}
}
return -ENOTTY;
/* (Re)allocate image data */
- new = urealloc ( image->data, len );
+ new = urealloc ( image->rwdata, len );
if ( ! new )
return -ENOMEM;
- image->data = new;
+ image->rwdata = new;
image->len = len;
return 0;
return rc;
/* Copy in new image data */
- memcpy ( image->data, data, len );
+ memcpy ( image->rwdata, data, len );
return 0;
}
final_len = ( ( image->len && is_block_cipher ( cipher ) ) ?
cipher->blocksize : 0 );
bulk_len = ( image->len - final_len );
- cipher_decrypt ( cipher, ctx, image->data, image->data, bulk_len );
+ cipher_decrypt ( cipher, ctx, image->data, image->rwdata, bulk_len );
/* Decrypt final block */
cipher_decrypt ( cipher, ctx, ( image->data + bulk_len ), final,
* have to include include any error-handling code path to
* reconstruct the block padding.
*/
- memcpy ( ( image->data + bulk_len ), final, final_len );
+ memcpy ( ( image->rwdata + bulk_len ), final, final_len );
image->len -= pad_len;
/* Clear image type and re-register image, if applicable */
* containing the potentially invalid (and therefore
* unreproducible) block padding.
*/
- cipher_encrypt ( cipher, ctxdup, image->data, image->data, bulk_len );
+ cipher_encrypt ( cipher, ctxdup, image->data, image->rwdata, bulk_len );
if ( original_flags & IMAGE_REGISTERED ) {
register_image ( image ); /* Cannot fail on re-registration */
image_put ( image );
goto err_shim_install;
}
- /* Attempt loading image */
+ /* Attempt loading image
+ *
+ * LoadImage() does not (allegedly) modify the image content,
+ * but requires a non-const pointer to SourceBuffer. We
+ * therefore use the .rwdata field rather than .data.
+ */
handle = NULL;
if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, path,
- exec->data, exec->len,
+ exec->rwdata, exec->len,
&handle ) ) != 0 ) {
/* Not an EFI image */
rc = -EEFI_LOAD ( efirc );
EFI_STATUS efirc;
int rc;
- /* Attempt loading image */
+ /* Attempt loading image
+ *
+ * LoadImage() does not (allegedly) modify the image content,
+ * but requires a non-const pointer to SourceBuffer. We
+ * therefore use the .rwdata field rather than .data.
+ */
handle = NULL;
if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, &empty_path,
- image->data, image->len,
+ image->rwdata, image->len,
&handle ) ) != 0 ) {
/* Not an EFI image */
rc = -EEFI_LOAD ( efirc );
#include <string.h>
#include <ipxe/image.h>
-#include <ipxe/uaccess.h>
#include <ipxe/init.h>
/* Raw image data for all embedded images */
.refcnt = REF_INIT ( free_image ), \
.name = _name, \
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
- .data = ( userptr_t ) ( embedded_image_ ## _index ## _data ), \
+ .rwdata = embedded_image_ ## _index ## _data, \
.len = ( size_t ) embedded_image_ ## _index ## _len, \
},
static struct image embedded_images[] = {
for ( i = 0 ; i < ( int ) ( sizeof ( embedded_images ) /
sizeof ( embedded_images[0] ) ) ; i++ ) {
image = &embedded_images[i];
-
- /* virt_to_user() cannot be used in a static
- * initialiser, so we cast the pointer to a userptr_t
- * in the initialiser and fix it up here. (This will
- * actually be a no-op on most platforms.)
- */
- data = ( ( void * ) image->data );
- image->data = virt_to_user ( data );
-
DBG ( "Embedded image \"%s\": %zd bytes at %p\n",
image->name, image->len, data );
-
if ( ( rc = register_image ( image ) ) != 0 ) {
DBG ( "Could not register embedded image \"%s\": "
"%s\n", image->name, strerror ( rc ) );
deflate_init ( deflate, format );
/* Initialise output chunk */
- deflate_chunk_init ( &out, extracted->data, 0, extracted->len );
+ deflate_chunk_init ( &out, extracted->rwdata, 0,
+ extracted->len );
/* Decompress data */
if ( ( rc = deflate_inflate ( deflate, data, len,
* If the @c IMAGE_STATIC flag is set, then this is a
* statically allocated image.
*/
- void *data;
+ union {
+ /** Read-only data */
+ const void *data;
+ /** Writable data */
+ void *rwdata;
+ };
/** Length of raw file image */
size_t len;
DBGC ( colour, "CMDLINE using command line \"%s\"\n", cmdline );
/* Prepare and register image */
- efi_cmdline_image.data = virt_to_user ( cmdline );
+ efi_cmdline_image.data = cmdline;
efi_cmdline_image.len = strlen ( cmdline );
if ( efi_cmdline_image.len &&
( ( rc = register_image ( &efi_cmdline_image ) ) != 0 ) ) {
/* Sanity check */
assert ( sizeof ( out ) == digest->digestsize );
- /* Correct image data pointer */
- test->image->data = virt_to_user ( ( void * ) test->image->data );
-
/* Check that image is detected as correct type */
okx ( register_image ( test->image ) == 0, file, line );
okx ( test->image->type == test->type, file, line );
.refcnt = REF_INIT ( ref_no_free ), \
.name = #_name, \
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
- .data = ( userptr_t ) ( _name ## __file ), \
+ .data = _name ## __file, \
.len = sizeof ( _name ## __file ), \
}; \
static struct asn1_test_digest _name ## _expected[] = { \
#include <ipxe/sha256.h>
#include <ipxe/x509.h>
#include <ipxe/image.h>
-#include <ipxe/uaccess.h>
#include <ipxe/der.h>
#include <ipxe/cms.h>
#include <ipxe/privkey.h>
.refcnt = REF_INIT ( ref_no_free ), \
.name = #NAME, \
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
- .data = ( userptr_t ) ( NAME ## _data ), \
+ .data = NAME ## _data, \
.len = sizeof ( NAME ## _data ), \
}, \
}
.refcnt = REF_INIT ( ref_no_free ), \
.name = #NAME, \
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
- .data = ( userptr_t ) ( NAME ## _data ), \
+ .data = NAME ## _data, \
.len = sizeof ( NAME ## _data ), \
}, \
}
.name = #NAME, \
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
.type = &der_image_type, \
- .data = ( userptr_t ) ( NAME ## _data ), \
+ .data = NAME ## _data, \
.len = sizeof ( NAME ## _data ), \
}, \
}
*/
static void cms_message_okx ( struct cms_test_message *msg,
const char *file, unsigned int line ) {
- const void *data = ( ( void * ) msg->image.data );
-
- /* Fix up image data pointer */
- msg->image.data = virt_to_user ( data );
/* Check ability to parse message */
okx ( cms_message ( &msg->image, &msg->cms ) == 0, file, line );
-
- /* Reset image data pointer */
- msg->image.data = ( ( userptr_t ) data );
}
#define cms_message_ok( msg ) \
cms_message_okx ( msg, __FILE__, __LINE__ )
time_t time, struct x509_chain *store,
struct x509_root *root, const char *file,
unsigned int line ) {
- const void *data = ( ( void * ) img->image.data );
-
- /* Fix up image data pointer */
- img->image.data = virt_to_user ( data );
/* Invalidate any certificates from previous tests */
x509_invalidate_chain ( msg->cms->certificates );
okx ( cms_verify ( msg->cms, &img->image, name, time, store,
root ) == 0, file, line );
okx ( img->image.flags & IMAGE_TRUSTED, file, line );
-
- /* Reset image data pointer */
- img->image.data = ( ( userptr_t ) data );
}
#define cms_verify_ok( msg, img, name, time, store, root ) \
cms_verify_okx ( msg, img, name, time, store, root, \
time_t time, struct x509_chain *store,
struct x509_root *root, const char *file,
unsigned int line ) {
- const void *data = ( ( void * ) img->image.data );
-
- /* Fix up image data pointer */
- img->image.data = virt_to_user ( data );
/* Invalidate any certificates from previous tests */
x509_invalidate_chain ( msg->cms->certificates );
okx ( cms_verify ( msg->cms, &img->image, name, time, store,
root ) != 0, file, line );
okx ( ! ( img->image.flags & IMAGE_TRUSTED ), file, line );
-
- /* Reset image data pointer */
- img->image.data = ( ( userptr_t ) data );
}
#define cms_verify_fail_ok( msg, img, name, time, store, root ) \
cms_verify_fail_okx ( msg, img, name, time, store, root, \
struct cms_test_keypair *keypair,
struct cms_test_image *expected,
const char *file, unsigned int line ) {
- const void *data = ( ( void * ) img->image.data );
-
- /* Fix up image data pointer */
- img->image.data = virt_to_user ( data );
/* Check ability to decrypt image */
okx ( cms_decrypt ( envelope->cms, &img->image, NULL,
assert ( ( test->width * test->height * sizeof ( test->data[0] ) )
== test->len );
- /* Correct image data pointer */
- test->image->data = virt_to_user ( ( void * ) test->image->data );
-
/* Check that image is detected as correct type */
okx ( register_image ( test->image ) == 0, file, line );
okx ( test->image->type == test->type, file, line );
/* Check pixel buffer data */
okx ( pixbuf->len == test->len, file, line );
- okx ( memcmp ( pixbuf->data, virt_to_user ( test->data ),
- test->len ) == 0, file, line );
+ okx ( memcmp ( pixbuf->data, test->data, test->len ) == 0,
+ file, line );
pixbuf_put ( pixbuf );
}
.refcnt = REF_INIT ( ref_no_free ), \
.name = #_name, \
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
- .data = ( userptr_t ) ( _name ## __file ), \
+ .data = _name ## __file, \
.len = sizeof ( _name ## __file ), \
}; \
static struct pixel_buffer_test _name = { \