This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Aligning data in buffers with a macro?


On Sun, Apr 01, 2012 at 11:30:37AM -0400, Carlos O'Donell wrote:
> What do people think about creating some generic macros we can use for
> alignment?
> 
> That way it's crystal clear what you intend with the code.
> 
> For exmaple this...
> 
>  628 # elif _STACK_GROWS_UP
>  629           char *guard = (char *) (((uintptr_t) pd - guardsize) &
> ~pagesize_m1);
>  630 #endif
> 
> ... would become:
> 
>  628 # elif _STACK_GROWS_UP
>  629           char *guard = (char *) ALIGN_DOWN((uintptr_t) pd -
> guardsize, pagesize_m1);
>  630 #endif

To be honest, that doesn't make much difference to me.  The second
variant is not shorter nor more readable I suspect.  Also I have 
a qualm about these changes--they might be quite error-prone.

> Do the kernel headers have something we can crib or use here?

I see a lot of various *_ALIGN macros, e.g.

arch/powerpc/boot/page.h
25:#define _ALIGN_UP(addr,size)	(((addr)+((size)-1))&(~((size)-1)))
26:#define _ALIGN_DOWN(addr,size)	((addr)&(~((size)-1)))

include/linux/kernel.h
10:#define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))

and so on.  There was an effort a few years back to unify these
align macros to one align.h header, but still there isn't any
such header.  See e.g. this patch:

http://lkml.indiana.edu/hypermail/linux/kernel/0908.2/01641.html

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]