[syslinux] [PATCH 3/5] installers: MSVC compatibility fixes
Pete Batard
pete at akeo.ie
Wed Feb 24 05:02:34 PST 2016
More MSVC compatibility fixes, for packed structures.
NB: In case you are aware of the issues that may come with MS vs GCC
packing, so far, I have not seen evidence of detrimental impact from
using ms_struct packing in MSVC (vs gcc_struct, which is explicitly
specified for MinGW), with regards to the sections of code I am using in
Rufus.
-------------- next part --------------
From 13b39c1f113a8bc5621249db21a382a689aa174e Mon Sep 17 00:00:00 2001
From: Pete Batard <pete at akeo.ie>
Date: Tue, 23 Feb 2016 19:57:28 +0000
Subject: [PATCH 3/5] installers: MSVC compatibility fixes
---
libinstaller/syslxint.h | 13 ++++++++++++-
libinstaller/syslxmod.c | 3 ++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/libinstaller/syslxint.h b/libinstaller/syslxint.h
index 7eee789..9ff63f2 100644
--- a/libinstaller/syslxint.h
+++ b/libinstaller/syslxint.h
@@ -17,7 +17,7 @@
#include "syslinux.h"
-#if defined(__386__) || defined(__i386__) || defined(__x86_64__)
+#if defined(__386__) || defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)
# define X86_MEM 1 /* Littleendian and unaligned safe */
#else
# define X86_MEM 0
@@ -26,10 +26,15 @@
#ifdef __GNUC__
# ifdef __MINGW32__
/* gcc 4.7 miscompiles packed structures in MS-bitfield mode */
+# define PACKME
# define PACKED __attribute__((packed,gcc_struct))
# else
+# define PACKME
# define PACKED __attribute__((packed))
# endif
+#elif defined(_MSC_VER)
+# define PACKME __pragma(pack(push, 1))
+# define PACKED __pragma(pack(pop))
#else
# error "Need to define PACKED for this compiler"
#endif
@@ -214,12 +219,14 @@ struct ext_patch_area {
};
/* Sector extent */
+PACKME
struct syslinux_extent {
uint64_t lba;
uint16_t len;
} PACKED;
/* FAT bootsector format, also used by other disk-based derivatives */
+PACKME
struct fat_boot_sector {
uint8_t bsJump[3];
char bsOemName[8];
@@ -236,7 +243,9 @@ struct fat_boot_sector {
uint32_t bsHiddenSecs;
uint32_t bsHugeSectors;
+ PACKME
union {
+ PACKME
struct {
uint8_t DriveNumber;
uint8_t Reserved1;
@@ -246,6 +255,7 @@ struct fat_boot_sector {
char FileSysType[8];
uint8_t Code[442];
} PACKED bs16;
+ PACKME
struct {
uint32_t FATSz32;
uint16_t ExtFlags;
@@ -270,6 +280,7 @@ struct fat_boot_sector {
} PACKED;
/* NTFS bootsector format */
+PACKME
struct ntfs_boot_sector {
uint8_t bsJump[3];
char bsOemName[8];
diff --git a/libinstaller/syslxmod.c b/libinstaller/syslxmod.c
index 0ec4164..7bf4d91 100644
--- a/libinstaller/syslxmod.c
+++ b/libinstaller/syslxmod.c
@@ -41,7 +41,8 @@ static void generate_extents(struct syslinux_extent _slimg *ex, int nptrs,
unsigned int len;
base = addr;
- len = lba = 0;
+ len = 0;
+ lba = 0;
memset_sl(ex, 0, nptrs * sizeof *ex);
--
1.9.5.msysgit.1
More information about the Syslinux
mailing list