PageRenderTime 56ms CodeModel.GetById 15ms app.highlight 36ms RepoModel.GetById 2ms app.codeStats 0ms

/src/core/sys/posix/setjmp.d

http://github.com/AlexeyProkhin/druntime
D | 209 lines | 136 code | 17 blank | 56 comment | 13 complexity | e139296c3abcb34abfd5c8d083b3a03b MD5 | raw file
  1/**
  2 * D header file for POSIX.
  3 *
  4 * Copyright: Copyright Sean Kelly 2005 - 2009.
  5 * License:   <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
  6 * Authors:   Sean Kelly
  7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
  8 */
  9
 10/*          Copyright Sean Kelly 2005 - 2009.
 11 * Distributed under the Boost Software License, Version 1.0.
 12 *    (See accompanying file LICENSE or copy at
 13 *          http://www.boost.org/LICENSE_1_0.txt)
 14 */
 15module core.sys.posix.setjmp;
 16
 17private import core.sys.posix.config;
 18private import core.sys.posix.signal; // for sigset_t
 19
 20version (Posix):
 21extern (C):
 22
 23//
 24// Required
 25//
 26/*
 27jmp_buf
 28
 29int  setjmp(ref jmp_buf);
 30void longjmp(ref jmp_buf, int);
 31*/
 32
 33version( linux )
 34{
 35    version( X86_64 )
 36    {
 37        //enum JB_BX      = 0;
 38        //enum JB_BP      = 1;
 39        //enum JB_12      = 2;
 40        //enum JB_13      = 3;
 41        //enum JB_14      = 4;
 42        //enum JB_15      = 5;
 43        //enum JB_SP      = 6;
 44        //enum JB_PC      = 7;
 45        //enum JB_SIZE    = 64;
 46
 47        alias long[8] __jmp_buf;
 48    }
 49    else version( X86 )
 50    {
 51        //enum JB_BX      = 0;
 52        //enum JB_SI      = 1;
 53        //enum JB_DI      = 2;
 54        //enum JB_BP      = 3;
 55        //enum JB_SP      = 4;
 56        //enum JB_PC      = 5;
 57        //enum JB_SIZE    = 24;
 58
 59        alias int[6] __jmp_buf;
 60    }
 61    else version ( SPARC )
 62    {
 63        alias int[3] __jmp_buf;
 64    }
 65    else version (ARM)
 66    {
 67        alias int[64] __jmp_buf;
 68    }
 69    else version (PPC)
 70    {
 71        alias int[64 + (12*4)] __jmp_buf;
 72    }
 73    else version (PPC64)
 74    {
 75        alias long[64] __jmp_buf;
 76    }
 77    else version (MIPS)
 78    {
 79        struct __jmp_buf
 80        {
 81            version (MIPS_O32)
 82            {
 83                void * __pc;
 84                void * __sp;
 85                int __regs[8];
 86                void * __fp;
 87                void * __gp;
 88            }
 89            else
 90            {
 91                long __pc;
 92                long __sp;
 93                long __regs[8];
 94                long __fp;
 95                long __gp;
 96            }
 97            int __fpc_csr;
 98            version (MIPS_N64)
 99                double __fpregs[8];
100            else
101                double __fpregs[6];
102        }
103    }
104    else
105        static assert(0, "unimplemented");
106
107    struct __jmp_buf_tag
108    {
109        __jmp_buf   __jmpbuf;
110        int         __mask_was_saved;
111        sigset_t    __saved_mask;
112    }
113
114    alias __jmp_buf_tag[1] jmp_buf;
115
116    alias _setjmp setjmp; // see XOpen block
117    void longjmp(ref jmp_buf, int);
118}
119else version( FreeBSD )
120{
121    // <machine/setjmp.h>
122    version( X86 )
123    {
124        enum _JBLEN = 11;
125        struct _jmp_buf { int[_JBLEN + 1] _jb; }
126    }
127    else version( X86_64)
128    {
129        enum _JBLEN = 12;
130        struct _jmp_buf { c_long[_JBLEN] _jb; }
131    }
132    else version( SPARC )
133    {
134        enum _JBLEN = 5;
135        struct _jmp_buf { c_long[_JBLEN + 1] _jb; }
136    }
137    else
138        static assert(0);
139    alias _jmp_buf[1] jmp_buf;
140
141    int  setjmp(ref jmp_buf);
142    void longjmp(ref jmp_buf, int);
143}
144
145//
146// C Extension (CX)
147//
148/*
149sigjmp_buf
150
151int  sigsetjmp(sigjmp_buf, int);
152void siglongjmp(sigjmp_buf, int);
153*/
154
155version( linux )
156{
157    alias jmp_buf sigjmp_buf;
158
159    int __sigsetjmp(sigjmp_buf, int);
160    alias __sigsetjmp sigsetjmp;
161    void siglongjmp(sigjmp_buf, int);
162}
163else version( FreeBSD )
164{
165    // <machine/setjmp.h>
166    version( X86 )
167    {
168        struct _sigjmp_buf { int[_JBLEN + 1] _ssjb; }
169    }
170    else version( X86_64)
171    {
172        struct _sigjmp_buf { c_long[_JBLEN] _sjb; }
173    }
174    else version( SPARC )
175    {
176        enum _JBLEN         = 5;
177        enum _JB_FP         = 0;
178        enum _JB_PC         = 1;
179        enum _JB_SP         = 2;
180        enum _JB_SIGMASK    = 3;
181        enum _JB_SIGFLAG    = 5;
182        struct _sigjmp_buf { c_long[_JBLEN + 1] _sjb; }
183    }
184    else
185        static assert(0);
186    alias _sigjmp_buf[1] sigjmp_buf;
187
188    int  sigsetjmp(ref sigjmp_buf);
189    void siglongjmp(ref sigjmp_buf, int);
190}
191
192//
193// XOpen (XSI)
194//
195/*
196int  _setjmp(jmp_buf);
197void _longjmp(jmp_buf, int);
198*/
199
200version( linux )
201{
202    int  _setjmp(ref jmp_buf);
203    void _longjmp(ref jmp_buf, int);
204}
205else version( FreeBSD )
206{
207    int  _setjmp(ref jmp_buf);
208    void _longjmp(ref jmp_buf, int);
209}