libc.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef LIBC_H
  2. #define LIBC_H
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. struct __libc {
  6. int *(*errno_location)(void);
  7. void (*cancelpt)(int);
  8. void (*lock)(volatile int *);
  9. void (*lockfile)(FILE *);
  10. void (**tsd_keys)(void *);
  11. void (*sigtimer)();
  12. int (*atexit)(void (*)(void));
  13. void (*fini)(void);
  14. void (*ldso_fini)(void);
  15. volatile int threads_minus_1;
  16. int ofl_lock;
  17. int (*rsyscall)(int, long, long, long, long, long, long);
  18. void (*fork_handler)(int);
  19. FILE *ofl_head;
  20. };
  21. #if 100*__GNUC__+__GNUC_MINOR__ >= 303 || defined(__PCC__) || defined(__TINYC__)
  22. extern struct __libc __libc __attribute__((visibility("hidden")));
  23. #define libc __libc
  24. #elif !defined(__PIC__)
  25. extern struct __libc __libc;
  26. #define libc __libc
  27. #else
  28. #define USE_LIBC_ACCESSOR
  29. extern struct __libc *__libc_loc(void) __attribute__((const));
  30. #define libc (*__libc_loc())
  31. #endif
  32. /* Designed to avoid any overhead in non-threaded processes */
  33. void __lock(volatile int *);
  34. void __lockfile(FILE *);
  35. #define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
  36. #define UNLOCK(x) (*(x)=0)
  37. #define CANCELPT(x) (libc.cancelpt ? libc.cancelpt((x)),0 : (void)(x),0)
  38. #define CANCELPT_BEGIN CANCELPT(1)
  39. #define CANCELPT_TRY CANCELPT(0)
  40. #define CANCELPT_END CANCELPT(-1)
  41. extern char **__environ;
  42. #define environ __environ
  43. #undef weak_alias
  44. #define weak_alias(old, new) \
  45. extern __typeof(old) new __attribute__((weak, alias(#old)))
  46. #undef LFS64_2
  47. //#define LFS64_2(x, y) weak_alias(x, y)
  48. #define LFS64_2(x, y) extern __typeof(x) y
  49. #undef LFS64
  50. #define LFS64(x) LFS64_2(x, x##64)
  51. #endif