1 Star 0 Fork 0

LongPanda / efifs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
0000-GRUB-fixes.patch 39.88 KB
一键复制 编辑 原始数据 按行查看 历史
Pete Batard 提交于 2019-05-04 14:39 . update GRUB and gnu-efi to latest
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
From b0459a06d51d3f32cff896f0a19cf3579708e0d4 Mon Sep 17 00:00:00 2001
From: Pete Batard <pete@akeo.ie>
Date: Sat, 4 May 2019 14:54:36 +0100
Subject: [PATCH] GRUB fixes
---
grub-core/fs/affs.c | 2 +
grub-core/fs/bfs.c | 2 +
grub-core/fs/btrfs.c | 151 ++++----------------------------
grub-core/fs/f2fs.c | 2 +
grub-core/fs/fat.c | 8 +-
grub-core/fs/hfs.c | 6 ++
grub-core/fs/hfsplus.c | 2 +
grub-core/fs/hfspluscomp.c | 5 ++
grub-core/fs/iso9660.c | 36 +++++---
grub-core/fs/jfs.c | 2 +
grub-core/fs/nilfs2.c | 4 +-
grub-core/fs/ntfs.c | 2 +
grub-core/fs/reiserfs.c | 16 +++-
grub-core/fs/sfs.c | 4 +-
grub-core/fs/udf.c | 2 +
grub-core/fs/ufs.c | 2 +
grub-core/fs/xfs.c | 2 +
grub-core/fs/zfs/zfs.c | 6 +-
grub-core/fs/zfs/zfs_lz4.c | 2 +
grub-core/kern/misc.c | 6 +-
grub-core/lib/minilzo/lzodefs.h | 3 +
include/grub/arm64/types.h | 4 +
include/grub/btrfs.h | 3 +
include/grub/exfat.h | 2 +
include/grub/fat.h | 2 +
include/grub/hfs.h | 2 +
include/grub/hfsplus.h | 6 ++
include/grub/misc.h | 10 +++
include/grub/ntfs.h | 2 +
include/grub/term.h | 4 +-
include/grub/types.h | 38 +++++---
include/grub/unicode.h | 2 +
include/grub/x86_64/types.h | 2 +-
include/grub/zfs/zap_leaf.h | 17 +++-
include/grub/zfs/zio.h | 2 +
35 files changed, 189 insertions(+), 172 deletions(-)
diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c
index 6b6a2bc91..90d02ce0c 100644
--- a/grub-core/fs/affs.c
+++ b/grub-core/fs/affs.c
@@ -30,6 +30,7 @@
GRUB_MOD_LICENSE ("GPLv3+");
/* The affs bootblock. */
+PRAGMA_BEGIN_PACKED
struct grub_affs_bblock
{
grub_uint8_t type[3];
@@ -77,6 +78,7 @@ struct grub_affs_file
grub_uint32_t extension;
grub_uint32_t type;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* The location of `struct grub_affs_file' relative to the end of a
file header block. */
diff --git a/grub-core/fs/bfs.c b/grub-core/fs/bfs.c
index 47dbe2011..236aa0b9f 100644
--- a/grub-core/fs/bfs.c
+++ b/grub-core/fs/bfs.c
@@ -69,6 +69,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
#define DOUBLE_INDIRECT_SHIFT 2
#define LOG_EXTENT_SIZE 3
+PRAGMA_BEGIN_PACKED
struct grub_bfs_extent
{
grub_uint32_t ag;
@@ -167,6 +168,7 @@ struct grub_bfs_btree_node
grub_uint16_t total_key_len;
#endif
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_bfs_data
{
diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 48bd3d04a..83aeec4af 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -17,14 +17,6 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
-/*
- * Tell zstd to expose functions that aren't part of the stable API, which
- * aren't safe to use when linking against a dynamic library. We vendor in a
- * specific zstd version, so we know what we're getting. We need these unstable
- * functions to provide our own allocator, which uses grub_malloc(), to zstd.
- */
-#define ZSTD_STATIC_LINKING_ONLY
-
#include <grub/err.h>
#include <grub/file.h>
#include <grub/mm.h>
@@ -35,7 +27,6 @@
#include <grub/lib/crc.h>
#include <grub/deflate.h>
#include <minilzo.h>
-#include <zstd.h>
#include <grub/i18n.h>
#include <grub/btrfs.h>
#include <grub/crypto.h>
@@ -56,12 +47,10 @@ GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE (GRUB_BTRFS_LZO_BLOCK_SIZE + \
(GRUB_BTRFS_LZO_BLOCK_SIZE / 16) + 64 + 3)
-#define ZSTD_BTRFS_MAX_WINDOWLOG 17
-#define ZSTD_BTRFS_MAX_INPUT (1 << ZSTD_BTRFS_MAX_WINDOWLOG)
-
typedef grub_uint8_t grub_btrfs_checksum_t[0x20];
typedef grub_uint16_t grub_btrfs_uuid_t[8];
+PRAGMA_BEGIN_PACKED
struct grub_btrfs_device
{
grub_uint64_t device_id;
@@ -96,6 +85,7 @@ struct btrfs_header
grub_uint32_t nitems;
grub_uint8_t level;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_btrfs_device_desc
{
@@ -122,6 +112,7 @@ struct grub_btrfs_data
struct grub_btrfs_extent_data *extent;
};
+PRAGMA_BEGIN_PACKED
struct grub_btrfs_chunk_item
{
grub_uint64_t size;
@@ -174,6 +165,7 @@ struct grub_btrfs_dir_item
grub_uint8_t type;
char name[0];
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_btrfs_leaf_descriptor
{
@@ -188,6 +180,7 @@ struct grub_btrfs_leaf_descriptor
} *data;
};
+PRAGMA_BEGIN_PACKED
struct grub_btrfs_time
{
grub_int64_t sec;
@@ -222,6 +215,7 @@ struct grub_btrfs_extent_data
};
};
} GRUB_PACKED;
+PRAGMA_END_PACKED
#define GRUB_BTRFS_EXTENT_INLINE 0
#define GRUB_BTRFS_EXTENT_REGULAR 1
@@ -229,7 +223,6 @@ struct grub_btrfs_extent_data
#define GRUB_BTRFS_COMPRESSION_NONE 0
#define GRUB_BTRFS_COMPRESSION_ZLIB 1
#define GRUB_BTRFS_COMPRESSION_LZO 2
-#define GRUB_BTRFS_COMPRESSION_ZSTD 3
#define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100
@@ -245,7 +238,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
static grub_err_t
read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb)
{
- struct grub_btrfs_superblock sblock;
+ struct grub_btrfs_superblock sblock = { 0 };
unsigned i;
grub_err_t err = GRUB_ERR_NONE;
for (i = 0; i < ARRAY_SIZE (superblock_sectors); i++)
@@ -825,17 +818,13 @@ raid56_read_retry (struct grub_btrfs_data *data,
goto cleanup;
}
else
- grub_dprintf ("btrfs", "enough disks for RAID 5: total %"
- PRIuGRUB_UINT64_T ", missing %" PRIuGRUB_UINT64_T "\n",
- nstripes, failed_devices);
-
- /* We have enough disks. So, rebuild the data. */
- if (chunk_type & GRUB_BTRFS_CHUNK_TYPE_RAID5)
- rebuild_raid5 (buf, buffers, nstripes, csize);
- else
- rebuild_raid6 (buffers, nstripes, csize, parities_pos, buf, stripen);
+ {
+ /* EfiFs - Remove support for RAID rebuild */
+ grub_dprintf ("btrfs", "RAID rebuild is not supported by this driver\n");
+ ret = GRUB_ERR_READ_ERROR;
+ goto cleanup;
+ }
- ret = GRUB_ERR_NONE;
cleanup:
if (buffers)
for (i = 0; i < nstripes; i++)
@@ -936,8 +925,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
"couldn't find the chunk descriptor");
}
- nstripes = grub_le_to_cpu16 (chunk->nstripes) ? : 1;
- chunk_stripe_length = grub_le_to_cpu64 (chunk->stripe_length) ? : 512;
+ nstripes = grub_le_to_cpu16 (chunk->nstripes) ? grub_le_to_cpu16 (chunk->nstripes) : 1;
+ chunk_stripe_length = grub_le_to_cpu64 (chunk->stripe_length) ? grub_le_to_cpu64 (chunk->stripe_length) : 512;
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
"+0x%" PRIxGRUB_UINT64_T
" (%d stripes (%d substripes) of %"
@@ -995,13 +984,13 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
grub_uint64_t middle, high;
grub_uint64_t low;
grub_uint16_t nsubstripes;
- nsubstripes = grub_le_to_cpu16 (chunk->nsubstripes) ? : 1;
+ nsubstripes = grub_le_to_cpu16 (chunk->nsubstripes) ? grub_le_to_cpu16 (chunk->nsubstripes) : 1;
middle = grub_divmod64 (off,
chunk_stripe_length,
&low);
high = grub_divmod64 (middle,
- nstripes / nsubstripes ? : 1,
+ nstripes / nsubstripes ? nstripes / nsubstripes : 1,
&stripen);
stripen *= nsubstripes;
redundancy = nsubstripes;
@@ -1229,96 +1218,6 @@ grub_btrfs_read_inode (struct grub_btrfs_data *data,
return grub_btrfs_read_logical (data, elemaddr, inode, sizeof (*inode), 0);
}
-static void *grub_zstd_malloc (void *state __attribute__((unused)), size_t size)
-{
- return grub_malloc (size);
-}
-
-static void grub_zstd_free (void *state __attribute__((unused)), void *address)
-{
- return grub_free (address);
-}
-
-static ZSTD_customMem grub_zstd_allocator (void)
-{
- ZSTD_customMem allocator;
-
- allocator.customAlloc = &grub_zstd_malloc;
- allocator.customFree = &grub_zstd_free;
- allocator.opaque = NULL;
-
- return allocator;
-}
-
-static grub_ssize_t
-grub_btrfs_zstd_decompress (char *ibuf, grub_size_t isize, grub_off_t off,
- char *obuf, grub_size_t osize)
-{
- void *allocated = NULL;
- char *otmpbuf = obuf;
- grub_size_t otmpsize = osize;
- ZSTD_DCtx *dctx = NULL;
- grub_size_t zstd_ret;
- grub_ssize_t ret = -1;
-
- /*
- * Zstd will fail if it can't fit the entire output in the destination
- * buffer, so if osize isn't large enough, allocate a temporary buffer.
- */
- if (otmpsize < ZSTD_BTRFS_MAX_INPUT)
- {
- allocated = grub_malloc (ZSTD_BTRFS_MAX_INPUT);
- if (!allocated)
- {
- grub_error (GRUB_ERR_OUT_OF_MEMORY, "failed allocate a zstd buffer");
- goto err;
- }
- otmpbuf = (char *) allocated;
- otmpsize = ZSTD_BTRFS_MAX_INPUT;
- }
-
- /* Create the ZSTD_DCtx. */
- dctx = ZSTD_createDCtx_advanced (grub_zstd_allocator ());
- if (!dctx)
- {
- /* ZSTD_createDCtx_advanced() only fails if it is out of memory. */
- grub_error (GRUB_ERR_OUT_OF_MEMORY, "failed to create a zstd context");
- goto err;
- }
-
- /*
- * Get the real input size, there may be junk at the
- * end of the frame.
- */
- isize = ZSTD_findFrameCompressedSize (ibuf, isize);
- if (ZSTD_isError (isize))
- {
- grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data corrupted");
- goto err;
- }
-
- /* Decompress and check for errors. */
- zstd_ret = ZSTD_decompressDCtx (dctx, otmpbuf, otmpsize, ibuf, isize);
- if (ZSTD_isError (zstd_ret))
- {
- grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data corrupted");
- goto err;
- }
-
- /*
- * Move the requested data into the obuf. obuf may be equal
- * to otmpbuf, which is why grub_memmove() is required.
- */
- grub_memmove (obuf, otmpbuf + off, osize);
- ret = osize;
-
-err:
- grub_free (allocated);
- ZSTD_freeDCtx (dctx);
-
- return ret;
-}
-
static grub_ssize_t
grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
char *obuf, grub_size_t osize)
@@ -1494,8 +1393,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
if (data->extent->compression != GRUB_BTRFS_COMPRESSION_NONE
&& data->extent->compression != GRUB_BTRFS_COMPRESSION_ZLIB
- && data->extent->compression != GRUB_BTRFS_COMPRESSION_LZO
- && data->extent->compression != GRUB_BTRFS_COMPRESSION_ZSTD)
+ && data->extent->compression != GRUB_BTRFS_COMPRESSION_LZO)
{
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"compression type 0x%x not supported",
@@ -1535,15 +1433,6 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
!= (grub_ssize_t) csize)
return -1;
}
- else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZSTD)
- {
- if (grub_btrfs_zstd_decompress (data->extent->inl, data->extsize -
- ((grub_uint8_t *) data->extent->inl
- - (grub_uint8_t *) data->extent),
- extoff, buf, csize)
- != (grub_ssize_t) csize)
- return -1;
- }
else
grub_memcpy (buf, data->extent->inl + extoff, csize);
break;
@@ -1581,10 +1470,6 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
ret = grub_btrfs_lzo_decompress (tmp, zsize, extoff
+ grub_le_to_cpu64 (data->extent->offset),
buf, csize);
- else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZSTD)
- ret = grub_btrfs_zstd_decompress (tmp, zsize, extoff
- + grub_le_to_cpu64 (data->extent->offset),
- buf, csize);
else
ret = -1;
diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c
index 644653dbe..e4d08e031 100644
--- a/grub-core/fs/f2fs.c
+++ b/grub-core/fs/f2fs.c
@@ -131,6 +131,7 @@ enum FILE_TYPE
F2FS_FT_SYMLINK = 7
};
+PRAGMA_BEGIN_PACKED
struct grub_f2fs_superblock
{
grub_uint32_t magic;
@@ -281,6 +282,7 @@ struct grub_f2fs_node
};
grub_uint8_t dummy[40];
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_fshelp_node
{
diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c
index d544e0af1..95040bbaa 100644
--- a/grub-core/fs/fat.c
+++ b/grub-core/fs/fat.c
@@ -75,6 +75,7 @@ enum
{
FLAG_CONTIGUOUS = 2
};
+PRAGMA_BEGIN_PACKED
struct grub_fat_dir_entry
{
grub_uint8_t entry_type;
@@ -115,6 +116,7 @@ struct grub_fat_dir_entry
} GRUB_PACKED volume_label;
} GRUB_PACKED type_specific;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_fat_dir_node
{
@@ -129,6 +131,7 @@ struct grub_fat_dir_node
typedef struct grub_fat_dir_node grub_fat_dir_node_t;
#else
+PRAGMA_BEGIN_PACKED
struct grub_fat_dir_entry
{
grub_uint8_t name[11];
@@ -156,6 +159,7 @@ struct grub_fat_long_name_entry
grub_uint16_t first_cluster;
grub_uint16_t name3[2];
} GRUB_PACKED;
+PRAGMA_END_PACKED
typedef struct grub_fat_dir_entry grub_fat_dir_node_t;
@@ -726,7 +730,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
grub_dprintf ("exfat", "unknown primary type 0x%02x\n",
dir.entry_type);
}
- return grub_errno ? : GRUB_ERR_EOF;
+ return grub_errno ? grub_errno : GRUB_ERR_EOF;
}
#else
@@ -853,7 +857,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
return GRUB_ERR_NONE;
}
- return grub_errno ? : GRUB_ERR_EOF;
+ return grub_errno ? grub_errno : GRUB_ERR_EOF;
}
#endif
diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c
index ac0a40990..573102d22 100644
--- a/grub-core/fs/hfs.c
+++ b/grub-core/fs/hfs.c
@@ -58,6 +58,7 @@ enum grub_hfs_cnid_type
};
/* A node descriptor. This is the header of every node. */
+PRAGMA_BEGIN_PACKED
struct grub_hfs_node
{
grub_uint32_t next;
@@ -83,6 +84,7 @@ struct grub_hfs_treeheader
grub_uint32_t free_nodes;
grub_uint8_t unused[76];
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* The state of a mounted HFS filesystem. */
struct grub_hfs_data
@@ -103,6 +105,7 @@ struct grub_hfs_data
/* The key as used on disk in a catalog tree. This is used to lookup
file/directory nodes by parent directory ID and filename. */
+PRAGMA_BEGIN_PACKED
struct grub_hfs_catalog_key
{
grub_uint8_t unused;
@@ -156,6 +159,7 @@ struct grub_hfs_filerec
in the extent overflow file. */
grub_hfs_datarecord_t extents;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* A record descriptor, both key and data, used to pass to call back
functions. */
@@ -720,11 +724,13 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
for (i = 0; i < reccnt; i++)
{
int pos = (nodesize >> 1) - 1 - i;
+ PRAGMA_BEGIN_PACKED
struct pointer
{
grub_uint8_t keylen;
grub_uint8_t key;
} GRUB_PACKED *pnt;
+ PRAGMA_END_PACKED
grub_uint16_t off = grub_be_to_cpu16 (node->offsets[pos]);
if (off > nodesize - sizeof(*pnt))
continue;
diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c
index 54786bb1c..b945c7469 100644
--- a/grub-core/fs/hfsplus.c
+++ b/grub-core/fs/hfsplus.c
@@ -44,6 +44,7 @@ enum grub_hfsplus_btnode_type
};
/* The header of a HFS+ B+ Tree. */
+PRAGMA_BEGIN_PACKED
struct grub_hfsplus_btheader
{
grub_uint16_t depth;
@@ -76,6 +77,7 @@ struct grub_hfsplus_catfile
struct grub_hfsplus_forkdata data;
struct grub_hfsplus_forkdata resource;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* Filetype information as used in inodes. */
#define GRUB_HFSPLUS_FILEMODE_MASK 0170000
diff --git a/grub-core/fs/hfspluscomp.c b/grub-core/fs/hfspluscomp.c
index d76f3f137..28c586d87 100644
--- a/grub-core/fs/hfspluscomp.c
+++ b/grub-core/fs/hfspluscomp.c
@@ -24,10 +24,12 @@
#include <grub/mm.h>
#include <grub/deflate.h>
#include <grub/file.h>
+#include <grub/types.h>
GRUB_MOD_LICENSE ("GPLv3+");
/* big-endian. */
+PRAGMA_BEGIN_PACKED
struct grub_hfsplus_compress_header1
{
grub_uint32_t header_size;
@@ -48,6 +50,7 @@ struct grub_hfsplus_compress_header3
{
grub_uint32_t num_chunks;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* little-endian. */
struct grub_hfsplus_compress_block_descriptor
@@ -56,6 +59,7 @@ struct grub_hfsplus_compress_block_descriptor
grub_uint32_t size;
};
+PRAGMA_BEGIN_PACKED
struct grub_hfsplus_compress_end_descriptor
{
grub_uint8_t always_the_same[50];
@@ -76,6 +80,7 @@ struct grub_hfsplus_compress_attr
grub_uint32_t uncompressed_inline_size;
grub_uint32_t always_0;
} GRUB_PACKED;
+PRAGMA_END_PACKED
enum
{
diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c
index 49c0c632b..7ff140ef8 100644
--- a/grub-core/fs/iso9660.c
+++ b/grub-core/fs/iso9660.c
@@ -49,6 +49,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_ISO9660_VOLDESC_END 255
/* The head of a volume descriptor. */
+PRAGMA_BEGIN_PACKED
struct grub_iso9660_voldesc
{
grub_uint8_t type;
@@ -129,8 +130,18 @@ struct grub_iso9660_susp_entry
{
grub_uint8_t sig[2];
grub_uint8_t len;
- grub_uint8_t version;
- grub_uint8_t data[0];
+/*! MSVC compilers cannot handle a zero sized array in the middle
+ of a struct, and grub_iso9660_susp_entry is reused within
+ grub_iso9660_susp_ce. Therefore, instead of defining:
+ grub_uint8_t version;
+ grub_uint8_t data[];
+ we leverage the fact that these attributes are the same size
+ and use an union. The only gotcha is that the actual
+ payload of u.data[] starts at 1, not 0. */
+ union {
+ grub_uint8_t version;
+ grub_uint8_t data[1];
+ } u;
} GRUB_PACKED;
/* The CE entry. This is used to describe the next block where data
@@ -145,6 +156,7 @@ struct grub_iso9660_susp_ce
grub_uint32_t len;
grub_uint32_t len_be;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_iso9660_data
{
@@ -412,7 +424,7 @@ set_rockridge (struct grub_iso9660_data *data)
/* The 2nd data byte stored how many bytes are skipped every time
to get to the SUA (System Usage Area). */
- data->susp_skip = entry->data[2];
+ data->susp_skip = entry->u.data[1 + 2];
entry = (struct grub_iso9660_susp_entry *) ((char *) entry + entry->len);
/* Iterate over the entries in the SUA area to detect
@@ -552,9 +564,9 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
/* The flags are stored at the data position 0, here the
filename type is stored. */
/* FIXME: Fix this slightly improper cast. */
- if (entry->data[0] & GRUB_ISO9660_RR_DOT)
+ if (entry->u.data[1 + 0] & GRUB_ISO9660_RR_DOT)
ctx->filename = (char *) ".";
- else if (entry->data[0] & GRUB_ISO9660_RR_DOTDOT)
+ else if (entry->u.data[1 + 0] & GRUB_ISO9660_RR_DOTDOT)
ctx->filename = (char *) "..";
else if (entry->len >= 5)
{
@@ -578,7 +590,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
return grub_errno;
}
ctx->filename_alloc = 1;
- grub_memcpy (ctx->filename + off, (char *) &entry->data[1], csize);
+ grub_memcpy (ctx->filename + off, (char *) &entry->u.data[1 + 1], csize);
ctx->filename[off + csize] = '\0';
}
}
@@ -587,7 +599,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
{
/* At position 0 of the PX record the st_mode information is
stored (little-endian). */
- grub_uint32_t mode = ((entry->data[0] + (entry->data[1] << 8))
+ grub_uint32_t mode = ((entry->u.data[1 + 0] + (entry->u.data[1 + 1] << 8))
& GRUB_ISO9660_FSTYPE_MASK);
switch (mode)
@@ -613,7 +625,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
while (pos + sizeof (*entry) < entry->len)
{
/* The current position is the `Component Flag'. */
- switch (entry->data[pos] & 30)
+ switch (entry->u.data[1 + pos] & 30)
{
case 0:
{
@@ -622,9 +634,9 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
Record'. */
if (ctx->symlink && !ctx->was_continue)
add_part (ctx, "/", 1);
- add_part (ctx, (char *) &entry->data[pos + 2],
- entry->data[pos + 1]);
- ctx->was_continue = (entry->data[pos] & 1);
+ add_part (ctx, (char *) &entry->u.data[1 + pos + 2],
+ entry->u.data[1 + pos + 1]);
+ ctx->was_continue = (entry->u.data[1 + pos] & 1);
break;
}
@@ -642,7 +654,7 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
}
/* In pos + 1 the length of the `Component Record' is
stored. */
- pos += entry->data[pos + 1] + 2;
+ pos += entry->u.data[1 + pos + 1] + 2;
}
/* Check if `grub_realloc' failed. */
diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c
index d5a6d6527..55ff31e31 100644
--- a/grub-core/fs/jfs.c
+++ b/grub-core/fs/jfs.c
@@ -61,6 +61,7 @@ struct grub_jfs_sblock
char volname2[16];
};
+PRAGMA_BEGIN_PACKED
struct grub_jfs_extent
{
/* The length of the extent in filesystem blocks. */
@@ -252,6 +253,7 @@ struct grub_jfs_diropen
char name[256 * GRUB_MAX_UTF8_PER_UTF16 + 1];
grub_uint32_t ino;
} GRUB_PACKED;
+PRAGMA_END_PACKED
static grub_dl_t my_mod;
diff --git a/grub-core/fs/nilfs2.c b/grub-core/fs/nilfs2.c
index 7ed148d3b..a56cf7f8c 100644
--- a/grub-core/fs/nilfs2.c
+++ b/grub-core/fs/nilfs2.c
@@ -132,6 +132,7 @@ struct grub_nilfs2_super_block
grub_uint32_t s_reserved[192];
};
+PRAGMA_BEGIN_PACKED
struct grub_nilfs2_dir_entry
{
grub_uint64_t inode;
@@ -144,6 +145,7 @@ struct grub_nilfs2_dir_entry
char pad;
#endif
} GRUB_PACKED;
+PRAGMA_END_PACKED
enum
{
@@ -735,7 +737,7 @@ static grub_err_t
grub_nilfs2_load_sb (struct grub_nilfs2_data *data)
{
grub_disk_t disk = data->disk;
- struct grub_nilfs2_super_block sb2;
+ struct grub_nilfs2_super_block sb2 = { 0 };
grub_uint64_t partition_size;
int valid[2];
int swp = 0;
diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c
index fc4e1f678..684478727 100644
--- a/grub-core/fs/ntfs.c
+++ b/grub-core/fs/ntfs.c
@@ -638,6 +638,7 @@ list_file (struct grub_ntfs_file *diro, grub_uint8_t *pos,
return 0;
}
+PRAGMA_BEGIN_PACKED
struct symlink_descriptor
{
grub_uint32_t type;
@@ -647,6 +648,7 @@ struct symlink_descriptor
grub_uint16_t off2;
grub_uint16_t len2;
} GRUB_PACKED;
+PRAGMA_END_PACKED
static char *
grub_ntfs_read_symlink (grub_fshelp_node_t node)
diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c
index af6a226a7..b76141fee 100644
--- a/grub-core/fs/reiserfs.c
+++ b/grub-core/fs/reiserfs.c
@@ -42,15 +42,27 @@
GRUB_MOD_LICENSE ("GPLv3+");
+#ifndef _MSC_VER
+#ifndef MIN
#define MIN(a, b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a < _b ? _a : _b; })
-
+#endif
+#ifndef MAX
#define MAX(a, b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })
+#endif
+#else
+#ifndef MIN
+#define MIN(a, b) ((a)<(b)?(a):(b))
+#endif
+#ifndef MAX
+#define MAX(a, b) ((a)>(b)?(a):(b))
+#endif
+#endif
#define REISERFS_SUPER_BLOCK_OFFSET 0x10000
#define REISERFS_MAGIC_LEN 12
@@ -82,6 +94,7 @@ enum grub_reiserfs_item_type
GRUB_REISERFS_UNKNOWN
};
+PRAGMA_BEGIN_PACKED
struct grub_reiserfs_superblock
{
grub_uint32_t block_count;
@@ -217,6 +230,7 @@ struct grub_reiserfs_directory_header
grub_uint16_t location;
grub_uint16_t state;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_fshelp_node
{
diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c
index 50c1fe72f..355313d5e 100644
--- a/grub-core/fs/sfs.c
+++ b/grub-core/fs/sfs.c
@@ -30,6 +30,7 @@
GRUB_MOD_LICENSE ("GPLv3+");
/* The common header for a block. */
+PRAGMA_BEGIN_PACKED
struct grub_sfs_bheader
{
grub_uint8_t magic[4];
@@ -121,9 +122,10 @@ struct grub_sfs_btree
supported. */
struct grub_sfs_btree_node node[1];
} GRUB_PACKED;
-
+PRAGMA_END_PACKED
+
struct cache_entry
{
grub_uint32_t off;
diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c
index dc8b6e2d1..8f95e3f76 100644
--- a/grub-core/fs/udf.c
+++ b/grub-core/fs/udf.c
@@ -113,6 +113,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_UDF_PARTMAP_TYPE_1 1
#define GRUB_UDF_PARTMAP_TYPE_2 2
+PRAGMA_BEGIN_PACKED
struct grub_udf_lb_addr
{
grub_uint32_t block_num;
@@ -370,6 +371,7 @@ struct grub_udf_aed
grub_uint32_t prev_ae;
grub_uint32_t ae_len;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_udf_data
{
diff --git a/grub-core/fs/ufs.c b/grub-core/fs/ufs.c
index fca46baa1..7b3fb63f6 100644
--- a/grub-core/fs/ufs.c
+++ b/grub-core/fs/ufs.c
@@ -152,6 +152,7 @@ struct grub_ufs_sblock
grub_uint32_t magic;
};
+PRAGMA_BEGIN_PACKED
#ifdef MODE_UFS2
/* UFS inode. */
struct grub_ufs_inode
@@ -235,6 +236,7 @@ struct grub_ufs_dirent
};
};
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* Information about a "mounted" ufs filesystem. */
struct grub_ufs_data
diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
index 96ffecbfc..e8138090e 100644
--- a/grub-core/fs/xfs.c
+++ b/grub-core/fs/xfs.c
@@ -93,6 +93,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
XFS_SB_FEAT_INCOMPAT_SPINODES | \
XFS_SB_FEAT_INCOMPAT_META_UUID)
+PRAGMA_BEGIN_PACKED
struct grub_xfs_sblock
{
grub_uint8_t magic[4];
@@ -209,6 +210,7 @@ struct grub_xfs_dirblock_tail
grub_uint32_t leaf_count;
grub_uint32_t leaf_stale;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_fshelp_node
{
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
index 2f72e42bf..c10235f53 100644
--- a/grub-core/fs/zfs/zfs.c
+++ b/grub-core/fs/zfs/zfs.c
@@ -141,7 +141,7 @@ ZAP_LEAF_NUMCHUNKS (int bs)
static inline zap_leaf_chunk_t *
ZAP_LEAF_CHUNK (zap_leaf_phys_t *l, int bs, int idx)
{
- return &((zap_leaf_chunk_t *) (l->l_entries
+ return &((zap_leaf_chunk_t *) (l->u.l_entries
+ (ZAP_LEAF_HASH_NUMENTRIES(bs) * 2)
/ sizeof (grub_properly_aligned_t)))[idx];
}
@@ -2260,7 +2260,7 @@ zap_leaf_lookup (zap_leaf_phys_t * l, grub_zfs_endian_t endian,
if (grub_zfs_to_cpu32 (l->l_hdr.lh_magic, endian) != ZAP_LEAF_MAGIC)
return grub_error (GRUB_ERR_BAD_FS, "invalid leaf magic");
- for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], endian);
+ for (chunk = grub_zfs_to_cpu16 (l->u.l_hash[LEAF_HASH (blksft, h, l)], endian);
chunk != CHAIN_END; chunk = grub_zfs_to_cpu16 (le->le_next, endian))
{
@@ -2709,7 +2709,9 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type,
return GRUB_ERR_NONE;
}
+#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
/*
* Get the file dnode for a given file name where mdn is the meta dnode
diff --git a/grub-core/fs/zfs/zfs_lz4.c b/grub-core/fs/zfs/zfs_lz4.c
index 5453822d0..873445803 100644
--- a/grub-core/fs/zfs/zfs_lz4.c
+++ b/grub-core/fs/zfs/zfs_lz4.c
@@ -74,6 +74,7 @@ static int LZ4_uncompress_unknownOutputSize(const char *source, char *dest,
#define S32 grub_int32_t
#define U64 grub_uint64_t
+PRAGMA_BEGIN_PACKED
typedef struct _U16_S {
U16 v;
} GRUB_PACKED U16_S;
@@ -83,6 +84,7 @@ typedef struct _U32_S {
typedef struct _U64_S {
U64 v;
} GRUB_PACKED U64_S;
+PRAGMA_END_PACKED
#define A64(x) (((U64_S *)(x))->v)
#define A32(x) (((U32_S *)(x))->v)
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 3b633d51f..1eed48883 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -138,7 +138,7 @@ grub_puts_ (const char *s)
return grub_puts (_(s));
}
-#if defined (__APPLE__) && ! defined (GRUB_UTIL)
+#if ( defined (__APPLE__) || defined (_MSC_VER) ) && ! defined (GRUB_UTIL)
int
grub_err_printf (const char *fmt, ...)
{
@@ -153,7 +153,7 @@ grub_err_printf (const char *fmt, ...)
}
#endif
-#if ! defined (__APPLE__) && ! defined (GRUB_UTIL)
+#if ! defined (__APPLE__) && ! defined (_MSC_VER) && ! defined (GRUB_UTIL)
int grub_err_printf (const char *fmt, ...)
__attribute__ ((alias("grub_printf")));
#endif
@@ -969,7 +969,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
{
grub_size_t len = 0;
grub_size_t fill;
- const char *p = ((char *) (grub_addr_t) curarg) ? : "(null)";
+ const char *p = (curarg != 0) ? ((char *) (grub_addr_t) curarg) : "(null)";
grub_size_t i;
while (len < format2 && p[len])
diff --git a/grub-core/lib/minilzo/lzodefs.h b/grub-core/lib/minilzo/lzodefs.h
index 0e40e332a..eea56b170 100644
--- a/grub-core/lib/minilzo/lzodefs.h
+++ b/grub-core/lib/minilzo/lzodefs.h
@@ -670,6 +670,9 @@
# define LZO_ARCH_I086 1
# define LZO_ARCH_IA16 1
# define LZO_INFO_ARCH "i086"
+#elif defined(__aarch64__) || defined(_M_ARM64)
+# define LZO_ARCH_ARM64 1
+# define LZO_INFO_ARCH "arm64"
#elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA)
# define LZO_ARCH_ALPHA 1
# define LZO_INFO_ARCH "alpha"
diff --git a/include/grub/arm64/types.h b/include/grub/arm64/types.h
index d132c5eab..54b5e6398 100644
--- a/include/grub/arm64/types.h
+++ b/include/grub/arm64/types.h
@@ -23,7 +23,11 @@
#define GRUB_TARGET_SIZEOF_VOID_P 8
/* The size of long. */
+#if defined(_MSC_VER)
+#define GRUB_TARGET_SIZEOF_LONG 4
+#else
#define GRUB_TARGET_SIZEOF_LONG 8
+#endif
/* currently only support little-endian. */
#undef GRUB_TARGET_WORDS_BIGENDIAN
diff --git a/include/grub/btrfs.h b/include/grub/btrfs.h
index 9d93fb6c1..f62312c04 100644
--- a/include/grub/btrfs.h
+++ b/include/grub/btrfs.h
@@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <grub/types.h>
#ifndef GRUB_BTRFS_H
#define GRUB_BTRFS_H 1
@@ -45,12 +46,14 @@ struct grub_btrfs_root_item
grub_uint64_t inode;
};
+PRAGMA_BEGIN_PACKED
struct grub_btrfs_key
{
grub_uint64_t object_id;
grub_uint8_t type;
grub_uint64_t offset;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_btrfs_root_backref
diff --git a/include/grub/exfat.h b/include/grub/exfat.h
index 2b8009cee..b7654d0aa 100644
--- a/include/grub/exfat.h
+++ b/include/grub/exfat.h
@@ -21,6 +21,7 @@
#include <grub/types.h>
+PRAGMA_BEGIN_PACKED
struct grub_exfat_bpb
{
grub_uint8_t jmp_boot[3];
@@ -42,6 +43,7 @@ struct grub_exfat_bpb
grub_uint8_t num_ph_drive;
grub_uint8_t reserved[8];
} GRUB_PACKED;
+PRAGMA_END_PACKED
#ifdef GRUB_UTIL
#include <grub/disk.h>
diff --git a/include/grub/fat.h b/include/grub/fat.h
index 8d7e4a1e5..bf4441479 100644
--- a/include/grub/fat.h
+++ b/include/grub/fat.h
@@ -21,6 +21,7 @@
#include <grub/types.h>
+PRAGMA_BEGIN_PACKED
struct grub_fat_bpb
{
grub_uint8_t jmp_boot[3];
@@ -66,6 +67,7 @@ struct grub_fat_bpb
} GRUB_PACKED fat32;
} GRUB_PACKED version_specific;
} GRUB_PACKED;
+PRAGMA_END_PACKED
#ifdef GRUB_UTIL
#include <grub/disk.h>
diff --git a/include/grub/hfs.h b/include/grub/hfs.h
index e27993c42..1a1943d67 100644
--- a/include/grub/hfs.h
+++ b/include/grub/hfs.h
@@ -36,6 +36,7 @@ typedef struct grub_hfs_extent grub_hfs_datarecord_t[3];
/* The HFS superblock (The official name is `Master Directory
Block'). */
+PRAGMA_BEGIN_PACKED
struct grub_hfs_sblock
{
grub_uint16_t magic;
@@ -68,5 +69,6 @@ struct grub_hfs_sblock
grub_uint32_t catalog_size;
grub_hfs_datarecord_t catalog_recs;
} GRUB_PACKED;
+PRAGMA_END_PACKED
#endif /* ! GRUB_HFS_HEADER */
diff --git a/include/grub/hfsplus.h b/include/grub/hfsplus.h
index 117740ae2..5a8caf59f 100644
--- a/include/grub/hfsplus.h
+++ b/include/grub/hfsplus.h
@@ -24,6 +24,7 @@
#define GRUB_HFSPLUS_SBLOCK 2
/* A HFS+ extent. */
+PRAGMA_BEGIN_PACKED
struct grub_hfsplus_extent
{
/* The first block of a file on disk. */
@@ -68,6 +69,7 @@ struct grub_hfsplus_volheader
struct grub_hfsplus_forkdata attr_file;
struct grub_hfsplus_forkdata startup_file;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_hfsplus_compress_index
{
@@ -138,6 +140,7 @@ struct grub_hfsplus_extkey_internal
grub_uint8_t type;
};
+PRAGMA_BEGIN_PACKED
struct grub_hfsplus_attrkey
{
grub_uint16_t keylen;
@@ -147,6 +150,7 @@ struct grub_hfsplus_attrkey
grub_uint16_t namelen;
grub_uint16_t name[0];
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_hfsplus_attrkey_internal
{
@@ -166,6 +170,7 @@ struct grub_hfsplus_key_internal
};
/* The on disk layout of a catalog key. */
+PRAGMA_BEGIN_PACKED
struct grub_hfsplus_catkey
{
grub_uint16_t keylen;
@@ -204,6 +209,7 @@ struct grub_hfsplus_btnode
grub_uint16_t count;
grub_uint16_t unused;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* Return the offset of the record with the index INDEX, in the node
NODE which is part of the B+ tree BTREE. */
diff --git a/include/grub/misc.h b/include/grub/misc.h
index ee48eb7a7..d1c5e7eee 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -27,12 +27,22 @@
#include <grub/i18n.h>
#include <grub/compiler.h>
+#ifndef _MSC_VER
#define ALIGN_UP(addr, align) \
((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1))
#define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((typeof (addr)) (align) - 1))
#define ALIGN_DOWN(addr, align) \
((addr) & ~((typeof (addr)) align - 1))
+#else
+#define ALIGN_UP(addr, align) \
+ ((addr + align - 1) & ~(align - 1))
+#define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((align) - 1))
+#define ALIGN_DOWN(addr, align) \
+ ((addr) & ~(align - 1))
+#endif
+#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))
+#endif
#define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; }
#define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, __VA_ARGS__)
diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h
index d1a6af696..203e0141e 100644
--- a/include/grub/ntfs.h
+++ b/include/grub/ntfs.h
@@ -101,6 +101,7 @@ enum
GRUB_NTFS_RF_BLNK = 1
};
+PRAGMA_BEGIN_PACKED
struct grub_ntfs_bpb
{
grub_uint8_t jmp_boot[3];
@@ -126,6 +127,7 @@ struct grub_ntfs_bpb
grub_uint64_t num_serial;
grub_uint32_t checksum;
} GRUB_PACKED;
+PRAGMA_END_PACKED
struct grub_ntfs_attr
{
diff --git a/include/grub/term.h b/include/grub/term.h
index 8117e2a24..f87c0d022 100644
--- a/include/grub/term.h
+++ b/include/grub/term.h
@@ -335,12 +335,12 @@ void grub_term_restore_pos (struct grub_term_coordinate *pos);
static inline unsigned grub_term_width (struct grub_term_output *term)
{
- return term->getwh(term).x ? : 80;
+ return term->getwh(term).x ? term->getwh(term).x : 80;
}
static inline unsigned grub_term_height (struct grub_term_output *term)
{
- return term->getwh(term).y ? : 24;
+ return term->getwh(term).y ? term->getwh(term).y : 24;
}
static inline struct grub_term_coordinate
diff --git a/include/grub/types.h b/include/grub/types.h
index 035a4b528..1fb923e92 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -26,10 +26,20 @@
#ifdef __MINGW32__
#define GRUB_PACKED __attribute__ ((packed,gcc_struct))
+#elif defined(_MSC_VER)
+#define GRUB_PACKED
#else
#define GRUB_PACKED __attribute__ ((packed))
#endif
+#ifdef _MSC_VER
+#define PRAGMA_BEGIN_PACKED __pragma(pack(push, 1))
+#define PRAGMA_END_PACKED __pragma(pack(pop))
+#else
+#define PRAGMA_BEGIN_PACKED
+#define PRAGMA_END_PACKED
+#endif
+
#ifdef GRUB_BUILD
# define GRUB_CPU_SIZEOF_VOID_P BUILD_SIZEOF_VOID_P
# define GRUB_CPU_SIZEOF_LONG BUILD_SIZEOF_LONG
@@ -170,17 +180,15 @@ static inline grub_uint16_t grub_swap_bytes16(grub_uint16_t _x)
#define grub_swap_bytes16_compile_time(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
#define grub_swap_bytes32_compile_time(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000UL) >> 24))
#define grub_swap_bytes64_compile_time(x) \
-({ \
- grub_uint64_t _x = (x); \
- (grub_uint64_t) ((_x << 56) \
- | ((_x & (grub_uint64_t) 0xFF00ULL) << 40) \
- | ((_x & (grub_uint64_t) 0xFF0000ULL) << 24) \
- | ((_x & (grub_uint64_t) 0xFF000000ULL) << 8) \
- | ((_x & (grub_uint64_t) 0xFF00000000ULL) >> 8) \
- | ((_x & (grub_uint64_t) 0xFF0000000000ULL) >> 24) \
- | ((_x & (grub_uint64_t) 0xFF000000000000ULL) >> 40) \
- | (_x >> 56)); \
-})
+((grub_uint64_t) ((((grub_uint64_t)x) << 56) \
+ | ((((grub_uint64_t)x) & (grub_uint64_t) 0xFF00ULL) << 40) \
+ | ((((grub_uint64_t)x) & (grub_uint64_t) 0xFF0000ULL) << 24) \
+ | ((((grub_uint64_t)x) & (grub_uint64_t) 0xFF000000ULL) << 8) \
+ | ((((grub_uint64_t)x) & (grub_uint64_t) 0xFF00000000ULL) >> 8) \
+ | ((((grub_uint64_t)x) & (grub_uint64_t) 0xFF0000000000ULL) >> 24) \
+ | ((((grub_uint64_t)x) & (grub_uint64_t) 0xFF000000000000ULL) >> 40) \
+ | (((grub_uint64_t)x) >> 56)) \
+)
#if (defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)) || defined(__clang__)
static inline grub_uint32_t grub_swap_bytes32(grub_uint32_t x)
@@ -257,18 +265,24 @@ static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t _x)
#endif /* ! WORDS_BIGENDIAN */
+PRAGMA_BEGIN_PACKED
struct grub_unaligned_uint16
{
grub_uint16_t val;
} GRUB_PACKED;
+PRAGMA_END_PACKED
+PRAGMA_BEGIN_PACKED
struct grub_unaligned_uint32
{
grub_uint32_t val;
} GRUB_PACKED;
+PRAGMA_END_PACKED
+PRAGMA_BEGIN_PACKED
struct grub_unaligned_uint64
{
grub_uint64_t val;
} GRUB_PACKED;
+PRAGMA_END_PACKED
typedef struct grub_unaligned_uint16 grub_unaligned_uint16_t;
typedef struct grub_unaligned_uint32 grub_unaligned_uint32_t;
@@ -309,10 +323,12 @@ static inline grub_uint64_t grub_get_unaligned64 (const void *ptr)
static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)
{
+ PRAGMA_BEGIN_PACKED
struct grub_unaligned_uint64_t
{
grub_uint64_t d;
} GRUB_PACKED;
+ PRAGMA_END_PACKED
struct grub_unaligned_uint64_t *dd = (struct grub_unaligned_uint64_t *) ptr;
dd->d = val;
}
diff --git a/include/grub/unicode.h b/include/grub/unicode.h
index a0403e91f..5984982fe 100644
--- a/include/grub/unicode.h
+++ b/include/grub/unicode.h
@@ -29,6 +29,7 @@ struct grub_unicode_bidi_pair
grub_uint32_t replace;
};
+PRAGMA_BEGIN_PACKED
struct grub_unicode_compact_range
{
unsigned start:21;
@@ -38,6 +39,7 @@ struct grub_unicode_compact_range
unsigned bidi_mirror:1;
unsigned join_type:3;
} GRUB_PACKED;
+PRAGMA_END_PACKED
/* Old-style Arabic shaping. Used for "visual UTF-8" and
in grub-mkfont to find variant glyphs in absence of GPOS tables. */
diff --git a/include/grub/x86_64/types.h b/include/grub/x86_64/types.h
index 0bbdc6d01..eefa80847 100644
--- a/include/grub/x86_64/types.h
+++ b/include/grub/x86_64/types.h
@@ -27,7 +27,7 @@
#endif
/* The size of long. */
-#if defined(__MINGW32__) || defined(__ILP32__)
+#if defined(__MINGW32__) || defined(__ILP32__) || defined(_MSC_VER)
#define GRUB_TARGET_SIZEOF_LONG 4
#else
#define GRUB_TARGET_SIZEOF_LONG 8
diff --git a/include/grub/zfs/zap_leaf.h b/include/grub/zfs/zap_leaf.h
index 95c67dcba..ac65e30b8 100644
--- a/include/grub/zfs/zap_leaf.h
+++ b/include/grub/zfs/zap_leaf.h
@@ -68,9 +68,18 @@ typedef struct zap_leaf_phys {
* zap_leaf_chunk structures. These structures are accessed
* with the ZAP_LEAF_CHUNK() macro.
*/
-
- grub_uint16_t l_hash[0];
- grub_properly_aligned_t l_entries[0];
+ /* Use an union to work around MSVC limitations. This only works
+ * here because this structure is not being included in another,
+ * as you must be mindful that, in the MSVC world, a union of
+ * zero sized arrays has a size of _1_, whereas in the gcc world,
+ * it has a size of _0_ => if you were to include this structure
+ * into another one, you would have to compute the offsets in a
+ * different manner for MSVC and gcc.
+ */
+ union {
+ grub_uint16_t l_hash[0];
+ grub_properly_aligned_t l_entries[0];
+ } u;
} zap_leaf_phys_t;
typedef union zap_leaf_chunk {
@@ -87,11 +96,13 @@ typedef union zap_leaf_chunk {
} l_entry;
struct zap_leaf_array {
grub_uint8_t la_type; /* always ZAP_CHUNK_ARRAY */
+ PRAGMA_BEGIN_PACKED
union
{
grub_uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
grub_uint64_t la_array64;
} GRUB_PACKED;
+ PRAGMA_END_PACKED
grub_uint16_t la_next; /* next blk or CHAIN_END */
} l_array;
struct zap_leaf_free {
diff --git a/include/grub/zfs/zio.h b/include/grub/zfs/zio.h
index 19ce136bb..11ee51b61 100644
--- a/include/grub/zfs/zio.h
+++ b/include/grub/zfs/zio.h
@@ -27,10 +27,12 @@
#define ZEC_MAGIC 0x210da7ab10c7a11ULL /* zio data bloc tail */
+PRAGMA_BEGIN_PACKED
typedef struct zio_eck {
grub_uint64_t zec_magic; /* for validation, endianness */
zio_cksum_t zec_cksum; /* 256-bit checksum */
} GRUB_PACKED zio_eck_t;
+PRAGMA_END_PACKED
/*
* Gang block headers are self-checksumming and contain an array
--
2.21.0.windows.1
1
https://gitee.com/longpanda/efifs.git
git@gitee.com:longpanda/efifs.git
longpanda
efifs
efifs
master

搜索帮助