iPXE
Functions
segment.h File Reference

Executable image segments. More...

#include <ipxe/uaccess.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int prep_segment (userptr_t segment, size_t filesz, size_t memsz)
 Prepare segment for loading.

Detailed Description

Executable image segments.

Definition in file segment.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int prep_segment ( userptr_t  segment,
size_t  filesz,
size_t  memsz 
)

Prepare segment for loading.

Parameters:
segmentSegment start
fileszSize of the "allocated bytes" portion of the segment
memszSize of the segment
Return values:
rcReturn status code

Definition at line 60 of file segment.c.

References memory_map::count, DBG, EINVAL, end, memory_region::end, ERANGE_SEGMENT, get_memmap(), memset_user(), mid, memory_map::regions, start, memory_region::start, and user_to_phys().

Referenced by bzimage_exec(), com32_load_image(), com32_prepare_bounce_buffer(), comboot_prepare_segment(), elf_load_segment(), multiboot_add_modules(), multiboot_load_raw(), nbi_prepare_segment(), and pxe_exec().

                                                                    {
        struct memory_map memmap;
        physaddr_t start = user_to_phys ( segment, 0 );
        physaddr_t mid = user_to_phys ( segment, filesz );
        physaddr_t end = user_to_phys ( segment, memsz );
        unsigned int i;

        DBG ( "Preparing segment [%lx,%lx,%lx)\n", start, mid, end );

        /* Sanity check */
        if ( filesz > memsz ) {
                DBG ( "Insane segment [%lx,%lx,%lx)\n", start, mid, end );
                return -EINVAL;
        }

        /* Get a fresh memory map.  This allows us to automatically
         * avoid treading on any regions that Etherboot is currently
         * editing out of the memory map.
         */
        get_memmap ( &memmap );

        /* Look for a suitable memory region */
        for ( i = 0 ; i < memmap.count ; i++ ) {
                if ( ( start >= memmap.regions[i].start ) &&
                     ( end <= memmap.regions[i].end ) ) {
                        /* Found valid region: zero bss and return */
                        memset_user ( segment, filesz, 0, ( memsz - filesz ) );
                        return 0;
                }
        }

        /* No suitable memory region found */
        DBG ( "Segment [%lx,%lx,%lx) does not fit into available memory\n",
              start, mid, end );
        return -ERANGE_SEGMENT;
}