From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 114286 invoked by alias); 3 Jul 2019 22:54:08 -0000 Mailing-List: contact libffi-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libffi-discuss-owner@sourceware.org Received: (qmail 114276 invoked by uid 89); 3 Jul 2019 22:54:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-5.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=cif, HX-Languages-Length:1009 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 Jul 2019 22:54:07 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F7D485A07 for ; Wed, 3 Jul 2019 22:54:06 +0000 (UTC) Received: from greed.delorie.com (ovpn-122-150.rdu2.redhat.com [10.10.122.150]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2B675C88D; Wed, 3 Jul 2019 22:54:03 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.14.7/8.14.7) with ESMTP id x63Ms2SY019646; Wed, 3 Jul 2019 18:54:02 -0400 From: DJ Delorie To: Anthony Green Cc: libffi-discuss@sourceware.org, fweimer@redhat.com Subject: Re: segfault in ffi_data_to_code_pointer In-Reply-To: <875zoirazv.fsf@laptop.atgreen.org> (message from Anthony Green on Wed, 03 Jul 2019 18:47:48 -0400) Date: Wed, 03 Jul 2019 22:54:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2019/txt/msg00019.txt.bz2 Anthony Green writes: > No, they should be using ffi_closure_alloc(). > > Can you point me at the ruby code that does this? ruby 2.6.3 ext/fiddle/closure.c In the failing case, USE_FFI_CLOSURE_ALLOC is not set static VALUE allocate(VALUE klass) { fiddle_closure * closure; VALUE i = TypedData_Make_Struct(klass, fiddle_closure, &closure_data_type, closure); fprintf (stderr, "DJ: allocate\n"); #if USE_FFI_CLOSURE_ALLOC closure->pcl = ffi_closure_alloc(sizeof(ffi_closure), &closure->code); #else closure->pcl = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); #endif return i; } initialize() { . . . #if USE_FFI_CLOSURE_ALLOC result = ffi_prep_closure_loc(pcl, cif, callback, (void *)self, cl->code); #else result = ffi_prep_closure(pcl, cif, callback, (void *)self); cl->code = (void *)pcl; i = mprotect(pcl, sizeof(*pcl), PROT_READ | PROT_EXEC); if (i) { rb_sys_fail("mprotect"); } #endif . . . }