[PATCH] vDSO for ppc/ppc64 submission

Tom Gall tom_gall at vnet.ibm.com
Fri Dec 9 13:13:54 EST 2005


Greetings,

Enclosed is the patch for ppc/ppc64 vDSO support in glibc plus changes to 
use the vDSO implementations of __vdso_get_tbfreq, __vdso_clock_gettime,
__vdso_clock_getres and __vdso_gettimeofday found in the 2.6.15 kernel 
written by Ben Herrenschmidt.

Comments/Complaints/Suggestions of course are most welcome.

Regards,

Tom

2005-12-08  Steven Munroe  <sjmunroe at us.ibm.com>
            Tom Gall <tom_gall at vnet.ibm.com>

	* elf/rtld.c (dl_main): Initialize l_local_scope for sysinfo_map.
	* sysdeps/powerpc/elf/libc-start.c: Move this.
	* sysdeps/unix/sysv/linux/powerpc/libc-start.c: To here.
	* sysdeps/powerpc/powerpc32/dl-start.S: add _dl_main_dispatch
	* sysdeps/powerpc/powerpc32/hp-timing.h: New file.
	* sysdeps/powerpc/Versions: add __vdso_ symbols
	* sysdeps/unix/sysv/linux/clock_getres.c: add INTERNAL_VSYSCALL
	defined by default to INTERNAL_SYSCALL and INLINE_VSYSCALL defined
	by default to INLINE_SYSCALL
	* sysdeps/unix/sysv/linux/clock_gettime.c: add INTERNAL_VSYSCALL
	defined by default to INTERNAL_SYSCALL and INLINE_VSYSCALL defined
	by default to INLINE_SYSCALL
	* sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h: new file
	* sysdeps/unix/sysv/linux/powerpc/clock_getres.c: New file.
	* sysdeps/unix/sysv/linux/powerpc/clock_gettime.c: New file.
	* sysdeps/unix/sysv/linux/powerpc/dl-vdso.c: New file.
	* sysdeps/unix/sysv/linux/powerpc/dl-vdso.h: New file.
	* sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c: use vDSO / format
	* sysdeps/unix/sysv/linux/powerpc/gettimeofday.c: New file.
	* sysdeps/unix/sysv/linux/powerpc/Makefile: Add routines += dl-vdso.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h: new 
	INLINE_VDSOCALL, INTERNAL_VDSOCALL_SIMPLE,
	INLINE_VDSOCALL_NO_SYSCALL_FALLBACK, INLINE_VDSOCALL_SIMPLE and
	INTERNAL_VDSOCALL macros
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h: new
	INLINE_VDSOCALL, INTERNAL_VDSOCALL_SIMPLE,
	INLINE_VDSOCALL_NO_SYSCALL_FALLBACK, INLINE_VDSOCALL_SIMPLE and
	INTERNAL_VDSOCALL macros
	macros

diff -uNr libc.orig/elf/rtld.c libc/elf/rtld.c
--- libc.orig/elf/rtld.c	2005-12-05 21:18:26.000000000 -0500
+++ libc/elf/rtld.c	2005-12-05 21:20:43.000000000 -0500
@@ -1296,6 +1296,13 @@
 	  elf_get_dynamic_info (l, dyn_temp);
 	  _dl_setup_hash (l);
 	  l->l_relocated = 1;
