From patchwork Fri Feb 8 17:31:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 14701 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id B587324195 for ; Fri, 8 Feb 2013 17:32:00 +0000 (UTC) Received: from mail-vb0-f49.google.com (mail-vb0-f49.google.com [209.85.212.49]) by fiordland.canonical.com (Postfix) with ESMTP id 517BBA18949 for ; Fri, 8 Feb 2013 17:32:00 +0000 (UTC) Received: by mail-vb0-f49.google.com with SMTP id s24so2473803vbi.8 for ; Fri, 08 Feb 2013 09:31:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=ny94hzctdIm+Ih+dYPCx9mz/XZX45lYDZZQOwfs1Ojs=; b=Zfa5ZKnVPjv6fEZutHUAZhgQFoimv79jhivvcHvsd4wJTgsYfVXKJ3Nq2E8IXuDiZz OHQxWwnHjwXyyS7cDAFD6nljEUIQET+rtfWpQ9B4FvMj8DEcWMg8QU2LKVWtFaSL+BFp CT+vYnDpDIMcmGKxdo0Ow3roz+UP+VUwSXOk/AIWRfy8hUCGbCEFiBXnC8DqG3pfGPNO iwi6QXnhaKEGbR8X+0lclXLj1EdFBLu+MvjBZAU1YnusS7r3L3ghmjLfGVGWLbvSj0Ar lOG1Vr3n36Z8VZw+UqJfSUd0ZD8lR70m1QTwMCLpujw9FKs2P33ii7LlcA16YoeW5EDZ JbeQ== X-Received: by 10.58.48.231 with SMTP id p7mr7928036ven.11.1360344719768; Fri, 08 Feb 2013 09:31:59 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.252.8 with SMTP id zo8csp158823vec; Fri, 8 Feb 2013 09:31:58 -0800 (PST) X-Received: by 10.180.14.166 with SMTP id q6mr4073860wic.22.1360344718200; Fri, 08 Feb 2013 09:31:58 -0800 (PST) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id vm1si11579160wjc.91.2013.02.08.09.31.57 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 08 Feb 2013 09:31:58 -0800 (PST) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1U3rnn-0000dp-O0; Fri, 08 Feb 2013 17:31:55 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Riku Voipio Subject: [PATCH] linux-user: Implement sendfile and sendfile64 Date: Fri, 8 Feb 2013 17:31:55 +0000 Message-Id: <1360344715-2442-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQnqz+1pLyl9WGHcS1vF46V8Xemta/WR6UNN6n8HGK/4Gu85/zGOomM4yEpoORCRPnW/X3JD Implement the sendfile and sendfile64 syscalls. This implementation passes all the LTP test cases for these syscalls. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- This test-driven-development thing is fun :-) configure | 17 ++++++++++++++++ linux-user/syscall.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/configure b/configure index 8789324..fd64e82 100755 --- a/configure +++ b/configure @@ -2715,6 +2715,20 @@ if compile_prog "" "" ; then epoll_pwait=yes fi +# check for sendfile support +sendfile=no +cat > $TMPC << EOF +#include + +int main(void) +{ + return sendfile(0, 0, 0, 0); +} +EOF +if compile_prog "" "" ; then + sendfile=yes +fi + # Check if tools are available to build documentation. if test "$docs" != "no" ; then if has makeinfo && has pod2man; then @@ -3551,6 +3565,9 @@ fi if test "$epoll_pwait" = "yes" ; then echo "CONFIG_EPOLL_PWAIT=y" >> $config_host_mak fi +if test "$sendfile" = "yes" ; then + echo "CONFIG_SENDFILE=y" >> $config_host_mak +fi if test "$inotify" = "yes" ; then echo "CONFIG_INOTIFY=y" >> $config_host_mak fi diff --git a/linux-user/syscall.c b/linux-user/syscall.c index fcdccfa..35df073 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -78,6 +78,9 @@ int __clone2(int (*fn)(void *), void *child_stack_base, #ifdef CONFIG_ATTR #include "qemu/xattr.h" #endif +#ifdef CONFIG_SENDFILE +#include +#endif #define termios host_termios #define winsize host_winsize @@ -7551,8 +7554,58 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #else goto unimplemented; #endif + +#ifdef CONFIG_SENDFILE + case TARGET_NR_sendfile: + { + off_t *offp = NULL; + off_t off; + if (arg3) { + ret = get_user_sal(off, arg3); + if (is_error(ret)) { + break; + } + offp = &off; + } + ret = get_errno(sendfile(arg1, arg2, offp, arg4)); + if (!is_error(ret) && arg3) { + abi_long ret2 = put_user_sal(off, arg3); + if (is_error(ret2)) { + ret = ret2; + } + } + break; + } +#ifdef TARGET_NR_sendfile64 + case TARGET_NR_sendfile64: + { + off_t *offp = NULL; + off_t off; + if (arg3) { + ret = get_user_s64(off, arg3); + if (is_error(ret)) { + break; + } + offp = &off; + } + ret = get_errno(sendfile(arg1, arg2, offp, arg4)); + if (!is_error(ret) && arg3) { + abi_long ret2 = put_user_s64(off, arg3); + if (is_error(ret2)) { + ret = ret2; + } + } + break; + } +#endif +#else case TARGET_NR_sendfile: +#ifdef TARGET_NR_sendfile64: + case TARGET_NR_sendfile64: +#endif goto unimplemented; +#endif + #ifdef TARGET_NR_getpmsg case TARGET_NR_getpmsg: goto unimplemented;