Debian Codegraph @

crt/aws-c-common/verification/cbmc/stubs/memcpy_override_havoc.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #undef memcpy
7
8 #include <proof_helpers/nondet.h>
9 #include <stdint.h>
10
11 /**
12 * Override the version of memcpy used by CBMC. Users may not want to pay
13 * for the cost of performing the computation of memcpy in proofs. In that
14 * case, this stub at least checks for the preconditions and make sure to
15 * havoc all elements pointed by *dst up to n.
16 */
17 void *memcpy_impl(void *dst, const void *src, size_t n) {
18 __CPROVER_precondition(
19 __CPROVER_POINTER_OBJECT(dst) != __CPROVER_POINTER_OBJECT(src) ||
20 ((const char *)src >= (const char *)dst + n) || ((const char *)dst >= (const char *)src + n),
21 "memcpy src/dst overlap");
22 __CPROVER_precondition(src != NULL && __CPROVER_r_ok(src, n), "memcpy source region readable");
23 __CPROVER_precondition(dst != NULL && __CPROVER_w_ok(dst, n), "memcpy destination region writeable");
24
25 if (n > 0) {
26 size_t index;
27 __CPROVER_assume(index < n);
28 ((uint8_t *)dst)[index] = nondet_uint8_t();
29 }
30 return dst;
31 }
32
33 void *memcpy(void *dst, const void *src, size_t n) {
34 return memcpy_impl(dst, src, n);
35 }
36
37 void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __CPROVER_size_t size) {
38 (void)size;
39 return memcpy_impl(dst, src, n);
40 }