xref: /netbsd/sys/sys/ras.h (revision fe56279c)
1*fe56279cSskrll /*	$NetBSD: ras.h,v 1.15 2021/01/11 21:51:20 skrll Exp $	*/
25bcbbd40Sgmcgarry 
35bcbbd40Sgmcgarry /*-
4bccf777bSad  * Copyright (c) 2002, 2004, 2007 The NetBSD Foundation, Inc.
55bcbbd40Sgmcgarry  * All rights reserved.
65bcbbd40Sgmcgarry  *
75bcbbd40Sgmcgarry  * This code is derived from software contributed to The NetBSD Foundation
85bcbbd40Sgmcgarry  * by Gregory McGarry.
95bcbbd40Sgmcgarry  *
105bcbbd40Sgmcgarry  * Redistribution and use in source and binary forms, with or without
115bcbbd40Sgmcgarry  * modification, are permitted provided that the following conditions
125bcbbd40Sgmcgarry  * are met:
135bcbbd40Sgmcgarry  * 1. Redistributions of source code must retain the above copyright
145bcbbd40Sgmcgarry  *    notice, this list of conditions and the following disclaimer.
155bcbbd40Sgmcgarry  * 2. Redistributions in binary form must reproduce the above copyright
165bcbbd40Sgmcgarry  *    notice, this list of conditions and the following disclaimer in the
175bcbbd40Sgmcgarry  *    documentation and/or other materials provided with the distribution.
185bcbbd40Sgmcgarry  *
195bcbbd40Sgmcgarry  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
205bcbbd40Sgmcgarry  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
215bcbbd40Sgmcgarry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
225bcbbd40Sgmcgarry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
235bcbbd40Sgmcgarry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
245bcbbd40Sgmcgarry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
255bcbbd40Sgmcgarry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
265bcbbd40Sgmcgarry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
275bcbbd40Sgmcgarry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
285bcbbd40Sgmcgarry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
295bcbbd40Sgmcgarry  * POSSIBILITY OF SUCH DAMAGE.
305bcbbd40Sgmcgarry  */
315bcbbd40Sgmcgarry 
325bcbbd40Sgmcgarry #ifndef _SYS_RAS_H_
335bcbbd40Sgmcgarry #define _SYS_RAS_H_
345bcbbd40Sgmcgarry 
35ebbad000Sscw #ifndef __ASSEMBLER__
365bcbbd40Sgmcgarry #include <sys/types.h>
375bcbbd40Sgmcgarry #include <sys/queue.h>
385bcbbd40Sgmcgarry 
395bcbbd40Sgmcgarry struct ras {
40bccf777bSad 	struct ras	*ras_next;
4153524e44Schristos 	void		*ras_startaddr;
4253524e44Schristos 	void		*ras_endaddr;
435bcbbd40Sgmcgarry };
445bcbbd40Sgmcgarry 
455bcbbd40Sgmcgarry #define RAS_INSTALL		0
465bcbbd40Sgmcgarry #define RAS_PURGE		1
475bcbbd40Sgmcgarry #define RAS_PURGE_ALL		2
48ebbad000Sscw #else
49ebbad000Sscw #include <sys/cdefs.h>
50ebbad000Sscw #endif /* __ASSEMBLER__ */
515bcbbd40Sgmcgarry 
525bcbbd40Sgmcgarry #ifdef _KERNEL
535bcbbd40Sgmcgarry 
54ebbad000Sscw #ifndef __ASSEMBLER__
555bcbbd40Sgmcgarry struct proc;
565bcbbd40Sgmcgarry 
5753524e44Schristos void	*ras_lookup(struct proc *, void *);
585bcbbd40Sgmcgarry int	ras_fork(struct proc *, struct proc *);
59bccf777bSad int	ras_purgeall(void);
60ebbad000Sscw #endif /* __ASSEMBLER__ */
61a3572728Ssimonb 
62ebbad000Sscw #else /* !_KERNEL */
635bcbbd40Sgmcgarry 
647a0d577eSchs #ifndef	RAS_DECL
657a0d577eSchs 
66fc892593Sthorpej #define	RAS_DECL(name)							\
677a0d577eSchs extern void __CONCAT(name,_ras_start(void)), __CONCAT(name,_ras_end(void))
687a0d577eSchs 
697a0d577eSchs #endif	/* RAS_DECL */
70fc892593Sthorpej 
71fc892593Sthorpej /*
72fc892593Sthorpej  * RAS_START and RAS_END contain implicit instruction reordering
73fc892593Sthorpej  * barriers.  See __insn_barrier() in <sys/cdefs.h>.
74ebbad000Sscw  *
75ebbad000Sscw  * Note: You are strongly advised to avoid coding RASs in C. There is a
76ebbad000Sscw  * good chance the compiler will generate code which cannot be restarted.
77fc892593Sthorpej  */
78fc892593Sthorpej #define	RAS_START(name)							\
79e14523e9Sperry 	__asm volatile(".globl " ___STRING(name) "_ras_start\n"	\
80fc892593Sthorpej 			 ___STRING(name) "_ras_start:" 			\
81fc892593Sthorpej 	    ::: "memory")
82fc892593Sthorpej 
83fc892593Sthorpej #define	RAS_END(name)							\
84e14523e9Sperry 	__asm volatile(".globl " ___STRING(name) "_ras_end\n"		\
85fc892593Sthorpej 			 ___STRING(name) "_ras_end:"			\
86fc892593Sthorpej 	    ::: "memory")
87fc892593Sthorpej 
884cfa0739Sskrll #define	RAS_ADDR(name)	((void *)(uintptr_t) __CONCAT(name,_ras_start))
89fc892593Sthorpej #define	RAS_SIZE(name)	((size_t)((uintptr_t) __CONCAT(name,_ras_end) -	\
90fc892593Sthorpej 				  (uintptr_t) __CONCAT(name,_ras_start)))
91fc892593Sthorpej 
92ebbad000Sscw #ifndef __ASSEMBLER__
935bcbbd40Sgmcgarry __BEGIN_DECLS
9453524e44Schristos int rasctl(void *, size_t, int);
955bcbbd40Sgmcgarry __END_DECLS
965bcbbd40Sgmcgarry 
97ebbad000Sscw #else /* __ASSEMBLER__ */
98ebbad000Sscw 
99a4f4c1ceSskrll #ifndef	_ASM_LS_CHAR
100a4f4c1ceSskrll #define	_ASM_LS_CHAR	;
101a4f4c1ceSskrll #endif
102a4f4c1ceSskrll 
103ebbad000Sscw /*
104ebbad000Sscw  * RAS_START_ASM and RAS_END_ASM are for use within assembly code.
105*fe56279cSskrll  * This is the preferred method of coding a RAS.
106ebbad000Sscw  */
107ebbad000Sscw #define	RAS_START_ASM(name)						\
108a4f4c1ceSskrll 	.globl _C_LABEL(__CONCAT(name,_ras_start))	 _ASM_LS_CHAR	\
109ebbad000Sscw 	_C_LABEL(__CONCAT(name,_ras_start)):
110ebbad000Sscw 
111ebbad000Sscw #define	RAS_END_ASM(name)						\
112a4f4c1ceSskrll 	.globl _C_LABEL(__CONCAT(name,_ras_end)) 	_ASM_LS_CHAR	\
113ebbad000Sscw 	_C_LABEL(__CONCAT(name,_ras_end)):
114ebbad000Sscw 
115ebbad000Sscw /*
116ebbad000Sscw  * RAS_START_ASM_HIDDEN and RAS_END_ASM_HIDDEN are similar to the above,
117ebbad000Sscw  * except that they limit the scope of the symbol such that it will not
118ebbad000Sscw  * be placed into the dynamic symbol table. Thus no other module (executable
119ebbad000Sscw  * or shared library) can reference it directly.
120ebbad000Sscw  */
121ebbad000Sscw #define	RAS_START_ASM_HIDDEN(name)					\
122a4f4c1ceSskrll 	.globl _C_LABEL(__CONCAT(name,_ras_start)) 	_ASM_LS_CHAR	\
123a4f4c1ceSskrll 	.hidden _C_LABEL(__CONCAT(name,_ras_start)) 	_ASM_LS_CHAR	\
124ebbad000Sscw 	_C_LABEL(__CONCAT(name,_ras_start)):
125ebbad000Sscw 
126ebbad000Sscw #define	RAS_END_ASM_HIDDEN(name)					\
127a4f4c1ceSskrll 	.globl _C_LABEL(__CONCAT(name,_ras_end)) 	_ASM_LS_CHAR	\
128a4f4c1ceSskrll 	.hidden _C_LABEL(__CONCAT(name,_ras_end)) 	_ASM_LS_CHAR	\
129ebbad000Sscw 	_C_LABEL(__CONCAT(name,_ras_end)):
130ebbad000Sscw #endif /* __ASSEMBLER__ */
131ebbad000Sscw 
1325bcbbd40Sgmcgarry #endif /* _KERNEL */
1335bcbbd40Sgmcgarry 
1345bcbbd40Sgmcgarry #endif /* !_SYS_RAS_H_ */
135