From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22300 invoked by alias); 3 Jul 2019 23:14:22 -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 22290 invoked by uid 89); 3 Jul 2019 23:14:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=Anthony X-HELO: mail-io1-f48.google.com Received: from mail-io1-f48.google.com (HELO mail-io1-f48.google.com) (209.85.166.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 Jul 2019 23:14:21 +0000 Received: by mail-io1-f48.google.com with SMTP id i10so8810529iol.13 for ; Wed, 03 Jul 2019 16:14:20 -0700 (PDT) Return-Path: Received: from localhost ([2607:fea8:551f:e9a1:56e1:adff:fea8:87d7]) by smtp.gmail.com with ESMTPSA id s24sm357138ioc.58.2019.07.03.16.14.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 16:14:18 -0700 (PDT) From: Anthony Green To: DJ Delorie Cc: Anthony Green , libffi-discuss@sourceware.org, fweimer@redhat.com Subject: Re: segfault in ffi_data_to_code_pointer References: Date: Wed, 03 Jul 2019 23:14:00 -0000 In-Reply-To: (DJ Delorie's message of "Wed, 03 Jul 2019 18:54:02 -0400") Message-ID: <878ste90dy.fsf@laptop.atgreen.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2019/txt/msg00020.txt.bz2 DJ Delorie writes: > 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 Thanks. This looks right to me. Perhaps they wrote this before ffi_closure_alloc() existed? I don't remember when every bit was introduced... Looks like you need to follow up with the ruby people. Thanks DJ, AG > 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 > . . . > }