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

Executable images. More...

#include <ipxe/tables.h>
#include <ipxe/list.h>
#include <ipxe/uaccess.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...
 

Macros

#define IMAGE_REGISTERED   0x00001
 Image is registered. More...
 
#define IMAGE_SELECTED   0x0002
 Image is selected for execution. More...
 
#define IMAGE_TRUSTED   0x0004
 Image is trusted. More...
 
#define IMAGE_AUTO_UNREGISTER   0x0008
 Image will be automatically unregistered after execution. 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 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 int have_images (void)
 Test for existence of images. More...
 
static struct imagefirst_image (void)
 Retrieve first 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...
 
int image_set_cmdline (struct image *image, const char *cmdline)
 Set image command line. 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...
 
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...
 
struct imageimage_find_selected (void)
 Find selected image. More...
 
int image_set_trust (int require_trusted, int permanent)
 Change image trust requirement. 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...
 
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...
 

Variables

struct image __attribute__
 
struct list_head images
 List of registered images. More...
 
struct imagecurrent_image
 Currently-executing image. More...
 

Detailed Description

Executable images.

Definition in file image.h.

Macro Definition Documentation

◆ IMAGE_REGISTERED

#define IMAGE_REGISTERED   0x00001

Image is registered.

Definition at line 64 of file image.h.

◆ IMAGE_SELECTED

#define IMAGE_SELECTED   0x0002

Image is selected for execution.

Definition at line 67 of file image.h.

◆ IMAGE_TRUSTED

#define IMAGE_TRUSTED   0x0004

Image is trusted.

Definition at line 70 of file image.h.

◆ IMAGE_AUTO_UNREGISTER

#define IMAGE_AUTO_UNREGISTER   0x0008

Image will be automatically unregistered after execution.

Definition at line 73 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 124 of file image.h.

◆ PROBE_NORMAL

#define PROBE_NORMAL   02

Normal image probe priority.

Definition at line 129 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 137 of file image.h.

◆ IMAGE_TYPES

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

Executable image type table.

Definition at line 140 of file image.h.

◆ __image_type

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

An executable image type.

Definition at line 143 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 149 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 153 of file image.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ have_images()

static int have_images ( void  )
inlinestatic

Test for existence of images.

Return values
existenceSome images exist

Definition at line 161 of file image.h.

161  {
162  return ( ! list_empty ( &images ) );
163 }
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
struct list_head images
List of registered images.
Definition: image.c:56

References images, and list_empty.

◆ first_image()

static struct image* first_image ( void  )
inlinestatic

Retrieve first image.

Return values
imageImage, or NULL

Definition at line 170 of file image.h.

170  {
171  return list_first_entry ( &images, struct image, list );
172 }
An executable image.
Definition: image.h:24
#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:56

References images, image::list, and list_first_entry.

Referenced by ipxe().

◆ alloc_image()

struct image* alloc_image ( struct uri uri)

Allocate executable image.

Parameters
uriURI, or NULL
Return values
imageExecutable image

Definition at line 90 of file image.c.

90  {
91  struct image *image;
92  int rc;
93 
94  /* Allocate image */
95  image = zalloc ( sizeof ( *image ) );
96  if ( ! image )
97  goto err_alloc;
98 
99  /* Initialise image */
101  if ( uri && ( ( rc = image_set_uri ( image, uri ) ) != 0 ) )
102  goto err_set_uri;
103 
104  return image;
105 
106  err_set_uri:
107  image_put ( image );
108  err_alloc:
109  return NULL;
110 }
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:119
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
An executable image.
Definition: image.h:24
static void free_image(struct refcnt *refcnt)
Free executable image.
Definition: image.c:72
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:206
A Uniform Resource Identifier.
Definition: uri.h:50
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct refcnt refcnt
Reference count.
Definition: image.h:26

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

Referenced by imgdownload(), and initrd_init().

◆ 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 119 of file image.c.

119  {
120  const char *name;
121  int rc;
122 
123  /* Set name, if image does not already have one */
124  if ( uri->path && ( ! ( image->name && image->name[0] ) ) ) {
125  name = basename ( ( char * ) uri->path );
126  if ( ( rc = image_set_name ( image, name ) ) != 0 )
127  return rc;
128  }
129 
130  /* Update image URI */
131  uri_put ( image->uri );
132  image->uri = uri_get ( uri );
133 
134  return 0;
135 }
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:188
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:177
An executable image.
Definition: image.h:24
const char * path
Path.
Definition: uri.h:66
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:144
struct uri * uri
URI of image.
Definition: image.h:32
A Uniform Resource Identifier.
Definition: uri.h:50
char * name
Name.
Definition: image.h:34

