Use AT_PAGESZ from the ELF header to obtain the page size.

diff --git a/include/unistd.h b/include/unistd.h
index 52250f9..c5ded91 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -120,8 +120,14 @@
 
 __extern int isatty(int);
 
-__extern int getpagesize(void);
-__extern int __getpageshift(void);
+static __inline__ int getpagesize(void) {
+  extern unsigned int __page_size;
+  return __page_size;
+}
+static __inline__ int __getpageshift(void) {
+  extern unsigned int __page_shift;
+  return __page_shift;
+}
 
 /* Standard file descriptor numbers. */
 #define STDIN_FILENO	0
diff --git a/klibc/Makefile b/klibc/Makefile
index 3fff392..9238a22 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -26,7 +26,6 @@
 	  __signal.o sysv_signal.o bsd_signal.o siglist.o siglongjmp.o \
 	  sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
 	  brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o \
-	  getpagesize.o getpageshift.o \
 	  memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
 	  memmove.o \
 	  strcasecmp.o strncasecmp.o strndup.o strerror.o \
diff --git a/klibc/__shared_init.c b/klibc/__shared_init.c
index 63e3f46..592a3db 100644
--- a/klibc/__shared_init.c
+++ b/klibc/__shared_init.c
@@ -1,56 +1,2 @@
-/*
- * __shared_init.c
- *
- * This function takes the raw data block set up by the ELF loader
- * in the kernel and parses it.  It is invoked by crt0.S which makes
- * any necessary adjustments and passes calls this function using
- * the standard C calling convention.
- *
- * The arguments are:
- *  uintptr_t *elfdata	 -- The ELF loader data block; usually from the stack.
- *                          Basically a pointer to argc.
- *  void (*onexit)(void) -- Function to install into onexit
- */
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <klibc/compiler.h>
-#include <elf.h>
-
-char **environ;
-
-__noreturn __libc_init(uintptr_t *elfdata, void (*onexit)(void))
-{
-  int argc;
-  char **argv, **envp, **envend;
-  struct auxentry {
-    uintptr_t type;
-    uintptr_t v;
-  } *auxentry;
-  typedef int (*main_t)(int, char **, char **);
-  main_t main_ptr = NULL;
-
-  (void)onexit;			/* For now, we ignore this... */
-
-  argc = (int)*elfdata++;
-  argv = (char **)elfdata;
-  envp = argv+(argc+1);
-
-  /* The auxillary entry vector is after all the environment vars */
-  for ( envend = envp ; *envend ; envend++ );
-  auxentry = (struct auxentry *)(envend+1);
-
-  while ( auxentry->type ) {
-    if ( auxentry->type == AT_ENTRY ) {
-      main_ptr = (main_t)(auxentry->v);
-      break;
-    }
-    auxentry++;
-  }
-
-  environ = envp;
-  exit(main_ptr(argc, argv, envp));
-}
-
-  
+#define SHARED 1
+#include "libc_init.c"
diff --git a/klibc/__static_init.c b/klibc/__static_init.c
index 5a90b5c..0b59eed 100644
--- a/klibc/__static_init.c
+++ b/klibc/__static_init.c
@@ -1,38 +1,2 @@
-/*
- * __static_init.c
- *
- * This function takes the raw data block set up by the ELF loader
- * in the kernel and parses it.  It is invoked by crt0.S which makes
- * any necessary adjustments and passes calls this function using
- * the standard C calling convention.
- *
- * The arguments are:
- *  uintptr_t *elfdata	 -- The ELF loader data block; usually from the stack.
- *                          Basically a pointer to argc.
- *  void (*onexit)(void) -- Function to install into onexit
- */
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <klibc/compiler.h>
-#include <elf.h>
-
-char **environ;
-
-extern int main(int, char **, char **);
-
-__noreturn __libc_init(uintptr_t *elfdata, void (*onexit)(void))
-{
-  int argc;
-  char **argv, **envp;
-
-  (void)onexit;			/* For now, we ignore this... */
-
-  argc = (int)*elfdata++;
-  argv = (char **)elfdata;
-  envp = argv+(argc+1);
-
-  environ = envp;
-  exit(main(argc, argv, envp));
-}
+#define SHARED 0
+#include "libc_init.c"
diff --git a/klibc/include/unistd.h b/klibc/include/unistd.h
index 52250f9..c5ded91 100644
--- a/klibc/include/unistd.h
+++ b/klibc/include/unistd.h
@@ -120,8 +120,14 @@
 
 __extern int isatty(int);
 
