* grub-core/fs/zfs/zfs.c (dmu_read): Use void * for some pointers to

avoid aliasing.
	(fzap_lookup): Likewise.
	(dnode_get): Likewise.
	(make_mdn): Likewise.
	(zfs_mount): Likewise.
	(fzap_iterate): Use temporary pointer to avoid aliasing.
	(grub_zfs_read): Likewise.
	* grub-core/loader/i386/xnu.c (grub_xnu_boot): Likewise.
	* grub-core/loader/xnu.c (grub_cmd_xnu_kernel): Use void * for some
	pointers to avoid aliasing.
	(grub_cmd_xnu_kernel64): Likewise.
	(grub_xnu_load_driver): Likewise.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-01-08 01:56:09 +01:00
parent fc836af9a5
commit e7121b6932
4 changed files with 63 additions and 33 deletions

View file

@ -1,3 +1,19 @@
2011-01-08 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/zfs/zfs.c (dmu_read): Use void * for some pointers to
avoid aliasing.
(fzap_lookup): Likewise.
(dnode_get): Likewise.
(make_mdn): Likewise.
(zfs_mount): Likewise.
(fzap_iterate): Use temporary pointer to avoid aliasing.
(grub_zfs_read): Likewise.
* grub-core/loader/i386/xnu.c (grub_xnu_boot): Likewise.
* grub-core/loader/xnu.c (grub_cmd_xnu_kernel): Use void * for some
pointers to avoid aliasing.
(grub_cmd_xnu_kernel64): Likewise.
(grub_xnu_load_driver): Likewise.
2011-01-08 Vladimir Serbinenko <phcoder@gmail.com> 2011-01-08 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/terminal.c (grub_cmd_terminal_input): Silence * grub-core/commands/terminal.c (grub_cmd_terminal_input): Silence

View file

