Skip to content

Commit 3af179f

Browse files
committed
[GR-15997] Document our implementation of FFI
1 parent b9d0ca0 commit 3af179f

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

doc/contributor/ffi.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# FFI
2+
3+
We have our own implementation of FFI, implemented entirely in Ruby + Truffle
4+
NFI.
5+
6+
Using the FFI gem C extension would be suboptimal because Sulong uses Truffle
7+
NFI to call native methods. Truffle NFI is implemented with `libffi`. The FFI C
8+
extension uses its own `libffi` to call native functions. This means we would
9+
use Truffle NFI's `libffi` to call the C extension `libffi` functions, adding
10+
overhead on every call to the C extension `libffi` functions.
11+
12+
FFI is also one way to avoid C extensions altogether, so it makes sense to not
13+
require C extension support for gems using FFI.
14+
15+
## Structure
16+
17+
* `lib/truffle/ffi`: Unchanged Ruby files from the gem.
18+
* `lib/truffle/truffle/ffi_backend`: our Ruby + Truffle NFI backend for FFI,
19+
which replaces the C extension and has the same API.
20+
* `lib/truffle/ffi.rb` coordinates `require`-ing the above.
21+
* `spec/ffi`: Specs from the FFI gem.
22+
* `src/main/ruby/truffleruby/core/truffle/ffi`: Implementation of
23+
`Truffle::FFI::Pointer`, which is also used in core and is aliased to
24+
`FFI::Pointer` once `"ffi"` is required. `Truffle::FFI::Pointer` should
25+
therefore have the same API as `FFI::Pointer` in the FFI gem.
26+
* `tool/import-ffi.sh`: Imports files from a checkout of the FFI gem.

doc/legal/legal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ files.
141141

142142
#### FFI
143143

144-
TruffleRuby includes parts of the FFI gem 1.9.25. The FFI gem is copyright
144+
TruffleRuby includes parts of the FFI gem 1.11.1. The FFI gem is copyright
145145
2008-2016, Ruby FFI project contributors, and covered by the three-clause BSD
146146
licence (see `ffi.txt`).
147147

doc/user/security.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ Consider potential vulnerabilities in your system `libssl`.
138138

139139
## FFI
140140

141-
We are not aware of any known vulnerabilities.
141+
Number | Description | Their Mitigation | Test | Our Mitigation
142+
--- | --- | --- | --- | ---
143+
CVE-2018-1000201 | A DLL loading issue can be hijacked on Windows when a `Symbol` is used for the library name | Treat Symbols the same as Strings in `ffi_lib` | | Applied the same mitigation, by using a version of FFI which fixed this vulnerability
142144

143145
# Notes on hashing
144146

doc/user/truffleruby-additions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ and set.
7777

7878
`AtomicReference` is marshalable.
7979

80+
## FFI
81+
82+
TruffleRuby includes a built-in implementation of [Ruby-FFI](https://github.com/ffi/ffi),
83+
compatible with version 1.11.1 of the `ffi` gem. This should be transparent: you can
84+
just install the `ffi` gem as normal, and it will use our built-in implementation,
85+
regardless of the version of the `ffi` gem.
86+
8087
## Polyglot programming
8188

8289
The `Polyglot` and `Java` modules provides access to the polyglot programming

0 commit comments

Comments
 (0)