From 16d45969bdfaa205a9f85b150d5cfae4aa2e8c6f Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Mon, 6 Mar 2023 11:19:36 +0100 Subject: [PATCH 1/2] Use assertChipStackLockedByCurrentThread when accessing statics in src/system/SystemStats.cpp --- src/lib/core/tests/BUILD.gn | 1 + src/setup_payload/tests/BUILD.gn | 1 + src/system/SystemStats.cpp | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/src/lib/core/tests/BUILD.gn b/src/lib/core/tests/BUILD.gn index 295f7a337d09dd..ec83bc715411c1 100644 --- a/src/lib/core/tests/BUILD.gn +++ b/src/lib/core/tests/BUILD.gn @@ -37,6 +37,7 @@ chip_test_suite("tests") { public_deps = [ "${chip_root}/src/lib/core", "${chip_root}/src/lib/support:testing", + "${chip_root}/src/platform", "${nlunit_test_root}:nlunit-test", ] } diff --git a/src/setup_payload/tests/BUILD.gn b/src/setup_payload/tests/BUILD.gn index 2d76bb4cfa5680..1b39f08f0eca25 100644 --- a/src/setup_payload/tests/BUILD.gn +++ b/src/setup_payload/tests/BUILD.gn @@ -34,6 +34,7 @@ chip_test_suite("tests") { public_deps = [ "${chip_root}/src/lib/support:testing", + "${chip_root}/src/platform", "${chip_root}/src/setup_payload", "${nlunit_test_root}:nlunit-test", ] diff --git a/src/system/SystemStats.cpp b/src/system/SystemStats.cpp index bf3473fd62c924..244a2517b31c78 100644 --- a/src/system/SystemStats.cpp +++ b/src/system/SystemStats.cpp @@ -29,6 +29,7 @@ #include #include +#include #include @@ -59,21 +60,29 @@ count_t sHighWatermarks[kNumEntries]; const Label * GetStrings() { + assertChipStackLockedByCurrentThread(); + return sStatsStrings; } count_t * GetResourcesInUse() { + assertChipStackLockedByCurrentThread(); + return sResourcesInUse; } count_t * GetHighWatermarks() { + assertChipStackLockedByCurrentThread(); + return sHighWatermarks; } void UpdateSnapshot(Snapshot & aSnapshot) { + assertChipStackLockedByCurrentThread(); + memcpy(&aSnapshot.mResourcesInUse, &sResourcesInUse, sizeof(aSnapshot.mResourcesInUse)); memcpy(&aSnapshot.mHighWatermarks, &sHighWatermarks, sizeof(aSnapshot.mHighWatermarks)); From 91a04fb41447e2d74a21b9c983d5e74574de3b89 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Mon, 6 Mar 2023 11:24:49 +0100 Subject: [PATCH 2/2] Update src/platform/Darwin/BleConnectionDelegateImpl.mm such that it does not creates a PacketBufferHandle from the ble work queue but from the chip work queue --- .../Darwin/BleConnectionDelegateImpl.mm | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/platform/Darwin/BleConnectionDelegateImpl.mm b/src/platform/Darwin/BleConnectionDelegateImpl.mm index 004a33bfb0e963..152aa7be829b49 100644 --- a/src/platform/Darwin/BleConnectionDelegateImpl.mm +++ b/src/platform/Darwin/BleConnectionDelegateImpl.mm @@ -380,24 +380,19 @@ - (void)peripheral:(CBPeripheral *)peripheral chip::Ble::ChipBleUUID charId; [BleConnection fillServiceWithCharacteristicUuids:characteristic svcId:&svcId charId:&charId]; - // build a inet buffer from the rxEv and send to blelayer. - __block chip::System::PacketBufferHandle msgBuf - = chip::System::PacketBufferHandle::NewWithData(characteristic.value.bytes, characteristic.value.length); - - if (!msgBuf.IsNull()) { - dispatch_async(_chipWorkQueue, ^{ - if (!_mBleLayer->HandleIndicationReceived((__bridge void *) peripheral, &svcId, &charId, std::move(msgBuf))) { - // since this error comes from device manager core - // we assume it would do the right thing, like closing the connection - ChipLogError(Ble, "Failed at handling incoming BLE data"); - } - }); - } else { - ChipLogError(Ble, "Failed at allocating buffer for incoming BLE data"); - dispatch_async(_chipWorkQueue, ^{ + dispatch_async(_chipWorkQueue, ^{ + // build a inet buffer from the rxEv and send to blelayer. + auto msgBuf = chip::System::PacketBufferHandle::NewWithData(characteristic.value.bytes, characteristic.value.length); + + if (msgBuf.IsNull()) { + ChipLogError(Ble, "Failed at allocating buffer for incoming BLE data"); _mBleLayer->HandleConnectionError((__bridge void *) peripheral, CHIP_ERROR_NO_MEMORY); - }); - } + } else if (!_mBleLayer->HandleIndicationReceived((__bridge void *) peripheral, &svcId, &charId, std::move(msgBuf))) { + // since this error comes from device manager core + // we assume it would do the right thing, like closing the connection + ChipLogError(Ble, "Failed at handling incoming BLE data"); + } + }); } else { ChipLogError( Ble, "BLE:Error receiving indication of Characteristics on the device: [%s]", [error.localizedDescription UTF8String]);