forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nrf5] Repair the newlib locking (project-chip#2100)
* [nrf5] Repair the newlib locking Calling stdio functions in certain circumstances currently crashes the device. Enabling configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES makes this more likely to happen. The problem is that the types used in FreeRTOSNewlibLockSupport.c don't match those used by newlib; we're mixing up struct __lock * with its content. Fix the implementation and remove all the typecasts. Note that we need a 2nd allocation for the dynamic case as FreeRTOS and newlib APIs don't match up well. Possibly we should remove this code, but for now just repair it. fixes project-chip#2084 * Add include paths to automake
- Loading branch information
Showing
11 changed files
with
215 additions
and
55 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
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,37 @@ | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License 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. | ||
|
||
import("//build_overrides/chip.gni") | ||
import("//build_overrides/nrf5_sdk.gni") | ||
|
||
config("support_config") { | ||
include_dirs = [ "../../.." ] | ||
} | ||
|
||
source_set("freertos_newlib_lock_support") { | ||
sources = [ "FreeRTOSNewlibLockSupport.c" ] | ||
|
||
public_deps = [ "${nrf5_sdk_build_root}:nrf5_sdk" ] | ||
|
||
public_configs = [ ":support_config" ] | ||
} | ||
|
||
source_set("freertos_newlib_lock_support_test") { | ||
sources = [ | ||
"FreeRTOSNewlibLockSupport_test.c", | ||
"FreeRTOSNewlibLockSupport_test.h", | ||
] | ||
|
||
public_deps = [ ":freertos_newlib_lock_support" ] | ||
} |
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
84 changes: 84 additions & 0 deletions
84
examples/platform/nrf528xx/app/support/FreeRTOSNewlibLockSupport_test.c
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,84 @@ | ||
/** | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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 "FreeRTOSNewlibLockSupport_test.h" | ||
|
||
#include <FreeRTOS.h> | ||
#include <assert.h> | ||
#include <semphr.h> | ||
#include <stdbool.h> | ||
#include <sys/lock.h> | ||
|
||
#ifndef __SINGLE_THREAD__ | ||
__LOCK_INIT(static, test_lock); | ||
__LOCK_INIT_RECURSIVE(static, test_lock_recursive); | ||
|
||
struct __lock | ||
{ | ||
SemaphoreHandle_t semaphore; | ||
}; | ||
|
||
struct __lock __lock_test_lock; | ||
struct __lock __lock_test_lock_recursive; | ||
|
||
__attribute__((constructor)) static void init_static_lock_test_mutexes(void) | ||
{ | ||
__lock_test_lock.semaphore = xSemaphoreCreateMutex(); | ||
__lock_test_lock_recursive.semaphore = xSemaphoreCreateRecursiveMutex(); | ||
} | ||
|
||
void freertos_newlib_lock_test() | ||
{ | ||
__lock_acquire(test_lock); | ||
bool acquired = __lock_try_acquire(test_lock); | ||
ASSERT(!acquired); | ||
__lock_release(test_lock); | ||
acquired = __lock_try_acquire(test_lock); | ||
ASSERT(acquired); | ||
__lock_release(test_lock); | ||
|
||
__lock_acquire_recursive(test_lock_recursive); | ||
__lock_acquire_recursive(test_lock_recursive); | ||
acquired = __lock_try_acquire_recursive(test_lock_recursive); | ||
ASSERT(acquired); | ||
__lock_release_recursive(test_lock_recursive); | ||
__lock_release_recursive(test_lock_recursive); | ||
__lock_release_recursive(test_lock_recursive); | ||
|
||
_LOCK_T dynamic_lock; | ||
__lock_init(dynamic_lock); | ||
__lock_acquire(dynamic_lock); | ||
acquired = __lock_try_acquire(dynamic_lock); | ||
ASSERT(!acquired); | ||
__lock_release(dynamic_lock); | ||
acquired = __lock_try_acquire(dynamic_lock); | ||
ASSERT(acquired); | ||
__lock_release(dynamic_lock); | ||
|
||
_LOCK_T dynamic_lock_recursive; | ||
__lock_init_recursive(dynamic_lock_recursive); | ||
__lock_acquire_recursive(dynamic_lock_recursive); | ||
acquired = __lock_try_acquire_recursive(dynamic_lock_recursive); | ||
ASSERT(acquired); | ||
__lock_release_recursive(dynamic_lock); | ||
acquired = __lock_try_acquire_recursive(dynamic_lock_recursive); | ||
ASSERT(acquired); | ||
__lock_release_recursive(dynamic_lock_recursive); | ||
} | ||
#else | ||
void freertos_newlib_lock_test() {} | ||
#endif |
Oops, something went wrong.