Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / debug_stub / win / thread_impl.cc
1 /*
2  * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 #include <windows.h>
8
9 #include "native_client/src/trusted/debug_stub/thread.h"
10 #include "native_client/src/trusted/service_runtime/nacl_signal.h"
11
12 /*
13  * Define the OS specific portions of IThread interface.
14  */
15
16 namespace port {
17
18 enum PosixSignals {
19   SIGINT  = 2,
20   SIGQUIT = 3,
21   SIGILL  = 4,
22   SIGTRACE= 5,
23   SIGBUS  = 7,
24   SIGFPE  = 8,
25   SIGKILL = 9,
26   SIGSEGV = 11,
27   SIGSTKFLT = 16,
28 };
29
30 int IThread::ExceptionToSignal(int ex) {
31   switch (static_cast<DWORD>(ex)) {
32     case EXCEPTION_GUARD_PAGE:
33     case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
34     case EXCEPTION_DATATYPE_MISALIGNMENT:
35     case EXCEPTION_ACCESS_VIOLATION:
36     case EXCEPTION_IN_PAGE_ERROR:
37     case EXCEPTION_PRIV_INSTRUCTION:
38       return SIGSEGV;
39
40     case EXCEPTION_BREAKPOINT:
41     case EXCEPTION_SINGLE_STEP:
42       return SIGTRACE;
43
44     case EXCEPTION_FLT_DENORMAL_OPERAND:
45     case EXCEPTION_FLT_DIVIDE_BY_ZERO:
46     case EXCEPTION_FLT_INEXACT_RESULT:
47     case EXCEPTION_FLT_INVALID_OPERATION:
48     case EXCEPTION_FLT_OVERFLOW:
49     case EXCEPTION_FLT_STACK_CHECK:
50     case EXCEPTION_FLT_UNDERFLOW:
51       return SIGFPE;
52
53     case EXCEPTION_INT_DIVIDE_BY_ZERO:
54     case EXCEPTION_INT_OVERFLOW:
55     case EXCEPTION_ILLEGAL_INSTRUCTION:
56       return SIGILL;
57
58     case EXCEPTION_STACK_OVERFLOW:
59       return SIGSTKFLT;
60
61     case CONTROL_C_EXIT:
62       return SIGQUIT;
63
64     case EXCEPTION_NONCONTINUABLE_EXCEPTION:
65     case EXCEPTION_INVALID_DISPOSITION:
66     case EXCEPTION_INVALID_HANDLE:
67       return SIGILL;
68   }
69   return SIGILL;
70 }
71
72 }  // namespace port