aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2014-01-17 16:54:32 -0800
committerH. Peter Anvin <hpa@zytor.com>2014-01-17 16:55:34 -0800
commit12eae5ce91273ba9a98b7fe9a838f5ef2f9044b7 (patch)
tree871283162279ea3cff76c9c776ea024c4839c4dd
parent39311d7551b2834c67f3fd3ac197f8f634afb2d1 (diff)
downloadhdt-12eae5ce91273ba9a98b7fe9a838f5ef2f9044b7.tar.gz
hdt-12eae5ce91273ba9a98b7fe9a838f5ef2f9044b7.tar.xz
hdt-12eae5ce91273ba9a98b7fe9a838f5ef2f9044b7.zip
installer: Add sparse address space annotations to the syslinux image
Add sparse address space annotations for the syslinux boot image, to make it easier to catch errors that break the DOS installer build again. Use "make CC=cgcc" to run sparse. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--extlinux/main.c16
-rw-r--r--libinstaller/syslinux.h12
-rw-r--r--libinstaller/syslxint.h77
-rw-r--r--libinstaller/syslxmod.c38
-rwxr-xr-xlinux/syslinux.c10
-rwxr-xr-xmtools/syslinux.c12
-rw-r--r--win/syslinux.c8
7 files changed, 116 insertions, 57 deletions
diff --git a/extlinux/main.c b/extlinux/main.c
index 9ee9abb4..47c1e68e 100644
--- a/extlinux/main.c
+++ b/extlinux/main.c
@@ -455,7 +455,7 @@ static int rewrite_boot_image(int devfd, const char *path, const char *filename)
}
/* Write boot image data into LDLINUX.SYS file */
- ret = xpwrite(fd, boot_image, boot_image_len, 0);
+ ret = xpwrite(fd, (const char _force *)boot_image, boot_image_len, 0);
if (ret != boot_image_len) {
perror("writing bootblock");
goto error;
@@ -473,7 +473,7 @@ static int rewrite_boot_image(int devfd, const char *path, const char *filename)
/* Write the patch area again - this relies on the file being overwritten
* in place! */
- ret = xpwrite(fd, boot_image, modbytes, 0);
+ ret = xpwrite(fd, (const char _force *)boot_image, modbytes, 0);
if (ret != modbytes) {
fprintf(stderr, "%s: write failure on %s\n", program, filename);
goto error;
@@ -552,7 +552,8 @@ int ext2_fat_install_file(const char *path, int devfd, struct stat *rst)
goto bail;
}
- r3 = xpwrite(fd, syslinux_ldlinuxc32, syslinux_ldlinuxc32_len, 0);
+ r3 = xpwrite(fd, (const char _force *)syslinux_ldlinuxc32,
+ syslinux_ldlinuxc32_len, 0);
if (r3 != syslinux_ldlinuxc32_len) {
fprintf(stderr, "%s: write failure on %s\n", program, c32file);
goto bail;
@@ -584,7 +585,8 @@ int btrfs_install_file(const char *path, int devfd, struct stat *rst)
int fd, rv;
patch_file_and_bootblock(-1, path, devfd);
- if (xpwrite(devfd, boot_image, boot_image_len, BTRFS_EXTLINUX_OFFSET)
+ if (xpwrite(devfd, (const char _force *)boot_image,
+ boot_image_len, BTRFS_EXTLINUX_OFFSET)
!= boot_image_len) {
perror("writing bootblock");
return 1;
@@ -621,7 +623,8 @@ int btrfs_install_file(const char *path, int devfd, struct stat *rst)
return 1;
}
- rv = xpwrite(fd, syslinux_ldlinuxc32, syslinux_ldlinuxc32_len, 0);
+ rv = xpwrite(fd, (const char _force *)syslinux_ldlinuxc32,
+ syslinux_ldlinuxc32_len, 0);
if (rv != (int)syslinux_ldlinuxc32_len) {
fprintf(stderr, "%s: write failure on %s\n", program, file);
rv = 1;
@@ -699,7 +702,8 @@ static int xfs_install_file(const char *path, int devfd, struct stat *rst)
goto bail;
}
- retval = xpwrite(fd, syslinux_ldlinuxc32, syslinux_ldlinuxc32_len, 0);
+ retval = xpwrite(fd, (const char _force *)syslinux_ldlinuxc32,
+ syslinux_ldlinuxc32_len, 0);
if (retval != (int)syslinux_ldlinuxc32_len) {
fprintf(stderr, "%s: write failure on %s\n", program, file);
goto bail;
diff --git a/libinstaller/syslinux.h b/libinstaller/syslinux.h
index f60a066e..f6c64333 100644
--- a/libinstaller/syslinux.h
+++ b/libinstaller/syslinux.h
@@ -17,16 +17,24 @@
#include "advconst.h"
#include "setadv.h"
+#ifdef __CHECKER__
+# define _slimg __attribute__((noderef,address_space(1)))
+# define _force __attribute__((force))
+#else
+# define _slimg
+# define _force
+#endif
+
/* The standard boot sector and ldlinux image */
extern unsigned char syslinux_bootsect[];
extern const unsigned int syslinux_bootsect_len;
extern const int syslinux_bootsect_mtime;
-extern unsigned char syslinux_ldlinux[];
+extern unsigned char _slimg syslinux_ldlinux[];
extern const unsigned int syslinux_ldlinux_len;
extern const int syslinux_ldlinux_mtime;
-extern unsigned char syslinux_ldlinuxc32[];
+extern unsigned char _slimg syslinux_ldlinuxc32[];
extern const unsigned int syslinux_ldlinuxc32_len;
#define boot_sector syslinux_bootsect
diff --git a/libinstaller/syslxint.h b/libinstaller/syslxint.h
index ce9cb209..a487efd4 100644
--- a/libinstaller/syslxint.h
+++ b/libinstaller/syslxint.h
@@ -124,32 +124,65 @@ static inline void set_64(uint64_t *p, uint64_t v)
*/
#ifdef __MSDOS__
-uint8_t get_8_sl(const uint8_t * p);
-uint16_t get_16_sl(const uint16_t * p);
-uint32_t get_32_sl(const uint32_t * p);
-uint64_t get_64_sl(const uint64_t * p);
-void set_8_sl(uint8_t * p, uint8_t v);
-void set_16_sl(uint16_t * p, uint16_t v);
-void set_32_sl(uint32_t * p, uint32_t v);
-void set_64_sl(uint64_t * p, uint64_t v);
-void memcpy_to_sl(void *dst, const void *src, size_t len);
-void memcpy_from_sl(void *dst, const void *src, size_t len);
-void memset_sl(void *dst, int c, size_t len);
+uint8_t get_8_sl(const uint8_t _slimg * p);
+uint16_t get_16_sl(const uint16_t _slimg * p);
+uint32_t get_32_sl(const uint32_t _slimg * p);
+uint64_t get_64_sl(const uint64_t _slimg * p);
+void set_8_sl(uint8_t _slimg * p, uint8_t v);
+void set_16_sl(uint16_t _slimg * p, uint16_t v);
+void set_32_sl(uint32_t _slimg * p, uint32_t v);
+void set_64_sl(uint64_t _slimg * p, uint64_t v);
+void memcpy_to_sl(void _slimg *dst, const void *src, size_t len);
+void memcpy_from_sl(void *dst, const void _slimg *src, size_t len);
+void memset_sl(void _slimg *dst, int c, size_t len);
#else
/* Sane system ... */
-#define get_8_sl(x) get_8(x)
-#define get_16_sl(x) get_16(x)
-#define get_32_sl(x) get_32(x)
-#define get_64_sl(x) get_64(x)
-#define set_8_sl(x,y) set_8(x,y)
-#define set_16_sl(x,y) set_16(x,y)
-#define set_32_sl(x,y) set_32(x,y)
-#define set_64_sl(x,y) set_64(x,y)
-#define memcpy_to_sl(d,s,l) memcpy(d,s,l)
-#define memcpy_from_sl(d,s,l) memcpy(d,s,l)
-#define memset_sl(d,c,l) memset(d,c,l)
+static inline uint8_t get_8_sl(const uint8_t _slimg * p)
+{
+ return get_8((const uint8_t _force *)p);
+}
+static inline uint16_t get_16_sl(const uint16_t _slimg * p)
+{
+ return get_16((const uint16_t _force *)p);
+}
+static inline uint32_t get_32_sl(const uint32_t _slimg * p)
+{
+ return get_32((const uint32_t _force *)p);
+}
+static inline uint64_t get_64_sl(const uint64_t _slimg * p)
+{
+ return get_64((const uint64_t _force *)p);
+}
+static inline void set_8_sl(uint8_t _slimg * p, uint8_t v)
+{
+ set_8((uint8_t _force *)p, v);
+}
+static inline void set_16_sl(uint16_t _slimg * p, uint16_t v)
+{
+ set_16((uint16_t _force *)p, v);
+}
+static inline void set_32_sl(uint32_t _slimg * p, uint32_t v)
+{
+ set_32((uint32_t _force *)p, v);
+}
+static inline void set_64_sl(uint64_t _slimg * p, uint64_t v)
+{
+ set_64((uint64_t _force *)p, v);
+}
+static inline void memcpy_to_sl(void _slimg *dst, const void *src, size_t len)
+{
+ memcpy((void _force *)dst, src, len);
+}
+static inline void memcpy_from_sl(void *dst, const void _slimg *src, size_t len)
+{
+ memcpy(dst, (const void _force *)src, len);
+}
+static inline void memset_sl(void _slimg *dst, int c, size_t len)
+{
+ memset((void _force *)dst, c, len);
+}
#endif
diff --git a/libinstaller/syslxmod.c b/libinstaller/syslxmod.c
index 197261ca..cc6e56a2 100644
--- a/libinstaller/syslxmod.c
+++ b/libinstaller/syslxmod.c
@@ -1,7 +1,7 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1998-2008 H. Peter Anvin - All Rights Reserved
- * Copyright 2009-2010 Intel Corporation; author H. Peter Anvin
+ * Copyright 2009-2014 Intel Corporation; author H. Peter Anvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,7 +30,7 @@
/*
* Generate sector extents
*/
-static void generate_extents(struct syslinux_extent *ex, int nptrs,
+static void generate_extents(struct syslinux_extent _slimg *ex, int nptrs,
const sector_t *sectp, int nsect)
{
uint32_t addr = 0x8000; /* ldlinux.sys starts loading here */
@@ -80,10 +80,15 @@ static void generate_extents(struct syslinux_extent *ex, int nptrs,
/*
* Form a pointer based on a 16-bit patcharea/epa field
*/
-static inline void *ptr(void *img, uint16_t *offset_p)
+static inline void *ptr(void *img, const uint16_t _slimg *offset_p)
{
return (char *)img + get_16_sl(offset_p);
}
+static inline void _slimg *slptr(void _slimg *img,
+ const uint16_t _slimg *offset_p)
+{
+ return (char _slimg *)img + get_16_sl(offset_p);
+}
/*
* This patches the boot sector and the beginning of ldlinux.sys
@@ -100,25 +105,26 @@ int syslinux_patch(const sector_t *sectp, int nsectors,
int stupid, int raid_mode,
const char *subdir, const char *subvol)
{
- struct patch_area *patcharea;
- struct ext_patch_area *epa;
- struct syslinux_extent *ex;
- uint32_t *wp;
+ struct patch_area _slimg *patcharea;
+ struct ext_patch_area _slimg *epa;
+ struct syslinux_extent _slimg *ex;
+ const uint32_t _slimg *wp;
int nsect = ((boot_image_len + SECTOR_SIZE - 1) >> SECTOR_SHIFT) + 2;
uint32_t csum;
int i, dw, nptrs;
struct fat_boot_sector *sbs = (struct fat_boot_sector *)boot_sector;
- uint64_t *advptrs;
+ uint64_t _slimg *advptrs;
if (nsectors < nsect)
return -1; /* The actual file is too small for content */
/* Search for LDLINUX_MAGIC to find the patch area */
- for (wp = (uint32_t *)boot_image; get_32_sl(wp) != LDLINUX_MAGIC;
+ for (wp = (const uint32_t _slimg *)boot_image;
+ get_32_sl(wp) != LDLINUX_MAGIC;
wp++)
;
- patcharea = (struct patch_area *)wp;
- epa = ptr(boot_image, &patcharea->epaoffset);
+ patcharea = (struct patch_area _slimg *)wp;
+ epa = slptr(boot_image, &patcharea->epaoffset);
/* First sector need pointer in boot sector */
set_32(ptr(sbs, &epa->sect1ptr0), sectp[0]);
@@ -144,7 +150,7 @@ int syslinux_patch(const sector_t *sectp, int nsectors,
}
/* Set the sector extents */
- ex = ptr(boot_image, &epa->secptroffset);
+ ex = slptr(boot_image, &epa->secptroffset);
nptrs = get_16_sl(&epa->secptrcnt);
#if 0
@@ -159,7 +165,7 @@ int syslinux_patch(const sector_t *sectp, int nsectors,
generate_extents(ex, nptrs, sectp, nsect-1-2);
/* ADV pointers */
- advptrs = ptr(boot_image, &epa->advptroffset);
+ advptrs = slptr(boot_image, &epa->advptroffset);
set_64_sl(&advptrs[0], sectp[nsect-1-2]);
set_64_sl(&advptrs[1], sectp[nsect-1-1]);
@@ -170,7 +176,7 @@ int syslinux_patch(const sector_t *sectp, int nsectors,
fprintf(stderr, "Subdirectory path too long... aborting install!\n");
exit(1);
}
- memcpy_to_sl(ptr(boot_image, &epa->diroffset), subdir, sublen);
+ memcpy_to_sl(slptr(boot_image, &epa->diroffset), subdir, sublen);
}
/* Poke in the subvolume information */
@@ -180,14 +186,14 @@ int syslinux_patch(const sector_t *sectp, int nsectors,
fprintf(stderr, "Subvol name too long... aborting install!\n");
exit(1);
}
- memcpy_to_sl(ptr(boot_image, &epa->subvoloffset), subvol, sublen);
+ memcpy_to_sl(slptr(boot_image, &epa->subvoloffset), subvol, sublen);
}
/* Now produce a checksum */
set_32_sl(&patcharea->checksum, 0);
csum = LDLINUX_MAGIC;
- for (i = 0, wp = (uint32_t *)boot_image; i < dw; i++, wp++)
+ for (i = 0, wp = (const uint32_t _slimg *)boot_image; i < dw; i++, wp++)
csum -= get_32_sl(wp); /* Negative checksum */
set_32_sl(&patcharea->checksum, csum);
diff --git a/linux/syslinux.c b/linux/syslinux.c
index f64834bd..912de71f 100755
--- a/linux/syslinux.c
+++ b/linux/syslinux.c
@@ -433,7 +433,8 @@ int main(int argc, char *argv[])
}
/* Write it the first time */
- if (xpwrite(fd, boot_image, boot_image_len, 0) != (int)boot_image_len ||
+ if (xpwrite(fd, (const char _force *)boot_image, boot_image_len, 0)
+ != (int)boot_image_len ||
xpwrite(fd, syslinux_adv, 2 * ADV_SIZE,
boot_image_len) != 2 * ADV_SIZE) {
fprintf(stderr, "%s: write failure on %s\n", program, ldlinux_name);
@@ -468,7 +469,8 @@ int main(int argc, char *argv[])
goto umount;
}
- rv = xpwrite(fd, syslinux_ldlinuxc32, syslinux_ldlinuxc32_len, 0);
+ rv = xpwrite(fd, (const char _force *)syslinux_ldlinuxc32,
+ syslinux_ldlinuxc32_len, 0);
if (rv != (int)syslinux_ldlinuxc32_len) {
fprintf(stderr, "%s: write failure on %s\n", program, ldlinux_name);
exit(1);
@@ -505,7 +507,9 @@ umount:
* Write the now-patched first sectors of ldlinux.sys
*/
for (i = 0; i < patch_sectors; i++) {
- xpwrite(dev_fd, boot_image + i * SECTOR_SIZE, SECTOR_SIZE,
+ xpwrite(dev_fd,
+ (const char _force *)boot_image + i * SECTOR_SIZE,
+ SECTOR_SIZE,
opt.offset + ((off_t) sectors[i] << SECTOR_SHIFT));
}
diff --git a/mtools/syslinux.c b/mtools/syslinux.c
index f43b5a5e..59244307 100755
--- a/mtools/syslinux.c
+++ b/mtools/syslinux.c
@@ -303,9 +303,11 @@ int main(int argc, char *argv[])
mtp = popen("mcopy -D o -D O -o - s:/ldlinux.sys", "w");
if (!mtp ||
- fwrite(syslinux_ldlinux, 1, syslinux_ldlinux_len, mtp)
+ fwrite((const void _force *)syslinux_ldlinux,
+ 1, syslinux_ldlinux_len, mtp)
!= syslinux_ldlinux_len ||
- fwrite(syslinux_adv, 1, 2 * ADV_SIZE, mtp)
+ fwrite((const void _force *)syslinux_adv,
+ 1, 2 * ADV_SIZE, mtp)
!= 2 * ADV_SIZE ||
(status = pclose(mtp), !WIFEXITED(status) || WEXITSTATUS(status))) {
die("failed to create ldlinux.sys");
@@ -336,7 +338,8 @@ int main(int argc, char *argv[])
/* Write the now-patched first sectors of ldlinux.sys */
for (i = 0; i < patch_sectors; i++) {
- xpwrite(dev_fd, syslinux_ldlinux + i * SECTOR_SIZE, SECTOR_SIZE,
+ xpwrite(dev_fd, (const char _force *)syslinux_ldlinux
+ + i * SECTOR_SIZE, SECTOR_SIZE,
opt.offset + ((off_t) sectors[i] << SECTOR_SHIFT));
}
@@ -358,7 +361,8 @@ int main(int argc, char *argv[])
(void)status; /* Keep _FORTIFY_SOURCE happy */
mtp = popen("mcopy -D o -D O -o - s:/ldlinux.c32", "w");
- if (!mtp || fwrite(syslinux_ldlinuxc32, 1, syslinux_ldlinuxc32_len, mtp)
+ if (!mtp || fwrite((const char _force *)syslinux_ldlinuxc32,
+ 1, syslinux_ldlinuxc32_len, mtp)
!= syslinux_ldlinuxc32_len ||
(status = pclose(mtp), !WIFEXITED(status) || WEXITSTATUS(status))) {
die("failed to create ldlinux.c32");
diff --git a/win/syslinux.c b/win/syslinux.c
index c291f005..639844e7 100644
--- a/win/syslinux.c
+++ b/win/syslinux.c
@@ -416,8 +416,8 @@ int main(int argc, char *argv[])
}
/* Write ldlinux.sys file */
- if (!WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len,
- &bytes_written, NULL) ||
+ if (!WriteFile(f_handle, (const char _force *)syslinux_ldlinux,
+ syslinux_ldlinux_len, &bytes_written, NULL) ||
bytes_written != syslinux_ldlinux_len) {
error("Could not write ldlinux.sys");
exit(1);
@@ -533,8 +533,8 @@ map_done:
}
/* Write ldlinux.c32 file */
- if (!WriteFile(f_handle, syslinux_ldlinuxc32, syslinux_ldlinuxc32_len,
- &bytes_written, NULL) ||
+ if (!WriteFile(f_handle, (const char _force *)syslinux_ldlinuxc32,
+ syslinux_ldlinuxc32_len, &bytes_written, NULL) ||
bytes_written != syslinux_ldlinuxc32_len) {
error("Could not write ldlinux.c32");
exit(1);