From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 81382 invoked by alias); 15 May 2015 01:08:21 -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 81371 invoked by uid 89); 15 May 2015 01:08:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f41.google.com Received: from mail-wg0-f41.google.com (HELO mail-wg0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 15 May 2015 01:08:14 +0000 Received: by wguv19 with SMTP id v19so32954802wgu.1 for ; Thu, 14 May 2015 18:08:11 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.194.161.138 with SMTP id xs10mr13481263wjb.37.1431652090932; Thu, 14 May 2015 18:08:10 -0700 (PDT) Received: by 10.194.10.68 with HTTP; Thu, 14 May 2015 18:08:10 -0700 (PDT) In-Reply-To: <82D490AB-0441-44F8-93D8-E22F7BEF3F89@realvnc.com> References: <82D490AB-0441-44F8-93D8-E22F7BEF3F89@realvnc.com> Date: Fri, 15 May 2015 01:08:00 -0000 Message-ID: Subject: Re: Crash when using closures on iOS+arm64 From: Russell Keith-Magee To: Simon Frost Cc: "libffi-discuss@sourceware.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015/txt/msg00073.txt.bz2 Hi Simon, On Fri, May 15, 2015 at 1:27 AM, Simon Frost wrot= e: > Hi, > > I=E2=80=99ve been attempting to use closures across 32-bit, 64-bit and si= mulator builds of an iOS project but I consistently see a crash on the arm6= 4 build when the closure is executed. This can be reproduced in a stripped = down Xcode project by simply copying the code from the =E2=80=9Cclosure_sim= ple.c=E2=80=9D unit test into the iOS application=E2=80=99s main.m file. I= =E2=80=99ve seen this issue on both the latest code from master and the v3.= 2.1 tagged release. > > Specifically I see an EXC_BAD_ACCESS exception when trying to call the ex= ecutable address pointer populated by ffi_closure_alloc. Somewhat interesti= ngly I see that the executable address (out param) and the writeable addres= s (return value) are set to the same value after calling ffi_closure_alloc = on arm64, whereas they have different values on armv7. This may be a red he= rring though, as I also noticed they also have the same value when running = in the i386 simulator where the code works correctly. > > All other libffi functionality appears to work fine on arm64, the only is= sue appears to be calling closures. Can anyone shed any light on this, or g= ive me any pointers as to how this could be resolved? Unfortunately I=E2=80= =99m not well enough versed in the lower levels of libffi to look into fixi= ng this myself. Yes, I've seen similar problems; master has *less* problems than the tagged release from my testing, but there are still some edge cases that don't work. As for fixing it - I'm in the same boat as you. I can provide test cases that demonstrate failures, but I have no idea how to fix those problems. Unfortunately, it looks like there aren't many people around who have an interest in iOS *and* know how the internals of libffi work. The current master code doesn't even *compile* for ARMv7 [1][2], but I haven't been able to shake out anyone who is able to address the problem. [1] https://github.com/atgreen/libffi/issues/181 [2] https://sourceware.org/ml/libffi-discuss/2015/msg00053.html Yours, Russ Magee %-)