iPXE
Data Structures | Macros | Functions | Variables
image.h File Reference

Executable images. More...

#include <ipxe/tables.h>
#include <ipxe/list.h>
#include <ipxe/refcnt.h>

Go to the source code of this file.

Data Structures

struct  image
 An executable image. More...
 
struct  image_type
 An executable image type. More...
 
struct  image_tag
 An image tag. More...
 

Macros

#define IMAGE_REGISTERED   0x0001
 Image is registered. More...
 
#define IMAGE_TRUSTED   0x0002
 Image is trusted. More...
 
#define IMAGE_AUTO_UNREGISTER   0x0004
 Image will be automatically unregistered after execution. More...
 
#define IMAGE_HIDDEN   0x0008
 Image will be hidden from enumeration. More...
 
#define IMAGE_STATIC   0x0010
 Image is statically allocated. More...
 
#define IMAGE_STATIC_NAME   0x0020
 Image name is statically allocated. More...
 
#define PROBE_MULTIBOOT   01
 Multiboot image probe priority. More...
 
#define PROBE_NORMAL   02
 Normal image probe priority. More...
 
#define PROBE_PXE   03
 PXE image probe priority. More...
 
#define IMAGE_TYPES   __table ( struct image_type, "image_types" )
 Executable image type table. More...
 
#define __image_type(probe_order)   __table_entry ( IMAGE_TYPES, probe_order )
 An executable image type. More...
 
#define IMAGE_TAGS   __table ( struct image_tag, "image_tags" )
 Image tag table. More...
 
#define __image_tag   __table_entry ( IMAGE_TAGS, 01 )
 An image tag. More...
 
#define for_each_image(image)   list_for_each_entry ( (image), &images, list )
 Iterate over all registered images. More...
 
#define for_each_image_safe(image, tmp)   list_for_each_entry_safe ( (image), (tmp), &images, list )
 Iterate over all registered images, safe against deletion. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static struct imagefirst_image (void)
 Retrieve first image. More...
 
void free_image (struct refcnt *refcnt)
 Free executable image. More...
 
struct imagealloc_image (struct uri *uri)
 Allocate executable image. More...
 
int image_set_uri (struct image *image, struct uri *uri)
 Set image URI. More...
 
int image_set_name (struct image *image, const char *name)
 Set image name. More...
 
char * image_strip_suffix (struct image *image)
 Strip dot suffix from image name, if present. More...
 
int image_set_cmdline (struct image *image, const char *cmdline)
 Set image command line. More...
 
int image_set_len (struct image *image, size_t len)
 Set image length. More...
 
int image_set_data (struct image *image, const void *data, size_t len)
 Set image data. More...
 
int register_image (struct image *image)
 Register executable image. More...
 
void unregister_image (struct image *image)
 Unregister executable image. More...
 
struct imagefind_image (const char *name)
 Find image by name. More...
 
struct imagefind_image_tag (struct image_tag *tag)
 Find image by tag. More...
 
int image_exec (struct image *image)
 Execute image. More...
 
int image_replace (struct image *replacement)
 Set replacement image. More...
 
int image_select (struct image *image)
 Select image for execution. More...
 
int image_set_trust (int require_trusted, int permanent)
 Change image trust requirement. More...
 
struct imageimage_memory (const char *name, const void *data, size_t len)
 Create registered image from block of memory. More...
 
const char * image_argument (struct image *image, const char *key)
 Find argument within image command line. More...
 
int image_pixbuf (struct image *image, struct pixel_buffer **pixbuf)
 Create pixel buffer from image. More...
 
int image_asn1 (struct image *image, size_t offset, struct asn1_cursor **cursor)
 Extract ASN.1 object from image. More...
 
int image_extract (struct image *image, const char *name, struct image **extracted)
 Extract archive image. More...
 
int image_extract_exec (struct image *image)
 Extract and execute image. More...
 
static struct imageimage_get (struct image *image)
 Increment reference count on an image. More...
 
static void image_put (struct image *image)
 Decrement reference count on an image. More...
 
static void image_clear_cmdline (struct image *image)
 Clear image command line. More...
 
static void image_trust (struct image *image)
 Set image as trusted. More...
 
static void image_untrust (struct image *image)
 Set image as untrusted. More...
 
static void image_hide (struct image *image)
 Mark image as hidden. More...
 
static struct imageimage_tag (struct image *image, struct image_tag *tag)
 Tag image. More...
 

Variables

struct image __attribute__
 
struct list_head images
 List of registered images. More...
 
struct image_tag current_image
 
struct image_tag selected_image
 

Detailed Description

Executable images.

Definition in file image.h.

Macro Definition Documentation

◆ IMAGE_REGISTERED

#define IMAGE_REGISTERED   0x0001

Image is registered.

Definition at line 76 of file image.h.

◆ IMAGE_TRUSTED

#define IMAGE_TRUSTED   0x0002

Image is trusted.

Definition at line 79 of file image.h.

◆ IMAGE_AUTO_UNREGISTER

#define IMAGE_AUTO_UNREGISTER   0x0004

Image will be automatically unregistered after execution.

Definition at line 82 of file image.h.

◆ IMAGE_HIDDEN

#define IMAGE_HIDDEN   0x0008

Image will be hidden from enumeration.

Definition at line 85 of file image.h.

◆ IMAGE_STATIC

#define IMAGE_STATIC   0x0010

Image is statically allocated.

Definition at line 88 of file image.h.

◆ IMAGE_STATIC_NAME

#define IMAGE_STATIC_NAME   0x0020

Image name is statically allocated.

Definition at line 91 of file image.h.

◆ PROBE_MULTIBOOT

#define PROBE_MULTIBOOT   01

Multiboot image probe priority.

Multiboot images are also valid executables in another format (e.g. ELF), so we must perform the multiboot probe first.

Definition at line 150 of file image.h.

◆ PROBE_NORMAL

#define PROBE_NORMAL   02

Normal image probe priority.

Definition at line 155 of file image.h.

◆ PROBE_PXE

#define PROBE_PXE   03

PXE image probe priority.

