#include <gpxe/uaccess.h>
Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| int | prep_segment (userptr_t segment, size_t filesz, size_t memsz) |
| Prepare segment for loading. | |
Definition in file segment.h.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
Prepare segment for loading.
| segment | Segment start | |
| filesz | Size of the "allocated bytes" portion of the segment | |
| memsz | Size of the segment |
| rc | Return status code |
Definition at line 42 of file segment.c.
References memory_map::count, DBG, EINVAL, memory_region::end, ERANGE, get_memmap(), memset_user(), memory_map::regions, memory_region::start, and user_to_phys().
Referenced by aout_probe(), bzimage_load(), bzimage_load_initrds(), comboot_load_image(), comboot_prepare_bounce_buffer(), comboot_prepare_segment(), elf_load_segment(), eltorito_load_disk(), get_x_header(), multiboot_load_raw(), nbi_prepare_segment(), and pxe_load().
00042 { 00043 struct memory_map memmap; 00044 physaddr_t start = user_to_phys ( segment, 0 ); 00045 physaddr_t mid = user_to_phys ( segment, filesz ); 00046 physaddr_t end = user_to_phys ( segment, memsz ); 00047 unsigned int i; 00048 00049 DBG ( "Preparing segment [%lx,%lx,%lx)\n", start, mid, end ); 00050 00051 /* Sanity check */ 00052 if ( filesz > memsz ) { 00053 DBG ( "Insane segment [%lx,%lx,%lx)\n", start, mid, end ); 00054 return -EINVAL; 00055 } 00056 00057 /* Get a fresh memory map. This allows us to automatically 00058 * avoid treading on any regions that Etherboot is currently 00059 * editing out of the memory map. 00060 */ 00061 get_memmap ( &memmap ); 00062 00063 /* Look for a suitable memory region */ 00064 for ( i = 0 ; i < memmap.count ; i++ ) { 00065 if ( ( start >= memmap.regions[i].start ) && 00066 ( end <= memmap.regions[i].end ) ) { 00067 /* Found valid region: zero bss and return */ 00068 memset_user ( segment, filesz, 0, ( memsz - filesz ) ); 00069 return 0; 00070 } 00071 } 00072 00073 /* No suitable memory region found */ 00074 DBG ( "Segment [%lx,%lx,%lx) does not fit into available memory\n", 00075 start, mid, end ); 00076 return -ERANGE; 00077 }
1.5.7.1