diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-04-23 18:07:47 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-07-02 11:29:37 (GMT) |
commit | 0b757d0c1b6f64d17086621ec692369d37fd62fc (patch) | |
tree | a11ea33f33a86790002b92d1cd2a57efe0dcf4dd /src/corelib/kernel | |
parent | d7d0d20469d447933c827d169651c3751c7069ad (diff) | |
download | Qt-0b757d0c1b6f64d17086621ec692369d37fd62fc.zip Qt-0b757d0c1b6f64d17086621ec692369d37fd62fc.tar.gz Qt-0b757d0c1b6f64d17086621ec692369d37fd62fc.tar.bz2 |
Use the safe versions of the network system calls I have just added.
Reviewed-By: ossi
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qcore_unix.cpp | 63 | ||||
-rw-r--r-- | src/corelib/kernel/qcore_unix_p.h | 13 |
2 files changed, 75 insertions, 1 deletions
diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index ffaf958..2549f77 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -119,3 +119,66 @@ int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, } QT_END_NAMESPACE + +#ifdef Q_OS_LINUX +// Don't wait for libc to supply the calls we need +// Make syscalls directly + +# if defined(__GLIBC__) && (__GLIBC__ * 0x100 + __GLIBC_MINOR__) >= 0x0204 +// glibc 2.4 has syscall(...) +# include <sys/syscall.h> +# include <asm/unistd.h> +# else +// no syscall(...) +static inline int syscall(...) { errno = ENOSYS; return -1;} +# endif + +# ifndef __NR_dup3 +# if defined(__i386__) +# define __NR_dup3 330 +# define __NR_pipe2 331 +# elif defined(__x86_64__) +# define __NR_accept4 288 +# define __NR_dup3 292 +# define __NR_pipe2 293 +# elif defined(__ia64__) +# define __NR_accept4 -1 +# define __NR_dup3 1316 +# define __NR_pipe2 1317 +# else +// set the syscalls to absurd numbers so that they'll cause ENOSYS errors +# warning "Please port the pipe2/dup3/accept4 code to this platform" +# define __NR_accept4 -1 +# define __NR_dup3 -1 +# define __NR_pipe2 -1 +# endif +# endif + +QT_BEGIN_NAMESPACE +namespace QtLibcSupplement { + int pipe2(int pipes[], int flags) + { + return syscall(__NR_pipe2, pipes, flags); + } + + int dup3(int oldfd, int newfd, int flags) + { + return syscall(__NR_dup3, oldfd, newfd, flags); + } + + int accept4(int s, sockaddr *addr, QT_SOCKLEN_T *addrlen, int flags) + { +# if defined(__NR_socketcall) + // This platform uses socketcall() instead of raw syscalls + // the SYS_ACCEPT4 number is cross-platform: 18 + return syscall(__NR_socketcall, 18, &s); +# else + return syscall(__NR_accept4, s, addr, addrlen, flags); +# endif + + Q_UNUSED(addr); Q_UNUSED(addrlen); Q_UNUSED(flags); // they're actually used + } +} +QT_END_NAMESPACE +#endif // Q_OS_LINUX + diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index 4e3158a..6ae4ff0 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -67,10 +67,21 @@ #include <errno.h> #include <fcntl.h> +struct sockaddr; + QT_BEGIN_NAMESPACE -#if defined(Q_OS_LINUX) && defined(__GLIBC__) && (__GLIBC__ * 0x100 + __GLIBC_MINOR__) >= 0x0209 +#if defined(Q_OS_LINUX) && defined(__GLIBC__) && (__GLIBC__ * 0x100 + __GLIBC_MINOR__) >= 0x0204 +// Linux supports thread-safe FD_CLOEXEC # define QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC 1 + +namespace QtLibcSupplement { + Q_CORE_EXPORT int accept4(int, sockaddr *, QT_SOCKLEN_T *, int flags); + Q_CORE_EXPORT int dup3(int oldfd, int newfd, int flags); + Q_CORE_EXPORT int pipe2(int pipes[], int flags); +} + +using namespace QtLibcSupplement; #else # define QT_UNIX_SUPPORTS_THREADSAFE_CLOEXEC 0 #endif |