On 7/8/06, Jim Gifford <[EMAIL PROTECTED]> wrote:

The best example and most noticeable is from page.h, PAGE_SHIFT is set
by a variable from the configuration file used to create the kernel.
Here is an unsanitized version. The same holds true with all
architectures in various different files.

/*
 * PAGE_SHIFT determines the page size
 */
#ifdef CONFIG_PAGE_SIZE_4KB
#define PAGE_SHIFT      12
#endif
#ifdef CONFIG_PAGE_SIZE_8KB
#define PAGE_SHIFT      13
#endif
#ifdef CONFIG_PAGE_SIZE_16KB
#define PAGE_SHIFT      14
#endif
#ifdef CONFIG_PAGE_SIZE_64KB
#define PAGE_SHIFT      16
#endif
#define PAGE_SIZE       (1UL << PAGE_SHIFT)
#define PAGE_MASK       (~((1 << PAGE_SHIFT) - 1))

Here is a santized version
#define PAGE_SIZE       (getpagesize())
static __inline__ int getpageshift()
{
    int pagesize = getpagesize();
    return (__builtin_clz(pagesize) ^ 31);
}

Interesting. I'd take another look. There is more sanitization in the
kernel build now. If you're talking about asm/page.h, here's what I
get on i386.

#ifndef _I386_PAGE_H
#define _I386_PAGE_H

#include <unistd.h>

#define PAGE_SIZE (getpagesize())
static __inline__ int getpageshift()
{
   int pagesize = getpagesize();
#if (__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))
   return (__builtin_clz(pagesize) ^ 31);
#else
   register int pageshift = -1;
   while (pagesize) { pagesize >>= 1; pageshift++; }
   return pageshift;
#endif
}
#define PAGE_SHIFT (getpageshift())
#define PAGE_MASK    (~(PAGE_SIZE-1))

#endif /* _I386_PAGE_H */

--
Dan
--
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to