1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 //
6 // Lock Dependency Tracking Runtime API
7 //
8 // Systems must provide an implementation of the following functions to support
9 // integration of the lock validator into the runtime environment.
10 //
11 
12 #pragma once
13 
14 #include <stdint.h>
15 
16 namespace lockdep {
17 
18 // Forward declarations.
19 class AcquiredLockEntry;
20 class ThreadLockState;
21 class LockClassState;
22 enum class LockResult : uint8_t;
23 
24 // System-defined hook to report detected lock validation failures.
25 extern void SystemLockValidationError(AcquiredLockEntry* lock_entry,
26                                       AcquiredLockEntry* conflicting_entry,
27                                       ThreadLockState* state,
28                                       void* caller_address,
29                                       void* caller_frame,
30                                       LockResult result);
31 
32 // System-defined hook to abort the program due to a fatal lock violation.
33 extern void SystemLockValidationFatal(AcquiredLockEntry* lock_entry,
34                                       ThreadLockState* state,
35                                       void* caller_address,
36                                       void* caller_frame,
37                                       LockResult result);
38 
39 // System-defined hook to report detection of a circular lock dependency.
40 extern void SystemCircularLockDependencyDetected(LockClassState* connected_set_root);
41 
42 // System-defined hook that returns the ThreadLockState instance for the current
43 // thread.
44 extern ThreadLockState* SystemGetThreadLockState();
45 
46 // System-defined hook that initializes the ThreadLockState for the current thread.
47 extern void SystemInitThreadLockState(ThreadLockState* state);
48 
49 // System-defined hook that triggers a loop detection pass. In response to this
50 // event the implementation must trigger a call lockdep::LoopDetectionPass() on
51 // a separate, dedicated or non-reentrant worker thread. Non-reentrancy is a
52 // hard requirement as lockdep::LoopDetectionPass() mutates non-thread safe
53 // state. An implementation may add hysteresis to prevent too many passes in a
54 // given time interval.
55 extern void SystemTriggerLoopDetection();
56 
57 } // namespace lockdep
58