diff --git a/src/arch/i386/image/multiboot.c b/src/arch/i386/image/multiboot.c index b9fb16396..f27f22807 100644 --- a/src/arch/i386/image/multiboot.c +++ b/src/arch/i386/image/multiboot.c @@ -255,7 +255,7 @@ static int multiboot_load_raw ( struct image *image, } /* Copy image to segment */ - copy_user ( buffer, 0, image->data, offset, filesz ); + memcpy_user ( buffer, 0, image->data, offset, filesz ); /* Record execution entry point */ image->entry = hdr->mb.entry_addr; diff --git a/src/arch/i386/include/librm.h b/src/arch/i386/include/librm.h index 19966c6db..859249e46 100644 --- a/src/arch/i386/include/librm.h +++ b/src/arch/i386/include/librm.h @@ -110,6 +110,18 @@ copy_from_real_librm ( void *dest, unsigned int src_seg, */ typedef intptr_t userptr_t; +/** + * Add offset to user pointer + * + * @v ptr User pointer + * @v offset Offset + * @ret new_ptr New pointer value + */ +static inline __attribute__ (( always_inline )) userptr_t +userptr_add ( userptr_t ptr, off_t offset ) { + return ( ptr + offset ); +} + /** * Copy data to user buffer * @@ -146,12 +158,28 @@ copy_from_user ( void *dest, userptr_t buffer, off_t offset, size_t len ) { * @v len Length */ static inline __attribute__ (( always_inline )) void -copy_user ( userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, - size_t len ) { +memcpy_user ( userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, + size_t len ) { memcpy ( ( ( void * ) dest + dest_off ), ( ( void * ) src + src_off ), len ); } +/** + * Copy data between user buffers, allowing for overlap + * + * @v dest Destination user buffer + * @v dest_off Offset within destination buffer + * @v src Source user buffer + * @v src_off Offset within source buffer + * @v len Length + */ +static inline __attribute__ (( always_inline )) void +memmove_user ( userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, + size_t len ) { + memmove ( ( ( void * ) dest + dest_off ), ( ( void * ) src + src_off ), + len ); +} + /** * Fill user buffer with a constant byte * diff --git a/src/image/elf.c b/src/image/elf.c index 9dc08675a..869be3f33 100644 --- a/src/image/elf.c +++ b/src/image/elf.c @@ -94,7 +94,7 @@ static int elf_load_segment ( struct image *image, Elf_Phdr *phdr ) { } /* Copy image to segment */ - copy_user ( buffer, 0, image->data, phdr->p_offset, phdr->p_filesz ); + memcpy_user ( buffer, 0, image->data, phdr->p_offset, phdr->p_filesz ); return 0; }