-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
164 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include <signal.h> | ||
|
||
int main() { | ||
sig_atomic_t atomic = 0; | ||
__atomic_test_and_set(&atomic, __ATOMIC_RELAXED); | ||
__atomic_clear(&atomic, __ATOMIC_RELAXED); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Werror |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "utils/s2n_atomic.h" | ||
|
||
#include "utils/s2n_safety.h" | ||
|
||
const s2n_atomic set_val = 1; | ||
const s2n_atomic clear_val = 0; | ||
|
||
S2N_RESULT s2n_atomic_init() | ||
{ | ||
#if S2N_ATOMIC_ENABLED | ||
RESULT_ENSURE(__atomic_always_lock_free(sizeof(s2n_atomic), NULL), S2N_ERR_ATOMIC); | ||
#endif | ||
return S2N_RESULT_OK; | ||
} | ||
|
||
void s2n_atomic_set(s2n_atomic *var) | ||
{ | ||
#if S2N_ATOMIC_ENABLED | ||
__atomic_store(var, &set_val, __ATOMIC_RELAXED); | ||
#else | ||
*var = 1; | ||
#endif | ||
} | ||
|
||
void s2n_atomic_clear(s2n_atomic *var) | ||
{ | ||
#if S2N_ATOMIC_ENABLED | ||
__atomic_store(var, &clear_val, __ATOMIC_RELAXED); | ||
#else | ||
*var = 0; | ||
#endif | ||
} | ||
|
||
bool s2n_atomic_check(s2n_atomic *var) | ||
{ | ||
#if S2N_ATOMIC_ENABLED | ||
s2n_atomic result = 0; | ||
__atomic_load(var, &result, __ATOMIC_RELAXED); | ||
return result; | ||
#else | ||
return *var; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 | ||
|
||
#include <signal.h> | ||
|
||
#include "utils/s2n_result.h" | ||
|
||
/* s2n-tls allows s2n_send and s2n_recv to be called concurrently. | ||
* There are a handful of values that both methods need to access. | ||
* However, C99 has no concept of concurrency, so provides no atomic data types. | ||
* | ||
* Traditionally, s2n-tls uses sig_atomic_t for its weak guarantee of atomicity for interrupts. | ||
*/ | ||
typedef sig_atomic_t s2n_atomic; | ||
|
||
/* These methods use compiler atomic built-ins if available and lock-free, but otherwise | ||
* rely on setting / clearing a small value generally being atomic in practice. | ||
*/ | ||
S2N_RESULT s2n_atomic_init(); | ||
void s2n_atomic_set(s2n_atomic *var); | ||
void s2n_atomic_clear(s2n_atomic *var); | ||
bool s2n_atomic_check(s2n_atomic *var); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters