lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sun, 28 Mar 2010 14:29:11 -0400
From:	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
To:	Imre Deak <imre.deak@...ia.com>
Cc:	Russell King - ARM Linux <linux@....linux.org.uk>,
	Alexander Shishkin <virtuoso@...nd.org>,
	"linux-arm-kernel@...ts.infradead.org" 
	<linux-arm-kernel@...ts.infradead.org>,
	Jamie Lokier <jamie@...reable.org>,
	"rostedt@...dmis.org" <rostedt@...dmis.org>,
	"mingo@...e.hu" <mingo@...e.hu>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [RFC PATCH] create generic alignment api (v2)

* Imre Deak (imre.deak@...ia.com) wrote:
> On Sun, Mar 28, 2010 at 03:22:47AM +0200, ext Mathieu Desnoyers wrote:
> >  [...]
> > +/**
> > + * offset_align - Calculate the offset needed to align an object on its natural
> > + *                alignment towards higher addresses.
> > + * @align_drift:  object offset from an "alignment"-aligned address.
> > + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> > + *
> > + * Returns the offset that must be added to align towards higher
> > + * addresses.
> > + */
> > +static inline size_t offset_align(size_t align_drift, size_t alignment)
> > +{
> > +	return (alignment - align_drift) & (alignment - 1);
> > +}
> > +
> > +/**
> > + * offset_align_floor - Calculate the offset needed to align an object
> > + *                      on its natural alignment towards lower addresses.
> > + * @align_drift:  object offset from an "alignment"-aligned address.
> > + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> > + *
> > + * Returns the offset that must be substracted to align towards lower addresses.
> > + */
> > +static inline size_t offset_align_floor(size_t align_drift, size_t alignment)
> > +{
> > +	return (align_drift - alignment) & (alignment - 1);
> > +}
> > +
> > +#define object_align(object)						       \
> > +	((typeof(object))((size_t) object + offset_align((size_t) object,      \
> > +			  sizeof(object))))
> > +
> > +#define object_align_floor(object)					       \
> > +	((typeof(object))((size_t) object - offset_align_floor((size_t) object,\
> > +			  sizeof(object))))
> > +
> 
> Here object must be a pointer, but then sizeof(object) will result in
> aligning to the arch word size not the object's natural alignment. Is
> this what you intended?

Nope, should be sizeof(*object). Good catch. I did the object_align*() macros
specifically as "helper" functions for your needs.

I'll repost a v3.

Thanks,

Mathieu

> 
> --Imre
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