Re: [PATCH 38/46] llseek: Use the llseek system call if defined

2012-11-26 Thread Markos Chandras
On 19 November 2012 09:51, Markos Chandras markos.chand...@gmail.com wrote:
 On Sat, Nov 17, 2012 at 8:37 PM, Mike Frysinger vap...@gentoo.org wrote:
 On Tuesday 13 November 2012 06:31:47 Markos Chandras wrote:
 -#if defined __NR__llseek  defined __UCLIBC_HAS_LFS__
 +#if (defined __NR__llseek ||defined __NR_llseek)  defined

 needs a space after that ||

  loff_t lseek64(int fd, loff_t offset, int whence)
  {
   loff_t result;
 +#if defined(__NR_llseek)
 + return (loff_t)(INLINE_SYSCALL(llseek, 5, fd, (off_t)(offset  32),
 + (off_t)(offset  0x), result, whence) ? : result);
 +#else
   return (loff_t)(INLINE_SYSCALL(_llseek, 5, fd, (off_t) (offset  32),
   (off_t) (offset  0x), result, 
 whence) ?: result);
 +#endif
  }

 only difference is first arg ?  so rather than this, put above the func:
 # ifndef __NR__llseek
 #  define __NR__llseek __NR_llseek
 # endif
 -mike

 Thanks Mike. I'll do that

 --
 Regards,
 Markos

I see this is already fixed in 0.9.33[1]. I guess I overlooked that

http://git.uclibc.org/uClibc/commit/?h=0.9.33id=db27d2f961cfd0838144bdcbc9b30b6ad22950c3

-- 
Regards,
Markos
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 03/46] dup2: Use dup3 if arch does not have the dup2 syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/dup2.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/libc/sysdeps/linux/common/dup2.c b/libc/sysdeps/linux/common/dup2.c
index 006f06b..88856ab 100644
--- a/libc/sysdeps/linux/common/dup2.c
+++ b/libc/sysdeps/linux/common/dup2.c
@@ -9,7 +9,24 @@
 
 #include sys/syscall.h
 #include unistd.h
+#if defined(__NR_dup3)  !defined(__NR_dup2)
+#include fcntl.h
+extern int __libc_fcntl (int fd, int cmd, ...);
+libc_hidden_proto(__libc_fcntl);
 
+int dup2(int old, int newfd)
+{
+   /*
+* Check if old fd is valid before we try
+* to ducplicate it. Return it if valid
+* or EBADF otherwise
+*/
+   if (old == newfd)
+   return __libc_fcntl(old, F_GETFL, 0)  0 ? -1 : newfd;
 
+   return dup3(old, newfd, 0);
+}
+#else
 _syscall2(int, dup2, int, oldfd, int, newfd)
+#endif
 libc_hidden_def(dup2)
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 09/46] chown: Use fchownat if arch does not have the chown syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/unistd.h | 1 +
 libc/sysdeps/linux/common/chown.c| 9 +
 libc/sysdeps/linux/common/fchownat.c | 1 +
 3 files changed, 11 insertions(+)

diff --git a/include/unistd.h b/include/unistd.h
index e58945d..296ae0a 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -469,6 +469,7 @@ extern int lchown (__const char *__file, __uid_t __owner, 
__gid_t __group)
 extern int fchownat (int __fd, __const char *__file, __uid_t __owner,
 __gid_t __group, int __flag)
  __THROW __nonnull ((2)) __wur;
+libc_hidden_proto(fchownat)
 #endif /* Use GNU.  */
 
 /* Change the process's working directory to PATH.  */
diff --git a/libc/sysdeps/linux/common/chown.c 
b/libc/sysdeps/linux/common/chown.c
index f2c60e0..edca3f8 100644
--- a/libc/sysdeps/linux/common/chown.c
+++ b/libc/sysdeps/linux/common/chown.c
@@ -8,9 +8,17 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
 #include unistd.h
 #include bits/wordsize.h
 
+#if defined(__NR_fchownat)  !defined(__NR_chown)
+int chown(const char *path, uid_t owner, gid_t group)
+{
+   return fchownat(AT_FDCWD, path, owner, group, 0);
+}
+
+#else
 
 #if (__WORDSIZE == 32  defined(__NR_chown32)) || __WORDSIZE == 64
 # ifdef __NR_chown32
@@ -37,4 +45,5 @@ int chown(const char *path, uid_t owner, gid_t group)
 }
 #endif
 
+#endif
 libc_hidden_def(chown)
diff --git a/libc/sysdeps/linux/common/fchownat.c 
b/libc/sysdeps/linux/common/fchownat.c
index 707164d..4ad818b 100644
--- a/libc/sysdeps/linux/common/fchownat.c
+++ b/libc/sysdeps/linux/common/fchownat.c
@@ -11,6 +11,7 @@
 
 #ifdef __NR_fchownat
 _syscall5(int, fchownat, int, fd, const char *, file, uid_t, owner, gid_t, 
group, int, flag)
+libc_hidden_def(fchownat)
 #else
 /* should add emulation with fchown() and /proc/self/fd/ ... */
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 16/46] utimes: Use utimensat if arch does not have the utimes syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/utimes.c | 23 +--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/libc/sysdeps/linux/common/utimes.c 
b/libc/sysdeps/linux/common/utimes.c
index 99d9202..3074e4e 100644
--- a/libc/sysdeps/linux/common/utimes.c
+++ b/libc/sysdeps/linux/common/utimes.c
@@ -8,11 +8,30 @@
  */
 
 #include sys/syscall.h
-#include utime.h
 #include sys/time.h
+#include fcntl.h
+#include utime.h
+#include stddef.h
+
 
+#if defined(__NR_utimensat)  !defined(__NR_utimes)
+int utimes(const char *file, const struct timeval tvp[2])
+{
+   struct timespec ts[2], *times;
+   if (tvp) {
+   times = ts;
+   times[0].tv_sec = tvp[0].tv_sec;
+   times[0].tv_nsec = tvp[0].tv_usec * 1000;
+   times[1].tv_sec = tvp[1].tv_sec;
+   times[1].tv_nsec = tvp[1].tv_usec * 1000;
+   } else {
+   times = NULL;
+   }
+
+   return utimensat(AT_FDCWD, file, times, 0);
+}
 
-#ifdef __NR_utimes
+#elif defined(__NR_utimes)
 _syscall2(int, utimes, const char *, file, const struct timeval *, tvp)
 #else
 #include stdlib.h
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 02/46] libc/sysdeps: dup3: check for __NR_dup3 since older kernels/arches lack it

2012-11-26 Thread Markos Chandras
From: Mike Frysinger vap...@gentoo.org

Signed-off-by: Mike Frysinger vap...@gentoo.org
---
 libc/sysdeps/linux/common/dup3.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/sysdeps/linux/common/dup3.c b/libc/sysdeps/linux/common/dup3.c
index 539c071..8a57785 100644
--- a/libc/sysdeps/linux/common/dup3.c
+++ b/libc/sysdeps/linux/common/dup3.c
@@ -10,4 +10,6 @@
 #include sys/syscall.h
 #include unistd.h
 
+#if defined(__NR_dup3)
 _syscall3(int, dup3, int, oldfd, int, newfd, int, flags)
+#endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 04/46] chmod: Use fchmodat if arch does not have the chmod syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/sys/stat.h   | 1 +
 libc/sysdeps/linux/common/chmod.c| 9 +
 libc/sysdeps/linux/common/fchmodat.c | 1 +
 3 files changed, 11 insertions(+)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index 170a4e6..88b7044 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -310,6 +310,7 @@ extern int fchmod (int __fd, __mode_t __mode) __THROW;
 extern int fchmodat (int __fd, __const char *__file, __mode_t __mode,
 int __flag)
  __THROW __nonnull ((2)) __wur;
+libc_hidden_proto(fchmodat)
 #endif /* Use ATFILE.  */
 
 
diff --git a/libc/sysdeps/linux/common/chmod.c 
b/libc/sysdeps/linux/common/chmod.c
index 871e023..c03bb2a 100644
--- a/libc/sysdeps/linux/common/chmod.c
+++ b/libc/sysdeps/linux/common/chmod.c
@@ -9,8 +9,16 @@
 
 #include sys/syscall.h
 #include sys/stat.h
+#include fcntl.h
+#include unistd.h
 
+#if defined(__NR_fchmodat)  !defined(__NR_chmod)
+int chmod(const char *path, mode_t mode)
+{
+   return fchmodat(AT_FDCWD, path, mode, 0);
+}
 
+#else
 #define __NR___syscall_chmod __NR_chmod
 static __inline__ _syscall2(int, __syscall_chmod, const char *, path, 
__kernel_mode_t, mode)
 
@@ -18,4 +26,5 @@ int chmod(const char *path, mode_t mode)
 {
return __syscall_chmod(path, mode);
 }
+#endif
 libc_hidden_def(chmod)
diff --git a/libc/sysdeps/linux/common/fchmodat.c 
b/libc/sysdeps/linux/common/fchmodat.c
index 8224a52..1e936e0 100644
--- a/libc/sysdeps/linux/common/fchmodat.c
+++ b/libc/sysdeps/linux/common/fchmodat.c
@@ -32,6 +32,7 @@ int fchmodat(int fd, const char *file, mode_t mode, int flag)
 
return INLINE_SYSCALL(fchmodat, 3, fd, file, mode);
 }
+libc_hidden_def(fchmodat)
 #else
 /* should add emulation with fchmod() and /proc/self/fd/ ... */
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 07/46] unlink: Use unlinkat if arch does not have the unlink syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/unistd.h | 1 +
 libc/sysdeps/linux/common/unlink.c   | 8 
 libc/sysdeps/linux/common/unlinkat.c | 1 +
 3 files changed, 10 insertions(+)

diff --git a/include/unistd.h b/include/unistd.h
index ee08e19..e58945d 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -859,6 +859,7 @@ libc_hidden_proto(unlink)
 /* Remove the link NAME relative to FD.  */
 extern int unlinkat (int __fd, __const char *__name, int __flag)
  __THROW __nonnull ((2));
+libc_hidden_proto(unlinkat)
 #endif
 
 /* Remove the directory PATH.  */
diff --git a/libc/sysdeps/linux/common/unlink.c 
b/libc/sysdeps/linux/common/unlink.c
index 513cdd5..6ece291 100644
--- a/libc/sysdeps/linux/common/unlink.c
+++ b/libc/sysdeps/linux/common/unlink.c
@@ -8,8 +8,16 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
 #include unistd.h
 
 
+#if defined(__NR_unlinkat)  !defined(__NR_unlink)
+int unlink(const char *pathname)
+{
+   return unlinkat(AT_FDCWD, pathname, 0);
+}
+#else
 _syscall1(int, unlink, const char *, pathname)
+#endif
 libc_hidden_def(unlink)
diff --git a/libc/sysdeps/linux/common/unlinkat.c 
b/libc/sysdeps/linux/common/unlinkat.c
index 0eaf2b6..432af1b 100644
--- a/libc/sysdeps/linux/common/unlinkat.c
+++ b/libc/sysdeps/linux/common/unlinkat.c
@@ -11,6 +11,7 @@
 
 #ifdef __NR_unlinkat
 _syscall3(int, unlinkat, int, fd, const char *, file, int, flag)
+libc_hidden_def(unlinkat)
 #else
 /* should add emulation with unlink() and /proc/self/fd/ ... */
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 00/46] Support for cut-down Linux syscalls

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Hi,

This is the v2 of the patchset I sent on the 13th of November 2012[1].

Changes since v1:

- drop dup3 patch and cherry-pick the dup3 patches from master branch[2]
- Fix dup2 to check if file descriptors are the same before calling
dup3[3]
- Make vfork act as fork() instead of clone()[4]
- Coding style fixes (char* foo - char *foo, ! defined - !defined etc)[5][6]
- Add missing libc_hidden_{proto,def} for internal calls.[7]
- Fix libc stubs for deprecated syscalls that may be implemented using the newer
ones (such as fstatfs, ustat, sendfile, fork, inotify_init, epoll_wait,
epoll_create)[8]
- Revert __IPC_64 patch and add a simple #ifndef/#endif macro to allow
architectures to override its value in the uClibc_arch_features.h[9]
- Revert logic for ARCH_HAS_NO_DEPRECATED_SYSCALLS.[10]

I will only post the patches that changed significantly since the first 
revision.

All patches are based on the 0.9.33 branch and are available in the
following git repository:
https://github.com/hwoarang/uClibc
git://github.com/hwoarang/uClibc.git 0.9.33-syscalls-for-upstream

[1]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047110.html
[2]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047175.html
[3]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047160.html
[4]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047161.html
[5]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047173.html
[6]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047172.html
[7]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047171.html
[8]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047177.html
[9]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047162.html
[10]: http://lists.uclibc.org/pipermail/uclibc/2012-November/047179.html

Markos Chandras (44):
  dup2: Use dup3 if arch does not have the dup2 syscall
  chmod: Use fchmodat if arch does not have the chmod syscall
  access: Use faccessat if arch does not have the access syscall
  link: Use linkat if arch does not have the link syscall
  unlink: Use unlinkat if arch does not have the unlink syscall
  mknod: Use mknodat if arch does not have the mknod syscall
  chown: Use fchownat if arch does not have the chown syscall
  rmdir: Use unlinkat if arch does not have the rmdir syscall
  lchown: Use fchownat if arch does not have the lchown syscall
  mkdir: Use mkdirat if arch does not have the mkdir syscall
  rename: Use renameat if arch does not have the rename syscall
  readlink: Use readlinkat if arch does not have the readlink syscall
  symlink: Use symlinkat if arch does not have the symlink syscall
  utimes: Use utimensat if arch does not have the utimes syscall
  pipe: Use pipe2 if arch does not have the pipe syscall
  epoll: Use epoll_create1 if arch does not have the epoll_create
syscall
  epoll: Use epoll_pwait if arch does not have the epoll_wait syscall
  inotify_init: Use inotify_init1 if inotify_init syscall is not
defined
  utime: Use utimensat if arch does not have the utime syscall
  vfork: Use fork if arch does not have the vfork syscall
  fork: Use clone if arch does not have the fork syscall
  ftruncate: Use ftruncate64 if arch does not have the ftruncate
syscall
  truncate: Use truncate64 if arch does not have the truncate syscall
  sendfile: Use sendfile64 if arch does not have the sendfile syscall
  getdents: Use getdents64 if arch does not have the getdents syscall
  statfs: Use statfs64 if arch does not have the statfs syscall
  fstatat: Use newfstatat only for 64-bit operations
  fstatat64: Use newfstatat only for 64-bit operations
  stat64: Use fstatat64 if arch does not have the stat64 syscall
  lstat: Use fstatat64 if arch does not have the lstat syscall
  lstat64: Use fstatat64 if arch does not have the lstat64 syscall
  ustat: Add ustat stub for arches that don't have the ustat system