+	  /* Initialize l_local_scope to contain just this map. This allows 
+	     the use of dl_lookup_symbol_x to resolve symbols within the vdso.
+	     So we create a single entry list pointing to l_real as its only
+	     element */
+	  
+	  l->l_local_scope[0]->r_nlist = 1;
+	  l->l_local_scope[0]->r_list = &l->l_real;
 
 	  /* Now that we have the info handy, use the DSO image's soname
 	     so this object can be looked up by name.  Note that we do not
diff -uNr libc.orig/sysdeps/powerpc/elf/libc-start.c libc/sysdeps/powerpc/elf/libc-start.c
--- libc.orig/sysdeps/powerpc/elf/libc-start.c	2005-12-05 21:18:27.000000000 -0500
+++ libc/sysdeps/powerpc/elf/libc-start.c	1969-12-31 19:00:00.000000000 -0500
@@ -1,99 +0,0 @@
-/* Copyright (C) 1998,2000,2001,2002,2003,2004 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 Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 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
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <ldsodefs.h>
-#include <bp-start.h>
-#include <bp-sym.h>
-
-extern int __cache_line_size;
-weak_extern (__cache_line_size)
-
-/* The main work is done in the generic function.  */
-#define LIBC_START_MAIN generic_start_main
-#define LIBC_START_DISABLE_INLINE
-#define LIBC_START_MAIN_AUXVEC_ARG
-#define MAIN_AUXVEC_ARG
-#include <sysdeps/generic/libc-start.c>
-
-
-struct startup_info
-{
-  void *__unbounded sda_base;
-  int (*main) (int, char **, char **, void *);
-  int (*init) (int, char **, char **, void *);
-  void (*fini) (void);
-};
-
-
-int
-/* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
-   BPs in the arglist of startup_info.main and startup_info.init. */
-BP_SYM (__libc_start_main) (int argc, char *__unbounded *__unbounded ubp_av,
-			    char *__unbounded *__unbounded ubp_ev,
-			    ElfW(auxv_t) *__unbounded auxvec,
-			    void (*rtld_fini) (void),
-			    struct startup_info *__unbounded stinfo,
-			    char *__unbounded *__unbounded stack_on_entry)
-{
-#if __BOUNDED_POINTERS__
-  char **argv;
-#else
-# define argv ubp_av
-#endif
-
-  /* the PPC SVR4 ABI says that the top thing on the stack will
-     be a NULL pointer, so if not we assume that we're being called
-     as a statically-linked program by Linux...	 */
-  if (*stack_on_entry != NULL)
-    {
-      char *__unbounded *__unbounded temp;
-      /* ...in which case, we have argc as the top thing on the
-	 stack, followed by argv (NULL-terminated), envp (likewise),
-	 and the auxilary vector.  */
-      /* 32/64-bit agnostic load from stack */
-      argc = *(long int *__unbounded) stack_on_entry;
-      ubp_av = stack_on_entry + 1;
-      ubp_ev = ubp_av + argc + 1;
-#ifdef HAVE_AUX_VECTOR
-      temp = ubp_ev;
-      while (*temp != NULL)
-        ++temp;
-      auxvec = (ElfW(auxv_t) *)++temp;
-#endif
-      rtld_fini = NULL;
-    }
-
-  /* Initialize the __cache_line_size variable from the aux vector.  */
-  for (ElfW(auxv_t) *av = auxvec; av->a_type != AT_NULL; ++av)
-    switch (av->a_type)
-      {
-      case AT_DCACHEBSIZE:
-        {
-          int *cls = & __cache_line_size;
-          if (cls != NULL)
-            *cls = av->a_un.a_val;
-        }
-        break;
-      }
-
-  return generic_start_main (stinfo->main, argc, ubp_av, auxvec,
-			     stinfo->init, stinfo->fini, rtld_fini,
-			     stack_on_entry);
-}
diff -uNr libc.orig/sysdeps/powerpc/powerpc32/dl-start.S libc/sysdeps/powerpc/powerpc32/dl-start.S
--- libc.orig/sysdeps/powerpc/powerpc32/dl-start.S	2005-12-05 21:18:27.000000000 -0500
+++ libc/sysdeps/powerpc/powerpc32/dl-start.S	2005-12-05 21:20:43.000000000 -0500
@@ -98,6 +98,7 @@
    Take the opportunity to clear LR, so anyone who accidentally returns
    from _start gets SEGV.  Also clear the next few words of the stack.  */
 
+ENTRY(_dl_main_dispatch)
 	li	r31,0
 	stw	r31,0(r1)
 	mtlr	r31
diff -uNr libc.orig/sysdeps/powerpc/powerpc32/hp-timing.h libc/sysdeps/powerpc/powerpc32/hp-timing.h
--- libc.orig/sysdeps/powerpc/powerpc32/hp-timing.h	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/powerpc/powerpc32/hp-timing.h	2005-12-05 21:20:43.000000000 -0500
@@ -0,0 +1,83 @@
+/* High precision, low overhead timing functions.  Generic version.
+   Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper at cygnus.com>, 1998.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _HP_TIMING_H
+#define _HP_TIMING_H	1
+
+
+/* There are no generic definitions for the times.  We could write something
+   using the `gettimeofday' system call where available but the overhead of
+   the system call might be too high.
+
+   In case a platform supports timers in the hardware the following macros
+   and types must be defined:
+
+   - HP_TIMING_AVAIL: test for availability.
+
+   - HP_TIMING_INLINE: this macro is non-zero if the functionality is not
+     implemented using function calls but instead uses some inlined code
+     which might simply consist of a few assembler instructions.  We have to
+     know this since we might want to use the macros here in places where we
+     cannot make function calls.
+
+   - hp_timing_t: This is the type for variables used to store the time
+     values.
+
+   - HP_TIMING_ZERO: clear `hp_timing_t' object.
+
+   - HP_TIMING_NOW: place timestamp for current time in variable given as
+     parameter.
+
+   - HP_TIMING_DIFF_INIT: do whatever is necessary to be able to use the
+     HP_TIMING_DIFF macro.
+
+   - HP_TIMING_DIFF: compute difference between two times and store it
+     in a third.  Source and destination might overlap.
+
+   - HP_TIMING_ACCUM: add time difference to another variable.  This might
+     be a bit more complicated to implement for some platforms as the
+     operation should be thread-safe and 64bit arithmetic on 32bit platforms
+     is not.
+
+   - HP_TIMING_ACCUM_NT: this is the variant for situations where we know
+     there are no threads involved.
+
+   - HP_TIMING_PRINT: write decimal representation of the timing value into
+     the given string.  This operation need not be inline even though
+     HP_TIMING_INLINE is specified.
+
+*/
+
+/* Provide dummy definitions.  */
+#define HP_TIMING_AVAIL		(0)
+#define HP_TIMING_INLINE	(0)
+typedef unsigned long long int hp_timing_t;
+#define HP_TIMING_ZERO(Var)
+#define HP_TIMING_NOW(var)
+#define HP_TIMING_DIFF_INIT()
+#define HP_TIMING_DIFF(Diff, Start, End)
+#define HP_TIMING_ACCUM(Sum, Diff)
+#define HP_TIMING_ACCUM_NT(Sum, Diff)
+#define HP_TIMING_PRINT(Buf, Len, Val)
+
+/* Since this implementation is not available we tell the user about it.  */
+#define HP_TIMING_NONAVAIL	1
+
+#endif /* hp-timing.h */
diff -uNr libc.orig/sysdeps/powerpc/Versions libc/sysdeps/powerpc/Versions
--- libc.orig/sysdeps/powerpc/Versions	2005-12-05 21:18:27.000000000 -0500
+++ libc/sysdeps/powerpc/Versions	2005-12-05 21:20:43.000000000 -0500
@@ -13,5 +13,8 @@
   GLIBC_PRIVATE {
     __novmx__libc_longjmp; __novmx__libc_siglongjmp;
     __vmx__libc_longjmp; __vmx__libc_siglongjmp;
+    __vdso_get_tbfreq;
+    __vdso_clock_gettime;
+    __vdso_clock_getres;
   }
 }