@ -603,7 +603,8 @@ dmu_read (dnode_end_t * dn, grub_uint64_t blkid, void **buf,
int idx, level; int idx, level;
blkptr_t *bp_array = dn->dn.dn_blkptr; blkptr_t *bp_array = dn->dn.dn_blkptr;
int epbs = dn->dn.dn_indblkshift - SPA_BLKPTRSHIFT; int epbs = dn->dn.dn_indblkshift - SPA_BLKPTRSHIFT;
blkptr_t *bp, *tmpbuf = 0; blkptr_t *bp;
void *tmpbuf = 0;
grub_zfs_endian_t endian; grub_zfs_endian_t endian;
grub_err_t err = GRUB_ERR_NONE; grub_err_t err = GRUB_ERR_NONE;
@ -646,7 +647,7 @@ dmu_read (dnode_end_t * dn, grub_uint64_t blkid, void **buf,
break; break;
} }
grub_dprintf ("zfs", "endian = %d\n", endian); grub_dprintf ("zfs", "endian = %d\n", endian);
err = zio_read (bp, endian, (void **) &tmpbuf, 0, data); err = zio_read (bp, endian, &tmpbuf, 0, data);
endian = (grub_zfs_to_cpu64 (bp->blk_prop, endian) >> 63) & 1; endian = (grub_zfs_to_cpu64 (bp->blk_prop, endian) >> 63) & 1;
if (err) if (err)
break; break;
@ -880,7 +881,7 @@ static grub_err_t
fzap_lookup (dnode_end_t * zap_dnode, zap_phys_t * zap, fzap_lookup (dnode_end_t * zap_dnode, zap_phys_t * zap,
char *name, grub_uint64_t * value, struct grub_zfs_data *data) char *name, grub_uint64_t * value, struct grub_zfs_data *data)
{ {
zap_leaf_phys_t *l; void *l;
grub_uint64_t hash, idx, blkid; grub_uint64_t hash, idx, blkid;
int blksft = zfs_log2 (grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec, int blksft = zfs_log2 (grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec,
zap_dnode->endian) << DNODE_SHIFT); zap_dnode->endian) << DNODE_SHIFT);
@ -903,7 +904,7 @@ fzap_lookup (dnode_end_t * zap_dnode, zap_phys_t * zap,
/* Get the leaf block */ /* Get the leaf block */
if ((1U << blksft) < sizeof (zap_leaf_phys_t)) if ((1U << blksft) < sizeof (zap_leaf_phys_t))
return grub_error (GRUB_ERR_BAD_FS, "ZAP leaf is too small"); return grub_error (GRUB_ERR_BAD_FS, "ZAP leaf is too small");
err = dmu_read (zap_dnode, blkid, (void **) &l, &leafendian, data); err = dmu_read (zap_dnode, blkid, &l, &leafendian, data);
if (err) if (err)
return err; return err;
@ -920,6 +921,7 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap,
struct grub_zfs_data *data) struct grub_zfs_data *data)
{ {
zap_leaf_phys_t *l; zap_leaf_phys_t *l;
void *l_in;
grub_uint64_t idx, blkid; grub_uint64_t idx, blkid;
grub_uint16_t chunk; grub_uint16_t chunk;
int blksft = zfs_log2 (grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec, int blksft = zfs_log2 (grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec,
@ -947,7 +949,8 @@ fzap_iterate (dnode_end_t * zap_dnode, zap_phys_t * zap,
{ {
blkid = ((grub_uint64_t *) zap)[idx + (1 << (blksft - 3 - 1))]; blkid = ((grub_uint64_t *) zap)[idx + (1 << (blksft - 3 - 1))];
err = dmu_read (zap_dnode, blkid, (void **) &l, &endian, data); err = dmu_read (zap_dnode, blkid, &l_in, &endian, data);
l = l_in;
if (err) if (err)
{ {
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
@ -1108,7 +1111,7 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type,
grub_uint64_t blkid, blksz; /* the block id this object dnode is in */ grub_uint64_t blkid, blksz; /* the block id this object dnode is in */
int epbs; /* shift of number of dnodes in a block */ int epbs; /* shift of number of dnodes in a block */
int idx; /* index within a block */ int idx; /* index within a block */
dnode_phys_t *dnbuf; void *dnbuf;
grub_err_t err; grub_err_t err;
grub_zfs_endian_t endian; grub_zfs_endian_t endian;
@ -1131,7 +1134,7 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type,
grub_dprintf ("zfs", "endian = %d, blkid=%llx\n", mdn->endian, grub_dprintf ("zfs", "endian = %d, blkid=%llx\n", mdn->endian,
(unsigned long long) blkid); (unsigned long long) blkid);
err = dmu_read (mdn, blkid, (void **) &dnbuf, &endian, data); err = dmu_read (mdn, blkid, &dnbuf, &endian, data);
if (err) if (err)
return err; return err;
grub_dprintf ("zfs", "alive\n"); grub_dprintf ("zfs", "alive\n");
@ -1153,7 +1156,7 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type,
data->dnode_endian = endian; data->dnode_endian = endian;
} }
grub_memmove (&(buf->dn), &dnbuf[idx], DNODE_SIZE); grub_memmove (&(buf->dn), (dnode_phys_t *) dnbuf + idx, DNODE_SIZE);
buf->endian = endian; buf->endian = endian;
if (type && buf->dn.dn_type != type) if (type && buf->dn.dn_type != type)
return grub_error(GRUB_ERR_BAD_FS, "incorrect dnode type"); return grub_error(GRUB_ERR_BAD_FS, "incorrect dnode type");
@ -1465,7 +1468,7 @@ get_filesystem_dnode (dnode_end_t * mosmdn, char *fsname,
static grub_err_t static grub_err_t
make_mdn (dnode_end_t * mdn, struct grub_zfs_data *data) make_mdn (dnode_end_t * mdn, struct grub_zfs_data *data)
{ {
objset_phys_t *osp; void *osp;
blkptr_t *bp; blkptr_t *bp;
grub_size_t ospsize; grub_size_t ospsize;
grub_err_t err; grub_err_t err;
@ -1473,7 +1476,7 @@ make_mdn (dnode_end_t * mdn, struct grub_zfs_data *data)
grub_dprintf ("zfs", "endian = %d\n", mdn->endian); grub_dprintf ("zfs", "endian = %d\n", mdn->endian);
bp = &(((dsl_dataset_phys_t *) DN_BONUS (&mdn->dn))->ds_bp); bp = &(((dsl_dataset_phys_t *) DN_BONUS (&mdn->dn))->ds_bp);
err = zio_read (bp, mdn->endian, (void **) &osp, &ospsize, data); err = zio_read (bp, mdn->endian, &osp, &ospsize, data);
if (err) if (err)
return err; return err;
if (ospsize < OBJSET_PHYS_SIZE_V14) if (ospsize < OBJSET_PHYS_SIZE_V14)
@ -1483,7 +1486,8 @@ make_mdn (dnode_end_t * mdn, struct grub_zfs_data *data)
} }
mdn->endian = (grub_zfs_to_cpu64 (bp->blk_prop, mdn->endian)>>63) & 1; mdn->endian = (grub_zfs_to_cpu64 (bp->blk_prop, mdn->endian)>>63) & 1;
grub_memmove ((char *) &(mdn->dn), (char *) &osp->os_meta_dnode, DNODE_SIZE); grub_memmove ((char *) &(mdn->dn),
(char *) &((objset_phys_t *) osp)->os_meta_dnode, DNODE_SIZE);
grub_free (osp); grub_free (osp);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -1960,7 +1964,7 @@ zfs_mount (grub_device_t dev)
int label = 0; int label = 0;
uberblock_phys_t *ub_array, *ubbest = NULL; uberblock_phys_t *ub_array, *ubbest = NULL;
vdev_boot_header_t *bh; vdev_boot_header_t *bh;
objset_phys_t *osp = 0; void *osp = 0;
grub_size_t ospsize; grub_size_t ospsize;
grub_err_t err; grub_err_t err;
int vdevnum; int vdevnum;
@ -2038,7 +2042,7 @@ zfs_mount (grub_device_t dev)
? LITTLE_ENDIAN : BIG_ENDIAN); ? LITTLE_ENDIAN : BIG_ENDIAN);
err = zio_read (&ubbest->ubp_uberblock.ub_rootbp, err = zio_read (&ubbest->ubp_uberblock.ub_rootbp,
ub_endian, ub_endian,
(void **) &osp, &ospsize, data); &osp, &ospsize, data);
if (err) if (err)
{ {
grub_dprintf ("zfs", "couldn't zio_read\n"); grub_dprintf ("zfs", "couldn't zio_read\n");
@ -2067,7 +2071,8 @@ zfs_mount (grub_device_t dev)
continue; continue;
#endif #endif
/* Got the MOS. Save it at the memory addr MOS. */ /* Got the MOS. Save it at the memory addr MOS. */
grub_memmove (&(data->mos.dn), &osp->os_meta_dnode, DNODE_SIZE); grub_memmove (&(data->mos.dn), &((objset_phys_t *) osp)->os_meta_dnode,
DNODE_SIZE);
data->mos.endian = (grub_zfs_to_cpu64 (ubbest->ubp_uberblock.ub_rootbp.blk_prop, ub_endian) >> 63) & 1; data->mos.endian = (grub_zfs_to_cpu64 (ubbest->ubp_uberblock.ub_rootbp.blk_prop, ub_endian) >> 63) & 1;
grub_memmove (&(data->current_uberblock), grub_memmove (&(data->current_uberblock),
&ubbest->ubp_uberblock, sizeof (uberblock_t)); &ubbest->ubp_uberblock, sizeof (uberblock_t));
@ -2201,7 +2206,7 @@ grub_zfs_open (struct grub_file *file, const char *fsfilename)
*/ */
if (data->dnode.dn.dn_bonustype == DMU_OT_SA) if (data->dnode.dn.dn_bonustype == DMU_OT_SA)
{ {
sa_hdr_phys_t *sahdrp; void *sahdrp;
int hdrsize; int hdrsize;
if (data->dnode.dn.dn_bonuslen != 0) if (data->dnode.dn.dn_bonuslen != 0)
@ -2212,7 +2217,7 @@ grub_zfs_open (struct grub_file *file, const char *fsfilename)
{ {
blkptr_t *bp = &data->dnode.dn.dn_spill; blkptr_t *bp = &data->dnode.dn.dn_spill;
err = zio_read (bp, data->dnode.endian, (void **) &sahdrp, NULL, data); err = zio_read (bp, data->dnode.endian, &sahdrp, NULL, data);
if (err) if (err)
return err; return err;
} }
@ -2221,7 +2226,7 @@ grub_zfs_open (struct grub_file *file, const char *fsfilename)
return grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt"); return grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt");
} }
hdrsize = SA_HDR_SIZE (sahdrp); hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp));
file->size = *(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET); file->size = *(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET);
} }
else else
@ -2280,6 +2285,7 @@ grub_zfs_read (grub_file_t file, char *buf, grub_size_t len)
read = 0; read = 0;
while (length) while (length)
{ {
void *t;
/* /*
* Find requested blkid and the offset within that block. * Find requested blkid and the offset within that block.
*/ */
@ -2287,8 +2293,9 @@ grub_zfs_read (grub_file_t file, char *buf, grub_size_t len)
grub_free (data->file_buf); grub_free (data->file_buf);
data->file_buf = 0; data->file_buf = 0;
err = dmu_read (&(data->dnode), blkid, (void **) &(data->file_buf), err = dmu_read (&(data->dnode), blkid, &t,
0, data); 0, data);
data->file_buf = t;
if (err) if (err)
return -1; return -1;

View file

@ -951,10 +951,11 @@ grub_err_t
grub_xnu_boot (void) grub_xnu_boot (void)
{ {
struct grub_xnu_boot_params *bootparams; struct grub_xnu_boot_params *bootparams;
void *bp_in;
grub_addr_t bootparams_target; grub_addr_t bootparams_target;
grub_err_t err; grub_err_t err;
grub_efi_uintn_t memory_map_size = 0; grub_efi_uintn_t memory_map_size = 0;
grub_efi_memory_descriptor_t *memory_map; void *memory_map;
grub_addr_t memory_map_target; grub_addr_t memory_map_target;
grub_efi_uintn_t map_key = 0; grub_efi_uintn_t map_key = 0;
grub_efi_uintn_t descriptor_size = 0; grub_efi_uintn_t descriptor_size = 0;
@ -1006,9 +1007,10 @@ grub_xnu_boot (void)
/* Relocate the boot parameters to heap. */ /* Relocate the boot parameters to heap. */
err = grub_xnu_heap_malloc (sizeof (*bootparams), err = grub_xnu_heap_malloc (sizeof (*bootparams),
(void **) &bootparams, &bootparams_target); &bp_in, &bootparams_target);
if (err) if (err)
return err; return err;
bootparams = bp_in;
/* Set video. */ /* Set video. */
err = grub_xnu_set_video (bootparams); err = grub_xnu_set_video (bootparams);
@ -1035,7 +1037,7 @@ grub_xnu_boot (void)
memory map growth. */ memory map growth. */
memory_map_size += 20 * descriptor_size; memory_map_size += 20 * descriptor_size;
err = grub_xnu_heap_malloc (memory_map_size, err = grub_xnu_heap_malloc (memory_map_size,
(void **) &memory_map, &memory_map_target); &memory_map, &memory_map_target);
if (err) if (err)
return err; return err;
@ -1109,7 +1111,7 @@ grub_xnu_boot (void)
grub_xnu_arg1 = bootparams_target; grub_xnu_arg1 = bootparams_target;
grub_autoefi_set_virtual_address_map (memory_map_size, descriptor_size, grub_autoefi_set_virtual_address_map (memory_map_size, descriptor_size,
descriptor_version,memory_map); descriptor_version, memory_map);
state.eip = grub_xnu_entry_point; state.eip = grub_xnu_entry_point;
state.eax = grub_xnu_arg1; state.eax = grub_xnu_arg1;

View file

@ -342,7 +342,8 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
grub_macho_t macho; grub_macho_t macho;
grub_uint32_t startcode, endcode; grub_uint32_t startcode, endcode;
int i; int i;
char *ptr, *loadaddr; char *ptr;
void *loadaddr;
grub_addr_t loadaddr_target; grub_addr_t loadaddr_target;
if (argc < 1) if (argc < 1)
@ -375,7 +376,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
if (!grub_xnu_relocator) if (!grub_xnu_relocator)
return grub_errno; return grub_errno;
grub_xnu_heap_target_start = startcode; grub_xnu_heap_target_start = startcode;
err = grub_xnu_heap_malloc (endcode - startcode, (void **) &loadaddr, err = grub_xnu_heap_malloc (endcode - startcode, &loadaddr,
&loadaddr_target); &loadaddr_target);
if (err) if (err)
@ -386,7 +387,8 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
} }
/* Load kernel. */ /* Load kernel. */
err = grub_macho_load32 (macho, loadaddr - startcode, GRUB_MACHO_NOBSS); err = grub_macho_load32 (macho, (char *) loadaddr - startcode,
GRUB_MACHO_NOBSS);
if (err) if (err)
{ {
grub_macho_close (macho); grub_macho_close (macho);
@ -450,7 +452,8 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
grub_macho_t macho; grub_macho_t macho;
grub_uint64_t startcode, endcode; grub_uint64_t startcode, endcode;
int i; int i;
char *ptr, *loadaddr; char *ptr;
void *loadaddr;
grub_addr_t loadaddr_target; grub_addr_t loadaddr_target;
if (argc < 1) if (argc < 1)
@ -486,7 +489,7 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
if (!grub_xnu_relocator) if (!grub_xnu_relocator)
return grub_errno; return grub_errno;
grub_xnu_heap_target_start = startcode; grub_xnu_heap_target_start = startcode;
err = grub_xnu_heap_malloc (endcode - startcode, (void **) &loadaddr, err = grub_xnu_heap_malloc (endcode - startcode, &loadaddr,
&loadaddr_target); &loadaddr_target);
if (err) if (err)
@ -497,7 +500,8 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
} }
/* Load kernel. */ /* Load kernel. */
err = grub_macho_load64 (macho, loadaddr - startcode, GRUB_MACHO_NOBSS); err = grub_macho_load64 (macho, (char *) loadaddr - startcode,
GRUB_MACHO_NOBSS);
if (err) if (err)
{ {
grub_macho_close (macho); grub_macho_close (macho);
@ -636,7 +640,8 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
grub_file_t infoplist; grub_file_t infoplist;
struct grub_xnu_extheader *exthead; struct grub_xnu_extheader *exthead;
int neededspace = sizeof (*exthead); int neededspace = sizeof (*exthead);
grub_uint8_t *buf, *buf0; grub_uint8_t *buf;
void *buf0;
grub_addr_t buf_target; grub_addr_t buf_target;
grub_size_t infoplistsize = 0, machosize = 0; grub_size_t infoplistsize = 0, machosize = 0;
char *name, *nameend; char *name, *nameend;
@ -692,7 +697,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE); err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
if (err) if (err)
return err; return err;
err = grub_xnu_heap_malloc (neededspace, (void **) &buf0, &buf_target); err = grub_xnu_heap_malloc (neededspace, &buf0, &buf_target);
if (err) if (err)
return err; return err;
buf = buf0; buf = buf0;
@ -704,7 +709,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
/* Load the binary. */ /* Load the binary. */
if (macho) if (macho)
{ {
exthead->binaryaddr = buf_target + (buf - buf0); exthead->binaryaddr = buf_target + (buf - (grub_uint8_t *) buf0);
exthead->binarysize = machosize; exthead->binarysize = machosize;
if (grub_xnu_is_64bit) if (grub_xnu_is_64bit)
err = grub_macho_readfile64 (macho, buf); err = grub_macho_readfile64 (macho, buf);
@ -723,7 +728,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
/* Load the plist. */ /* Load the plist. */
if (infoplist) if (infoplist)
{ {
exthead->infoplistaddr = buf_target + (buf - buf0); exthead->infoplistaddr = buf_target + (buf - (grub_uint8_t *) buf0);
exthead->infoplistsize = infoplistsize + 1; exthead->infoplistsize = infoplistsize + 1;
if (grub_file_read (infoplist, buf, infoplistsize) if (grub_file_read (infoplist, buf, infoplistsize)
!= (grub_ssize_t) (infoplistsize)) != (grub_ssize_t) (infoplistsize))
@ -739,7 +744,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
} }
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
exthead->nameaddr = (buf - buf0) + buf_target; exthead->nameaddr = (buf - (grub_uint8_t *) buf0) + buf_target;
exthead->namesize = namelen + 1; exthead->namesize = namelen + 1;
grub_memcpy (buf, name, namelen); grub_memcpy (buf, name, namelen);
buf[namelen] = 0; buf[namelen] = 0;