18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <stddef.h>
38c2ecf20Sopenharmony_ci#include <stdbool.h>
48c2ecf20Sopenharmony_ci#include <linux/compiler.h>
58c2ecf20Sopenharmony_ci#include <linux/lockdep.h>
68c2ecf20Sopenharmony_ci#include <unistd.h>
78c2ecf20Sopenharmony_ci#include <sys/syscall.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cistatic __thread struct task_struct current_obj;
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* lockdep wants these */
128c2ecf20Sopenharmony_cibool debug_locks = true;
138c2ecf20Sopenharmony_cibool debug_locks_silent;
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci__attribute__((destructor)) static void liblockdep_exit(void)
168c2ecf20Sopenharmony_ci{
178c2ecf20Sopenharmony_ci	debug_check_no_locks_held();
188c2ecf20Sopenharmony_ci}
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistruct task_struct *__curr(void)
218c2ecf20Sopenharmony_ci{
228c2ecf20Sopenharmony_ci	if (current_obj.pid == 0) {
238c2ecf20Sopenharmony_ci		/* Makes lockdep output pretty */
248c2ecf20Sopenharmony_ci		prctl(PR_GET_NAME, current_obj.comm);
258c2ecf20Sopenharmony_ci		current_obj.pid = syscall(__NR_gettid);
268c2ecf20Sopenharmony_ci	}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	return &current_obj;
298c2ecf20Sopenharmony_ci}
30