sparc: Implement memcpy/mempcpy ifunc selection in C
[glibc.git] / libio / libioP.h
blob0613439ad4e8f03b36d09f3fe11cb202ec6fb81f
1 /* Copyright (C) 1993-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library 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 GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>.
18 As a special exception, if you link the code in this file with
19 files compiled with a GNU compiler to produce an executable,
20 that does not cause the resulting executable to be covered by
21 the GNU Lesser General Public License. This exception does not
22 however invalidate any other reasons why the executable file
23 might be covered by the GNU Lesser General Public License.
24 This exception applies to code released by its copyright holders
25 in files containing the exception. */
27 /* NOTE: libio is now exclusively used only by glibc since libstdc++ has its
28 own implementation. As a result, functions that were implemented for C++
29 (like *sputn) may no longer have C++ semantics. This is of course only
30 relevant for internal callers of these functions since these functions are
31 not intended for external use otherwise.
33 FIXME: All of the C++ cruft eventually needs to go away. */
35 #include <stddef.h>
37 #include <errno.h>
38 #include <libc-lock.h>
40 #include <math_ldbl_opt.h>
42 #include "iolibio.h"
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
48 #define _IO_seek_set 0
49 #define _IO_seek_cur 1
50 #define _IO_seek_end 2
52 /* THE JUMPTABLE FUNCTIONS.
54 * The _IO_FILE type is used to implement the FILE type in GNU libc,
55 * as well as the streambuf class in GNU iostreams for C++.
56 * These are all the same, just used differently.
57 * An _IO_FILE (or FILE) object is allows followed by a pointer to
58 * a jump table (of pointers to functions). The pointer is accessed
59 * with the _IO_JUMPS macro. The jump table has an eccentric format,
60 * so as to be compatible with the layout of a C++ virtual function table.
61 * (as implemented by g++). When a pointer to a streambuf object is
62 * coerced to an (_IO_FILE*), then _IO_JUMPS on the result just
63 * happens to point to the virtual function table of the streambuf.
64 * Thus the _IO_JUMPS function table used for C stdio/libio does
65 * double duty as the virtual function table for C++ streambuf.
67 * The entries in the _IO_JUMPS function table (and hence also the
68 * virtual functions of a streambuf) are described below.
69 * The first parameter of each function entry is the _IO_FILE/streambuf
70 * object being acted on (i.e. the 'this' parameter).
73 #include <shlib-compat.h>
74 #if !SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
75 /* Setting this macro disables the use of the _vtable_offset bias in
76 _IO_JUMPS_FUNCS, below. That is only needed if we want to
77 support old binaries (see oldfileops.c). */
78 # define _G_IO_NO_BACKWARD_COMPAT 1
79 #endif
81 #if (!defined _IO_USE_OLD_IO_FILE \
82 && (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0))
83 # define _IO_JUMPS_OFFSET 1
84 #else
85 # define _IO_JUMPS_OFFSET 0
86 #endif
88 /* Type of MEMBER in struct type TYPE. */
89 #define _IO_MEMBER_TYPE(TYPE, MEMBER) __typeof__ (((TYPE){}).MEMBER)
91 /* Essentially ((TYPE *) THIS)->MEMBER, but avoiding the aliasing
92 violation in case THIS has a different pointer type. */
93 #define _IO_CAST_FIELD_ACCESS(THIS, TYPE, MEMBER) \
94 (*(_IO_MEMBER_TYPE (TYPE, MEMBER) *)(((char *) (THIS)) \
95 + offsetof(TYPE, MEMBER)))
97 #define _IO_JUMPS(THIS) (THIS)->vtable
98 #define _IO_JUMPS_FILE_plus(THIS) \
99 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE_plus, vtable)
100 #define _IO_WIDE_JUMPS(THIS) \
101 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data)->_wide_vtable
102 #define _IO_CHECK_WIDE(THIS) \
103 (_IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data) != NULL)
105 #if _IO_JUMPS_OFFSET
106 # define _IO_JUMPS_FUNC(THIS) \
107 (IO_validate_vtable \
108 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
109 + (THIS)->_vtable_offset)))
110 # define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
111 #else
112 # define _IO_JUMPS_FUNC(THIS) (IO_validate_vtable (_IO_JUMPS_FILE_plus (THIS)))
113 # define _IO_vtable_offset(THIS) 0
114 #endif
115 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
116 #define JUMP_FIELD(TYPE, NAME) TYPE NAME
117 #define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
118 #define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
119 #define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
120 #define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
121 #define JUMP_INIT(NAME, VALUE) VALUE
122 #define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
124 #define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
125 #define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
126 #define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
127 #define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
129 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
130 It does not delete (free) it, but does everything else to finalize it.
131 It matches the streambuf::~streambuf virtual destructor. */
132 typedef void (*_IO_finish_t) (_IO_FILE *, int); /* finalize */
133 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
134 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
136 /* The 'overflow' hook flushes the buffer.
137 The second argument is a character, or EOF.
138 It matches the streambuf::overflow virtual function. */
139 typedef int (*_IO_overflow_t) (_IO_FILE *, int);
140 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
141 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
143 /* The 'underflow' hook tries to fills the get buffer.
144 It returns the next character (as an unsigned char) or EOF. The next
145 character remains in the get buffer, and the get position is not changed.
146 It matches the streambuf::underflow virtual function. */
147 typedef int (*_IO_underflow_t) (_IO_FILE *);
148 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
149 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
151 /* The 'uflow' hook returns the next character in the input stream
152 (cast to unsigned char), and increments the read position;
153 EOF is returned on failure.
154 It matches the streambuf::uflow virtual function, which is not in the
155 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
156 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
157 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
159 /* The 'pbackfail' hook handles backing up.
160 It matches the streambuf::pbackfail virtual function. */
161 typedef int (*_IO_pbackfail_t) (_IO_FILE *, int);
162 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
163 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
165 /* The 'xsputn' hook writes upto N characters from buffer DATA.
166 Returns EOF or the number of character actually written.
167 It matches the streambuf::xsputn virtual function. */
168 typedef _IO_size_t (*_IO_xsputn_t) (_IO_FILE *FP, const void *DATA,
169 _IO_size_t N);
170 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
171 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
173 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
174 Returns the number of character actually read.
175 It matches the streambuf::xsgetn virtual function. */
176 typedef _IO_size_t (*_IO_xsgetn_t) (_IO_FILE *FP, void *DATA, _IO_size_t N);
177 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
178 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
180 /* The 'seekoff' hook moves the stream position to a new position
181 relative to the start of the file (if DIR==0), the current position
182 (MODE==1), or the end of the file (MODE==2).
183 It matches the streambuf::seekoff virtual function.
184 It is also used for the ANSI fseek function. */
185 typedef _IO_off64_t (*_IO_seekoff_t) (_IO_FILE *FP, _IO_off64_t OFF, int DIR,
186 int MODE);
187 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
188 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
190 /* The 'seekpos' hook also moves the stream position,
191 but to an absolute position given by a fpos64_t (seekpos).
192 It matches the streambuf::seekpos virtual function.
193 It is also used for the ANSI fgetpos and fsetpos functions. */
194 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
195 typedef _IO_off64_t (*_IO_seekpos_t) (_IO_FILE *, _IO_off64_t, int);
196 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
197 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
199 /* The 'setbuf' hook gives a buffer to the file.
200 It matches the streambuf::setbuf virtual function. */
201 typedef _IO_FILE* (*_IO_setbuf_t) (_IO_FILE *, char *, _IO_ssize_t);
202 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
203 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
205 /* The 'sync' hook attempts to synchronize the internal data structures
206 of the file with the external state.
207 It matches the streambuf::sync virtual function. */
208 typedef int (*_IO_sync_t) (_IO_FILE *);
209 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
210 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
212 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
213 It matches the streambuf::doallocate virtual function, which is not
214 in the ANSI/ISO C++ standard, but is part traditional implementations. */
215 typedef int (*_IO_doallocate_t) (_IO_FILE *);
216 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
217 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
219 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
220 sysstat) are low-level hooks specific to this implementation.
221 There is no correspondence in the ANSI/ISO C++ standard library.
222 The hooks basically correspond to the Unix system functions
223 (read, write, close, lseek, and stat) except that a _IO_FILE*
224 parameter is used instead of an integer file descriptor; the default
225 implementation used for normal files just calls those functions.
226 The advantage of overriding these functions instead of the higher-level
227 ones (underflow, overflow etc) is that you can leave all the buffering
228 higher-level functions. */
230 /* The 'sysread' hook is used to read data from the external file into
231 an existing buffer. It generalizes the Unix read(2) function.
232 It matches the streambuf::sys_read virtual function, which is
233 specific to this implementation. */
234 typedef _IO_ssize_t (*_IO_read_t) (_IO_FILE *, void *, _IO_ssize_t);
235 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
236 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
238 /* The 'syswrite' hook is used to write data from an existing buffer
239 to an external file. It generalizes the Unix write(2) function.
240 It matches the streambuf::sys_write virtual function, which is
241 specific to this implementation. */
242 typedef _IO_ssize_t (*_IO_write_t) (_IO_FILE *, const void *, _IO_ssize_t);
243 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
244 #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
246 /* The 'sysseek' hook is used to re-position an external file.
247 It generalizes the Unix lseek(2) function.
248 It matches the streambuf::sys_seek virtual function, which is
249 specific to this implementation. */
250 typedef _IO_off64_t (*_IO_seek_t) (_IO_FILE *, _IO_off64_t, int);
251 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
252 #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
254 /* The 'sysclose' hook is used to finalize (close, finish up) an
255 external file. It generalizes the Unix close(2) function.
256 It matches the streambuf::sys_close virtual function, which is
257 specific to this implementation. */
258 typedef int (*_IO_close_t) (_IO_FILE *); /* finalize */
259 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
260 #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
262 /* The 'sysstat' hook is used to get information about an external file
263 into a struct stat buffer. It generalizes the Unix fstat(2) call.
264 It matches the streambuf::sys_stat virtual function, which is
265 specific to this implementation. */
266 typedef int (*_IO_stat_t) (_IO_FILE *, void *);
267 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
268 #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
270 /* The 'showmany' hook can be used to get an image how much input is
271 available. In many cases the answer will be 0 which means unknown
272 but some cases one can provide real information. */
273 typedef int (*_IO_showmanyc_t) (_IO_FILE *);
274 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
275 #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
277 /* The 'imbue' hook is used to get information about the currently
278 installed locales. */
279 typedef void (*_IO_imbue_t) (_IO_FILE *, void *);
280 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
281 #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
284 #define _IO_CHAR_TYPE char /* unsigned char ? */
285 #define _IO_INT_TYPE int
287 struct _IO_jump_t
289 JUMP_FIELD(size_t, __dummy);
290 JUMP_FIELD(size_t, __dummy2);
291 JUMP_FIELD(_IO_finish_t, __finish);
292 JUMP_FIELD(_IO_overflow_t, __overflow);
293 JUMP_FIELD(_IO_underflow_t, __underflow);
294 JUMP_FIELD(_IO_underflow_t, __uflow);
295 JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
296 /* showmany */
297 JUMP_FIELD(_IO_xsputn_t, __xsputn);
298 JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
299 JUMP_FIELD(_IO_seekoff_t, __seekoff);
300 JUMP_FIELD(_IO_seekpos_t, __seekpos);
301 JUMP_FIELD(_IO_setbuf_t, __setbuf);
302 JUMP_FIELD(_IO_sync_t, __sync);
303 JUMP_FIELD(_IO_doallocate_t, __doallocate);
304 JUMP_FIELD(_IO_read_t, __read);
305 JUMP_FIELD(_IO_write_t, __write);
306 JUMP_FIELD(_IO_seek_t, __seek);
307 JUMP_FIELD(_IO_close_t, __close);
308 JUMP_FIELD(_IO_stat_t, __stat);
309 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
310 JUMP_FIELD(_IO_imbue_t, __imbue);
311 #if 0
312 get_column;
313 set_column;
314 #endif
317 /* We always allocate an extra word following an _IO_FILE.
318 This contains a pointer to the function jump table used.
319 This is for compatibility with C++ streambuf; the word can
320 be used to smash to a pointer to a virtual function table. */
322 struct _IO_FILE_plus
324 _IO_FILE file;
325 const struct _IO_jump_t *vtable;
328 #ifdef _IO_USE_OLD_IO_FILE
329 /* This structure is used by the compatibility code as if it were an
330 _IO_FILE_plus, but has enough space to initialize the _mode argument
331 of an _IO_FILE_complete. */
332 struct _IO_FILE_complete_plus
334 struct _IO_FILE_complete file;
335 const struct _IO_jump_t *vtable;
337 #endif
339 /* Special file type for fopencookie function. */
340 struct _IO_cookie_file
342 struct _IO_FILE_plus __fp;
343 void *__cookie;
344 _IO_cookie_io_functions_t __io_functions;
347 _IO_FILE *_IO_fopencookie (void *cookie, const char *mode,
348 _IO_cookie_io_functions_t io_functions);
351 /* Iterator type for walking global linked list of _IO_FILE objects. */
353 typedef struct _IO_FILE *_IO_ITER;
355 /* Generic functions */
357 extern void _IO_switch_to_main_get_area (_IO_FILE *) __THROW;
358 extern void _IO_switch_to_backup_area (_IO_FILE *) __THROW;
359 extern int _IO_switch_to_get_mode (_IO_FILE *);
360 libc_hidden_proto (_IO_switch_to_get_mode)
361 extern void _IO_init_internal (_IO_FILE *, int) attribute_hidden;
362 extern int _IO_sputbackc (_IO_FILE *, int) __THROW;
363 libc_hidden_proto (_IO_sputbackc)
364 extern int _IO_sungetc (_IO_FILE *) __THROW;
365 extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
366 libc_hidden_proto (_IO_un_link)
367 extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
368 libc_hidden_proto (_IO_link_in)
369 extern void _IO_doallocbuf (_IO_FILE *) __THROW;
370 libc_hidden_proto (_IO_doallocbuf)
371 extern void _IO_unsave_markers (_IO_FILE *) __THROW;
372 libc_hidden_proto (_IO_unsave_markers)
373 extern void _IO_setb (_IO_FILE *, char *, char *, int) __THROW;
374 libc_hidden_proto (_IO_setb)
375 extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
376 libc_hidden_proto (_IO_adjust_column)
377 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
379 _IO_ssize_t _IO_least_wmarker (_IO_FILE *, wchar_t *) __THROW;
380 libc_hidden_proto (_IO_least_wmarker)
381 extern void _IO_switch_to_main_wget_area (_IO_FILE *) __THROW;
382 libc_hidden_proto (_IO_switch_to_main_wget_area)
383 extern void _IO_switch_to_wbackup_area (_IO_FILE *) __THROW;
384 libc_hidden_proto (_IO_switch_to_wbackup_area)
385 extern int _IO_switch_to_wget_mode (_IO_FILE *);
386 libc_hidden_proto (_IO_switch_to_wget_mode)
387 extern void _IO_wsetb (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW;
388 libc_hidden_proto (_IO_wsetb)
389 extern wint_t _IO_sputbackwc (_IO_FILE *, wint_t) __THROW;
390 libc_hidden_proto (_IO_sputbackwc)
391 extern wint_t _IO_sungetwc (_IO_FILE *) __THROW;
392 extern void _IO_wdoallocbuf (_IO_FILE *) __THROW;
393 libc_hidden_proto (_IO_wdoallocbuf)
394 extern void _IO_unsave_wmarkers (_IO_FILE *) __THROW;
395 extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
396 extern _IO_off64_t get_file_offset (_IO_FILE *fp);
398 /* Marker-related function. */
400 extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *);
401 extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *);
402 extern void _IO_remove_marker (struct _IO_marker *) __THROW;
403 extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
404 __THROW;
405 extern int _IO_marker_delta (struct _IO_marker *) __THROW;
406 extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
407 extern int _IO_seekmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
408 extern int _IO_seekwmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
410 /* Functions for iterating global list and dealing with its lock */
412 extern _IO_ITER _IO_iter_begin (void) __THROW;
413 libc_hidden_proto (_IO_iter_begin)
414 extern _IO_ITER _IO_iter_end (void) __THROW;
415 libc_hidden_proto (_IO_iter_end)
416 extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
417 libc_hidden_proto (_IO_iter_next)
418 extern _IO_FILE *_IO_iter_file (_IO_ITER) __THROW;
419 libc_hidden_proto (_IO_iter_file)
420 extern void _IO_list_lock (void) __THROW;
421 libc_hidden_proto (_IO_list_lock)
422 extern void _IO_list_unlock (void) __THROW;
423 libc_hidden_proto (_IO_list_unlock)
424 extern void _IO_list_resetlock (void) __THROW;
425 libc_hidden_proto (_IO_list_resetlock)
426 extern void _IO_enable_locks (void) __THROW;
427 libc_hidden_proto (_IO_enable_locks)
429 /* Default jumptable functions. */
431 extern int _IO_default_underflow (_IO_FILE *) __THROW;
432 extern int _IO_default_uflow (_IO_FILE *);
433 libc_hidden_proto (_IO_default_uflow)
434 extern wint_t _IO_wdefault_uflow (_IO_FILE *);
435 libc_hidden_proto (_IO_wdefault_uflow)
436 extern int _IO_default_doallocate (_IO_FILE *) __THROW;
437 libc_hidden_proto (_IO_default_doallocate)
438 extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW;
439 libc_hidden_proto (_IO_wdefault_doallocate)
440 extern void _IO_default_finish (_IO_FILE *, int) __THROW;
441 libc_hidden_proto (_IO_default_finish)
442 extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW;
443 libc_hidden_proto (_IO_wdefault_finish)
444 extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW;
445 libc_hidden_proto (_IO_default_pbackfail)
446 extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW;
447 libc_hidden_proto (_IO_wdefault_pbackfail)
448 extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t);
449 extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t);
450 libc_hidden_proto (_IO_default_xsputn)
451 extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t);
452 libc_hidden_proto (_IO_wdefault_xsputn)
453 extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t);
454 libc_hidden_proto (_IO_default_xsgetn)
455 extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t);
456 libc_hidden_proto (_IO_wdefault_xsgetn)
457 extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int)
458 __THROW;
459 extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int);
460 extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t);
461 extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t);
462 extern int _IO_default_stat (_IO_FILE *, void *) __THROW;
463 extern _IO_off64_t _IO_default_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
464 extern int _IO_default_sync (_IO_FILE *) __THROW;
465 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
466 extern int _IO_default_showmanyc (_IO_FILE *) __THROW;
467 extern void _IO_default_imbue (_IO_FILE *, void *) __THROW;
469 extern const struct _IO_jump_t _IO_file_jumps;
470 libc_hidden_proto (_IO_file_jumps)
471 extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
472 extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
473 extern const struct _IO_jump_t _IO_wfile_jumps;
474 libc_hidden_proto (_IO_wfile_jumps)
475 extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
476 extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
477 extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
478 extern const struct _IO_jump_t _IO_streambuf_jumps;
479 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
480 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
481 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
482 extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
483 extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t);
484 libc_hidden_proto (_IO_do_write)
485 extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t);
486 extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t);
487 extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t);
488 libc_hidden_proto (_IO_wdo_write)
489 extern int _IO_flush_all_lockp (int);
490 extern int _IO_flush_all (void);
491 libc_hidden_proto (_IO_flush_all)
492 extern int _IO_cleanup (void);
493 extern void _IO_flush_all_linebuffered (void);
494 libc_hidden_proto (_IO_flush_all_linebuffered)
495 extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *);
496 extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *);
497 extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
498 extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *);
499 extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
500 extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
501 extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
502 extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
503 extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW;
506 #define _IO_do_flush(_f) \
507 ((_f)->_mode <= 0 \
508 ? _IO_do_write(_f, (_f)->_IO_write_base, \
509 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
510 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
511 ((_f)->_wide_data->_IO_write_ptr \
512 - (_f)->_wide_data->_IO_write_base)))
513 #define _IO_old_do_flush(_f) \
514 _IO_old_do_write(_f, (_f)->_IO_write_base, \
515 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
516 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
517 #define _IO_mask_flags(fp, f, mask) \
518 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
519 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
520 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
521 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
522 (fp)->_wide_data->_IO_read_ptr = (g), \
523 (fp)->_wide_data->_IO_read_end = (eg))
524 #define _IO_setp(__fp, __p, __ep) \
525 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
526 = __p, (__fp)->_IO_write_end = (__ep))
527 #define _IO_wsetp(__fp, __p, __ep) \
528 ((__fp)->_wide_data->_IO_write_base \
529 = (__fp)->_wide_data->_IO_write_ptr = __p, \
530 (__fp)->_wide_data->_IO_write_end = (__ep))
531 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
532 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
533 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
534 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
535 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
536 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
537 - (fp)->_wide_data->_IO_buf_base)
539 /* Jumptable functions for files. */
541 extern int _IO_file_doallocate (_IO_FILE *) __THROW;
542 libc_hidden_proto (_IO_file_doallocate)
543 extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
544 libc_hidden_proto (_IO_file_setbuf)
545 extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
546 libc_hidden_proto (_IO_file_seekoff)
547 extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int)
548 __THROW;
549 extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
550 libc_hidden_proto (_IO_file_xsputn)
551 extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t);
552 libc_hidden_proto (_IO_file_xsgetn)
553 extern int _IO_file_stat (_IO_FILE *, void *) __THROW;
554 libc_hidden_proto (_IO_file_stat)
555 extern int _IO_file_close (_IO_FILE *) __THROW;
556 libc_hidden_proto (_IO_file_close)
557 extern int _IO_file_close_mmap (_IO_FILE *) __THROW;
558 extern int _IO_file_underflow (_IO_FILE *);
559 libc_hidden_proto (_IO_file_underflow)
560 extern int _IO_file_underflow_mmap (_IO_FILE *);
561 extern int _IO_file_underflow_maybe_mmap (_IO_FILE *);
562 extern int _IO_file_overflow (_IO_FILE *, int);
563 libc_hidden_proto (_IO_file_overflow)
564 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
565 extern _IO_FILE* _IO_file_attach (_IO_FILE *, int);
566 libc_hidden_proto (_IO_file_attach)
567 extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int);
568 libc_hidden_proto (_IO_file_open)
569 extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int);
570 libc_hidden_proto (_IO_file_fopen)
571 extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t);
572 extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t);
573 libc_hidden_proto (_IO_file_read)
574 extern int _IO_file_sync (_IO_FILE *);
575 libc_hidden_proto (_IO_file_sync)
576 extern int _IO_file_close_it (_IO_FILE *);
577 libc_hidden_proto (_IO_file_close_it)
578 extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
579 libc_hidden_proto (_IO_file_seek)
580 extern void _IO_file_finish (_IO_FILE *, int);
581 libc_hidden_proto (_IO_file_finish)
583 extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int);
584 extern int _IO_new_file_close_it (_IO_FILE *);
585 extern void _IO_new_file_finish (_IO_FILE *, int);
586 extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *,
587 int);
588 extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *,
589 const struct _IO_jump_t *) __THROW;
590 extern void _IO_new_file_init_internal (struct _IO_FILE_plus *)
591 __THROW attribute_hidden;
592 extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
593 extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t);
594 extern int _IO_new_file_sync (_IO_FILE *);
595 extern int _IO_new_file_underflow (_IO_FILE *);
596 extern int _IO_new_file_overflow (_IO_FILE *, int);
597 extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
598 extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t);
599 extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
601 extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
602 extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
603 extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
604 extern int _IO_old_file_underflow (_IO_FILE *);
605 extern int _IO_old_file_overflow (_IO_FILE *, int);
606 extern void _IO_old_file_init_internal (struct _IO_FILE_plus *)
607 __THROW attribute_hidden;
608 extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int);
609 extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *);
610 extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t);
611 extern int _IO_old_file_sync (_IO_FILE *);
612 extern int _IO_old_file_close_it (_IO_FILE *);
613 extern void _IO_old_file_finish (_IO_FILE *, int);
615 extern int _IO_wfile_doallocate (_IO_FILE *) __THROW;
616 extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t);
617 libc_hidden_proto (_IO_wfile_xsputn)
618 extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t);
619 extern wint_t _IO_wfile_sync (_IO_FILE *);
620 libc_hidden_proto (_IO_wfile_sync)
621 extern wint_t _IO_wfile_underflow (_IO_FILE *);
622 libc_hidden_proto (_IO_wfile_underflow)
623 extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t);
624 libc_hidden_proto (_IO_wfile_overflow)
625 extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int);
626 libc_hidden_proto (_IO_wfile_seekoff)
628 /* Jumptable functions for proc_files. */
629 extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *)
630 __THROW;
631 extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *)
632 __THROW;
633 extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *);
634 extern int _IO_proc_close (_IO_FILE *) __THROW;
635 extern int _IO_new_proc_close (_IO_FILE *) __THROW;
636 extern int _IO_old_proc_close (_IO_FILE *);
638 /* Jumptable functions for strfiles. */
639 extern int _IO_str_underflow (_IO_FILE *) __THROW;
640 libc_hidden_proto (_IO_str_underflow)
641 extern int _IO_str_overflow (_IO_FILE *, int) __THROW;
642 libc_hidden_proto (_IO_str_overflow)
643 extern int _IO_str_pbackfail (_IO_FILE *, int) __THROW;
644 libc_hidden_proto (_IO_str_pbackfail)
645 extern _IO_off64_t _IO_str_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
646 libc_hidden_proto (_IO_str_seekoff)
647 extern void _IO_str_finish (_IO_FILE *, int) __THROW;
649 /* Other strfile functions */
650 struct _IO_strfile_;
651 extern _IO_ssize_t _IO_str_count (_IO_FILE *) __THROW;
653 /* And the wide character versions. */
654 extern void _IO_wstr_init_static (_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *)
655 __THROW;
656 extern _IO_ssize_t _IO_wstr_count (_IO_FILE *) __THROW;
657 extern _IO_wint_t _IO_wstr_overflow (_IO_FILE *, _IO_wint_t) __THROW;
658 extern _IO_wint_t _IO_wstr_underflow (_IO_FILE *) __THROW;
659 extern _IO_off64_t _IO_wstr_seekoff (_IO_FILE *, _IO_off64_t, int, int)
660 __THROW;
661 extern _IO_wint_t _IO_wstr_pbackfail (_IO_FILE *, _IO_wint_t) __THROW;
662 extern void _IO_wstr_finish (_IO_FILE *, int) __THROW;
664 extern int _IO_vasprintf (char **result_ptr, const char *format,
665 _IO_va_list args) __THROW;
666 extern int _IO_vdprintf (int d, const char *format, _IO_va_list arg);
667 extern int _IO_vsnprintf (char *string, _IO_size_t maxlen,
668 const char *format, _IO_va_list args) __THROW;
671 extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int);
672 libc_hidden_proto (_IO_getline)
673 extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t,
674 int, int, int *);
675 libc_hidden_proto (_IO_getline_info)
676 extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *);
677 extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int);
678 extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t,
679 wint_t, int, wint_t *);
681 extern struct _IO_FILE_plus *_IO_list_all;
682 libc_hidden_proto (_IO_list_all)
683 extern void (*_IO_cleanup_registration_needed) (void);
685 extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
686 _IO_size_t, char *) __THROW;
687 extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
688 attribute_hidden;
689 extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
690 attribute_hidden;
692 #ifndef EOF
693 # define EOF (-1)
694 #endif
696 #if _G_HAVE_MMAP
698 # include <unistd.h>
699 # include <fcntl.h>
700 # include <sys/mman.h>
701 # include <sys/param.h>
703 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
704 # define MAP_ANONYMOUS MAP_ANON
705 # endif
707 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
708 # undef _G_HAVE_MMAP
709 # define _G_HAVE_MMAP 0
710 # endif
712 #endif /* _G_HAVE_MMAP */
714 extern int _IO_vscanf (const char *, _IO_va_list) __THROW;
716 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
717 #ifndef _IO_pos_BAD
718 # define _IO_pos_BAD ((_IO_off64_t) -1)
719 #endif
720 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
721 #ifndef _IO_pos_adjust
722 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
723 #endif
724 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
725 #ifndef _IO_pos_0
726 # define _IO_pos_0 ((_IO_off64_t) 0)
727 #endif
729 #ifdef __cplusplus
731 #endif
733 #ifdef _IO_MTSAFE_IO
734 /* check following! */
735 # ifdef _IO_USE_OLD_IO_FILE
736 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
737 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
738 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
739 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
740 # else
741 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
742 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
743 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
744 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
745 NULL, WDP, 0 }
746 # endif
747 #else
748 # ifdef _IO_USE_OLD_IO_FILE
749 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
750 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
751 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
752 0, _IO_pos_BAD }
753 # else
754 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
755 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
756 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
757 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
758 NULL, WDP, 0 }
759 # endif
760 #endif
762 #define _IO_va_start(args, last) va_start(args, last)
764 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
766 #if 1
767 # define COERCE_FILE(FILE) /* Nothing */
768 #else
769 /* This is part of the kludge for binary compatibility with old stdio. */
770 # define COERCE_FILE(FILE) \
771 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
772 && (FILE) = *(FILE**)&((int*)fp)[1])
773 #endif
775 #ifdef EINVAL
776 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
777 #else
778 # define MAYBE_SET_EINVAL /* nothing */
779 #endif
781 #ifdef IO_DEBUG
782 # define CHECK_FILE(FILE, RET) \
783 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
784 else { COERCE_FILE(FILE); \
785 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
786 { MAYBE_SET_EINVAL; return RET; }}
787 #else
788 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
789 #endif
791 static inline void
792 __attribute__ ((__always_inline__))
793 _IO_acquire_lock_fct (_IO_FILE **p)
795 _IO_FILE *fp = *p;
796 if ((fp->_flags & _IO_USER_LOCK) == 0)
797 _IO_funlockfile (fp);
800 static inline void
801 __attribute__ ((__always_inline__))
802 _IO_acquire_lock_clear_flags2_fct (_IO_FILE **p)
804 _IO_FILE *fp = *p;
805 fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD);
806 if ((fp->_flags & _IO_USER_LOCK) == 0)
807 _IO_funlockfile (fp);
810 #if !defined _IO_MTSAFE_IO && IS_IN (libc)
811 # define _IO_acquire_lock(_fp) \
812 do { \
813 _IO_FILE *_IO_acquire_lock_file = NULL
814 # define _IO_acquire_lock_clear_flags2(_fp) \
815 do { \
816 _IO_FILE *_IO_acquire_lock_file = (_fp)
817 # define _IO_release_lock(_fp) \
818 if (_IO_acquire_lock_file != NULL) \
819 _IO_acquire_lock_file->_flags2 &= ~(_IO_FLAGS2_FORTIFY \
820 | _IO_FLAGS2_SCANF_STD); \
821 } while (0)
822 #endif
824 /* Collect all vtables in a special section for vtable verification.
825 These symbols cover the extent of this section. */
826 symbol_set_declare (__libc_IO_vtables)
828 /* libio vtables need to carry this attribute so that they pass
829 validation. */
830 #define libio_vtable __attribute__ ((section ("__libc_IO_vtables")))
832 #ifdef SHARED
833 /* If equal to &_IO_vtable_check (with pointer guard protection),
834 unknown vtable pointers are valid. This function pointer is solely
835 used as a flag. */
836 extern void (*IO_accept_foreign_vtables) (void) attribute_hidden;
838 /* Assigns the passed function pointer (either NULL or
839 &_IO_vtable_check) to IO_accept_foreign_vtables. */
840 static inline void
841 IO_set_accept_foreign_vtables (void (*flag) (void))
843 #ifdef PTR_MANGLE
844 PTR_MANGLE (flag);
845 #endif
846 atomic_store_relaxed (&IO_accept_foreign_vtables, flag);
849 #else /* !SHARED */
851 /* The statically-linked version does nothing. */
852 static inline void
853 IO_set_accept_foreign_vtables (void (*flag) (void))
857 #endif
859 /* Check if unknown vtable pointers are permitted; otherwise,
860 terminate the process. */
861 void _IO_vtable_check (void) attribute_hidden;
863 /* Perform vtable pointer validation. If validation fails, terminate
864 the process. */
865 static inline const struct _IO_jump_t *
866 IO_validate_vtable (const struct _IO_jump_t *vtable)
868 /* Fast path: The vtable pointer is within the __libc_IO_vtables
869 section. */
870 uintptr_t section_length = __stop___libc_IO_vtables - __start___libc_IO_vtables;
871 const char *ptr = (const char *) vtable;
872 uintptr_t offset = ptr - __start___libc_IO_vtables;
873 if (__glibc_unlikely (offset >= section_length))
874 /* The vtable pointer is not in the expected section. Use the
875 slow path, which will terminate the process if necessary. */
876 _IO_vtable_check ();
877 return vtable;