Debian Codegraph @

crt/s2n/tests/cbmc/stubs/memcpy_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 memcpy
17
18 #include <cbmc_proof/nondet.h>
19 #include <stdint.h>
20
21 /**
22 * Overrides the version of memcpy used by CBMC. Users may not want to pay
23 * for the cost of performing the computation of memcpy in proofs.
24 * In that case, this stub at least checks for the preconditions and
25 * assigns arbitrary values to *dst.
26 */
27 void *memcpy_impl(void *dst, const void *src, size_t n) {
28 __CPROVER_precondition(
29 __CPROVER_POINTER_OBJECT(dst) != __CPROVER_POINTER_OBJECT(src) ||
30 ((const char *)src >= (const char *)dst + n) || ((const char *)dst >= (const char *)src + n),
31 "memcpy src/dst overlap");
32 __CPROVER_precondition(src != NULL && __CPROVER_r_ok(src, n), "memcpy source region readable");
33 __CPROVER_precondition(dst != NULL && __CPROVER_w_ok(dst, n), "memcpy destination region writeable");
34
35 __CPROVER_havoc_object(dst);
36 return dst;
37 }
38
39 void *memcpy(void *dst, const void *src, size_t n) {
40 return memcpy_impl(dst, src, n);
41 }
42
43 void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __CPROVER_size_t size) {
44 (void)size;
45 return memcpy_impl(dst, src, n);
46 }