* manual/arith.texi: Document MTASC-safety properties.
[jlayton/glibc.git] / include / libc-internal.h
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.  */
10 extern void __libc_init_secure (void);
11
12 /* This function will be called from _init in init-first.c.  */
13 extern 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.  */
17 extern int __profile_frequency (void);
18 libc_hidden_proto (__profile_frequency)
19
20 /* Hooks for the instrumenting functions.  */
21 extern void __cyg_profile_func_enter (void *this_fn, void *call_site);
22 extern void __cyg_profile_func_exit (void *this_fn, void *call_site);
23
24 /* Get frequency of the system processor.  */
25 extern hp_timing_t __get_clockfreq (void);
26
27 /* Free all allocated resources.  */
28 extern void __libc_freeres (void);
29 libc_hidden_proto (__libc_freeres)
30
31 /* Free resources stored in thread-local variables on thread exit.  */
32 extern void __libc_thread_freeres (void);
33
34 /* Define and initialize `__progname' et. al.  */
35 extern void __init_misc (int, char **, char **);
36
37 /* 1 if 'type' is a pointer type, 0 otherwise.  */
38 # define __pointer_type(type) (__builtin_classify_type ((type) 0) == 5)
39
40 /* __intptr_t if P is true, or T if P is false.  */
41 # define __integer_if_pointer_type_sub(T, P) \
42   __typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0 : (void *) (P))) 0 \
43                   : (__typeof__ (0 ? (__intptr_t *) 0 : (void *) (!(P)))) 0))
44
45 /* __intptr_t if EXPR has a pointer type, or the type of EXPR otherwise.  */
46 # define __integer_if_pointer_type(expr) \
47   __integer_if_pointer_type_sub(__typeof__ ((__typeof__ (expr)) 0), \
48                                 __pointer_type (__typeof__ (expr)))
49
50 /* Cast an integer or a pointer VAL to integer with proper type.  */
51 # define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val))
52
53 /* Align a value by rounding down to closest size.
54    e.g. Using size of 4096, we get this behavior:
55         {4095, 4096, 4097} = {0, 4096, 4096}.  */
56 #define ALIGN_DOWN(base, size)  ((base) & -((__typeof__ (base)) (size)))
57
58 /* Align a value by rounding up to closest size.
59    e.g. Using size of 4096, we get this behavior:
60         {4095, 4096, 4097} = {4096, 4096, 8192}.
61
62   Note: The size argument has side effects (expanded multiple times).  */
63 #define ALIGN_UP(base, size)    ALIGN_DOWN ((base) + (size) - 1, (size))
64
65 /* Same as ALIGN_DOWN(), but automatically casts when base is a pointer.  */
66 #define PTR_ALIGN_DOWN(base, size) \
67   ((__typeof__ (base)) ALIGN_DOWN ((uintptr_t) (base), (size)))
68
69 /* Same as ALIGN_UP(), but automatically casts when base is a pointer.  */
70 #define PTR_ALIGN_UP(base, size) \
71   ((__typeof__ (base)) ALIGN_UP ((uintptr_t) (base), (size)))
72
73 #endif /* _LIBC_INTERNAL  */