[uClibc] [PATCH] getpagesize for mips

Atsushi Nemoto anemo at mba.ocn.ne.jp
Mon Dec 22 11:07:49 UTC 2003


With recent Linux/MIPS kernel headers, uClibc's getpagesize() returns
65536.

This is because new the kernel has configurable PAGESIZE and
EXEC_PAGESIZE is the maximum pagesize the kernel is planning to
support (65536).  Also, the kernel header (asm/page.h) does not export
PAGE_SIZE for userland.

The kernel passes AT_PAGESZ to ELF binaries via auxiliary vector, but
uClibc does not handle it.  Instead of modifying the auxiliary vector
handling, I just added mips-specific getpagesize which refers the
kernel configuration directly.


diff -urN uClibc-0.9.24.org/libc/sysdeps/linux/mips/Makefile uClibc-0.9.24/libc/sysdeps/linux/mips/Makefile
--- uClibc-0.9.24.org/libc/sysdeps/linux/mips/Makefile	Sat Nov 29 04:39:51 2003
+++ uClibc-0.9.24/libc/sysdeps/linux/mips/Makefile	Mon Dec 22 16:45:14 2003
@@ -28,7 +28,7 @@
 SOBJS=$(patsubst %.S,%.o, $(SSRC))
 
 CSRC=__longjmp.c  brk.c vfork.c setjmp_aux.c _mmap.c __syscall_error.c \
-	cacheflush.c pread_write.c sysmips.c _test_and_set.c
+	cacheflush.c pread_write.c sysmips.c _test_and_set.c getpagesize.c
 COBJS=$(patsubst %.c,%.o, $(CSRC))
 
 OBJS=$(SOBJS) $(MOBJ) $(COBJS)
diff -urN uClibc-0.9.24.org/libc/sysdeps/linux/mips/getpagesize.c uClibc-0.9.24/libc/sysdeps/linux/mips/getpagesize.c
--- uClibc-0.9.24.org/libc/sysdeps/linux/mips/getpagesize.c	Thu Jan  1 09:00:00 1970
+++ uClibc-0.9.24/libc/sysdeps/linux/mips/getpagesize.c	Mon Dec 22 19:55:36 2003
@@ -0,0 +1,58 @@
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <unistd.h>
+#include <features.h>
+#include <sys/param.h>
+#include <linux/config.h>
+
+/* Since Oct 15 2003, the Linux/MIPS kernel supports configurable
+PAGESIZE and EXEC_PAGESIZE is the maximum pagesize the Linux/MIPS
+kernel is planning to support (65536) */
+#ifdef CONFIG_PAGE_SIZE_4KB
+#define KERNEL_PAGESIZE	(1 << 12)
+#endif
+#ifdef CONFIG_PAGE_SIZE_16KB
+#define KERNEL_PAGESIZE	(1 << 14)
+#endif
+#ifdef CONFIG_PAGE_SIZE_64KB
+#define KERNEL_PAGESIZE	(1 << 16)
+#endif
+
+/* Return the system page size.  */
+int __getpagesize(void)
+{
+#ifdef	KERNEL_PAGESIZE
+  return KERNEL_PAGESIZE;
+#else	/* No KERNEL_PAGESIZE.  */
+#ifdef	EXEC_PAGESIZE
+  return EXEC_PAGESIZE;
+#else	/* No EXEC_PAGESIZE.  */
+#ifdef	NBPG
+#ifndef	CLSIZE
+#define	CLSIZE	1
+#endif	/* No CLSIZE.  */
+  return NBPG * CLSIZE;
+#else	/* No NBPG.  */
+  return NBPC;
+#endif	/* NBPG.  */
+#endif	/* EXEC_PAGESIZE.  */
+#endif	/* KERNEL_PAGESIZE.  */
+}
+
+weak_alias(__getpagesize, getpagesize);



More information about the uClibc mailing list