1 /* $NetBSD: longjmp.c,v 1.1 2005/10/16 17:15:38 christos Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christian Limpach.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include "namespace.h"
33 #include <sys/types.h>
40 #define __LIBC12_SOURCE__
42 #include <compat/include/setjmp.h>
49 __longjmp14(jmp_buf env
, int val
)
51 struct sigcontext
*sc
= (void *)env
;
52 __jmp_buf_regs_t
*r
= (void *)&sc
[1];
55 /* Ensure non-zero SP */
60 * Set _UC_CPU. No FPU data saved, so we can't restore
61 * that. Set _UC_{SET,CLR}STACK according to SS_ONSTACK
63 memset(&uc
, 0, sizeof(uc
));
64 uc
.uc_flags
= _UC_CPU
| (sc
->sc_onstack
? _UC_SETSTACK
: _UC_CLRSTACK
);
67 * Set the signal mask - this is a weak symbol, so don't use
68 * _UC_SIGMASK in the mcontext, libpthread might override sigprocmask.
70 sigprocmask(SIG_SETMASK
, &sc
->sc_mask
, NULL
);
72 /* Fill other registers */
73 uc
.uc_mcontext
.__gregs
[_REG_CCR
] = sc
->sc_tstate
;
74 uc
.uc_mcontext
.__gregs
[_REG_PC
] = sc
->sc_pc
;
75 uc
.uc_mcontext
.__gregs
[_REG_nPC
] = sc
->sc_npc
;
76 uc
.uc_mcontext
.__gregs
[_REG_G1
] = sc
->sc_g1
;
77 uc
.uc_mcontext
.__gregs
[_REG_G2
] = sc
->sc_o0
;
78 uc
.uc_mcontext
.__gregs
[_REG_G3
] = r
->__glob
[0];
79 uc
.uc_mcontext
.__gregs
[_REG_G4
] = r
->__glob
[1];
80 uc
.uc_mcontext
.__gregs
[_REG_G5
] = r
->__glob
[2];
81 uc
.uc_mcontext
.__gregs
[_REG_G6
] = r
->__glob
[3];
82 uc
.uc_mcontext
.__gregs
[_REG_G7
] = r
->__glob
[4];
83 uc
.uc_mcontext
.__gregs
[_REG_O6
] = sc
->sc_sp
;
85 /* Make return value non-zero */
89 /* Save return value in context */
90 uc
.uc_mcontext
.__gregs
[_REG_O0
] = val
;