xref: /optee_os/lib/libutils/isoc/include/setjmp.h (revision 7749dda24cf2b1f0a04d1de529cde03b6ca79867)
11bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-3-Clause */
20c81fcd6SJens Wiklander /*
30c81fcd6SJens Wiklander  * Copyright (c) 1994-2009  Red Hat, Inc.
40c81fcd6SJens Wiklander  * Copyright (c) 2016, Linaro Limited
5acf07754SMarouene Boubakri  * Copyright 2022-2023 NXP
60c81fcd6SJens Wiklander  * All rights reserved.
70c81fcd6SJens Wiklander  *
80c81fcd6SJens Wiklander  * Redistribution and use in source and binary forms, with or without
90c81fcd6SJens Wiklander  * modification, are permitted provided that the following conditions are met:
100c81fcd6SJens Wiklander  *
110c81fcd6SJens Wiklander  * 1. Redistributions of source code must retain the above copyright notice,
120c81fcd6SJens Wiklander  * this list of conditions and the following disclaimer.
130c81fcd6SJens Wiklander  *
140c81fcd6SJens Wiklander  * 2. Redistributions in binary form must reproduce the above copyright notice,
150c81fcd6SJens Wiklander  * this list of conditions and the following disclaimer in the documentation
160c81fcd6SJens Wiklander  * and/or other materials provided with the distribution.
170c81fcd6SJens Wiklander  *
180c81fcd6SJens Wiklander  * 3. Neither the name of the copyright holder nor the names of its
190c81fcd6SJens Wiklander  * contributors may be used to endorse or promote products derived from this
200c81fcd6SJens Wiklander  * software without specific prior written permission.
210c81fcd6SJens Wiklander  *
220c81fcd6SJens Wiklander  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
230c81fcd6SJens Wiklander  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
240c81fcd6SJens Wiklander  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
250c81fcd6SJens Wiklander  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
260c81fcd6SJens Wiklander  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
270c81fcd6SJens Wiklander  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
280c81fcd6SJens Wiklander  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
290c81fcd6SJens Wiklander  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
300c81fcd6SJens Wiklander  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
310c81fcd6SJens Wiklander  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
320c81fcd6SJens Wiklander  * POSSIBILITY OF SUCH DAMAGE.
330c81fcd6SJens Wiklander  */
340c81fcd6SJens Wiklander 
350c81fcd6SJens Wiklander #ifndef __SETJMP_H
360c81fcd6SJens Wiklander #define __SETJMP_H
370c81fcd6SJens Wiklander 
38f88850d4SJerome Forissier #include <compiler.h>
39f88850d4SJerome Forissier 
402fa93c74SJens Wiklander #if defined(ARM32)
410c81fcd6SJens Wiklander /*
420c81fcd6SJens Wiklander  * All callee preserved registers:
430c81fcd6SJens Wiklander  * v1 - v7, fp, ip, sp, lr, f4, f5, f6, f7
44c96d7091SSumit Garg  * One additional 32-bit value used in case ftrace
45c96d7091SSumit Garg  * is enabled to restore ftrace return stack.
460c81fcd6SJens Wiklander  */
47c96d7091SSumit Garg #define _JBLEN 24
482fa93c74SJens Wiklander #define _JBTYPE int
490c81fcd6SJens Wiklander #endif
500c81fcd6SJens Wiklander 
512fa93c74SJens Wiklander #if defined(ARM64)
520c81fcd6SJens Wiklander #define _JBLEN 22
530c81fcd6SJens Wiklander #define _JBTYPE long long
540c81fcd6SJens Wiklander #endif
55bc12b0e9SAlvin Chang 
56bc12b0e9SAlvin Chang #if defined(RV64) || defined(RV32)
57acf07754SMarouene Boubakri /*
58acf07754SMarouene Boubakri  * Callee preserved registers:
59acf07754SMarouene Boubakri  * s0-s11, ra, sp
60bc12b0e9SAlvin Chang  * One additional value used in case ftrace
61bc12b0e9SAlvin Chang  * is enabled to restore ftrace return stack.
62acf07754SMarouene Boubakri  */
63bc12b0e9SAlvin Chang #define _JBLEN 15
64acf07754SMarouene Boubakri #define _JBTYPE unsigned long
65acf07754SMarouene Boubakri #endif
660c81fcd6SJens Wiklander 
670c81fcd6SJens Wiklander #ifdef _JBLEN
680c81fcd6SJens Wiklander typedef	_JBTYPE jmp_buf[_JBLEN];
690c81fcd6SJens Wiklander #endif
700c81fcd6SJens Wiklander 
71f88850d4SJerome Forissier void __noreturn longjmp(jmp_buf env, int val);
720c81fcd6SJens Wiklander int setjmp(jmp_buf env);
730c81fcd6SJens Wiklander 
74099918f6SSumit Garg #ifdef CFG_FTRACE_SUPPORT
759d6ac097SSumit Garg void ftrace_longjmp(unsigned int *ret_idx);
769d6ac097SSumit Garg void ftrace_setjmp(unsigned int *ret_idx);
779d6ac097SSumit Garg #endif
78*7749dda2SAleksandr Iashchenko #ifdef CFG_CORE_SANITIZE_KADDRESS
79*7749dda2SAleksandr Iashchenko void asan_handle_longjmp(void *old_sp);
80*7749dda2SAleksandr Iashchenko #endif
810c81fcd6SJens Wiklander #endif /*__SETJMP_H*/
82