Skip to content

Commit fafe18a

Browse files
committed
New option --mmio-regions to specify memory regions
This new option will enable us to eventually drop support for __CPROVER_allocated_memory, which 1) requires awkward scanning of goto functions in goto_check_c, 2) wrongly suggests these declarations are limited to some scope, and 3) yields a spurious undefined-function warning in symex.
1 parent 365871d commit fafe18a

File tree

7 files changed

+60
-2
lines changed

7 files changed

+60
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE broken-smt-backend
2+
main.c
3+
--pointer-check -DCMDLINE --mmio-regions 0x10:4
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[main\.pointer_dereference\.2\] .* dereference failure: invalid integer address in \*p: SUCCESS$
7+
^\[main\.assertion\.1\] .* assertion \*p==42: SUCCESS$
8+
^\[main\.pointer_dereference\.[0-9]+\] .* dereference failure: invalid integer address in p\[.*1\]: FAILURE$
9+
^\[main\.assertion\.2\] .* assertion \*\(p\+1\)==42: SUCCESS$
10+
^VERIFICATION FAILED$
11+
--
12+
^warning: ignoring

regression/cbmc/memory_allocation1/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ int main()
44
{
55
int *p=0x10;
66

7+
#ifndef CMDLINE
78
__CPROVER_allocated_memory(0x10, sizeof(int));
9+
#endif
810
*p=42;
911
assert(*p==42);
1012
*(p+1)=42;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--bounds-check -DCMDLINE --mmio-regions 0x1000:400,0x11000:400 --mmio-regions 0x21000:400,0x31000:400
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[main\.array_bounds\.[1-5]\] .*: SUCCESS$
7+
^\[main\.array_bounds\.[67]\] line 40 array.buffer (dynamic object )?upper bound in buffers\[\(signed long (long )?int\)0\]->buffer\[\(signed long (long )?int\)100\]: FAILURE$
8+
^\*\* 1 of 12 failed
9+
^VERIFICATION FAILED$
10+
--
11+
^warning: ignoring

regression/cbmc/memory_allocation2/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ static buffert(*const buffers[4]) = {BUF0, BUF1, BUF2, BUF3};
2424

2525
main()
2626
{
27+
#ifndef CMDLINE
2728
__CPROVER_allocated_memory(BUF0_BASE, sizeof(buffert));
2829
__CPROVER_allocated_memory(BUF1_BASE, sizeof(buffert));
2930
__CPROVER_allocated_memory(BUF2_BASE, sizeof(buffert));
3031
__CPROVER_allocated_memory(BUF3_BASE, sizeof(buffert));
32+
#endif
3133

3234
_cbmc_printf2(sizeof_buffers, sizeof(buffers));
3335
_cbmc_printf2(sizeof_buffers_0, sizeof(buffers[0]));
@@ -36,4 +38,7 @@ main()
3638
buffers[0]->buffer[0];
3739
buffers[0]->buffer[BUFFER_SIZE - 1];
3840
buffers[0]->buffer[BUFFER_SIZE]; // should be out-of-bounds
41+
buffers[1]->buffer[0];
42+
buffers[2]->buffer[0];
43+
buffers[3]->buffer[0];
3944
}

regression/cbmc/memory_allocation2/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ main.c
44
^EXIT=10$
55
^SIGNAL=0$
66
^\[main\.array_bounds\.[1-5]\] .*: SUCCESS$
7-
^\[main\.array_bounds\.[67]\] line 38 array.buffer (dynamic object )?upper bound in buffers\[\(signed long (long )?int\)0\]->buffer\[\(signed long (long )?int\)100\]: FAILURE$
8-
^\*\* 1 of 6 failed
7+
^\[main\.array_bounds\.[67]\] line 40 array.buffer (dynamic object )?upper bound in buffers\[\(signed long (long )?int\)0\]->buffer\[\(signed long (long )?int\)100\]: FAILURE$
8+
^\*\* 1 of 12 failed
99
^VERIFICATION FAILED$
1010
--
1111
^warning: ignoring

src/ansi-c/goto_check_c.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Author: Daniel Kroening, kroening@kroening.com
4444
#include <algorithm>
4545
#include <optional>
4646

47+
#include "literals/convert_integer_literal.h"
48+
4749
class goto_check_ct
4850
{
4951
public:
@@ -76,6 +78,8 @@ class goto_check_ct
7678
error_labels = _options.get_list_option("error-label");
7779
enable_pointer_primitive_check =
7880
_options.get_bool_option("pointer-primitive-check");
81+
82+
parse_mmio_regions(_options.get_list_option("mmio-regions"));
7983
}
8084

8185
typedef goto_functionst::goto_functiont goto_functiont;
@@ -327,6 +331,8 @@ class goto_check_ct
327331
/// \returns a pair (name, status) if the match succeeds
328332
/// and the name is known, nothing otherwise.
329333
named_check_statust match_named_check(const irep_idt &named_check) const;
334+
335+
void parse_mmio_regions(const optionst::value_listt &regions);
330336
};
331337

