diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/restricted/aws/s2n/utils/s2n_ensure.h | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/restricted/aws/s2n/utils/s2n_ensure.h')
-rw-r--r-- | contrib/restricted/aws/s2n/utils/s2n_ensure.h | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/contrib/restricted/aws/s2n/utils/s2n_ensure.h b/contrib/restricted/aws/s2n/utils/s2n_ensure.h index 8949521e9a..a3e2286192 100644 --- a/contrib/restricted/aws/s2n/utils/s2n_ensure.h +++ b/contrib/restricted/aws/s2n/utils/s2n_ensure.h @@ -1,70 +1,70 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -#pragma once - -#define s2n_likely(x) __builtin_expect(!!(x), 1) -#define s2n_unlikely(x) __builtin_expect(!!(x), 0) - -/** - * s2n_ensure provides low-level safety check functionality - * - * This should only consumed directly by s2n_safety. - * - * Note: This module can be replaced by static analyzer implementation - * to insert additional safety checks. - */ - -/** - * Ensures `cond` is true, otherwise `action` will be performed - */ -#define __S2N_ENSURE( cond, action ) do {if ( !(cond) ) { action; }} while (0) - -#define __S2N_ENSURE_LIKELY( cond, action ) do {if ( s2n_unlikely( !(cond) ) ) { action; }} while (0) - -#ifdef NDEBUG -#define __S2N_ENSURE_DEBUG( cond, action ) do {} while (0) -#else -#define __S2N_ENSURE_DEBUG( cond, action ) __S2N_ENSURE_LIKELY((cond), action) -#endif - -#define __S2N_ENSURE_PRECONDITION( result ) (s2n_likely(s2n_result_is_ok(result)) ? S2N_RESULT_OK : S2N_RESULT_ERROR) - -#ifdef NDEBUG -#define __S2N_ENSURE_POSTCONDITION( result ) (S2N_RESULT_OK) -#else -#define __S2N_ENSURE_POSTCONDITION( result ) (s2n_likely(s2n_result_is_ok(result)) ? S2N_RESULT_OK : S2N_RESULT_ERROR) -#endif - -#define __S2N_ENSURE_SAFE_MEMCPY( d , s , n , guard ) \ - do { \ - __typeof( n ) __tmp_n = ( n ); \ - if ( s2n_likely( __tmp_n ) ) { \ - void *r = s2n_ensure_memcpy_trace( (d), (s) , (__tmp_n), _S2N_DEBUG_LINE); \ - guard(r); \ - } \ - } while(0) - -#define __S2N_ENSURE_SAFE_MEMSET( d , c , n , guard ) \ - do { \ - __typeof( n ) __tmp_n = ( n ); \ - if ( s2n_likely( __tmp_n ) ) { \ - __typeof( d ) __tmp_d = ( d ); \ - guard( __tmp_d ); \ - memset( __tmp_d, (c), __tmp_n); \ - } \ - } while(0) - -extern void* s2n_ensure_memcpy_trace(void *restrict to, const void *restrict from, size_t size, const char *debug_str); +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#pragma once + +#define s2n_likely(x) __builtin_expect(!!(x), 1) +#define s2n_unlikely(x) __builtin_expect(!!(x), 0) + +/** + * s2n_ensure provides low-level safety check functionality + * + * This should only consumed directly by s2n_safety. + * + * Note: This module can be replaced by static analyzer implementation + * to insert additional safety checks. + */ + +/** + * Ensures `cond` is true, otherwise `action` will be performed + */ +#define __S2N_ENSURE( cond, action ) do {if ( !(cond) ) { action; }} while (0) + +#define __S2N_ENSURE_LIKELY( cond, action ) do {if ( s2n_unlikely( !(cond) ) ) { action; }} while (0) + +#ifdef NDEBUG +#define __S2N_ENSURE_DEBUG( cond, action ) do {} while (0) +#else +#define __S2N_ENSURE_DEBUG( cond, action ) __S2N_ENSURE_LIKELY((cond), action) +#endif + +#define __S2N_ENSURE_PRECONDITION( result ) (s2n_likely(s2n_result_is_ok(result)) ? S2N_RESULT_OK : S2N_RESULT_ERROR) + +#ifdef NDEBUG +#define __S2N_ENSURE_POSTCONDITION( result ) (S2N_RESULT_OK) +#else +#define __S2N_ENSURE_POSTCONDITION( result ) (s2n_likely(s2n_result_is_ok(result)) ? S2N_RESULT_OK : S2N_RESULT_ERROR) +#endif + +#define __S2N_ENSURE_SAFE_MEMCPY( d , s , n , guard ) \ + do { \ + __typeof( n ) __tmp_n = ( n ); \ + if ( s2n_likely( __tmp_n ) ) { \ + void *r = s2n_ensure_memcpy_trace( (d), (s) , (__tmp_n), _S2N_DEBUG_LINE); \ + guard(r); \ + } \ + } while(0) + +#define __S2N_ENSURE_SAFE_MEMSET( d , c , n , guard ) \ + do { \ + __typeof( n ) __tmp_n = ( n ); \ + if ( s2n_likely( __tmp_n ) ) { \ + __typeof( d ) __tmp_d = ( d ); \ + guard( __tmp_d ); \ + memset( __tmp_d, (c), __tmp_n); \ + } \ + } while(0) + +extern void* s2n_ensure_memcpy_trace(void *restrict to, const void *restrict from, size_t size, const char *debug_str); |