Sync usage with man page.
[netbsd-mini2440.git] / lib / libc / arch / sparc / gen / longjmp.c
blob9356baff55d200a5a0dce14f4a97e441ae8bdefe
1 /* $NetBSD: longjmp.c,v 1.1 2005/10/15 22:11:22 uwe Exp $ */
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
12 * are met:
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>
34 #include <ucontext.h>
35 #include <signal.h>
36 #include <stdlib.h>
37 #include <string.h>
39 #define __LIBC12_SOURCE__
40 #include <setjmp.h>
41 #include <compat/include/setjmp.h>
44 * Use setcontext to reload the stack pointer, program counter <pc,npc>, and
45 * set the return value in %o0. The %i and %l registers will be reloaded
46 * from the place to which %sp points.
48 void
49 __longjmp14(jmp_buf env, int val)
51 struct sigcontext *sc = (void *)env;
52 ucontext_t uc;
54 /* Ensure non-zero SP */
55 if (sc->sc_sp == 0)
56 goto err;
58 /* Initialise the fields we're going to use */
59 uc.uc_link = 0;
62 * Set _UC_{SET,CLR}STACK according to SS_ONSTACK.
64 * Restore the signal mask with sigprocmask() instead of _UC_SIGMASK,
65 * since libpthread may want to interpose on signal handling.
67 uc.uc_flags = _UC_CPU | (sc->sc_onstack ? _UC_SETSTACK : _UC_CLRSTACK);
69 sigprocmask(SIG_SETMASK, &sc->sc_mask, NULL);
71 /* Extract PSR, PC, NPC and SP from jmp_buf */
72 uc.uc_mcontext.__gregs[_REG_PSR] = sc->sc_psr;
73 uc.uc_mcontext.__gregs[_REG_PC] = sc->sc_pc;
74 uc.uc_mcontext.__gregs[_REG_nPC] = sc->sc_npc;
75 uc.uc_mcontext.__gregs[_REG_O6] = sc->sc_sp;
77 /* Set the return value; make sure it's non-zero */
78 uc.uc_mcontext.__gregs[_REG_O0] = (val != 0 ? val : 1);
80 setcontext(&uc);
82 err:
83 longjmperror();
84 abort();
85 /* NOTREACHED */