Skip to content
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

add owi_char #385

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## unreleased

- adds a `owi_char` function to create char symbolic value
- adds a `Mem` argument to external function to allow direct manipulation of the memory.
- support other solvers through the `--solver` option (Z3, Colibri2, Bitwuzla and CVC5)
- support the extended constant expressions proposal
Expand Down
13 changes: 13 additions & 0 deletions src/concolic/concolic_wasm_ffi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ module M :
in
(I32 n, Value.pair n sym_expr) )

let symbol_char () : Value.int32 Choice.t =
Choice.with_new_symbol (Ty_bitv 32) (fun sym forced_value ->
let n =
match forced_value with
| None -> Int32.logand 0xFFl (Random.bits32 ())
| Some (Num (I32 n)) -> n
| _ -> assert false
in
let sym_expr =
Expr.make (Cvtop (Ty_bitv 32, Zero_extend 24, Expr.mk_symbol sym))
in
(I32 n, Value.pair n sym_expr) )

let symbol_i64 () : Value.int64 Choice.t =
Choice.with_new_symbol (Ty_bitv 64) (fun sym forced_value ->
let n =
Expand Down
2 changes: 2 additions & 0 deletions src/intf/wasm_ffi_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module type S0 = sig

val symbol_i8 : unit -> Value.int32 t

val symbol_char : unit -> Value.int32 t

val symbol_i32 : unit -> Value.int32 t

val symbol_i64 : unit -> Value.int64 t
Expand Down
2 changes: 2 additions & 0 deletions src/libc/include/owi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ owi_free(void *);

__attribute__((import_module("symbolic"), import_name("i8_symbol"))) char
owi_i8(void);
__attribute__((import_module("symbolic"), import_name("char_symbol"))) char
owi_char(void);
__attribute__((import_module("symbolic"), import_name("i32_symbol"))) int
owi_i32(void);
__attribute__((import_module("symbolic"), import_name("i64_symbol"))) long long
Expand Down
7 changes: 7 additions & 0 deletions src/symbolic/symbolic_wasm_ffi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module M :
Choice.with_new_symbol (Ty_bitv 8) (fun sym ->
Expr.make (Cvtop (Ty_bitv 32, Zero_extend 24, Expr.symbol sym)) )

let symbol_char () =
Choice.with_new_symbol (Ty_bitv 8) (fun sym ->
Expr.make (Cvtop (Ty_bitv 32, Zero_extend 24, Expr.symbol sym)) )

let symbol_i32 () = Choice.with_new_symbol (Ty_bitv 32) Expr.symbol

let symbol_i64 () = Choice.with_new_symbol (Ty_bitv 64) Expr.symbol
Expand Down Expand Up @@ -80,6 +84,9 @@ let symbolic_extern_module =
[ ( "i8_symbol"
, Symbolic.P.Extern_func.Extern_func (Func (UArg Res, R1 I32), symbol_i8)
)
; ( "char_symbol"
, Symbolic.P.Extern_func.Extern_func (Func (UArg Res, R1 I32), symbol_char)
)
; ( "i32_symbol"
, Symbolic.P.Extern_func.Extern_func (Func (UArg Res, R1 I32), symbol_i32)
)
Expand Down
8 changes: 8 additions & 0 deletions test/c/char.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <owi.h>

int main(void) {
char c = owi_char();
owi_assume(c == 'B');
owi_assert('b' - c == 32);
return 0;
}
2 changes: 2 additions & 0 deletions test/c/char.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ owi c ./char.c
All OK
3 changes: 2 additions & 1 deletion test/c/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
(package owi)
malloc_aligned.c
main.c
exit.c))
exit.c
char.c))
Loading