PXE images have no signature checks, so will claim all image files. They must therefore be tried last in the probe order list.

Definition at line 163 of file image.h.

◆ IMAGE_TYPES

#define IMAGE_TYPES   __table ( struct image_type, "image_types" )

Executable image type table.

Definition at line 166 of file image.h.

◆ __image_type

#define __image_type (   probe_order)    __table_entry ( IMAGE_TYPES, probe_order )

An executable image type.

Definition at line 169 of file image.h.

◆ IMAGE_TAGS

#define IMAGE_TAGS   __table ( struct image_tag, "image_tags" )

Image tag table.

Definition at line 180 of file image.h.

◆ __image_tag

struct image_tag current_image __image_tag   __table_entry ( IMAGE_TAGS, 01 )

An image tag.

Currently-executing image.

Definition at line 183 of file image.h.

◆ for_each_image

#define for_each_image (   image)    list_for_each_entry ( (image), &images, list )

Iterate over all registered images.

Definition at line 190 of file image.h.

◆ for_each_image_safe

#define for_each_image_safe (   image,
  tmp 
)    list_for_each_entry_safe ( (image), (tmp), &images, list )

Iterate over all registered images, safe against deletion.

Definition at line 194 of file image.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ first_image()

static struct image* first_image ( void  )
inlinestatic

Retrieve first image.

Return values
imageImage, or NULL

Definition at line 202 of file image.h.

202  {
203  return list_first_entry ( &images, struct image, list );
204 }
An executable image.
Definition: image.h:23
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
struct list_head images
List of registered images.
Definition: image.c:58

References images, image::list, and list_first_entry.

Referenced by ipxe().

◆ free_image()

void free_image ( struct refcnt refcnt)

Free executable image.

Parameters
refcntReference counter

Image consumers must call image_put() rather than calling free_image() directly. This function is exposed for use only by static images.

Definition at line 85 of file image.c.

85  {
86  struct image *image = container_of ( refcnt, struct image, refcnt );
87  struct image_tag *tag;
88 
89  /* Sanity check: free_image() should not be called directly on
90  * dynamically allocated images.
91  */
92  assert ( refcnt->count < 0 );
93  DBGC ( image, "IMAGE %s freed\n", image->name );
94 
95  /* Clear any tag weak references */
97  if ( tag->image == image )
98  tag->image = NULL;
99  }
100 
101  /* Free dynamic allocations used by both static and dynamic images */
102  free ( image->cmdline );
103  uri_put ( image->uri );
105 
106  /* Free image name, if dynamically allocated */
107  if ( ! ( image->flags & IMAGE_STATIC_NAME ) )
108  free ( image->name );
109 
110  /* Free image data and image itself, if dynamically allocated */
111  if ( ! ( image->flags & IMAGE_STATIC ) ) {
112  ufree ( image->rwdata );
113  free ( image );
114  }
115 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
unsigned int flags
Flags.
Definition: image.h:39
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
An image tag.
Definition: image.h:172
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
char * cmdline
Command line to pass to image.
Definition: image.h:42
A reference counter.
Definition: refcnt.h:26
int count
Current reference count.
Definition: refcnt.h:32
#define IMAGE_STATIC
Image is statically allocated.
Definition: image.h:88
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define IMAGE_TAGS
Image tag table.
Definition: image.h:180
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
struct uri * uri
URI of image.
Definition: image.h:31
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:249
void * rwdata
Writable data.
Definition: image.h:52
#define IMAGE_STATIC_NAME
Image name is statically allocated.
Definition: image.h:91
struct image * replacement
Replacement image.
Definition: image.h:72
uint64_t tag
Identity tag.
Definition: edd.h:30
char * name
Name.
Definition: image.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), image::cmdline, container_of, refcnt::count, DBGC, image::flags, for_each_table_entry, free, image_put(), IMAGE_STATIC, IMAGE_STATIC_NAME, IMAGE_TAGS, image::name, NULL, image::replacement, image::rwdata, tag, ufree(), image::uri, and uri_put().

Referenced by alloc_image(), cmdline_image_free(), efi_cmdline_free(), and lkrn_exec().

◆ alloc_image()

struct image* alloc_image ( struct uri uri)

Allocate executable image.

Parameters
uriURI, or NULL
Return values
imageExecutable image

Definition at line 123 of file image.c.

