return 0;
}
+static bool ptr_is_aligned(const void *data, int data_sz)
+{
+ return ((uintptr_t)data) % data_sz == 0;
+}
+
static int btf_dump_int_data(struct btf_dump *d,
const struct btf_type *t,
__u32 type_id,
/* handle packed int data - accesses of integers not aligned on
* int boundaries can cause problems on some platforms.
*/
- if (((uintptr_t)data) % sz)
+ if (!ptr_is_aligned(data, sz))
return btf_dump_bitfield_data(d, t, data, 0, 0);
switch (sz) {
int sz = t->size;
/* handle unaligned data; copy to local union */
- if (((uintptr_t)data) % sz) {
+ if (!ptr_is_aligned(data, sz)) {
memcpy(&fl, data, sz);
flp = &fl;
}
return err;
}
+union ptr_data {
+ unsigned int p;
+ unsigned long long lp;
+};
+
static int btf_dump_ptr_data(struct btf_dump *d,
const struct btf_type *t,
__u32 id,
const void *data)
{
- btf_dump_type_values(d, "%p", *(void **)data);
+ if (ptr_is_aligned(data, d->ptr_sz) && d->ptr_sz == sizeof(void *)) {
+ btf_dump_type_values(d, "%p", *(void **)data);
+ } else {
+ union ptr_data pt;
+
+ memcpy(&pt, data, d->ptr_sz);
+ if (d->ptr_sz == 4)
+ btf_dump_type_values(d, "0x%x", pt.p);
+ else
+ btf_dump_type_values(d, "0x%llx", pt.lp);
+ }
return 0;
}
int sz = t->size;
/* handle unaligned enum value */
- if (((uintptr_t)data) % sz) {
+ if (!ptr_is_aligned(data, sz)) {
*value = (__s64)btf_dump_bitfield_get_data(d, t, data, 0, 0);
return 0;
}