Skip to content

Instantly share code, notes, and snippets.

@xijo
Created May 25, 2015 13:21
Show Gist options
  • Save xijo/143140c52bf3f35720da to your computer and use it in GitHub Desktop.
Save xijo/143140c52bf3f35720da to your computer and use it in GitHub Desktop.
require 'ffi'
module Hello
extend FFI::Library
ffi_lib 'target/release/libembed.dylib'
attach_function :process, [ :string ], :string
end
puts Hello.process('foo')
#[no_mangle]
pub extern fn process(foo: f32) -> f32 {
foo
}
@xijo
Copy link
Author

xijo commented May 25, 2015

Segmentation faults instantly:

embed.rb:9: [BUG] Segmentation fault at 0x00000000000000
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:
     * ~/Library/Logs/CrashReporter
     * /Library/Logs/CrashReporter
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.

-- Control frame information -----------------------------------------------
c:0003 p:---- s:0009 e:000008 CFUNC  :process
c:0002 p:0032 s:0005 E:000640 EVAL   embed.rb:9 [FINISH]
c:0001 p:0000 s:0002 E:0001d0 TOP    [FINISH]

-- Ruby level backtrace information ----------------------------------------
embed.rb:9:in `<main>'
embed.rb:9:in `process'

-- Machine register context ------------------------------------------------
 rax: 0x0000000000000008 rbx: 0x1d1d1d1d1d1d1d1d rcx: 0x1d1d1d1d1d1d1d1d
 rdx: 0x1d1d1d1d1d1d1d1d rdi: 0x1d1d1d1d1d1d1d10 rsi: 0x00000001025997f4
 rbp: 0x00007fff5daae100 rsp: 0x00007fff5daae100  r8: 0x00007ffe4a4092c8
  r9: 0x0000000000000962 r10: 0x0000000000007000 r11: 0x0000000102279e10
 r12: 0x00007fff5daae140 r13: 0x00007ffe2a695fd8 r14: 0x00007fff5daae150
 r15: 0x00007fff5daae170 rip: 0x00007fff84f4d152 rfl: 0x0000000000010202

-- C level backtrace information -------------------------------------------
0   ruby                                0x00000001022f0765 rb_vm_bugreport + 149
1   ruby                                0x0000000102193a19 rb_bug_context + 473
2   ruby                                0x000000010226af43 sigsegv + 83
3   libsystem_platform.dylib            0x00007fff88218f1a _sigtramp + 26
4   libsystem_c.dylib                   0x00007fff84f4d152 strlen + 18
5   ???                                 0x00007fff5daae120 0x0 + 140734764867872

-- Other runtime information -----------------------------------------------

* Loaded script: embed.rb

* Loaded features:

    0 enumerator.so
    1 rational.so
    2 complex.so
    3 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/x86_64-darwin14/enc/encdb.bundle
    4 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/x86_64-darwin14/enc/trans/transdb.bundle
    5 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/unicode_normalize.rb
    6 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/x86_64-darwin14/rbconfig.rb
    7 thread.rb
    8 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/x86_64-darwin14/thread.bundle
    9 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/compatibility.rb
   10 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/defaults.rb
   11 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/deprecate.rb
   12 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/errors.rb
   13 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/version.rb
   14 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/requirement.rb
   15 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/platform.rb
   16 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/basic_specification.rb
   17 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/stub_specification.rb
   18 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/util/stringio.rb
   19 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/specification.rb
   20 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/exceptions.rb
   21 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb
   22 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb
   23 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb
   24 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems.rb
   25 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/path_support.rb
   26 ~/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/dependency.rb
   27 ~/.gem/ruby/2.2.2/extensions/x86_64-darwin-14/2.2.0-static/ffi-1.9.8/ffi_c.bundle
   28 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/platform.rb
   29 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/types.rb
   30 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/library.rb
   31 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/errno.rb
   32 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/pointer.rb
   33 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/memorypointer.rb
   34 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/struct_layout_builder.rb
   35 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/struct.rb
   36 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/union.rb
   37 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/managedstruct.rb
   38 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/callback.rb
   39 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/io.rb
   40 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/autopointer.rb
   41 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/variadic.rb
   42 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/enum.rb
   43 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi/ffi.rb
   44 ~/.gem/ruby/2.2.2/gems/ffi-1.9.8/lib/ffi.rb

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
Don't forget to include the above Crash Report log file.
For details: http://www.ruby-lang.org/bugreport.html

Abort trap: 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment