Add LZSS Mach-O support (needed for new xnu kernelcache).

* grub-core/Makefile.core.def (xnu): Add file lzss.c
	* grub-core/loader/lzss.c: New file.
	* grub-core/loader/xnu.c (grub_xnu_load_driver): Close binaryfile
	on Mach-O open failure.
	* grub-core/loader/macho.c (grub_macho_close): Free uncompressedXX.
	Don't free cmdsXX in uncompressedXX is set.
	(grub_macho_file): Init new fields.
	New argument is_64bit. All users updated.
	Handle compressed. Error out if no suitable architecture is found.
	Don't close file.
	(grub_macho_open): New argument is_64bit. All users updated.
	* grub-core/loader/macho32.c: Add defines for new fields.
	* grub-core/loader/macho64.c: Likewise.
	* grub-core/loader/machoXX.c (grub_macho_contains_macho): Make static.
	(grub_macho_parse): Handle compressed.
	Defer actual processing if compressed.
	(grub_macho_cmds_iterate): Decompress if compressed. New argument
	"filename". All users updated.
	(grub_macho_size): New argument "filename". All users updated.
	(grub_macho_get_entry_point): Likewise.
	(grub_macho_load): Handle compressed.
	* include/grub/macho.h (grub_macho_lzss_header): New struct.
	(GRUB_MACHO_LZSS_OFFSET): New define.
	(grub_decompress_lzss): New proto.
	* include/grub/machoload.h (grub_macho_file): New fields to handle
	compressed.
	(grub_macho_contains_macho64): Remove proto.
	(grub_macho_contains_macho32): Likewise.
	* util/grub.d/30_os-prober.in: Use kernel cache if available.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-02-29 13:26:13 +01:00
parent ebd17d6f51
commit 99ce1597a4
11 changed files with 339 additions and 80 deletions

View file

@ -68,14 +68,6 @@ struct grub_macho_header64
grub_uint32_t reserved;
} __attribute__ ((packed));
/* Convenience union. What do we need to load to identify the file type. */
union grub_macho_filestart
{
struct grub_macho_fat_header fat;
struct grub_macho_header32 thin32;
struct grub_macho_header64 thin64;
} __attribute__ ((packed));
/* Common header of Mach-O commands. */
struct grub_macho_cmd
{
@ -121,4 +113,28 @@ struct grub_macho_segment64
#define GRUB_MACHO_CMD_THREAD 5
struct grub_macho_lzss_header
{
char magic[8];
#define GRUB_MACHO_LZSS_MAGIC "complzss"
grub_uint32_t unused;
grub_uint32_t uncompressed_size;
grub_uint32_t compressed_size;
};
/* Convenience union. What do we need to load to identify the file type. */
union grub_macho_filestart
{
struct grub_macho_fat_header fat;
struct grub_macho_header32 thin32;
struct grub_macho_header64 thin64;
struct grub_macho_lzss_header lzss;
} __attribute__ ((packed));
#define GRUB_MACHO_LZSS_OFFSET 0x180
grub_size_t
grub_decompress_lzss (grub_uint8_t *dst, grub_uint8_t *dstend,
grub_uint8_t *src, grub_uint8_t *srcend);
#endif

View file

@ -33,27 +33,38 @@ struct grub_macho_file
int ncmds32;
grub_size_t cmdsize32;
grub_uint8_t *cmds32;
grub_uint8_t *uncompressed32;
int compressed32;
grub_size_t compressed_size32;
grub_size_t uncompressed_size32;
grub_ssize_t offset64;
grub_ssize_t end64;
int ncmds64;
grub_size_t cmdsize64;
grub_uint8_t *cmds64;
grub_uint8_t *uncompressed64;
int compressed64;
grub_size_t compressed_size64;
grub_size_t uncompressed_size64;
};
typedef struct grub_macho_file *grub_macho_t;
grub_macho_t grub_macho_open (const char *);
grub_macho_t grub_macho_file (grub_file_t file, const char *filename);
grub_macho_t grub_macho_open (const char *, int is_64bit);
grub_macho_t grub_macho_file (grub_file_t file, const char *filename,
int is_64bit);
grub_err_t grub_macho_close (grub_macho_t);
int grub_macho_contains_macho32 (grub_macho_t);
grub_err_t grub_macho_size32 (grub_macho_t macho, grub_uint32_t *segments_start,
grub_uint32_t *segments_end, int flags);
grub_uint32_t grub_macho_get_entry_point32 (grub_macho_t macho);
grub_uint32_t *segments_end, int flags,
const char *filename);
grub_uint32_t grub_macho_get_entry_point32 (grub_macho_t macho,
const char *filename);
int grub_macho_contains_macho64 (grub_macho_t);
grub_err_t grub_macho_size64 (grub_macho_t macho, grub_uint64_t *segments_start,
grub_uint64_t *segments_end, int flags);
grub_uint64_t grub_macho_get_entry_point64 (grub_macho_t macho);
grub_uint64_t *segments_end, int flags,
const char *filename);
grub_uint64_t grub_macho_get_entry_point64 (grub_macho_t macho,
const char *filename);
/* Ignore BSS segments when loading. */
#define GRUB_MACHO_NOBSS 0x1