18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * vvar.h: Shared vDSO/kernel variable declarations
48c2ecf20Sopenharmony_ci * Copyright (c) 2011 Andy Lutomirski
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * A handful of variables are accessible (read-only) from userspace
78c2ecf20Sopenharmony_ci * code in the vsyscall page and the vdso.  They are declared here.
88c2ecf20Sopenharmony_ci * Some other file must define them with DEFINE_VVAR.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * In normal kernel code, they are used like any other variable.
118c2ecf20Sopenharmony_ci * In user code, they are accessed through the VVAR macro.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * These variables live in a page of kernel data that has an extra RO
148c2ecf20Sopenharmony_ci * mapping for userspace.  Each variable needs a unique offset within
158c2ecf20Sopenharmony_ci * that page; specify that offset with the DECLARE_VVAR macro.  (If
168c2ecf20Sopenharmony_ci * you mess up, the linker will catch it.)
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#ifndef _ASM_X86_VVAR_H
208c2ecf20Sopenharmony_ci#define _ASM_X86_VVAR_H
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#ifdef EMIT_VVAR
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci * EMIT_VVAR() is used by the kernel linker script to put vvars in the
258c2ecf20Sopenharmony_ci * right place. Also, it's used by kernel code to import offsets values.
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_ci#define DECLARE_VVAR(offset, type, name) \
288c2ecf20Sopenharmony_ci	EMIT_VVAR(name, offset)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#else
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciextern char __vvar_page;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define DECLARE_VVAR(offset, type, name)				\
358c2ecf20Sopenharmony_ci	extern type vvar_ ## name[CS_BASES]				\
368c2ecf20Sopenharmony_ci	__attribute__((visibility("hidden")));				\
378c2ecf20Sopenharmony_ci	extern type timens_ ## name[CS_BASES]				\
388c2ecf20Sopenharmony_ci	__attribute__((visibility("hidden")));				\
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define VVAR(name) (vvar_ ## name)
418c2ecf20Sopenharmony_ci#define TIMENS(name) (timens_ ## name)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define DEFINE_VVAR(type, name)						\
448c2ecf20Sopenharmony_ci	type name[CS_BASES]						\
458c2ecf20Sopenharmony_ci	__attribute__((section(".vvar_" #name), aligned(16))) __visible
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#endif
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/* DECLARE_VVAR(offset, type, name) */
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciDECLARE_VVAR(128, struct vdso_data, _vdso_data)
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#undef DECLARE_VVAR
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#endif
56