[git commit future] fcntl: add cancellation to fcntl64, use cancel.h
Peter S. Mazinger
ps.m at gmx.net
Wed Apr 20 10:50:38 UTC 2011
commit: http://git.uclibc.org/uClibc/commit/?id=1beb8e206f0cd8f6030539a74ddd7e3b52004766
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/future
fcntl64 missed cancellation.
Guard fcntl64 for 32bit archs.
Reuse as much code as possible in __syscall_fcntl.c.
Provide aliases fcntl64 if syscall is not available or on 64bit archs.
Signed-off-by: Peter S. Mazinger <ps.m at gmx.net>
---
include/fcntl.h | 11 ++--
libc/sysdeps/linux/common/__syscall_fcntl.c | 75 +++++++------------------
libc/sysdeps/linux/common/__syscall_fcntl64.c | 26 ++++++--
3 files changed, 45 insertions(+), 67 deletions(-)
diff --git a/include/fcntl.h b/include/fcntl.h
index f2b4629..e4a00cf 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -75,7 +75,10 @@ __BEGIN_DECLS
__THROW. */
#if !defined(__USE_FILE_OFFSET64) || defined(__LP64__)
extern int fcntl (int __fd, int __cmd, ...);
+# ifdef _LIBC
+extern int __fcntl_nocancel(int, int, void *) attribute_hidden;
libc_hidden_proto(fcntl)
+# endif
#else
# ifdef __REDIRECT
extern int __REDIRECT (fcntl, (int __fd, int __cmd, ...), fcntl64);
@@ -85,7 +88,10 @@ extern int __REDIRECT (fcntl, (int __fd, int __cmd, ...), fcntl64);
#endif
#if defined(__USE_LARGEFILE64) && !defined(__LP64__)
extern int fcntl64 (int __fd, int __cmd, ...);
+# ifdef _LIBC
+extern int __fcntl64_nocancel(int, int, void *) attribute_hidden;
libc_hidden_proto(fcntl64)
+# endif
#endif
/* Open FILE and return a new file descriptor for it, or -1 on error.
@@ -232,11 +238,6 @@ extern int posix_fallocate64 (int __fd, __off64_t __offset, __off64_t __len);
# endif
#endif
-#ifdef _LIBC
-extern int __fcntl_nocancel (int fd, int cmd, ...);
-libc_hidden_proto(__fcntl_nocancel)
-#endif
-
__END_DECLS
#endif /* fcntl.h */
diff --git a/libc/sysdeps/linux/common/__syscall_fcntl.c b/libc/sysdeps/linux/common/__syscall_fcntl.c
index 6d4c339..5ae6122 100644
--- a/libc/sysdeps/linux/common/__syscall_fcntl.c
+++ b/libc/sysdeps/linux/common/__syscall_fcntl.c
@@ -10,39 +10,26 @@
#include <sys/syscall.h>
#include <stdarg.h>
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
-#include <sysdep-cancel.h> /* Must come before <fcntl.h>. */
-#endif
+#include <cancel.h> /* Must come before <fcntl.h>. */
#include <fcntl.h>
#include <bits/wordsize.h>
-extern __typeof(fcntl) __libc_fcntl;
-libc_hidden_proto(__libc_fcntl)
-
-int __fcntl_nocancel (int fd, int cmd, ...)
+int __NC(fcntl)(int fd, int cmd, void *arg)
{
- va_list ap;
- void *arg;
-
- va_start (ap, cmd);
- arg = va_arg (ap, void *);
- va_end (ap);
-
-# if __WORDSIZE == 32
+#if __WORDSIZE == 32
if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
-# if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
- return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
-# else
+# if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
+ return __NC(fcntl64)(fd, cmd, arg);
+# else
__set_errno(ENOSYS);
return -1;
-# endif
- }
# endif
- return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
+ }
+#endif
+ return INLINE_SYSCALL(fcntl, 3, fd, cmd, arg);
}
-libc_hidden_def(__fcntl_nocancel)
-int __libc_fcntl (int fd, int cmd, ...)
+int fcntl(int fd, int cmd, ...)
{
va_list ap;
void *arg;
@@ -51,41 +38,19 @@ int __libc_fcntl (int fd, int cmd, ...)
arg = va_arg (ap, void *);
va_end (ap);
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
-# if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
- return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
-# else
- return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
-# endif
-
+ return __NC(fcntl)(fd, cmd, arg);
+#ifdef __NEW_THREADS
int oldtype = LIBC_CANCEL_ASYNC ();
-
-# if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
- int result = INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
-# else
- int result = INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
-# endif
-
+ int result = __NC(fcntl)(fd, cmd, arg);
LIBC_CANCEL_RESET (oldtype);
-
return result;
-#else
-# if __WORDSIZE == 32
- if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
-# if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
- return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
-# else
- __set_errno(ENOSYS);
- return -1;
-# endif
- }
-# endif
- return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
#endif
}
-libc_hidden_def(__libc_fcntl)
-
-libc_hidden_proto(fcntl)
-weak_alias(__libc_fcntl,fcntl)
-libc_hidden_weak(fcntl)
+lt_strong_alias(fcntl)
+lt_libc_hidden(fcntl)
+#if defined __UCLIBC_HAS_LFS__ && (__WORDSIZE == 64 || !defined __NR_fcntl64)
+strong_alias_untyped(fcntl,fcntl64)
+lt_strong_alias(fcntl64)
+lt_libc_hidden(fcntl64)
+#endif
diff --git a/libc/sysdeps/linux/common/__syscall_fcntl64.c b/libc/sysdeps/linux/common/__syscall_fcntl64.c
index 09291e5..f84cc57 100644
--- a/libc/sysdeps/linux/common/__syscall_fcntl64.c
+++ b/libc/sysdeps/linux/common/__syscall_fcntl64.c
@@ -9,22 +9,34 @@
#include <_lfs_64.h>
#include <sys/syscall.h>
+#include <bits/wordsize.h>
-#ifdef __NR_fcntl64
+#if defined __NR_fcntl64 && __WORDSIZE == 32
# include <stdarg.h>
# include <fcntl.h>
-# define __NR___syscall_fcntl64 __NR_fcntl64
-static __inline__ _syscall3(int, __syscall_fcntl64, int, fd, int, cmd, long, arg)
+# include <cancel.h>
+
+# define __NR___fcntl64_nocancel __NR_fcntl64
+_syscall3(int, __NC(fcntl64), int, fd, int, cmd, void *, arg)
+
int fcntl64(int fd, int cmd, ...)
{
- long arg;
+ void *arg;
va_list list;
va_start(list, cmd);
- arg = va_arg(list, long);
+ arg = va_arg(list, void *);
va_end(list);
- return (__syscall_fcntl64(fd, cmd, arg));
+ if (SINGLE_THREAD_P || (cmd != F_SETLKW64))
+ return __NC(fcntl64)(fd, cmd, arg);
+# ifdef __NEW_THREADS
+ int oldtype = LIBC_CANCEL_ASYNC();
+ int result = __NC(fcntl64)(fd, cmd, arg);
+ LIBC_CANCEL_RESET(oldtype);
+ return result;
+# endif
}
-libc_hidden_def(fcntl64)
+lt_strong_alias(fcntl64)
+lt_libc_hidden(fcntl64)
#endif
--
1.7.3.4
More information about the uClibc-cvs
mailing list