xref: /freebsd/sys/x86/include/ifunc.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1d5effb01SKonstantin Belousov /*-
2632227a7SKonstantin Belousov  * Copyright (c) 2015-2018 The FreeBSD Foundation
3d5effb01SKonstantin Belousov  *
4d5effb01SKonstantin Belousov  * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
5d5effb01SKonstantin Belousov  * under sponsorship from the FreeBSD Foundation.
6d5effb01SKonstantin Belousov  *
7d5effb01SKonstantin Belousov  * Redistribution and use in source and binary forms, with or without
8d5effb01SKonstantin Belousov  * modification, are permitted provided that the following conditions
9d5effb01SKonstantin Belousov  * are met:
10d5effb01SKonstantin Belousov  * 1. Redistributions of source code must retain the above copyright
11d5effb01SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer.
12d5effb01SKonstantin Belousov  * 2. Redistributions in binary form must reproduce the above copyright
13d5effb01SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer in the
14d5effb01SKonstantin Belousov  *    documentation and/or other materials provided with the distribution.
15d5effb01SKonstantin Belousov  *
16d5effb01SKonstantin Belousov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17d5effb01SKonstantin Belousov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18d5effb01SKonstantin Belousov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19d5effb01SKonstantin Belousov  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20d5effb01SKonstantin Belousov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21d5effb01SKonstantin Belousov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22d5effb01SKonstantin Belousov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23d5effb01SKonstantin Belousov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24d5effb01SKonstantin Belousov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25d5effb01SKonstantin Belousov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26d5effb01SKonstantin Belousov  * SUCH DAMAGE.
27d5effb01SKonstantin Belousov  */
28d5effb01SKonstantin Belousov 
29d5effb01SKonstantin Belousov #ifndef __X86_IFUNC_H
30d5effb01SKonstantin Belousov #define	__X86_IFUNC_H
31d5effb01SKonstantin Belousov 
32*7c5a46a1SKonstantin Belousov #define	DEFINE_IFUNC(qual, ret_type, name, args)			\
33*7c5a46a1SKonstantin Belousov     static ret_type (*name##_resolver(void))args __used;		\
34d5effb01SKonstantin Belousov     qual ret_type name args __attribute__((ifunc(#name "_resolver")));	\
35*7c5a46a1SKonstantin Belousov     static ret_type (*name##_resolver(void))args
36d5effb01SKonstantin Belousov 
37*7c5a46a1SKonstantin Belousov #define	DEFINE_UIFUNC(qual, ret_type, name, args)			\
38*7c5a46a1SKonstantin Belousov     static ret_type (*name##_resolver(uint32_t, uint32_t, uint32_t,	\
39*7c5a46a1SKonstantin Belousov 	uint32_t))args __used;						\
40632227a7SKonstantin Belousov     qual ret_type name args __attribute__((ifunc(#name "_resolver")));	\
41*7c5a46a1SKonstantin Belousov     static ret_type (*name##_resolver(				\
42632227a7SKonstantin Belousov 	uint32_t cpu_feature __unused,					\
43632227a7SKonstantin Belousov 	uint32_t cpu_feature2 __unused,					\
44632227a7SKonstantin Belousov 	uint32_t cpu_stdext_feature __unused,				\
45632227a7SKonstantin Belousov 	uint32_t cpu_stdext_feature2 __unused))args
46632227a7SKonstantin Belousov 
47d5effb01SKonstantin Belousov #endif
48