Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/msvc-inval.c @ 17907:0a1c2535cad9
euidaccess: Fix Android build
* modules/euidaccess (Depends-on): Add fcntl-h to ensure that
AT_EACCESS gets declared.
author | Kevin Cernekee <cernekee@google.com> |
---|---|
date | Wed, 11 Feb 2015 15:22:54 -0800 |
parents | ab58d4870664 |
children |
rev | line source |
---|---|
15645 | 1 /* Invalid parameter handler for MSVC runtime libraries. |
17848 | 2 Copyright (C) 2011-2015 Free Software Foundation, Inc. |
15645 | 3 |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2, or (at your option) | |
7 any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License along | |
16366
bb182ee4a09d
maint: replace FSF snail-mail addresses with URLs
Paul Eggert <eggert@cs.ucla.edu>
parents:
16214
diff
changeset
|
15 with this program; if not, see <http://www.gnu.org/licenses/>. */ |
15645 | 16 |
17 #include <config.h> | |
18 | |
19 /* Specification. */ | |
20 #include "msvc-inval.h" | |
21 | |
15786
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
22 #if HAVE_MSVC_INVALID_PARAMETER_HANDLER \ |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
23 && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING) |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
24 |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
25 /* Get _invalid_parameter_handler type and _set_invalid_parameter_handler |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
26 declaration. */ |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
27 # include <stdlib.h> |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
28 |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
29 # if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
30 |
17432
a31d597d15e9
msvc-inval: port to mingw-w64
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
31 static void __cdecl |
15786
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
32 gl_msvc_invalid_parameter_handler (const wchar_t *expression, |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
33 const wchar_t *function, |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
34 const wchar_t *file, |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
35 unsigned int line, |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
36 uintptr_t dummy) |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
37 { |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
38 } |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
39 |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
40 # else |
15645 | 41 |
16214
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
42 /* Get declarations of the native Windows API functions. */ |
15786
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
43 # define WIN32_LEAN_AND_MEAN |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
44 # include <windows.h> |
15645 | 45 |
15786
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
46 # if defined _MSC_VER |
15645 | 47 |
17432
a31d597d15e9
msvc-inval: port to mingw-w64
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
48 static void __cdecl |
15645 | 49 gl_msvc_invalid_parameter_handler (const wchar_t *expression, |
50 const wchar_t *function, | |
51 const wchar_t *file, | |
52 unsigned int line, | |
53 uintptr_t dummy) | |
54 { | |
55 RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL); | |
56 } | |
57 | |
15786
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
58 # else |
15784
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
59 |
15785
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
60 /* An index to thread-local storage. */ |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
61 static DWORD tls_index; |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
62 static int tls_initialized /* = 0 */; |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
63 |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
64 /* Used as a fallback only. */ |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
65 static struct gl_msvc_inval_per_thread not_per_thread; |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
66 |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
67 struct gl_msvc_inval_per_thread * |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
68 gl_msvc_inval_current (void) |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
69 { |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
70 if (!tls_initialized) |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
71 { |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
72 tls_index = TlsAlloc (); |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
73 tls_initialized = 1; |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
74 } |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
75 if (tls_index == TLS_OUT_OF_INDEXES) |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
76 /* TlsAlloc had failed. */ |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
77 return ¬_per_thread; |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
78 else |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
79 { |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
80 struct gl_msvc_inval_per_thread *pointer = |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
81 (struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index); |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
82 if (pointer == NULL) |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
83 { |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
84 /* First call. Allocate a new 'struct gl_msvc_inval_per_thread'. */ |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
85 pointer = |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
86 (struct gl_msvc_inval_per_thread *) |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
87 malloc (sizeof (struct gl_msvc_inval_per_thread)); |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
88 if (pointer == NULL) |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
89 /* Could not allocate memory. Use the global storage. */ |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
90 pointer = ¬_per_thread; |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
91 TlsSetValue (tls_index, pointer); |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
92 } |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
93 return pointer; |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
94 } |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
95 } |
15784
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
96 |
17432
a31d597d15e9
msvc-inval: port to mingw-w64
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
97 static void __cdecl |
15784
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
98 gl_msvc_invalid_parameter_handler (const wchar_t *expression, |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
99 const wchar_t *function, |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
100 const wchar_t *file, |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
101 unsigned int line, |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
102 uintptr_t dummy) |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
103 { |
15785
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
104 struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current (); |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
105 if (current->restart_valid) |
5e020d269ce6
msvc-inval: Make handler multithread-safe.
Bruno Haible <bruno@clisp.org>
parents:
15784
diff
changeset
|
106 longjmp (current->restart, 1); |
15784
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
107 else |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
108 /* An invalid parameter notification from outside the gnulib code. |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
109 Give the caller a chance to intervene. */ |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
110 RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL); |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
111 } |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
112 |
15786
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
113 # endif |
104b4f91678d
msvc-inval: Allow three invalid parameter handling modes.
Bruno Haible <bruno@clisp.org>
parents:
15785
diff
changeset
|
114 |
15784
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
115 # endif |
f1e8251b45f3
msvc-inval: Install handler globally.
Bruno Haible <bruno@clisp.org>
parents:
15645
diff
changeset
|
116 |
15645 | 117 static int gl_msvc_inval_initialized /* = 0 */; |
118 | |
119 void | |
120 gl_msvc_inval_ensure_handler (void) | |
121 { | |
122 if (gl_msvc_inval_initialized == 0) | |
123 { | |
124 _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler); | |
125 gl_msvc_inval_initialized = 1; | |
126 } | |
127 } | |
128 | |
129 #endif |