call
  stat: Use fstatat64 if arch does not have the stat syscall
  fstat: Use fstat64() if arch does not have the fstat syscall
  fstatfs: Add __libc_fstatfs wrapper
  fstatfs64: Prefer fstatfs64 system call instead of __libc_fstatfs
  fcntl: Use fcntl64 is arch does not have the fcntl syscall
  openat: Add openat syscall for NPTL
  open64: Use openat if arch does not have the open syscall
  not-cancel.h: Use openat if arch does not have the open syscall
  open-wrapper: Use a wrapper for the open() symbol
  ldso: Use newer syscalls if arch does not have the deprecated
syscalls
  libc/ipc: Allow architectures to define their own __IPC_64 macro
  Config.in: Introduce symbol for arches with deprecated syscalls

Mike Frysinger (2):
  libc/sysdeps: add dup3 syscall wrapper
  libc/sysdeps: dup3: check for __NR_dup3 since older kernels/arches
lack it

 extra/Configs/Config.alpha |  1 +
 extra/Configs/Config.arm   |  1 +
 extra/Configs/Config.avr32 |  1 +
 

[PATCH v2 01/46] libc/sysdeps: add dup3 syscall wrapper

2012-11-26 Thread Markos Chandras
From: Mike Frysinger vap...@gentoo.org

Some projects (like udev) are starting to use this.

Signed-off-by: Mike Frysinger vap...@gentoo.org
---
 include/unistd.h  |  6 ++
 libc/sysdeps/linux/common/Makefile.in |  1 +
 libc/sysdeps/linux/common/dup3.c  | 13 +
 3 files changed, 20 insertions(+)
 create mode 100644 libc/sysdeps/linux/common/dup3.c

diff --git a/include/unistd.h b/include/unistd.h
index 1b2fd4d..766fcf3 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -513,6 +513,12 @@ extern int dup (int __fd) __THROW __wur;
 extern int dup2 (int __fd, int __fd2) __THROW;
 libc_hidden_proto(dup2)
 
+#ifdef __USE_GNU
+/* Duplicate FD to FD2, closing FD2 and making it open on the same
+   file while setting flags according to FLAGS.  */
+extern int dup3 (int __fd, int __fd2, int __flags) __THROW;
+#endif
+
 /* NULL-terminated array of NAME=VALUE environment variables.  */
 extern char **__environ;
 #ifdef __USE_GNU
diff --git a/libc/sysdeps/linux/common/Makefile.in 
b/libc/sysdeps/linux/common/Makefile.in
index b39082b..bbffd9a 100644
--- a/libc/sysdeps/linux/common/Makefile.in
+++ b/libc/sysdeps/linux/common/Makefile.in
@@ -23,6 +23,7 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \
bdflush.c \
capget.c \
capset.c \
+   dup3.c \
eventfd.c \
inotify.c \
ioperm.c \
diff --git a/libc/sysdeps/linux/common/dup3.c b/libc/sysdeps/linux/common/dup3.c
new file mode 100644
index 000..539c071
--- /dev/null
+++ b/libc/sysdeps/linux/common/dup3.c
@@ -0,0 +1,13 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * dup2() for uClibc
+ *
+ * Copyright (C) 2000-2006 Erik Andersen ander...@uclibc.org
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include sys/syscall.h
+#include unistd.h
+
+_syscall3(int, dup3, int, oldfd, int, newfd, int, flags)
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 06/46] link: Use linkat if arch does not have the link syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/unistd.h   | 1 +
 libc/sysdeps/linux/common/link.c   | 9 +
 libc/sysdeps/linux/common/linkat.c | 1 +
 3 files changed, 11 insertions(+)

diff --git a/include/unistd.h b/include/unistd.h
index 1540aa9..ee08e19 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -823,6 +823,7 @@ extern int link (__const char *__from, __const char *__to)
 extern int linkat (int __fromfd, __const char *__from, int __tofd,
   __const char *__to, int __flags)
  __THROW __nonnull ((2, 4)) __wur;
+libc_hidden_proto(linkat)
 #endif
 
 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
diff --git a/libc/sysdeps/linux/common/link.c b/libc/sysdeps/linux/common/link.c
index b5e5536..5856caa 100644
--- a/libc/sysdeps/linux/common/link.c
+++ b/libc/sysdeps/linux/common/link.c
@@ -8,5 +8,14 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
 #include unistd.h
+
+#if defined(__NR_linkat)  !defined(__NR_link)
+int link(const char *oldpath, const char *newpath)
+{
+   return linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
+}
+#else
 _syscall2(int, link, const char *, oldpath, const char *, newpath)
+#endif
diff --git a/libc/sysdeps/linux/common/linkat.c 
b/libc/sysdeps/linux/common/linkat.c
index 9abe9ec..26a3d08 100644
--- a/libc/sysdeps/linux/common/linkat.c
+++ b/libc/sysdeps/linux/common/linkat.c
@@ -11,6 +11,7 @@
 
 #ifdef __NR_linkat
 _syscall5(int, linkat, int, fromfd, const char *, from, int, tofd, const char 
*, to, int, flags)
+libc_hidden_def(linkat)
 #else
 /* should add emulation with link() and /proc/self/fd/ ... */
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 05/46] access: Use faccessat if arch does not have the access syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/unistd.h  |  1 +
 libc/sysdeps/linux/common/access.c| 10 ++
 libc/sysdeps/linux/common/faccessat.c |  1 +
 3 files changed, 12 insertions(+)

