Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #ifndef _IPXE_IMAGE_H
  2. #define _IPXE_IMAGE_H
  3. /**
  4. * @file
  5. *
  6. * Executable images
  7. *
  8. */
  9. FILE_LICENCE ( GPL2_OR_LATER );
  10. #include <ipxe/tables.h>
  11. #include <ipxe/list.h>
  12. #include <ipxe/uaccess.h>
  13. #include <ipxe/refcnt.h>
  14. struct uri;
  15. struct image_type;
  16. /** An executable image */
  17. struct image {
  18. /** Reference count */
  19. struct refcnt refcnt;
  20. /** List of registered images */
  21. struct list_head list;
  22. /** URI of image */
  23. struct uri *uri;
  24. /** Name */
  25. char *name;
  26. /** Flags */
  27. unsigned int flags;
  28. /** Command line to pass to image */
  29. char *cmdline;
  30. /** Raw file image */
  31. userptr_t data;
  32. /** Length of raw file image */
  33. size_t len;
  34. /** Image type, if known */
  35. struct image_type *type;
  36. /** Replacement image
  37. *
  38. * An image wishing to replace itself with another image (in a
  39. * style similar to a Unix exec() call) should return from its
  40. * exec() method with the replacement image set to point to
  41. * the new image.
  42. *
  43. * If an image unregisters itself as a result of being
  44. * executed, it must make sure that its replacement image (if
  45. * any) is registered, otherwise the replacement is likely to
  46. * be freed before it can be executed.
  47. */
  48. struct image *replacement;
  49. };
  50. /** Image is registered */
  51. #define IMAGE_REGISTERED 0x00001
  52. /** Image is selected for execution */
  53. #define IMAGE_SELECTED 0x0002
  54. /** Image is trusted */
  55. #define IMAGE_TRUSTED 0x0004
  56. /** An executable image type */
  57. struct image_type {
  58. /** Name of this image type */
  59. char *name;
  60. /** Probe image
  61. *
  62. * @v image Executable image
  63. * @ret rc Return status code
  64. *
  65. * Return success if the image is of this image type.
  66. */
  67. int ( * probe ) ( struct image *image );
  68. /**
  69. * Execute image
  70. *
  71. * @v image Executable image
  72. * @ret rc Return status code
  73. */
  74. int ( * exec ) ( struct image *image );
  75. };
  76. /**
  77. * Multiboot image probe priority
  78. *
  79. * Multiboot images are also valid executables in another format
  80. * (e.g. ELF), so we must perform the multiboot probe first.
  81. */
  82. #define PROBE_MULTIBOOT 01
  83. /**
  84. * Normal image probe priority
  85. */
  86. #define PROBE_NORMAL 02
  87. /**
  88. * PXE image probe priority
  89. *
  90. * PXE images have no signature checks, so will claim all image files.
  91. * They must therefore be tried last in the probe order list.
  92. */
  93. #define PROBE_PXE 03
  94. /** Executable image type table */
  95. #define IMAGE_TYPES __table ( struct image_type, "image_types" )
  96. /** An executable image type */
  97. #define __image_type( probe_order ) __table_entry ( IMAGE_TYPES, probe_order )
  98. extern struct list_head images;
  99. extern struct image *current_image;
  100. /** Iterate over all registered images */
  101. #define for_each_image( image ) \
  102. list_for_each_entry ( (image), &images, list )
  103. /** Iterate over all registered images, safe against deletion */
  104. #define for_each_image_safe( image, tmp ) \
  105. list_for_each_entry_safe ( (image), (tmp), &images, list )
  106. /**
  107. * Test for existence of images
  108. *
  109. * @ret existence Some images exist
  110. */
  111. static inline int have_images ( void ) {
  112. return ( ! list_empty ( &images ) );
  113. }
  114. /**
  115. * Retrieve first image
  116. *
  117. * @ret image Image, or NULL
  118. */
  119. static inline struct image * first_image ( void ) {
  120. return list_first_entry ( &images, struct image, list );
  121. }
  122. extern struct image * alloc_image ( struct uri *uri );
  123. extern int image_set_name ( struct image *image, const char *name );
  124. extern int image_set_cmdline ( struct image *image, const char *cmdline );
  125. extern int register_image ( struct image *image );
  126. extern void unregister_image ( struct image *image );
  127. struct image * find_image ( const char *name );
  128. extern int image_probe ( struct image *image );
  129. extern int image_exec ( struct image *image );
  130. extern int image_replace ( struct image *replacement );
  131. extern int image_select ( struct image *image );
  132. extern struct image * image_find_selected ( void );
  133. extern int image_set_trust ( int require_trusted, int permanent );
  134. /**
  135. * Increment reference count on an image
  136. *
  137. * @v image Image
  138. * @ret image Image
  139. */
  140. static inline struct image * image_get ( struct image *image ) {
  141. ref_get ( &image->refcnt );
  142. return image;
  143. }
  144. /**
  145. * Decrement reference count on an image
  146. *
  147. * @v image Image
  148. */
  149. static inline void image_put ( struct image *image ) {
  150. ref_put ( &image->refcnt );
  151. }
  152. /**
  153. * Clear image command line
  154. *
  155. * @v image Image
  156. */
  157. static inline void image_clear_cmdline ( struct image *image ) {
  158. image_set_cmdline ( image, NULL );
  159. }
  160. /**
  161. * Set image as trusted
  162. *
  163. * @v image Image
  164. */
  165. static inline void image_trust ( struct image *image ) {
  166. image->flags |= IMAGE_TRUSTED;
  167. }
  168. /**
  169. * Set image as untrusted
  170. *
  171. * @v image Image
  172. */
  173. static inline void image_untrust ( struct image *image ) {
  174. image->flags &= ~IMAGE_TRUSTED;
  175. }
  176. #endif /* _IPXE_IMAGE_H */