From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700101.outbound.protection.outlook.com [40.107.70.101]) by sourceware.org (Postfix) with ESMTPS id 02A54384B822 for ; Thu, 5 Nov 2020 14:23:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 02A54384B822 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HrFZgHp/z/V/GszrFEDC4JNXzs2ZwHoaK04Rg8WNhgUko96VFCBD17wBkvbSLJ/82kuFQ6m33leooqprFLxAEE2x6Tp/zgtM3xFrnAodJLmjJoTSp2NzT1vEd6lbDFPUJTeJQ/CnEzEql8yPKGiPnOGVWmeiXzE2g8SnMndMbBvTYjkBTIuN/J1kq9Q8OpwmZ/uEyIe03tS7jOqnCN5PlbQXqKlnUAXDaT6+tCp8e3QzKrsRuMIXzunbRZxeQr1jxmRNu4p1uw59uq7tU7yvCHIspkxGSPEHHOQ5L34gDu/ztfzLGGtXsuTjnOrmXGPL53wf8CABdlkLnDBoshlzQQ== 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-SenderADCheck; bh=5w42klbhzgmd+ggG8YcVl1OZXEDh/cdtlm/bcTfzJNM=; b=iwVO//U4Vl3IXUyfV7c1RXmhIrZ4CGMa+pyBSwNPlBSlCG04GuiGj4D/UfLLFWkVhLr437iQuCUDCvQA4GgJ4o+TJFyhQFQuWJkQvLoVGVsQOKUL+qY/Wf0YdeXztvEFp1NSzDtseN+XEI2f4diU7rA/auESqbkI3cut9VEjTorinvLh6AH/cbzo3zIqzFWcZd2X4850BSwgmPdTCf4gPptl1z1WuJUHW13iuoNuTY43p8t2uXQQ+ifwgs4nDYmOIgS5tYTxLFYPozsCunBReKMd7Ab3FLbpIruFPx84rQ1haFRJK7cYF8JgIyPTUD1fB26sUyl92+z/KgHTGx+1rQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none Received: from MN2PR04MB6176.namprd04.prod.outlook.com (2603:10b6:208:e3::13) by MN2PR04MB6032.namprd04.prod.outlook.com (2603:10b6:208:d6::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.29; Thu, 5 Nov 2020 14:23:36 +0000 Received: from MN2PR04MB6176.namprd04.prod.outlook.com ([fe80::113e:c874:1207:eca8]) by MN2PR04MB6176.namprd04.prod.outlook.com ([fe80::113e:c874:1207:eca8%6]) with mapi id 15.20.3541.021; Thu, 5 Nov 2020 14:23:36 +0000 Subject: Re: AF_UNIX status report To: cygwin-developers@cygwin.com References: <1d0ea5dc-7e9b-d8fe-5f6e-da7a799a3b13@cornell.edu> <20201027094340.GJ5492@calimero.vinschen.de> <0f945b4c-aa30-e08e-9f86-d4b41279ba10@pismotec.com> <20201030092019.GW5492@calimero.vinschen.de> <38e33f7a-e87d-fea8-ac9e-826f94c189d4@cornell.edu> <20201104120304.GF33165@calimero.vinschen.de> From: Ken Brown Message-ID: <88b3dfe6-a67d-c597-afe2-4edb13cee5d7@cornell.edu> Date: Thu, 5 Nov 2020 09:23:34 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 In-Reply-To: <20201104120304.GF33165@calimero.vinschen.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [2604:6000:b407:7f00:4d7:217c:b95e:420c] X-ClientProxiedBy: BL0PR01CA0029.prod.exchangelabs.com (2603:10b6:208:71::42) To MN2PR04MB6176.namprd04.prod.outlook.com (2603:10b6:208:e3::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [IPv6:2604:6000:b407:7f00:4d7:217c:b95e:420c] (2604:6000:b407:7f00:4d7:217c:b95e:420c) by BL0PR01CA0029.prod.exchangelabs.com (2603:10b6:208:71::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Thu, 5 Nov 2020 14:23:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d221f5c1-af33-47da-a14e-08d8819661f8 X-MS-TrafficTypeDiagnostic: MN2PR04MB6032: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l3TFBdGzCH6/uEy5yoVYNpjAUR2137Yy4Ec7BrAnU96+hXxdKewnwZHfMwb+6o6JB30kQq/CckxU9KrxM/D1RCDtoC0Ei4zxoHiN7Sjb2VR1zyDtjjoRb93oOiElqgAUj0CHUIcRG/R6twkZxeU4MNyfHtiqj8LJJT4LJUeqPBbqH0qwB5Stj6V4kOGxsdBL/WUhXBXYbleZAp5vxLaCUbpZc2enfSszQvbZPPKzGXLOpwvUtHHLfQchU6EcX5QqxMbDHxTC3CICtceAJ6RksI/l7lI9V3tHj8cN0CFMW2+7CzFFchUxgqM0Lr/goU/dJ9hej5CctYDSwXGp0koi/MxHQcnVKNIUtGx/0fHXbbL6f6ULmFO2yXi5aukaC05r X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR04MB6176.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39860400002)(396003)(346002)(136003)(366004)(376002)(31686004)(5660300002)(75432002)(53546011)(31696002)(6916009)(36756003)(66556008)(4001150100001)(66476007)(66946007)(478600001)(316002)(52116002)(6486002)(786003)(2906002)(7116003)(2616005)(186003)(16526019)(86362001)(83380400001)(8676002)(8936002)(66574015)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: CVMxvWW3utLmbY7WEiqAFIY7GfNXHdj+uMIOU30nW4wEu7matuWxHQMZr1MxYI/4RqURxoUtZVJylI4WeXBKGSIrwHxGlvBEfRLtxDTJpRGrvjPLVEViG8s+qWqRcGpnUWH7ikoh7xeWBJlBhCC7Mc8FL2FQe5BJGRlP/GxaSmxUB5bx/qIeaJDPv078lbdRmVJvJ3LM7i9OwY5Sm/qLKXE5LFEBgj9hr+6jlehGW1dqdGw0xexIw4WKCasfNTd7atv1MHf98azeANsADL3q3k9ImItB+RncD7ClufYHea8T12n76vGsONvXgY+lQZgpY0eq0JPWkUDDowGQ0wiThYLiBJwTYPkwYBigSNTVYppFiwqKLYqtmxYQWpj/qGlMKcerB3EldEKjxfyNiZo53xsSfGeIC3zZOtHcOIuUCxmuWRl/y1izzX55cte/56cDhm/UZwNILWmEyMiT6XPdEJvmMCnLYu9N4ssC1P/9XJTCgAAU2YGzzpED3RPxKrWbAps+CHCPPSXIELr1/m1ItEsmpQnrWg8G0lvYlGByz80RgwnyghXMO46MZWPV66XMFa0aJzF6Lz0rsxef0mBt69i6Urxe5DFDyflMjd9j5ChTeosGZjWNtqaNteC7/bMGL4sT4FkHclTyJ5NTzuNStAw4WEQpenfULGYFV+9X06AFu+yYWgzcz2bDftCsa/9fA62HLyLpjARolwF+FQqsvA== X-OriginatorOrg: cornell.edu X-MS-Exchange-CrossTenant-Network-Message-Id: d221f5c1-af33-47da-a14e-08d8819661f8 X-MS-Exchange-CrossTenant-AuthSource: MN2PR04MB6176.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2020 14:23:36.4775 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d7e4366-1b9b-45cf-8e79-b14b27df46e1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fiDhlit9OwIwyN1cAScREt9/V25OD/5pM3Uy48RuUr4gU+cPjL2IUFzNwXDLBOLCQhoM8uK/MvNkZxtGZAigxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6032 X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, KAM_DMARC_STATUS, MSGID_FROM_MTA_HEADER, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Nov 2020 14:23:43 -0000 On 11/4/2020 7:03 AM, Corinna Vinschen wrote: > On Nov 3 10:43, Ken Brown via Cygwin-developers wrote: >> On 10/30/2020 5:20 AM, Corinna Vinschen wrote: >>> On Oct 29 14:53, Joe Lowe wrote: >>>> On 2020-10-29 13:19, Ken Brown via Cygwin-developers wrote: >>>>> On 10/27/2020 5:43 AM, Corinna Vinschen wrote: >>>>>> On Oct 26 18:04, Ken Brown via Cygwin-developers wrote: >>>>>>> 2. I haven't given any thought at all as to how to implement SCM_RIGHTS >>>>>>> ancillary data.  I could definitely use suggestions on that >>>>>>> before I start >>>>>>> thrashing around. >>>>>> >>>>>> I have only vague ideas at that point.  Assuming we can replace the >>>>>> socket implemantation with the pipe implementation, what we have is a >>>>>> pipe which can impersonate the peer at least from the server side, and >>>>>> it knows the client process.  This in turn can be used to duplicate >>>>>> handles.  So what we could do is to define fhandler methods which create >>>>>> a matching serialization  and deserialization of the fhandler data, plus >>>>>> duplicating the handles for the other process, sent over the pipe as >>>>>> admin package.  This must work in either direction, regardless if the >>>>>> server or the client sends the SCM_RIGHTS block. >>>>> >>>>> This sounds reasonable. >>>>> >>>>> I have no experience with serialization.  Do you happen to know of a >>>>> good example that I could look at? >>> >>> Unfortunately not. Probably we can just send the entire fhandler and >>> the recipient fiddles the content in a per-class way, kind of like >>> fhandler::dup. >> >> I'm working on implementing this, and I've bumped into an elementary C++ >> question. In order to send the fhandler in an admin packet, I need to >> determine its size dynamically, given an (fhandler_base *) pointer to it. >> AFAICS, this requires something like the following. >> >> In the definition of class fhandler_base, put a virtual function >> >> virtual size_t size () const { return sizeof *this; } >> >> and then repeat this essentially verbatim in every derived class: >> >> size_t size () const { return sizeof *this; } >> >> Does this seem right? I did an internet search and didn't find anything >> substantially different, although there were several suggestions to use >> templates in various ways. I'm not convinced that using templates would >> actually improve the code, but I can do it if you think it's better. > > Actually, I don't like templates that much. You could do the above, or > just always send a block of size fhandler_union. OK, here's how I imagine this working: A process wants to send a file descriptor fd, so it creates a msghdr with an SCM_RIGHTS cmsghdr and calls sendmsg. The latter creates and sends an admin packet A containing the fhandler for fd, and then it sends the original packet P. At the receiving end, recvmsg sees packet A first (recvmsg is always checking for admin packets anyway whenever it's called). It stores the fhandler somewhere. When it then reads packet P, it retrieves the stored fhandler, fiddles with it (duplicating handles, etc.), and creates the new file descriptor. Does this seem reasonable? The main thing bothering me is the lack of atomicity. I don't like the gap between the sending of the two packets A and P, and similarly for the receiving. I thought about using the io_lock to at least make sure that the two packets are adjacent in the pipe, but I don't know if we want to tie up the io_lock for that long. Also, the sending process might be sending several file descriptors at once, so that there would be several admin packets to be sent (unless we want to cram it all into one). Ken