* include/grub/types.h (grub_properly_aligned_t): New type.

(GRUB_PROPERLY_ALIGNED_ARRAY): New macro.
	(grub_get_unaligned16): Add explicit casts.
	(grub_get_unaligned32): Likewise.
	(grub_get_unaligned64): Likewise.
	(grub_set_unaligned16): New function.
	(grub_set_unaligned32): Likewise.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-12-13 01:54:59 +01:00
parent 47ae27ec75
commit 1f313b942b
2 changed files with 58 additions and 18 deletions

View file

@ -1,3 +1,13 @@
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/types.h (grub_properly_aligned_t): New type.
(GRUB_PROPERLY_ALIGNED_ARRAY): New macro.
(grub_get_unaligned16): Add explicit casts.
(grub_get_unaligned32): Likewise.
(grub_get_unaligned64): Likewise.
(grub_set_unaligned16): New function.
(grub_set_unaligned32): Likewise.
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com> 2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/datetime.c (grub_weekday_names): Make const. * grub-core/normal/datetime.c (grub_weekday_names): Make const.

View file

@ -140,6 +140,10 @@ typedef grub_int32_t grub_ssize_t;
#define PTR_TO_UINT32(x) ((grub_uint32_t)(grub_uint64_t)(x)) #define PTR_TO_UINT32(x) ((grub_uint32_t)(grub_uint64_t)(x))
#endif #endif
typedef grub_uint64_t grub_properly_aligned_t;
#define GRUB_PROPERLY_ALIGNED_ARRAY(name, size) grub_properly_aligned_t name[(size + sizeof (grub_properly_aligned_t) - 1) / sizeof (grub_properly_aligned_t)]
/* The type for representing a file offset. */ /* The type for representing a file offset. */
typedef grub_uint64_t grub_off_t; typedef grub_uint64_t grub_off_t;
@ -222,30 +226,56 @@ static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t x)
# define grub_cpu_to_le32_compile_time(x) ((grub_uint32_t) (x)) # define grub_cpu_to_le32_compile_time(x) ((grub_uint32_t) (x))
#endif /* ! WORDS_BIGENDIAN */ #endif /* ! WORDS_BIGENDIAN */
static inline grub_uint16_t grub_get_unaligned16(void *ptr) static inline grub_uint16_t grub_get_unaligned16 (const void *ptr)
{ {
struct struct grub_unaligned_uint16_t
{ {
grub_uint16_t d; grub_uint16_t d;
} __attribute__((packed)) *dd = ptr; } __attribute__ ((packed));
const struct grub_unaligned_uint16_t *dd
= (const struct grub_unaligned_uint16_t *) ptr;
return dd->d; return dd->d;
} }
static inline grub_uint32_t grub_get_unaligned32(void *ptr) static inline void grub_set_unaligned16 (void *ptr, grub_uint16_t val)
{ {
struct struct grub_unaligned_uint16_t
{
grub_uint16_t d;
} __attribute__ ((packed));
struct grub_unaligned_uint16_t *dd = (struct grub_unaligned_uint16_t *) ptr;
dd->d = val;
}
static inline grub_uint32_t grub_get_unaligned32 (const void *ptr)
{
struct grub_unaligned_uint32_t
{ {
grub_uint32_t d; grub_uint32_t d;
} __attribute__((packed)) *dd = ptr; } __attribute__ ((packed));
const struct grub_unaligned_uint32_t *dd
= (const struct grub_unaligned_uint32_t *) ptr;
return dd->d; return dd->d;
} }
static inline grub_uint64_t grub_get_unaligned64(void *ptr) static inline void grub_set_unaligned32 (void *ptr, grub_uint32_t val)
{ {
struct struct grub_unaligned_uint32_t
{
grub_uint32_t d;
} __attribute__ ((packed));
struct grub_unaligned_uint32_t *dd = (struct grub_unaligned_uint32_t *) ptr;
dd->d = val;
}
static inline grub_uint64_t grub_get_unaligned64 (const void *ptr)
{
struct grub_unaligned_uint64_t
{ {
grub_uint64_t d; grub_uint64_t d;
} __attribute__((packed)) *dd = ptr; } __attribute__ ((packed));
const struct grub_unaligned_uint64_t *dd
= (const struct grub_unaligned_uint64_t *)ptr;
return dd->d; return dd->d;
} }