[git commit] ldso: Use newer syscalls if arch does not have the deprecated syscalls

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Wed Feb 20 12:45:13 UTC 2013

commit: http://git.uclibc.org/uClibc/commit/?id=634e74f630772fe2eb0e731d8a5cd35cf4a0da79
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
 ldso/include/dl-syscall.h |   41 ++++++++++++++++++++++++++++++++++++-----
 ldso/include/ldso.h       |    4 ++++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h
index acfef52..b1f69ab 100644
--- a/ldso/include/dl-syscall.h
+++ b/ldso/include/dl-syscall.h
@@ -23,7 +23,7 @@ extern int _dl_errno;
 /* Pull in whatever this particular arch's kernel thinks the kernel version of
  * struct stat should look like.  It turns out that each arch has a different
  * opinion on the subject, and different kernel revs use different names... */
-#if defined(__sparc_v9__) && (__WORDSIZE == 64)
+#if !defined __NR_stat || (defined(__sparc_v9__) && (__WORDSIZE == 64))
 #define kernel_stat64 stat
 #define kernel_stat stat
@@ -48,9 +48,18 @@ static __always_inline _syscall1(void, _dl_exit, int, status)
 #define __NR__dl_close __NR_close
 static __always_inline _syscall1(int, _dl_close, int, fd)
-#define __NR__dl_open __NR_open
+#if defined __NR_openat && !defined __NR_open
+static __always_inline int _dl_open(const char *fn,
+						int flags, __kernel_mode_t mode)
+	return INLINE_SYSCALL(openat, 4, AT_FDCWD, fn, flags, mode);
+#elif defined __NR_open
+# define __NR__dl_open __NR_open
 static __always_inline _syscall3(int, _dl_open, const char *, fn, int, flags,
                         __kernel_mode_t, mode)
 #define __NR__dl_write __NR_write
 static __always_inline _syscall3(unsigned long, _dl_write, int, fd,
@@ -64,11 +73,27 @@ static __always_inline _syscall3(unsigned long, _dl_read, int, fd,
 static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
                         unsigned long, len, int, prot)
-#define __NR__dl_stat __NR_stat
+#if defined __NR_fstatat64 && !defined __NR_stat
+# define __NR__dl_fstatat64 __NR_fstatat64
+static __always_inline _syscall4(int, _dl_fstatat64, int, fd, const char *,
+				 fn, struct stat *, stat, int, flags)
+static __always_inline int _dl_stat(const char *file_name,
+                        struct stat *buf)
+	return _dl_fstatat64(AT_FDCWD, file_name, buf, 0);
+#elif defined __NR_stat
+# define __NR__dl_stat __NR_stat
 static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
                         struct stat *, buf)
-#define __NR__dl_fstat __NR_fstat
+#if defined __NR_fstat64 && !defined __NR_fstat
+# define __NR__dl_fstat __NR_fstat64
+#elif defined __NR_fstat
+# define __NR__dl_fstat __NR_fstat
 static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf)
 #define __NR__dl_munmap __NR_munmap
@@ -104,9 +129,15 @@ static __always_inline _syscall0(gid_t, _dl_getegid)
 #define __NR__dl_getpid __NR_getpid
 static __always_inline _syscall0(gid_t, _dl_getpid)
-#define __NR__dl_readlink __NR_readlink
+#if defined __NR_readlinkat && !defined __NR_readlink
+# define __NR__dl_readlink __NR_readlinkat
+static __always_inline _syscall4(int, _dl_readlink, int, id, const char *, path,
+						char *, buf, size_t, bufsiz)
+#elif defined __NR_readlink
+# define __NR__dl_readlink __NR_readlink
 static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
                         size_t, bufsiz)
 #ifdef __NR_pread64
 #define __NR___syscall_pread __NR_pread64
diff --git a/ldso/include/ldso.h b/ldso/include/ldso.h
index e0671f7..1e04653 100644
--- a/ldso/include/ldso.h
+++ b/ldso/include/ldso.h
@@ -30,6 +30,10 @@
 #include <stddef.h> /* for ptrdiff_t */
 #include <stdbool.h>
 #define _FCNTL_H
+/* We need this if arch has only new syscalls defined */
+#ifndef AT_FDCWD
+#define AT_FDCWD -100
+#endif /* AT_FDCWD */
 #include <bits/fcntl.h>
 #include <bits/wordsize.h>
 /* Pull in the arch specific type information */

More information about the uClibc-cvs mailing list