Loading system/btif/Android.bp +7 −0 Original line number Original line Diff line number Diff line Loading @@ -139,6 +139,13 @@ cc_test { "libprocessgroup", "libprocessgroup", "libutils", "libutils", "libcrypto", "libcrypto", "android.hardware.keymaster@4.0", "android.hardware.keymaster@3.0", "libkeymaster4support", "libkeystore_aidl", "libkeystore_binder", "libkeystore_parcelables", "libbinder", ], ], static_libs: [ static_libs: [ "libbt-bta", "libbt-bta", Loading system/main/Android.bp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -54,6 +54,12 @@ cc_library_shared { "libtinyxml2", "libtinyxml2", "libz", "libz", "libcrypto", "libcrypto", "android.hardware.keymaster@4.0", "android.hardware.keymaster@3.0", "libkeymaster4support", "libkeystore_aidl", "libkeystore_binder", "libkeystore_parcelables", ], ], static_libs: [ static_libs: [ "libbt-sbc-decoder", "libbt-sbc-decoder", Loading system/osi/src/alarm.cc +11 −5 Original line number Original line Diff line number Diff line Loading @@ -91,7 +91,7 @@ struct alarm_t { // potentially long-running callback is executing. |alarm_cancel| uses this // potentially long-running callback is executing. |alarm_cancel| uses this // mutex to provide a guarantee to its caller that the callback will not be // mutex to provide a guarantee to its caller that the callback will not be // in progress when it returns. // in progress when it returns. std::recursive_mutex* callback_mutex; std::shared_ptr<std::recursive_mutex> callback_mutex; uint64_t creation_time_ms; uint64_t creation_time_ms; uint64_t period_ms; uint64_t period_ms; uint64_t deadline_ms; uint64_t deadline_ms; Loading Loading @@ -174,7 +174,8 @@ static alarm_t* alarm_new_internal(const char* name, bool is_periodic) { alarm_t* ret = static_cast<alarm_t*>(osi_calloc(sizeof(alarm_t))); alarm_t* ret = static_cast<alarm_t*>(osi_calloc(sizeof(alarm_t))); ret->callback_mutex = new std::recursive_mutex; std::shared_ptr<std::recursive_mutex> ptr(new std::recursive_mutex()); ret->callback_mutex = ptr; ret->is_periodic = is_periodic; ret->is_periodic = is_periodic; ret->stats.name = osi_strdup(name); ret->stats.name = osi_strdup(name); Loading @@ -191,7 +192,7 @@ void alarm_free(alarm_t* alarm) { if (!alarm) return; if (!alarm) return; alarm_cancel(alarm); alarm_cancel(alarm); delete alarm->callback_mutex; osi_free((void*)alarm->stats.name); osi_free((void*)alarm->stats.name); alarm->closure.~CancelableClosureInStruct(); alarm->closure.~CancelableClosureInStruct(); osi_free(alarm); osi_free(alarm); Loading Loading @@ -245,13 +246,15 @@ void alarm_cancel(alarm_t* alarm) { CHECK(alarms != NULL); CHECK(alarms != NULL); if (!alarm) return; if (!alarm) return; std::shared_ptr<std::recursive_mutex> local_mutex_ref = alarm->callback_mutex; { { std::lock_guard<std::mutex> lock(alarms_mutex); std::lock_guard<std::mutex> lock(alarms_mutex); local_mutex_ref = alarm->callback_mutex; alarm_cancel_internal(alarm); alarm_cancel_internal(alarm); } } // If the callback for |alarm| is in progress, wait here until it completes. // If the callback for |alarm| is in progress, wait here until it completes. std::lock_guard<std::recursive_mutex> lock(*alarm->callback_mutex); std::lock_guard<std::recursive_mutex> lock(*local_mutex_ref); } } // Internal implementation of canceling an alarm. // Internal implementation of canceling an alarm. Loading Loading @@ -583,7 +586,10 @@ static void alarm_ready_generic(alarm_t* alarm, alarm->queue = NULL; alarm->queue = NULL; } } std::lock_guard<std::recursive_mutex> cb_lock(*alarm->callback_mutex); // Increment the reference count of the mutex so it doesn't get freed // before the callback gets finished executing. std::shared_ptr<std::recursive_mutex> local_mutex_ref = alarm->callback_mutex; std::lock_guard<std::recursive_mutex> cb_lock(*local_mutex_ref); lock.unlock(); lock.unlock(); // Update the statistics // Update the statistics Loading system/osi/test/alarm_test.cc +14 −0 Original line number Original line Diff line number Diff line Loading @@ -344,3 +344,17 @@ TEST_F(AlarmTest, test_callback_free_race) { } } alarm_cleanup(); alarm_cleanup(); } } static void remove_cb(void* data) { alarm_free((alarm_t*)data); semaphore_post(semaphore); } TEST_F(AlarmTest, test_delete_during_callback) { for (int i = 0; i < 1000; ++i) { alarm_t* alarm = alarm_new("alarm_test.test_delete_during_callback"); alarm_set(alarm, 0, remove_cb, alarm); semaphore_wait(semaphore); } alarm_cleanup(); } system/stack/sdp/sdp_db.cc +5 −1 Original line number Original line Diff line number Diff line Loading @@ -117,7 +117,11 @@ static bool find_uuid_in_seq(uint8_t* p, uint32_t seq_len, uint8_t* p_uuid, while (p < p_end) { while (p < p_end) { type = *p++; type = *p++; p = sdpu_get_len_from_type(p, type, &len); p = sdpu_get_len_from_type(p, p_end, type, &len); if (p == NULL || (p + len) > p_end) { SDP_TRACE_WARNING("%s: bad length", __func__); break; } type = type >> 3; type = type >> 3; if (type == UUID_DESC_TYPE) { if (type == UUID_DESC_TYPE) { if (sdpu_compare_uuid_arrays(p, len, p_uuid, uuid_len)) return (true); if (sdpu_compare_uuid_arrays(p, len, p_uuid, uuid_len)) return (true); Loading Loading
system/btif/Android.bp +7 −0 Original line number Original line Diff line number Diff line Loading @@ -139,6 +139,13 @@ cc_test { "libprocessgroup", "libprocessgroup", "libutils", "libutils", "libcrypto", "libcrypto", "android.hardware.keymaster@4.0", "android.hardware.keymaster@3.0", "libkeymaster4support", "libkeystore_aidl", "libkeystore_binder", "libkeystore_parcelables", "libbinder", ], ], static_libs: [ static_libs: [ "libbt-bta", "libbt-bta", Loading
system/main/Android.bp +6 −0 Original line number Original line Diff line number Diff line Loading @@ -54,6 +54,12 @@ cc_library_shared { "libtinyxml2", "libtinyxml2", "libz", "libz", "libcrypto", "libcrypto", "android.hardware.keymaster@4.0", "android.hardware.keymaster@3.0", "libkeymaster4support", "libkeystore_aidl", "libkeystore_binder", "libkeystore_parcelables", ], ], static_libs: [ static_libs: [ "libbt-sbc-decoder", "libbt-sbc-decoder", Loading
system/osi/src/alarm.cc +11 −5 Original line number Original line Diff line number Diff line Loading @@ -91,7 +91,7 @@ struct alarm_t { // potentially long-running callback is executing. |alarm_cancel| uses this // potentially long-running callback is executing. |alarm_cancel| uses this // mutex to provide a guarantee to its caller that the callback will not be // mutex to provide a guarantee to its caller that the callback will not be // in progress when it returns. // in progress when it returns. std::recursive_mutex* callback_mutex; std::shared_ptr<std::recursive_mutex> callback_mutex; uint64_t creation_time_ms; uint64_t creation_time_ms; uint64_t period_ms; uint64_t period_ms; uint64_t deadline_ms; uint64_t deadline_ms; Loading Loading @@ -174,7 +174,8 @@ static alarm_t* alarm_new_internal(const char* name, bool is_periodic) { alarm_t* ret = static_cast<alarm_t*>(osi_calloc(sizeof(alarm_t))); alarm_t* ret = static_cast<alarm_t*>(osi_calloc(sizeof(alarm_t))); ret->callback_mutex = new std::recursive_mutex; std::shared_ptr<std::recursive_mutex> ptr(new std::recursive_mutex()); ret->callback_mutex = ptr; ret->is_periodic = is_periodic; ret->is_periodic = is_periodic; ret->stats.name = osi_strdup(name); ret->stats.name = osi_strdup(name); Loading @@ -191,7 +192,7 @@ void alarm_free(alarm_t* alarm) { if (!alarm) return; if (!alarm) return; alarm_cancel(alarm); alarm_cancel(alarm); delete alarm->callback_mutex; osi_free((void*)alarm->stats.name); osi_free((void*)alarm->stats.name); alarm->closure.~CancelableClosureInStruct(); alarm->closure.~CancelableClosureInStruct(); osi_free(alarm); osi_free(alarm); Loading Loading @@ -245,13 +246,15 @@ void alarm_cancel(alarm_t* alarm) { CHECK(alarms != NULL); CHECK(alarms != NULL); if (!alarm) return; if (!alarm) return; std::shared_ptr<std::recursive_mutex> local_mutex_ref = alarm->callback_mutex; { { std::lock_guard<std::mutex> lock(alarms_mutex); std::lock_guard<std::mutex> lock(alarms_mutex); local_mutex_ref = alarm->callback_mutex; alarm_cancel_internal(alarm); alarm_cancel_internal(alarm); } } // If the callback for |alarm| is in progress, wait here until it completes. // If the callback for |alarm| is in progress, wait here until it completes. std::lock_guard<std::recursive_mutex> lock(*alarm->callback_mutex); std::lock_guard<std::recursive_mutex> lock(*local_mutex_ref); } } // Internal implementation of canceling an alarm. // Internal implementation of canceling an alarm. Loading Loading @@ -583,7 +586,10 @@ static void alarm_ready_generic(alarm_t* alarm, alarm->queue = NULL; alarm->queue = NULL; } } std::lock_guard<std::recursive_mutex> cb_lock(*alarm->callback_mutex); // Increment the reference count of the mutex so it doesn't get freed // before the callback gets finished executing. std::shared_ptr<std::recursive_mutex> local_mutex_ref = alarm->callback_mutex; std::lock_guard<std::recursive_mutex> cb_lock(*local_mutex_ref); lock.unlock(); lock.unlock(); // Update the statistics // Update the statistics Loading
system/osi/test/alarm_test.cc +14 −0 Original line number Original line Diff line number Diff line Loading @@ -344,3 +344,17 @@ TEST_F(AlarmTest, test_callback_free_race) { } } alarm_cleanup(); alarm_cleanup(); } } static void remove_cb(void* data) { alarm_free((alarm_t*)data); semaphore_post(semaphore); } TEST_F(AlarmTest, test_delete_during_callback) { for (int i = 0; i < 1000; ++i) { alarm_t* alarm = alarm_new("alarm_test.test_delete_during_callback"); alarm_set(alarm, 0, remove_cb, alarm); semaphore_wait(semaphore); } alarm_cleanup(); }
system/stack/sdp/sdp_db.cc +5 −1 Original line number Original line Diff line number Diff line Loading @@ -117,7 +117,11 @@ static bool find_uuid_in_seq(uint8_t* p, uint32_t seq_len, uint8_t* p_uuid, while (p < p_end) { while (p < p_end) { type = *p++; type = *p++; p = sdpu_get_len_from_type(p, type, &len); p = sdpu_get_len_from_type(p, p_end, type, &len); if (p == NULL || (p + len) > p_end) { SDP_TRACE_WARNING("%s: bad length", __func__); break; } type = type >> 3; type = type >> 3; if (type == UUID_DESC_TYPE) { if (type == UUID_DESC_TYPE) { if (sdpu_compare_uuid_arrays(p, len, p_uuid, uuid_len)) return (true); if (sdpu_compare_uuid_arrays(p, len, p_uuid, uuid_len)) return (true); Loading