Skip to content

sqlite3_connection_pool: support opening pools without executable-memory FFI callbacks #396

Description

@laurens-pilot

Summary

sqlite3_connection_pool currently requires the Dart VM to allocate executable memory whenever a pool is opened, even when native update hooks are disabled. This causes release/AOT Flutter applications to abort on GrapheneOS when the per-app Dynamic code loading from memory restriction is enabled.

This came up while investigating ente/ente#3436.

Root cause

RawSqliteConnectionPool.open unconditionally creates an initializer with:

NativeCallable<Pointer<InitializedPool> Function()>.isolateLocal(...)

Dart implements NativeCallable by allocating an FFI callback trampoline page and changing it from writable to executable (Dart VM source). GrapheneOS denies that mprotect operation when in-memory dynamic code loading is restricted, and the Dart VM terminates the process. The failure is fatal and cannot be caught by the application.

Setting PoolConnections(enableNativeUpdateHooks: false) does not avoid this requirement: It disables the SQLite update hooks, but the initializer NativeCallable is still constructed before pkg_sqlite3_connection_pool_open is called.

Requested behavior

Could pool initialization support an AOT path that does not dynamically allocate executable callback trampolines?

Two possible directions appear to be:

  1. Use a statically compiled Pointer.fromFunction initializer backed by carefully scoped isolate-local initialization state.
  2. Adjust the native API so the initialized connections/options can be passed without a Dart callback.

Ideally, open and openAsync would retain their current multi-isolate, exception propagation and cleanup behavior while working when new anonymous executable mappings are prohibited.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions