Skip to content

[Rust] Add Platform::register_calling_convention - #8651

Merged
emesare merged 3 commits into
Vector35:devfrom
jrozner:rust-platform-register-calling-convention
Oct 11, 2026
Merged

emesare merged 3 commits into
Vector35:devfrom
jrozner:rust-platform-register-calling-convention

Conversation

@jrozner

@jrozner jrozner commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds Platform::register_calling_convention, a safe wrapper for BNRegisterPlatformCallingConvention, so a platform can be given calling conventions that aren't tied to a role.

Motivation

The Rust crate can set the default/cdecl/stdcall/fastcall/syscall conventions on a platform, and calling_conventions() lists what's registered, but nothing registers an extra one. A plugin that creates its own platforms (Platform::new + register_os) currently has to look up handles by name and call binaryninjacore_sys directly in unsafe code to make the architecture's other calling conventions available on them, because Platform::handle and CoreCallingConvention::handle are pub(crate). The Python API already has Platform.register_calling_convention.

Change

  • pub fn register_calling_convention(&self, cc: &CoreCallingConvention) on Platform, next to the role setters. It uses the same architecture-match assertion as the cc_func! setters and then calls BNRegisterPlatformCallingConvention.
  • A test in rust/tests/platform.rs creates an x86_64 platform, registers win64, and checks that calling_conventions() returns it.

Testing

  • cargo check -p binaryninja
  • cargo test -p binaryninja --test platform -- --test-threads=1 (all 5 pass, including the new test), against a headless install
  • rustfmt --check on the changed files

Expose BNRegisterPlatformCallingConvention so a platform can be given
calling conventions beyond the default/cdecl/stdcall/fastcall/syscall
roles. Like the role setters, it asserts that the calling convention's
architecture matches the platform's.
arch_handle is already a CoreArchitecture, so .borrow().as_ref() was a
no-op that clippy flags as useless_asref. Compare the handles directly.
@emesare emesare self-assigned this Oct 10, 2026
@emesare emesare added the Component: Rust API Issue needs changes to the Rust API label Oct 10, 2026
@emesare
emesare self-requested a review October 10, 2026 18:46
@emesare
emesare merged commit f15f46d into Vector35:dev Oct 11, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Rust API Issue needs changes to the Rust API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants