wrappers.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
  3. *
  4. * This 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 of the License, or (at your option) any later version.
  8. *
  9. * This 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 this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  17. */
  18. #ifndef _COBALT_WRAPPERS_H
  19. #define _COBALT_WRAPPERS_H
  20. #include <boilerplate/compiler.h>
  21. #define __WRAP(call) __wrap_ ## call
  22. #define __STD(call) __real_ ## call
  23. #define __COBALT(call) __cobalt_ ## call
  24. #define __RT(call) __COBALT(call)
  25. #define COBALT_DECL(T, FN, I) \
  26. __typeof__(T) __RT(FN) I; \
  27. __typeof__(T) __STD(FN) I; \
  28. __typeof__(T) __WRAP(FN) I
  29. #if __USE_TIME_BITS64 && __TIMESIZE == 32
  30. /*
  31. * Make __RT() and __STD() usable in combination with time64_t related services.
  32. */
  33. #define COBALT_IMPL_TIME64(T, FN, FN_64, I) \
  34. __typeof__(T) __wrap_##FN_64 I \
  35. __attribute__((alias("__cobalt_" __stringify(FN)), weak)); \
  36. COBALT_IMPL(T, FN, I)
  37. #define COBALT_DECL_TIME64(T, FN, A, I) \
  38. __typeof__(T) __STD(A) I; \
  39. extern T __REDIRECT_NTH(__STD(FN), I, __real_##A); \
  40. COBALT_DECL(T, FN, I)
  41. #else
  42. #define COBALT_IMPL_TIME64(T, FN, FN_64, I) COBALT_IMPL(T, FN, I)
  43. #define COBALT_DECL_TIME64(T, FN, FN_64, I) COBALT_DECL(T, FN, I)
  44. #endif
  45. /*
  46. *
  47. * Each "foo" Cobalt routine shadowing a POSIX service may be
  48. * overriden by an external library (see --with-cobalt-override
  49. * option), in which case we generate the following symbols:
  50. *
  51. * __real_foo() => Original POSIX implementation.
  52. * __cobalt_foo() => Cobalt implementation.
  53. * __wrap_foo() => Weak alias to __cobalt_foo(), may be
  54. * overriden.
  55. *
  56. * In the latter case, the external library shall provide its own
  57. * implementation of __wrap_foo(), overriding Cobalt's foo()
  58. * version. The original Cobalt implementation can still be
  59. * referenced as __COBALT(foo).
  60. */
  61. #define COBALT_IMPL(T, FN, I) \
  62. __typeof__(T) __wrap_##FN I \
  63. __attribute__((alias("__cobalt_" __stringify(FN)), weak)); \
  64. __typeof__(T) __cobalt_##FN I
  65. #endif /* !_COBALT_WRAPPERS_H */