1 : /*
2 : * Copyright 2010 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can
4 : * be found in the LICENSE file.
5 : */
6 :
7 : #include <signal.h>
8 : #include <sys/ucontext.h>
9 :
10 : #include "native_client/src/trusted/service_runtime/nacl_signal.h"
11 :
12 : /*
13 : * Definition of the POSIX ucontext_t for Mac OS X can be found in:
14 : * /usr/include/mach/i386/_structs.h
15 : */
16 :
17 : #if __DARWIN_UNIX03
18 : #define REG(R) uc_mcontext->__ss.__##R
19 : #else
20 : #define REG(R) uc_mcontext->ss.R
21 : #endif
22 :
23 : /*
24 : * Fill a signal context structure from the raw platform dependent
25 : * signal information.
26 : */
27 : void NaClSignalContextFromHandler(struct NaClSignalContext *sigCtx,
28 4 : const void *rawCtx) {
29 4 : ucontext_t *uctx = (ucontext_t *) rawCtx;
30 :
31 4 : sigCtx->prog_ctr = uctx->REG(eip);
32 4 : sigCtx->stack_ptr = uctx->REG(esp);
33 :
34 4 : sigCtx->eax = uctx->REG(eax);
35 4 : sigCtx->ebx = uctx->REG(ebx);
36 4 : sigCtx->ecx = uctx->REG(ecx);
37 4 : sigCtx->edx = uctx->REG(edx);
38 4 : sigCtx->esi = uctx->REG(esi);
39 4 : sigCtx->edi = uctx->REG(edi);
40 4 : sigCtx->ebp = uctx->REG(ebp);
41 4 : sigCtx->flags = uctx->REG(eflags);
42 4 : sigCtx->cs = uctx->REG(cs);
43 4 : sigCtx->ss = uctx->REG(ss);
44 4 : sigCtx->ds = uctx->REG(ds);
45 4 : sigCtx->es = uctx->REG(es);
46 4 : sigCtx->fs = uctx->REG(fs);
47 4 : sigCtx->gs = uctx->REG(gs);
48 4 : }
49 :
50 :
51 : /*
52 : * Update the raw platform dependent signal information from the
53 : * signal context structure.
54 : */
55 : void NaClSignalContextToHandler(void *rawCtx,
56 0 : const struct NaClSignalContext *sigCtx) {
57 0 : ucontext_t *uctx = (ucontext_t *) rawCtx;
58 :
59 0 : uctx->REG(eip) = sigCtx->prog_ctr;
60 0 : uctx->REG(esp) = sigCtx->stack_ptr;
61 :
62 0 : uctx->REG(eax) = sigCtx->eax;
63 0 : uctx->REG(ebx) = sigCtx->ebx;
64 0 : uctx->REG(ecx) = sigCtx->ecx;
65 0 : uctx->REG(edx) = sigCtx->edx;
66 0 : uctx->REG(esi) = sigCtx->esi;
67 0 : uctx->REG(edi) = sigCtx->edi;
68 0 : uctx->REG(ebp) = sigCtx->ebp;
69 0 : uctx->REG(eflags) = sigCtx->flags;
70 0 : uctx->REG(cs) = sigCtx->cs;
71 0 : uctx->REG(ss) = sigCtx->ss;
72 0 : uctx->REG(ds) = sigCtx->ds;
73 0 : uctx->REG(es) = sigCtx->es;
74 0 : uctx->REG(fs) = sigCtx->fs;
75 0 : uctx->REG(gs) = sigCtx->gs;
76 0 : }
|