References basename(), image_set_name(), image::name, name, 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 144 of file image.c.

144  {
145  char *name_copy;
146 
147  /* Duplicate name */
148  name_copy = strdup ( name );
149  if ( ! name_copy )
150  return -ENOMEM;
151 
152  /* Replace existing name */
153  free ( image->name );
154  image->name = name_copy;
155 
156  return 0;
157 }
const char * name
Definition: ath9k_hw.c:1984
An executable image.
Definition: image.h:24
#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:350
char * name
Name.
Definition: image.h:34

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

Referenced by image_set_uri(), imgsingle_exec(), initrd_init(), and register_image().

◆ 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 166 of file image.c.

166  {
167 
168  free ( image->cmdline );
169  image->cmdline = NULL;
170  if ( cmdline ) {
171  image->cmdline = strdup ( cmdline );
172  if ( ! image->cmdline )
173  return -ENOMEM;
174  }
175  return 0;
176 }
An executable image.
Definition: image.h:24
char * cmdline
Command line to pass to image.
Definition: image.h:39
#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:350
uint32_t cmdline
Definition: multiboot.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by image_clear_cmdline(), and imgsingle_exec().

◆ register_image()

int register_image ( struct image image)

Register executable image.

Parameters
imageExecutable image
Return values
rcReturn status code

Definition at line 210 of file image.c.

210  {
211  static unsigned int imgindex = 0;
212  char name[8]; /* "imgXXXX" */
213  int rc;
214 
215  /* Create image name if it doesn't already have one */
216  if ( ! image->name ) {
217  snprintf ( name, sizeof ( name ), "img%d", imgindex++ );
218  if ( ( rc = image_set_name ( image, name ) ) != 0 )
219  return rc;
220  }
221 
222  /* Avoid ending up with multiple "selected" images on
223  * re-registration
224  */
225  if ( image_find_selected() )
227 
228  /* Add to image list */
229  image_get ( image );
231  list_add_tail ( &image->list, &images );
232  DBGC ( image, "IMAGE %s at [%lx,%lx) registered\n",
233  image->name, user_to_phys ( image->data, 0 ),
234  user_to_phys ( image->data, image->len ) );
235 
236  /* Try to detect image type, if applicable. Ignore failures,
237  * since we expect to handle some unrecognised images
238  * (e.g. kernel initrds, multiboot modules, random files
239  * provided via our EFI virtual filesystem, etc).
240  */
241  if ( ! image->type )
242  image_probe ( image );
243 
244  return 0;
245 }
unsigned int flags
Flags.
Definition: image.h:36
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
userptr_t data
Raw file image.
Definition: image.h:41
struct image_type * type
Image type, if known.
Definition: image.h:46
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition: image.h:196
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
static int image_probe(struct image *image)
Determine image type.
Definition: image.c:184
#define IMAGE_SELECTED
Image is selected for execution.
Definition: image.h:67
#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:64
size_t len
Length of raw file image.
Definition: image.h:43
struct list_head images
List of registered images.
Definition: image.c:56
int image_set_name(struct image *image, const char *name)
Set image name.
Definition: image.c:144
struct image * image_find_selected(void)
Find selected image.
Definition: image.c:451
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:29
char * name
Name.
Definition: image.h:34

References image::data, DBGC, image::flags, image_find_selected(), image_get(), image_probe(), IMAGE_REGISTERED, IMAGE_SELECTED, image_set_name(), images, image::len, image::list, list_add_tail, image::name, name, rc, snprintf(), image::type, and user_to_phys().

Referenced by asn1_okx(), cmdline_init(), embedded_init(), imgdownload(), initrd_init(), pixbuf_okx(), script_exec(), and test_init().

◆ unregister_image()

void unregister_image ( struct image image)

Unregister executable image.

Parameters
imageExecutable image

Definition at line 252 of file image.c.

252  {
253 
254  /* Do nothing unless image is registered */
255  if ( ! ( image->flags & IMAGE_REGISTERED ) )
256  return;
257 
258  DBGC ( image, "IMAGE %s unregistered\n", image->name );
259  list_del ( &image->list );
261  image_put ( image );
262 }
unsigned int flags
Flags.
Definition: image.h:36
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define IMAGE_REGISTERED
Image is registered.
Definition: image.h:64
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:206
struct list_head list
List of registered images.
Definition: image.h:29
char * name
Name.
Definition: image.h:34

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

Referenced by asn1_okx(), bzimage_exec(), cert_exec(), com32_exec_loop(), comboot_exec_loop(), console_exec(), image_exec(), imgfree_exec(), imgverify_exec(), pixbuf_okx(), and script_exec().

◆ 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 270 of file image.c.

270  {
271  struct image *image;
272 
274  if ( strcmp ( image->name, name ) == 0 )
275  return image;
276  }
277 
278  return NULL;
279 }
const char * name
Definition: ath9k_hw.c:1984
An executable image.
Definition: image.h:24
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
struct list_head images
List of registered images.
Definition: image.c:56
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:157
struct list_head list
List of registered images.
Definition: image.h:29
char * name
Name.
Definition: image.h:34
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References images, image::list, list_for_each_entry, image::name, name, NULL, and strcmp().

Referenced by imgacquire(), and imgmulti_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 291 of file image.c.

291  {
292  struct image *saved_current_image;
293  struct image *replacement = NULL;
294  struct uri *old_cwuri;
295  int rc;
296 
297  /* Sanity check */
299 
300  /* Switch current working directory to be that of the image itself */
301  old_cwuri = uri_get ( cwuri );
302  churi ( image->uri );
303 
304  /* Preserve record of any currently-running image */
305  saved_current_image = current_image;
306 
307  /* Take out a temporary reference to the image. This allows
308  * the image to unregister itself if necessary, without
309  * automatically freeing itself.
310  */
312 
313  /* Check that this image can be executed */
314  if ( ! ( image->type && image->type->exec ) ) {
315  rc = -ENOEXEC;
316  goto err;
317  }
318 
319  /* Check that image is trusted (if applicable) */
320  if ( require_trusted_images && ! ( image->flags & IMAGE_TRUSTED ) ) {
321  DBGC ( image, "IMAGE %s is not trusted\n", image->name );
322  rc = -EACCES_UNTRUSTED;
323  goto err;
324  }
325 
326  /* Record boot attempt */
327  syslog ( LOG_NOTICE, "Executing \"%s\"\n", image->name );
328 
329  /* Try executing the image */
330  if ( ( rc = image->type->exec ( image ) ) != 0 ) {
331  DBGC ( image, "IMAGE %s could not execute: %s\n",
332  image->name, strerror ( rc ) );
333  /* Do not return yet; we still have clean-up to do */
334  }
335 
336  /* Record result of boot attempt */
337  if ( rc == 0 ) {
338  syslog ( LOG_NOTICE, "Execution of \"%s\" completed\n",
339  image->name );
340  } else {
341  syslog ( LOG_ERR, "Execution of \"%s\" failed: %s\n",
342  image->name, strerror ( rc ) );
343  }
344 
345  /* Pick up replacement image before we drop the original
346  * image's temporary reference. The replacement image must
347  * already be registered, so we don't need to hold a temporary
348  * reference (which would complicate the tail-recursion).
349  */
350  replacement = image->replacement;
351  if ( replacement )
352  assert ( replacement->flags & IMAGE_REGISTERED );
353 
354  err:
355  /* Unregister image if applicable */
358 
359  /* Debug message for tail-recursion. Placed here because the
360  * image_put() may end up freeing the image.
361  */
362  if ( replacement ) {
363  DBGC ( image, "IMAGE %s replacing self with IMAGE %s\n",
364  image->name, replacement->name );
365  }
366 
367  /* Drop temporary reference to the original image */
368  image_put ( image );
369 
370  /* Restore previous currently-running image */
371  current_image = saved_current_image;
372 
373  /* Reset current working directory */
374  churi ( old_cwuri );
375  uri_put ( old_cwuri );
376 
377  /* Tail-recurse into replacement image, if one exists */
378  if ( replacement )
379  return image_exec ( replacement );
380 
381  return rc;
382 }
unsigned int flags
Flags.
Definition: image.h:36
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct image * current_image
Currently-executing image.
Definition: image.c:59
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:188
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:177
#define EACCES_UNTRUSTED
Definition: image.c:46
#define ENOEXEC
Exec format error.
Definition: errno.h:519
struct image_type * type
Image type, if known.
Definition: image.h:46
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition: image.h:196
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
#define LOG_ERR
Error: error conditions.
Definition: syslog.h:35
#define IMAGE_AUTO_UNREGISTER
Image will be automatically unregistered after execution.
Definition: image.h:73
int(* exec)(struct image *image)
Execute image.
Definition: image.h:94
int image_exec(struct image *image)
Execute image.
Definition: image.c:291
void churi(struct uri *uri)
Change working URI.
Definition: cwuri.c:45
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define IMAGE_REGISTERED
Image is registered.
Definition: image.h:64
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define IMAGE_TRUSTED
Image is trusted.
Definition: image.h:70
struct uri * uri
URI of image.
Definition: image.h:32
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:206
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:252
#define syslog(priority, fmt,...)
Write message to system log.
Definition: syslog.h:93
struct image * replacement
Replacement image.
Definition: image.h:60
A Uniform Resource Identifier.
Definition: uri.h:50
static int require_trusted_images
Current image trust requirement.
Definition: image.c:62
struct uri * cwuri
Current working URI.
Definition: cwuri.c:38
char * name
Name.
Definition: image.h:34
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#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_TRUSTED, LOG_ERR, LOG_NOTICE, image::name, NULL, rc, 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 393 of file image.c.