diff --git a/include/unistd.h b/include/unistd.h
index 766fcf3..1540aa9 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -274,6 +274,7 @@ extern int eaccess (__const char *__name, int __type)
otherwise use real IDs like `access'.  */
 extern int faccessat (int __fd, __const char *__file, int __type, int __flag)
  __THROW __nonnull ((2)) __wur;
+libc_hidden_proto(faccessat)
 #endif /* Use GNU.  */
 
 
diff --git a/libc/sysdeps/linux/common/access.c 
b/libc/sysdeps/linux/common/access.c
index a075d42..fd676d9 100644
--- a/libc/sysdeps/linux/common/access.c
+++ b/libc/sysdeps/linux/common/access.c
@@ -8,5 +8,15 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
 #include unistd.h
+
+#if defined(__NR_faccessat)  !defined(__NR_access)
+int access(const char *pathname, int mode)
+{
+   return faccessat(AT_FDCWD, pathname, mode, 0);
+}
+
+#else
 _syscall2(int, access, const char *, pathname, int, mode)
+#endif
diff --git a/libc/sysdeps/linux/common/faccessat.c 
b/libc/sysdeps/linux/common/faccessat.c
index 09ca129..ba84953 100644
--- a/libc/sysdeps/linux/common/faccessat.c
+++ b/libc/sysdeps/linux/common/faccessat.c
@@ -12,5 +12,6 @@
 #ifdef __NR_faccessat
 _syscall4(int, faccessat, int, fd, const char *, file, int, type, int, flag)
 #else
+libc_hidden_def(faccessat)
 /* should add emulation with faccess() and /proc/self/fd/ ... */
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 13/46] rename: Use renameat if arch does not have the rename syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/stdio.h  | 1 +
 libc/sysdeps/linux/common/rename.c   | 9 -
 libc/sysdeps/linux/common/renameat.c | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/stdio.h b/include/stdio.h
index 289b861..c531d88 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -152,6 +152,7 @@ __END_NAMESPACE_STD
 /* Rename file OLD relative to OLDFD to NEW relative to NEWFD.  */
 extern int renameat (int __oldfd, __const char *__old, int __newfd,
 __const char *__new) __THROW;
+libc_hidden_proto(renameat)
 #endif
 
 __BEGIN_NAMESPACE_STD
diff --git a/libc/sysdeps/linux/common/rename.c 
b/libc/sysdeps/linux/common/rename.c
index 9d8397a..bc4ea6f 100644
--- a/libc/sysdeps/linux/common/rename.c
+++ b/libc/sysdeps/linux/common/rename.c
@@ -8,11 +8,18 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
 #include unistd.h
 #include string.h
 #include sys/param.h
 #include stdio.h
 
+#if defined(__NR_renameat)  !defined(__NR_rename)
+int rename(const char *oldpath, const char *newpath)
+{
+   return renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
+}
+#else
 #define __NR___syscall_rename __NR_rename
 static __inline__ _syscall2(int, __syscall_rename, const char *, oldpath,
const char *, newpath)
@@ -21,4 +28,4 @@ int rename(const char * oldpath, const char * newpath)
 {
return __syscall_rename(oldpath, newpath);
 }
-
+#endif
diff --git a/libc/sysdeps/linux/common/renameat.c 
b/libc/sysdeps/linux/common/renameat.c
index a898f7b..b0b91fa 100644
--- a/libc/sysdeps/linux/common/renameat.c
+++ b/libc/sysdeps/linux/common/renameat.c
@@ -11,6 +11,7 @@
 
 #ifdef __NR_renameat
 _syscall4(int, renameat, int, oldfd, const char *, old, int, newfd, const char 
*, new)
+libc_hidden_def(renameat)
 #else
 /* should add emulation with rename() and /proc/self/fd/ ... */
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 08/46] mknod: Use mknodat if arch does not have the mknod syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/mknod.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libc/sysdeps/linux/common/mknod.c 
b/libc/sysdeps/linux/common/mknod.c
index b52c8c5..9e31ef3 100644
--- a/libc/sysdeps/linux/common/mknod.c
+++ b/libc/sysdeps/linux/common/mknod.c
@@ -9,7 +9,14 @@
 
 #include sys/syscall.h
 #include sys/stat.h
+#include fcntl.h
 
+#if defined(__NR_mknodat)  !defined(__NR_mknod)
+int mknod(const char *path, mode_t mode, dev_t dev)
+{
+   return mknodat(AT_FDCWD, path, mode, dev);
+}
+#else
 int mknod(const char *path, mode_t mode, dev_t dev)
 {
unsigned long long int k_dev;
@@ -19,4 +26,5 @@ int mknod(const char *path, mode_t mode, dev_t dev)
 
return INLINE_SYSCALL(mknod, 3, path, mode, (unsigned int)k_dev);
 }
+#endif
 libc_hidden_def(mknod)
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 17/46] pipe: Use pipe2 if arch does not have the pipe syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/pipe.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libc/sysdeps/linux/common/pipe.c b/libc/sysdeps/linux/common/pipe.c
index 8eae27c..614cc24 100644
--- a/libc/sysdeps/linux/common/pipe.c
+++ b/libc/sysdeps/linux/common/pipe.c
@@ -11,5 +11,13 @@
 #include unistd.h
 
 
+#if defined(__NR_pipe2)  !defined(__NR_pipe)
+int pipe(int filedes[2])
+{
+   return pipe2(filedes, 0);
+}
+/* If both are defined then use the pipe syscall */
+#else
 _syscall1(int, pipe, int *, filedes)
+#endif
 libc_hidden_def(pipe)
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 12/46] mkdir: Use mkdirat if arch does not have the mkdir syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/sys/stat.h  | 1 +
 libc/sysdeps/linux/common/mkdir.c   | 8 
 libc/sysdeps/linux/common/mkdirat.c | 1 +
 3 files changed, 10 insertions(+)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index 88b7044..e04fd44 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -336,6 +336,7 @@ libc_hidden_proto(mkdir)
with FD.  */
 extern int mkdirat (int __fd, __const char *__path, __mode_t __mode)
  __THROW __nonnull ((2));
+libc_hidden_proto(mkdirat)
 #endif
 
 /* Create a device file named PATH, with permission and special bits MODE
diff --git a/libc/sysdeps/linux/common/mkdir.c 
b/libc/sysdeps/linux/common/mkdir.c
index fbc587d..933812b 100644
--- a/libc/sysdeps/linux/common/mkdir.c
+++ b/libc/sysdeps/linux/common/mkdir.c
@@ -9,8 +9,15 @@
 
 #include sys/syscall.h
 #include sys/stat.h
+#include fcntl.h
 
+#if defined(__NR_mkdirat)  !defined(__NR_mkdir)
+int mkdir(const char *pathname, mode_t mode)
+{
+   return mkdirat(AT_FDCWD, pathname, mode);
+}
 
+#else
 #define __NR___syscall_mkdir __NR_mkdir
 static __inline__ _syscall2(int, __syscall_mkdir, const char *, pathname,
__kernel_mode_t, mode)
@@ -19,4 +26,5 @@ int mkdir(const char *pathname, mode_t mode)
 {
return (__syscall_mkdir(pathname, mode));
 }
+#endif
 libc_hidden_def(mkdir)
diff --git a/libc/sysdeps/linux/common/mkdirat.c 
b/libc/sysdeps/linux/common/mkdirat.c
index 4da9468..871104b 100644
--- a/libc/sysdeps/linux/common/mkdirat.c
+++ b/libc/sysdeps/linux/common/mkdirat.c
@@ -11,6 +11,7 @@
 
 #ifdef __NR_mkdirat
 _syscall3(int, mkdirat, int, fd, const char *, path, mode_t, mode)
+libc_hidden_def(mkdirat)
 #else
 /* should add emulation with mkdir() and /proc/self/fd/ ... */
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 10/46] rmdir: Use unlinkat if arch does not have the rmdir syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/rmdir.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libc/sysdeps/linux/common/rmdir.c 
b/libc/sysdeps/linux/common/rmdir.c
index bad6654..4d12a22 100644
--- a/libc/sysdeps/linux/common/rmdir.c
+++ b/libc/sysdeps/linux/common/rmdir.c
@@ -8,8 +8,16 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
 #include unistd.h
 
 
+#if defined(__NR_unlinkat)  !defined(__NR_rmdir)
+int rmdir(const char *pathname)
+{
+   return unlinkat(AT_FDCWD, pathname, AT_REMOVEDIR);
+}
+#else
 _syscall1(int, rmdir, const char *, pathname)
+#endif
 libc_hidden_def(rmdir)
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 15/46] symlink: Use symlinkat if arch does not have the symlink syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/unistd.h  |  1 +
 libc/sysdeps/linux/common/symlink.c   | 13 +
 libc/sysdeps/linux/common/symlinkat.c |  1 +
 3 files changed, 15 insertions(+)

diff --git a/include/unistd.h b/include/unistd.h
index bd75bbf..7f4db6d 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -845,6 +845,7 @@ libc_hidden_proto(readlink)
 /* Like symlink but a relative path in TO is interpreted relative to TOFD.  */
 extern int symlinkat (__const char *__from, int __tofd,
  __const char *__to) __THROW __nonnull ((1, 3)) __wur;
+libc_hidden_proto(symlinkat)
 
 /* Like readlink but a relative PATH is interpreted relative to FD.  */
 extern ssize_t readlinkat (int __fd, __const char *__restrict __path,
diff --git a/libc/sysdeps/linux/common/symlink.c 
b/libc/sysdeps/linux/common/symlink.c
index e53e8d4..ab52015 100644
--- a/libc/sysdeps/linux/common/symlink.c
+++ b/libc/sysdeps/linux/common/symlink.c
@@ -9,6 +9,19 @@
 
 #include sys/syscall.h
 #if defined __USE_BSD || defined __USE_UNIX98 || defined __USE_XOPEN2K
+#include fcntl.h
 #include unistd.h
+
+#if defined(__NR_symlinkat)  !defined(__NR_symlink)
+int symlink(const char *oldpath, const char *newpath)
+{
+   return symlinkat(oldpath, AT_FDCWD, newpath);
+}
+
+#else
+
 _syscall2(int, symlink, const char *, oldpath, const char *, newpath)
+
+#endif
+
 #endif
diff --git a/libc/sysdeps/linux/common/symlinkat.c 
b/libc/sysdeps/linux/common/symlinkat.c
index 6381b33..9181581 100644
--- a/libc/sysdeps/linux/common/symlinkat.c
+++ b/libc/sysdeps/linux/common/symlinkat.c
@@ -11,6 +11,7 @@
 
 #ifdef __NR_symlinkat
 _syscall3(int, symlinkat, const char *, from, int, tofd, const char *, to)
+libc_hidden_def(symlinkat)
 #else
 /* should add emulation with symlink() and /proc/self/fd/ ... */
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 14/46] readlink: Use readlinkat if arch does not have the readlink syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/unistd.h   | 1 +
 libc/sysdeps/linux/common/readlink.c   | 8 
 libc/sysdeps/linux/common/readlinkat.c | 1 +
 3 files changed, 10 insertions(+)

diff --git a/include/unistd.h b/include/unistd.h
index 296ae0a..bd75bbf 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -850,6 +850,7 @@ extern int symlinkat (__const char *__from, int __tofd,
 extern ssize_t readlinkat (int __fd, __const char *__restrict __path,
   char *__restrict __buf, size_t __len)
  __THROW __nonnull ((2, 3)) __wur;
+libc_hidden_proto(readlinkat)
 #endif
 
 /* Remove the link NAME.  */
diff --git a/libc/sysdeps/linux/common/readlink.c 
b/libc/sysdeps/linux/common/readlink.c
index ef9e835..5dfd82c 100644
--- a/libc/sysdeps/linux/common/readlink.c
+++ b/libc/sysdeps/linux/common/readlink.c
@@ -8,7 +8,15 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
 #include unistd.h
 
+#if defined(__NR_readlinkat)  !defined(__NR_readlink)
+ssize_t readlink (const char *path, char *buf, size_t len)
+{
+   return readlinkat(AT_FDCWD, path, buf, len);
+}
+#else
 _syscall3(ssize_t, readlink, const char *, path, char *, buf, size_t, bufsiz)
+#endif
 libc_hidden_def(readlink)
diff --git a/libc/sysdeps/linux/common/readlinkat.c 
b/libc/sysdeps/linux/common/readlinkat.c
index d0a98e1..995b9e2 100644
--- a/libc/sysdeps/linux/common/readlinkat.c
+++ b/libc/sysdeps/linux/common/readlinkat.c
@@ -11,6 +11,7 @@
 
 #ifdef __NR_readlinkat
 _syscall4(ssize_t, readlinkat, int, fd, const char *, path, char *, buf, 
size_t, len)
+libc_hidden_def(readlinkat)
 #else
 /* should add emulation with readlink() and /proc/self/fd/ ... */
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 18/46] epoll: Use epoll_create1 if arch does not have the epoll_create syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/epoll.c | 20 ++--
 libc/sysdeps/linux/common/stubs.c |  2 +-
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/libc/sysdeps/linux/common/epoll.c 
b/libc/sysdeps/linux/common/epoll.c
index ab3e73b..f07ab94 100644
--- a/libc/sysdeps/linux/common/epoll.c
+++ b/libc/sysdeps/linux/common/epoll.c
@@ -16,17 +16,25 @@
 #endif
 
 /*
- * epoll_create()
+ * epoll_create1()
  */
-#ifdef __NR_epoll_create
-_syscall1(int, epoll_create, int, size)
+#if defined(__NR_epoll_create1)
+_syscall1(int, epoll_create1, int, flags)
 #endif
 
+#if defined(__NR_epoll_create1)  !defined(__NR_epoll_create)
+int epoll_create(int size)
+{
+   return INLINE_SYSCALL(epoll_create1, 1, 0);
+}
+
 /*
- * epoll_create1()
+ * epoll_create()
  */
-#ifdef __NR_epoll_create1
-_syscall1(int, epoll_create1, int, flags)
+
+/* For systems that have both, prefer the old one */
+#elif defined(__NR_epoll_create)
+_syscall1(int, epoll_create, int, size)
 #endif
 
 /*
diff --git a/libc/sysdeps/linux/common/stubs.c 
b/libc/sysdeps/linux/common/stubs.c
index 7af14c1..3b6df48 100644
--- a/libc/sysdeps/linux/common/stubs.c
+++ b/libc/sysdeps/linux/common/stubs.c
@@ -81,7 +81,7 @@ make_stub(create_module)
 make_stub(delete_module)
 #endif
 
-#ifndef __NR_epoll_create
+#if !defined(__NR_epoll_create)  !defined(__NR_epoll_create1)
 make_stub(epoll_create)
 #endif
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 20/46] inotify_init: Use inotify_init1 if inotify_init syscall is not defined

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/inotify.c | 14 ++
 libc/sysdeps/linux/common/stubs.c   |  3 ++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/libc/sysdeps/linux/common/inotify.c 
b/libc/sysdeps/linux/common/inotify.c
index e2f3836..8f5aa25 100644
--- a/libc/sysdeps/linux/common/inotify.c
+++ b/libc/sysdeps/linux/common/inotify.c
@@ -11,12 +11,18 @@
 #include sys/syscall.h
 #include sys/inotify.h
 
-#ifdef __NR_inotify_init
-_syscall0(int, inotify_init)
+#if defined(__NR_inotify_init1)
+_syscall1(int, inotify_init1, int, flags)
 #endif
 
-#ifdef __NR_inotify_init1
-_syscall1(int, inotify_init1, int, flags)
+#if defined(__NR_inotify_init1)  !defined(__NR_inotify_init)
+int inotify_init(void)
+{
+   return INLINE_SYSCALL(inotify_init1, 1, 0);
+}
+
+#elif defined(__NR_intofity_init)
+_syscall0(int, inotify_init)
 #endif
 
 #ifdef __NR_inotify_add_watch
diff --git a/libc/sysdeps/linux/common/stubs.c 
b/libc/sysdeps/linux/common/stubs.c
index e96e458..b7e0357 100644
--- a/libc/sysdeps/linux/common/stubs.c
+++ b/libc/sysdeps/linux/common/stubs.c
@@ -157,7 +157,8 @@ make_stub(getxattr)
 make_stub(init_module)
 #endif
 
-#if !defined __NR_inotify_init  defined __UCLIBC_LINUX_SPECIFIC__
+#if !defined __NR_inotify_init  !defined(__NR_inotify_init1) \
+defined __UCLIBC_LINUX_SPECIFIC__
 make_stub(inotify_init)
 #endif
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 25/46] truncate: Use truncate64 if arch does not have the truncate syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/unistd.h   | 1 +
 libc/sysdeps/linux/common/truncate.c   | 9 +
 libc/sysdeps/linux/common/truncate64.c | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/unistd.h b/include/unistd.h
index 7f4db6d..8151726 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -1044,6 +1044,7 @@ extern int __REDIRECT_NTH (truncate,
 # ifdef __USE_LARGEFILE64
 extern int truncate64 (__const char *__file, __off64_t __length)
  __THROW __nonnull ((1)) __wur;
+libc_hidden_proto(truncate64)
 # endif
 
 #endif /* Use BSD || X/Open Unix.  */
diff --git a/libc/sysdeps/linux/common/truncate.c 
b/libc/sysdeps/linux/common/truncate.c
index 2331bdd..cbdd3bd 100644
--- a/libc/sysdeps/linux/common/truncate.c
+++ b/libc/sysdeps/linux/common/truncate.c
@@ -11,5 +11,14 @@
 #include unistd.h
 
 
+#if defined(__NR_truncate64)  !defined(__NR_truncate)
+int truncate(const char *path, __off_t length)
+{
+   return truncate64(path, length);
+}
+libc_hidden_def(truncate);
+
+#else
 _syscall2(int, truncate, const char *, path, __off_t, length)
 libc_hidden_def(truncate)
+#endif
diff --git a/libc/sysdeps/linux/common/truncate64.c 
b/libc/sysdeps/linux/common/truncate64.c
index 1f6c459..f0bb4b1 100644
--- a/libc/sysdeps/linux/common/truncate64.c
+++ b/libc/sysdeps/linux/common/truncate64.c
@@ -64,5 +64,5 @@ int truncate64(const char * path, __off64_t length)
 }
 
 #endif /* __NR_truncate64 */
-
+libc_hidden_def(truncate64)
 #endif /* __UCLIBC_HAS_LFS__ */
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 27/46] getdents: Use getdents64 if arch does not have the getdents syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/getdents.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libc/sysdeps/linux/common/getdents.c 
b/libc/sysdeps/linux/common/getdents.c
index 46f7b8e..9823e5d 100644
--- a/libc/sysdeps/linux/common/getdents.c
+++ b/libc/sysdeps/linux/common/getdents.c
@@ -44,10 +44,12 @@ struct kernel_dirent
 
 ssize_t __getdents (int fd, char *buf, size_t nbytes) attribute_hidden;
 
+#if defined(__NR_getdents)
 #define __NR___syscall_getdents __NR_getdents
 static __always_inline _syscall3(int, __syscall_getdents, int, fd, unsigned 
char *, kdirp, size_t, count)
+#endif
 
-#if defined __ASSUME_GETDENTS32_D_TYPE
+#if defined __ASSUME_GETDENTS32_D_TYPE  defined __NR_getdents
 
 ssize_t __getdents (int fd, char *buf, size_t nbytes)
 {
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 33/46] lstat64: Use fstatat64 if arch does not have the lstat64 syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/lstat64.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/libc/sysdeps/linux/common/lstat64.c 
b/libc/sysdeps/linux/common/lstat64.c
index 235b76d..89c8707 100644
--- a/libc/sysdeps/linux/common/lstat64.c
+++ b/libc/sysdeps/linux/common/lstat64.c
@@ -9,12 +9,22 @@
 
 #include sys/syscall.h
 
-#if defined __UCLIBC_HAS_LFS__  defined __NR_lstat64
+#if defined __UCLIBC_HAS_LFS__
+# include fcntl.h
 # include unistd.h
 # include sys/stat.h
 # include xstatconv.h
 
 
+#if defined(__NR_fstatat64)  !defined(__NR_lstat64)
+int lstat64(const char *file_name, struct stat64 *buf)
+{
+   return fstatat64(AT_FDCWD, file_name, buf, AT_SYMLINK_NOFOLLOW);
+}
+libc_hidden_def(lstat64)
+
+/* For systems which have both, prefer the old one */
+#elif defined(__NR_lstat64)
 # define __NR___syscall_lstat64 __NR_lstat64
 static __inline__ _syscall2(int, __syscall_lstat64, const char *, file_name,
  struct kernel_stat64 *, buf)
@@ -33,3 +43,5 @@ int lstat64(const char *file_name, struct stat64 *buf)
 libc_hidden_def(lstat64)
 
 #endif
+
+#endif /* __UCLIBC_HAS_LFS__ */
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 26/46] sendfile: Use sendfile64 if arch does not have the sendfile syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/sys/sendfile.h |  1 +
 libc/sysdeps/linux/common/sendfile.c   | 44 +++---
 libc/sysdeps/linux/common/sendfile64.c |  1 +
 libc/sysdeps/linux/common/stubs.c  |  3 ++-
 4 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/include/sys/sendfile.h b/include/sys/sendfile.h
index 4c1367b..6280234 100644
--- a/include/sys/sendfile.h
+++ b/include/sys/sendfile.h
@@ -45,6 +45,7 @@ extern ssize_t __REDIRECT_NTH (sendfile,
 #ifdef __USE_LARGEFILE64
 extern ssize_t sendfile64 (int __out_fd, int __in_fd, __off64_t *__offset,
   size_t __count) __THROW;
+libc_hidden_proto(sendfile64)
 #endif
 
 __END_DECLS
diff --git a/libc/sysdeps/linux/common/sendfile.c 
b/libc/sysdeps/linux/common/sendfile.c
index 89bab9f..63ce37a 100644
--- a/libc/sysdeps/linux/common/sendfile.c
+++ b/libc/sysdeps/linux/common/sendfile.c
@@ -8,16 +8,54 @@
  */
 
 #include sys/syscall.h
+#include stddef.h
 #include unistd.h
 #include sys/sendfile.h
 
-#ifdef __NR_sendfile
+#if defined(__NR_sendfile64)  !defined(__NR_sendfile)
+ssize_t sendfile(int out_fd, int in_fd, __off_t *offset, size_t count)
+{
+   __off64_t off64, *off;
+   ssize_t res;
 
+   /*
+* Check if valids fd and valid pointers were passed
+* This does not prevent the user from passing
+* an arbitrary pointer causing a segfault or
+* other security issues
+*/
+
+   if (in_fd  0 || out_fd  0) {
+   __set_errno(EBADF);
+   return -1;
+   }
+
+   if (offset == NULL || (int)offset  0) {
+   __set_errno(EFAULT);
+   return -1;
+   }
+
+   if (offset) {
+   off = off64;
+   off64 = *offset;
+   } else {
+   off = NULL;
+   }
+
+   res = INLINE_SYSCALL(sendfile64, 4, out_fd, in_fd, off, count);
+
+   if (res = 0)
+   *offset = off64;
+
+   return res;
+}
+
+#elif defined(__NR_sendfile)
 _syscall4(ssize_t, sendfile, int, out_fd, int, in_fd, __off_t *, offset,
  size_t, count)
 
-#if ! defined __NR_sendfile64  defined __UCLIBC_HAS_LFS__
+#if ! defined(__NR_sendfile64)  defined(__UCLIBC_HAS_LFS__)
 strong_alias(sendfile,sendfile64)
 #endif
 
-#endif /* __NR_sendfile */
+#endif
diff --git a/libc/sysdeps/linux/common/sendfile64.c 
b/libc/sysdeps/linux/common/sendfile64.c
index fc5155f..9a59485 100644
--- a/libc/sysdeps/linux/common/sendfile64.c
+++ b/libc/sysdeps/linux/common/sendfile64.c
@@ -21,4 +21,5 @@
 
 #if defined __UCLIBC_HAS_LFS__  defined __NR_sendfile64
 _syscall4(ssize_t,sendfile64, int, out_fd, int, in_fd, __off64_t *, offset, 
size_t, count)
+libc_hidden_def(sendfile64)
 #endif
diff --git a/libc/sysdeps/linux/common/stubs.c 
b/libc/sysdeps/linux/common/stubs.c
index 9cb8de0..1837195 100644
--- a/libc/sysdeps/linux/common/stubs.c
+++ b/libc/sysdeps/linux/common/stubs.c
@@ -278,7 +278,8 @@ make_stub(sched_setaffinity)
 make_stub(send)
 #endif
 
-#if !defined __NR_sendfile  defined __UCLIBC_LINUX_SPECIFIC__
+#if !defined __NR_sendfile  !defined(__NR_sendfile64) \
+defined __UCLIBC_LINUX_SPECIFIC__
 make_stub(sendfile)
 #endif
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 34/46] ustat: Add ustat stub for arches that don't have the ustat system call

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/stubs.c | 4 
 libc/sysdeps/linux/common/ustat.c | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/libc/sysdeps/linux/common/stubs.c 
b/libc/sysdeps/linux/common/stubs.c
index 1837195..160d27f 100644
--- a/libc/sysdeps/linux/common/stubs.c
+++ b/libc/sysdeps/linux/common/stubs.c
@@ -396,6 +396,10 @@ make_stub(umount2)
 make_stub(unshare)
 #endif
 
+#if !defined __NR_ustat
+make_stub(ustat)
+#endif
+
 #ifndef __NR_utimensat
 make_stub(futimens)
 make_stub(utimensat)
diff --git a/libc/sysdeps/linux/common/ustat.c 
b/libc/sysdeps/linux/common/ustat.c
index e97fa76..1bcb581 100644
--- a/libc/sysdeps/linux/common/ustat.c
+++ b/libc/sysdeps/linux/common/ustat.c
@@ -11,6 +11,7 @@
 #include sys/ustat.h
 #include sys/sysmacros.h
 
+#ifdef __NR_ustat
 #define __NR___syscall_ustat __NR_ustat
 /* Kernel's fs/super.c defines this:
  * long sys_ustat(unsigned dev, struct ustat __user * ubuf),
@@ -24,3 +25,4 @@ int ustat(dev_t dev, struct ustat *ubuf)
 {
return __syscall_ustat(dev, ubuf);
 }
+#endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 21/46] utime: Use utimensat if arch does not have the utime syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/utime.c | 22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/libc/sysdeps/linux/common/utime.c 
b/libc/sysdeps/linux/common/utime.c
index c9fd1bf..75d4d2c 100644
--- a/libc/sysdeps/linux/common/utime.c
+++ b/libc/sysdeps/linux/common/utime.c
@@ -8,10 +8,30 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
+#include stddef.h
 #include utime.h
 
 
-#ifdef __NR_utime
+#if defined(__NR_utimensat)  !defined(__NR_utime)
+int utime(const char *file, const struct utimbuf *times)
+{
+   struct timespec tspecs[2], *ts;
+
+   if (times) {
+   ts = tspecs;
+   ts[0].tv_sec = times-actime;
+   ts[0].tv_nsec = 0;
+   ts[1].tv_sec = times-modtime;
+   ts[1].tv_nsec = 0;
+   } else {
+   ts = NULL;
+   }
+
+   return utimensat(AT_FDCWD, file, ts, 0);
+}
+
+#elif defined(__NR_utime)
 _syscall2(int, utime, const char *, file, const struct utimbuf *, times)
 #else
 #include stdlib.h
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 24/46] ftruncate: Use ftruncate64 if arch does not have the ftruncate syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/ftruncate.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libc/sysdeps/linux/common/ftruncate.c 
b/libc/sysdeps/linux/common/ftruncate.c
index 3bdef3f..72f86f9 100644
--- a/libc/sysdeps/linux/common/ftruncate.c
+++ b/libc/sysdeps/linux/common/ftruncate.c
@@ -11,5 +11,14 @@
 #include unistd.h
 
 
+#if defined(__NR_ftruncate64)  !defined(__NR_ftruncate)
+int ftruncate(int fd, __off_t length)
+{
+   return ftruncate64(fd, length);
+}
+libc_hidden_def(ftruncate);
+
+#else
 _syscall2(int, ftruncate, int, fd, __off_t, length)
 libc_hidden_def(ftruncate)
+#endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 38/46] fstatfs64: Prefer fstatfs64 system call instead of __libc_fstatfs

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Using __libc_fstatfs for fstatfs64 adds a small delay as it needs to
use a 32-bit data structure to get the file info and them pass them to
the 64-bit data structure which was given as a fstatfs64 argument. Using
the system call directly should make the entire process much faster.
Also fix the arguments for fstatfs64. It takes three arguments
(see fs/fstatfs.c in Linux kernel sources) so despite what the manpage
says, the size of the buffer needs to be passed as the second argument

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/misc/statfs/fstatfs64.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libc/misc/statfs/fstatfs64.c b/libc/misc/statfs/fstatfs64.c
index 27bb8d6..0cb710f 100644
--- a/libc/misc/statfs/fstatfs64.c
+++ b/libc/misc/statfs/fstatfs64.c
@@ -23,8 +23,10 @@
 #include string.h
 #include sys/statfs.h
 #include sys/statvfs.h
+#include sys/syscall.h
 #include stddef.h
 
+#if defined(__NR_fstatfs)
 extern __typeof(fstatfs) __libc_fstatfs;
 
 /* Return information about the filesystem on which FD resides.  */
@@ -48,4 +50,16 @@ int fstatfs64 (int fd, struct statfs64 *buf)
 
 return 0;
 }
+#else
+/*
+ * Use the fstatfs64 system call if fstatfs is not defined
+ * This is for backwards compatibility and it should be
+ * made default in the future
+ */
+int fstatfs64(int fd, struct statfs64 *buf)
+{
+   /* Signature has 2 arguments but syscalls wants 3 */
+   return INLINE_SYSCALL(fstatfs64, 3, fd, sizeof(*buf), buf);
+}
+#endif
 libc_hidden_def(fstatfs64)
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 29/46] fstatat: Use newfstatat only for 64-bit operations

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/fstatat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/sysdeps/linux/common/fstatat.c 
b/libc/sysdeps/linux/common/fstatat.c
index 33daa7c..a0bc3cd 100644
--- a/libc/sysdeps/linux/common/fstatat.c
+++ b/libc/sysdeps/linux/common/fstatat.c
@@ -11,7 +11,7 @@
 #include xstatconv.h
 
 /* 64bit ports tend to favor newfstatat() */
-#ifdef __NR_newfstatat
+#if __WORDSIZE == 64  defined __NR_newfstatat
 # define __NR_fstatat64 __NR_newfstatat
 #endif
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 28/46] statfs: Use statfs64 if arch does not have the statfs syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/sys/statfs.h   |  1 +
 libc/sysdeps/linux/common/statfs.c | 53 +-
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/include/sys/statfs.h b/include/sys/statfs.h
index c754ea3..de42696 100644
--- a/include/sys/statfs.h
+++ b/include/sys/statfs.h
@@ -31,6 +31,7 @@ __BEGIN_DECLS
 #ifndef __USE_FILE_OFFSET64
 extern int statfs (__const char *__file, struct statfs *__buf)
  __THROW __nonnull ((1, 2));
+libc_hidden_proto(statfs)
 #else
 # ifdef __REDIRECT_NTH
 extern int __REDIRECT_NTH (statfs,
diff --git a/libc/sysdeps/linux/common/statfs.c 
b/libc/sysdeps/linux/common/statfs.c
index d24bc9d..34c2fcf 100644
--- a/libc/sysdeps/linux/common/statfs.c
+++ b/libc/sysdeps/linux/common/statfs.c
@@ -12,11 +12,62 @@
 #include sys/param.h
 #include sys/vfs.h
 
+#if defined(__NR_statfs64)  !defined(__NR_statfs)
 extern __typeof(statfs) __libc_statfs attribute_hidden;
+
+int __libc_statfs(const char *path, struct statfs *buf)
+{
+   struct statfs64 b;
+   int err;
+
+   /*
+* See if pointer has a sane value.
+* This does not prevent the user from
+* passing an arbitrary possitive value
+* that can lead to a segfault or potential
+* security problems
+*/
+
+   if (buf == NULL || (int)buf  0) {
+   __set_errno(EFAULT);
+   return -1;
+   }
+
+   err = INLINE_SYSCALL(statfs64, 3, path, sizeof(b), b);
+
+   if (err  0)
+   return -1;
+
+   buf-f_type = b.f_type;
+   buf-f_bsize = b.f_bsize;
+   buf-f_blocks = b.f_blocks;
+   buf-f_bfree = b.f_bfree;
+   buf-f_bavail = b.f_bavail;
+   buf-f_files = b.f_files;
+   buf-f_ffree = b.f_ffree;
+   buf-f_namelen = b.f_namelen;
+   buf-f_frsize = b.f_frsize;
+   buf-f_fsid = b.f_fsid;
+   memcpy(buf-f_spare, b.f_spare, sizeof(b.f_spare));
+
+   return err;
+}
+#if defined __UCLIBC_LINUX_SPECIFIC__ || defined __UCLIBC_HAS_THREADS_NATIVE__
+/* statfs is used by NPTL, so it must exported in case */
+weak_alias(__libc_statfs, statfs)
+#endif
+
+/* For systems which have both, prefer the old one */
+#else
+extern __typeof(statfs) __libc_statfs attribute_hidden;
+
 #define __NR___libc_statfs __NR_statfs
 _syscall2(int, __libc_statfs, const char *, path, struct statfs *, buf)
 
 #if defined __UCLIBC_LINUX_SPECIFIC__ || defined __UCLIBC_HAS_THREADS_NATIVE__
 /* statfs is used by NPTL, so it must exported in case */
-weak_alias(__libc_statfs,statfs)
+weak_alias(__libc_statfs, statfs)
+#endif
+
 #endif
+libc_hidden_def(statfs)
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 35/46] stat: Use fstatat64 if arch does not have the stat syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/stat.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libc/sysdeps/linux/common/stat.c b/libc/sysdeps/linux/common/stat.c
index 829f35a..038e0c0 100644
--- a/libc/sysdeps/linux/common/stat.c
+++ b/libc/sysdeps/linux/common/stat.c
@@ -8,12 +8,21 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
 #include unistd.h
 #include sys/stat.h
 #include xstatconv.h
 
 #undef stat
 
+#if defined(__NR_fstat64)  !defined(__NR_stat)
+int stat(const char *file_name, struct stat *buf)
+{
+   return fstatat(AT_FDCWD, file_name, buf, 0);
+}
+
+#else
+
 int stat(const char *file_name, struct stat *buf)
 {
int result;
@@ -35,12 +44,14 @@ int stat(const char *file_name, struct stat *buf)
if (result == 0) {
__xstat_conv(kbuf, buf);
}
-#endif
+#endif /* __NR_stat64 */
return result;
 }
+#endif /* __NR_fstat64 */
 libc_hidden_def(stat)
 
-#if ! defined __NR_stat64  defined __UCLIBC_HAS_LFS__
+#if ! defined __NR_stat64  ! defined __NR_fstatat64  \
+   defined __UCLIBC_HAS_LFS__
 strong_alias_untyped(stat,stat64)
 libc_hidden_def(stat64)
-#endif
+#endif /* __UCLIBC_HAS_LFS__ */
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 39/46] fcntl: Use fcntl64 is arch does not have the fcntl syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/__syscall_fcntl.c   | 57 +--
 libc/sysdeps/linux/common/__syscall_fcntl64.c |  5 +++
 2 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/libc/sysdeps/linux/common/__syscall_fcntl.c 
b/libc/sysdeps/linux/common/__syscall_fcntl.c
index 6d4c339..7cc598c 100644
--- a/libc/sysdeps/linux/common/__syscall_fcntl.c
+++ b/libc/sysdeps/linux/common/__syscall_fcntl.c
@@ -19,6 +19,53 @@
 extern __typeof(fcntl) __libc_fcntl;
 libc_hidden_proto(__libc_fcntl)
 
+
+#if defined(__NR_fcntl64)  !defined (__NR_fcntl)
+
+int __libc_fcntl (int fd, int cmd, ...)
+{
+   va_list ap;
+   void *arg;
+
+   va_start (ap, cmd);
+   arg = va_arg (ap, void*);
+   va_end (ap);
+
+   return INLINE_SYSCALL(fcntl64, 3, fd, cmd, arg);
+}
+libc_hidden_def(__libc_fcntl)
+
+int __fcntl_nocancel (int fd, int cmd, ...)
+{
+   va_list ap;
+   void *arg;
+
+   va_start (ap, cmd);
+   arg = va_arg (ap, void*);
+   va_end (ap);
+
+#ifdef __UCLIBC_HAS_THREADS_NATIVE__
+   if (SINGLE_THREAD_P)
+   return INLINE_SYSCALL(fcntl64, 3, fd, cmd, arg);
+
+   int oldtype = LIBC_CANCEL_ASYNC ();
+
+   int result = INLINE_SYSCALL(fcntl64, 3, fd, cmd, arg);
+
+   LIBC_CANCEL_RESET (oldtype);
+
+   return result;
+
+#else
+
+   return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
+
+#endif
+}
+libc_hidden_def(__fcntl_nocancel)
+
+#else
+
 int __fcntl_nocancel (int fd, int cmd, ...)
 {
va_list ap;
@@ -70,7 +117,9 @@ int __libc_fcntl (int fd, int cmd, ...)
LIBC_CANCEL_RESET (oldtype);
 
return result;
-#else
+
+#else /* __UCLIBC_HAS_THREADS_NATIVE__ */
+
 # if __WORDSIZE == 32
if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
 #  if defined __UCLIBC_HAS_LFS__  defined __NR_fcntl64
@@ -80,12 +129,14 @@ int __libc_fcntl (int fd, int cmd, ...)
return -1;
 #  endif
}
-# endif
+# endif /* __WORDSIZE */
return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
-#endif
+#endif /* __UCLIBC_HAS_THREADS_NATIVE__ */
 }
 libc_hidden_def(__libc_fcntl)
 
+#endif
+
 libc_hidden_proto(fcntl)
 weak_alias(__libc_fcntl,fcntl)
 libc_hidden_weak(fcntl)
diff --git a/libc/sysdeps/linux/common/__syscall_fcntl64.c 
b/libc/sysdeps/linux/common/__syscall_fcntl64.c
index e8782e9..96f1bae 100644
--- a/libc/sysdeps/linux/common/__syscall_fcntl64.c
+++ b/libc/sysdeps/linux/common/__syscall_fcntl64.c
@@ -27,4 +27,9 @@ int fcntl64(int fd, int cmd, ...)
return (__syscall_fcntl64(fd, cmd, arg));
 }
 libc_hidden_def(fcntl64)
+
+#if !defined(__NR_fcntl)
+strong_alias(fcntl64, fcntl)
+#endif /* !__NR_fcntl__ */
+
 #endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 42/46] not-cancel.h: Use openat if arch does not have the open syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/not-cancel.h   | 7 +++
 libpthread/linuxthreads.old/sysdeps/pthread/not-cancel.h | 9 +
 libpthread/linuxthreads/sysdeps/pthread/not-cancel.h | 9 +
 libpthread/nptl/sysdeps/unix/sysv/linux/not-cancel.h | 9 +
 4 files changed, 34 insertions(+)

diff --git a/libc/sysdeps/linux/common/not-cancel.h 
b/libc/sysdeps/linux/common/not-cancel.h
index 9418417..f46571a 100644
--- a/libc/sysdeps/linux/common/not-cancel.h
+++ b/libc/sysdeps/linux/common/not-cancel.h
@@ -21,10 +21,17 @@
 #include sysdep.h
 
 /* Uncancelable open.  */
+#if defined(__NR_openat)  !defined(__NR_open)
+#define open_not_cancel(name, flags, mode) \
+   INLINE_SYSCALL (openat, 4, AT_FDCWD, (const char *) (name), (flags), (mode))
+#define open_not_cancel_2(name, flags) \
+   INLINE_SYSCALL (openat, 3, AT_FDCWD, (const char *) (name), (flags))
+#else
 #define open_not_cancel(name, flags, mode) \
INLINE_SYSCALL (open, 3, (const char *) (name), (flags), (mode))
 #define open_not_cancel_2(name, flags) \
INLINE_SYSCALL (open, 2, (const char *) (name), (flags))
+#endif
 
 /* Uncancelable close.  */
 #define close_not_cancel(fd) \
diff --git a/libpthread/linuxthreads.old/sysdeps/pthread/not-cancel.h 
b/libpthread/linuxthreads.old/sysdeps/pthread/not-cancel.h
index 80d33be..261c274 100644
--- a/libpthread/linuxthreads.old/sysdeps/pthread/not-cancel.h
+++ b/libpthread/linuxthreads.old/sysdeps/pthread/not-cancel.h
@@ -22,10 +22,19 @@
 #include sysdep.h
 
 /* Uncancelable open.  */
+#if defined(__NR_openat)  !defined(__NR_open)
+#define open_not_cancel(name, flags, mode) \
+   INLINE_SYSCALL (openat, 4, AT_FDCWD, (const char *) (name), \
+   (flags), (mode))
+#define open_not_cancel_2(name, flags) \
+   INLINE_SYSCALL (openat, 3, AT_FDCWD, (const char *) (name), \
+   (flags))
+#else
 #define open_not_cancel(name, flags, mode) \
INLINE_SYSCALL (open, 3, (const char *) (name), (flags), (mode))
 #define open_not_cancel_2(name, flags) \
INLINE_SYSCALL (open, 2, (const char *) (name), (flags))
+#endif
 
 /* Uncancelable openat.  */
 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
diff --git a/libpthread/linuxthreads/sysdeps/pthread/not-cancel.h 
b/libpthread/linuxthreads/sysdeps/pthread/not-cancel.h
index 80d33be..f5eef39 100644
--- a/libpthread/linuxthreads/sysdeps/pthread/not-cancel.h
+++ b/libpthread/linuxthreads/sysdeps/pthread/not-cancel.h
@@ -22,10 +22,19 @@
 #include sysdep.h
 
 /* Uncancelable open.  */
+#if defined(__NR_openat)  !defined(__NR_open)
+#define open_not_cancel(name, flags, mode) \
+   INLINE_SYSCALL (openat, 4, (int) (AT_FDCWD), (const char *) (name), \
+   (flags), (mode))
+#define open_not_cancel_2(name, flags) \
+   INLINE_SYSCALL (openat, 3, (int) (AT_FDCWD), (const char *) (name), \
+   (flags))
+#else
 #define open_not_cancel(name, flags, mode) \
INLINE_SYSCALL (open, 3, (const char *) (name), (flags), (mode))
 #define open_not_cancel_2(name, flags) \
INLINE_SYSCALL (open, 2, (const char *) (name), (flags))
+#endif
 
 /* Uncancelable openat.  */
 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/not-cancel.h 
b/libpthread/nptl/sysdeps/unix/sysv/linux/not-cancel.h
index 80d33be..261c274 100644
--- a/libpthread/nptl/sysdeps/unix/sysv/linux/not-cancel.h
+++ b/libpthread/nptl/sysdeps/unix/sysv/linux/not-cancel.h
@@ -22,10 +22,19 @@
 #include sysdep.h
 
 /* Uncancelable open.  */
+#if defined(__NR_openat)  !defined(__NR_open)
+#define open_not_cancel(name, flags, mode) \
+   INLINE_SYSCALL (openat, 4, AT_FDCWD, (const char *) (name), \
+   (flags), (mode))
+#define open_not_cancel_2(name, flags) \
+   INLINE_SYSCALL (openat, 3, AT_FDCWD, (const char *) (name), \
+   (flags))
+#else
 #define open_not_cancel(name, flags, mode) \
INLINE_SYSCALL (open, 3, (const char *) (name), (flags), (mode))
 #define open_not_cancel_2(name, flags) \
INLINE_SYSCALL (open, 2, (const char *) (name), (flags))
+#endif
 
 /* Uncancelable openat.  */
 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 40/46] openat: Add openat syscall for NPTL

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/Makefile.in  |  2 +-
 .../sysdeps/unix/sysv/linux/Makefile.commonarch|  4 +++-
 libpthread/nptl/sysdeps/unix/sysv/linux/openat.S   | 22 ++
 3 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/openat.S

diff --git a/libc/sysdeps/linux/common/Makefile.in 
b/libc/sysdeps/linux/common/Makefile.in
index bbffd9a..3663e91 100644
--- a/libc/sysdeps/linux/common/Makefile.in
+++ b/libc/sysdeps/linux/common/Makefile.in
@@ -65,7 +65,7 @@ CSRC-$(if $(findstring 
yy,$(UCLIBC_LINUX_SPECIFIC)$(UCLIBC_HAS_LFS)),y) += \
 # NPTL needs these internally: madvise.c
 CSRC-$(findstring y,$(UCLIBC_LINUX_SPECIFIC)$(UCLIBC_HAS_THREADS_NATIVE)) += 
madvise.c
 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
-CSRC- += fork.c getpid.c raise.c open.c close.c read.c write.c
+CSRC- += fork.c getpid.c raise.c open.c openat.c close.c read.c write.c
 CSRC- += $(if $(findstring =arm=,=$(TARGET_ARCH)=),vfork.c)
 CSRC- += $(if $(findstring =x86_64=,=$(TARGET_ARCH)=),vfork.c)
 CSRC- += $(if $(findstring 
=mips=y=,=$(TARGET_ARCH)=$(CONFIG_MIPS_O32_ABI)=),waitpid.c)
diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/Makefile.commonarch 
b/libpthread/nptl/sysdeps/unix/sysv/linux/Makefile.commonarch
index 8a762b7..ab2d6c9 100644
--- a/libpthread/nptl/sysdeps/unix/sysv/linux/Makefile.commonarch
+++ b/libpthread/nptl/sysdeps/unix/sysv/linux/Makefile.commonarch
@@ -77,7 +77,7 @@ librt_linux_CSRC += mq_notify.c timer_create.c timer_delete.c 
\
timer_settime.c
 
 # These provide both a cancellable and a not cancellable implementation
-libc_linux_SSRC = close.S open.S write.S read.S waitpid.S
+libc_linux_SSRC = close.S open.S openat.S write.S read.S waitpid.S
 libc_linux_SSRC := $(filter-out 
$(libc_linux_arch_SSRC-OMIT),$(libc_linux_SSRC))
 
 libpthread_linux_CSRC := $(filter-out $(notdir 
$(libpthread_linux_arch_OBJS:.o=.c)),$(libpthread_linux_CSRC))
@@ -145,6 +145,7 @@ CFLAGS-OMIT-libc-lowlevellock.c = -DNOT_IN_libc 
-DIS_IN_libpthread
 
 CFLAGS-OMIT-close.S = -DNOT_IN_libc -DIS_IN_libpthread
 CFLAGS-OMIT-open.S = -DNOT_IN_libc -DIS_IN_libpthread
+CFLAGS-OMIT-openat.S = -DNOT_IN_libc -DIS_IN_libpthread
 CFLAGS-OMIT-read.S = -DNOT_IN_libc -DIS_IN_libpthread
 CFLAGS-OMIT-write.S = -DNOT_IN_libc -DIS_IN_libpthread
 CFLAGS-OMIT-waitpid.S = -DNOT_IN_libc -DIS_IN_libpthread
@@ -158,6 +159,7 @@ CFLAGS-OMIT-timer_routines.c = -DIS_IN_libpthread
 CFLAGS-OMIT-timer_settime.c = -DIS_IN_libpthread
 
 ASFLAGS-open.S = -D_LIBC_REENTRANT
+ASFLAGS-openat.S = -D_LIBC_REENTRANT
 ASFLAGS-close.S = -D_LIBC_REENTRANT
 ASFLAGS-read.S = -D_LIBC_REENTRANT
 ASFLAGS-write.S = -D_LIBC_REENTRANT
diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/openat.S 
b/libpthread/nptl/sysdeps/unix/sysv/linux/openat.S
new file mode 100644
index 000..468154b
--- /dev/null
+++ b/libpthread/nptl/sysdeps/unix/sysv/linux/openat.S
@@ -0,0 +1,22 @@
+#include sysdep-cancel.h
+
+/*
+extern int __openat_nocancel (const char *, int, ...) attribute_hidden;
+*/
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+#if defined(__NR_openat)
+PSEUDO (__libc_openat, openat, 4)
+ret
+PSEUDO_END(__libc_openat)
+
+libc_hidden_def (__openat_nocancel)
+libc_hidden_def (__libc_openat)
+weak_alias (__libc_openat, __openat)
+libc_hidden_weak (__openat)
+weak_alias (__libc_openat, openat)
+libc_hidden_weak (openat)
+
+#endif
+
+#endif
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 43/46] open-wrapper: Use a wrapper for the open() symbol

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Internal libc operations, gcc and other packages require for libc to
define an open() symbol. In case the arch does not have NR_open, we define
this symbol to be a wrapper to the openat syscall.

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/Makefile.in  |  2 +-
 libc/sysdeps/linux/common/open-wrapper.c   | 77 ++
 libc/sysdeps/linux/common/open.c   | 39 -
 libpthread/linuxthreads.old/wrapsyscall.c  |  3 +-
 libpthread/nptl/sysdeps/unix/sysv/linux/open.S |  8 ++-
 5 files changed, 87 insertions(+), 42 deletions(-)
 create mode 100644 libc/sysdeps/linux/common/open-wrapper.c
 delete mode 100644 libc/sysdeps/linux/common/open.c

diff --git a/libc/sysdeps/linux/common/Makefile.in 
b/libc/sysdeps/linux/common/Makefile.in
index 3663e91..3e947c1 100644
--- a/libc/sysdeps/linux/common/Makefile.in
+++ b/libc/sysdeps/linux/common/Makefile.in
@@ -65,7 +65,7 @@ CSRC-$(if $(findstring 
yy,$(UCLIBC_LINUX_SPECIFIC)$(UCLIBC_HAS_LFS)),y) += \
 # NPTL needs these internally: madvise.c
 CSRC-$(findstring y,$(UCLIBC_LINUX_SPECIFIC)$(UCLIBC_HAS_THREADS_NATIVE)) += 
madvise.c
 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
-CSRC- += fork.c getpid.c raise.c open.c openat.c close.c read.c write.c
+CSRC- += fork.c getpid.c raise.c openat.c close.c read.c write.c
 CSRC- += $(if $(findstring =arm=,=$(TARGET_ARCH)=),vfork.c)
 CSRC- += $(if $(findstring =x86_64=,=$(TARGET_ARCH)=),vfork.c)
 CSRC- += $(if $(findstring 
=mips=y=,=$(TARGET_ARCH)=$(CONFIG_MIPS_O32_ABI)=),waitpid.c)
diff --git a/libc/sysdeps/linux/common/open-wrapper.c 
b/libc/sysdeps/linux/common/open-wrapper.c
new file mode 100644
index 000..2377843
--- /dev/null
+++ b/libc/sysdeps/linux/common/open-wrapper.c
@@ -0,0 +1,77 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * open() for uClibc
+ *
+ * Copyright (C) 2000-2006 Erik Andersen ander...@uclibc.org
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include sys/syscall.h
+#include stdlib.h
+#include stdarg.h
+#include fcntl.h
+#include string.h
+#include sys/param.h
+
+#if defined(__NR_open)
+#define __NR___syscall_open __NR_open
+static __inline__ _syscall3(int, __syscall_open, const char *, file,
+   int, flags, __kernel_mode_t, mode)
+#endif
+
+/* NPTL has its own implementation */
+#if ! defined(__UCLIBC_HAS_THREADS_NATIVE__)
+int open(const char *file, int oflag, ...)
+{
+   mode_t mode = 0;
+
+   if (oflag  O_CREAT) {
+   va_list arg;
+   va_start(arg, oflag);
+   mode = va_arg(arg, mode_t);
+   va_end(arg);
+   }
+#if defined(__NR_openat)  !defined(__NR_open)
+   return openat(AT_FDCWD, file, oflag, mode);
+#else
+   return __syscall_open(file, oflag, mode);
+#endif
+}
+
+#else
+#if defined(__NR_openat)  !defined(__NR_open)
+/*
+ * Arches that don't support the open() syscall, need to
+ * define a symbol for that so other packages that rely
+ * on it, can build and run successfully
+ */
+int open(const char *file, int oflag, ...)
+{
+   mode_t mode = 0;
+
+   va_list arg;
+   va_start(arg, oflag);
+   mode = va_arg(arg, mode_t);
+   va_end(arg);
+
+   return openat(AT_FDCWD, file, oflag, mode);
+}
+
+#else
+/*
+ * The implementation for open() is defined in the NTPL source files.
+ * We must not define it here, to avoid symbol collisions
+ */
+#endif
+
+#endif /* __UCLIBC_HAS_THREADS_NATIVE__ */
+
+#ifdef __LINUXTHREADS_NEW__
+libc_hidden_def(open)
+#elif defined(__LINUXTHREADS_OLD__) || \
+( defined(__UCLIBC_HAS_THREADS_NATIVE__)  defined(__NR_openat) \
+ !defined(__NR_open) )
+libc_hidden_weak(open)
+strong_alias(open, __libc_open)
+#endif
diff --git a/libc/sysdeps/linux/common/open.c b/libc/sysdeps/linux/common/open.c
deleted file mode 100644
index 9fb694d..000
--- a/libc/sysdeps/linux/common/open.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * open() for uClibc
- *
- * Copyright (C) 2000-2006 Erik Andersen ander...@uclibc.org
- *
- * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
- */
-
-#include sys/syscall.h
-#include stdlib.h
-#include stdarg.h
-#include fcntl.h
-#include string.h
-#include sys/param.h
-
-#define __NR___syscall_open __NR_open
-static __inline__ _syscall3(int, __syscall_open, const char *, file,
-   int, flags, __kernel_mode_t, mode)
-
-int open(const char *file, int oflag, ...)
-{
-   mode_t mode = 0;
-
-   if (oflag  O_CREAT) {
-   va_list arg;
-   va_start(arg, oflag);
-   mode = va_arg(arg, mode_t);
-   va_end(arg);
-   }
-
-   return __syscall_open(file, oflag, mode);
-}
-#ifndef __LINUXTHREADS_OLD__
-libc_hidden_def(open)
-#else
-libc_hidden_weak(open)
-strong_alias(open,__libc_open)
-#endif
diff --git a/libpthread/linuxthreads.old/wrapsyscall.c 

[PATCH v2 37/46] fstatfs: Add __libc_fstatfs wrapper

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

New architectures don't have fstatfs anymore, so we use a wrapper for
__libc_fstatfs which will use fstatfs64 internally. The interface however
needs to remain the same (i.e accepting a struct statfs as a second
argument) for backwards compatibility

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/fstatfs.c | 43 -
 libc/sysdeps/linux/common/stubs.c   |  3 ++-
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/libc/sysdeps/linux/common/fstatfs.c 
b/libc/sysdeps/linux/common/fstatfs.c
index fa0024a..82efdc9 100644
--- a/libc/sysdeps/linux/common/fstatfs.c
+++ b/libc/sysdeps/linux/common/fstatfs.c
@@ -9,8 +9,9 @@
 
 #include sys/syscall.h
 #include sys/vfs.h
+#include string.h
 
-#ifndef __USE_FILE_OFFSET64
+#if ! defined(__USE_FILE_OFFSET64)
 extern int fstatfs (int __fildes, struct statfs *__buf)
  __THROW __nonnull ((2));
 #else
@@ -23,8 +24,48 @@ extern int __REDIRECT_NTH (fstatfs, (int __fildes, struct 
statfs *__buf),
 #endif
 
 extern __typeof(fstatfs) __libc_fstatfs attribute_hidden;
+#ifdef __NR_fstatfs
 #define __NR___libc_fstatfs __NR_fstatfs
 _syscall2(int, __libc_fstatfs, int, fd, struct statfs *, buf)
+#else
+/* Backwards compatibility for __libc_fstatfs */
+int __libc_fstatfs (int __fildes, struct statfs *__buf)
+{
+   struct statfs64 b;
+   int err;
+
+   /*
+* Check if __buf has a sane value.
+* This does not prevent the user from passing
+* an artitrary possitive value that can lead to
+* segfault or other security problems
+*/
+   if ( __buf == NULL || (int)__buf  0) {
+   __set_errno(EFAULT);
+   return -1;
+   }
+
+   err = INLINE_SYSCALL(fstatfs64, 3, __fildes, sizeof(b), b);
+
+   if (err  0)
+   return -1;
+
+   memset(__buf, 0x00, sizeof(*__buf));
+   __buf-f_type = b.f_type;
+   __buf-f_bsize = b.f_bsize;
+   __buf-f_blocks = b.f_blocks;
+   __buf-f_bfree = b.f_bfree;
+   __buf-f_bavail = b.f_bavail;
+   __buf-f_files = b.f_files;
+   __buf-f_ffree = b.f_ffree;
+   __buf-f_namelen = b.f_namelen;
+   __buf-f_frsize = b.f_frsize;
+   __buf-f_fsid = b.f_fsid;
+   memcpy(__buf-f_spare, b.f_spare, sizeof(b.f_spare));
+   return err;
+};
+/* Redefined fstatfs because we need it for backwards compatibility */
+#endif /* __NR_fstatfs */
 
 #if defined __UCLIBC_LINUX_SPECIFIC__
 weak_alias(__libc_fstatfs,fstatfs)
diff --git a/libc/sysdeps/linux/common/stubs.c 
b/libc/sysdeps/linux/common/stubs.c
index 160d27f..967f074 100644
--- a/libc/sysdeps/linux/common/stubs.c
+++ b/libc/sysdeps/linux/common/stubs.c
@@ -121,7 +121,8 @@ make_stub(fremovexattr)
 make_stub(fsetxattr)
 #endif
 
-#if !defined __NR_fstatfs  defined __UCLIBC_LINUX_SPECIFIC__
+#if !defined __NR_fstatfs  !defined(__NR_fstatfs64) \
+defined __UCLIBC_LINUX_SPECIFIC__
 make_stub(fstatfs)
 #endif
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 44/46] ldso: Use newer syscalls if arch does not have the deprecated syscalls

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 ldso/include/dl-syscall.h | 88 +++
 ldso/include/ldso.h   |  4 +++
 2 files changed, 92 insertions(+)

diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h
index 547dad1..3c7d762 100644
--- a/ldso/include/dl-syscall.h
+++ b/ldso/include/dl-syscall.h
@@ -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)
 
+#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,12 +73,85 @@ 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)
 
+#if defined(__NR_fstatat64)  !defined(__NR_stat)
+static __always_inline int _dl_stat(const char *file_name,
+struct stat *buf)
+{
+   int ret;
+   struct kernel_stat64 kbuf;
+   size_t n;
+   register unsigned char *p;
+
+   ret = INLINE_SYSCALL(fstatat64, 4, AT_FDCWD, file_name, kbuf, 0);
+
+   if (ret == 0) {
+   /* We have no libc so we need to implement our own memset */
+   n = sizeof(*buf);
+   p = buf;
+   while(n) {
+   *p++ = 0;
+   --n;
+   }
+   buf-st_dev = kbuf.st_dev;
+   buf-st_ino = kbuf.st_ino;
+   buf-st_mode = kbuf.st_mode;
+   buf-st_nlink = kbuf.st_nlink;
+   buf-st_uid = kbuf.st_uid;
+   buf-st_gid = kbuf.st_gid;
+   buf-st_rdev = kbuf.st_rdev;
+   buf-st_size = kbuf.st_size;
+   buf-st_blksize = kbuf.st_blksize;
+   buf-st_blocks = kbuf.st_blocks;
+   buf-st_atim = kbuf.st_atim;
+   buf-st_mtim = kbuf.st_mtim;
+   buf-st_ctim = kbuf.st_ctim;
+   }
+   return ret;
+}
+#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
 
+#if defined(__NR_fstat64)  !defined(__NR_fstat)
+static __always_inline int _dl_fstat(int fd, struct stat *buf)
+{
+   int result;
+   struct kernel_stat64 kbuf;
+   size_t n;
+   register unsigned char *p;
+
+   result = INLINE_SYSCALL(fstat64, 2, fd, kbuf);
+
+   if (result == 0) {
+   /* We have no libc so we need to implement our own memset */
+   n = sizeof(*buf);
+   p = buf;
+   while(n) {
+   *p++ = 0;
+   --n;
+   }
+   buf-st_dev = kbuf.st_dev;
+   buf-st_ino = kbuf.st_ino;
+   buf-st_mode = kbuf.st_mode;
+   buf-st_nlink = kbuf.st_nlink;
+   buf-st_uid = kbuf.st_uid;
+   buf-st_gid = kbuf.st_gid;
+   buf-st_rdev = kbuf.st_rdev;
+   buf-st_size = kbuf.st_size;
+   buf-st_blksize = kbuf.st_blksize;
+   buf-st_blocks = kbuf.st_blocks;
+   buf-st_atim = kbuf.st_atim;
+   buf-st_mtim = kbuf.st_mtim;
+   buf-st_ctim = kbuf.st_ctim;
+   }
+   return result;
+}
+#elif defined(__NR_fstat)
 #define __NR__dl_fstat __NR_fstat
 static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf)
+#endif
 
 #define __NR__dl_munmap __NR_munmap
 static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned 
long, length)
@@ -104,9 +186,15 @@ static __always_inline _syscall0(gid_t, _dl_getegid)
 #define __NR__dl_getpid __NR_getpid
 static __always_inline _syscall0(gid_t, _dl_getpid)
 
+#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
diff --git a/ldso/include/ldso.h b/ldso/include/ldso.h
index 

[PATCH v2 19/46] epoll: Use epoll_pwait if arch does not have the epoll_wait syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/epoll.c | 10 ++
 libc/sysdeps/linux/common/stubs.c |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libc/sysdeps/linux/common/epoll.c 
b/libc/sysdeps/linux/common/epoll.c
index f07ab94..3278f9d 100644
--- a/libc/sysdeps/linux/common/epoll.c
+++ b/libc/sysdeps/linux/common/epoll.c
@@ -87,5 +87,15 @@ int __libc_epoll_pwait(int epfd, struct epoll_event *events, 
int maxevents,
}
 # endif
 }
+/*
+ * If epoll_wait is not defined, then call epoll_pwait instead using NULL
+ * for sigmask argument
+ */
+#if !defined(__NR_epoll_wait)
+int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int 
timeout)
+{
+   return INLINE_SYSCALL(epoll_pwait, 5, epfd, events, maxevents, timeout, 
NULL);
+}
+#endif
 weak_alias(__libc_epoll_pwait, epoll_pwait)
 #endif
diff --git a/libc/sysdeps/linux/common/stubs.c 
b/libc/sysdeps/linux/common/stubs.c
index 3b6df48..e96e458 100644
--- a/libc/sysdeps/linux/common/stubs.c
+++ b/libc/sysdeps/linux/common/stubs.c
@@ -89,7 +89,7 @@ make_stub(epoll_create)
 make_stub(epoll_ctl)
 #endif
 
-#ifndef __NR_epoll_wait
+#if !defined(__NR_epoll_wait)  !defined(__NR_epoll_pwait)
 make_stub(epoll_wait)
 #endif
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 23/46] fork: Use clone if arch does not have the fork syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/fork.c  | 17 -
 libc/sysdeps/linux/common/stubs.c |  2 +-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/libc/sysdeps/linux/common/fork.c b/libc/sysdeps/linux/common/fork.c
index 14e00a2..7322581 100644
--- a/libc/sysdeps/linux/common/fork.c
+++ b/libc/sysdeps/linux/common/fork.c
@@ -9,10 +9,25 @@
 
 #include sys/syscall.h
 #include unistd.h
+#include unistd.h
+#include signal.h
 
 #ifdef __ARCH_USE_MMU__
 
-#ifdef __NR_fork
+#if defined(__NR_clone)  !defined(__NR_fork)
+pid_t __libc_fork(void)
+{
+   pid_t pid = INLINE_SYSCALL(clone, 4, SIGCHLD, NULL, NULL, NULL);
+
+   if (pid0)
+   return -1;
+
+   return pid;
+}
+weak_alias(__libc_fork, fork)
+libc_hidden_weak(fork)
+
+#elif defined(__NR_fork)
 #define __NR___libc_fork __NR_fork
 extern __typeof(fork) __libc_fork;
 _syscall0(pid_t, __libc_fork)
diff --git a/libc/sysdeps/linux/common/stubs.c 
b/libc/sysdeps/linux/common/stubs.c
index b7e0357..9cb8de0 100644
--- a/libc/sysdeps/linux/common/stubs.c
+++ b/libc/sysdeps/linux/common/stubs.c
@@ -105,7 +105,7 @@ make_stub(fdatasync)
 make_stub(flistxattr)
 #endif
 
-#ifndef __NR_fork
+#if !defined(__NR_fork)  !defined(__NR_clone)
 make_stub(fork)
 #endif
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 32/46] lstat: Use fstatat64 if arch does not have the lstat syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/lstat.c | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/libc/sysdeps/linux/common/lstat.c 
b/libc/sysdeps/linux/common/lstat.c
index db72d1f..9f086f4 100644
--- a/libc/sysdeps/linux/common/lstat.c
+++ b/libc/sysdeps/linux/common/lstat.c
@@ -8,10 +8,20 @@
  */
 
 #include sys/syscall.h
+#include fcntl.h
 #include unistd.h
 #include sys/stat.h
 #include xstatconv.h
 
+#if defined(__NR_fstatat64)  !defined(__NR_lstat)
+int lstat(const char *file_name, struct stat *buf)
+{
+   return fstatat(AT_FDCWD, file_name, buf, AT_SYMLINK_NOFOLLOW);
+}
+libc_hidden_def(lstat)
+
+/* For systems which have both, prefer the old one */
+#else
 int lstat(const char *file_name, struct stat *buf)
 {
int result;
@@ -33,12 +43,15 @@ int lstat(const char *file_name, struct stat *buf)
if (result == 0) {
__xstat_conv(kbuf, buf);
}
-#endif
+#endif /* __NR_lstat64 */
return result;
 }
 libc_hidden_def(lstat)
 
-#if ! defined __NR_lstat64  defined __UCLIBC_HAS_LFS__
+#if ! defined __NR_fstatat64  ! defined __NR_lstat64 \
+defined __UCLIBC_HAS_LFS__
 strong_alias_untyped(lstat,lstat64)
 libc_hidden_def(lstat64)
 #endif
+
+#endif /* __NR_fstatat64 */
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 46/46] Config.in: Introduce symbol for arches with deprecated syscalls

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Linuxthreads(old and new) need deprecated syscalls to build. Existing
architectures support these system calls but new architectures don't.
This symbol has no functional change apart from hidding the Linuxthreads
symbols from arches that don't support them.

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 extra/Configs/Config.alpha  | 1 +
 extra/Configs/Config.arm| 1 +
 extra/Configs/Config.avr32  | 1 +
 extra/Configs/Config.bfin   | 1 +
 extra/Configs/Config.c6x| 1 +
 extra/Configs/Config.cris   | 1 +
 extra/Configs/Config.e1 | 1 +
 extra/Configs/Config.frv| 1 +
 extra/Configs/Config.h8300  | 1 +
 extra/Configs/Config.hppa   | 1 +
 extra/Configs/Config.i386   | 1 +
 extra/Configs/Config.i960   | 1 +
 extra/Configs/Config.ia64   | 1 +
 extra/Configs/Config.in | 2 ++
 extra/Configs/Config.in.arch| 8 
 extra/Configs/Config.m68k   | 1 +
 extra/Configs/Config.microblaze | 1 +
 extra/Configs/Config.mips   | 1 +
 extra/Configs/Config.nios   | 1 +
 extra/Configs/Config.nios2  | 1 +
 extra/Configs/Config.powerpc| 1 +
 extra/Configs/Config.sh | 1 +
 extra/Configs/Config.sh64   | 1 +
 extra/Configs/Config.sparc  | 1 +
 extra/Configs/Config.v850   | 1 +
 extra/Configs/Config.vax| 1 +
 extra/Configs/Config.x86_64 | 1 +
 extra/Configs/Config.xtensa | 1 +
 28 files changed, 36 insertions(+)

diff --git a/extra/Configs/Config.alpha b/extra/Configs/Config.alpha
index 144924a..212df6a 100644
--- a/extra/Configs/Config.alpha
+++ b/extra/Configs/Config.alpha
@@ -13,4 +13,5 @@ config FORCE_OPTIONS_FOR_ARCH
select ARCH_LITTLE_ENDIAN
select ARCH_HAS_MMU
select ARCH_HAS_NO_LDSO
+   select ARCH_HAS_DEPRECATED_SYSCALLS
select UCLIBC_HAS_LFS
diff --git a/extra/Configs/Config.arm b/extra/Configs/Config.arm
index 0bb2971..9473eba 100644
--- a/extra/Configs/Config.arm
+++ b/extra/Configs/Config.arm
@@ -11,6 +11,7 @@ config FORCE_OPTIONS_FOR_ARCH
bool
default y
select ARCH_ANY_ENDIAN
+   select ARCH_HAS_DEPRECATED_SYSCALLS
 
 config CONFIG_ARM_EABI
bool Build for EABI
diff --git a/extra/Configs/Config.avr32 b/extra/Configs/Config.avr32
index cbadb4c..5fcd6f2 100644
--- a/extra/Configs/Config.avr32
+++ b/extra/Configs/Config.avr32
@@ -11,6 +11,7 @@ config FORCE_OPTIONS_FOR_ARCH
bool
default y
select ARCH_BIG_ENDIAN
+   select ARCH_HAS_DEPRECATED_SYSCALLS
select FORCE_SHAREABLE_TEXT_SEGMENTS
 
 choice
diff --git a/extra/Configs/Config.bfin b/extra/Configs/Config.bfin
index a70afcf..c3ed171 100644
--- a/extra/Configs/Config.bfin
+++ b/extra/Configs/Config.bfin
@@ -12,3 +12,4 @@ config FORCE_OPTIONS_FOR_ARCH
default y
select ARCH_LITTLE_ENDIAN
select ARCH_HAS_NO_MMU
+   select ARCH_HAS_DEPRECATED_SYSCALLS
diff --git a/extra/Configs/Config.c6x b/extra/Configs/Config.c6x
index 96adfb3..cc8d647 100644
--- a/extra/Configs/Config.c6x
+++ b/extra/Configs/Config.c6x
@@ -11,6 +11,7 @@ config FORCE_OPTIONS_FOR_ARCH
default y
select ARCH_ANY_ENDIAN
select ARCH_HAS_NO_MMU
+   select ARCH_HAS_DEPRECATED_SYSCALLS
 
 choice
prompt Target Processor Type
diff --git a/extra/Configs/Config.cris b/extra/Configs/Config.cris
index 52ca0c3..c49817f 100644
--- a/extra/Configs/Config.cris
+++ b/extra/Configs/Config.cris
@@ -11,6 +11,7 @@ config FORCE_OPTIONS_FOR_ARCH
bool
default y
select ARCH_LITTLE_ENDIAN
+   select ARCH_HAS_DEPRECATED_SYSCALLS
 
 choice
prompt Target Architecture Type
diff --git a/extra/Configs/Config.e1 b/extra/Configs/Config.e1
index ecaa9f0..284bbfa 100644
--- a/extra/Configs/Config.e1
+++ b/extra/Configs/Config.e1
@@ -13,3 +13,4 @@ config FORCE_OPTIONS_FOR_ARCH
select ARCH_BIG_ENDIAN
select ARCH_HAS_NO_MMU
select ARCH_HAS_NO_SHARED
+   select ARCH_HAS_DEPRECATED_SYSCALLS
diff --git a/extra/Configs/Config.frv b/extra/Configs/Config.frv
index b389870..d7eeaf9 100644
--- a/extra/Configs/Config.frv
+++ b/extra/Configs/Config.frv
@@ -13,3 +13,4 @@ config FORCE_OPTIONS_FOR_ARCH
select ARCH_BIG_ENDIAN
select UCLIBC_HAS_FPU
select ARCH_HAS_NO_MMU
+   select ARCH_HAS_DEPRECATED_SYSCALLS
diff --git a/extra/Configs/Config.h8300 b/extra/Configs/Config.h8300
index ffcb9c8..458851b 100644
--- a/extra/Configs/Config.h8300
+++ b/extra/Configs/Config.h8300
@@ -12,6 +12,7 @@ config FORCE_OPTIONS_FOR_ARCH
default y
select ARCH_ANY_ENDIAN
select ARCH_HAS_NO_MMU
+   select ARCH_HAS_DEPRECATED_SYSCALLS
 
 choice
prompt Target Processor
diff --git a/extra/Configs/Config.hppa b/extra/Configs/Config.hppa
index 1323de2..938e2e3 100644
--- a/extra/Configs/Config.hppa
+++ b/extra/Configs/Config.hppa
@@ -15,3 +15,4 @@ config FORCE_OPTIONS_FOR_ARCH
select 

[PATCH v2 31/46] stat64: Use fstatat64 if arch does not have the stat64 syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 include/sys/stat.h|  1 +
 libc/sysdeps/linux/common/fstatat64.c |  1 +
 libc/sysdeps/linux/common/stat64.c| 16 ++--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index e04fd44..4b16c71 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -257,6 +257,7 @@ extern int __REDIRECT_NTH (fstatat, (int __fd, __const char 
*__restrict __file,
 extern int fstatat64 (int __fd, __const char *__restrict __file,
  struct stat64 *__restrict __buf, int __flag)
  __THROW __nonnull ((2, 3));
+libc_hidden_proto(fstatat64)
 # endif
 #endif
 
diff --git a/libc/sysdeps/linux/common/fstatat64.c 
b/libc/sysdeps/linux/common/fstatat64.c
index 203ec4c..5926711 100644
--- a/libc/sysdeps/linux/common/fstatat64.c
+++ b/libc/sysdeps/linux/common/fstatat64.c
@@ -29,6 +29,7 @@ int fstatat64(int fd, const char *file, struct stat64 *buf, 
int flag)
 
return ret;
 }
+libc_hidden_def(fstatat64)
 #else
 /* should add emulation with fstat64() and /proc/self/fd/ ... */
 #endif
diff --git a/libc/sysdeps/linux/common/stat64.c 
b/libc/sysdeps/linux/common/stat64.c
index a76f182..52a83ec 100644
--- a/libc/sysdeps/linux/common/stat64.c
+++ b/libc/sysdeps/linux/common/stat64.c
@@ -9,11 +9,21 @@
 
 #include sys/syscall.h
 #include sys/stat.h
+#include fcntl.h
+#include unistd.h
 
-#if defined __UCLIBC_HAS_LFS__  defined __NR_stat64
+#if defined __UCLIBC_HAS_LFS__
 
+#if defined(__NR_fstatat64)  !defined(__NR_stat64)
+int stat64(const char *file_name, struct stat64 *buf)
+{
+   return fstatat64(AT_FDCWD, file_name, buf, 0);
+}
+libc_hidden_def(stat64)
+
+/* For systems which have both, prefer the old one */
+#elif defined(__NR_stat64)
 # define __NR___syscall_stat64 __NR_stat64
-# include unistd.h
 # include xstatconv.h
 
 static __inline__ _syscall2(int, __syscall_stat64,
@@ -32,3 +42,5 @@ int stat64(const char *file_name, struct stat64 *buf)
 }
 libc_hidden_def(stat64)
 #endif
+
+#endif /* __UCLIBC_HAS_LFS__ */
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 41/46] open64: Use openat if arch does not have the open syscall

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/open64.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libc/sysdeps/linux/common/open64.c 
b/libc/sysdeps/linux/common/open64.c
index c1f5400..cb43af6 100644
--- a/libc/sysdeps/linux/common/open64.c
+++ b/libc/sysdeps/linux/common/open64.c
@@ -34,11 +34,18 @@ int open64 (const char *file, int oflag, ...)
 
 #ifdef __UCLIBC_HAS_THREADS_NATIVE__
   if (SINGLE_THREAD_P)
+#if defined(__NR_openat)  !defined(__NR_open)
+return INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag | O_LARGEFILE, 
mode);
+#else
 return INLINE_SYSCALL (open, 3, file, oflag | O_LARGEFILE, mode);
+#endif
 
   int oldtype = LIBC_CANCEL_ASYNC ();
-
+#if defined(__NR_openat)  !defined(__NR_open)
+  int result = INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag | O_LARGEFILE, 
mode);
+#else
   int result = INLINE_SYSCALL (open, 3, file, oflag | O_LARGEFILE, mode);
+#endif
 
   LIBC_CANCEL_RESET (oldtype);
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 45/46] libc/ipc: Allow architectures to define their own __IPC_64 macro

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

New architectures don't define ARCH_WANT_IPC_PARSE_VERSION in their kernel.
This means that every cmd passed to semctl,msgctl and shmctl is IPC_64 by
default. For these architectures we need to define __IPC_64 as 0. Existing
architectures are not affected by this change.

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/misc/sysvipc/ipc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/misc/sysvipc/ipc.h b/libc/misc/sysvipc/ipc.h
index 339d136..fa2ff90 100644
--- a/libc/misc/sysvipc/ipc.h
+++ b/libc/misc/sysvipc/ipc.h
@@ -3,11 +3,13 @@
 #include syscall.h
 #include bits/wordsize.h
 
+#ifndef __IPC_64
 #if __WORDSIZE == 32 || defined __alpha__ || defined __mips__
 # define __IPC_64  0x100
 #else
 # define __IPC_64  0x0
 #endif
+#endif
 
 #ifdef __NR_ipc
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


[PATCH v2 30/46] fstatat64: Use newfstatat only for 64-bit operations

2012-11-26 Thread Markos Chandras
From: Markos Chandras markos.chand...@imgtec.com

Signed-off-by: Markos Chandras markos.chand...@imgtec.com
---
 libc/sysdeps/linux/common/fstatat64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/sysdeps/linux/common/fstatat64.c 
b/libc/sysdeps/linux/common/fstatat64.c
index 95627af..203ec4c 100644
--- a/libc/sysdeps/linux/common/fstatat64.c
+++ b/libc/sysdeps/linux/common/fstatat64.c
@@ -13,7 +13,7 @@
 #ifdef __UCLIBC_HAS_LFS__
 
 /* 64bit ports tend to favor newfstatat() */
-#ifdef __NR_newfstatat
+#if __WORDSIZE == 64  defined __NR_newfstatat
 # define __NR_fstatat64 __NR_newfstatat
 #endif
 
-- 
1.8.0


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


wrongly auxvt in __uClibc_main

2012-11-26 Thread Filippo ARCIDIACONO

Folks,
we have seen some issues recently in uClibc related to the way the aux 
vect is managed inside __uClibc_main.


Running a set-[user,group]-ID ELF binaries with some 'unsecure' 
environment variable set (i.e LD_LIBRARY_PATH or LD_PRELOAD), auxvt is 
wrongly set in __uClibc_main.


The problem is caused by the call to _dl_unsetenv function in ldso.c 
that pops the specific env variables
from the stack adding a corresponding number of NULL entries at the end 
of the environments stack.
To be clearer, at the beginning the stack looks like as expected 
(assuming M env variables and N aux_vect entries)


argc
argv[0]
...
argv[argc-1]
NULL /* separator */
envp[0]
...
LD_LIBRARY_PATH
...
envp[M-1]
NULL /* separator */
aux_vect[0]
...
aux_vect[N-1]
NULL /* separator */

After the LD_LIBRARY_PATH has been removed by _dl_unsetenv, the stack 
will look like to libc


argc
argv[0]
...
argv[argc-1]
NULL /* separator */
envp[0]
...
envp[M-2]
NULL /* filled by ld.so */
NULL /* separator */
auxvect[0]
...
aux_vect[N-1]
NULL /* separator */

Currently, __uClibc_main assumes that there is just one NULL separator 
between environments and aux_vect entries, as from the extract below:


aux_dat = (unsigned long*)__environ;
while (*aux_dat) {
aux_dat++;
}
aux_dat++; -- This move the aux_dat of just 1 position to skip the 
NULL separator


Due to this, the local auxvt array (initialised by memset) won't be 
filled with proper values.

All the following code that use the auxvt variable is wrong.

For example, the check for the SUID binaries will be affected, as it 
needs to verify AT_UID, AT_GID, AT-EUID and AT_EGID entries (all NULL)


A potential dirty fix or work-around would be to replace aux_dat++ 
statement with while (!(*aux_dat++)) to skip all the NULL entries, but 
doing so there is no way to detect the case where aux_vect is not present.


So, the proper fix we have in mind is to completely remove the aux vect 
handling from libc and keep it solely into the dynamic linker (as 
actually glibc is doing). If libc needs to check some values from aux 
vect, it can refer to globals exported by the ld.so.


Feedback are really welcome,
Regards,
Filippo
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: dlclose segfaults on x86_64

2012-11-26 Thread Carmelo AMOROSO
On 01/11/2012 16.26, Natanael Copa wrote:
 On Fri, Oct 5, 2012 at 1:46 PM, Natanael Copa natanael.c...@gmail.com wrote:
 building vlc will end up with a segfaulting ./vlc-cache-gen on x86_64.
 ...
 Core was generated by
 `/home/ncopa/aports/main/vlc/src/vlc-2.0.3/bin/.libs/lt-vlc-cache-gen
 ../modules'.
 Program terminated with signal 11, Segmentation fault.
 #0  0x7f9e5fc53e30 in free (mem=0x7f9e6056a668)
 at libc/stdlib/malloc-standard/free.c:324
 324 p-fd = *fb;
 (gdb) bt
 #0  0x7f9e5fc53e30 in free (mem=0x7f9e6056a668)
 at libc/stdlib/malloc-standard/free.c:324
 #1  0x7f9e5f0843d6 in do_dlclose (vhandle=0x7f9e60ca7be0, need_fini=1)
 at ldso/libdl/libdl.c:960
 #2  0x7f9e5f084a47 in dlclose (vhandle=0x7f9e60ca7be0)
 at ldso/libdl/libdl.c:1063
 #3  0x7f9e5ff06e1c in module_Unload (handle=optimized out)
 at posix/plugin.c:89
 ...
 
 Does not seem like anybody really cares, but for the record, Timo
 Teräs solved it with:
 --- ./ldso/libdl/libdl.c.orig
 +++ ./ldso/libdl/libdl.c
 @@ -951,8 +951,8 @@
 
 dtv_t *dtv = THREAD_DTV ();
 
 -
 _dl_assert(!(dtv[tls_lmap-l_tls_modid].pointer.is_static));
 -   if
 (dtv[tls_lmap-l_tls_modid].pointer.val != TLS_DTV_UNALLOCATED) {
 +   if
 (!(dtv[tls_lmap-l_tls_modid].pointer.is_static) 
 +
 dtv[tls_lmap-l_tls_modid].pointer.val != TLS_DTV_UNALLOCATED) {
 /* Note that free is
 called for NULL is well.  We
 deallocate even if it
 is this dtv entry we are
 supposed to load.  The
 reason is that we call
 
 
 Downloadable patch is available here:
 http://git.alpinelinux.org/cgit/aports/plain/main/libc0.9.32/uclibc-dlclose-fix.patch
 

Can we have a well git formed patch sent to this list, unless I've
missed it ?

Thanks,
Carmelo

 I have a relatively small testcase application that can reproduce it
 (using vlc's plugins)
 

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH v2 28/46] statfs: Use statfs64 if arch does not have the statfs syscall

2012-11-26 Thread Mark Salter
On Mon, 2012-11-26 at 14:24 +, Markos Chandras wrote:
 +int __libc_statfs(const char *path, struct statfs *buf)
 +{
 +   struct statfs64 b;
 +   int err;
 +
 +   /*
 +* See if pointer has a sane value.
 +* This does not prevent the user from
 +* passing an arbitrary possitive value
 +* that can lead to a segfault or potential
 +* security problems
 +*/
 +
 +   if (buf == NULL || (int)buf  0) {
 +   __set_errno(EFAULT);
 +   return -1;
 +   }

This seems wrong. Doesn't the kernel already validate addresses passed
in from userspace. Even in the no-MMU case, some architectures add
basic checking for user addresses.

In any case, the (int)buf  0 is clearly non-portable. C6X can have
perfectly good addresses which make negative ints.

--Mark

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH v2 46/46] Config.in: Introduce symbol for arches with deprecated syscalls

2012-11-26 Thread Mark Salter
On Mon, 2012-11-26 at 14:24 +, Markos Chandras wrote:
 diff --git a/extra/Configs/Config.c6x b/extra/Configs/Config.c6x
 index 96adfb3..cc8d647 100644
 --- a/extra/Configs/Config.c6x
 +++ b/extra/Configs/Config.c6x
 @@ -11,6 +11,7 @@ config FORCE_OPTIONS_FOR_ARCH
 default y
 select ARCH_ANY_ENDIAN
 select ARCH_HAS_NO_MMU
 +   select ARCH_HAS_DEPRECATED_SYSCALLS

Upstream C6X kernel does not have deprecated syscalls.


___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: wrongly auxvt in __uClibc_main

2012-11-26 Thread Rich Felker
On Mon, Nov 26, 2012 at 04:45:18PM +0100, Filippo ARCIDIACONO wrote:
 Folks,
 we have seen some issues recently in uClibc related to the way the
 aux vect is managed inside __uClibc_main.
 
 Running a set-[user,group]-ID ELF binaries with some 'unsecure'
 environment variable set (i.e LD_LIBRARY_PATH or LD_PRELOAD), auxvt
 is wrongly set in __uClibc_main.
 
 The problem is caused by the call to _dl_unsetenv function in ldso.c
 that pops the specific env variables
 from the stack adding a corresponding number of NULL entries at the
 end of the environments stack.

I don't know if anybody wants to tackle this, but I believe the
current _dl_unsetenv behavior is non-conforming (the implementation
does not have a license to unset environment variables at will). The
correct behavior is just ignoring the variables in the current (suid)
process, but still making them available to the application which
might want to query them with getenv or pass them on to child
processes. There is some concern about the safety of the latter, but
the issue only arises if the suid program has elevated itself to
having both read and effective uid privileged. If the real/effective
ids still differ, the child will ignore the environment variables, and
if they process has fully dropped privileges down to that of the
invoking user (the original real uid), then it's appropriate that the
environment variables be honored.

I don't believe whoever originally added the _dl_unsetenv logic
thought these issues out well...

Rich
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH v2 28/46] statfs: Use statfs64 if arch does not have the statfs syscall

