Repository navigation
feat(c-abi): add kernel_abi_version() for dynamic-linking consumers #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -831,6 +831,31 @@ pub unsafe extern "C" fn kernel_init_logging( | |
| } | ||
| } | ||
|
|
||
| /// The C ABI version this shared library implements. A consumer that loads the | ||
| /// kernel as a shared library (`.so`/`.dylib`/`.dll`) at run time should call | ||
| /// this immediately after `dlopen` and refuse to proceed if the value does not | ||
| /// match the version it was built against — turning an ABI mismatch (a wrong or | ||
| /// stale library dropped next to the binary) into a clear, actionable error | ||
| /// instead of silent memory corruption or a crash. | ||
| /// | ||
| /// This matters most while the C ABI is pre-1.0: per this crate's own docs the | ||
| /// struct layouts and function set "may change freely" until v1.0, so a | ||
| /// statically-linked consumer is protected by the compiler but a dynamically | ||
| /// linked one needs a runtime check. Bump this on every breaking C ABI change | ||
| /// (added/removed/renumbered function, changed struct layout or signature). | ||
| /// It is intentionally NOT the crate's semver — it tracks only the C ABI shape. | ||
| /// | ||
| /// # Safety | ||
| /// None — takes no pointers and reads no shared state. | ||
| #[no_mangle] | ||
| pub extern "C" fn kernel_abi_version() -> u32 { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Low — No test accompanies the new symbol. A one-line unit test asserting |
||
| KERNEL_C_ABI_VERSION | ||
| } | ||
|
|
||
| /// Current C ABI version. See `kernel_abi_version`. Start at 1; increment on any | ||
| /// breaking change to the C ABI (databricks_kernel.h). | ||
| pub const KERNEL_C_ABI_VERSION: u32 = 1; | ||
|
|
||
| /// Add (or overwrite) one server-bound session-conf entry. Unknown keys | ||
| /// are filtered against the kernel allowlist at `open()` time, matching | ||
| /// the Rust-crate path. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Low — The header declares the runtime accessor
kernel_abi_version()but exposes no companion compile-time constant (e.g.#define DATABRICKS_KERNEL_ABI_VERSION 1). The documented usage is to compare the runtime value against "the version it was built against", but a C/ODBC consumer building against this header has nothing in the header to compare against — it must hardcode the literal1itself, which is exactly the drift the check is meant to prevent (a stale header would keep comparing against a stale hardcoded constant).Consider emitting the constant into the header alongside the declaration so consumers can write
if (kernel_abi_version() != DATABRICKS_KERNEL_ABI_VERSION) { ... }. The Rust side already hasKERNEL_C_ABI_VERSION; keeping the header macro in lockstep with it (the same way theKernelStatusCodeenum is kept in lockstep) closes the loop for the header's own consumers.