393  {
394  struct image *image = current_image;
395  int rc;
396 
397  /* Sanity check */
399 
400  /* Fail unless there is a currently-executing image */
401  if ( ! image ) {
402  rc = -ENOTTY;
403  DBGC ( replacement, "IMAGE %s cannot replace non-existent "
404  "image: %s\n", replacement->name, strerror ( rc ) );
405  return rc;
406  }
407 
408  /* Check that the replacement image can be executed */
409  if ( ! ( replacement->type && replacement->type->exec ) )
410  return -ENOEXEC;
411 
412  /* Clear any existing replacement */
414 
415  /* Set replacement */
417  DBGC ( image, "IMAGE %s will replace self with IMAGE %s\n",
418  image->name, replacement->name );
419 
420  return 0;
421 }
unsigned int flags
Flags.
Definition: image.h:36
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct image * current_image
Currently-executing image.
Definition: image.c:59
#define ENOEXEC
Exec format error.
Definition: errno.h:519
struct image_type * type
Image type, if known.
Definition: image.h:46
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition: image.h:196
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
int(* exec)(struct image *image)
Execute image.
Definition: image.h:94
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define IMAGE_REGISTERED
Image is registered.
Definition: image.h:64
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:206
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
struct image * replacement
Replacement image.
Definition: image.h:60
char * name
Name.
Definition: image.h:34

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

Referenced by comboot_fetch_kernel(), 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 429 of file image.c.

429  {
430  struct image *tmp;
431 
432  /* Unselect all other images */
433  for_each_image ( tmp )
434  tmp->flags &= ~IMAGE_SELECTED;
435 
436  /* Check that this image can be executed */
437  if ( ! ( image->type && image->type->exec ) )
438  return -ENOEXEC;
439 
440  /* Mark image as selected */
442 
443  return 0;
444 }
unsigned int flags
Flags.
Definition: image.h:36
#define ENOEXEC
Exec format error.
Definition: errno.h:519
struct image_type * type
Image type, if known.
Definition: image.h:46
An executable image.
Definition: image.h:24
int(* exec)(struct image *image)
Execute image.
Definition: image.h:94
#define IMAGE_SELECTED
Image is selected for execution.
Definition: image.h:67
#define for_each_image(image)
Iterate over all registered images.
Definition: image.h:149
uint8_t * tmp
Definition: entropy.h:156

References ENOEXEC, image_type::exec, image::flags, for_each_image, IMAGE_SELECTED, tmp, and image::type.

Referenced by embedded_init(), and imgselect().

◆ image_find_selected()

struct image* image_find_selected ( void  )

Find selected image.

Return values
imageExecutable image, or NULL

Definition at line 451 of file image.c.

451  {
452  struct image *image;
453 
454  for_each_image ( image ) {
455  if ( image->flags & IMAGE_SELECTED )
456  return image;
457  }
458  return NULL;
459 }
unsigned int flags
Flags.
Definition: image.h:36
An executable image.
Definition: image.h:24
#define IMAGE_SELECTED
Image is selected for execution.
Definition: image.h:67
#define for_each_image(image)
Iterate over all registered images.
Definition: image.h:149
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References image::flags, for_each_image, IMAGE_SELECTED, and NULL.

Referenced by imgsingle_exec(), and register_image().

◆ 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 468 of file image.c.

