From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60052.outbound.protection.outlook.com [40.107.6.52]) by sourceware.org (Postfix) with ESMTPS id CA9993858418 for ; Wed, 13 Jul 2022 08:37:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CA9993858418 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=AhRxXxgnXh43Yc6z+6maivijo7lfxcRwMADkc8HG2mR7vuo9nxP855bpPx4j7cBPF3lFdC/d8XIOm7ubTs3qv5e/O0z0Bvg6i/gNziqpEJ9qEyJNTCgdVClGQIBZj5BuJ1c/thsw6g7rdDgCRY5DUbTrnALHTZIQUrbeaTQxy6BUb7XUBsY+BMBCLtuh1AD5VU5LvLULJO0feKi0ssczumnssafpim4AG7fldJ/o1zFMiGFSRKwAdtooPxyc6zy7WsT04ZBHPbL7W+dmKA7AopKlC5UGemvj3bSMDTJu7LF6PuWto9OpY+JlrynJr3Q4sU3Lno8aSUDFNf/eOv4IcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iT2LMp1A4V+TkHcIvfbdJcQbMhzfNq3MhSTIWSNzPEU=; b=Krf/1zER7MRX5IPA+A1/JGi0+4P9scco4YtbLKa0Ou4cpSeilM7KUBEPlbOjfRYUZCZhM9CgmxMhlYE9MCTjhk4X3Ln9zaPUqN/tVWRqrrHK5rHyXU06v7OyEr6XeiUlAON9rCAXcu/atMPHrYpHSnL8JlSfOBIM8ntPH2FijtTy5N8AZl+zYe5c/PrxpKqA4KpfmWliY8enT05002jSYItJZFsMGf/sqEqLCJR60ixgqXTqugS1hW1wCisv2arXW6OKLHpxsHaUxXOi8nBX268QAvR/Qob20QCTV2ac5arIhw5NgW7mslhMhxN0YGCqQB5uLtBgX+FdcCJBxtfAWw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB7PR03CA0098.eurprd03.prod.outlook.com (2603:10a6:10:72::39) by VI1PR08MB5359.eurprd08.prod.outlook.com (2603:10a6:803:12f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.16; Wed, 13 Jul 2022 08:37:37 +0000 Received: from DBAEUR03FT013.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:72:cafe::e3) by DB7PR03CA0098.outlook.office365.com (2603:10a6:10:72::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12 via Frontend Transport; Wed, 13 Jul 2022 08:37:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT013.mail.protection.outlook.com (100.127.142.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.15 via Frontend Transport; Wed, 13 Jul 2022 08:37:37 +0000 Received: ("Tessian outbound 6f9e7ef31fa8:v122"); Wed, 13 Jul 2022 08:37:37 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c153269fcadeb29a X-CR-MTA-TID: 64aa7808 Received: from efcf4bb10f77.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id E2005C68-EEE4-42F8-A4E6-3A08ACC7283F.1; Wed, 13 Jul 2022 08:37:29 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id efcf4bb10f77.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 13 Jul 2022 08:37:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZQDnJ2elOSfVrdGPDtMrF/t51vv7ZsX3cUWrOeo5BSz+aXq5L88RlUEbxG/tjSk5MtMI8Q6taN5rd81qcFtchGsCKtGyb6dStSaYoLSqMIZg2YJtlEUXHJOsSCMNVMgqRnH+JcgVPKrrSWR3+kaAL4uOlMu0EVsuBwpVN3aoYnD1KS23OxxeyfunRUMKsLIy7EW6f76uEmuSqiM0i5uePyy48KSuIOFDbAs7ard+RvMR4Gz8NE86OJclqOpVb60w9LgShGSlfjHmol6g9ED61RX/REhqC8YOoeHiPp+AsMAiwIV4Oz5C7M48VGtnQ6rVHTTYagewQQShYiVupvZp9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iT2LMp1A4V+TkHcIvfbdJcQbMhzfNq3MhSTIWSNzPEU=; b=RHft5vZ4FpPEZ7uyJoyF6QJ+ol65VnnjGSCoBPkQP+IW5Oh40A+cdesl0ej5iaTY9UXh/5ll57nuJk/AU+LjZ6m6oSVMlwxUhylFyU4cxR7GLVHIKq/Y+mgLoWTpFSOnr7fX0/iXoavnuMhfo8tlMbAgSwvmgfsK/jZZ8d+DmEBbxGO+4MMDw/82Kq7esNBQIPwPvsLJyinhgrszgd9p//1LVFKHxWl/ZJqy/nD8Sy6aNgKqrmRsFDipJ2KEVaM17vI/E4RPY+4Lum/mp9tFUTR3aHUUjn6r8fcI4iHjFG61ScSkhjKApXsca9MexPpgvJfaFOhqA2M8KFuvAVQ4wQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DB9PR08MB7179.eurprd08.prod.outlook.com (2603:10a6:10:2cc::19) by VI1PR08MB3453.eurprd08.prod.outlook.com (2603:10a6:803:80::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.23; Wed, 13 Jul 2022 08:37:28 +0000 Received: from DB9PR08MB7179.eurprd08.prod.outlook.com ([fe80::7920:5d4b:d11d:d5e4]) by DB9PR08MB7179.eurprd08.prod.outlook.com ([fe80::7920:5d4b:d11d:d5e4%3]) with mapi id 15.20.5417.026; Wed, 13 Jul 2022 08:37:28 +0000 Date: Wed, 13 Jul 2022 09:37:09 +0100 From: Szabolcs Nagy To: David Malcolm Cc: Mir Immad , gcc@gcc.gnu.org, libc-alpha@sourceware.org Subject: Re: Adding file descriptor attribute(s) to gcc and glibc Message-ID: References: <260f0b41c663133cea96eb64bd85e8ba16d8a936.camel@redhat.com> <5769682d0d17579cbd72f72a4001bfa8444b80a8.camel@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5769682d0d17579cbd72f72a4001bfa8444b80a8.camel@redhat.com> X-ClientProxiedBy: SN7PR18CA0029.namprd18.prod.outlook.com (2603:10b6:806:f3::28) To DB9PR08MB7179.eurprd08.prod.outlook.com (2603:10a6:10:2cc::19) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 2ccbf468-c597-43cb-5123-08da64aaf0e7 X-MS-TrafficTypeDiagnostic: VI1PR08MB3453:EE_|DBAEUR03FT013:EE_|VI1PR08MB5359:EE_ x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: KO3Xb0lDxbUKAxj9r2Yg7ewCIT4khDeZRqTDurJTDLz+Om+A4i31OuCJPM6fkUMO4uxAbtjMvEtW5XFqw5lvwhhWPv46zsqAcLazZZBFA0v/35TbW10pS5jXeO7/CfJt4VYEJQoTC+Mn7n2R56GsdakHy8vuXqkq9pgiiKR8N8uhmMmoC+AnqF5ifsrd5nv9N1/wopWk1YIJBXUE9ohmPacgX9lL6nL2eRO+TkiBCLy8qM9NDvsScdvUDYZbLf2f1fXLpbbpzS/uHlzvVSI6yZa4dITTRQ1TFrwc1riUHEwOmoxQ2wRPtusVjJbn9Ynli2Eui7snD0iPNcb1sROmi96hTcYrqh7K2Yo02EZ+1PbuxNMKhAodQshtCd/s4AmCgUByFQO/ZbLGtQPokY5NeH1cQlTKSMZSA9r7erKyLgC8RFLog46DFLDIU/MXytyEWxaPRpGS+WbjnqURe92wcmiYA2wvTzzjqSnUpVixQI7BRQFBwJ1lU+jhHAOrXkFtKHMVLMlY3ojus1AKzDAijk5IY7mxX8bqujERw+MODBILr2ulqNufK3e1X+ZGYs4UstDjQ8gP9xpSrstATVaLzKzG2PfMy/gviywGKXnm/u/OWQhbMdoOREA8m7oUMBHj/4bnfyfW/krLM5AqAIPGw3GTonGBqo8xrS+sWkb/ycpFruD4i7irjRpclAqpMX0uOSwfgx310DCPXO5dH3rHF3Pr/uvgoEEeqQVx6hZ3382wC5Uj6qawpuRGO7ADLk4BUV4sfCJ+kveMvFBwcc1bMA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7179.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(396003)(366004)(39860400002)(346002)(376002)(136003)(6916009)(8936002)(5660300002)(26005)(186003)(6506007)(6512007)(2616005)(36756003)(86362001)(66476007)(478600001)(83380400001)(6666004)(966005)(6486002)(44832011)(8676002)(2906002)(38100700002)(66946007)(316002)(41300700001)(4326008)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3453 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 3b4ce7dc-a39a-48f8-5e8a-08da64aaeb05 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: upxLqveieXJIYsZ0IIUbqOJktwCDs05lPObPgXbgTcMB0w7GSaHHutV8JFAlHXYRwTeP2BsEw155t1gQo/5am3BQFPgscsdeoXuP4TeWFsQsH50DZqBQxAvrtfBn7jlYOoeZo4WoHqpgMC9HgYsKTmEQvNqYbjgaJSanGcLLOZwR+XKY0pnOAqGmImrojb4LcAAw/9wPj86KBnXMkgo1TnHVoInE3mKa9BQEGeKYNWafTW0eaHStLQG22YDOyZSu8PhCvwftxtPPzLEczU1TP9HrX8ASduKGcCx7BIGiK8O1gamHWnFa2nepnVJjH2YFawFJOMWQmwIj0S1zNpxQWPKAxQR9a5wzZN8kT2gWw/avdPFPxixotY3bA/ZJTax9QU5Pnq3xJ9MK4bbegJEf6G1Acf9fNv6DbEZlkMSSmgiJjp+0j8yZ1tIPN4182nZFrTzBfi4EFDIxt4Wr+66Ylqey7tMAFMr+qBxl9HuQ5dYm+DD7D4fO5ub8nMs26+41gyhq28L/T6RUgxkqrR3Fks3hvJ40StU79EIGWrDwz5poS6f5whrCkVHQT4NTRNJ3BLmsyPjWDz4oJhqiYdzw0CC46Y1lGVt/zGqY5y3NAcBNP6F2wGVZARUEJ64ALmJBG510B6nVKlCyf+nBQNtnDdImiWQXF2eUNLju0HSuykDQP8avq1LFLG/FW6SmWb0fHJ+XE5T2SW+V/NKV702xhl3SPtIJkZ+9DLCRu+GmcxDYXVcSYbbIyn8KAAHuyXHzG73DRSsJIBlvlA35R4WXu0zC7n9DWBsbElLtNWDEgWQelGeJN5iCK9zqJDA/ftNOxtVKIpcwB/vWqBXQEQG9oAbFFK3gzK6RlVPCVbwiTD8= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230016)(4636009)(396003)(39860400002)(136003)(376002)(346002)(40470700004)(46966006)(36840700001)(356005)(70206006)(4326008)(82740400003)(70586007)(81166007)(36756003)(336012)(36860700001)(82310400005)(47076005)(8676002)(316002)(966005)(107886003)(2616005)(6862004)(44832011)(86362001)(40480700001)(8936002)(5660300002)(41300700001)(2906002)(26005)(6486002)(6506007)(186003)(6666004)(83380400001)(40460700003)(478600001)(6512007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2022 08:37:37.5099 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ccbf468-c597-43cb-5123-08da64aaf0e7 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT013.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5359 X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, KAM_DMARC_NONE, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jul 2022 08:37:46 -0000 The 07/12/2022 18:25, David Malcolm via Libc-alpha wrote: > On Tue, 2022-07-12 at 18:16 -0400, David Malcolm wrote: > > On Tue, 2022-07-12 at 23:03 +0530, Mir Immad wrote: > > GCC's attribute syntax here: > >   https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html > > allows for a parenthesized list of parameters for the attribute, which > > can be: > >  (a) An identifier > >  (b) An identifier followed by a comma and a non-empty comma-separated > > list of expressions > >  (c) A possibly empty comma-separated list of expressions > > > > I'd hoped to have an argument number, with an optional extra param > > describing the direction of the access, but syntax (b) puts the > > identifier first, alas. > > > > Here's one possible way of doing it with a single attribute, via syntax > > (b): > > e.g. > >    __attribute__((fd_argument (access, 1)) > >    __attribute__((fd_argument (read, 1)) > >    __attribute__((fd_argument (write, 1)) > > > > meaning that argument 1 of the function is expected to be an open file- > > descriptor, and that it must be possible to read from/write to that fd > > for cases 2 and 3. > > > > Here are some possible examples of how glibc might use this syntax: > > > >     int dup (int oldfd) > >       __attribute((fd_argument (access, 1)); > > > >     int ftruncate (int fd, off_t length) > >       __attribute((fd_argument (access, 1)); > > > >     ssize_t pread(int fd, void *buf, size_t count, off_t offset) > >       __attribute((fd_argument (read, 1)); > > > >     ssize_t pwrite(int fd, const void *buf, size_t count,  > >                    off_t offset); > >       __attribute((fd_argument (write, 1)); > > > > ...but as I said, I'm most interested in input from glibc developers on > > this. note that glibc headers have to be namespace clean so it would be more like __attribute__((__fd_argument (__access, 1))) __attribute__((__fd_argument (__read, 1))) __attribute__((__fd_argument (__write, 1))) so it would be even shorter to write __attribute__((__fd_argument_access (1))) __attribute__((__fd_argument_read (1))) __attribute__((__fd_argument_write (1))) > > I just realized that the attribute could accept both the single integer > argument number (syntax (c)) for the "don't care about access > direction" case, or the ({read|write}, N) of syntax (b) above, giving > e.g.: > > int dup (int oldfd) > __attribute((fd_argument (1)); > > int ftruncate (int fd, off_t length) > __attribute((fd_argument (1)); > > ssize_t pread(int fd, void *buf, size_t count, off_t offset) > __attribute((fd_argument (read, 1)); > > ssize_t pwrite(int fd, const void *buf, size_t count, > off_t offset); > __attribute((fd_argument (write, 1)); > > for the above examples. > > How does that look? > Dave i think fd in ftruncate should be open for writing. to be honest, i'd expect interesting fd bugs to be dynamic and not easy to statically analyze. the use-after-unchecked-open maybe useful. i would not expect the access direction to catch many bugs.