-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more docs Document fix locking in tests
- Loading branch information
Showing
11 changed files
with
150 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# XXXX. Use static Thread Safety Analysis annotations | ||
|
||
Date: 2022-03-21 | ||
|
||
## Status | ||
|
||
Proposed | ||
|
||
## Context | ||
|
||
Some mistakes in lock usage can be detected statically. | ||
As opposed to dynamic approaches, either TSan (already in use) or lock priorities (proposed in [2], not implemented), the static approach proposed now can be checked reliably in the compiler, or in the IDE (if based on clangd). | ||
|
||
The way it works is that functions are annotated with what locks they require to be held, and the compiler then checks these conditions are satisfied. | ||
|
||
Some additional features of the Clang solution, namely, the TA_GUARDED() annotation for struct members, are available only in C++ [3]; meaning these features may not be used in skupper-router. | ||
|
||
[1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html | ||
[2] | ||
|
||
## Decision | ||
|
||
Annotate all functions that acquire, release, or require locks with the Clang Thread Safety Analysis annotations. | ||
Run a CI job that will check these annotations. | ||
|
||
## Consequences | ||
|
||
Header file defining the annotations needs to be included. | ||
There are multiple possibilities, either the Clang one(mutex.h), or the Zircon one (thread_annotations.h). | ||
They are functionally equivalent, differing only in license and how they name the helper macros. | ||
|
||
Annotation checking (-W) is only implemented in Clang, the GCC implementation was abandoned. | ||
|
||
The lock order checking () is not implemented (not even in Clang) | ||
|
||
|
||
|
||
Disadvantages and limitations | ||
|
||
Python code is not visible to Clang | ||
|
||
limited C support | ||
|
||
requires clang | ||
|
||
? can also annotate for coverity ? |
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,61 @@ | ||
// Copyright 2017 The Fuchsia Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#pragma once | ||
|
||
// This header defines thread annotation macros to be used everywhere in Zircon | ||
// outside of publicly exposed headers. See system/public/zircon/compiler.h for | ||
// the publicly exported macros. | ||
|
||
// The thread safety analysis system is documented at | ||
// http://clang.llvm.org/docs/ThreadSafetyAnalysis.html and its use in Zircon is documented at | ||
// docs/thread_annotations.md. The macros we use are: | ||
// | ||
// TA_CAP(x) |x| is the capability this type represents, e.g. "mutex". | ||
// TA_GUARDED(x) the annotated variable is guarded by the capability (e.g. lock) |x| | ||
// TA_ACQ(x) function acquires the mutex |x| | ||
// TA_ACQ_SHARED(x) function acquires the mutex |x| for shared reading | ||
// TA_ACQ_BEFORE(x) Indicates that if both this mutex and muxex |x| are to be acquired, | ||
// that this mutex must be acquired before mutex |x|. | ||
// TA_ACQ_AFTER(x) Indicates that if both this mutex and muxex |x| are to be acquired, | ||
// that this mutex must be acquired after mutex |x|. | ||
// TA_TRY_ACQ(bool, x) function acquires the mutex |x| if the function returns |bool| | ||
// TA_TRY_ACQ_SHARED(bool, x) function acquires the mutex |x| for shared reading if the function | ||
// returns |bool| | ||
// TA_REL(x) function releases the mutex |x| | ||
// TA_REL_SHARED(x) function releases the shared for reading mutex |x| | ||
// TA_ASSERT(x) function asserts that |x| is held | ||
// TA_ASSERT_SHARED(x) function asserts that |x| is held for shared reading | ||
// TA_REQ(x) function requires that the caller hold the mutex |x| | ||
// TA_REQ_SHARED(x) function requires that the caller hold the mutex |x| for shared | ||
// reading TA_EXCL(x) function requires that the caller not be holding the mutex | ||
// |x| TA_RET_CAP(x) function returns a reference to the mutex |x| TA_SCOPED_CAP type | ||
// represents a scoped or RAII-style wrapper around a capability TA_NO_THREAD_SAFETY_ANALYSIS | ||
// function is excluded entirely from thread safety analysis | ||
|
||
#ifdef __clang__ | ||
#define THREAD_ANNOTATION(x) __attribute__((x)) | ||
#else | ||
#define THREAD_ANNOTATION(x) | ||
#endif | ||
|
||
#define TA_CAP(x) THREAD_ANNOTATION(capability(x)) | ||
#define TA_GUARDED(x) THREAD_ANNOTATION(guarded_by(x)) | ||
#define TA_ACQ(...) THREAD_ANNOTATION(acquire_capability(__VA_ARGS__)) | ||
#define TA_ACQ_SHARED(...) THREAD_ANNOTATION(acquire_shared_capability(__VA_ARGS__)) | ||
#define TA_ACQ_BEFORE(...) THREAD_ANNOTATION(acquired_before(__VA_ARGS__)) | ||
#define TA_ACQ_AFTER(...) THREAD_ANNOTATION(acquired_after(__VA_ARGS__)) | ||
#define TA_TRY_ACQ(...) THREAD_ANNOTATION(try_acquire_capability(__VA_ARGS__)) | ||
#define TA_TRY_ACQ_SHARED(...) THREAD_ANNOTATION(try_acquire_shared_capability(__VA_ARGS__)) | ||
#define TA_REL(...) THREAD_ANNOTATION(release_capability(__VA_ARGS__)) | ||
#define TA_REL_SHARED(...) THREAD_ANNOTATION(release_shared_capability(__VA_ARGS__)) | ||
#define TA_REL_GENERIC(...) THREAD_ANNOTATION(release_generic_capability(__VA_ARGS__)) | ||
#define TA_ASSERT(...) THREAD_ANNOTATION(assert_capability(__VA_ARGS__)) | ||
#define TA_ASSERT_SHARED(...) THREAD_ANNOTATION(assert_shared_capability(__VA_ARGS__)) | ||
#define TA_REQ(...) THREAD_ANNOTATION(requires_capability(__VA_ARGS__)) | ||
#define TA_REQ_SHARED(...) THREAD_ANNOTATION(requires_shared_capability(__VA_ARGS__)) | ||
#define TA_EXCL(...) THREAD_ANNOTATION(locks_excluded(__VA_ARGS__)) | ||
#define TA_RET_CAP(x) THREAD_ANNOTATION(lock_returned(x)) | ||
#define TA_SCOPED_CAP THREAD_ANNOTATION(scoped_lockable) | ||
#define TA_NO_THREAD_SAFETY_ANALYSIS THREAD_ANNOTATION(no_thread_safety_analysis) |
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