7 * Executable/loadable images
11 #include <gpxe/tables.h>
12 #include <gpxe/list.h>
13 #include <gpxe/uaccess.h>
14 #include <gpxe/refcnt.h>
19 /** An executable or loadable image */
21 /** Reference count */
24 /** List of registered images */
25 struct list_head list;
34 /** Command line to pass to image */
38 /** Length of raw file image */
41 /** Image type, if known */
42 struct image_type *type;
43 /** Image type private data */
52 * An image wishing to replace itself with another image (in a
53 * style similar to a Unix exec() call) should return from its
54 * exec() method with the replacement image set to point to
55 * the new image. The new image must already be in a suitable
56 * state for execution (i.e. loaded).
58 * If an image unregisters itself as a result of being
59 * executed, it must make sure that its replacement image (if
60 * any) is registered, otherwise the replacement is likely to
61 * be freed before it can be executed.
63 struct image *replacement;
66 /** Image is loaded */
67 #define IMAGE_LOADED 0x0001
69 /** An executable or loadable image type */
71 /** Name of this image type */
74 * Load image into memory
76 * @v image Executable/loadable image
77 * @ret rc Return status code
79 * Load the image into memory at the correct location as
80 * determined by the file format.
82 * If the file image is in the correct format, the method must
83 * update @c image->type to point to its own type (unless @c
84 * image->type is already set). This allows the autoloading
85 * code to disambiguate between "this is not my image format"
86 * and "there is something wrong with this image". In
87 * particular, setting @c image->type and then returning an
88 * error will cause image_autoload() to abort and return an
89 * error, rather than continuing to the next image type.
91 int ( * load ) ( struct image *image );
93 * Execute loaded image
95 * @v image Loaded image
96 * @ret rc Return status code
98 * Note that the image may be invalidated by the act of
99 * execution, i.e. an image is allowed to choose to unregister
100 * (and so potentially free) itself.
102 int ( * exec ) ( struct image *image );
106 * Multiboot image probe priority
108 * Multiboot images are also valid executables in another format
109 * (e.g. ELF), so we must perform the multiboot probe first.
111 #define PROBE_MULTIBOOT 01
114 * Normal image probe priority
116 #define PROBE_NORMAL 02
119 * PXE image probe priority
121 * PXE images have no signature checks, so will claim all image files.
122 * They must therefore be tried last in the probe order list.
126 /** Executable or loadable image type table */
127 #define IMAGE_TYPES __table ( struct image_type, "image_types" )
129 /** An executable or loadable image type */
130 #define __image_type( probe_order ) __table_entry ( IMAGE_TYPES, probe_order )
132 extern struct list_head images;
134 /** Iterate over all registered images */
135 #define for_each_image( image ) \
136 list_for_each_entry ( (image), &images, list )
139 * Test for existence of images
141 * @ret existence Some images exist
143 static inline int have_images ( void ) {
144 return ( ! list_empty ( &images ) );
147 extern struct image * alloc_image ( void );
148 extern int image_set_uri ( struct image *image, struct uri *uri );
149 extern int image_set_cmdline ( struct image *image, const char *cmdline );
150 extern int register_image ( struct image *image );
151 extern void unregister_image ( struct image *image );
152 extern void promote_image ( struct image *image );
153 struct image * find_image ( const char *name );
154 extern int image_load ( struct image *image );
155 extern int image_autoload ( struct image *image );
156 extern int image_exec ( struct image *image );
157 extern int register_and_autoload_image ( struct image *image );
158 extern int register_and_autoexec_image ( struct image *image );
161 * Increment reference count on an image
166 static inline struct image * image_get ( struct image *image ) {
167 ref_get ( &image->refcnt );
172 * Decrement reference count on an image
176 static inline void image_put ( struct image *image ) {
177 ref_put ( &image->refcnt );
184 * @v name New image name
185 * @ret rc Return status code
187 static inline int image_set_name ( struct image *image, const char *name ) {
188 strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
192 #endif /* _GPXE_IMAGE_H */