include/linux/compiler-context-analysis.h

Source file repositories/reference/linux-study-clean/include/linux/compiler-context-analysis.h

File Facts

System
Linux kernel
Corpus path
include/linux/compiler-context-analysis.h
Extension
.h
Size
18428 bytes
Lines
483
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

*	context_lock_struct(my_handle) {
 *		int foo;
 *		long bar;
 *	};
 *
 *	struct some_state {
 *		...
 *	};
 *	// ... declared elsewhere ...
 *	context_lock_struct(some_state);
 *
 * Note: The implementation defines several helper functions that can acquire
 * and release the context lock.
 */
# define context_lock_struct(name, ...)									\
	struct __ctx_lock_type(name) __VA_ARGS__ name;							\
	static __always_inline void __acquire_ctx_lock(const struct name *var)				\
		__attribute__((overloadable)) __no_context_analysis __acquires_ctx_lock(var) { }	\
	static __always_inline void __acquire_shared_ctx_lock(const struct name *var)			\
		__attribute__((overloadable)) __no_context_analysis __acquires_shared_ctx_lock(var) { } \
	static __always_inline bool __try_acquire_ctx_lock(const struct name *var, bool ret)		\
		__attribute__((overloadable)) __no_context_analysis __try_acquires_ctx_lock(1, var)	\
	{ return ret; }											\
	static __always_inline bool __try_acquire_shared_ctx_lock(const struct name *var, bool ret)	\
		__attribute__((overloadable)) __no_context_analysis __try_acquires_shared_ctx_lock(1, var) \
	{ return ret; }											\
	static __always_inline void __release_ctx_lock(const struct name *var)				\
		__attribute__((overloadable)) __no_context_analysis __releases_ctx_lock(var) { }	\
	static __always_inline void __release_shared_ctx_lock(const struct name *var)			\
		__attribute__((overloadable)) __no_context_analysis __releases_shared_ctx_lock(var) { } \
	static __always_inline void __assume_ctx_lock(const struct name *var)				\
		__attribute__((overloadable)) __assumes_ctx_lock(var) { }				\
	static __always_inline void __assume_shared_ctx_lock(const struct name *var)			\
		__attribute__((overloadable)) __assumes_shared_ctx_lock(var) { }			\
	struct name

/**
 * disable_context_analysis() - disables context analysis
 *
 * Disables context analysis. Must be paired with a later
 * enable_context_analysis().
 */
# define disable_context_analysis()				\
	__diag_push();						\
	__diag_ignore_all("-Wunknown-warning-option", "")	\
	__diag_ignore_all("-Wthread-safety", "")		\
	__diag_ignore_all("-Wthread-safety-pointer", "")

/**
 * enable_context_analysis() - re-enables context analysis
 *
 * Re-enables context analysis. Must be paired with a prior
 * disable_context_analysis().
 */
# define enable_context_analysis() __diag_pop()

/**
 * __no_context_analysis - function attribute, disables context analysis
 *
 * Function attribute denoting that context analysis is disabled for the
 * whole function. Prefer use of `context_unsafe()` where possible.
 */
# define __no_context_analysis	__attribute__((no_thread_safety_analysis))

#else /* !WARN_CONTEXT_ANALYSIS */

# define __ctx_lock_type(name)
# define __reentrant_ctx_lock
# define __acquires_ctx_lock(...)
# define __acquires_shared_ctx_lock(...)
# define __try_acquires_ctx_lock(ret, var)
# define __try_acquires_shared_ctx_lock(ret, var)
# define __releases_ctx_lock(...)
# define __releases_shared_ctx_lock(...)
# define __assumes_ctx_lock(...)
# define __assumes_shared_ctx_lock(...)
# define __returns_ctx_lock(var)
# define __guarded_by(...)
# define __pt_guarded_by(...)
# define __excludes_ctx_lock(...)
# define __requires_ctx_lock(...)
# define __requires_shared_ctx_lock(...)
# define __acquire_ctx_lock(var)			do { } while (0)
# define __acquire_shared_ctx_lock(var)		do { } while (0)
# define __try_acquire_ctx_lock(var, ret)		(ret)
# define __try_acquire_shared_ctx_lock(var, ret)	(ret)
# define __release_ctx_lock(var)			do { } while (0)
# define __release_shared_ctx_lock(var)		do { } while (0)
# define __assume_ctx_lock(var)			do { (void)(var); } while (0)
# define __assume_shared_ctx_lock(var)			do { (void)(var); } while (0)

Annotation

Implementation Notes