Debian Codegraph @

crt/s2n/tests/sidetrail/working/stubs/s2n_ensure.h

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").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #pragma once
17
18 #include "utils/s2n_annotations.h"
19 #include "sidetrail.h"
20
21 void __VERIFIER_assume(int);
22
23 #define MEMCOPY_COST 2
24 void *memcpy(void *str1, const void *str2, size_t n);
25
26 void *s2n_sidetrail_memset(void * ptr, int value, size_t num);
27
28 #define __S2N_ENSURE( cond, action ) __VERIFIER_assume((cond))
29 #define __S2N_ENSURE_DEBUG( cond, action ) __VERIFIER_assume((cond))
30
31 #define __S2N_ENSURE_PRECONDITION( result ) S2N_RESULT_OK
32 #define __S2N_ENSURE_POSTCONDITION( result ) S2N_RESULT_OK
33
34 /* memmove isn't supported, so use memcpy instead.
35 * For the purposes of these proofs, there should be no useful difference.
36 */
37 #define __S2N_ENSURE_SAFE_MEMMOVE( d , s , n , guard ) do { memcpy((d), (s), (n)); } while(0)
38
39 #define __S2N_ENSURE_SAFE_MEMSET( d , c , n , guard ) \
40 do { \
41 __typeof( n ) __tmp_n = ( n ); \
42 if ( __tmp_n ) { \
43 __typeof( d ) __tmp_d = ( d ); \
44 guard( __tmp_d ); \
45 s2n_sidetrail_memset( __tmp_d, (c), __tmp_n); \
46 } \
47 } while(0)
48
49 #define __S2N_ENSURE_CHECKED_RETURN(v) do { return v; } while(0)
50
51 /**
52 * The C runtime does not give a way to check these properties,
53 * but we can at least check for nullness.
54 */
55 #define S2N_MEM_IS_READABLE_CHECK(base, len) (((len) == 0) || (base) != NULL)
56 #define S2N_MEM_IS_WRITABLE_CHECK(base, len) (((len) == 0) || (base) != NULL)
57
58 /**
59 * These macros can safely be used in validate functions.
60 */
61 #define S2N_MEM_IS_READABLE(base, len) (((len) == 0) || (base) != NULL)
62 #define S2N_MEM_IS_WRITABLE(base, len) (((len) == 0) || (base) != NULL)
63 #define S2N_OBJECT_PTR_IS_READABLE(ptr) ((ptr) != NULL)
64 #define S2N_OBJECT_PTR_IS_WRITABLE(ptr) ((ptr) != NULL)
65
66 #define S2N_IMPLIES(a, b) (!(a) || (b))
67 #define S2N_IFF(a, b) (!!(a) == !!(b))
68
69 /**
70 * These macros are used to specify code contracts in CBMC proofs.
71 */
72 #define CONTRACT_ASSIGNS(...)
73 #define CONTRACT_ASSIGNS_ERR(...)
74 #define CONTRACT_REQUIRES(...)
75 #define CONTRACT_ENSURES(...)
76 #define CONTRACT_INVARIANT(...)
77 #define CONTRACT_RETURN_VALUE