From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Pedro Alves Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Throw an exception when mutating read-only data Date: Mon, 3 Apr 2017 11:49:45 +0100 Message-ID: References: <20170402101131.10387-1-wingo@pobox.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1491216610 24645 195.159.176.226 (3 Apr 2017 10:50:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 3 Apr 2017 10:50:10 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 To: Andy Wingo , guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Apr 03 12:50:04 2017 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cuzYd-00058X-1k for guile-devel@m.gmane.org; Mon, 03 Apr 2017 12:49:59 +0200 Original-Received: from localhost ([::1]:58479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuzYi-0002s2-SV for guile-devel@m.gmane.org; Mon, 03 Apr 2017 06:50:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuzYd-0002rk-Mq for guile-devel@gnu.org; Mon, 03 Apr 2017 06:50:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cuzYa-0005pA-F6 for guile-devel@gnu.org; Mon, 03 Apr 2017 06:49:59 -0400 Original-Received: from mail-wr0-f174.google.com ([209.85.128.174]:34721) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cuzYa-0005k3-8f for guile-devel@gnu.org; Mon, 03 Apr 2017 06:49:56 -0400 Original-Received: by mail-wr0-f174.google.com with SMTP id l43so165319722wre.1 for ; Mon, 03 Apr 2017 03:49:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=AefdUUK8m3x1QQhWgW/ThcCexTLiGElnAAmNLtiD1H8=; b=mYoZ89n0PHJnQLbFy5p8SNqEIAWiTyEwNQ01C/6zXSWTGhWPLib5VeHhZ7DJvSDuXF qONEwnLOCkNlNLePOMBVj0oQ5ztd7eBZTECt4AE7Rd5rqsYO3Rw/cilgXkNQowwRAgYe 8sUOIfqBZgk1g0T5NXfHVTgisNJ0Nv1n+XO85IXcX5+o6v1diFirWz0Bnxj0Gtm+ZWRu Y/OH8x1dGUirqWgZSiZptG0kdMsUOJs6ZN3pgp8p+Ghl+opecrAtq8Yv0J8IJibX2Asp eB45r8b22rt0fbevXkansSqoq9F6wC6+8u4ueTN6gN6mB6OoVK2H91WZyt/wvp6vGsn9 QTqA== X-Gm-Message-State: AFeK/H0YAuXZlOnHu68CvTPYwgu0Ih6YHfw5uvUsPByO2dIrq0RH8zIz hedbIbzCKsHfSQ5T2JMarw== X-Received: by 10.28.170.148 with SMTP id t142mr8932712wme.57.1491216587418; Mon, 03 Apr 2017 03:49:47 -0700 (PDT) Original-Received: from [192.168.0.101] ([37.189.166.198]) by smtp.gmail.com with ESMTPSA id p185sm13841483wme.20.2017.04.03.03.49.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 03:49:46 -0700 (PDT) In-Reply-To: <20170402101131.10387-1-wingo@pobox.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.128.174 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19093 Archived-At: Hi Andy, I'm mostly clueless on Guile's internals, but this patch caught my eye, given the potential for conflict with GDBs use of libguile. On 04/02/2017 11:11 AM, Andy Wingo wrote: > +void > +scm_maybe_throw_exception_for_mutation_of_read_only_data (void *addr) > +{ > + if (!find_mapped_elf_image_unlocked (addr)) > + return; > + > + /* Assume that a SEGV originating from access to an address in our > + mapped ELF images is because that part of the image was mapped > + read-only, and user code is trying to mutate it. Throw an > + exception instead. */ > + scm_misc_error (NULL, "Attempt to mutate read-only value", SCM_EOL); AFAICS, guile uses bare setjmp/longjmp for exceptions. But, one should not use longjmp to jump out of a signal handler, since that leaves the signal mask disabled if the system automatically masks the signal on handler entry (which is true on e.g., the Linux kernel). Instead, sigsetjmp+siglongjmp should be used, in order to restore the signal mask. Since sigsetjmp is heavy weight (it requires a system call to get the current mask [1]), I'd recommend instead to use sigsetjmp/siglongjmp around the problematic code area, and then call scm_misc_error back in mainline code (as opposed to changing SCM_I_SETJMP/SCM_I_LONGJMP and forcing all exception handling to use sigsetjmp+siglongjmp). [1] - See and the linked URL for a practical difference that made in GDB. Thanks, Pedro Alves