11 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13 #include <ipxe/tables.h>
14 #include <ipxe/list.h>
15 #include <ipxe/uaccess.h>
16 #include <ipxe/refcnt.h>
22 /** An executable image */
24 /** Reference count */
27 /** List of registered images */
28 struct list_head list;
37 /** Command line to pass to image */
41 /** Length of raw file image */
44 /** Image type, if known */
45 struct image_type *type;
49 * An image wishing to replace itself with another image (in a
50 * style similar to a Unix exec() call) should return from its
51 * exec() method with the replacement image set to point to
54 * If an image unregisters itself as a result of being
55 * executed, it must make sure that its replacement image (if
56 * any) is registered, otherwise the replacement is likely to
57 * be freed before it can be executed.
59 struct image *replacement;
62 /** Image is registered */
63 #define IMAGE_REGISTERED 0x00001
65 /** Image is selected for execution */
66 #define IMAGE_SELECTED 0x0002
68 /** Image is trusted */
69 #define IMAGE_TRUSTED 0x0004
71 /** Image will be automatically unregistered after execution */
72 #define IMAGE_AUTO_UNREGISTER 0x0008
74 /** An executable image type */
76 /** Name of this image type */
82 * @ret rc Return status code
84 * Return success if the image is of this image type.
86 int ( * probe ) ( struct image *image );
91 * @ret rc Return status code
93 int ( * exec ) ( struct image *image );
95 * Create pixel buffer from image
98 * @v pixbuf Pixel buffer to fill in
99 * @ret rc Return status code
101 int ( * pixbuf ) ( struct image *image, struct pixel_buffer **pixbuf );
105 * Multiboot image probe priority
107 * Multiboot images are also valid executables in another format
108 * (e.g. ELF), so we must perform the multiboot probe first.
110 #define PROBE_MULTIBOOT 01
113 * Normal image probe priority
115 #define PROBE_NORMAL 02
118 * PXE image probe priority
120 * PXE images have no signature checks, so will claim all image files.
121 * They must therefore be tried last in the probe order list.
125 /** Executable image type table */
126 #define IMAGE_TYPES __table ( struct image_type, "image_types" )
128 /** An executable image type */
129 #define __image_type( probe_order ) __table_entry ( IMAGE_TYPES, probe_order )
131 extern struct list_head images;
132 extern struct image *current_image;
134 /** Iterate over all registered images */
135 #define for_each_image( image ) \
136 list_for_each_entry ( (image), &images, list )
138 /** Iterate over all registered images, safe against deletion */
139 #define for_each_image_safe( image, tmp ) \
140 list_for_each_entry_safe ( (image), (tmp), &images, list )
143 * Test for existence of images
145 * @ret existence Some images exist
147 static inline int have_images ( void ) {
148 return ( ! list_empty ( &images ) );
152 * Retrieve first image
154 * @ret image Image, or NULL
156 static inline struct image * first_image ( void ) {
157 return list_first_entry ( &images, struct image, list );
160 extern struct image * alloc_image ( struct uri *uri );
161 extern int image_set_name ( struct image *image, const char *name );
162 extern int image_set_cmdline ( struct image *image, const char *cmdline );
163 extern int register_image ( struct image *image );
164 extern void unregister_image ( struct image *image );
165 struct image * find_image ( const char *name );
166 extern int image_exec ( struct image *image );
167 extern int image_replace ( struct image *replacement );
168 extern int image_select ( struct image *image );
169 extern struct image * image_find_selected ( void );
170 extern int image_set_trust ( int require_trusted, int permanent );
171 extern int image_pixbuf ( struct image *image, struct pixel_buffer **pixbuf );
174 * Increment reference count on an image
179 static inline struct image * image_get ( struct image *image ) {
180 ref_get ( &image->refcnt );
185 * Decrement reference count on an image
189 static inline void image_put ( struct image *image ) {
190 ref_put ( &image->refcnt );
194 * Clear image command line
198 static inline void image_clear_cmdline ( struct image *image ) {
199 image_set_cmdline ( image, NULL );
203 * Set image as trusted
207 static inline void image_trust ( struct image *image ) {
208 image->flags |= IMAGE_TRUSTED;
212 * Set image as untrusted
216 static inline void image_untrust ( struct image *image ) {
217 image->flags &= ~IMAGE_TRUSTED;
220 #endif /* _IPXE_IMAGE_H */