2020-08-18 13:57:41 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _STATIC_CALL_TYPES_H
|
|
|
|
#define _STATIC_CALL_TYPES_H
|
|
|
|
|
2020-08-18 13:57:42 +00:00
|
|
|
#include <linux/types.h>
|
2020-08-18 13:57:41 +00:00
|
|
|
#include <linux/stringify.h>
|
2021-01-18 14:12:18 +00:00
|
|
|
#include <linux/compiler.h>
|
2020-08-18 13:57:41 +00:00
|
|
|
|
|
|
|
#define STATIC_CALL_KEY_PREFIX __SCK__
|
2020-08-18 13:57:42 +00:00
|
|
|
#define STATIC_CALL_KEY_PREFIX_STR __stringify(STATIC_CALL_KEY_PREFIX)
|
|
|
|
#define STATIC_CALL_KEY_PREFIX_LEN (sizeof(STATIC_CALL_KEY_PREFIX_STR) - 1)
|
2020-08-18 13:57:41 +00:00
|
|
|
#define STATIC_CALL_KEY(name) __PASTE(STATIC_CALL_KEY_PREFIX, name)
|
2021-01-27 23:18:37 +00:00
|
|
|
#define STATIC_CALL_KEY_STR(name) __stringify(STATIC_CALL_KEY(name))
|
2020-08-18 13:57:41 +00:00
|
|
|
|
|
|
|
#define STATIC_CALL_TRAMP_PREFIX __SCT__
|
|
|
|
#define STATIC_CALL_TRAMP_PREFIX_STR __stringify(STATIC_CALL_TRAMP_PREFIX)
|
2020-08-18 13:57:42 +00:00
|
|
|
#define STATIC_CALL_TRAMP_PREFIX_LEN (sizeof(STATIC_CALL_TRAMP_PREFIX_STR) - 1)
|
2020-08-18 13:57:41 +00:00
|
|
|
#define STATIC_CALL_TRAMP(name) __PASTE(STATIC_CALL_TRAMP_PREFIX, name)
|
|
|
|
#define STATIC_CALL_TRAMP_STR(name) __stringify(STATIC_CALL_TRAMP(name))
|
|
|
|
|
2020-08-18 13:57:49 +00:00
|
|
|
/*
|
|
|
|
* Flags in the low bits of static_call_site::key.
|
|
|
|
*/
|
|
|
|
#define STATIC_CALL_SITE_TAIL 1UL /* tail call */
|
|
|
|
#define STATIC_CALL_SITE_INIT 2UL /* init section */
|
|
|
|
#define STATIC_CALL_SITE_FLAGS 3UL
|
|
|
|
|
2020-08-18 13:57:42 +00:00
|
|
|
/*
|
|
|
|
* The static call site table needs to be created by external tooling (objtool
|
|
|
|
* or a compiler plugin).
|
|
|
|
*/
|
|
|
|
struct static_call_site {
|
|
|
|
s32 addr;
|
|
|
|
s32 key;
|
|
|
|
};
|
|
|
|
|
2021-01-18 14:12:18 +00:00
|
|
|
#define DECLARE_STATIC_CALL(name, func) \
|
|
|
|
extern struct static_call_key STATIC_CALL_KEY(name); \
|
|
|
|
extern typeof(func) STATIC_CALL_TRAMP(name);
|
|
|
|
|
|
|
|
#ifdef CONFIG_HAVE_STATIC_CALL
|
|
|
|
|
2021-01-27 23:18:37 +00:00
|
|
|
#define __raw_static_call(name) (&STATIC_CALL_TRAMP(name))
|
|
|
|
|
|
|
|
#ifdef CONFIG_HAVE_STATIC_CALL_INLINE
|
|
|
|
|
2021-01-18 14:12:18 +00:00
|
|
|
/*
|
|
|
|
* __ADDRESSABLE() is used to ensure the key symbol doesn't get stripped from
|
|
|
|
* the symbol table so that objtool can reference it when it generates the
|
|
|
|
* .static_call_sites section.
|
|
|
|
*/
|
2021-01-27 23:18:37 +00:00
|
|
|
#define __STATIC_CALL_ADDRESSABLE(name) \
|
|
|
|
__ADDRESSABLE(STATIC_CALL_KEY(name))
|
|
|
|
|
2021-01-18 14:12:18 +00:00
|
|
|
#define __static_call(name) \
|
|
|
|
({ \
|
2021-01-27 23:18:37 +00:00
|
|
|
__STATIC_CALL_ADDRESSABLE(name); \
|
|
|
|
__raw_static_call(name); \
|
2021-01-18 14:12:18 +00:00
|
|
|
})
|
|
|
|
|
2021-01-27 23:18:37 +00:00
|
|
|
#else /* !CONFIG_HAVE_STATIC_CALL_INLINE */
|
|
|
|
|
|
|
|
#define __STATIC_CALL_ADDRESSABLE(name)
|
|
|
|
#define __static_call(name) __raw_static_call(name)
|
|
|
|
|
|
|
|
#endif /* CONFIG_HAVE_STATIC_CALL_INLINE */
|
|
|
|
|
|
|
|
#ifdef MODULE
|
|
|
|
#define __STATIC_CALL_MOD_ADDRESSABLE(name)
|
|
|
|
#define static_call_mod(name) __raw_static_call(name)
|
|
|
|
#else
|
|
|
|
#define __STATIC_CALL_MOD_ADDRESSABLE(name) __STATIC_CALL_ADDRESSABLE(name)
|
|
|
|
#define static_call_mod(name) __static_call(name)
|
|
|
|
#endif
|
|
|
|
|
2021-01-18 14:12:18 +00:00
|
|
|
#define static_call(name) __static_call(name)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define static_call(name) \
|
|
|
|
((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func))
|
|
|
|
|
|
|
|
#endif /* CONFIG_HAVE_STATIC_CALL */
|
|
|
|
|
2020-08-18 13:57:41 +00:00
|
|
|
#endif /* _STATIC_CALL_TYPES_H */
|