From patchwork Sat Jul 15 13:52:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 703210 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e4d:0:b0:314:25da:8dc4 with SMTP id r13csp156730wrt; Sat, 15 Jul 2023 06:54:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlHZJFFz4YmYJ7A8cJXaDVGK9akorhNn+Wq4xNJiysP4FCB+qZcxd8sGSTcVDMEq8XlnG45+ X-Received: by 2002:a0c:db03:0:b0:621:3b88:7b09 with SMTP id d3-20020a0cdb03000000b006213b887b09mr7229929qvk.35.1689429267990; Sat, 15 Jul 2023 06:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689429267; cv=none; d=google.com; s=arc-20160816; b=z8h6ig4sdfyhJoiu0RPN89E0yPsq5x7I8ozbFbt4nblyD1Z0JVRS3lf+JyKg29ZfH3 Zq+skTALghcbYLVy7Z8O+yiNJjwyU5S+gSRJMwd0jFnaXWfQ/+smh29exMcXuSD9MFWr hPGlcJlr7gjEYX0pxLKLucpfUnUPHOHcSJMtKR87CfgSLTH0ix5P+sSH4Y5GJLhV/Aka HsARSQKdYW/cKLIgx4puYfg9AoRLmIX8k+yyLP1mpLo7nJnfX4VcAlMgRImICulLy7eV OxGhE+qHSBTe7hprXYnSRMqpTQJRjwJCZZRMyqf0GmnfM9OKoj5vvFhkQHiaGotyfAlc zBhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0PrN0L5Atjyx6hFnGJcyTHnWGq2syM21Wu73egPOuXw=; fh=ZuLSLtzpwbOj79Lm6HQkAzCl7AYBeBRT4Q/1zeFcrQg=; b=iuOSP393KokJszqjHASGA6yAJQEXxVuWg05Vg1uKFutKcqp6RAgBAP7aQudhhpgOy9 fdzKKfP8xlzbjwwTvw1FbbZy+q5/lhYVHYA+ZBh/mNPsDTpMxEi2Beal6KofoK4rWcJx VA5q68hdsKPByaIaqchtPEP/Rk3TvSWNc9Y1Rgg63SUg9vbPfIOfD9ou/9v+lylEfBke GDVuxlA9Q7npVdbNipVu+KuUPmzMIfscWwFDsmSVxZkVlsc5PEp8C467QWTR+7BlAuIr 5JixE01w8Tw1G/KDFe+fxsMvCIYmaMg0HxQEuAzNThW87BsFCAnXJpsOr+FBwAnuhprq m1ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wmCpZrzt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w10-20020a0ca80a000000b006259adfabbcsi5639869qva.283.2023.07.15.06.54.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Jul 2023 06:54:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wmCpZrzt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qKfir-0004EY-TA; Sat, 15 Jul 2023 09:54:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qKfiO-00045V-7L for qemu-devel@nongnu.org; Sat, 15 Jul 2023 09:53:41 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qKfiM-0001Hu-K6 for qemu-devel@nongnu.org; Sat, 15 Jul 2023 09:53:40 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fbd33a57dcso29510255e9.0 for ; Sat, 15 Jul 2023 06:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689429217; x=1692021217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0PrN0L5Atjyx6hFnGJcyTHnWGq2syM21Wu73egPOuXw=; b=wmCpZrzt9CW2VaTqz/sExcOWDC0dI3Y9DVSjbnE75X0PnetawVc2bmZT51B7pxbBiO 0wAzYchNSSRy25zt+o8mx6p/h2ZFJRV7vcgAuFOEpmIFXLnkPeS+Nrxtea3q401WTXKl kFB3lM8XazziLMnH8VkM7f6vRPXIsi+zmfIYnbNVaeysnw+LLjPZNfnC5I6U4lxg1PT4 x2RceFby1vzjIAmuRzD59ipQFzi0KIlOFKv56JTdyk6FMYr8db/piR2Ym6aLChAclgQx LnFG7YUIFWqrLz5jf0W9rzQ4LA/77P6uQxdbbDDQmbz3Xaz2X4MW1FwiPIIn01a/QLiF ldpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689429217; x=1692021217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0PrN0L5Atjyx6hFnGJcyTHnWGq2syM21Wu73egPOuXw=; b=QhXO7jLMjzfHQVSx/QjWpXJOY7skYYA3bExHcv+XFtagcSewOwoygbq6uQH0rp2imy xltJL2YinJhEVd3NC6EGWVsh9Igg+74ARP19LI91ytLIQSDDrfK7FWIBcxPaFaEdnYNG NsYafAToZvM3KEFGV8DtiCyEui2+BQgsEVieFEvZDcDwc2Y9nWtpBJhk6Dir66vcxeug TcPr7ZEST8aVJLUx46VVu+ugWUWigVcyMay2zluh9eSCpl1HEg454JQONCHGvGJ00a3q MY6wYc86/xAC/aDgZecR6292YfiykZepyMl4Oh+vjAq4sz4t34ABEJaq67+xsEgrNUsK U9Ew== X-Gm-Message-State: ABy/qLaOE7/YI2DxX+bYMdolReSEZ5zAsTD+yQ17Gu301qoeHRymktAl SVkevDwt3z0JoHp+cO48qi/7ewNtMvfB2f5rOeE3YQ== X-Received: by 2002:a05:600c:2993:b0:3f9:c82e:9d87 with SMTP id r19-20020a05600c299300b003f9c82e9d87mr6634743wmd.13.1689429217231; Sat, 15 Jul 2023 06:53:37 -0700 (PDT) Received: from stoup.lan ([51.219.12.49]) by smtp.gmail.com with ESMTPSA id k10-20020a5d66ca000000b00313f9085119sm13838014wrw.113.2023.07.15.06.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 06:53:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 22/47] linux-user/strace: Expand struct flags to hold a mask Date: Sat, 15 Jul 2023 14:52:52 +0100 Message-Id: <20230715135317.7219-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230715135317.7219-1-richard.henderson@linaro.org> References: <20230715135317.7219-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org A zero bit value does not make sense -- it must relate to some field in some way. Define FLAG_BASIC with a build-time sanity check. Adjust FLAG_GENERIC and FLAG_TARGET to use it. Add FLAG_GENERIC_MASK and FLAG_TARGET_MASK. Fix up the existing flag definitions for build errors. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson Message-Id: <20230707204054.8792-6-richard.henderson@linaro.org> --- linux-user/strace.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index 669200c4a4..9228b235da 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -46,15 +46,21 @@ struct syscallname { */ struct flags { abi_long f_value; /* flag */ + abi_long f_mask; /* mask */ const char *f_string; /* stringified flag */ }; +/* No 'struct flags' element should have a zero mask. */ +#define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N } + /* common flags for all architectures */ -#define FLAG_GENERIC(name) { name, #name } +#define FLAG_GENERIC_MASK(V, M) FLAG_BASIC(V, M, #V) +#define FLAG_GENERIC(V) FLAG_BASIC(V, V, #V) /* target specific flags (syscall_defs.h has TARGET_) */ -#define FLAG_TARGET(name) { TARGET_ ## name, #name } +#define FLAG_TARGET_MASK(V, M) FLAG_BASIC(TARGET_##V, TARGET_##M, #V) +#define FLAG_TARGET(V) FLAG_BASIC(TARGET_##V, TARGET_##V, #V) /* end of flags array */ -#define FLAG_END { 0, NULL } +#define FLAG_END { 0, 0, NULL } /* Structure used to translate enumerated values into strings */ struct enums { @@ -963,7 +969,7 @@ print_syscall_ret_ioctl(CPUArchState *cpu_env, const struct syscallname *name, #endif UNUSED static const struct flags access_flags[] = { - FLAG_GENERIC(F_OK), + FLAG_GENERIC_MASK(F_OK, R_OK | W_OK | X_OK), FLAG_GENERIC(R_OK), FLAG_GENERIC(W_OK), FLAG_GENERIC(X_OK), @@ -999,9 +1005,9 @@ UNUSED static const struct flags mode_flags[] = { }; UNUSED static const struct flags open_access_flags[] = { - FLAG_TARGET(O_RDONLY), - FLAG_TARGET(O_WRONLY), - FLAG_TARGET(O_RDWR), + FLAG_TARGET_MASK(O_RDONLY, O_ACCMODE), + FLAG_TARGET_MASK(O_WRONLY, O_ACCMODE), + FLAG_TARGET_MASK(O_RDWR, O_ACCMODE), FLAG_END, }; @@ -1010,7 +1016,9 @@ UNUSED static const struct flags open_flags[] = { FLAG_TARGET(O_CREAT), FLAG_TARGET(O_DIRECTORY), FLAG_TARGET(O_EXCL), +#if TARGET_O_LARGEFILE != 0 FLAG_TARGET(O_LARGEFILE), +#endif FLAG_TARGET(O_NOCTTY), FLAG_TARGET(O_NOFOLLOW), FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */ @@ -1075,7 +1083,7 @@ UNUSED static const struct flags umount2_flags[] = { }; UNUSED static const struct flags mmap_prot_flags[] = { - FLAG_GENERIC(PROT_NONE), + FLAG_GENERIC_MASK(PROT_NONE, PROT_READ | PROT_WRITE | PROT_EXEC), FLAG_GENERIC(PROT_EXEC), FLAG_GENERIC(PROT_READ), FLAG_GENERIC(PROT_WRITE), @@ -1103,7 +1111,7 @@ UNUSED static const struct flags mmap_flags[] = { #ifdef MAP_POPULATE FLAG_TARGET(MAP_POPULATE), #endif -#ifdef TARGET_MAP_UNINITIALIZED +#if defined(TARGET_MAP_UNINITIALIZED) && TARGET_MAP_UNINITIALIZED != 0 FLAG_TARGET(MAP_UNINITIALIZED), #endif FLAG_TARGET(MAP_HUGETLB), @@ -1201,13 +1209,13 @@ UNUSED static const struct flags statx_flags[] = { FLAG_GENERIC(AT_SYMLINK_NOFOLLOW), #endif #ifdef AT_STATX_SYNC_AS_STAT - FLAG_GENERIC(AT_STATX_SYNC_AS_STAT), + FLAG_GENERIC_MASK(AT_STATX_SYNC_AS_STAT, AT_STATX_SYNC_TYPE), #endif #ifdef AT_STATX_FORCE_SYNC - FLAG_GENERIC(AT_STATX_FORCE_SYNC), + FLAG_GENERIC_MASK(AT_STATX_FORCE_SYNC, AT_STATX_SYNC_TYPE), #endif #ifdef AT_STATX_DONT_SYNC - FLAG_GENERIC(AT_STATX_DONT_SYNC), + FLAG_GENERIC_MASK(AT_STATX_DONT_SYNC, AT_STATX_SYNC_TYPE), #endif FLAG_END, }; @@ -1481,14 +1489,10 @@ print_flags(const struct flags *f, abi_long flags, int last) const char *sep = ""; int n; - if ((flags == 0) && (f->f_value == 0)) { - qemu_log("%s%s", f->f_string, get_comma(last)); - return; - } for (n = 0; f->f_string != NULL; f++) { - if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) { + if ((flags & f->f_mask) == f->f_value) { qemu_log("%s%s", sep, f->f_string); - flags &= ~f->f_value; + flags &= ~f->f_mask; sep = "|"; n++; }