123  {
124  struct image *image;
125  int rc;
126 
127  /* Allocate image */
128  image = zalloc ( sizeof ( *image ) );
129  if ( ! image )
130  goto err_alloc;
131 
132  /* Initialise image */
134  if ( uri && ( ( rc = image_set_uri ( image, uri ) ) != 0 ) )
135  goto err_set_uri;
136 
137  return image;
138 
139  err_set_uri:
140  image_put ( image );
141  err_alloc:
142  return NULL;
143 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int image_set_uri(struct image *image, struct uri *uri)
Set image URI.
Definition: image.c:152
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
An executable image.
Definition: image.h:23
void free_image(struct refcnt *refcnt)
Free executable image.
Definition: image.c:85
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:249
A Uniform Resource Identifier.
Definition: uri.h:64
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct refcnt refcnt
Reference count.
Definition: image.h:25

References free_image(), image_put(), image_set_uri(), NULL, rc, ref_init, image::refcnt, and zalloc().

Referenced by cpio_okx(), image_extract(), image_memory(), and imgdownload().

◆ image_set_uri()

int image_set_uri ( struct image image,
struct uri uri 
)

Set image URI.

Parameters
imageImage
uriNew image URI
Return values
rcReturn status code

Definition at line 152 of file image.c.

152  {
153  const char *name;
154  int rc;
155 
156  /* Set name, if image does not already have one */
157  if ( ! ( image->name && image->name[0] ) ) {
158  name = ( uri->path ? uri->path : uri->opaque );
159  if ( name ) {
160  name = basename ( ( char * ) name );
161  if ( ( rc = image_set_name ( image, name ) ) != 0 )
162  return rc;
163  }
164  }
165 
166  /* Update image URI */
167  uri_put ( image->uri );
168  image->uri = uri_get ( uri );
169 
170  return 0;
171 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:194
An executable image.
Definition: image.h:23
const char * path
Path (after URI decoding)
Definition: uri.h:80
char * basename(char *path)
Return base name from path.
Definition: basename.c:42
int image_set_name(struct image *image, const char *name)
Set image name.
Definition: image.c:180
struct uri * uri
URI of image.
Definition: image.h:31
const char * opaque
Opaque part.
Definition: uri.h:70
A Uniform Resource Identifier.
Definition: uri.h:64
char * name
Name.
Definition: image.h:37

References basename(), image_set_name(), image::name, name, uri::opaque, uri::path, rc, image::uri, uri_get(), and uri_put().

Referenced by alloc_image(), and downloader_vredirect().

◆ image_set_name()

int image_set_name ( struct image image,
const char *  name 
)

Set image name.

Parameters
imageImage
nameNew image name
Return values
rcReturn status code

Definition at line 180 of file image.c.

180  {
181  char *name_copy;
182 
183  /* Duplicate name */
184  name_copy = strdup ( name );
185  if ( ! name_copy )
186  return -ENOMEM;
187 
188  /* Free existing name, if not statically allocated */
189  if ( ! ( image->flags & IMAGE_STATIC_NAME ) )
190  free ( image->name );
191 
192  /* Replace existing name */
193  image->name = name_copy;
195 
196  return 0;
197 }
unsigned int flags
Flags.
Definition: image.h:39
const char * name
Definition: ath9k_hw.c:1984
An executable image.
Definition: image.h:23
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
char * strdup(const char *src)
Duplicate string.
Definition: string.c:393
#define IMAGE_STATIC_NAME
Image name is statically allocated.
Definition: image.h:91
char * name
Name.
Definition: image.h:37

References ENOMEM, image::flags, free, IMAGE_STATIC_NAME, image::name, name, and strdup().

Referenced by cms_decrypt(), cpio_okx(), image_extract(), image_memory(), image_set_uri(), imgsingle_exec(), and register_image().

◆ image_strip_suffix()

char* image_strip_suffix ( struct image image)

Strip dot suffix from image name, if present.

Parameters
imageImage
Return values
sepPosition of old dot separator, or NULL

Definition at line 205 of file image.c.

205  {
206  char *dot;
207 
208  /* Locate and strip suffix, if present */
209  if ( image->name &&
210  ( ( dot = strrchr ( image->name, '.' ) ) != NULL ) ) {
211  *dot = '\0';
212  return dot;
213  }
214 
215  return NULL;
216 }
char * strrchr(const char *src, int character)
Find rightmost character within a string.
Definition: string.c:289
An executable image.
Definition: image.h:23
char * name
Name.
Definition: image.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References image::name, NULL, and strrchr().

Referenced by cms_decrypt(), and image_extract().

◆ image_set_cmdline()

int image_set_cmdline ( struct image image,
const char *  cmdline 
)

Set image command line.

Parameters
imageImage
cmdlineNew image command line, or NULL
Return values
rcReturn status code

Definition at line 225 of file image.c.

225  {
226 
227  free ( image->cmdline );
228  image->cmdline = NULL;
229  if ( cmdline ) {
230  image->cmdline = strdup ( cmdline );
231  if ( ! image->cmdline )
232  return -ENOMEM;
233  }
234  return 0;
235 }
An executable image.
Definition: image.h:23
char * cmdline
Command line to pass to image.
Definition: image.h:42
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
char * strdup(const char *src)
Duplicate string.
Definition: string.c:393
uint32_t cmdline
Definition: multiboot.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References cmdline, image::cmdline, ENOMEM, free, NULL, and strdup().

Referenced by cpio_okx(), image_clear_cmdline(), image_extract_exec(), and imgsingle_exec().

◆ image_set_len()

int image_set_len ( struct image image,
size_t  len 
)

Set image length.

Parameters
imageImage
lenLength of image data
Return values
rcReturn status code

Definition at line 244 of file image.c.

244  {
245  void *new;
246 
247  /* Refuse to reallocate static images */
248  if ( image->flags & IMAGE_STATIC )
249  return -ENOTTY;
250 
251  /* (Re)allocate image data */
252  new = urealloc ( image->rwdata, len );
253  if ( ! new )
254  return -ENOMEM;
255  image->rwdata = new;
256  image->len = len;
257 
258  return 0;
259 }
unsigned int flags
Flags.
Definition: image.h:39
An executable image.
Definition: image.h:23
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define IMAGE_STATIC
Image is statically allocated.
Definition: image.h:88
ring len
Length.
Definition: dwmac.h:231
size_t len
Length of raw file image.
Definition: image.h:55
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
void * rwdata
Writable data.
Definition: image.h:52
void * urealloc(void *ptr, size_t new_size)
Reallocate external memory.

References ENOMEM, ENOTTY, image::flags, IMAGE_STATIC, image::len, len, image::rwdata, and urealloc().

Referenced by cpio_okx(), gzip_extract(), image_set_data(), and zlib_deflate().

◆ image_set_data()

int image_set_data ( struct image image,
const void *  data,
size_t  len 
)

Set image data.

Parameters
imageImage
dataImage data
lenLength of image data
Return values
rcReturn status code

Definition at line 269 of file image.c.

269  {
270  int rc;
271 
272  /* Set image length */
273  if ( ( rc = image_set_len ( image, len ) ) != 0 )
274  return rc;
275 
276  /* Copy in new image data */
277  memcpy ( image->rwdata, data, len );
278 
279  return 0;
280 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An executable image.
Definition: image.h:23
void * memcpy(void *dest, const void *src, size_t len) __nonnull
ring len
Length.
Definition: dwmac.h:231
int image_set_len(struct image *image, size_t len)
Set image length.
Definition: image.c:244
void * rwdata
Writable data.
Definition: image.h:52
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References data, image_set_len(), len, memcpy(), rc, and image::rwdata.

Referenced by image_memory(), and zimg_extract().

◆ register_image()

int register_image ( struct image image)

Register executable image.

Parameters
imageExecutable image
Return values
rcReturn status code

Definition at line 314 of file image.c.

314  {
315  static unsigned int imgindex = 0;
316  char name[8]; /* "imgXXXX" */
317  int rc;
318 
319  /* Sanity checks */
320  if ( image->flags & IMAGE_STATIC ) {
321  assert ( ( image->name == NULL ) ||
322  ( image->flags & IMAGE_STATIC_NAME ) );
323  assert ( image->cmdline == NULL );
324  }
325 
326  /* Create image name if it doesn't already have one */
327  if ( ! image->name ) {
328  snprintf ( name, sizeof ( name ), "img%d", imgindex++ );
329  if ( ( rc = image_set_name ( image, name ) ) != 0 )
330  return rc;
331  }
332 
333  /* Add to image list */
334  image_get ( image );
336  list_add_tail ( &image->list, &images );
337  DBGC ( image, "IMAGE %s at [%lx,%lx) registered\n",
338  image->name, virt_to_phys ( image->data ),
339  ( virt_to_phys ( image->data ) + image->len ) );
340 
341  /* Try to detect image type, if applicable. Ignore failures,
342  * since we expect to handle some unrecognised images
343  * (e.g. kernel initrds, multiboot modules, random files
344  * provided via our EFI virtual filesystem, etc).
345  */
346  if ( ! image->type )
347  image_probe ( image );
348 
349  return 0;
350 }
unsigned int flags
Flags.
Definition: image.h:39
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
const void * data
Read-only data.
Definition: image.h:50
struct image_type * type
Image type, if known.
Definition: image.h:58
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition: image.h:239
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
char * cmdline
Command line to pass to image.
Definition: image.h:42
static int image_probe(struct image *image)
Determine image type.
Definition: image.c:288
#define IMAGE_STATIC
Image is statically allocated.
Definition: image.h:88
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
#define IMAGE_REGISTERED
Image is registered.
Definition: image.h:76
size_t len
Length of raw file image.
Definition: image.h:55
struct list_head images
List of registered images.
Definition: image.c:58
int image_set_name(struct image *image, const char *name)
Set image name.
Definition: image.c:180
#define IMAGE_STATIC_NAME
Image name is statically allocated.
Definition: image.h:91
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
struct list_head list
List of registered images.
Definition: image.h:28
char * name
Name.
Definition: image.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), image::cmdline, image::data, DBGC, image::flags, image_get(), image_probe(), IMAGE_REGISTERED, image_set_name(), IMAGE_STATIC, IMAGE_STATIC_NAME, images, image::len, image::list, list_add_tail, image::name, name, NULL, rc, snprintf(), and image::type.

Referenced by asn1_okx(), cmdline_init(), cms_decrypt(), efi_cmdline_init(), efi_image_exec(), embedded_init(), image_exec(), image_extract(), image_memory(), imgdownload(), pixbuf_okx(), and test_init().

◆ unregister_image()

void unregister_image ( struct image image)

Unregister executable image.

Parameters
imageExecutable image

Definition at line 357 of file image.c.

357  {
358 
359  /* Do nothing unless image is registered */
360  if ( ! ( image->flags & IMAGE_REGISTERED ) )
361  return;
362 
363  DBGC ( image, "IMAGE %s unregistered\n", image->name );
364  list_del ( &image->list );
366  image_put ( image );
367 }
unsigned int flags
Flags.
Definition: image.h:39
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define IMAGE_REGISTERED
Image is registered.
Definition: image.h:76
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:249
struct list_head list
List of registered images.
Definition: image.h:28
char * name
Name.
Definition: image.h:37

References DBGC, image::flags, image_put(), IMAGE_REGISTERED, image::list, list_del, and image::name.

Referenced by asn1_okx(), bzimage_exec(), cert_exec(), cms_decrypt(), com32_exec_loop(), comboot_exec_loop(), console_exec(), efi_autoexec_load(), efi_image_exec(), fdt_test_exec(), gzip_okx(), image_exec(), image_extract(), image_extract_exec(), imgdecrypt_exec(), imgextract_exec(), imgfree_exec(), imgverify_exec(), pixbuf_okx(), and zlib_okx().

◆ find_image()

struct image* find_image ( const char *  name)

Find image by name.

Parameters
nameImage name
Return values
imageExecutable image, or NULL

Definition at line 375 of file image.c.

375  {
376  struct image *image;
377 
378  for_each_image ( image ) {
379  if ( strcmp ( image->name, name ) == 0 )
380  return image;
381  }
382 
383  return NULL;
384 }
const char * name
Definition: ath9k_hw.c:1984
An executable image.
Definition: image.h:23
#define for_each_image(image)
Iterate over all registered images.
Definition: image.h:190
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
char * name
Name.
Definition: image.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References for_each_image, image::name, name, NULL, and strcmp().

Referenced by imgacquire(), and imgmulti_exec().

◆ find_image_tag()

struct image* find_image_tag ( struct image_tag tag)

Find image by tag.

Parameters
tagImage tag
Return values
imageExecutable image, or NULL

Definition at line 392 of file image.c.

392  {
393  struct image *image;
394 
395  for_each_image ( image ) {
396  if ( tag->image == image )
397  return image;
398  }
399 
400  return NULL;
401 }
An executable image.
Definition: image.h:23
#define for_each_image(image)
Iterate over all registered images.
Definition: image.h:190
uint64_t tag
Identity tag.
Definition: edd.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References for_each_image, NULL, and tag.

Referenced by efi_file_open(), efi_image_exec(), fdt_create(), imgsingle_exec(), and shim_exec().

◆ image_exec()

int image_exec ( struct image image)

Execute image.

Parameters
imageExecutable image
Return values
rcReturn status code

The image must already be registered. Note that executing an image may cause it to unregister itself. The caller must therefore assume that the image pointer becomes invalid.

Definition at line 413 of file image.c.

413  {
414  struct image *saved_current_image;
415  struct image *replacement = NULL;
416  struct uri *old_cwuri;
417  int rc;
418 
419  /* Sanity check */
421 
422  /* Switch current working directory to be that of the image
423  * itself, if applicable
424  */
425  old_cwuri = uri_get ( cwuri );
426  if ( image->uri )
427  churi ( image->uri );
428 
429  /* Set as currently running image */
430  saved_current_image = image_tag ( image, &current_image );
431 
432  /* Take out a temporary reference to the image, so that it
433  * does not get freed when temporarily unregistered.
434  */
435  image_get ( image );
436 
437  /* Check that this image can be executed */
438  if ( ! ( image->type && image->type->exec ) ) {
439  rc = -ENOEXEC;
440  goto err;
441  }
442 
443  /* Check that image is trusted (if applicable) */
444  if ( require_trusted_images && ! ( image->flags & IMAGE_TRUSTED ) ) {
445  DBGC ( image, "IMAGE %s is not trusted\n", image->name );
446  rc = -EACCES_UNTRUSTED;
447  goto err;
448  }
449 
450  /* Record boot attempt */
451  syslog ( LOG_NOTICE, "Executing \"%s\"\n", image->name );
452 
453  /* Temporarily unregister the image during its execution */
455 
456  /* Try executing the image */
457  if ( ( rc = image->type->exec ( image ) ) != 0 ) {
458  DBGC ( image, "IMAGE %s could not execute: %s\n",
459  image->name, strerror ( rc ) );
460  /* Do not return yet; we still have clean-up to do */
461  }
462 
463  /* Record result of boot attempt */
464  if ( rc == 0 ) {
465  syslog ( LOG_NOTICE, "Execution of \"%s\" completed\n",
466  image->name );
467  } else {
468  syslog ( LOG_ERR, "Execution of \"%s\" failed: %s\n",
469  image->name, strerror ( rc ) );
470  }
471 
472  /* Re-register image (unless due to be replaced) */
473  if ( ! image->replacement )
474  register_image ( image );
475 
476  /* Pick up replacement image before we drop the original
477  * image's temporary reference. The replacement image must
478  * already be registered, so we don't need to hold a temporary
479  * reference (which would complicate the tail-recursion).
480  */
482  if ( replacement )
483  assert ( replacement->flags & IMAGE_REGISTERED );
484 
485  /* Clear any recorded replacement image */
488 
489  err:
490  /* Unregister image if applicable */
493 
494  /* Debug message for tail-recursion. Placed here because the
495  * image_put() may end up freeing the image.
496  */
497  if ( replacement ) {
498  DBGC ( image, "IMAGE %s replacing self with IMAGE %s\n",
499  image->name, replacement->name );
500  }
501 
502  /* Drop temporary reference to the original image */
503  image_put ( image );
504 
505  /* Restore previous currently-running image */
506  image_tag ( saved_current_image, &current_image );
507 
508  /* Reset current working directory */
509  churi ( old_cwuri );
510  uri_put ( old_cwuri );
511 
512  /* Tail-recurse into replacement image, if one exists */
513  if ( replacement )
514  return image_exec ( replacement );
515 
516  return rc;
517 }
unsigned int flags
Flags.
Definition: image.h:39
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:194
#define EACCES_UNTRUSTED
Definition: image.c:48
#define ENOEXEC
Exec format error.
Definition: errno.h:519
struct image_type * type
Image type, if known.
Definition: image.h:58
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition: image.h:239
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
#define LOG_ERR
Error: error conditions.
Definition: syslog.h:35
#define IMAGE_AUTO_UNREGISTER
Image will be automatically unregistered after execution.
Definition: image.h:82
int(* exec)(struct image *image)
Execute image.
Definition: image.h:112
int image_exec(struct image *image)
Execute image.
Definition: image.c:413
struct image_tag current_image
void churi(struct uri *uri)
Change working URI.
Definition: cwuri.c:45
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
const char * replacement
Definition: editstring.h:53
#define IMAGE_REGISTERED
Image is registered.
Definition: image.h:76
int register_image(struct image *image)
Register executable image.
Definition: image.c:314
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define IMAGE_TRUSTED
Image is trusted.
Definition: image.h:79
struct uri * uri
URI of image.
Definition: image.h:31
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:249
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:357
#define syslog(priority, fmt,...)
Write message to system log.
Definition: syslog.h:93
struct image * replacement
Replacement image.
Definition: image.h:72
A Uniform Resource Identifier.
Definition: uri.h:64
static int require_trusted_images
Current image trust requirement.
Definition: image.c:71
struct uri * cwuri
Current working URI.
Definition: cwuri.c:38
static struct image * image_tag(struct image *image, struct image_tag *tag)
Tag image.
Definition: image.h:296
char * name
Name.
Definition: image.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define LOG_NOTICE
Notice: normal but significant conditions.
Definition: syslog.h:41

References assert(), churi(), current_image, cwuri, DBGC, EACCES_UNTRUSTED, ENOEXEC, image_type::exec, image::flags, IMAGE_AUTO_UNREGISTER, image_exec(), image_get(), image_put(), IMAGE_REGISTERED, image_tag(), IMAGE_TRUSTED, LOG_ERR, LOG_NOTICE, image::name, NULL, rc, register_image(), replacement, image::replacement, require_trusted_images, strerror(), syslog, image::type, unregister_image(), image::uri, uri_get(), and uri_put().

Referenced by image_exec(), imgexec(), ipxe(), and uriboot().

◆ image_replace()

int image_replace ( struct image replacement)

Set replacement image.

Parameters
replacementReplacement image
Return values
rcReturn status code

The replacement image must already be registered, and must remain registered until the currently-executing image returns.

Definition at line 528 of file image.c.

528  {
529  struct image *image = current_image.image;
530  int rc;
531 
532  /* Sanity check */
533  assert ( replacement->flags & IMAGE_REGISTERED );
534 
535  /* Fail unless there is a currently-executing image */
536  if ( ! image ) {
537  rc = -ENOTTY;
538  DBGC ( replacement, "IMAGE %s cannot replace non-existent "
539  "image: %s\n", replacement->name, strerror ( rc ) );
540  return rc;
541  }
542 
543  /* Check that the replacement image can be executed */
544  if ( ! ( replacement->type && replacement->type->exec ) )
545  return -ENOEXEC;
546 
547  /* Clear any existing replacement */
549 
550  /* Set replacement */
552  DBGC ( image, "IMAGE %s will replace self with IMAGE %s\n",
553  image->name, replacement->name );
554 
555  return 0;
556 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ENOEXEC
Exec format error.
Definition: errno.h:519
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition: image.h:239
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
struct image * image
Image (weak reference, nullified when image is freed)
Definition: image.h:176
struct image_tag current_image
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
const char * replacement
Definition: editstring.h:53
#define IMAGE_REGISTERED
Image is registered.
Definition: image.h:76
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:249
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
struct image * replacement
Replacement image.
Definition: image.h:72
char * name
Name.
Definition: image.h:37

References assert(), current_image, DBGC, ENOEXEC, ENOTTY, image_tag::image, image_get(), image_put(), IMAGE_REGISTERED, image::name, rc, replacement, image::replacement, and strerror().

Referenced by comboot_fetch_kernel(), image_extract_exec(), and imgexec().

◆ image_select()

int image_select ( struct image image)

Select image for execution.

Parameters
imageExecutable image
Return values
rcReturn status code

Definition at line 564 of file image.c.

564  {
565 
566  /* Check that this image can be executed */
567  if ( ! ( image->type && image->type->exec ) )
568  return -ENOEXEC;
569 
570  /* Mark image as selected */
572 
573  return 0;
574 }
struct image_tag selected_image
#define ENOEXEC
Exec format error.
Definition: errno.h:519
struct image_type * type
Image type, if known.
Definition: image.h:58
An executable image.
Definition: image.h:23
int(* exec)(struct image *image)
Execute image.
Definition: image.h:112
static struct image * image_tag(struct image *image, struct image_tag *tag)
Tag image.
Definition: image.h:296

References ENOEXEC, image_type::exec, image_tag(), selected_image, and image::type.

Referenced by embedded_init(), and imgselect().

◆ image_set_trust()

int image_set_trust ( int  require_trusted,
int  permanent 
)

Change image trust requirement.

Parameters
require_trustedRequire trusted images
permanentMake trust requirement permanent
Return values
rcReturn status code

Definition at line 583 of file image.c.

583  {
584 
585  /* Update trust requirement, if permitted to do so */
587  require_trusted_images = require_trusted;
589  }
590 
591  /* Fail if we attempted to change the trust requirement but
592  * were not permitted to do so.
593  */
594  if ( require_trusted_images != require_trusted )
595  return -EACCES_PERMANENT;
596 
597  return 0;
598 }
static int require_trusted_images_permanent
Prevent changes to image trust requirement.
Definition: image.c:74
#define EACCES_PERMANENT
Definition: image.c:52
static int require_trusted_images
Current image trust requirement.
Definition: image.c:71

References EACCES_PERMANENT, require_trusted_images, and require_trusted_images_permanent.

Referenced by imgtrust_exec().

◆ image_memory()

struct image* image_memory ( const char *  name,
const void *  data,
size_t  len 
)

Create registered image from block of memory.

Parameters
nameName
dataImage data
lenLength
Return values
imageImage, or NULL on error

Definition at line 608 of file image.c.

609  {
610  struct image *image;
611  int rc;
612 
613  /* Allocate image */
614  image = alloc_image ( NULL );
615  if ( ! image ) {
616  rc = -ENOMEM;
617  goto err_alloc_image;
618  }
619 
620  /* Set name */
621  if ( ( rc = image_set_name ( image, name ) ) != 0 )
622  goto err_set_name;
623 
624  /* Set data */
625  if ( ( rc = image_set_data ( image, data, len ) ) != 0 )
626  goto err_set_data;
627 
628  /* Register image */
629  if ( ( rc = register_image ( image ) ) != 0 )
630  goto err_register;
631 
632  /* Drop local reference to image */
633  image_put ( image );
634 
635  return image;
636 
637  err_register:
638  err_set_data:
639  err_set_name:
640  image_put ( image );
641  err_alloc_image:
642  return NULL;
643 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
An executable image.
Definition: image.h:23
#define ENOMEM
Not enough space.
Definition: errno.h:534
ring len
Length.
Definition: dwmac.h:231
int register_image(struct image *image)
Register executable image.
Definition: image.c:314
int image_set_name(struct image *image, const char *name)
Set image name.
Definition: image.c:180
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:249
int image_set_data(struct image *image, const void *data, size_t len)
Set image data.
Definition: image.c:269
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct image * alloc_image(struct uri *uri)
Allocate executable image.
Definition: image.c:123
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References alloc_image(), data, ENOMEM, image_put(), image_set_data(), image_set_name(), len, name, NULL, rc, and register_image().

Referenced by fdt_test_exec(), gzip_okx(), imgmem(), initrd_init(), and zlib_okx().

◆ image_argument()

const char* image_argument ( struct image image,
const char *  key 
)

Find argument within image command line.

Parameters
imageImage
keyArgument search key (including trailing delimiter)
Return values
valueArgument value, or NULL if not found

Definition at line 652 of file image.c.

652  {
653  const char *cmdline = image->cmdline;
654  const char *search;
655  const char *match;
656  const char *next;
657 
658  /* Find argument */
659  for ( search = cmdline ; search ; search = next ) {
660 
661  /* Find next occurrence, if any */
662  match = strstr ( search, key );
663  if ( ! match )
664  break;
665  next = ( match + strlen ( key ) );
666 
667  /* Check preceding delimiter, if any */
668  if ( ( match == cmdline ) || isspace ( match[-1] ) )
669  return next;
670  }
671 
672  return NULL;
673 }
An executable image.
Definition: image.h:23
char * cmdline
Command line to pass to image.
Definition: image.h:42
char * strstr(const char *haystack, const char *needle)
Find substring.
Definition: string.c:309
int isspace(int character)
Check to see if character is a space.
Definition: ctype.c:41
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
uint32_t cmdline
Definition: multiboot.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
union @391 key
Sense key.
Definition: scsi.h:17

References cmdline, image::cmdline, isspace(), key, next, NULL, strlen(), and strstr().

Referenced by bzimage_parse_cmdline(), and cpio_parse_cmdline().

◆ image_pixbuf()

int image_pixbuf ( struct image image,
struct pixel_buffer **  pixbuf 
)

Create pixel buffer from image.

Parameters
imageImage
pixbufPixel buffer to fill in
Return values
rcReturn status code

Definition at line 99 of file pixbuf.c.

99  {
100  int rc;
101 
102  /* Check that this image can be used to create a pixel buffer */
103  if ( ! ( image->type && image->type->pixbuf ) )
104  return -ENOTSUP;
105 
106  /* Try creating pixel buffer */
107  if ( ( rc = image->type->pixbuf ( image, pixbuf ) ) != 0 ) {
108  DBGC ( image, "IMAGE %s could not create pixel buffer: %s\n",
109  image->name, strerror ( rc ) );
110  return rc;
111  }
112 
113  return 0;
114 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct image_type * type
Image type, if known.
Definition: image.h:58
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int(* pixbuf)(struct image *image, struct pixel_buffer **pixbuf)
Create pixel buffer from image.
Definition: image.h:120
char * name
Name.
Definition: image.h:37

References DBGC, ENOTSUP, image::name, image_type::pixbuf, rc, strerror(), and image::type.

Referenced by console_exec(), and pixbuf_okx().

◆ image_asn1()

int image_asn1 ( struct image image,
size_t  offset,
struct asn1_cursor **  cursor 
)

Extract ASN.1 object from image.

Parameters
imageImage
offsetOffset within image
cursorASN.1 cursor to fill in
Return values
nextOffset to next image, or negative error

The caller is responsible for eventually calling free() on the allocated ASN.1 cursor.

Definition at line 1015 of file asn1.c.

1016  {
1017  int next;
1018  int rc;
1019 
1020  /* Sanity check */
1021  assert ( offset <= image->len );
1022 
1023  /* Check that this image can be used to extract an ASN.1 object */
1024  if ( ! ( image->type && image->type->asn1 ) )
1025  return -ENOTSUP;
1026 
1027  /* Try creating ASN.1 cursor */
1028  next = image->type->asn1 ( image, offset, cursor );
1029  if ( next < 0 ) {
1030  rc = next;
1031  DBGC ( image, "IMAGE %s could not extract ASN.1 object: %s\n",
1032  image->name, strerror ( rc ) );
1033  return rc;
1034  }
1035 
1036  return next;
1037 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct image_type * type
Image type, if known.
Definition: image.h:58
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
int(* asn1)(struct image *image, size_t offset, struct asn1_cursor **cursor)
Extract ASN.1 object from image.
Definition: image.h:132
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
char * name
Name.
Definition: image.h:37

References image_type::asn1, assert(), DBGC, ENOTSUP, len, image::name, next, offset, rc, strerror(), and image::type.

Referenced by asn1_okx(), cms_message(), and image_x509().

◆ image_extract()

int image_extract ( struct image image,
const char *  name,
struct image **  extracted 
)

Extract archive image.

Parameters
imageImage
nameExtracted image name
extractedExtracted image to fill in
Return values
rcReturn status code

Definition at line 44 of file archive.c.

45  {
46  int rc;
47 
48  /* Check that this image can be used to extract an archive image */
49  if ( ! ( image->type && image->type->extract ) ) {
50  rc = -ENOTSUP;
51  goto err_unsupported;
52  }
53 
54  /* Allocate new image */
55  *extracted = alloc_image ( image->uri );
56  if ( ! *extracted ) {
57  rc = -ENOMEM;
58  goto err_alloc;
59  }
60 
61  /* Set image name */
62  if ( ( rc = image_set_name ( *extracted,
63  ( name ? name : image->name ) ) ) != 0 ) {
64  goto err_set_name;
65  }
66 
67  /* Strip any archive or compression suffix from implicit name */
68  if ( ! name )
69  image_strip_suffix ( *extracted );
70 
71  /* Try extracting archive image */
72  if ( ( rc = image->type->extract ( image, *extracted ) ) != 0 ) {
73  DBGC ( image, "IMAGE %s could not extract image: %s\n",
74  image->name, strerror ( rc ) );
75  goto err_extract;
76  }
77 
78  /* Register image */
79  if ( ( rc = register_image ( *extracted ) ) != 0 )
80  goto err_register;
81 
82  /* Propagate trust flag */
83  if ( image->flags & IMAGE_TRUSTED )
84  image_trust ( *extracted );
85 
86  /* Drop local reference to image */
87  image_put ( *extracted );
88 
89  return 0;
90 
91  unregister_image ( *extracted );
92  err_register:
93  err_extract:
94  err_set_name:
95  image_put ( *extracted );
96  err_alloc:
97  err_unsupported:
98  return rc;
99 }
unsigned int flags
Flags.
Definition: image.h:39
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
char * image_strip_suffix(struct image *image)
Strip dot suffix from image name, if present.
Definition: image.c:205
struct image_type * type
Image type, if known.
Definition: image.h:58
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define ENOMEM
Not enough space.
Definition: errno.h:534
int register_image(struct image *image)
Register executable image.
Definition: image.c:314
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int image_set_name(struct image *image, const char *name)
Set image name.
Definition: image.c:180
#define IMAGE_TRUSTED
Image is trusted.
Definition: image.h:79
struct uri * uri
URI of image.
Definition: image.h:31
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:249
int(* extract)(struct image *image, struct image *extracted)
Extract archive image.
Definition: image.h:141
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:357
static void image_trust(struct image *image)
Set image as trusted.
Definition: image.h:267
struct image * alloc_image(struct uri *uri)
Allocate executable image.
Definition: image.c:123
char * name
Name.
Definition: image.h:37

References alloc_image(), DBGC, ENOMEM, ENOTSUP, image_type::extract, image::flags, image_put(), image_set_name(), image_strip_suffix(), image_trust(), IMAGE_TRUSTED, image::name, name, rc, register_image(), strerror(), image::type, unregister_image(), and image::uri.

Referenced by gzip_okx(), image_extract_exec(), imgextract(), and zlib_okx().

◆ image_extract_exec()

int image_extract_exec ( struct image image)

Extract and execute image.

Parameters
imageImage
Return values
rcReturn status code

Definition at line 107 of file archive.c.

107  {
108  struct image *extracted;
109  int rc;
110 
111  /* Extract image */
112  if ( ( rc = image_extract ( image, NULL, &extracted ) ) != 0 )
113  goto err_extract;
114 
115  /* Set image command line */
116  if ( ( rc = image_set_cmdline ( extracted, image->cmdline ) ) != 0 )
117  goto err_set_cmdline;
118 
119  /* Set auto-unregister flag */
120  extracted->flags |= IMAGE_AUTO_UNREGISTER;
121 
122  /* Replace current image */
123  if ( ( rc = image_replace ( extracted ) ) != 0 )
124  goto err_replace;
125 
126  /* Return to allow replacement image to be executed */
127  return 0;
128 
129  err_replace:
130  err_set_cmdline:
131  unregister_image ( extracted );
132  err_extract:
133  return rc;
134 }
unsigned int flags
Flags.
Definition: image.h:39
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An executable image.
Definition: image.h:23
#define IMAGE_AUTO_UNREGISTER
Image will be automatically unregistered after execution.
Definition: image.h:82
char * cmdline
Command line to pass to image.
Definition: image.h:42
int image_extract(struct image *image, const char *name, struct image **extracted)
Extract archive image.
Definition: archive.c:44
int image_replace(struct image *replacement)
Set replacement image.
Definition: image.c:528
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:357
int image_set_cmdline(struct image *image, const char *cmdline)
Set image command line.
Definition: image.c:225
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References image::cmdline, image::flags, IMAGE_AUTO_UNREGISTER, image_extract(), image_replace(), image_set_cmdline(), NULL, rc, and unregister_image().

◆ image_get()

static struct image* image_get ( struct image image)
inlinestatic

Increment reference count on an image.

Parameters
imageImage
Return values
imageImage

Definition at line 239 of file image.h.

239  {
240  ref_get ( &image->refcnt );
241  return image;
242 }
An executable image.
Definition: image.h:23
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
struct refcnt refcnt
Reference count.
Definition: image.h:25

References ref_get, and image::refcnt.

Referenced by bzimage_exec(), cms_decrypt(), create_downloader(), efi_file_open_image(), image_exec(), image_replace(), and register_image().

◆ image_put()

static void image_put ( struct image image)
inlinestatic

Decrement reference count on an image.

Parameters
imageImage

Definition at line 249 of file image.h.

249  {
250  ref_put ( &image->refcnt );
251 }
An executable image.
Definition: image.h:23
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
struct refcnt refcnt
Reference count.
Definition: image.h:25

References ref_put, and image::refcnt.

Referenced by alloc_image(), cmdline_init(), cms_decrypt(), cpio_okx(), downloader_free(), efi_cmdline_init(), efi_file_free(), free_image(), image_exec(), image_extract(), image_memory(), image_replace(), imgdownload(), and unregister_image().

◆ image_clear_cmdline()

static void image_clear_cmdline ( struct image image)
inlinestatic

Clear image command line.

Parameters
imageImage

Definition at line 258 of file image.h.

258  {
260 }
int image_set_cmdline(struct image *image, const char *cmdline)
Set image command line.
Definition: image.c:225
An executable image.
Definition: image.h:23
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References image_set_cmdline(), and NULL.

◆ image_trust()

static void image_trust ( struct image image)
inlinestatic

Set image as trusted.

Parameters
imageImage

Definition at line 267 of file image.h.

267  {
269 }
unsigned int flags
Flags.
Definition: image.h:39
An executable image.
Definition: image.h:23
#define IMAGE_TRUSTED
Image is trusted.
Definition: image.h:79

References image::flags, and IMAGE_TRUSTED.

Referenced by cms_verify(), embedded_init(), and image_extract().

◆ image_untrust()

static void image_untrust ( struct image image)
inlinestatic

Set image as untrusted.

Parameters
imageImage

Definition at line 276 of file image.h.

276  {
278 }
unsigned int flags
Flags.
Definition: image.h:39
An executable image.
Definition: image.h:23
#define IMAGE_TRUSTED
Image is trusted.
Definition: image.h:79

References image::flags, and IMAGE_TRUSTED.

Referenced by cms_decrypt(), and cms_verify().

◆ image_hide()

static void image_hide ( struct image image)
inlinestatic

Mark image as hidden.

Parameters
imageImage

Definition at line 285 of file image.h.

285  {
287 }
unsigned int flags
Flags.
Definition: image.h:39
An executable image.
Definition: image.h:23
#define IMAGE_HIDDEN
Image will be hidden from enumeration.
Definition: image.h:85

References image::flags, and IMAGE_HIDDEN.

Referenced by imgfdt(), and shim().

◆ image_tag()

static struct image* image_tag ( struct image image,
struct image_tag tag 
)
inlinestatic

Tag image.

Parameters
imageImage
tagImage tag
Return values
prevPrevious tagged image (if any)

Definition at line 296 of file image.h.

297  {
298  struct image *prev = tag->image;
299 
300  tag->image = image;
301  return prev;
302 }
An executable image.
Definition: image.h:23
uint64_t tag
Identity tag.
Definition: edd.h:30

References tag.

Referenced by fdt_test_exec(), image_exec(), image_select(), imgfdt(), and shim().

Variable Documentation

◆ __attribute__

◆ images

struct list_head images

List of registered images.

Definition at line 58 of file image.c.

Referenced by first_image(), initrd_dump(), initrd_load(), initrd_region(), initrd_squash_high(), initrd_startup(), initrd_swap(), lkrn_exec(), and register_image().

◆ current_image

struct image_tag current_image

◆ selected_image

struct image_tag selected_image