Skip to content

Commit 9d31155

Browse files
committed
Update int_arg_registers return empty vector.
1 parent f42aa59 commit 9d31155

File tree

2 files changed

+122
-17
lines changed

2 files changed

+122
-17
lines changed

arch/riscv/src/lib.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use binaryninja::{
1515
UnusedRegisterStackInfo,
1616
},
1717
binary_view::{BinaryView, BinaryViewExt},
18-
calling_convention::{register_calling_convention, CallingConvention, ConventionBuilder},
18+
calling_convention::{
19+
register_calling_convention, CallingConvention, ConventionBuilder, RegisterListKind,
20+
},
1921
custom_binary_view::{BinaryViewType, BinaryViewTypeExt},
2022
disassembly::{InstructionTextToken, InstructionTextTokenKind},
2123
function::Function,
@@ -2842,6 +2844,27 @@ impl<D: RiscVDisassembler> CallingConvention for RiscVCC<D> {
28422844
fn are_argument_registers_used_for_var_args(&self) -> bool {
28432845
true
28442846
}
2847+
2848+
// Register-list/class based API - default implementations for simple calling convention
2849+
fn register_argument_classes(&self) -> Vec<u32> {
2850+
Vec::new()
2851+
}
2852+
2853+
fn register_argument_class_lists(&self, _class_id: u32) -> Vec<u32> {
2854+
Vec::new()
2855+
}
2856+
2857+
fn register_argument_lists(&self) -> Vec<u32> {
2858+
Vec::new()
2859+
}
2860+
2861+
fn register_argument_list_regs(&self, _reg_list_id: u32) -> Vec<RegisterId> {
2862+
Vec::new()
2863+
}
2864+
2865+
fn register_argument_list_kind(&self, _reg_list_id: u32) -> RegisterListKind {
2866+
RegisterListKind::IntegerSemantics
2867+
}
28452868
}
28462869

28472870
struct RiscVELFPLTRecognizer;

rust/src/calling_convention.rs

Lines changed: 98 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,24 @@ pub trait CallingConvention: Sync {
6161
fn implicitly_defined_registers(&self) -> Vec<RegisterId>;
6262
fn are_argument_registers_used_for_var_args(&self) -> bool;
6363

64+
// Register-list/class based API with default implementations
6465
// Register-list/class based API with default implementations
6566
fn register_argument_classes(&self) -> Vec<u32> {
66-
Vec::new()
67+
vec![]
6768
}
68-
69+
6970
fn register_argument_class_lists(&self, _class_id: u32) -> Vec<u32> {
70-
Vec::new()
71+
vec![]
7172
}
72-
73+
7374
fn register_argument_lists(&self) -> Vec<u32> {
74-
Vec::new()
75+
vec![]
7576
}
76-
77+
7778
fn register_argument_list_regs(&self, _reg_list_id: u32) -> Vec<RegisterId> {
78-
Vec::new()
79+
vec![]
7980
}
80-
81+
8182
fn register_argument_list_kind(&self, _reg_list_id: u32) -> RegisterListKind {
8283
RegisterListKind::IntegerSemantics
8384
}
@@ -354,10 +355,7 @@ where
354355
})
355356
}
356357

357-
extern "C" fn cb_register_argument_lists<C>(
358-
ctxt: *mut c_void,
359-
count: *mut usize,
360-
) -> *mut u32
358+
extern "C" fn cb_register_argument_lists<C>(ctxt: *mut c_void, count: *mut usize) -> *mut u32
361359
where
362360
C: CallingConvention,
363361
{
@@ -408,8 +406,12 @@ where
408406
ffi_wrap!("CallingConvention::register_argument_list_kind", unsafe {
409407
let ctxt = &*(ctxt as *mut CustomCallingConventionContext<C>);
410408
match ctxt.cc.register_argument_list_kind(reg_list_id) {
411-
RegisterListKind::IntegerSemantics => BNRegisterListKind::REGISTER_LIST_KIND_INTEGER_SEMANTICS,
412-
RegisterListKind::FloatSemantics => BNRegisterListKind::REGISTER_LIST_KIND_FLOAT_SEMANTICS,
409+
RegisterListKind::IntegerSemantics => {
410+
BNRegisterListKind::REGISTER_LIST_KIND_INTEGER_SEMANTICS
411+
}
412+
RegisterListKind::FloatSemantics => {
413+
BNRegisterListKind::REGISTER_LIST_KIND_FLOAT_SEMANTICS
414+
}
413415
}
414416
})
415417
}
@@ -789,8 +791,12 @@ impl CallingConvention for CoreCallingConvention {
789791
unsafe {
790792
let kind = BNGetRegisterArgumentListKind(self.handle, reg_list_id);
791793
match kind {
792-
BNRegisterListKind::REGISTER_LIST_KIND_INTEGER_SEMANTICS => RegisterListKind::IntegerSemantics,
793-
BNRegisterListKind::REGISTER_LIST_KIND_FLOAT_SEMANTICS => RegisterListKind::FloatSemantics,
794+
BNRegisterListKind::REGISTER_LIST_KIND_INTEGER_SEMANTICS => {
795+
RegisterListKind::IntegerSemantics
796+
}
797+
BNRegisterListKind::REGISTER_LIST_KIND_FLOAT_SEMANTICS => {
798+
RegisterListKind::FloatSemantics
799+
}
794800
}
795801
}
796802
}
@@ -940,6 +946,12 @@ pub struct ConventionBuilder<A: Architecture> {
940946

941947
arch_handle: A::Handle,
942948
_arch: PhantomData<*const A>,
949+
950+
register_argument_classes: Vec<u32>,
951+
register_argument_class_lists: Vec<u32>,
952+
register_argument_lists: Vec<u32>,
953+
register_argument_list_regs: Vec<RegisterId>,
954+
register_argument_list_kind: RegisterListKind,
943955
}
944956

