compat32: provide a type and a macro for (u)int64_t handling on non-x86 arches
uint64_t is 4-byte aligned on i386, but is 8-bytes aligned on all other 32bit arches FreeBSD supports. Provide the freebsd32_uint64_t type and the FU64_CP() macro, which are intended to be used where 32bit ABI uses (u)int64_t type, and do proper layout and copying for the aggregate type. Reviewed by: des, emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54663
This commit is contained in:
@@ -36,8 +36,17 @@
|
||||
#include <sys/_ffcounter.h>
|
||||
|
||||
/*
|
||||
* i386 is the only arch with a 32-bit time_t
|
||||
* i386 is the only arch with a 32-bit time_t.
|
||||
* Also it is the only arch with (u)int64_t having 4-bytes alignment.
|
||||
*/
|
||||
typedef struct {
|
||||
#ifdef __amd64__
|
||||
uint32_t val[2];
|
||||
#else
|
||||
uint64_t val;
|
||||
#endif
|
||||
} freebsd32_uint64_t;
|
||||
|
||||
#ifdef __amd64__
|
||||
typedef int32_t time32_t;
|
||||
#else
|
||||
|
||||
@@ -67,6 +67,14 @@
|
||||
TS_CP((src), (dst), it_value); \
|
||||
} while (0)
|
||||
|
||||
#define FU64_CP(src, dst, fld) do { \
|
||||
_Static_assert(sizeof((src).fld) == sizeof(uint64_t), \
|
||||
"FU64_CP src: " #src "." #fld "is not 8 bytes"); \
|
||||
_Static_assert(sizeof((dst).fld) == sizeof(uint64_t), \
|
||||
"FU64_CP dst: " #dst "." #fld "is not 8 bytes"); \
|
||||
memcpy(&(dst).fld, &(src).fld, sizeof(uint64_t)); \
|
||||
} while (0)
|
||||
|
||||
#define BT_CP(src, dst, fld) do { \
|
||||
CP((src).fld, (dst).fld, sec); \
|
||||
*(uint64_t *)&(dst).fld.frac[0] = (src).fld.frac; \
|
||||
|
||||
Reference in New Issue
Block a user