You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

image.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef _GPXE_IMAGE_H
  2. #define _GPXE_IMAGE_H
  3. /**
  4. * @file
  5. *
  6. * Executable/loadable images
  7. *
  8. */
  9. #include <gpxe/tables.h>
  10. #include <gpxe/list.h>
  11. #include <gpxe/uaccess.h>
  12. #include <gpxe/refcnt.h>
  13. struct image_type;
  14. /** Maximum length of a command line */
  15. #define CMDLINE_MAX 128
  16. /** An executable or loadable image */
  17. struct image {
  18. /** Reference count */
  19. struct refcnt refcnt;
  20. /** Name */
  21. char name[16];
  22. /** List of registered images */
  23. struct list_head list;
  24. /** Flags */
  25. unsigned int flags;
  26. /** Command line to pass to image */
  27. char cmdline[CMDLINE_MAX];
  28. /** Raw file image */
  29. userptr_t data;
  30. /** Length of raw file image */
  31. size_t len;
  32. /** Image type, if known */
  33. struct image_type *type;
  34. /** Image type private data */
  35. union {
  36. physaddr_t phys;
  37. userptr_t user;
  38. unsigned long ul;
  39. } priv;
  40. };
  41. /** Image is loaded */
  42. #define IMAGE_LOADED 0x0001
  43. /** An executable or loadable image type */
  44. struct image_type {
  45. /** Name of this image type */
  46. char *name;
  47. /**
  48. * Load image into memory
  49. *
  50. * @v image Executable/loadable image
  51. * @ret rc Return status code
  52. *
  53. * Load the image into memory at the correct location as
  54. * determined by the file format.
  55. *
  56. * If the file image is in the correct format, the method must
  57. * update @c image->type to point to its own type (unless @c
  58. * image->type is already set). This allows the autoloading
  59. * code to disambiguate between "this is not my image format"
  60. * and "there is something wrong with this image". In
  61. * particular, setting @c image->type and then returning an
  62. * error will cause image_autoload() to abort and return an
  63. * error, rather than continuing to the next image type.
  64. */
  65. int ( * load ) ( struct image *image );
  66. /**
  67. * Execute loaded image
  68. *
  69. * @v image Loaded image
  70. * @ret rc Return status code
  71. */
  72. int ( * exec ) ( struct image *image );
  73. };
  74. /**
  75. * Multiboot image probe priority
  76. *
  77. * Multiboot images are also valid executables in another format
  78. * (e.g. ELF), so we must perform the multiboot probe first.
  79. */
  80. #define PROBE_MULTIBOOT 01
  81. /**
  82. * Normal image probe priority
  83. */
  84. #define PROBE_NORMAL 02
  85. /**
  86. * PXE image probe priority
  87. *
  88. * PXE images have no signature checks, so will claim all image files.
  89. * They must therefore be tried last in the probe order list.
  90. */
  91. #define PROBE_PXE 03
  92. /** An executable or loadable image type */
  93. #define __image_type( probe_order ) \
  94. __table ( struct image_type, image_types, probe_order )
  95. extern struct list_head images;
  96. /** Iterate over all registered images */
  97. #define for_each_image( image ) \
  98. list_for_each_entry ( (image), &images, list )
  99. extern struct image * alloc_image ( void );
  100. extern int register_image ( struct image *image );
  101. extern void unregister_image ( struct image *image );
  102. extern void promote_image ( struct image *image );
  103. struct image * find_image ( const char *name );
  104. extern int image_load ( struct image *image );
  105. extern int image_autoload ( struct image *image );
  106. extern int image_exec ( struct image *image );
  107. /**
  108. * Increment reference count on an image
  109. *
  110. * @v image Image
  111. * @ret image Image
  112. */
  113. static inline struct image * image_get ( struct image *image ) {
  114. ref_get ( &image->refcnt );
  115. return image;
  116. }
  117. /**
  118. * Decrement reference count on an image
  119. *
  120. * @v image Image
  121. */
  122. static inline void image_put ( struct image *image ) {
  123. ref_put ( &image->refcnt );
  124. }
  125. #endif /* _GPXE_IMAGE_H */