2012-11-26 Thread Rich Felker
On Mon, Nov 26, 2012 at 02:31:06PM -0500, Mark Salter wrote:
 On Mon, 2012-11-26 at 14:24 +, Markos Chandras wrote:
  +int __libc_statfs(const char *path, struct statfs *buf)
  +{
  +   struct statfs64 b;
  +   int err;
  +
  +   /*
  +* See if pointer has a sane value.
  +* This does not prevent the user from
  +* passing an arbitrary possitive value
  +* that can lead to a segfault or potential
  +* security problems
  +*/
  +
  +   if (buf == NULL || (int)buf  0) {
  +   __set_errno(EFAULT);
  +   return -1;
  +   }
 
 This seems wrong. Doesn't the kernel already validate addresses passed
 in from userspace. Even in the no-MMU case, some architectures add
 basic checking for user addresses.
 
 In any case, the (int)buf  0 is clearly non-portable. C6X can have
 perfectly good addresses which make negative ints.

Indeed, this code is definitely wrong as-written. There's no
obligation to fail with EFAULT when a bad address is given, so just
crashing is perfectly acceptable. 

With that said, I question why this code is even needed. If an arch
doesn't have a non-64-bit statfs call, then why would it have a
separate non-64-bit, legacy statfs structure? If it really needs one,
the statfs structure could just be defined to match the layout of the
statfs64 structure, but with 32-bit off_t fields and 32 bits of
padding next to them instead of the usual 64-bit off_t. Then no
conversion code would be needed.

Rich
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH v2 46/46] Config.in: Introduce symbol for arches with deprecated syscalls

