Send a crash report when a hung process is detected.
[chromium-blink-merge.git] / native_client_sdk / src / libraries / third_party / pthreads-win32 / ptw32_throw.c
blob1404e940f5f8c420d2c80fda40d693fe1154e67f
1 /*
2 * ptw32_throw.c
4 * Description:
5 * This translation unit implements routines which are private to
6 * the implementation and may be used throughout it.
8 * --------------------------------------------------------------------------
10 * Pthreads-win32 - POSIX Threads Library for Win32
11 * Copyright(C) 1998 John E. Bossom
12 * Copyright(C) 1999,2005 Pthreads-win32 contributors
14 * Contact Email: rpj@callisto.canberra.edu.au
16 * The current list of contributors is contained
17 * in the file CONTRIBUTORS included with the source
18 * code distribution. The list can also be seen at the
19 * following World Wide Web location:
20 * http://sources.redhat.com/pthreads-win32/contributors.html
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License as published by the Free Software Foundation; either
25 * version 2 of the License, or (at your option) any later version.
27 * This library is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 * Lesser General Public License for more details.
32 * You should have received a copy of the GNU Lesser General Public
33 * License along with this library in the file COPYING.LIB;
34 * if not, write to the Free Software Foundation, Inc.,
35 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
38 #include "pthread.h"
39 #include "implement.h"
41 #if defined(__CLEANUP_C)
42 # include <setjmp.h>
43 #endif
46 * ptw32_throw
48 * All canceled and explicitly exited POSIX threads go through
49 * here. This routine knows how to exit both POSIX initiated threads and
50 * 'implicit' POSIX threads for each of the possible language modes (C,
51 * C++, and SEH).
53 #if defined(_MSC_VER)
55 * Ignore the warning:
56 * "C++ exception specification ignored except to indicate that
57 * the function is not __declspec(nothrow)."
59 #pragma warning(disable:4290)
60 #endif
61 void
62 ptw32_throw (DWORD exception)
63 #if defined(__CLEANUP_CXX)
64 throw(ptw32_exception_cancel,ptw32_exception_exit)
65 #endif
68 * Don't use pthread_self() to avoid creating an implicit POSIX thread handle
69 * unnecessarily.
71 ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
73 #if defined(__CLEANUP_SEH)
74 DWORD exceptionInformation[3];
75 #endif
77 sp->state = PThreadStateExiting;
79 if (exception != PTW32_EPS_CANCEL && exception != PTW32_EPS_EXIT)
81 /* Should never enter here */
82 exit (1);
85 if (NULL == sp || sp->implicit)
88 * We're inside a non-POSIX initialised Win32 thread
89 * so there is no point to jump or throw back to. Just do an
90 * explicit thread exit here after cleaning up POSIX
91 * residue (i.e. cleanup handlers, POSIX thread handle etc).
93 #if ! (defined(__MINGW64__) || defined(__MINGW32__)) || defined (__MSVCRT__) || defined (__DMC__)
94 unsigned exitCode = 0;
96 switch (exception)
98 case PTW32_EPS_CANCEL:
99 exitCode = (unsigned)(size_t) PTHREAD_CANCELED;
100 break;
101 case PTW32_EPS_EXIT:
102 if (NULL != sp)
104 exitCode = (unsigned)(size_t) sp->exitStatus;
106 break;
108 #endif
110 #if defined(PTW32_STATIC_LIB)
112 pthread_win32_thread_detach_np ();
114 #endif
116 #if ! (defined(__MINGW64__) || defined(__MINGW32__)) || defined (__MSVCRT__) || defined (__DMC__)
117 _endthreadex (exitCode);
118 #else
119 _endthread ();
120 #endif
124 #if defined(__CLEANUP_SEH)
127 exceptionInformation[0] = (DWORD) (exception);
128 exceptionInformation[1] = (DWORD) (0);
129 exceptionInformation[2] = (DWORD) (0);
131 RaiseException (EXCEPTION_PTW32_SERVICES, 0, 3, exceptionInformation);
133 #else /* __CLEANUP_SEH */
135 #if defined(__CLEANUP_C)
137 ptw32_pop_cleanup_all (1);
138 longjmp (sp->start_mark, exception);
140 #else /* __CLEANUP_C */
142 #if defined(__CLEANUP_CXX)
144 switch (exception)
146 case PTW32_EPS_CANCEL:
147 throw ptw32_exception_cancel ();
148 break;
149 case PTW32_EPS_EXIT:
150 throw ptw32_exception_exit ();
151 break;
154 #else
156 #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
158 #endif /* __CLEANUP_CXX */
160 #endif /* __CLEANUP_C */
162 #endif /* __CLEANUP_SEH */
164 /* Never reached */
168 void
169 ptw32_pop_cleanup_all (int execute)
171 while (NULL != ptw32_pop_cleanup (execute))
177 DWORD
178 ptw32_get_exception_services_code (void)
180 #if defined(__CLEANUP_SEH)
182 return EXCEPTION_PTW32_SERVICES;
184 #else
186 return (DWORD)0;
188 #endif