Skip to content

Commit 9619503

Browse files
authored
exports abi processors (#1093)
* exports abi processors This adds 2 new functions to C.Abi, to be able to register a new abi processor and then access it later. * uses Hashtbl for abi registry
1 parent cfeacbf commit 9619503

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

lib/bap_c/bap_c_abi.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ let stage2 stage1 = object
182182
else prog
183183
end
184184

185+
let registry = Hashtbl.create (module String)
186+
let register name abi = Hashtbl.set registry ~key:name ~data:abi
187+
let get_processor name = Hashtbl.find registry name
188+
185189
let create_api_processor size abi : Bap_api.t =
186190
let addr_size = size#pointer in
187191
let stage1 gamma = object(self)

lib/bap_c/bap_c_abi.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ val data : #Bap_c_size.base -> Bap_c_type.t -> Bap_c_data.t
8282
*)
8383
val arg_intent : Bap_c_type.t -> intent
8484

85+
(** [register name t] registers an abi processor [t] named [name] that
86+
may be used by subroutines in this project.*)
87+
val register : string -> t -> unit
88+
89+
(** [get_processor name] is used to access an abi processor with its
90+
name.*)
91+
val get_processor : string -> t option
92+
8593

8694
(** An abstraction of a stack, commonly used in C compilers. *)
8795
module Stack : sig

plugins/arm/arm_gnueabi.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ let api arch = C.Abi.create_api_processor arch abi
6161
let main proj = match Project.arch proj with
6262
| #Arch.arm ->
6363
info "using armeabi ABI";
64+
C.Abi.register "eabi" abi;
6465
Bap_api.process (api size);
6566
Project.set proj Bap_abi.name "eabi"
6667
| _ -> proj

plugins/mips/mips_abi.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ let set_abi proj m =
105105
insert_args = dispatch m (Project.arch proj);
106106
apply_attrs = fun _ -> ident
107107
} in
108+
C.Abi.register A.name abi;
108109
let api = C.Abi.create_api_processor A.size abi in
109110
Bap_api.process api;
110111
let prog = Project.program proj in

plugins/powerpc/powerpc_abi.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ let main proj = match Project.arch proj with
8080
insert_args = dispatch (module Abi32);
8181
apply_attrs = fun _ -> ident
8282
} in
83+
C.Abi.register Abi32.name abi;
8384
let api = C.Abi.create_api_processor Abi32.size abi in
8485
Bap_api.process api;
8586
let prog = Project.program proj in

plugins/x86/x86_abi.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ let setup ?(abi=fun _ -> None) () =
251251
insert_args = dispatch abi;
252252
apply_attrs = fun _ -> ident
253253
} in
254+
C.Abi.register Abi.name abi;
254255
let api = C.Abi.create_api_processor Abi.size abi in
255256
Bap_api.process api;
256257
let prog = demangle Abi.demangle (Project.program proj) in

0 commit comments

Comments
 (0)