2012-11-26 Thread Markos Chandras
On 26 November 2012 19:37, Mark Salter msal...@redhat.com wrote:
 On Mon, 2012-11-26 at 14:24 +, Markos Chandras wrote:
 diff --git a/extra/Configs/Config.c6x b/extra/Configs/Config.c6x
 index 96adfb3..cc8d647 100644
 --- a/extra/Configs/Config.c6x
 +++ b/extra/Configs/Config.c6x
 @@ -11,6 +11,7 @@ config FORCE_OPTIONS_FOR_ARCH
 default y
 select ARCH_ANY_ENDIAN
 select ARCH_HAS_NO_MMU
 +   select ARCH_HAS_DEPRECATED_SYSCALLS

 Upstream C6X kernel does not have deprecated syscalls.



Hi Mark,

That's weird. It makes me wonder how come C6X is supported in uClibc
without the deprecated syscalls. I will have a look

-- 
Regards,
Markos
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH v2 28/46] statfs: Use statfs64 if arch does not have the statfs syscall

2012-11-26 Thread Markos Chandras
On 26 November 2012 19:49, Rich Felker dal...@aerifal.cx wrote:
 On Mon, Nov 26, 2012 at 02:31:06PM -0500, Mark Salter wrote:
 On Mon, 2012-11-26 at 14:24 +, Markos Chandras wrote:
  +int __libc_statfs(const char *path, struct statfs *buf)
  +{
  +   struct statfs64 b;
  +   int err;
  +
  +   /*
  +* See if pointer has a sane value.
  +* This does not prevent the user from
  +* passing an arbitrary possitive value
  +* that can lead to a segfault or potential
  +* security problems
  +*/
  +
  +   if (buf == NULL || (int)buf  0) {
  +   __set_errno(EFAULT);
  +   return -1;
  +   }

 This seems wrong. Doesn't the kernel already validate addresses passed
 in from userspace. Even in the no-MMU case, some architectures add
 basic checking for user addresses.

 In any case, the (int)buf  0 is clearly non-portable. C6X can have
 perfectly good addresses which make negative ints.

 Indeed, this code is definitely wrong as-written. There's no
 obligation to fail with EFAULT when a bad address is given, so just
 crashing is perfectly acceptable.

 With that said, I question why this code is even needed. If an arch
 doesn't have a non-64-bit statfs call, then why would it have a
 separate non-64-bit, legacy statfs structure? If it really needs one,
 the statfs structure could just be defined to match the layout of the
 statfs64 structure, but with 32-bit off_t fields and 32 bits of
 padding next to them instead of the usual 64-bit off_t. Then no
 conversion code would be needed.

 Rich

This is just for backwards compatibility. This patch tries to use the
existing structures so we
don't have to avoid a new one for these architectures.
As for the simple buf pointer check, I think you missed the point.
This pointer is never passed to the kernel
(it is not passed to the INLINE_SYSCALL macro) so the kernel does not
know about it. It is possible your userspace
program to pass an invalid buf pointer and the INLINE_SYSCALL to
succeed but you will crash after that when you try
to dereference any member of the invalid buf pointer.

-- 
Regards,
Markos
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH v2 28/46] statfs: Use statfs64 if arch does not have the statfs syscall

