blob: 577956d9182d25098a4591580f0c20d006553f6f [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJ_COMPAT_SETJMP_H__
20#define __PJ_COMPAT_SETJMP_H__
21
22/**
23 * @file setjmp.h
24 * @brief Provides setjmp.h functionality.
25 */
26
27#if defined(PJ_HAS_SETJMP_H) && PJ_HAS_SETJMP_H != 0
28# include <setjmp.h>
29 typedef jmp_buf pj_jmp_buf;
30# define pj_setjmp(buf) setjmp(buf)
31# define pj_longjmp(buf,d) longjmp(buf,d)
32
33#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0 && \
34 defined(PJ_M_I386) && PJ_M_I386 != 0
35
36 /*
37 * These are taken from uClibc.
38 * Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
39 */
40# if defined __USE_MISC || defined _ASM
41# define JB_BX 0
42# define JB_SI 1
43# define JB_DI 2
44# define JB_BP 3
45# define JB_SP 4
46# define JB_PC 5
47# define JB_SIZE 24
48# endif
49
50# ifndef _ASM
51 typedef int __jmp_buf[6];
52
53 /* A `sigset_t' has a bit for each signal. */
54# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
55 typedef struct __sigset_t_tag
56 {
57 unsigned long int __val[_SIGSET_NWORDS];
58 } __sigset_t;
59
60 /* Calling environment, plus possibly a saved signal mask. */
61 typedef struct __jmp_buf_tag /* C++ doesn't like tagless structs. */
62 {
63 /* NOTE: The machine-dependent definitions of `__sigsetjmp'
64 assume that a `jmp_buf' begins with a `__jmp_buf' and that
65 `__mask_was_saved' follows it. Do not move these members
66 or add others before it. */
67 __jmp_buf __jmpbuf; /* Calling environment. */
68 int __mask_was_saved; /* Saved the signal mask? */
69 // we never saved the mask.
70 __sigset_t __saved_mask; /* Saved signal mask. */
71 } jmp_buf[1];
72
73 typedef jmp_buf sigjmp_buf;
74 typedef jmp_buf pj_jmp_buf;
75
76 PJ_DECL(int) pj_setjmp(pj_jmp_buf env);
77 PJ_DECL(void) pj_longjmp(pj_jmp_buf env, int val) __attribute__((noreturn));
78
79# endif /* _ASM */
80
81#else
82# warning "setjmp()/longjmp() is not implemented"
83 typedef int pj_jmp_buf[1];
84# define pj_setjmp(buf) 0
85# define pj_longjmp(buf,d) 0
86#endif
87
88
89#endif /* __PJ_COMPAT_SETJMP_H__ */
90