From patchwork Fri Mar 14 18:10:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 26277 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4E91E20143 for ; Fri, 14 Mar 2014 18:10:53 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id lx4sf9830127iec.3 for ; Fri, 14 Mar 2014 11:10:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=wiAY3DhFzqPg5pJi/rySnISnyZJHjRBaWsVGzSewHl4=; b=S6xE0HOmgMqNdjVWuD4QU0eWf3GbyIIqr3H6VtfYXuBowe1OeDDsCd/QfId8pI0G4L hrRKFo5EYNZXUPh0LfIt4KsR15ozp7sOAlbJqtZUKWwEMxpELSIogFl2Q38O18p4T97Y +bPizg1dGhnv6P4psv4gf7eD8Yk1kjvaHBayGT8bOsgMndtpXk3ucTEFCx8z+T164rlX v4gA2pnx4BbjSnaT5kx8qpEobDIn2HXilyx34jBunAUVRen8mwFHKmwqmCmxe8WVJDlV ukPpKHIXRBOJdhXnioirzad04f0qV1JeT44IOlY8i97gMUVAC7UK5kEfs8f6536wDP7u qMjg== X-Gm-Message-State: ALoCoQlsfl31q+/52qeuRVb/ORUX/T8QTQUdVXGG8I/UXFhkvmdZ6sYlxLlnIzjDPEqbK7YCPZ0a X-Received: by 10.43.4.4 with SMTP id oa4mr3169162icb.2.1394820652808; Fri, 14 Mar 2014 11:10:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.91.131 with SMTP id z3ls893448qgd.59.gmail; Fri, 14 Mar 2014 11:10:52 -0700 (PDT) X-Received: by 10.58.106.134 with SMTP id gu6mr192429veb.44.1394820652723; Fri, 14 Mar 2014 11:10:52 -0700 (PDT) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id tt2si2378816vdc.87.2014.03.14.11.10.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Mar 2014 11:10:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id pa12so3194495veb.1 for ; Fri, 14 Mar 2014 11:10:52 -0700 (PDT) X-Received: by 10.52.30.230 with SMTP id v6mr6239880vdh.6.1394820652594; Fri, 14 Mar 2014 11:10:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.78.9 with SMTP id i9csp41218vck; Fri, 14 Mar 2014 11:10:52 -0700 (PDT) X-Received: by 10.180.72.195 with SMTP id f3mr7159544wiv.61.1394820651757; Fri, 14 Mar 2014 11:10:51 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id f20si9320904wic.51.2014.03.14.11.10.51 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 14 Mar 2014 11:10:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WOWZG-0003qN-37; Fri, 14 Mar 2014 18:10:50 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Riku Voipio Subject: [PATCH] linux-user: Implement capget, capset Date: Fri, 14 Mar 2014 18:10:50 +0000 Message-Id: <1394820650-14750-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Implement the capget and capset syscalls. This is useful because simple programs like 'ls' try to use it in AArch64, and otherwise we emit a lot of noise about it being unimplemented. Signed-off-by: Peter Maydell --- Bugfix or feature? You decide :-) linux-user/syscall.c | 71 +++++++++++++++++++++++++++++++++++++++++++++-- linux-user/syscall_defs.h | 11 ++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2a8b66c..53c3d69 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #ifdef __ia64__ @@ -7641,9 +7642,75 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, unlock_user(p, arg1, ret); break; case TARGET_NR_capget: - goto unimplemented; case TARGET_NR_capset: - goto unimplemented; + { + struct target_user_cap_header *target_header; + struct target_user_cap_data *target_data; + struct __user_cap_header_struct header; + struct __user_cap_data_struct data[2]; + struct __user_cap_data_struct *dataptr = NULL; + int i, target_datalen; + int data_items = 1; + + if (!lock_user_struct(VERIFY_WRITE, target_header, arg1, 1)) { + goto efault; + } + header.version = tswap32(target_header->version); + header.pid = tswap32(target_header->pid); + + if (header.version != _LINUX_CAPABILITY_VERSION_1) { + /* Version 2 and up takes pointer to two user_data structs */ + data_items = 2; + } + + target_datalen = sizeof(*target_data) * data_items; + + if (arg2) { + if (num == TARGET_NR_capget) { + target_data = lock_user(VERIFY_WRITE, arg2, target_datalen, 0); + } else { + target_data = lock_user(VERIFY_READ, arg2, target_datalen, 1); + } + if (!target_data) { + unlock_user_struct(target_header, arg1, 0); + goto efault; + } + + if (num == TARGET_NR_capset) { + for (i = 0; i < data_items; i++) { + data[i].effective = tswap32(target_data[i].effective); + data[i].permitted = tswap32(target_data[i].permitted); + data[i].inheritable = tswap32(target_data[i].inheritable); + } + } + + dataptr = data; + } + + if (num == TARGET_NR_capget) { + ret = get_errno(capget(&header, dataptr)); + } else { + ret = get_errno(capset(&header, dataptr)); + } + + /* The kernel always updates version for both capget and capset */ + target_header->version = tswap32(header.version); + unlock_user_struct(target_header, arg1, 1); + + if (arg2) { + if (num == TARGET_NR_capget) { + for (i = 0; i < data_items; i++) { + target_data[i].effective = tswap32(data[i].effective); + target_data[i].permitted = tswap32(data[i].permitted); + target_data[i].inheritable = tswap32(data[i].inheritable); + } + unlock_user(target_data, arg2, target_datalen); + } else { + unlock_user(target_data, arg2, 0); + } + } + break; + } case TARGET_NR_sigaltstack: #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \ defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \ diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 732c9e3..7db878a 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2559,3 +2559,14 @@ struct target_sigevent { } _sigev_thread; } _sigev_un; }; + +struct target_user_cap_header { + uint32_t version; + int pid; +}; + +struct target_user_cap_data { + uint32_t effective; + uint32_t permitted; + uint32_t inheritable; +};