2012-11-26 Thread Rich Felker
On Mon, Nov 26, 2012 at 08:26:11PM +, Markos Chandras wrote:
 On 26 November 2012 19:49, Rich Felker dal...@aerifal.cx wrote:
  On Mon, Nov 26, 2012 at 02:31:06PM -0500, Mark Salter wrote:
  On Mon, 2012-11-26 at 14:24 +, Markos Chandras wrote:
   +int __libc_statfs(const char *path, struct statfs *buf)
   +{
   +   struct statfs64 b;
   +   int err;
   +
   +   /*
   +* See if pointer has a sane value.
   +* This does not prevent the user from
   +* passing an arbitrary possitive value
   +* that can lead to a segfault or potential
   +* security problems
   +*/
   +
   +   if (buf == NULL || (int)buf  0) {
   +   __set_errno(EFAULT);
   +   return -1;
   +   }
 
  This seems wrong. Doesn't the kernel already validate addresses passed
  in from userspace. Even in the no-MMU case, some architectures add
  basic checking for user addresses.
 
  In any case, the (int)buf  0 is clearly non-portable. C6X can have
  perfectly good addresses which make negative ints.
 
  Indeed, this code is definitely wrong as-written. There's no
  obligation to fail with EFAULT when a bad address is given, so just
  crashing is perfectly acceptable.
 
  With that said, I question why this code is even needed. If an arch
  doesn't have a non-64-bit statfs call, then why would it have a
  separate non-64-bit, legacy statfs structure? If it really needs one,
  the statfs structure could just be defined to match the layout of the
  statfs64 structure, but with 32-bit off_t fields and 32 bits of
  padding next to them instead of the usual 64-bit off_t. Then no
  conversion code would be needed.
 
  Rich
 
 This is just for backwards compatibility. This patch tries to use the
 existing structures so we
 don't have to avoid a new one for these architectures.

As far as I know, there's nothing to maintain backwards
compatibility with. The stat structures vary per-arch, and an arch
that doesn't have a non-64-bit statfs syscall doesn't have an existing
struct statfs to maintain backwards compatibility with. You can just
define struct statfs to match the layout of the 64-bit struct.

By the way, the old small-off_t functions are supposed to give an
error if any off_t value does not fit in the range of off_t, rather
than silently truncating. So even if you want to keep the conversion
code, you need to check this. If using my approach (with same struct
layout and padding for the extra 32 bits), you'd need to test that the
padding is zero and return an error if any nonzero value appeared in
the padding (except perhaps in the case of -1?).

 As for the simple buf pointer check, I think you missed the point.
 This pointer is never passed to the kernel
 (it is not passed to the INLINE_SYSCALL macro) so the kernel does not
 know about it. It is possible your userspace
 program to pass an invalid buf pointer and the INLINE_SYSCALL to
 succeed but you will crash after that when you try
 to dereference any member of the invalid buf pointer.

Crashing is perfectly acceptable behavior. statfs() is under no
obligation to report EFAULT; passing an invalid pointer is undefined
behavior and the expected result should be a crash or worse. Even if
the kernel handles it, passing bogus pointers won't necessarily give
EFAULT; if they happen to point to writable memory, you'll just
clobber random memory.

Rich
___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: [PATCH v2 46/46] Config.in: Introduce symbol for arches with deprecated syscalls

2012-11-26 Thread Mark Salter
On Mon, 2012-11-26 at 20:21 +, Markos Chandras wrote:
 Hi Mark,
 
 That's weird. It makes me wonder how come C6X is supported in uClibc
 without the deprecated syscalls. I will have a look

The upstream kernel requires a patched uClibc. The original c6x support
which went into uClibc was based on a kernel which did have the needed
syscalls. Those syscalls got dropped when the kernel was submitted
upstream.



___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


Re: wrongly auxvt in __uClibc_main

2012-11-26 Thread Carmelo AMOROSO
On 26/11/2012 20.45, Rich Felker wrote:
 On Mon, Nov 26, 2012 at 04:45:18PM +0100, Filippo ARCIDIACONO wrote:
 Folks,
 we have seen some issues recently in uClibc related to the way the
 aux vect is managed inside __uClibc_main.

 Running a set-[user,group]-ID ELF binaries with some 'unsecure'
 environment variable set (i.e LD_LIBRARY_PATH or LD_PRELOAD), auxvt
 is wrongly set in __uClibc_main.

 The problem is caused by the call to _dl_unsetenv function in ldso.c
 that pops the specific env variables
 from the stack adding a corresponding number of NULL entries at the
 end of the environments stack.
 

Hi Rich,

 I don't know if anybody wants to tackle this, but I believe the
 current _dl_unsetenv behavior is non-conforming (the implementation
 does not have a license to unset environment variables at will). The
 correct behavior is just ignoring the variables in the current (suid)
 process, but still making them available to the application which
 might want to query them with getenv or pass them on to child
 processes. There is some concern about the safety of the latter, but
 the issue only arises if the suid program has elevated itself to
 having both read and effective uid privileged. If the real/effective
 ids still differ, the child will ignore the environment variables, and
 if they process has fully dropped privileges down to that of the
 invoking user (the original real uid), then it's appropriate that the
 environment variables be honored.

I see your concerns, currently I have not a clear idea.

 
 I don't believe whoever originally added the _dl_unsetenv logic
 thought these issues out well...
 

anyway there is another case that is showing the same issue anyway. If
one of the constructor of a dependent shared libraries called the C
library unsetenv, the side effect would be the same, that is aux vect
invalid if used into the __uClibc_main.

Beside the issue with suid programs, also the actual value of the
pagesize used by the running kernel could be affected.

So I think that there are still more valid reason for redesigning this
core piece of code.

 Rich

Cheers,
Carmelo

 ___
 uClibc mailing list
 uClibc@uclibc.org
 http://lists.busybox.net/mailman/listinfo/uclibc
 

___
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc