PageRenderTime 49ms CodeModel.GetById 2ms app.highlight 43ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/sys/posix/ucontext.d

http://github.com/AlexeyProkhin/druntime
D | 403 lines | 326 code | 39 blank | 38 comment | 5 complexity | b0d1e1619b630fb9c75ed30fc0899c74 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.ucontext;
 16
 17private import core.sys.posix.config;
 18public import core.sys.posix.signal; // for sigset_t, stack_t
 19
 20version (Posix):
 21extern (C):
 22
 23//
 24// XOpen (XSI)
 25//
 26/*
 27mcontext_t
 28
 29struct ucontext_t
 30{
 31    ucontext_t* uc_link;
 32    sigset_t    uc_sigmask;
 33    stack_t     uc_stack;
 34    mcontext_t  uc_mcontext;
 35}
 36*/
 37
 38version( linux )
 39{
 40
 41    version( X86_64 )
 42    {
 43        enum
 44        {
 45            REG_R8 = 0,
 46            REG_R9,
 47            REG_R10,
 48            REG_R11,
 49            REG_R12,
 50            REG_R13,
 51            REG_R14,
 52            REG_R15,
 53            REG_RDI,
 54            REG_RSI,
 55            REG_RBP,
 56            REG_RBX,
 57            REG_RDX,
 58            REG_RAX,
 59            REG_RCX,
 60            REG_RSP,
 61            REG_RIP,
 62            REG_EFL,
 63            REG_CSGSFS,     /* Actually short cs, gs, fs, __pad0.  */
 64            REG_ERR,
 65            REG_TRAPNO,
 66            REG_OLDMASK,
 67            REG_CR2
 68        }
 69
 70        private
 71        {
 72            struct _libc_fpxreg
 73            {
 74                ushort[4] significand;
 75                ushort    exponent;
 76                ushort[3] padding;
 77            }
 78
 79            struct _libc_xmmreg
 80            {
 81                uint[4] element;
 82            }
 83
 84            struct _libc_fpstate
 85            {
 86                ushort           cwd;
 87                ushort           swd;
 88                ushort           ftw;
 89                ushort           fop;
 90                ulong            rip;
 91                ulong            rdp;
 92                uint             mxcsr;
 93                uint             mxcr_mask;
 94                _libc_fpxreg[8]  _st;
 95                _libc_xmmreg[16] _xmm;
 96                uint[24]         padding;
 97            }
 98
 99            enum NGREG = 23;
100
101            alias c_long            greg_t;
102            alias greg_t[NGREG]     gregset_t;
103            alias _libc_fpstate*    fpregset_t;
104        }
105
106        struct mcontext_t
107        {
108            gregset_t   gregs;
109            fpregset_t  fpregs;
110            c_ulong[8]  __reserved1;
111        }
112
113        struct ucontext_t
114        {
115            c_ulong         uc_flags;
116            ucontext_t*     uc_link;
117            stack_t         uc_stack;
118            mcontext_t      uc_mcontext;
119            sigset_t        uc_sigmask;
120            _libc_fpstate   __fpregs_mem;
121        }
122    }
123    else version( X86 )
124    {
125        enum
126        {
127            REG_GS = 0,
128            REG_FS,
129            REG_ES,
130            REG_DS,
131            REG_EDI,
132            REG_ESI,
133            REG_EBP,
134            REG_ESP,
135            REG_EBX,
136            REG_EDX,
137            REG_ECX,
138            REG_EAX,
139            REG_TRAPNO,
140            REG_ERR,
141            REG_EIP,
142            REG_CS,
143            REG_EFL,
144            REG_UESP,
145            REG_SS
146        }
147
148        private
149        {
150            struct _libc_fpreg
151            {
152              ushort[4] significand;
153              ushort    exponent;
154            }
155
156            struct _libc_fpstate
157            {
158              c_ulong           cw;
159              c_ulong           sw;
160              c_ulong           tag;
161              c_ulong           ipoff;
162              c_ulong           cssel;
163              c_ulong           dataoff;
164              c_ulong           datasel;
165              _libc_fpreg[8]    _st;
166              c_ulong           status;
167            }
168
169            enum NGREG = 19;
170
171            alias int               greg_t;
172            alias greg_t[NGREG]     gregset_t;
173            alias _libc_fpstate*    fpregset_t;
174        }
175
176        struct mcontext_t
177        {
178            gregset_t   gregs;
179            fpregset_t  fpregs;
180            c_ulong     oldmask;
181            c_ulong     cr2;
182        }
183
184        struct ucontext_t
185        {
186            c_ulong         uc_flags;
187            ucontext_t*     uc_link;
188            stack_t         uc_stack;
189            mcontext_t      uc_mcontext;
190            sigset_t        uc_sigmask;
191            _libc_fpstate   __fpregs_mem;
192        }
193    }
194    else version (MIPS)
195    {
196        private
197        {
198            enum NGREG  = 32;
199            enum NFPREG = 32;
200
201            alias ulong         greg_t;
202            alias greg_t[NGREG] gregset_t;
203
204            struct fpregset_t
205            {
206                union fp_r_t
207                {
208                    double[NFPREG]  fp_dregs;
209                    static struct fp_fregs_t
210                    {
211                        float   _fp_fregs;
212                        uint    _fp_pad;
213                    } fp_fregs_t[NFPREG] fp_fregs;
214                } fp_r_t fp_r;
215            }
216        }
217
218        version (MIPS_O32)
219        {
220            struct mcontext_t
221            {
222                uint regmask;
223                uint status;
224                greg_t pc;
225                gregset_t gregs;
226                fpregset_t fpregs;
227                uint fp_owned;
228                uint fpc_csr;
229                uint fpc_eir;
230                uint used_math;
231                uint dsp;
232                greg_t mdhi;
233                greg_t mdlo;
234                c_ulong hi1;
235                c_ulong lo1;
236                c_ulong hi2;
237                c_ulong lo2;
238                c_ulong hi3;
239                c_ulong lo3;
240            }
241        }
242        else
243        {
244            struct mcontext_t
245            {
246                gregset_t gregs;
247                fpregset_t fpregs;
248                greg_t mdhi;
249                greg_t hi1;
250                greg_t hi2;
251                greg_t hi3;
252                greg_t mdlo;
253                greg_t lo1;
254                greg_t lo2;
255                greg_t lo3;
256                greg_t pc;
257                uint fpc_csr;
258                uint used_math;
259                uint dsp;
260                uint reserved;
261            }
262        }
263
264        struct ucontext_t
265        {
266            c_ulong     uc_flags;
267            ucontext_t* uc_link;
268            stack_t     uc_stack;
269            mcontext_t  uc_mcontext;
270            sigset_t    uc_sigmask;
271        }
272    }
273    else
274        static assert(0, "unimplemented");
275}
276else version( FreeBSD )
277{
278    // <machine/ucontext.h>
279    version( X86_64 )
280    {
281      alias long __register_t;
282      alias uint __uint32_t;
283      alias ushort __uint16_t;
284
285      struct mcontext_t {
286       __register_t    mc_onstack;
287       __register_t    mc_rdi;
288       __register_t    mc_rsi;
289       __register_t    mc_rdx;
290       __register_t    mc_rcx;
291       __register_t    mc_r8;
292       __register_t    mc_r9;
293       __register_t    mc_rax;
294       __register_t    mc_rbx;
295       __register_t    mc_rbp;
296       __register_t    mc_r10;
297       __register_t    mc_r11;
298       __register_t    mc_r12;
299       __register_t    mc_r13;
300       __register_t    mc_r14;
301       __register_t    mc_r15;
302       __uint32_t      mc_trapno;
303       __uint16_t      mc_fs;
304       __uint16_t      mc_gs;
305       __register_t    mc_addr;
306       __uint32_t      mc_flags;
307       __uint16_t      mc_es;
308       __uint16_t      mc_ds;
309       __register_t    mc_err;
310       __register_t    mc_rip;
311       __register_t    mc_cs;
312       __register_t    mc_rflags;
313       __register_t    mc_rsp;
314       __register_t    mc_ss;
315
316       long    mc_len;                 /* sizeof(mcontext_t) */
317
318       long    mc_fpformat;
319       long    mc_ownedfp;
320
321       align(16)
322       long    mc_fpstate[64];
323
324       __register_t    mc_fsbase;
325       __register_t    mc_gsbase;
326
327       long    mc_spare[6];
328      }
329    }
330    else version( X86 )
331    {
332        alias int __register_t;
333
334        struct mcontext_t
335        {
336            __register_t    mc_onstack;
337            __register_t    mc_gs;
338            __register_t    mc_fs;
339            __register_t    mc_es;
340            __register_t    mc_ds;
341            __register_t    mc_edi;
342            __register_t    mc_esi;
343            __register_t    mc_ebp;
344            __register_t    mc_isp;
345            __register_t    mc_ebx;
346            __register_t    mc_edx;
347            __register_t    mc_ecx;
348            __register_t    mc_eax;
349            __register_t    mc_trapno;
350            __register_t    mc_err;
351            __register_t    mc_eip;
352            __register_t    mc_cs;
353            __register_t    mc_eflags;
354            __register_t    mc_esp;
355            __register_t    mc_ss;
356
357            int             mc_len;
358            int             mc_fpformat;
359            int             mc_ownedfp;
360            int[1]          mc_spare1;
361
362            align(16)
363            int[128]        mc_fpstate;
364
365            __register_t    mc_fsbase;
366            __register_t    mc_gsbase;
367
368            int[6]          mc_spare2;
369        }
370    }
371
372    // <ucontext.h>
373    enum UCF_SWAPPED = 0x00000001;
374
375    struct ucontext_t
376    {
377        sigset_t        uc_sigmask;
378        mcontext_t      uc_mcontext;
379
380        ucontext_t*     uc_link;
381        stack_t         uc_stack;
382        int             uc_flags;
383        int[4]          __spare__;
384    }
385}
386
387//
388// Obsolescent (OB)
389//
390/*
391int  getcontext(ucontext_t*);
392void makecontext(ucontext_t*, void function(), int, ...);
393int  setcontext(in ucontext_t*);
394int  swapcontext(ucontext_t*, in ucontext_t*);
395*/
396
397static if( is( ucontext_t ) )
398{
399    int  getcontext(ucontext_t*);
400    void makecontext(ucontext_t*, void function(), int, ...);
401    int  setcontext(in ucontext_t*);
402    int  swapcontext(ucontext_t*, in ucontext_t*);
403}