您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

image.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. struct image_type;
  13. /** Maximum length of a command line */
  14. #define CMDLINE_MAX 128
  15. /** An executable or loadable image */
  16. struct image {
  17. /** Name */
  18. char name[16];
  19. /** List of registered images */
  20. struct list_head list;
  21. /** Command line to pass to image */
  22. char cmdline[CMDLINE_MAX];
  23. /** Raw file image */
  24. userptr_t data;
  25. /** Length of raw file image */
  26. size_t len;
  27. /**
  28. * Free raw file image
  29. *
  30. * @v data Raw file image
  31. *
  32. * Call this method before freeing up the @c struct @c image.
  33. */
  34. void ( * free ) ( userptr_t data );
  35. /** Entry point */
  36. physaddr_t entry;
  37. /** Image type, if known */
  38. struct image_type *type;
  39. /** Flags */
  40. unsigned int flags;
  41. };
  42. /** Image is loaded */
  43. #define IMAGE_LOADED 0x0001
  44. /** An executable or loadable image type */
  45. struct image_type {
  46. /** Name of this image type */
  47. char *name;
  48. /**
  49. * Load image into memory
  50. *
  51. * @v image Executable/loadable image
  52. * @ret rc Return status code
  53. *
  54. * Load the image into memory. The file image may be
  55. * discarded after this call; the method must preserve any
  56. * information it may require later (e.g. the execution
  57. * address) within the @c image structure.
  58. *
  59. * If the file image is in the correct format, the method must
  60. * update @c image->type to point to its own type (unless @c
  61. * image->type is already set). This allows the autoloading
  62. * code to disambiguate between "this is not my image format"
  63. * and "there is something wrong with this image". In
  64. * particular, setting @c image->type and then returning an
  65. * error will cause image_autoload() to abort and return an
  66. * error, rather than continuing to the next image type.
  67. */
  68. int ( * load ) ( struct image *image );
  69. /**
  70. * Execute loaded image
  71. *
  72. * @v image Loaded image
  73. * @ret rc Return status code
  74. */
  75. int ( * exec ) ( struct image *image );
  76. };
  77. /** An executable or loadable image type */
  78. #define __image_type __table ( struct image_type, image_types, 01 )
  79. /**
  80. * An unverifiable executable or loadable image type
  81. *
  82. * This should be used to mark image types for which there are no
  83. * signature or other checks that can be used to verify the validity
  84. * of the image (such as PXE images). These will then be tried last
  85. * in the list of image types.
  86. */
  87. #define __default_image_type __table ( struct image_type, image_types, 02 )
  88. extern struct list_head images;
  89. /** Iterate over all registered images */
  90. #define for_each_image( image ) \
  91. list_for_each_entry ( (image), &images, list )
  92. extern int register_image ( struct image *image );
  93. extern void unregister_image ( struct image *image );
  94. struct image * find_image ( const char *name );
  95. extern int image_load ( struct image *image );
  96. extern int image_autoload ( struct image *image );
  97. extern int image_exec ( struct image *image );
  98. #endif /* _GPXE_IMAGE_H */