From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30175 invoked from network); 18 Jul 2020 01:21:44 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 18 Jul 2020 01:21:44 -0000 Received: (qmail 7846 invoked by uid 550); 18 Jul 2020 01:21:41 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 7828 invoked from network); 18 Jul 2020 01:21:40 -0000 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yqxmail.com; s=dkim; t=1595035288; bh=MsXEpFdgPKuKaTXGHqp8lSpG1vF+bkAKG7MKY9IuQjk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BTu0FGU4RRRNtXCa0NWPgfe0RK+/FPAt4Pheb3eXeMVNCji3Y7AcUNuVIdBlST/Jh SD+S3Jozvm+BW09qlI6k4GJHQcxHx/MbveguN/zD58Ib3QrJWMh2JpmsJtSikP0fZT F0zWyecTXHJVyimOU+9b3iku7De11v4/NKDLY+DwIH5sX+YMbcROdpkSz0c5WQyq9J 7wKJTHH3shq2S2d4/+QApLuOFH6m3ym8JnYJ6Zw2N/0OAG3V5RPtXYUdqRXDMzmCHm VYErayRonuAQLtvS41WUQAwBfy3W7Tq7izJm7yjPXPupi5o/LTyg3iL+shxbcVGhiL fQzEvJsWxKzDA== Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 17 Jul 2020 18:21:27 -0700 From: Hydro Flask To: musl@lists.openwall.com Cc: Carlos O'Donell , Florian Weimer In-Reply-To: <20200717233058.GJ14669@brightrain.aerifal.cx> References: <04c05d65470b5c94808481eaf724cc5d@yqxmail.com> <87pn8uwu18.fsf@oldenburg2.str.redhat.com> <4095a8a7f75becee9bcfc71024e43802@yqxmail.com> <20200717092111.GA3210874@port70.net> <7a8de0d4-d9f7-6ab2-1aec-713597b47ca8@redhat.com> <03e28c2e6beb406c3a1ce3bfa99c67eb@yqxmail.com> <20200717211050.GB3210874@port70.net> <20200717211933.GI14669@brightrain.aerifal.cx> <449cc77dc2bc153de7a2633ee8613b42@yqxmail.com> <20200717233058.GJ14669@brightrain.aerifal.cx> Message-ID: <75e93ed84f40957c3750fb42c366447b@yqxmail.com> Subject: Re: [musl] Idea: futex() system call entry point On 2020-07-17 16:30, Rich Felker wrote: > On Fri, Jul 17, 2020 at 02:37:27PM -0700, Hydro Flask wrote: >> Maybe a less complex suggestion is to expose a syscall_cp() >> function, so you can get cancellation point functionality for any >> system call. I actually quite like that option. How does that sound? > > In the specific case of futex waits, it's not clear to me that there's > any side effect for which you need to know in the cancellation handler > whether it occurred, so why can't you just enable async cancel around > syscall() and disable it again after? Oh I hadn't thought of that. That's actually a pretty good short-term solution. So you're saying: int fuxex_wait(int *uaddr, int val, const struct timespec *timeout) { int old, ret; /* pthread_setcanceltype() automatically calls pthread_testcancel() if async is enabled */ ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old); if (ret) { errno = ret; ret = -1; } ret = syscall(SYS_futex, uaddr, FUTEX_WAIT, val, timeout); old = pthread_setcanceltype(old, &old); if (old) abort(); return ret; } I think you're right that even if the futex call succeeds, it's fine to cancel since it does not mutate any meaningful observable state. I think that should satisfy all my requirements when doing this on musl. pthread_testcancel/pthread_setcanceltype should be AS-safe in musl if cancellation is disabled or the interrupted code is AC-safe. That should likely also work in other libcs assuming a sane implementation of all the required functions involved. Thank you Hydro