Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

image.h 5.0KB

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