945957
macro_rules! bool_arg {
@@ -984,6 +996,44 @@ macro_rules! reg {
984996
};
985997
}
986998

999+
macro_rules! u32_list {
1000+
($name:ident) => {
1001+
pub fn $name(mut self, ids: &[u32]) -> Self {
1002+
self.$name = ids.to_vec();
1003+
self
1004+
}
1005+
};
1006+
}
1007+
1008+
macro_rules! reg_list_simple {
1009+
($name:ident) => {
1010+
pub fn $name(mut self, regs: &[&str]) -> Self {
1011+
{
1012+
// FIXME NLL
1013+
let arch = self.arch_handle.borrow();
1014+
let arch_regs: Vec<RegisterId> = regs
1015+
.iter()
1016+
.filter_map(|&r| arch.register_by_name(r))
1017+
.map(|r| r.id())
1018+
.collect();
1019+
1020+
self.$name = arch_regs;
1021+
}
1022+
1023+
self
1024+
}
1025+
};
1026+
}
1027+
1028+
macro_rules! list_kind {
1029+
($name:ident) => {
1030+
pub fn $name(mut self, kind: RegisterListKind) -> Self {
1031+
self.$name = kind;
1032+
self
1033+
}
1034+
};
1035+
}
1036+
9871037
impl<A: Architecture> ConventionBuilder<A> {
9881038
pub fn new(arch: &A) -> Self {
9891039
Self {
@@ -1009,6 +1059,12 @@ impl<A: Architecture> ConventionBuilder<A> {
10091059

10101060
arch_handle: arch.handle(),
10111061
_arch: PhantomData,
1062+
1063+
register_argument_classes: Vec::new(),
1064+
register_argument_class_lists: Vec::new(),
1065+
register_argument_lists: Vec::new(),
1066+
register_argument_list_regs: Vec::new(),
1067+
register_argument_list_kind: RegisterListKind::IntegerSemantics,
10121068
}
10131069
}
10141070

@@ -1032,6 +1088,12 @@ impl<A: Architecture> ConventionBuilder<A> {
10321088

10331089
bool_arg!(are_argument_registers_used_for_var_args);
10341090

1091+
u32_list!(register_argument_classes);
1092+
u32_list!(register_argument_class_lists);
1093+
u32_list!(register_argument_lists);
1094+
reg_list_simple!(register_argument_list_regs);
1095+
list_kind!(register_argument_list_kind);
1096+
10351097
pub fn register(self, name: &str) -> Ref<CoreCallingConvention> {
10361098
let arch = self.arch_handle.clone();
10371099
register_calling_convention(arch.borrow(), name, self)
@@ -1094,6 +1156,26 @@ impl<A: Architecture> CallingConvention for ConventionBuilder<A> {
10941156
fn are_argument_registers_used_for_var_args(&self) -> bool {
10951157
self.are_argument_registers_used_for_var_args
10961158
}
1159+
1160+
fn register_argument_classes(&self) -> Vec<u32> {
1161+
self.register_argument_classes.clone()
1162+
}
1163+
1164+
fn register_argument_class_lists(&self, _class_id: u32) -> Vec<u32> {
1165+
self.register_argument_class_lists.clone()
1166+
}
1167+
1168+
fn register_argument_lists(&self) -> Vec<u32> {
1169+
self.register_argument_lists.clone()
1170+
}
1171+
1172+
fn register_argument_list_regs(&self, _reg_list_id: u32) -> Vec<RegisterId> {
1173+
self.register_argument_list_regs.clone()
1174+
}
1175+
1176+
fn register_argument_list_kind(&self, _reg_list_id: u32) -> RegisterListKind {
1177+
self.register_argument_list_kind
1178+
}
10971179
}
10981180

10991181
unsafe impl<A: Architecture> Send for ConventionBuilder<A> {}

0 commit comments

Comments
 (0)