Browse Source

ldso: Use newer syscalls if arch does not have the deprecated syscalls

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

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Markos Chandras 11 years ago
parent
commit
634e74f630
2 changed files with 40 additions and 5 deletions
  1. 36 5
      ldso/include/dl-syscall.h
  2. 4 0
      ldso/include/ldso.h

+ 36 - 5
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
 #else
 #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)
+#endif
 
 #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)
+#endif
 
-#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
+#endif
 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)
+#endif
 
 #ifdef __NR_pread64
 #define __NR___syscall_pread __NR_pread64

+ 4 - 0
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 */