/src/rauc/subprojects/glib-2.76.5/glib/glib-private.c
Line | Count | Source |
1 | | /* GLIB - Library of useful routines for C programming |
2 | | * Copyright (C) 2011 Red Hat, Inc. |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | * |
6 | | * This library is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU Lesser General Public |
8 | | * License as published by the Free Software Foundation; either |
9 | | * version 2.1 of the License, or (at your option) any later version. |
10 | | * |
11 | | * This library is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | | * Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public |
17 | | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
18 | | * |
19 | | * Author: Colin Walters <walters@verbum.org> |
20 | | */ |
21 | | |
22 | | #include "config.h" |
23 | | |
24 | | #include "glib-private.h" |
25 | | #include "glib-init.h" |
26 | | |
27 | | #ifdef USE_INVALID_PARAMETER_HANDLER |
28 | | #include <crtdbg.h> |
29 | | #endif |
30 | | |
31 | | /** |
32 | | * glib__private__: |
33 | | * @arg: Do not use this argument |
34 | | * |
35 | | * Do not call this function; it is used to share private |
36 | | * API between glib, gobject, and gio. |
37 | | */ |
38 | | GLibPrivateVTable * |
39 | | glib__private__ (void) |
40 | 4.31k | { |
41 | 4.31k | static GLibPrivateVTable table = { |
42 | 4.31k | g_wakeup_new, |
43 | 4.31k | g_wakeup_free, |
44 | 4.31k | g_wakeup_get_pollfd, |
45 | 4.31k | g_wakeup_signal, |
46 | 4.31k | g_wakeup_acknowledge, |
47 | | |
48 | 4.31k | g_get_worker_context, |
49 | | |
50 | 4.31k | g_check_setuid, |
51 | 4.31k | g_main_context_new_with_next_id, |
52 | | |
53 | 4.31k | g_dir_open_with_errno, |
54 | 4.31k | g_dir_new_from_dirp, |
55 | | |
56 | 4.31k | glib_init, |
57 | | |
58 | | #ifdef G_OS_WIN32 |
59 | | g_win32_stat_utf8, |
60 | | g_win32_lstat_utf8, |
61 | | g_win32_readlink_utf8, |
62 | | g_win32_fstat, |
63 | | g_win32_find_helper_executable_path, |
64 | | g_win32_reopen_noninherited, |
65 | | g_win32_handle_is_socket, |
66 | | #endif |
67 | | |
68 | 4.31k | g_win32_push_empty_invalid_parameter_handler, |
69 | 4.31k | g_win32_pop_invalid_parameter_handler, |
70 | | |
71 | 4.31k | g_find_program_for_path, |
72 | 4.31k | }; |
73 | | |
74 | 4.31k | return &table; |
75 | 4.31k | } |
76 | | |
77 | | #ifdef USE_INVALID_PARAMETER_HANDLER |
78 | | /* |
79 | | * This is the (empty) invalid parameter handler |
80 | | * that is used for Visual C++ 2005 (and later) builds |
81 | | * so that we can use this instead of the system automatically |
82 | | * aborting the process, when calling _get_osfhandle(), isatty() |
83 | | * and _commit() (via g_fsync()) and so on with an invalid file |
84 | | * descriptor. |
85 | | * |
86 | | * This is necessary so that the gspawn helper and the test programs |
87 | | * will continue to run as expected, since we are purposely or |
88 | | * forced to use invalid FDs. |
89 | | * |
90 | | * Please see https://learn.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation?view=msvc-170 |
91 | | * for an explanation on this. |
92 | | */ |
93 | | static void |
94 | | empty_invalid_parameter_handler (const wchar_t *expression, |
95 | | const wchar_t *function, |
96 | | const wchar_t *file, |
97 | | unsigned int line, |
98 | | uintptr_t pReserved) |
99 | | { |
100 | | } |
101 | | |
102 | | /* fallback to _set_invalid_parameter_handler() if we don't have _set_thread_local_invalid_parameter_handler() */ |
103 | | #ifndef HAVE__SET_THREAD_LOCAL_INVALID_PARAMETER_HANDLER |
104 | | # define _set_thread_local_invalid_parameter_handler _set_invalid_parameter_handler |
105 | | #endif |
106 | | |
107 | | #endif |
108 | | /* |
109 | | * g_win32_push_empty_invalid_parameter_handler: |
110 | | * @handler: a possibly uninitialized GWin32InvalidParameterHandler |
111 | | */ |
112 | | void |
113 | | g_win32_push_empty_invalid_parameter_handler (GWin32InvalidParameterHandler *handler) |
114 | 0 | { |
115 | | #ifdef USE_INVALID_PARAMETER_HANDLER |
116 | | /* use the empty invalid parameter handler to override the default invalid parameter_handler */ |
117 | | handler->pushed_handler = empty_invalid_parameter_handler; |
118 | | handler->old_handler = _set_thread_local_invalid_parameter_handler (handler->pushed_handler); |
119 | | |
120 | | /* Disable the message box for assertions. */ |
121 | | handler->pushed_report_mode = 0; |
122 | | handler->prev_report_mode = _CrtSetReportMode(_CRT_ASSERT, handler->pushed_report_mode); |
123 | | #endif |
124 | 0 | } |
125 | | |
126 | | /* |
127 | | * g_win32_pop_invalid_parameter_handler: |
128 | | * @handler: a GWin32InvalidParameterHandler processed with |
129 | | * g_win32_push_empty_invalid_parameter_handler() |
130 | | */ |
131 | | void |
132 | | g_win32_pop_invalid_parameter_handler (GWin32InvalidParameterHandler *handler) |
133 | 0 | { |
134 | | #ifdef USE_INVALID_PARAMETER_HANDLER |
135 | | G_GNUC_UNUSED _invalid_parameter_handler popped_handler; |
136 | | G_GNUC_UNUSED int popped_report_mode; |
137 | | |
138 | | /* Restore previous/default invalid parameter handler, check the value returned matches the one we previously pushed */ |
139 | | popped_handler = _set_thread_local_invalid_parameter_handler (handler->old_handler); |
140 | | g_return_if_fail (handler->pushed_handler == popped_handler); |
141 | | |
142 | | /* Restore the message box for assertions, check the value returned matches the one we previously pushed */ |
143 | | popped_report_mode = _CrtSetReportMode(_CRT_ASSERT, handler->prev_report_mode); |
144 | | g_return_if_fail (handler->pushed_report_mode == popped_report_mode); |
145 | | #endif |
146 | 0 | } |