3 *************************************************************************
6 * Copyright (C) 2009-2013, Intel Corporation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
20 * * Neither the name of Intel Corporation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
32 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
35 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 **************************************************************************/
46 # include "windows-clean.h"
47 # include "internal/abi.h"
48 # include "cilktools/cilkscreen.h"
52 __CILKRTS_BEGIN_EXTERN_C
54 COMMON_PORTABLE
const char *const __cilkrts_assertion_failed
=
55 "%s:%d: cilk assertion failed: %s\n";
57 COMMON_PORTABLE
void __cilkrts_bug(const char *fmt
,...) cilk_nothrow
59 #if defined (_WIN32) && defined(_DEBUG)
60 _CRTIMP
void __cdecl
_wassert(__in_z
const wchar_t * _Message
,
61 __in_z
const wchar_t *_File
,
64 wchar_t wmessage
[256];
67 _vsnprintf_s(message
, 256, _TRUNCATE
, fmt
, l
);
69 _snwprintf_s(wmessage
, 256, _TRUNCATE
, _CRT_WIDE("%S"),
72 // Force asserts to go to stderr and the debugger. This isn't polite, but
73 // we're about to kill the app anyway and it will prevent our tests from
75 _CrtSetReportMode(_CRT_ASSERT
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
76 _CrtSetReportFile(_CRT_ASSERT
, _CRTDBG_FILE_STDERR
);
78 _wassert(wmessage
, _CRT_WIDE(__FILE__
), __LINE__
);
80 // If there's a debugger attached, give it a chance to look at the failure
81 if (IsDebuggerPresent())
87 /* To reduce user confusion, write all user-generated output
88 before the system-generated error message. */
92 vfprintf(stderr
, fmt
, l
);
105 COMMON_PORTABLE
void cilkbug_assert_no_uncaught_exception(void)
107 bool uncaught
= std::uncaught_exception();
108 CILK_ASSERT(!uncaught
);
111 COMMON_SYSDEP
void abort_because_rts_is_corrupted(void)
113 __cilkrts_bug("The Cilk Plus runtime system detected a corruption "
114 "in its data structures. This is most likely caused "
115 "by an application bug. Aborting execution.\n");
119 COMMON_SYSDEP
void __cilkrts_dbgprintf(const char *fmt
,...)
124 // Cilkscreen shouldn't watch this
125 __cilkscreen_disable_checking();
128 _vsnprintf_s(message
, 2048, _TRUNCATE
, fmt
, l
);
130 OutputDebugStringA (message
);
132 // Re-enable Cilkscreen
133 __cilkscreen_enable_checking();
137 __CILKRTS_END_EXTERN_C