468  {
469 
470  /* Update trust requirement, if permitted to do so */
472  require_trusted_images = require_trusted;
474  }
475 
476  /* Fail if we attempted to change the trust requirement but
477  * were not permitted to do so.
478  */
479  if ( require_trusted_images != require_trusted )
480  return -EACCES_PERMANENT;
481 
482  return 0;
483 }
static int require_trusted_images_permanent
Prevent changes to image trust requirement.
Definition: image.c:65
#define EACCES_PERMANENT
Definition: image.c:50
static int require_trusted_images
Current image trust requirement.
Definition: image.c:62

References EACCES_PERMANENT, require_trusted_images, and require_trusted_images_permanent.

Referenced by imgtrust_exec().

◆ 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 97 of file pixbuf.c.

97  {
98  int rc;
99 
100  /* Check that this image can be used to create a pixel buffer */
101  if ( ! ( image->type && image->type->pixbuf ) )
102  return -ENOTSUP;
103 
104  /* Try creating pixel buffer */
105  if ( ( rc = image->type->pixbuf ( image, pixbuf ) ) != 0 ) {
106  DBGC ( image, "IMAGE %s could not create pixel buffer: %s\n",
107  image->name, strerror ( rc ) );
108  return rc;
109  }
110 
111  return 0;
112 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct image_type * type
Image type, if known.
Definition: image.h:46
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
#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:102
char * name
Name.
Definition: image.h:34

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 854 of file asn1.c.

855  {
856  int next;
857  int rc;
858 
859  /* Sanity check */
860  assert ( offset <= image->len );
861 
862  /* Check that this image can be used to extract an ASN.1 object */
863  if ( ! ( image->type && image->type->asn1 ) )
864  return -ENOTSUP;
865 
866  /* Try creating ASN.1 cursor */
867  next = image->type->asn1 ( image, offset, cursor );
868  if ( next < 0 ) {
869  rc = next;
870  DBGC ( image, "IMAGE %s could not extract ASN.1 object: %s\n",
871  image->name, strerror ( rc ) );
872  return rc;
873  }
874 
875  return next;
876 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t next
Next descriptor address.
Definition: myson.h:18
struct image_type * type
Image type, if known.
Definition: image.h:46
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
int(* asn1)(struct image *image, size_t offset, struct asn1_cursor **cursor)
Extract ASN.1 object from image.
Definition: image.h:114
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint32_t len
Length.
Definition: ena.h:14
char * name
Name.
Definition: image.h:34

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

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

◆ 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 196 of file image.h.

196  {
197  ref_get ( &image->refcnt );
198  return image;
199 }
An executable image.
Definition: image.h:24
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
struct refcnt refcnt
Reference count.
Definition: image.h:26

References ref_get, and image::refcnt.

Referenced by bzimage_exec(), create_downloader(), efi_file_open(), 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 206 of file image.h.

206  {
207  ref_put ( &image->refcnt );
208 }
An executable image.
Definition: image.h:24
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
struct refcnt refcnt
Reference count.
Definition: image.h:26

References ref_put, and image::refcnt.

Referenced by alloc_image(), cmdline_init(), downloader_free(), efi_file_close(), free_image(), image_exec(), image_replace(), imgdownload(), initrd_init(), and unregister_image().

◆ image_clear_cmdline()

static void image_clear_cmdline ( struct image image)
inlinestatic

Clear image command line.

Parameters
imageImage

Definition at line 215 of file image.h.

215  {
217 }
int image_set_cmdline(struct image *image, const char *cmdline)
Set image command line.
Definition: image.c:166
An executable image.
Definition: image.h:24
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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 224 of file image.h.

224  {
226 }
unsigned int flags
Flags.
Definition: image.h:36
An executable image.
Definition: image.h:24
#define IMAGE_TRUSTED
Image is trusted.
Definition: image.h:70

References image::flags, and IMAGE_TRUSTED.

Referenced by imgverify().

◆ image_untrust()

static void image_untrust ( struct image image)
inlinestatic

Set image as untrusted.

Parameters
imageImage

Definition at line 233 of file image.h.

233  {
235 }
unsigned int flags
Flags.
Definition: image.h:36
An executable image.
Definition: image.h:24
#define IMAGE_TRUSTED
Image is trusted.
Definition: image.h:70

References image::flags, and IMAGE_TRUSTED.

Referenced by imgverify().

Variable Documentation

◆ __attribute__

◆ images

struct list_head images

◆ current_image

struct image* current_image

Currently-executing image.

Definition at line 59 of file image.c.

Referenced by goto_exec(), image_exec(), and image_replace().