libc-internal.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _LIBC_INTERNAL_H
  16. #define _LIBC_INTERNAL_H 1
  17. #include <features.h>
  18. #ifndef __ASSEMBLER__
  19. /* GCC understands weak symbols and aliases; use its interface where
  20. possible, instead of embedded assembly language. */
  21. /* Define ALIASNAME as a strong alias for NAME. */
  22. # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
  23. # define _strong_alias(name, aliasname) \
  24. extern __typeof (name) aliasname __attribute__ ((alias (#name)));
  25. /* This comes between the return type and function name in
  26. a function definition to make that definition weak. */
  27. # define weak_function __attribute__ ((weak))
  28. # define weak_const_function __attribute__ ((weak, __const__))
  29. /* Define ALIASNAME as a weak alias for NAME.
  30. If weak aliases are not available, this defines a strong alias. */
  31. # define weak_alias(name, aliasname) _weak_alias (name, aliasname)
  32. # define _weak_alias(name, aliasname) \
  33. extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
  34. /* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined). */
  35. # define weak_extern(symbol) _weak_extern (weak symbol)
  36. # define _weak_extern(expr) _Pragma (#expr)
  37. #else /* __ASSEMBLER__ */
  38. #ifdef __SYMBOL_PREFIX
  39. # define C_SYMBOL_NAME(name) _##name
  40. #else
  41. # define C_SYMBOL_NAME(name) name
  42. #endif
  43. # define strong_alias(name, aliasname) \
  44. .global C_SYMBOL_NAME (aliasname) ; \
  45. .set C_SYMBOL_NAME(aliasname),C_SYMBOL_NAME(name)
  46. # define weak_alias(name, aliasname) \
  47. .weak C_SYMBOL_NAME(aliasname) ; \
  48. C_SYMBOL_NAME(aliasname) = C_SYMBOL_NAME(name)
  49. # define weak_extern(symbol) \
  50. .weak C_SYMBOL_NAME(symbol)
  51. #endif /* __ASSEMBLER__ */
  52. /* When a reference to SYMBOL is encountered, the linker will emit a
  53. warning message MSG. */
  54. #ifdef __HAVE_ELF__
  55. /* We want the .gnu.warning.SYMBOL section to be unallocated. */
  56. # define __make_section_unallocated(section_string) \
  57. asm (".section " section_string "\n\t.previous");
  58. /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
  59. section attributes on what looks like a comment to the assembler. */
  60. # define __sec_comment "\n\t#"
  61. # ifdef __cris__
  62. # define link_warning(symbol, msg)
  63. # else
  64. # define link_warning(symbol, msg) \
  65. __make_section_unallocated (".gnu.warning." #symbol) \
  66. static const char __evoke_link_warning_##symbol[] \
  67. __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
  68. = msg;
  69. # endif
  70. #else /* __HAVE_ELF__ */
  71. # define link_warning(symbol, msg) \
  72. asm (".stabs \"" msg "\",30,0,0,0\n\t" \
  73. ".stabs \"" __C_SYMBOL_PREFIX__ #symbol "\",1,0,0,0\n");
  74. #endif /* __HAVE_ELF__ */
  75. #ifndef weak_function
  76. /* If we do not have the __attribute__ ((weak)) syntax, there is no way we
  77. can define functions as weak symbols. The compiler will emit a `.globl'
  78. directive for the function symbol, and a `.weak' directive in addition
  79. will produce an error from the assembler. */
  80. # define weak_function /* empty */
  81. # define weak_const_function /* empty */
  82. #endif
  83. /* On some platforms we can make internal function calls (i.e., calls of
  84. functions not exported) a bit faster by using a different calling
  85. convention. */
  86. #if 0 /*def __i386__*/
  87. # define internal_function __attribute__ ((regparm (3), stdcall))
  88. #endif
  89. #ifndef internal_function
  90. # define internal_function /* empty */
  91. #endif
  92. #ifndef NOT_IN_libc
  93. # define IS_IN_libc 1
  94. #endif
  95. /* Prepare for the case that `__builtin_expect' is not available. */
  96. #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
  97. # define __builtin_expect(x, expected_value) (x)
  98. #endif
  99. #ifndef likely
  100. # define likely(x) __builtin_expect((!!(x)),1)
  101. #endif
  102. #ifndef unlikely
  103. # define unlikely(x) __builtin_expect((!!(x)),0)
  104. #endif
  105. #ifndef __LINUX_COMPILER_H
  106. # define __LINUX_COMPILER_H
  107. #endif
  108. #ifndef __cast__
  109. # define __cast__(_to)
  110. #endif
  111. #define attribute_unused __attribute__ ((unused))
  112. /* Arrange to hide uClibc internals */
  113. #if __GNUC_PREREQ (3, 3)
  114. # define attribute_hidden __attribute__ ((visibility ("hidden")))
  115. #else
  116. # define attribute_hidden
  117. #endif
  118. #define hidden_def(name) extern __typeof (name) name attribute_hidden;
  119. #ifndef __ASSEMBLER__
  120. # define hidden_strong_alias(name, aliasname) _hidden_strong_alias(name, aliasname)
  121. # define _hidden_strong_alias(name, aliasname) \
  122. extern __typeof (name) aliasname __attribute__ ((alias (#name))) attribute_hidden;
  123. # define hidden_weak_alias(name, aliasname) _hidden_weak_alias (name, aliasname)
  124. # define _hidden_weak_alias(name, aliasname) \
  125. extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))) attribute_hidden;
  126. #else /* __ASSEMBLER__ */
  127. # define hidden_strong_alias(name, aliasname) \
  128. .global C_SYMBOL_NAME (aliasname) ; \
  129. .hidden C_SYMBOL_NAME (aliasname) ; \
  130. .set C_SYMBOL_NAME(aliasname),C_SYMBOL_NAME(name)
  131. # define hidden_weak_alias(name, aliasname) \
  132. .weak C_SYMBOL_NAME(aliasname) ; \
  133. .hidden C_SYMBOL_NAME(aliasname) ; \
  134. C_SYMBOL_NAME(aliasname) = C_SYMBOL_NAME(name)
  135. #endif /* __ASSEMBLER__ */
  136. #ifdef __UCLIBC_BUILD_RELRO__
  137. # define attribute_relro __attribute__ ((section (".data.rel.ro")))
  138. #else
  139. # define attribute_relro
  140. #endif
  141. #ifdef __GNUC__
  142. # define attribute_noreturn __attribute__ ((__noreturn__))
  143. #else
  144. # define attribute_noreturn
  145. #endif
  146. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  147. # define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
  148. #endif
  149. /* Pull in things like __attribute_used__ */
  150. #include <sys/cdefs.h>
  151. /* --- this is added to integrate linuxthreads */
  152. #define __USE_UNIX98 1
  153. #ifndef __ASSEMBLER__
  154. # ifdef IS_IN_libc
  155. # define __UC(N) __ ## N
  156. # define __UC_ALIAS(N) strong_alias( __ ## N , N )
  157. # if defined __UCLIBC_HAS_XLOCALE__ && defined __UCLIBC_DO_XLOCALE
  158. # define __UCXL(N) __ ## N ## _l
  159. # define __UCXL_ALIAS(N) strong_alias ( __ ## N ## _l , N ## _l )
  160. # else
  161. # define __UCXL(N) __UC(N)
  162. # define __UCXL_ALIAS(N) __UC_ALIAS(N)
  163. # endif
  164. # define __need_size_t
  165. # ifdef __UCLIBC_HAS_WCHAR__
  166. # define __need_wchar_t
  167. # define __need_wint_t
  168. # endif
  169. # include <stddef.h>
  170. # include <bits/types.h>
  171. # ifndef __ssize_t_defined
  172. typedef __ssize_t ssize_t;
  173. # define __ssize_t_defined
  174. # endif
  175. # include <bits/sigset.h>
  176. /* prototypes for internal use, please keep these in sync w/ updated headers */
  177. /* #include <fcntl.h> */
  178. #ifndef __USE_FILE_OFFSET64
  179. extern int __open (__const char *__file, int __oflag, ...) __nonnull ((1)) attribute_hidden;
  180. extern int __fcntl (int __fd, int __cmd, ...) attribute_hidden;
  181. #else
  182. # ifdef __REDIRECT
  183. extern int __REDIRECT (__open, (__const char *__file, int __oflag, ...), __open64)
  184. __nonnull ((1)) attribute_hidden;
  185. extern int __REDIRECT (__fcntl, (int __fd, int __cmd, ...), __fcntl64) attribute_hidden;
  186. # else
  187. # define __open __open64
  188. # define __fcntl __fcntl64
  189. # endif
  190. #endif
  191. #ifdef __USE_LARGEFILE64
  192. extern int __open64 (__const char *__file, int __oflag, ...) __nonnull ((1)) attribute_hidden;
  193. extern int __fcntl64 (int __fd, int __cmd, ...) attribute_hidden;
  194. #endif
  195. /* #include <string.h> */
  196. extern int __memcmp (__const void *__s1, __const void *__s2, size_t __n) attribute_hidden;
  197. extern void *__memcpy (void *__restrict __dest,
  198. __const void *__restrict __src, size_t __n) attribute_hidden;
  199. extern void *__memmove (void *__dest, __const void *__src, size_t __n) attribute_hidden;
  200. extern void *__memset (void *__s, int __c, size_t __n) attribute_hidden;
  201. extern char *__strcpy (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
  202. extern size_t __strlen (__const char *__s) attribute_hidden;
  203. extern int __strcmp (__const char *__s1, __const char *__s2) attribute_hidden;
  204. extern char *__strcat (char *__restrict __dest, __const char *__restrict __src) attribute_hidden;
  205. extern char *__strncpy (char *__restrict __dest,
  206. __const char *__restrict __src, size_t __n) attribute_hidden;
  207. extern char *__strchr (__const char *__s, int __c) attribute_hidden;
  208. extern char *__strrchr (__const char *__s, int __c) attribute_hidden;
  209. extern int __strncmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
  210. extern char *__strdup (__const char *__s) attribute_hidden;
  211. extern int __strcasecmp (__const char *__s1, __const char *__s2) attribute_hidden;
  212. extern int __strncasecmp (__const char *__s1, __const char *__s2, size_t __n) attribute_hidden;
  213. extern void *__rawmemchr (__const void *__s, int __c) __THROW __attribute_pure__ __nonnull ((1)) attribute_hidden;
  214. extern size_t __strspn (__const char *__s, __const char *__accept)
  215. __THROW __attribute_pure__ __nonnull ((1, 2)) attribute_hidden;
  216. extern char *__strpbrk (__const char *__s, __const char *__accept)
  217. __THROW __attribute_pure__ __nonnull ((1, 2)) attribute_hidden;
  218. extern size_t __strnlen (__const char *__string, size_t __maxlen)
  219. __THROW __attribute_pure__ __nonnull ((1)) attribute_hidden;
  220. extern char *__strtok_r (char *__restrict __s, __const char *__restrict __delim,
  221. char **__restrict __save_ptr) __THROW __nonnull ((2, 3)) attribute_hidden;
  222. /* sources are built w/ _GNU_SOURCE, this gets undefined */
  223. extern int __xpg_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
  224. extern char *__glibc_strerror_r_internal (int __errnum, char *__buf, size_t __buflen) attribute_hidden;
  225. /* ctype.h */
  226. extern int __tolower (int __c) __THROW attribute_hidden;
  227. extern int __toupper (int __c) __THROW attribute_hidden;
  228. #ifdef __UCLIBC_HAS_WCHAR__
  229. /* wchar.h */
  230. extern size_t __wcslen (__const wchar_t *__s) __THROW __attribute_pure__ attribute_hidden;
  231. extern wchar_t *__wcscpy (wchar_t *__restrict __dest, __const wchar_t *__restrict __src) __THROW attribute_hidden;
  232. extern size_t __wcsspn (__const wchar_t *__wcs, __const wchar_t *__accept)
  233. __THROW __attribute_pure__ attribute_hidden;
  234. extern wchar_t *__wcspbrk (__const wchar_t *__wcs, __const wchar_t *__accept)
  235. __THROW __attribute_pure__ attribute_hidden;
  236. /* wctype.h */
  237. extern wint_t __towlower (wint_t __wc) __THROW attribute_hidden;
  238. #endif
  239. /* #include <unistd.h> */
  240. extern ssize_t __read(int __fd, void *__buf, size_t __nbytes) attribute_hidden;
  241. extern ssize_t __write(int __fd, __const void *__buf, size_t __n) attribute_hidden;
  242. extern int __close(int __fd) attribute_hidden;
  243. extern __pid_t __getpid (void) attribute_hidden;
  244. extern void _exit_internal (int __status) __attribute__ ((__noreturn__)) attribute_hidden;
  245. #ifndef __USE_FILE_OFFSET64
  246. extern int __lockf (int __fd, int __cmd, __off_t __len) attribute_hidden;
  247. extern __off_t __lseek (int __fd, __off_t __offset, int __whence) __THROW attribute_hidden;
  248. #else
  249. # ifdef __REDIRECT
  250. extern int __REDIRECT (__lockf, (int __fd, int __cmd, __off64_t __len),
  251. __lockf64) attribute_hidden;
  252. extern __off64_t __REDIRECT (__lseek,
  253. (int __fd, __off64_t __offset, int __whence),
  254. __lseek64) attribute_hidden;
  255. # else
  256. # define __lockf __lockf64
  257. # define __lseek __lseek64
  258. # endif
  259. #endif
  260. #ifdef __USE_LARGEFILE64
  261. extern int __lockf64 (int __fd, int __cmd, __off64_t __len) attribute_hidden;
  262. extern __off64_t __lseek64 (int __fd, __off64_t __offset, int __whence) __THROW attribute_hidden;
  263. #endif
  264. /* #include <stdio.h> */
  265. extern void __perror (__const char *__s) attribute_hidden;
  266. extern int __printf (__const char *__restrict __format, ...) attribute_hidden;
  267. extern int __sprintf (char *__restrict __s,
  268. __const char *__restrict __format, ...) attribute_hidden;
  269. /* hack */
  270. #define abort __abort
  271. #define fprintf __fprintf
  272. #define fclose __fclose
  273. #ifndef __USE_FILE_OFFSET64
  274. #define fopen __fopen
  275. #else
  276. #define fopen __fopen64
  277. #endif
  278. #ifdef __USE_LARGEFILE64
  279. #define fopen64 __fopen64
  280. #endif
  281. /* #include <stdlib.h> */
  282. extern char *__getenv (__const char *__name) attribute_hidden;
  283. extern void __exit (int __status) __THROW __attribute__ ((__noreturn__)) attribute_hidden;
  284. /* #include <signal.h> */
  285. extern int __sigprocmask (int __how, __const __sigset_t *__restrict __set,
  286. __sigset_t *__restrict __oset) attribute_hidden;
  287. /* #include <sys/ioctl.h> */
  288. extern int __ioctl (int __fd, unsigned long int __request, ...) attribute_hidden;
  289. /* #include <sys/socket.h> */
  290. extern int __socket (int __domain, int __type, int __protocol) attribute_hidden;
  291. /* #include <sys/stat.h> */
  292. #ifndef __USE_FILE_OFFSET64
  293. struct stat;
  294. extern int __stat (__const char *__restrict __file,
  295. struct stat *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
  296. extern int __fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2)) attribute_hidden;
  297. extern int __lstat (__const char *__restrict __file,
  298. struct stat *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
  299. #else
  300. # ifdef __REDIRECT_NTH
  301. extern int __REDIRECT_NTH (__stat, (__const char *__restrict __file,
  302. struct stat *__restrict __buf), __stat64)
  303. __nonnull ((1, 2)) attribute_hidden;
  304. extern int __REDIRECT_NTH (__fstat, (int __fd, struct stat *__buf), __fstat64)
  305. __nonnull ((2)) attribute_hidden;
  306. extern int __REDIRECT_NTH (__lstat,
  307. (__const char *__restrict __file,
  308. struct stat *__restrict __buf), __lstat64)
  309. __nonnull ((1, 2)) attribute_hidden;
  310. # else
  311. # define __stat __stat64
  312. # define __fstat __fstat64
  313. # define __lstat __lstat64
  314. # endif
  315. #endif
  316. #ifdef __USE_LARGEFILE64
  317. struct stat64;
  318. extern int __stat64 (__const char *__restrict __file,
  319. struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2)) attribute_hidden;
  320. extern int __fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2)) attribute_hidden;
  321. extern int __lstat64 (__const char *__restrict __file,
  322. struct stat64 *__restrict __buf)
  323. __THROW __nonnull ((1, 2)) attribute_hidden;
  324. #endif
  325. /* #include <sys/statfs.h> */
  326. #ifndef __USE_FILE_OFFSET64
  327. struct statfs;
  328. extern int __statfs (__const char *__file, struct statfs *__buf)
  329. __THROW __nonnull ((1, 2)) attribute_hidden;
  330. extern int __fstatfs (int __fildes, struct statfs *__buf)
  331. __THROW __nonnull ((2)) attribute_hidden;
  332. #else
  333. # ifdef __REDIRECT
  334. extern int __REDIRECT (__statfs,
  335. (__const char *__file, struct statfs *__buf),
  336. __statfs64) __nonnull ((1, 2)) attribute_hidden;
  337. extern int __REDIRECT (__fstatfs, (int __fildes, struct statfs *__buf),
  338. __fstatfs64) __nonnull ((2)) attribute_hidden;
  339. # else
  340. # define __statfs __statfs64
  341. # endif
  342. #endif
  343. #ifdef __USE_LARGEFILE64
  344. struct statfs64;
  345. extern int __statfs64 (__const char *__file, struct statfs64 *__buf)
  346. __THROW __nonnull ((1, 2)) attribute_hidden;
  347. extern int __fstatfs64 (int __fildes, struct statfs64 *__buf)
  348. __THROW __nonnull ((2)) attribute_hidden;
  349. #endif
  350. # if 0 /* undoable here */
  351. /* #include <dirent.h> */
  352. typedef struct __dirstream DIR;
  353. extern DIR *__opendir (__const char *__name) attribute_hidden;
  354. extern int __closedir (DIR *__dirp) attribute_hidden;
  355. /* #include <stdio.h> */
  356. extern int __vfprintf (FILE *__restrict __s, __const char *__restrict __format,
  357. __gnuc_va_list __arg) attribute_hidden;
  358. extern int __fprintf (FILE *__restrict __stream,
  359. __const char *__restrict __format, ...) attribute_hidden;
  360. extern int __fclose (FILE *__stream) attribute_hidden;
  361. #ifndef __USE_FILE_OFFSET64
  362. extern FILE *__fopen (__const char *__restrict __filename,
  363. __const char *__restrict __modes) attribute_hidden;
  364. #else
  365. # ifdef __REDIRECT
  366. extern FILE *__REDIRECT (__fopen, (__const char *__restrict __filename,
  367. __const char *__restrict __modes), __fopen64) attribute_hidden;
  368. # else
  369. # define __fopen __fopen64
  370. # endif
  371. #endif
  372. #ifdef __USE_LARGEFILE64
  373. extern FILE *__fopen64 (__const char *__restrict __filename,
  374. __const char *__restrict __modes) attribute_hidden;
  375. #endif
  376. /* #include <sys/time.h> */
  377. # define __need_timeval
  378. # include <bits/time.h>
  379. extern int __gettimeofday(struct timeval *__restrict __tv, *__restrict __timezone__ptr_t __tz) attribute_hidden;
  380. # endif
  381. /* #include <pthread.h> */
  382. # ifndef __UCLIBC_HAS_THREADS__
  383. # define __pthread_mutex_init(mutex, mutexattr) ((void)0)
  384. # define __pthread_mutex_lock(mutex) ((void)0)
  385. # define __pthread_mutex_trylock(mutex) ((void)0)
  386. # define __pthread_mutex_unlock(mutex) ((void)0)
  387. # endif
  388. /* internal access to program name */
  389. extern const char *__uclibc_progname attribute_hidden;
  390. # endif /* IS_IN_libc */
  391. /* #include <alloca.h> */
  392. #include <bits/stackinfo.h>
  393. #if _STACK_GROWS_DOWN
  394. # define extend_alloca(buf, len, newlen) \
  395. (__typeof (buf)) ({ size_t __newlen = (newlen); \
  396. char *__newbuf = alloca (__newlen); \
  397. if (__newbuf + __newlen == (char *) buf) \
  398. len += __newlen; \
  399. else \
  400. len = __newlen; \
  401. __newbuf; })
  402. #elif _STACK_GROWS_UP
  403. # define extend_alloca(buf, len, newlen) \
  404. (__typeof (buf)) ({ size_t __newlen = (newlen); \
  405. char *__newbuf = alloca (__newlen); \
  406. char *__buf = (buf); \
  407. if (__buf + __newlen == __newbuf) \
  408. { \
  409. len += __newlen; \
  410. __newbuf = __buf; \
  411. } \
  412. else \
  413. len = __newlen; \
  414. __newbuf; })
  415. #else
  416. # warning unknown stack
  417. # define extend_alloca(buf, len, newlen) \
  418. alloca (((len) = (newlen)))
  419. #endif
  420. #endif /* __ASSEMBLER__ */
  421. #endif /* _LIBC_INTERNAL_H */