iPXE
segment.h File Reference

Executable image segments. More...

#include <stdint.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int prep_segment (void *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()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

References memsz, and segment.

◆ prep_segment()

int prep_segment ( void * segment,
size_t filesz,
size_t memsz )
extern

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 61 of file segment.c.

61 {
62 struct memmap_region region;
63 physaddr_t start = virt_to_phys ( segment );
64 physaddr_t mid = ( start + filesz );
65 physaddr_t end = ( start + memsz );
67
68 DBGC ( segment, "SEGMENT [%#08lx,%#08lx,%#08lx)\n", start, mid, end );
69
70 /* Check for malformed lengths */
71 if ( filesz > memsz ) {
72 DBGC ( segment, "SEGMENT [%#08lx,%#08lx,%#08lx) is "
73 "malformed\n", start, mid, end );
74 return -EINVAL;
75 }
76
77 /* Zero-length segments do not need a memory region */
78 if ( memsz == 0 )
79 return 0;
80 max = ( end - 1 );
81
82 /* Check for address space overflow */
83 if ( max < start ) {
84 DBGC ( segment, "SEGMENT [%#08lx,%#08lx,%#08lx) wraps "
85 "around\n", start, mid, end );
86 return -EINVAL;
87 }
88
89 /* Describe region containing this segment */
90 memmap_describe ( start, 1, &region );
91 DBGC_MEMMAP ( segment, &region );
92
93 /* Fail unless region is usable and sufficiently large */
94 if ( ( ! memmap_is_usable ( &region ) ) || ( region.max < max ) ) {
95 DBGC ( segment, "SEGMENT [%#08lx,%#08lx,%#08lx) does not fit "
96 "into available memory\n", start, mid, end );
97 return -ERANGE_SEGMENT;
98 }
99
100 /* Found valid region: zero bss and return */
101 memset ( ( segment + filesz ), 0, ( memsz - filesz ) );
102 return 0;
103}
unsigned long physaddr_t
Definition stdint.h:20
#define max(x, y)
Definition ath.h:41
static size_t memsz
Definition fdtmem.c:51
#define DBGC(...)
Definition compiler.h:505
uint32_t start
Starting offset.
Definition netvsc.h:1
#define EINVAL
Invalid argument.
Definition errno.h:429
static int memmap_is_usable(const struct memmap_region *region)
Check if memory region is usable.
Definition memmap.h:87
void memmap_describe(uint64_t min, int hide, struct memmap_region *region)
Describe memory region from system memory map.
Definition null_memmap.h:29
#define DBGC_MEMMAP(...)
Definition memmap.h:207
void * memset(void *dest, int character, size_t len) __nonnull
uint16_t segment
Code segment.
Definition librm.h:3
uint16_t mid
Middle 16 bits of address.
Definition librm.h:9
uint32_t end
Ending offset.
Definition netvsc.h:7
#define ERANGE_SEGMENT
Segment-specific error messages.
Definition segment.c:46
A memory region descriptor.
Definition memmap.h:49

References DBGC, DBGC_MEMMAP, EINVAL, end, ERANGE_SEGMENT, max, memmap_region::max, memmap_describe(), memmap_is_usable(), memset(), memsz, mid, segment, and start.

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