summaryrefslogtreecommitdiff
path: root/ext/ffi/lib.rs
AgeCommit message (Collapse)Author
2024-11-04refactor(runtime/permissions): use concrete error types (#26464)Leo Kettmeir
2024-10-14refactor(ext/ffi): use concrete error types (#26170)Leo Kettmeir
2024-09-16refactor(permissions): split up Descriptor into Allow, Deny, and Query (#25508)David Sherret
This makes the permission system more versatile.
2024-09-12refactor: cleanup unstable checks for WebGPU, FFI and FS APIs (#25586)Asher Gomez
Continuation of work in #25488. --------- Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com>
2024-06-06refactor: remove `PermissionsContainer` in deno_runtime (#24119)David Sherret
Also removes permissions being passed in for node resolution. It was completely useless because we only checked it for reading package.json files, but Deno reading package.json files for resolution is perfectly fine. My guess is this is also a perf improvement because Deno is doing less work.
2024-05-28BREAKING(ffi/unstable): always return u64 as bigint (#23981)Divy Srivastava
The mixed `number | bigint` representation was useful optimization for pointers. Now, pointers are represented as V8 externals. As part of the FFI stabilization effort we want to make `bigint` the only representation for `u64` and `i64`. BigInt representation performance is almost on par with mixed representation with the added benefit that its less confusing and users don't need manual checks and conversions for doing operations on the value. ``` cpu: AMD Ryzen 5 7530U with Radeon Graphics runtime: deno 1.43.6+92a8d09 (x86_64-unknown-linux-gnu) file:///home/divy/gh/ffi/main.ts benchmark time (avg) iter/s (min … max) p75 p99 p995 -------------------------------------------------------------------------- ----------------------------- nop 4.01 ns/iter 249,533,690.5 (3.97 ns … 10.8 ns) 3.97 ns 4.36 ns 9.03 ns ret bigint 7.74 ns/iter 129,127,186.8 (7.72 ns … 10.46 ns) 7.72 ns 8.11 ns 8.82 ns ret i32 7.81 ns/iter 128,087,100.5 (7.77 ns … 12.72 ns) 7.78 ns 8.57 ns 9.75 ns ret bigint (add op) 15.02 ns/iter 66,588,253.2 (14.64 ns … 24.99 ns) 14.76 ns 19.13 ns 19.44 ns ret i32 (add op) 12.02 ns/iter 83,209,131.8 (11.95 ns … 18.18 ns) 11.98 ns 13.11 ns 14.5 ns ```
2024-01-01chore: update copyright to 2024 (#21753)David Sherret
2023-12-12perf(ext/ffi): switch from middleware to tasks (#21239)Matt Mastracci
Deno-side changes for https://github.com/denoland/deno_core/pull/350 --------- Co-authored-by: Aapo Alasuutari <aapo.alasuutari@gmail.com>
2023-10-12refactor: FeatureChecker integration in ext/ crates (#20797)Bartek Iwańczuk
Towards https://github.com/denoland/deno/issues/20779.
2023-10-05chore(ext/ffi): migrate from op -> op2 for ffi (#20509)Matt Mastracci
Migrate to op2. Making a few decisions to get this across the line: - Empty slices, no matter where the come from, are null pointers. The v8 bugs (https://bugs.chromium.org/p/v8/issues/detail?id=13489) and (https://bugs.chromium.org/p/v8/issues/detail?id=13488) make passing around zero-length slice pointers too dangerous as they might be uninitialized or null data. - Offsets and lengths are `#[number] isize` and `#[number] usize` respectively -- 53 bits should be enough for anyone - Pointers are bigints. This is a u64 in the fastcall world, and can accept Integer/Int32/Number/BigInt v8 types in the slow world.
2023-10-04refactor: use deno_core::FeatureChecker for unstable checks (#20765)Bartek Iwańczuk
2023-08-03feat(permissions): add "--deny-*" flags (#19070)Asher Gomez
This commit adds new "--deny-*" permission flags. These are complimentary to "--allow-*" flags. These flags can be used to restrict access to certain resources, even if they were granted using "--allow-*" flags or the "--allow-all" ("-A") flag. Eg. specifying "--allow-read --deny-read" will result in a permission error, while "--allow-read --deny-read=/etc" will allow read access to all FS but the "/etc" directory. Runtime permissions APIs ("Deno.permissions") were adjusted as well, mainly by adding, a new "PermissionStatus.partial" field. This field denotes that while permission might be granted to requested resource, it's only partial (ie. a "--deny-*" flag was specified that excludes some of the requested resources). Eg. specifying "--allow-read=foo/ --deny-read=foo/bar" and then querying for permissions like "Deno.permissions.query({ name: "read", path: "foo/" })" will return "PermissionStatus { state: "granted", onchange: null, partial: true }", denoting that some of the subpaths don't have read access. Closes #18804. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
2023-07-30perf(ext/ffi): Avoid receiving on FFI async work channel when no ↵Aapo Alasuutari
UnsafeCallback exists (#19454)
2023-05-07fix(ext/ffi): UnsafeCallback can hang with 'deno test' (#19018)Aapo Alasuutari
2023-03-17perf(core) Reduce copying and cloning in extension initialization (#18252)Matt Mastracci
Follow-up to #18210: * we are passing the generated `cfg` object into the state function rather than passing individual config fields * reduce cloning dramatically by making the state_fn `FnOnce` * `take` for `ExtensionBuilder` to avoid more unnecessary copies * renamed `config` to `options`
2023-03-17feat(core) deno_core::extension! macro to simplify extension registration ↵Matt Mastracci
(#18210) This implements two macros to simplify extension registration and centralize a lot of the boilerplate as a base for future improvements: * `deno_core::ops!` registers a block of `#[op]`s, optionally with type parameters, useful for places where we share lists of ops * `deno_core::extension!` is used to register an extension, and creates two methods that can be used at runtime/snapshot generation time: `init_ops` and `init_ops_and_esm`. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-03-09refactor(core): remove RuntimeOptions::extensions_with_js (#18099)Bartek Iwańczuk
This commit removes "deno_core::RuntimeOptions::extensions_with_js". Now it's embedders' responsibility to properly register extensions that will not contains JavaScript sources when running from an existing snapshot. Prerequisite for https://github.com/denoland/deno/pull/18080
2023-03-09refactor: Split extension registration for runtime and snapshotting (#18095)Bartek Iwańczuk
This commit splits "<ext_name>::init" functions into "init_ops" and "init_ops_and_esm". That way we don't have to construct list of ESM sources on each startup if we're running with a snapshot. In a follow up commit "deno_core" will be changed to not have a split between "extensions" and "extensions_with_js" - it will be embedders' responsibility to pass appropriately configured extensions. Prerequisite for https://github.com/denoland/deno/pull/18080
2023-03-09refactor(core): Extension::builder_with_deps (#18093)Bartek Iwańczuk
Prerequisite for https://github.com/denoland/deno/pull/18080
2023-03-07refactor(core): don't use Result in ExtensionBuilder::state (#18066)Bartek Iwańczuk
There's no point for this API to expect result. If something fails it should result in a panic during build time to signal to embedder that setup is wrong.
2023-03-05refactor: move "pathFromURL" to deno_web extension (#18037)Bartek Iwańczuk
This API is required by several extensions like "ext/node", "ext/ffi" and also FS APIs that we want to move to a separate crate. Because of that "pathFromURL" API was moved to "deno_web" extension so other extension crates can rely on it.
2023-02-22fix(ext/ffi): Fix re-ref'ing UnsafeCallback (#17704)Aapo Alasuutari
2023-02-22feat(ext/ffi): Replace pointer integers with v8::External objects (#16889)Aapo Alasuutari
2023-02-07 refactor: remove prefix from include_js_files & use extension name (#17683)Leo Kettmeir
2023-02-07refactor: Use ES modules for internal runtime code (#17648)Leo Kettmeir
This PR refactors all internal js files (except core) to be written as ES modules. `__bootstrap`has been mostly replaced with static imports in form in `internal:[path to file from repo root]`. To specify if files are ESM, an `esm` method has been added to `Extension`, similar to the `js` method. A new ModuleLoader called `InternalModuleLoader` has been added to enable the loading of internal specifiers, which is used in all situations except when a snapshot is only loaded, and not a new one is created from it. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-02-05 refactor: rename `deno` specifiers to `internal` (#17655)Leo Kettmeir
2023-01-27chore: upgrade to Rust 1.67 (#17548)David Sherret
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-01-08feat(core): allow specifying name and dependencies of an Extension (#17301)Leo Kettmeir
2023-01-02chore: update copyright year to 2023 (#17247)David Sherret
Yearly tradition of creating extra noise in git.
2022-12-12refactor(ext/ffi): split into multiple parts (#16950)Divy Srivastava
- [x] `dlfcn.rs` - `dlopen()`-related code. - [x] `turbocall.rs` - Call trampoline JIT compiler. - [x] `repr.rs` - Pointer representation. Home of the UnsafePointerView ops. - [x] `symbol.rs` - Function symbol related code. - [x] `callback.rs` - Home of `Deno.UnsafeCallback` ops. - [x] `ir.rs` - Intermediate representation for values. Home of the `NativeValue` type. - [x] `call.rs` - Generic call ops. Home to everything related to calling FFI symbols. - [x] `static.rs` - static symbol support I find easier to work with this setup, I eventually want to expand TurboCall to unroll type conversion loop in generic calls, generate code for individual symbols (lazy function pointers), etc.
2022-12-05fix(ops): disallow auto-borrowing OpState across potential await point (#16952)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/16934 Example compiler error: ``` error: mutable opstate is not supported in async ops --> core/ops_builtin.rs:122:1 | 122 | #[op] | ^^^^^ | = note: this error originates in the attribute macro `op` (in Nightly builds, run with -Z macro-backtrace for more info) ```
2022-11-27fix(ext/ffi): Null buffer pointer value is inconsistent (#16625)Aapo Alasuutari
Currently, slow call path will always create a dangling pointer to replace a null pointer when called with eg. a `new Uint8Array()` parameter, which V8 initialises as a null pointer backed buffer. However, the fast call path will never change the pointer value and will thus expose a null pointer. Thus, it's possible that the pointer value that a native call sees coming from Deno changes between two sequential invocations of the same function with the exact same parameters. Since null pointers can be quite important, and `Uint8Array` is the chosen fast path for Deno FFI `"buffer"` parameters, I think it is fairly important that the null pointer be properly exposed to the native code. Thus this PR. ### `*mut c_void` While here, I also changed the type of our pointer values to `*mut c_void`. This is mainly due to JS buffers always being `*mut`, and because we offer a way to turn a pointer into a JS `ArrayBuffer` (`op_ffi_get_buf`) which is read-write. I'm not exactly sure which way we should really go here, we have pointers that are definitely mut but we also cannot assume all of our pointers are. So, do we go with the maxima or the minima? ### `optimisedCall(new Uint8Array())` V8 seems to have a bug where calling an optimised function with a newly created empty `Uint8Array` (no argument or 0) will not see the data pointer being null but instead it's some stable pointer, perhaps pointing to some internal null-backing-store. The pointer value is also an odd (not even) number, so it might specifically be a tagged pointer. This will probably be an issue for some users, if they try to use eg. `method(cstr("something"), new Uint8Array())` as a way to do a fast call to `method` with a null pointer as the second parameter. If instead of a `new Uint8Array()` the user instead uses some `const NULL = new Uint8Array()` where the `NULL` buffer has been passed to a slow call previously, then the fast call will properly see a null pointer. I'll take this up with some V8 engineers to see if this couldn't be fixed.
2022-11-26feat(ops): support raw pointer arguments (#16826)Divy Srivastava
See https://github.com/denoland/deno/pull/16814#discussion_r1032744083. Allows nullable buffers in low-level ops like FFI: ```rust fn op_ffi_ptr_of<FP>( state: &mut OpState, buf: *const u8, out: &mut [u32], ) where FP: FfiPermissions + 'static { // .. } ```
2022-10-20chore: upgrade rusty_v8 to 0.54.0 (#16368)Bartek Iwańczuk
<!-- Before submitting a PR, please read http://deno.land/manual/contributing 1. Give the PR a descriptive title. Examples of good title: - fix(std/http): Fix race condition in server - docs(console): Update docstrings - feat(doc): Handle nested reexports Examples of bad title: - fix #7123 - update docs - fix bugs 2. Ensure there is a related issue and it is referenced in the PR text. 3. Ensure there are tests that cover the changes. 4. Ensure `cargo test` passes. 5. Ensure `./tools/format.js` passes without changing files. 6. Ensure `./tools/lint.js` passes. -->
2022-10-20feat(ext/ffi): Make op_ffi_ptr_of fast (#16297)Aapo Alasuutari
Makes `op_ffi_ptr_of` fast. One of the tests changed from printing `false` to `true` as the fast `&[u8]` slice path creates the slice with a null pointer. Thus the `op_ffi_ptr_of` will now return a null pointer value whereas previously it returned a dangling pointer value.
2022-10-20perf(ext/ffi): Fast UnsafePointerView read functions (#16351)Aapo Alasuutari
This PR makes pointer read methods of `Deno.UnsafePointerView` Fast API compliant, with the exception of `getCString` which cannot be made fast with current V8 Fast API.
2022-10-15fix(ext/ffi): Fix UnsafeCallback ref'ing making Deno enter a live-loop (#16216)Aapo Alasuutari
Fixes #15136 Currently `UnsafeCallback` class' `ref()` and `unref()` methods rely on the `event_loop_middleware` implementation in core. If even a single `UnsafeCallback` is ref'ed, then the FFI event loop middleware will always return `true` to signify that there may still be more work for the event loop to do. The middleware handling in core does not wait a moment to check again, but will instead synchronously directly re-poll the event loop and middlewares for more work. This becomes a live-loop. This PR introduces a `Future` implementation for the `CallbackInfo` struct that acts as the intermediary data storage between an `UnsafeCallback` and the `libffi` C callback. Ref'ing a callback now means calling an async op that binds to the `CallbackInfo` Future and only resolves once the callback is unref'ed. The `libffi` C callback will call the waker of this Future when it fires to make sure that the main thread wakes up to receive the callback.
2022-10-13fix(ext/ffi): Invalid 'function' return type check logic, remove U32x2 as ↵Aapo Alasuutari
unnecessary (#16259) The return type checking for `"function"` type FFI values was incorrect and presumed that functions were still being registered as objects containing a "function" key. While here, I also removed the whole return type checking logic as it was needed for optionally creating BigInts on return when needed, but serde_v8 does this automatically now (I think).
2022-10-07fix(ext/ffi): Fix usize and isize FFI callback parameters missing match arm ↵Aapo Alasuutari
(#16172) Mea culpa. Back when I re-introduced parameter and return value types to FFI callbacks I failed to properly account for the change in match arm logic. As a result, usize and isize parameters in FFI callbacks currently enter the branch meant for void only. This PR changes the match arms to all be explicit, making sure that void is the only arm marked unreachable and that it stays that way.
2022-09-07perf(ops): inline &[u8] arguments and enable fast API (#15731)Divy Srivastava
2022-09-07feat(ext/ffi): Implement FFI fast-call trampoline with Dynasmrt (#15305)Arnau Orriols
2022-09-05feat(ext/ffi): Support bool FFI type (#15754)Aapo Alasuutari
2022-08-23BREAKING(ext/ffi): specialized `buffer` type (#15518)Divy Srivastava
2022-08-21chore: use Rust 1.63.0 (#15464)Mathias Lafeldt
2022-08-10fix(ext/ffi): unstable op_ffi_unsafe_callback_ref (#15439)Luca Casonato
2022-08-05fix(ext/ffi): Check CStr for UTF-8 validity on read (#15318)Aapo Alasuutari
Co-authored-by: Phosra <phosra@tutanota.com>
2022-07-28perf(ext/ffi): use fast api calls for 64bit return types (#15313)Divy Srivastava
2022-07-27perf(ext/ffi): support Uint8Array in fast calls (#15319)Divy Srivastava
2022-07-27chore(ext/ffi): Remove unnecessary byte_offset conditional slicing (#15320)Aapo Alasuutari
2022-07-24chore(ext/ffi): remove dependency on stdint.h (#15294)Divy Srivastava