332338
/// Allows to:
@@ -463,6 +469,22 @@ void goto_check_ct::collect_allocations(const goto_functionst &goto_functions)
463469
}
464470
}
465471

472+
void goto_check_ct::parse_mmio_regions(const optionst::value_listt &regions)
473+
{
474+
for(const std::string &range : regions)
475+
{
476+
const auto sep = range.find(':');
477+
if(sep == std::string::npos || sep + 1 == range.size())
478+
continue;
479+
480+
const std::string start = range.substr(0, sep);
481+
const std::string size = range.substr(sep + 1);
482+
483+
allocations.push_back(
484+
{convert_integer_literal(start), convert_integer_literal(size)});
485+
}
486+
}
487+
466488
void goto_check_ct::invalidate(const exprt &lhs)
467489
{
468490
if(lhs.id() == ID_index)

src/ansi-c/goto_check_c.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void goto_check_c(
4444
"(pointer-overflow-check)(conversion-check)(undefined-shift-check)" \
4545
"(float-overflow-check)(nan-check)(no-built-in-assertions)" \
4646
"(pointer-primitive-check)" \
47+
"(mmio-regions):" \
4748
"(retain-trivial-checks)" \
4849
"(error-label):" \
4950
"(no-assertions)(no-assumptions)" \
@@ -64,6 +65,8 @@ void goto_check_c(
6465
" --nan-check check floating-point for NaN\n" \
6566
" --enum-range-check checks that all enum type expressions have values in the enum range\n" /* NOLINT(whitespace/line_length) */ \
6667
" --pointer-primitive-check checks that all pointers in pointer primitives are valid or null\n" /* NOLINT(whitespace/line_length) */ \
68+
" --mmio-regions addr:sz,... list of start-address:size address ranges\n" \
69+
" permitted for read/write access\n" \
6770
" --retain-trivial-checks include checks that are trivially true\n" \
6871
" --error-label label check that label is unreachable\n" \
6972
" --no-built-in-assertions ignore assertions in built-in library\n" \
@@ -86,6 +89,9 @@ void goto_check_c(
8689
options.set_option("nan-check", cmdline.isset("nan-check")); \
8790
options.set_option("built-in-assertions", !cmdline.isset("no-built-in-assertions")); /* NOLINT(whitespace/line_length) */ \
8891
options.set_option("pointer-primitive-check", cmdline.isset("pointer-primitive-check")); /* NOLINT(whitespace/line_length) */ \
92+
if(cmdline.isset("mmio-regions")) \
93+
options.set_option( \
94+
"mmio-regions", cmdline.get_comma_separated_values("mmio-regions")); \
8995
options.set_option("retain-trivial-checks", \
9096
cmdline.isset("retain-trivial-checks")); \
9197
options.set_option("assertions", !cmdline.isset("no-assertions")); /* NOLINT(whitespace/line_length) */ \

0 commit comments

Comments
 (0)