OSDN Git Service

Implement hidden poll, switch user to hidden *printf/*scanf/poll
[uclinux-h8/uClibc.git] / include / libc-internal.h
1 /* Copyright (C) 1991,92,93,95,96,97,98,99,2000,2001 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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.
8
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.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #ifndef _LIBC_INTERNAL_H
20 #define _LIBC_INTERNAL_H 1
21
22 /* Some nice features only work properly with ELF */
23 #if defined __HAVE_ELF__
24 /* Define ALIASNAME as a weak alias for NAME. */
25 # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
26 # define _weak_alias(name, aliasname) \
27   extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
28 /* Define ALIASNAME as a strong alias for NAME.  */
29 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
30 # define _strong_alias(name, aliasname) \
31   extern __typeof (name) aliasname __attribute__ ((alias (#name)));
32 /* This comes between the return type and function name in
33  *    a function definition to make that definition weak.  */
34 # define weak_function __attribute__ ((weak))
35 # define weak_const_function __attribute__ ((weak, __const__))
36 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
37  * section attributes on what looks like a comment to the assembler. */
38 # if defined(__cris__) 
39 #   define link_warning(symbol, msg)
40 # else
41 #   define link_warning(symbol, msg)                                          \
42         asm (".section "  ".gnu.warning." #symbol  "\n\t.previous");          \
43             static const char __evoke_link_warning_##symbol[]                 \
44             __attribute__ ((unused, section (".gnu.warning." #symbol "\n\t#"))) = msg;
45 # endif
46 #else /* !defined __HAVE_ELF__ */
47 # define strong_alias(name, aliasname) _strong_alias (name, aliasname)
48 # define weak_alias(name, aliasname) _strong_alias (name, aliasname)
49 # define _strong_alias(name, aliasname) \
50         __asm__(".global " __C_SYMBOL_PREFIX__ #aliasname "\n" \
51                 ".set " __C_SYMBOL_PREFIX__ #aliasname "," __C_SYMBOL_PREFIX__ #name);
52 # define link_warning(symbol, msg) \
53         asm (".stabs \"" msg "\",30,0,0,0\n\t" \
54               ".stabs \"" #symbol "\",1,0,0,0\n");
55 #endif
56
57 #ifndef weak_function
58 /* If we do not have the __attribute__ ((weak)) syntax, there is no way we
59    can define functions as weak symbols.  The compiler will emit a `.globl'
60    directive for the function symbol, and a `.weak' directive in addition
61    will produce an error from the assembler.  */ 
62 # define weak_function          /* empty */
63 # define weak_const_function    /* empty */
64 #endif
65
66 /* On some platforms we can make internal function calls (i.e., calls of
67    functions not exported) a bit faster by using a different calling
68    convention.  */
69 #if 0 /*def __i386__*/
70 # define internal_function __attribute__ ((regparm (3), stdcall))
71 #endif
72 #ifndef internal_function
73 # define internal_function      /* empty */
74 #endif
75
76 #ifndef NOT_IN_libc
77 # define IS_IN_libc 1
78 #endif
79
80 /* Prepare for the case that `__builtin_expect' is not available.  */
81 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
82 # define __builtin_expect(x, expected_value) (x)
83 #endif
84 #ifndef likely
85 # define likely(x)      __builtin_expect((!!(x)),1)
86 #endif
87 #ifndef unlikely
88 # define unlikely(x)    __builtin_expect((!!(x)),0)
89 #endif
90 #ifndef __LINUX_COMPILER_H
91 # define __LINUX_COMPILER_H
92 #endif
93 #ifndef __cast__
94 # define __cast__(_to)
95 #endif
96
97 /* Arrange to hide uClibc internals */
98 #if __GNUC_PREREQ (3, 3)
99 # define attribute_hidden __attribute__ ((visibility ("hidden")))
100 #else
101 # define attribute_hidden
102 #endif
103 #define hidden_def(name) extern __typeof (name) name attribute_hidden;
104 /* Define ALIASNAME as a hidden weak alias for NAME. */
105 # define hidden_weak_alias(name, aliasname) _hidden_weak_alias (name, aliasname)
106 # define _hidden_weak_alias(name, aliasname) \
107   extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) __attribute__ ((visibility ("hidden")));
108 /* Define ALIASNAME as a hidden strong alias for NAME.  */
109 # define hidden_strong_alias(name, aliasname) _hidden_strong_alias(name, aliasname)
110 # define _hidden_strong_alias(name, aliasname) \
111   extern __typeof (name) aliasname __attribute__ ((alias (#name))) __attribute__ ((visibility ("hidden")));
112
113 #ifdef __UCLIBC_BUILD_RELRO__
114 # define attribute_relro __attribute__ ((section (".data.rel.ro")))
115 #else
116 # define attribute_relro
117 #endif
118
119 #ifdef __GNUC__
120 # define attribute_noreturn __attribute__ ((__noreturn__))
121 #else
122 # define attribute_noreturn
123 #endif
124
125 /* Pull in things like __attribute_used__ */
126 #include <sys/cdefs.h>
127
128 /* --- this is added to integrate linuxthreads */
129 #define __USE_UNIX98            1
130
131 #ifndef __ASSEMBLER__
132 # ifdef IS_IN_libc
133
134 #  define __UC(N) __ ## N
135 #  define __UC_ALIAS(N) strong_alias( __ ## N , N )
136 #  if defined __UCLIBC_HAS_XLOCALE__ && defined __UCLIBC_DO_XLOCALE
137 #   define __UCXL(N) __ ## N ## _l
138 #   define __UCXL_ALIAS(N) strong_alias ( __ ## N ## _l , N ## _l )
139 #  else
140 #   define __UCXL(N) __UC(N)
141 #   define __UCXL_ALIAS(N) __UC_ALIAS(N)
142 #  endif
143
144 #  include <bits/types.h>
145
146 #  ifndef __ssize_t_defined
147 typedef __ssize_t ssize_t;
148 #   define __ssize_t_defined
149 #  endif
150
151 #  define __need_size_t
152 #  include <stddef.h>
153
154 #  include <bits/sigset.h>
155
156 /* prototypes for internal use, please keep these in sync w/ updated headers */
157 /* #include <fcntl.h> */
158 extern int __open(__const char *__file, int __oflag, ...) attribute_hidden;
159
160 /* #include <string.h> */
161 extern int __memcmp (__const void *__s1, __const void *__s2, size_t __n) attribute_hidden;
162 extern void *__memcpy (void *__restrict __dest,
163                      __const void *__restrict __src, size_t __n) attribute_hidden;
164 extern void *__memmove (void *__dest, __const void *__src, size_t __n) attribute_hidden;
165 extern void *__memset (void *__s, int __c, size_t __n) attribute_hidden;
166 extern char *__strcpy (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
167 extern size_t __strlen (__const char *__s) attribute_hidden;
168 extern int __strcmp (__const char *__s1, __const char *__s2) attribute_hidden;
169 extern char *__strcat (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
170 extern char *__strncpy (char *__restrict __dest,
171                       __const char *__restrict __src, size_t __n) attribute_hidden;
172 extern char *__strchr (__const char *__s, int __c) attribute_hidden;
173 extern int __strncmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
174 extern char *__strdup (__const char *__s) attribute_hidden;
175 extern int __strcasecmp (__const char *__s1, __const char *__s2) attribute_hidden;
176 extern int __strncasecmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
177
178 /* sources are built w/ _GNU_SOURCE, this gets undefined */
179 extern int __xpg_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
180 extern char *__glibc_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
181
182 /* #include <unistd.h> */
183 extern ssize_t __read(int __fd, void *__buf, size_t __nbytes) attribute_hidden;
184 extern ssize_t __write(int __fd, __const void *__buf, size_t __n) attribute_hidden;
185 extern int __close(int __fd) attribute_hidden;
186 extern __pid_t __getpid (void) attribute_hidden;
187
188 /* #include <stdio.h> */
189 extern void __perror (__const char *__s) attribute_hidden;
190 extern int __printf (__const char *__restrict __format, ...) attribute_hidden;
191 extern int __sprintf (char *__restrict __s,
192                     __const char *__restrict __format, ...) attribute_hidden;
193 /* hack */
194 #define fprintf __fprintf
195
196 /* #include <stdlib.h> */
197 extern char *__getenv (__const char *__name) attribute_hidden;
198
199 /* #include <signal.h> */
200 extern int __sigprocmask (int __how, __const __sigset_t *__restrict __set,
201                         __sigset_t *__restrict __oset) attribute_hidden;
202
203 /* #include <sys/ioctl.h> */
204 extern int __ioctl (int __fd, unsigned long int __request, ...) attribute_hidden;
205
206 /* #include <sys/socket.h> */
207 extern int __socket (int __domain, int __type, int __protocol) attribute_hidden;
208
209 #  if 0 /* undoable here */
210 /* #include <dirent.h> */
211 typedef struct __dirstream DIR;
212 extern DIR *__opendir (__const char *__name) attribute_hidden;
213 extern int __closedir (DIR *__dirp) attribute_hidden;
214
215 /* #include <stdio.h> */
216 extern int __vfprintf (FILE *__restrict __s, __const char *__restrict __format,
217                      __gnuc_va_list __arg) attribute_hidden;
218 extern int __fprintf (FILE *__restrict __stream,
219                     __const char *__restrict __format, ...) attribute_hidden;
220
221 /* #include <sys/time.h> */
222 #   define __need_timeval
223 #   include <bits/time.h>
224 extern int __gettimeofday(struct timeval *__restrict __tv, *__restrict __timezone__ptr_t __tz) attribute_hidden;
225 #  endif
226
227 /* #include <pthread.h> */
228 #  ifndef __UCLIBC_HAS_THREADS__
229 #   define __pthread_mutex_init(mutex, mutexattr)         ((void)0)
230 #   define __pthread_mutex_lock(mutex)                    ((void)0)
231 #   define __pthread_mutex_trylock(mutex)                 ((void)0)
232 #   define __pthread_mutex_unlock(mutex)                  ((void)0)
233 #  endif
234
235 # endif /* IS_IN_libc */
236 #endif /* __ASSEMBLER__ */
237
238 #endif /* _LIBC_INTERNAL_H */