On Monday 15 September 2008 07:02, Vladimir Dronnikov wrote:
> >
> > sizeof(size_t) may be != 4. sizeof(unsigned) also may be != 4.
> > Also, this may perform illegal unaligned accesses.
> >
> Yes. I admit the code is for x86 mostly...
> Is there any way do fix that issue for other archs? To use hton*()? Bad for
> performance. To use string representation of numbers? Bad again...
include/platform.h:
/* parameter is supposed to be an uint32_t* ptr */
#if defined(i386) || defined(__x86_64__)
#define get_unaligned_u32p(u32p) (*(u32p))
/* #elif ... - add your favorite arch today! */
#else
/* performs reasonably well (gcc usually inlines memcpy here) */
#define get_unaligned_u32p(u32p) ({ uint32_t __t; memcpy(&__t, (u32p), 4); __t;
})
#endif
You may need to implement put_unaligned_u32p(u32p, v) macro too.
This code in networking/udhcp/options.c might use it:
/* This memcpy is for processors which can't
* handle a simple unaligned 32-bit assignment */
memcpy(&option[OPT_DATA], &data, 4);
return add_option_string(optionptr, option);
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox