Debian Codegraph @

crt/aws-c-common/verification/cbmc/stubs/memcpy_override_no_op.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 /**
7 * FUNCTION: memcpy
8 *
9 * This function overrides the original implementation of the memcpy function
10 * from string.h. It copies the values of n bytes from the *src to the *dst.
11 * It also checks if the size of the arrays pointed to by both the *dst and
12 * *src parameters are at least n bytes and if they overlap.
13 */
14
15 #undef memcpy
16
17 #include <proof_helpers/nondet.h>
18 #include <stdint.h>
19
20 /**
21 * Override the version of memcpy used by CBMC.
22 */
23 void *memcpy_impl(void *dst, const void *src, size_t n) {
24 __CPROVER_precondition(
25 __CPROVER_POINTER_OBJECT(dst) != __CPROVER_POINTER_OBJECT(src) ||
26 ((const char *)src >= (const char *)dst + n) || ((const char *)dst >= (const char *)src + n),
27 "memcpy src/dst overlap");
28 __CPROVER_precondition(src != NULL && __CPROVER_r_ok(src, n), "memcpy source region readable");
29 __CPROVER_precondition(dst != NULL && __CPROVER_w_ok(dst, n), "memcpy destination region writeable");
30
31 return dst;
32 }
33
34 void *memcpy(void *dst, const void *src, size_t n) {
35 return memcpy_impl(dst, src, n);
36 }
37
38 void *__builtin___memcpy_chk(void *dst, const void *src, __CPROVER_size_t n, __CPROVER_size_t size) {
39 (void)size;
40 return memcpy_impl(dst, src, n);
41 }