Debian Codegraph @

crt/s2n/tests/cbmc/stubs/memmove_havoc.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. A copy of the License is
6 * located at
7 *
8 * http://aws.amazon.com/apache2.0/
9 *
10 * or in the "license" file accompanying this file. This file is distributed on an
11 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 * implied. See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #undef memmove
17
18 #include <cbmc_proof/nondet.h>
19 #include <stdint.h>
20
21 /**
22 * Override the version of memmove used by CBMC. Users may not want to pay
23 * for the cost of performing the computation of memmove in proofs. In that
24 * case, this stub at least checks for the preconditions and make sure to
25 * havoc all elements pointed by *dest up to n.
26 */
27 void *memmove_impl(void *dest, const void *src, size_t n) {
28 __CPROVER_HIDE:;
29 __CPROVER_precondition(src != NULL && __CPROVER_r_ok(src, n), "memmove source region readable");
30 __CPROVER_precondition(dest != NULL && __CPROVER_w_ok(dest, n), "memmove destination region writeable");
31
32 if (n > 0) {
33 size_t idx;
34 __CPROVER_assume(idx < n);
35 ((uint8_t *)dest)[idx] = nondet_uint8_t();
36 }
37
38 return dest;
39 }
40
41 void *memmove(void *dest, const void *src, size_t n) {
42 __CPROVER_HIDE:;
43 return memmove_impl(dest, src, n);
44 }
45
46 void *__builtin___memmove_chk(void *dest, const void *src, size_t n, size_t size) {
47 __CPROVER_HIDE:;
48 (void)size;
49 return memmove_impl(dest, src, n);
50 }