-__extern int getpagesize(void);
-__extern int __getpageshift(void);
+static __inline__ int getpagesize(void) {
+  extern unsigned int __page_size;
+  return __page_size;
+}
+static __inline__ int __getpageshift(void) {
+  extern unsigned int __page_shift;
+  return __page_shift;
+}
 
 /* Standard file descriptor numbers. */
 #define STDIN_FILENO	0
diff --git a/klibc/libc_init.c b/klibc/libc_init.c
new file mode 100644
index 0000000..494d8cc
--- /dev/null
+++ b/klibc/libc_init.c
@@ -0,0 +1,76 @@
+/*
+ * libc_init.c
+ *
+ * This function takes the raw data block set up by the ELF loader
+ * in the kernel and parses it.  It is invoked by crt0.S which makes
+ * any necessary adjustments and passes calls this function using
+ * the standard C calling convention.
+ *
+ * The arguments are:
+ *  uintptr_t *elfdata	 -- The ELF loader data block; usually from the stack.
+ *                          Basically a pointer to argc.
+ *  void (*onexit)(void) -- Function to install into onexit
+ */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <klibc/compiler.h>
+#include <elf.h>
+
+char **environ;
+unsigned int __page_size, __page_shift;
+
+struct auxentry {
+  uintptr_t type;
+  uintptr_t v;
+};
+
+__noreturn __libc_init(uintptr_t *elfdata, void (*onexit)(void))
+{
+  int argc;
+  char **argv, **envp, **envend;
+  struct auxentry *auxentry;
+#if SHARED
+  typedef int (*main_t)(int, char **, char **);
+  main_t MAIN = NULL;
+#else
+  extern int main(int, char **, char **);
+#define MAIN main
+#endif
+  unsigned int page_size = 0, page_shift = 0;
+
+  (void)onexit;			/* For now, we ignore this... */
+
+  argc = (int)*elfdata++;
+  argv = (char **)elfdata;
+  envp = argv+(argc+1);
+
+  /* The auxillary entry vector is after all the environment vars */
+  for ( envend = envp ; *envend ; envend++ );
+  auxentry = (struct auxentry *)(envend+1);
+
+  while ( auxentry->type ) {
+    switch ( auxentry->type ) {
+#if SHARED
+    case AT_ENTRY:
+      MAIN = (main_t)(auxentry->v);
+      break;
+#endif
+    case AT_PAGESZ:
+      page_size = (int)(auxentry->v);
+      break;
+    }
+    auxentry++;
+  }
+
+  __page_size = page_size;
+  while ( page_size > 1 ) {
+    page_shift++;
+    page_size >>= 1;
+  }
+  __page_shift = page_shift;
+
+  environ = envp;
+  exit(MAIN(argc, argv, envp));
+}
diff --git a/klibc/tests/getpagesize.c b/klibc/tests/getpagesize.c
new file mode 100644
index 0000000..bda37e1
--- /dev/null
+++ b/klibc/tests/getpagesize.c
@@ -0,0 +1,11 @@
+#include <unistd.h>
+#include <stdio.h>
+
+int main(void)
+{
+  printf("getpagesize()    = %d\n"
+	 "__getpageshift() = %d\n",
+	 getpagesize(), __getpageshift());
+
+  return 0;
+}