iPXE
Defines | Functions | Variables
segment.c File Reference

Executable image segments. More...

#include <errno.h>
#include <ipxe/uaccess.h>
#include <ipxe/io.h>
#include <ipxe/errortab.h>
#include <ipxe/segment.h>

Go to the source code of this file.

Defines

#define ERANGE_SEGMENT   __einfo_error ( EINFO_ERANGE_SEGMENT )
 Segment-specific error messages.
#define EINFO_ERANGE_SEGMENT   __einfo_uniqify ( EINFO_ERANGE, 0x01, "Requested memory not available" )

Functions

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

Variables

struct errortab segment_errors[] __errortab

Detailed Description

Executable image segments.

Definition in file segment.c.


Define Documentation

Segment-specific error messages.

This error happens sufficiently often to merit a user-friendly description.

Definition at line 45 of file segment.c.

Referenced by prep_segment().

#define EINFO_ERANGE_SEGMENT   __einfo_uniqify ( EINFO_ERANGE, 0x01, "Requested memory not available" )

Definition at line 46 of file segment.c.


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;
}

Variable Documentation

struct errortab segment_errors [] __errortab
Initial value:

Definition at line 48 of file segment.c.