1/* This file contains a number of internal prototype declarations that
2 don't fit anywhere else. */
3
4#ifndef _LIBC_INTERNAL
5# define _LIBC_INTERNAL 1
6
7#include <hp-timing.h>
8
9/* Initialize the `__libc_enable_secure' flag. */
10extern void __libc_init_secure (void);
11
12/* This function will be called from _init in init-first.c. */
13extern void __libc_global_ctors (void);
14
15/* Discover the tick frequency of the machine if something goes wrong,
16 we return 0, an impossible hertz. */
17extern int __profile_frequency (void);
18libc_hidden_proto (__profile_frequency)
19
20/* Hooks for the instrumenting functions. */
21extern void __cyg_profile_func_enter (void *this_fn, void *call_site);
22extern void __cyg_profile_func_exit (void *this_fn, void *call_site);
23
24/* Get frequency of the system processor. */
25extern hp_timing_t __get_clockfreq (void);
26
27/* Free all allocated resources. */
28extern void __libc_freeres (void);
29libc_hidden_proto (__libc_freeres)
30
31/* Free resources stored in thread-local variables on thread exit. */
32extern void __libc_thread_freeres (void);
33
34/* Define and initialize `__progname' et. al. */
35extern void __init_misc (int, char **, char **);
36
37# if IS_IN (rtld)
38extern __typeof (__profile_frequency) __profile_frequency attribute_hidden;
39# endif
40
41/* 1 if 'type' is a pointer type, 0 otherwise. */
42# define __pointer_type(type) (__builtin_classify_type ((type) 0) == 5)
43
44/* __intptr_t if P is true, or T if P is false. */
45# define __integer_if_pointer_type_sub(T, P) \
46 __typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0 : (void *) (P))) 0 \
47 : (__typeof__ (0 ? (__intptr_t *) 0 : (void *) (!(P)))) 0))
48
49/* __intptr_t if EXPR has a pointer type, or the type of EXPR otherwise. */
50# define __integer_if_pointer_type(expr) \
51 __integer_if_pointer_type_sub(__typeof__ ((__typeof__ (expr)) 0), \
52 __pointer_type (__typeof__ (expr)))
53
54/* Cast an integer or a pointer VAL to integer with proper type. */
55# define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val))
56
57/* Align a value by rounding down to closest size.
58 e.g. Using size of 4096, we get this behavior:
59 {4095, 4096, 4097} = {0, 4096, 4096}. */
60#define ALIGN_DOWN(base, size) ((base) & -((__typeof__ (base)) (size)))
61
62/* Align a value by rounding up to closest size.
63 e.g. Using size of 4096, we get this behavior:
64 {4095, 4096, 4097} = {4096, 4096, 8192}.
65
66 Note: The size argument has side effects (expanded multiple times). */
67#define ALIGN_UP(base, size) ALIGN_DOWN ((base) + (size) - 1, (size))
68
69/* Same as ALIGN_DOWN(), but automatically casts when base is a pointer. */
70#define PTR_ALIGN_DOWN(base, size) \
71 ((__typeof__ (base)) ALIGN_DOWN ((uintptr_t) (base), (size)))
72
73/* Same as ALIGN_UP(), but automatically casts when base is a pointer. */
74#define PTR_ALIGN_UP(base, size) \
75 ((__typeof__ (base)) ALIGN_UP ((uintptr_t) (base), (size)))
76
77/* Ignore the value of an expression when a cast to void does not
78 suffice (in particular, for a call to a function declared with
79 attribute warn_unused_result). */
80#define ignore_value(x) \
81 ({ __typeof__ (x) __ignored_value = (x); (void) __ignored_value; })
82
83/* The macros to control diagnostics are structured like this, rather
84 than a single macro that both pushes and pops diagnostic state and
85 takes the affected code as an argument, because the GCC pragmas
86 work by disabling the diagnostic for a range of source locations
87 and do not work when all the pragmas and the affected code are in a
88 single macro expansion. */
89
90/* Push diagnostic state. */
91#define DIAG_PUSH_NEEDS_COMMENT _Pragma ("GCC diagnostic push")
92
93/* Pop diagnostic state. */
94#define DIAG_POP_NEEDS_COMMENT _Pragma ("GCC diagnostic pop")
95
96#define _DIAG_STR1(s) #s
97#define _DIAG_STR(s) _DIAG_STR1(s)
98
99/* Ignore the diagnostic OPTION. VERSION is the most recent GCC
100 version for which the diagnostic has been confirmed to appear in
101 the absence of the pragma (in the form MAJOR.MINOR for GCC 4.x,
102 just MAJOR for GCC 5 and later). Uses of this pragma should be
103 reviewed when the GCC version given is no longer supported for
104 building glibc; the version number should always be on the same
105 source line as the macro name, so such uses can be found with grep.
106 Uses should come with a comment giving more details of the
107 diagnostic, and an architecture on which it is seen if possibly
108 optimization-related and not in architecture-specific code. This
109 macro should only be used if the diagnostic seems hard to fix (for
110 example, optimization-related false positives). */
111#define DIAG_IGNORE_NEEDS_COMMENT(version, option) \
112 _Pragma (_DIAG_STR (GCC diagnostic ignored option))
113
114#endif /* _LIBC_INTERNAL */
115