diff -uNr libc.orig/sysdeps/unix/sysv/linux/clock_getres.c libc/sysdeps/unix/sysv/linux/clock_getres.c
--- libc.orig/sysdeps/unix/sysv/linux/clock_getres.c	2005-12-05 21:18:30.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/clock_getres.c	2005-12-07 13:54:09.000000000 -0500
@@ -24,9 +24,16 @@
 
 #include "kernel-features.h"
 
+#ifndef INTERNAL_VSYSCALL
+#define INTERNAL_VSYSCALL INTERNAL_SYSCALL
+#endif
+
+#ifndef INLINE_VSYSCALL 
+#define INLINE_VSYSCALL INLINE_SYSCALL
+#endif
 
 #define SYSCALL_GETRES \
-  retval = INLINE_SYSCALL (clock_getres, 2, clock_id, res); \
+  retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, res); \
   break
 
 #ifdef __ASSUME_POSIX_TIMERS
@@ -109,7 +116,7 @@
   if (!__libc_missing_posix_cpu_timers)
     {
       INTERNAL_SYSCALL_DECL (err);
-      int r = INTERNAL_SYSCALL (clock_getres, err, 2, clock_id, res);
+      int r = INTERNAL_VSYSCALL (clock_getres, err, 2, clock_id, res);
       if (!INTERNAL_SYSCALL_ERROR_P (r, err))
 	return 0;
 
@@ -128,7 +135,7 @@
 	    {
 	      /* Check whether the kernel supports CPU clocks at all.
 		 If not, record it for the future.  */
-	      r = INTERNAL_SYSCALL (clock_getres, err, 2,
+	      r = INTERNAL_VSYSCALL (clock_getres, err, 2,
 				    MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
 				    NULL);
 	      if (INTERNAL_SYSCALL_ERROR_P (r, err))
diff -uNr libc.orig/sysdeps/unix/sysv/linux/clock_gettime.c libc/sysdeps/unix/sysv/linux/clock_gettime.c
--- libc.orig/sysdeps/unix/sysv/linux/clock_gettime.c	2005-12-05 21:18:30.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/clock_gettime.c	2005-12-07 13:52:13.000000000 -0500
@@ -23,9 +23,16 @@
 #include "kernel-posix-cpu-timers.h"
 #include "kernel-features.h"
 
+#ifndef INTERNAL_VSYSCALL
+#define INTERNAL_VSYSCALL INTERNAL_SYSCALL
+#endif
+
+#ifndef INLINE_VSYSCALL
+#define INLINE_VSYSCALL INLINE_SYSCALL
+#endif
 
 #define SYSCALL_GETTIME \
-  retval = INLINE_SYSCALL (clock_gettime, 2, clock_id, tp); \
+  retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \
   break
 
 #ifdef __ASSUME_POSIX_TIMERS
@@ -108,7 +115,7 @@
   if (!__libc_missing_posix_cpu_timers)
     {
       INTERNAL_SYSCALL_DECL (err);
-      int r = INTERNAL_SYSCALL (clock_gettime, err, 2, clock_id, tp);
+      int r = INTERNAL_VSYSCALL (clock_gettime, err, 2, clock_id, tp);
       if (!INTERNAL_SYSCALL_ERROR_P (r, err))
 	return 0;
 
@@ -127,7 +134,7 @@
 	    {
 	      /* Check whether the kernel supports CPU clocks at all.
 		 If not, record it for the future.  */
-	      r = INTERNAL_SYSCALL (clock_getres, err, 2,
+	      r = INTERNAL_VSYSCALL (clock_getres, err, 2,
 				    MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
 				    NULL);
 	      if (INTERNAL_SYSCALL_ERROR_P (r, err))
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h libc/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h	2005-12-05 21:20:43.000000000 -0500
@@ -0,0 +1,36 @@
+/* Resolved function pointers to VDSO functions.
+   Copyright (C) 2005 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+
+#ifndef _LIBC_VDSO_H
+#define _LIBC_VDSO_H
+
+#ifdef SHARED
+
+extern void *__vdso_gettimeofday;
+
+extern void *__vdso_clock_gettime;
+
+extern void *__vdso_clock_getres;
+
+extern void *__vdso_get_tbfreq;
+
+#endif
+
+#endif /* _LIBC_VDSO_H */
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/clock_getres.c libc/sysdeps/unix/sysv/linux/powerpc/clock_getres.c
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/clock_getres.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/clock_getres.c	2005-12-07 16:44:14.000000000 -0500
@@ -0,0 +1,25 @@
+/* clock_getres -- Get the resolution of a POSIX clockid_t.  Linux version.
+   Copyright (C) 2005 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <bits/libc-vdso.h>
+
+#define INTERNAL_VSYSCALL INTERNAL_VDSOCALL_SIMPLE 
+#define INLINE_VSYSCALL INLINE_VDSOCALL
+
+#include <sysdeps/unix/sysv/linux/clock_getres.c>
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c libc/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c	2005-12-07 16:44:35.000000000 -0500
@@ -0,0 +1,25 @@
+/* clock_gettime -- Get current time from a POSIX clockid_t.  Linux version.
+   Copyright (C) 2005 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <bits/libc-vdso.h>
+
+#define INTERNAL_VSYSCALL INTERNAL_VDSOCALL_SIMPLE
+#define INLINE_VSYSCALL INLINE_VDSOCALL
+
+#include <sysdeps/unix/sysv/linux/clock_gettime.c>
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c	2005-12-05 21:20:43.000000000 -0500
@@ -0,0 +1,59 @@
+/* ELF symbol resolve functions for VDSO objects.
+   Copyright (C) 2005 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include "config.h"
+#include <dl-hash.h>
+#include <ldsodefs.h>
+
+void *internal_function
+_dl_vdso_vsym (const char *name, const char *version)
+{
+  ElfW (Sym) wsym;
+  const ElfW (Sym) * ref = &wsym;
+  struct link_map *map = GLRO (dl_sysinfo_map);
+  void *value = NULL;
+  struct r_found_version vers;
+  lookup_t result;
+
+
+  if (map != NULL)
+    {
+      /* Use a WEAK REF so we don't error out if the symbol is not found.  */
+      memset (&wsym, 0, sizeof (ElfW (Sym)));
+      wsym.st_info = (unsigned char) ELFW (ST_INFO (STB_WEAK, STT_NOTYPE));
+      /* Compute hash value to the version string.  */
+      vers.name = version;
+      vers.hidden = 1;
+      vers.hash = _dl_elf_hash (version);
+      /* We don't have a specific file where the symbol can be found.  */
+      vers.filename = NULL;
+
+      /* Search the scope of the vdso map.  */
+      result = GLRO (dl_lookup_symbol_x) (name, map, &ref,
+					  map->l_local_scope,
+					  &vers, 0, 0, NULL);
+
+      if (ref != NULL)
+	{
+	  value = DL_SYMBOL_ADDRESS (result, ref);
+
+	}
+    }
+  return value;
+}
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h	2005-12-05 21:20:43.000000000 -0500
@@ -0,0 +1,29 @@
+/* ELF symbol resolve functions for VDSO objects.
+   Copyright (C) 2005 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef	_DL_VDSO_H
+#define _DL_VDSO_H
+
+/* Functions for resolving symbols in the VDSO link map.  */
+
+extern void *
+_dl_vdso_vsym (const char *name, const char *version)
+     internal_function attribute_hidden;
+
+#endif /* dl-vdso.h */
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c libc/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c	2005-12-05 21:18:30.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c	2005-12-05 21:20:43.000000000 -0500
@@ -22,14 +22,15 @@
 #include <string.h>
 #include <unistd.h>
 #include <libc-internal.h>
-
+#include <sysdep.h>
+#include <bits/libc-vdso.h>
 
 hp_timing_t
 __get_clockfreq (void)
 {
   /* We read the information from the /proc filesystem.  /proc/cpuinfo
      contains at least one line like:
-        timebase        : 33333333
+     timebase        : 33333333
      We search for this line and convert the number into an integer.  */
   static hp_timing_t timebase_freq;
   hp_timing_t result = 0L;
@@ -38,68 +39,76 @@
   if (timebase_freq != 0)
     return timebase_freq;
 
-  int fd = open ("/proc/cpuinfo", O_RDONLY);
-  if (__builtin_expect (fd != -1, 1))
+  /* if we can use the vDSO to obtain the timebase even better */
+#ifdef SHARED
+  timebase_freq = INLINE_VDSOCALL_SIMPLE (get_tbfreq, 0);
+  if (timebase_freq == 0)
+#endif
     {
-      /* The timebase will be in the 1st 1024 bytes for systems with up
-         to 8 processors.  If the first read returns less then 1024
-	 bytes read,  we have the whole cpuinfo and can start the scan.
-	 Otherwise we will have to read more to insure we have the
-	 timebase value in the scan.  */
-      char buf[1024];
-      ssize_t n;
+      int fd = open ("/proc/cpuinfo", O_RDONLY);
 
-      n = read (fd, buf, sizeof (buf));
-      if (n == sizeof (buf))
+      if (__builtin_expect (fd != -1, 1))
 	{
-	  /* We are here because the 1st read returned exactly sizeof
-	     (buf) bytes.  This implies that we are not at EOF and may
-	     not have read the timebase value yet.  So we need to read
-	     more bytes until we know we have EOF.  We copy the lower
-	     half of buf to the upper half and read sizeof (buf)/2
-	     bytes into the lower half of buf and repeat until we
-	     reach EOF.  We can assume that the timebase will be in
-	     the last 512 bytes of cpuinfo, so two 512 byte half_bufs
-	     will be sufficient to contain the timebase and will
-	     handle the case where the timebase spans the half_buf
-	     boundry.  */
-	  const ssize_t half_buf = sizeof (buf) / 2;
-	  while (n >= half_buf)
+	  /* The timebase will be in the 1st 1024 bytes for systems with up
+	     to 8 processors.  If the first read returns less then 1024
+	     bytes read,  we have the whole cpuinfo and can start the scan.
+	     Otherwise we will have to read more to insure we have the
+	     timebase value in the scan.  */
+	  char buf[1024];
+	  ssize_t n;
+
+	  n = read (fd, buf, sizeof (buf));
+	  if (n == sizeof (buf))
 	    {
-	      memcpy (buf, buf + half_buf, half_buf);
-	      n = read (fd, buf + half_buf, half_buf);
+	      /* We are here because the 1st read returned exactly sizeof
+	         (buf) bytes.  This implies that we are not at EOF and may
+	         not have read the timebase value yet.  So we need to read
+	         more bytes until we know we have EOF.  We copy the lower
+	         half of buf to the upper half and read sizeof (buf)/2
+	         bytes into the lower half of buf and repeat until we
+	         reach EOF.  We can assume that the timebase will be in
+	         the last 512 bytes of cpuinfo, so two 512 byte half_bufs
+	         will be sufficient to contain the timebase and will
+	         handle the case where the timebase spans the half_buf
+	         boundry.  */
+	      const ssize_t half_buf = sizeof (buf) / 2;
+	      while (n >= half_buf)
+		{
+		  memcpy (buf, buf + half_buf, half_buf);
+		  n = read (fd, buf + half_buf, half_buf);
+		}
+	      if (n >= 0)
+		n += half_buf;
 	    }
-	  if (n >= 0)
-	    n += half_buf;
-	}
-
-      if (__builtin_expect (n, 1) > 0)
-	{
-	  char *mhz = memmem (buf, n, "timebase", 7);
 
-	  if (__builtin_expect (mhz != NULL, 1))
+	  if (__builtin_expect (n, 1) > 0)
 	    {
-	      char *endp = buf + n;
+	      char *mhz = memmem (buf, n, "timebase", 7);
 
-	      /* Search for the beginning of the string.  */
-	      while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
-		++mhz;
-
-	      while (mhz < endp && *mhz != '\n')
+	      if (__builtin_expect (mhz != NULL, 1))
 		{
-		  if (*mhz >= '0' && *mhz <= '9')
+		  char *endp = buf + n;
+
+		  /* Search for the beginning of the string.  */
+		  while (mhz < endp && (*mhz < '0' || *mhz > '9')
+			 && *mhz != '\n')
+		    ++mhz;
+
+		  while (mhz < endp && *mhz != '\n')
 		    {
-		      result *= 10;
-		      result += *mhz - '0';
-		    }
+		      if (*mhz >= '0' && *mhz <= '9')
+			{
+			  result *= 10;
+			  result += *mhz - '0';
+			}
 
-		  ++mhz;
+		      ++mhz;
+		    }
 		}
+	      timebase_freq = result;
 	    }
-	  timebase_freq = result;
+	  close (fd);
 	}
-      close (fd);
     }
-
   return timebase_freq;
 }
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c libc/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c	2005-12-07 14:02:19.000000000 -0500
@@ -0,0 +1,41 @@
+/* Copyright (C) 2005 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <bp-checks.h>
+#include <stddef.h>
+#include <sys/time.h>
+#include <time.h>
+#include <hp-timing.h>
+
+#undef __gettimeofday
+#include <bits/libc-vdso.h>
+
+/* Get the current time of day and timezone information,
+   putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
+   Returns 0 on success, -1 on errors.  */
+
+int
+__gettimeofday (tv, tz)
+     struct timeval *tv;
+     struct timezone *tz;
+{
+  return INLINE_VDSOCALL (gettimeofday, 2, CHECK_1 (tv), CHECK_1 (tz));
+}
+
+INTDEF (__gettimeofday) weak_alias (__gettimeofday, gettimeofday)
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/libc-start.c libc/sysdeps/unix/sysv/linux/powerpc/libc-start.c
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/libc-start.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/libc-start.c	2005-12-05 21:20:43.000000000 -0500
@@ -0,0 +1,130 @@
+/* Copyright (C) 1998,2000,2001,2002,2003,2004,2005 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <ldsodefs.h>
+#include <bp-start.h>
+#include <bp-sym.h>
+
+extern int __cache_line_size;
+weak_extern (__cache_line_size)
+/* The main work is done in the generic function.  */
+#define LIBC_START_MAIN generic_start_main
+#define LIBC_START_DISABLE_INLINE
+#define LIBC_START_MAIN_AUXVEC_ARG
+#define MAIN_AUXVEC_ARG
+#define INIT_MAIN_ARGS
+#include <sysdeps/generic/libc-start.c>
+
+struct startup_info
+  {
+    void *__unbounded sda_base;
+    int (*main) (int, char **, char **, void *);
+    int (*init) (int, char **, char **, void *);
+    void (*fini) (void);
+  };
+
+
+#ifdef SHARED
+#include <sys/time.h>
+#include <dl-vdso.h>
+#undef __gettimeofday
+#undef __clock_gettime
+#undef __clock_getres
+#include <bits/libc-vdso.h>
+
+void *__vdso_gettimeofday;
+void *__vdso_clock_gettime;
+void *__vdso_clock_getres;
+void *__vdso_get_tbfreq;
+
+static inline void _libc_vdso_platform_setup (void)
+  {
+    __vdso_gettimeofday = _dl_vdso_vsym ("__kernel_gettimeofday",
+  				         "LINUX_2.6.15");
+
+    __vdso_clock_gettime = _dl_vdso_vsym ("__kernel_clock_gettime",
+					  "LINUX_2.6.15");
+
+    __vdso_clock_getres = _dl_vdso_vsym ("__kernel_clock_getres",
+				         "LINUX_2.6.15");
+
+    __vdso_get_tbfreq = _dl_vdso_vsym ("__kernel_vdso_get_tbfreq",
+				       "LINUX_2.6.15");
+  }
+#endif
+
+int
+/* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
+   BPs in the arglist of startup_info.main and startup_info.init. */
+  BP_SYM (__libc_start_main) (int argc, char *__unbounded * __unbounded ubp_av,
+			      char *__unbounded * __unbounded ubp_ev,
+			      ElfW (auxv_t) * __unbounded auxvec,
+			      void (*rtld_fini) (void),
+			      struct startup_info * __unbounded stinfo,
+			      char *__unbounded * __unbounded stack_on_entry)
+{
+#if __BOUNDED_POINTERS__
+  char **argv;
+#else
+# define argv ubp_av
+#endif
+
+  /* the PPC SVR4 ABI says that the top thing on the stack will
+     be a NULL pointer, so if not we assume that we're being called
+     as a statically-linked program by Linux...  */
+  if (*stack_on_entry != NULL)
+    {
+      char *__unbounded * __unbounded temp;
+      /* ...in which case, we have argc as the top thing on the
+         stack, followed by argv (NULL-terminated), envp (likewise),
+         and the auxilary vector.  */
+      /* 32/64-bit agnostic load from stack */
+      argc = *(long int *__unbounded) stack_on_entry;
+      ubp_av = stack_on_entry + 1;
+      ubp_ev = ubp_av + argc + 1;
+#ifdef HAVE_AUX_VECTOR
+      temp = ubp_ev;
+      while (*temp != NULL)
+	++temp;
+      auxvec = (ElfW (auxv_t) *)++ temp;
+#endif
+      rtld_fini = NULL;
+    }
+
+  /* Initialize the __cache_line_size variable from the aux vector.  */
+  for (ElfW (auxv_t) * av = auxvec; av->a_type != AT_NULL; ++av)
+    switch (av->a_type)
+      {
+      case AT_DCACHEBSIZE:
+	{
+	  int *cls = &__cache_line_size;
+	  if (cls != NULL)
+	    *cls = av->a_un.a_val;
+	}
+	break;
+      }
+#ifdef SHARED
+  /* Resolve and initialize function pointers for VDSO functions.  */
+  _libc_vdso_platform_setup ();
+#endif
+  return generic_start_main (stinfo->main, argc, ubp_av, auxvec,
+			     stinfo->init, stinfo->fini, rtld_fini,
+			     stack_on_entry);
+}
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/Makefile libc/sysdeps/unix/sysv/linux/powerpc/Makefile
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/Makefile	2005-12-05 21:18:30.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/Makefile	2005-12-05 21:20:43.000000000 -0500
@@ -2,3 +2,8 @@
 ifeq ($(subdir),rt)
 librt-routines += rt-sysdep
 endif
+
+ifeq ($(subdir),misc)
+routines += dl-vdso
+endif
+
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h	2005-12-05 21:18:30.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h	2005-12-08 16:00:17.300339776 -0500
@@ -54,6 +54,139 @@
 
 # include <errno.h>
 
+# undef INLINE_VDSOCALL
+#ifdef SHARED
+# define INLINE_VDSOCALL(name, nr, args...)                             \
+  ({                                                                    \
+    INTERNAL_SYSCALL_DECL (sc_err);                                     \
+    long int sc_ret = 0;                                                \
+                                                                        \
+    if ( __vdso_ ## name !=NULL)                                        \
+        sc_ret = INTERNAL_VDSOCALL (__vdso_ ## name, sc_err, nr, args);  \
+    if (( __vdso_ ## name == NULL ) || (sc_ret == ENOSYS))              \
+        sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args);   		\
+    if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err))                      \
+      {                                                                 \
+        __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));          \
+        sc_ret = -1L;                                                   \
+      }                                                                 \
+    sc_ret;                                                             \
+  })
+#else
+# define INLINE_VDSOCALL(name, nr, args...)				\
+  ({									\
+    INTERNAL_SYSCALL_DECL (sc_err);					\
+    long int sc_ret;							\
+									\
+    sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args);      	 	\
+    if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) 			\
+      {									\
+        __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));		\
+	sc_ret = -1L;							\
+      }									\
+    sc_ret;								\
+  })
+#endif
+
+# undef INTERNAL_VDSOCALL_SIMPLE
+#ifdef SHARED
+# define INTERNAL_VDSOCALL_SIMPLE(name, err, nr, args...)              \
+  ({                                                                   \
+    long int v_ret = 0;                                                \
+                                                                       \
+    if ( __vdso_ ## name !=NULL)                                       \
+        v_ret = INTERNAL_VDSOCALL (__vdso_ ## name, err, nr, args);  \
+    if (( __vdso_ ## name == NULL ) || (v_ret == ENOSYS))              \       
+        v_ret = INTERNAL_SYSCALL (name, err, nr, args);   		\
+    v_ret;                                                             \
+  })
+#else
+# define INTERNAL_VDSOCALL_SIMPLE(name, err, nr, args...)		\
+  ({									\
+    long int v_ret;							\
+									\
+    v_ret = INTERNAL_SYSCALL (name, err, nr, args);      	 	\
+    v_ret;								\
+  })
+#endif
+
+# undef INLINE_VDSOCALL_NO_SYSCALL_FALLBACK
+# define INLINE_VDSOCALL_NO_SYSCALL_FALLBACK(name, nr, args...)		\
+  ({									\
+    INTERNAL_SYSCALL_DECL (sc_err);					\
+    long int sc_ret=0;							\
+									\
+    if (__vdso_ ## name !=NULL) 					\
+      {									\
+        sc_ret = INTERNAL_VDSOCALL (__vdso_ ## name, sc_err, nr, args);	 \
+      }           							\
+    else                                                                \
+      {                                                                 \
+        sc_ret = ENOSYS;                                                \
+      }                                                                 \
+    if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) 			\
+      {									\
+        __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));		\
+	sc_ret = -1L;							\
+      }									\
+    sc_ret;								\
+  })
+
+# undef INLINE_VDSOCALL_SIMPLE
+# define INLINE_VDSOCALL_SIMPLE(name, nr, args...)			\
+  ({									\
+    INTERNAL_SYSCALL_DECL (sc_err);					\
+    long int sc_ret=0;							\
+									\
+    if (__vdso_ ## name !=NULL) 					\
+      {									\
+        sc_ret = INTERNAL_VDSOCALL (__vdso_ ## name, sc_err, nr, args);	 \
+      }           							\
+    else                                                                \
+      {                                                                 \
+        sc_ret = ENOSYS;                                                \
+      }                                                                 \
+    sc_ret;								\
+  })
+
+/* Define a macro which expands inline into the wrapper code for a VDSO
+   call. This use is for internal calls that do not need to handle errors
+   normally. It will never touch errno.
+   On powerpc a system call basically clobbers the same registers like a
+   function call, with the exception of LR (which is needed for the
+   "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
+   an error return status).  */
+
+# undef INTERNAL_VDSOCALL
+# define INTERNAL_VDSOCALL_NCS(funcptr, err, nr, args...)		\
+  ({									\
+    register void *r0  __asm__ ("r0");					\
+    register long int r3  __asm__ ("r3");				\
+    register long int r4  __asm__ ("r4");				\
+    register long int r5  __asm__ ("r5");				\
+    register long int r6  __asm__ ("r6");				\
+    register long int r7  __asm__ ("r7");				\
+    register long int r8  __asm__ ("r8");				\
+    register long int r9  __asm__ ("r9");				\
+    register long int r10 __asm__ ("r10");				\
+    register long int r11 __asm__ ("r11");				\
+    register long int r12 __asm__ ("r12");				\
+    LOADARGS_##nr(funcptr, args);					\
+    __asm__ __volatile__						\
+      ("mtctr %0\n\t"							\
+       "bctrl\n\t"							\
+       "mfcr %0"							\
+       : "=&r" (r0),							\
+	 "=&r" (r3), "=&r" (r4), "=&r" (r5),  "=&r" (r6),  "=&r" (r7),	\
+	 "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12)	\
+       : ASM_INPUT_##nr							\
+       : "cr0", "ctr", "lr", "memory");					\
+    err = (long int)r0;							\
+    (int) r3;								\
+  })
+# define INTERNAL_VDSOCALL(name, err, nr, args...) \
+  INTERNAL_VDSOCALL_NCS (name, err, nr, ##args)
+
 # undef INLINE_SYSCALL
 # define INLINE_SYSCALL(name, nr, args...)				\
   ({									\
diff -uNr libc.orig/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
--- libc.orig/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h	2005-12-05 21:18:30.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h	2005-12-08 16:00:42.708338736 -0500
@@ -66,7 +66,144 @@
 #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
 
-#endif	/* __ASSEMBLER__ */
+#endif /* __ASSEMBLER__ */
+
+/* This version is for kernels that implement system calls that
+   behave like function calls as far as register saving.  
+   It falls back to the syscall in the case that the vDSO doesn't
+   exist or fails for ENOSYS */
+
+# undef INLINE_VDSOCALL
+#ifdef SHARED
+# define INLINE_VDSOCALL(name, nr, args...)                             \
+  ({                                                                    \
+    INTERNAL_SYSCALL_DECL (sc_err);                                     \
+    long int sc_ret = 0;                                                \
+                                                                        \
+    if ( __vdso_ ## name !=NULL)                                        \
+        sc_ret = INTERNAL_VDSOCALL (__vdso_ ## name, sc_err, nr, args); \
+    if (( __vdso_ ## name == NULL ) || (sc_ret == ENOSYS))              \
+        sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); 		\
+    if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err))                      \
+      {                                                                 \
+        __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));          \
+        sc_ret = -1L;                                                   \
+      }                                                                 \
+    sc_ret;                                                             \
+  })
+#else
+# define INLINE_VDSOCALL(name, nr, args...)                             \
+  ({                                                                    \
+    INTERNAL_SYSCALL_DECL (sc_err);					\
+    long int sc_ret;                                                    \
+                                                                        \
+    sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args);			\
+    if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err))                      \
+      {                                                                 \
+        __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));          \
+        sc_ret = -1L;                                                   \
+      }                                                                 \
+    sc_ret;                                                             \
+  })
+#endif
+
+# undef INTERNAL_VDSOCALL_SIMPLE
+#ifdef SHARED
+# define INTERNAL_VDSOCALL_SIMPLE(name, err, nr, args...)              \
+  ({                                                                   \
+    long int v_ret = 0;                                                \
+                                                                       \
+    if ( __vdso_ ## name !=NULL)                                       \
+        v_ret = INTERNAL_VDSOCALL (__vdso_ ## name, err, nr, args);  \
+    if (( __vdso_ ## name == NULL ) || (v_ret == ENOSYS))              \
+        v_ret = INTERNAL_SYSCALL (name, err, nr, args);              \
+    v_ret;                                                             \
+  })
+#else
+# define INTERNAL_VDSOCALL_SIMPLE(name, err, nr, args...)               \
+  ({                                                                    \
+    long int v_ret;                                                     \
+                                                                        \
+    v_ret = INTERNAL_SYSCALL (name, err, nr, args);                   \
+    v_ret;                                                              \
+  })
+#endif
+
+
+/* This version does not fail back to a syscall as the previous
+   version does */
+# undef INLINE_VDSOCALL_NO_SYSCALL_FALLBACK
+# define INLINE_VDSOCALL_NO_SYSCALL_FALLBACK(name, nr, args...)         \
+  ({									\
+     INTERNAL_SYSCALL_DECL (sc_err);					\
+     long int sc_ret = 0;						\
+     if (__vdso_ ## name !=NULL) 	                                \
+       {								\
+          sc_ret = INTERNAL_VDSOCALL (__vdso_ ## name, sc_err, nr, args);  \
+       }								\
+     else								\
+       {								\
+          sc_ret = ENOSYS;						\
+       }								\
+     if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err))			\
+       {								\
+          __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));	\
+          sc_ret = -1L;							\
+       }								\
+     sc_ret;								\
+  })
+
+/* This version is for internal uses when there is no desire
+   to set errno */
+# undef INLINE_VDSOCALL_SIMPLE
+# define INLINE_VDSOCALL_SIMPLE(name, nr, args...)                      \
+  ({                                                                    \
+    INTERNAL_SYSCALL_DECL (sc_err);					\
+    long int sc_ret=0;                                                  \
+                                                                        \
+    if ( __vdso_ ## name !=NULL)                                        \
+      {                                                                 \
+        sc_ret = INTERNAL_VDSOCALL (__vdso_ ## name, sc_err, nr, args);  \
+      }									\
+    else								\
+      {									\
+        sc_ret = ENOSYS;						\
+      }									\
+    sc_ret;								\
+  })
+
+/* Define a macro which expands inline into the wrapper code for a system
+   call. This use is for internal calls that do not need to handle errors
+   normally. It will never touch errno. This returns just what the kernel
+   gave back in the non-error (CR0.SO cleared) case, otherwise (CR0.SO set)
+   the negation of the return value in the kernel gets reverted.  */
+
+#define INTERNAL_VDSOCALL_NCS(funcptr, err, nr, args...) \
+  ({									\
+    register void *r0  __asm__ ("r0");					\
+    register long int r3  __asm__ ("r3");				\
+    register long int r4  __asm__ ("r4");				\
+    register long int r5  __asm__ ("r5");				\
+    register long int r6  __asm__ ("r6");				\
+    register long int r7  __asm__ ("r7");				\
+    register long int r8  __asm__ ("r8");				\
+    LOADARGS_##nr(funcptr, args);					\
+    __asm__ __volatile__						\
+      ("mtctr %0\n\t"							\
+       "bctrl\n\t"							\
+       "mfcr  %0\n\t"							\
+       "0:"								\
+       : "=&r" (r0),							\
+         "=&r" (r3), "=&r" (r4), "=&r" (r5),				\
+         "=&r" (r6), "=&r" (r7), "=&r" (r8)				\
+       : ASM_INPUT_##nr							\
+       : "r9", "r10", "r11", "r12",					\
+         "cr0", "ctr", "lr", "memory");					\
+	  err = (long int)r0;						\
+    (int) r3;								\
+  })
+#define INTERNAL_VDSOCALL(name, err, nr, args...)			\
+  INTERNAL_VDSOCALL_NCS (name, err, nr, ##args)
 
 #undef INLINE_SYSCALL
 



More information about the Linuxppc64-dev mailing list